aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/fbrun/FbRun.cc77
-rw-r--r--util/fbrun/FbRun.hh12
2 files changed, 48 insertions, 41 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index 7aa7938..1dc5ae7 100644
--- a/util/fbrun/FbRun.cc
+++ b/util/fbrun/FbRun.cc
@@ -19,11 +19,12 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbRun.cc,v 1.7 2002/11/26 17:13:36 fluxgen Exp $ 22// $Id: FbRun.cc,v 1.8 2002/11/27 21:56:56 fluxgen Exp $
23 23
24#include "FbRun.hh" 24#include "FbRun.hh"
25 25
26#include "App.hh" 26#include "App.hh"
27#include "EventManager.hh"
27 28
28#include <X11/Xlib.h> 29#include <X11/Xlib.h>
29#include <X11/keysym.h> 30#include <X11/keysym.h>
@@ -48,6 +49,7 @@ m_current_history_item(0) {
48 49
49FbRun::~FbRun() { 50FbRun::~FbRun() {
50 hide(); 51 hide();
52 FbTk::EventManager::instance()->unregisterEventHandler(m_win);
51 XDestroyWindow(m_display, m_win); 53 XDestroyWindow(m_display, m_win);
52} 54}
53 55
@@ -70,7 +72,7 @@ void FbRun::run(const std::string &command) {
70 else 72 else
71 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; 73 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
72 } 74 }
73 75 FbTk::App::instance()->end(); // end application
74 m_end = true; // mark end of processing 76 m_end = true; // mark end of processing
75} 77}
76 78
@@ -192,7 +194,9 @@ void FbRun::createWindow(int x, int y, size_t width, size_t height) {
192 throw string("Failed to create FbRun window!"); 194 throw string("Failed to create FbRun window!");
193 195
194 XSelectInput(m_display, m_win, KeyPressMask|ExposureMask); 196 XSelectInput(m_display, m_win, KeyPressMask|ExposureMask);
195 197
198 FbTk::EventManager::instance()->registerEventHandler(*this, m_win);
199
196 setNoMaximize(); 200 setNoMaximize();
197 201
198 m_width = width; 202 m_width = width;
@@ -200,48 +204,43 @@ void FbRun::createWindow(int x, int y, size_t width, size_t height) {
200 204
201} 205}
202 206
203void FbRun::handleEvent(XEvent * const xev) { 207void FbRun::keyPressEvent(XKeyEvent &ke) {
204 switch (xev->type) { 208 KeySym ks;
205 case KeyPress: { 209 char keychar[1];
206 KeySym ks; 210 XLookupString(&ke, keychar, 1, &ks, 0);
207 char keychar[1]; 211 if (ks == XK_Escape) {
208 XLookupString(&xev->xkey, keychar, 1, &ks, 0); 212 m_end = true;
209 if (ks == XK_Escape) { 213 hide();
210 m_end = true; 214 return; // no more processing
211 hide(); 215 } else if (ks == XK_Return) {
212 return; // no more processing 216 run(m_runtext);
213 } else if (ks == XK_Return) { 217 m_runtext = ""; // clear text
214 run(m_runtext); 218 } else if (ks == XK_BackSpace) {
215 m_runtext = ""; // clear text 219 if (m_runtext.size() != 0) { // we can't erase what we don't have ;)
216 } else if (ks == XK_BackSpace) { 220 m_runtext.erase(m_runtext.size()-1);
217 if (m_runtext.size() != 0) { // we can't erase what we don't have ;)
218 m_runtext.erase(m_runtext.size()-1);
219 redrawLabel();
220 }
221 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) {
222 m_runtext+=keychar[0]; // append character
223 redrawLabel();
224 } else if (IsCursorKey(ks)) {
225
226 switch (ks) {
227 case XK_Up:
228 prevHistoryItem();
229 break;
230 case XK_Down:
231 nextHistoryItem();
232 break;
233 }
234 redrawLabel();
235 }
236 } break;
237 case Expose:
238 redrawLabel(); 221 redrawLabel();
222 }
223 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) {
224 m_runtext+=keychar[0]; // append character
225 redrawLabel();
226 } else if (IsCursorKey(ks)) {
227
228 switch (ks) {
229 case XK_Up:
230 prevHistoryItem();
239 break; 231 break;
240 default: 232 case XK_Down:
233 nextHistoryItem();
241 break; 234 break;
235 }
236 redrawLabel();
242 } 237 }
243} 238}
244 239
240void FbRun::exposeEvent(XExposeEvent &ev) {
241 redrawLabel();
242}
243
245void FbRun::getSize(size_t &width, size_t &height) { 244void FbRun::getSize(size_t &width, size_t &height) {
246 XWindowAttributes attr; 245 XWindowAttributes attr;
247 XGetWindowAttributes(m_display, m_win, &attr); 246 XGetWindowAttributes(m_display, m_win, &attr);
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh
index efcd54f..41e5925 100644
--- a/util/fbrun/FbRun.hh
+++ b/util/fbrun/FbRun.hh
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: FbRun.hh,v 1.6 2002/11/15 14:03:14 fluxgen Exp $ 22// $Id: FbRun.hh,v 1.7 2002/11/27 21:56:02 fluxgen Exp $
23 23
24#ifndef FBRUN_HH 24#ifndef FBRUN_HH
25#define FBRUN_HH 25#define FBRUN_HH
@@ -33,7 +33,7 @@
33/** 33/**
34 Creates and managed a run window 34 Creates and managed a run window
35*/ 35*/
36class FbRun: public FbTk::EventHandler<XEvent> { 36class FbRun: public FbTk::EventHandler {
37public: 37public:
38 FbRun(int x = 0, int y = 0, size_t width = 200); 38 FbRun(int x = 0, int y = 0, size_t width = 200);
39 ~FbRun(); 39 ~FbRun();
@@ -63,6 +63,14 @@ public:
63 @return true on success, else false 63 @return true on success, else false
64 */ 64 */
65 bool loadHistory(const char *filename); 65 bool loadHistory(const char *filename);
66 /**
67 @name events
68 */
69 ///@{
70 void exposeEvent(XExposeEvent &ev);
71 void keyPressEvent(XKeyEvent &ev);
72 ///@}
73
66private: 74private:
67 void nextHistoryItem(); 75 void nextHistoryItem();
68 void prevHistoryItem(); 76 void prevHistoryItem();