diff options
-rw-r--r-- | util/fbrun/FbRun.cc | 45 | ||||
-rw-r--r-- | util/fbrun/FbRun.hh | 6 |
2 files changed, 43 insertions, 8 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 0ce297a..2d5499a 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc | |||
@@ -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.cc,v 1.9 2002/12/05 00:07:39 fluxgen Exp $ | 22 | // $Id: FbRun.cc,v 1.10 2003/03/22 11:33:04 fluxgen Exp $ |
23 | 23 | ||
24 | #include "FbRun.hh" | 24 | #include "FbRun.hh" |
25 | 25 | ||
@@ -30,6 +30,7 @@ | |||
30 | #include <X11/Xlib.h> | 30 | #include <X11/Xlib.h> |
31 | #include <X11/keysym.h> | 31 | #include <X11/keysym.h> |
32 | #include <X11/Xutil.h> | 32 | #include <X11/Xutil.h> |
33 | #include <X11/cursorfont.h> | ||
33 | 34 | ||
34 | #include <unistd.h> | 35 | #include <unistd.h> |
35 | 36 | ||
@@ -40,13 +41,16 @@ using namespace std; | |||
40 | FbRun::FbRun(int x, int y, size_t width): | 41 | FbRun::FbRun(int x, int y, size_t width): |
41 | m_font("fixed"), | 42 | m_font("fixed"), |
42 | m_win((int)0, x, y, //screen num and position | 43 | m_win((int)0, x, y, //screen num and position |
43 | width + m_bevel, m_font.height(), // size | 44 | width + m_bevel, m_font.height() + 2, // size |
44 | KeyPressMask|ExposureMask), // eventmask | 45 | KeyPressMask|ExposureMask), // eventmask |
45 | m_display(FbTk::App::instance()->display()), | 46 | m_display(FbTk::App::instance()->display()), |
46 | m_bevel(4), | 47 | m_bevel(4), |
47 | m_gc(DefaultGC(m_display, DefaultScreen(m_display))), | 48 | m_gc(DefaultGC(m_display, DefaultScreen(m_display))), |
48 | m_end(false), | 49 | m_end(false), |
49 | m_current_history_item(0) { | 50 | m_current_history_item(0), |
51 | m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)), | ||
52 | m_cursor_pos(0) { | ||
53 | XDefineCursor(FbTk::App::instance()->display(), m_win.window(), m_cursor); | ||
50 | // setting nomaximize in local resize | 54 | // setting nomaximize in local resize |
51 | resize(width, m_font.height()); | 55 | resize(width, m_font.height()); |
52 | FbTk::EventManager::instance()->registerEventHandler(*this, m_win.window()); | 56 | FbTk::EventManager::instance()->registerEventHandler(*this, m_win.window()); |
@@ -172,7 +176,12 @@ void FbRun::drawString(int x, int y, | |||
172 | } | 176 | } |
173 | } | 177 | } |
174 | 178 | ||
175 | m_font.drawText(m_win.window(), DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y); | 179 | m_font.drawText(m_win.window(), DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y - 2); |
180 | int cursor_pos = m_font.textWidth(text + m_cursor_pos, len - startpos) + 1; | ||
181 | // draw cursor position | ||
182 | XDrawLine(FbTk::App::instance()->display(), m_win.window(), m_gc, | ||
183 | cursor_pos, 0, | ||
184 | cursor_pos, m_font.height()); | ||
176 | } | 185 | } |
177 | 186 | ||
178 | void FbRun::keyPressEvent(XKeyEvent &ke) { | 187 | void FbRun::keyPressEvent(XKeyEvent &ke) { |
@@ -183,7 +192,6 @@ void FbRun::keyPressEvent(XKeyEvent &ke) { | |||
183 | m_end = true; | 192 | m_end = true; |
184 | hide(); | 193 | hide(); |
185 | FbTk::App::instance()->end(); // end program | 194 | FbTk::App::instance()->end(); // end program |
186 | return; // no more processing | ||
187 | } else if (ks == XK_Return) { | 195 | } else if (ks == XK_Return) { |
188 | run(m_runtext); | 196 | run(m_runtext); |
189 | m_runtext = ""; // clear text | 197 | m_runtext = ""; // clear text |
@@ -191,9 +199,12 @@ void FbRun::keyPressEvent(XKeyEvent &ke) { | |||
191 | if (m_runtext.size() != 0) { // we can't erase what we don't have ;) | 199 | if (m_runtext.size() != 0) { // we can't erase what we don't have ;) |
192 | m_runtext.erase(m_runtext.size()-1); | 200 | m_runtext.erase(m_runtext.size()-1); |
193 | redrawLabel(); | 201 | redrawLabel(); |
202 | m_cursor_pos--; | ||
194 | } | 203 | } |
195 | } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { | 204 | } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { // insert normal character at cursor pos |
196 | m_runtext+=keychar[0]; // append character | 205 | char in_char[2] = {keychar[0], 0}; |
206 | m_runtext.insert(m_cursor_pos, in_char); | ||
207 | m_cursor_pos++; | ||
197 | redrawLabel(); | 208 | redrawLabel(); |
198 | } else if (IsCursorKey(ks)) { | 209 | } else if (IsCursorKey(ks)) { |
199 | 210 | ||
@@ -204,8 +215,16 @@ void FbRun::keyPressEvent(XKeyEvent &ke) { | |||
204 | case XK_Down: | 215 | case XK_Down: |
205 | nextHistoryItem(); | 216 | nextHistoryItem(); |
206 | break; | 217 | break; |
218 | case XK_Left: | ||
219 | cursorLeft(); | ||
220 | break; | ||
221 | case XK_Right: | ||
222 | cursorRight(); | ||
223 | break; | ||
207 | } | 224 | } |
208 | redrawLabel(); | 225 | redrawLabel(); |
226 | } else if (ks == XK_End) { | ||
227 | m_cursor_pos = m_runtext.size() - 1; | ||
209 | } | 228 | } |
210 | } | 229 | } |
211 | 230 | ||
@@ -243,3 +262,15 @@ void FbRun::nextHistoryItem() { | |||
243 | m_runtext = m_history[m_current_history_item]; | 262 | m_runtext = m_history[m_current_history_item]; |
244 | 263 | ||
245 | } | 264 | } |
265 | |||
266 | |||
267 | void FbRun::cursorLeft() { | ||
268 | if (m_cursor_pos > 0) | ||
269 | m_cursor_pos--; | ||
270 | } | ||
271 | |||
272 | void FbRun::cursorRight() { | ||
273 | m_cursor_pos++; | ||
274 | if (m_cursor_pos >= m_runtext.size()) | ||
275 | m_cursor_pos = m_runtext.size() - 1; | ||
276 | } | ||
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh index a577e45..29a9afd 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.8 2002/12/05 00:07:38 fluxgen Exp $ | 22 | // $Id: FbRun.hh,v 1.9 2003/03/22 11:31:43 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef FBRUN_HH | 24 | #ifndef FBRUN_HH |
25 | #define FBRUN_HH | 25 | #define FBRUN_HH |
@@ -75,6 +75,8 @@ public: | |||
75 | private: | 75 | private: |
76 | void nextHistoryItem(); | 76 | void nextHistoryItem(); |
77 | void prevHistoryItem(); | 77 | void prevHistoryItem(); |
78 | void cursorLeft(); | ||
79 | void cursorRight(); | ||
78 | void drawString(int x, int y, const char *text, size_t len); | 80 | void drawString(int x, int y, const char *text, size_t len); |
79 | void getSize(size_t &width, size_t &height); | 81 | void getSize(size_t &width, size_t &height); |
80 | void createWindow(int x, int y, size_t width, size_t height); | 82 | void createWindow(int x, int y, size_t width, size_t height); |
@@ -92,6 +94,8 @@ private: | |||
92 | std::vector<std::string> m_history; ///< history list of commands | 94 | std::vector<std::string> m_history; ///< history list of commands |
93 | size_t m_current_history_item; ///< holds current position in command history | 95 | size_t m_current_history_item; ///< holds current position in command history |
94 | std::string m_history_file; ///< holds filename for command history file | 96 | std::string m_history_file; ///< holds filename for command history file |
97 | Cursor m_cursor; | ||
98 | int m_cursor_pos; | ||
95 | }; | 99 | }; |
96 | 100 | ||
97 | #endif // FBRUN_HH | 101 | #endif // FBRUN_HH |