aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/fbrun/FbRun.cc35
-rw-r--r--util/fbrun/FbRun.hh11
2 files changed, 31 insertions, 15 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index 6a0e6d8..d2f468c 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.4 2002/11/12 19:20:31 fluxgen Exp $ 22// $Id: FbRun.cc,v 1.5 2002/11/13 16:43:52 fluxgen Exp $
23 23
24#include "FbRun.hh" 24#include "FbRun.hh"
25 25
@@ -42,7 +42,8 @@ m_display(BaseDisplay::getXDisplay()),
42m_bevel(4), 42m_bevel(4),
43m_gc(DefaultGC(m_display, DefaultScreen(m_display))), 43m_gc(DefaultGC(m_display, DefaultScreen(m_display))),
44m_end(false), 44m_end(false),
45m_current_history_item(0) { 45m_current_history_item(0),
46m_drawstart_x(0) {
46 createWindow(x, y, width + m_bevel, m_font.height()); 47 createWindow(x, y, width + m_bevel, m_font.height());
47} 48}
48 49
@@ -137,7 +138,7 @@ void FbRun::resize(size_t width, size_t height) {
137 assert(m_win); 138 assert(m_win);
138 XResizeWindow(m_display, m_win, width, height); 139 XResizeWindow(m_display, m_win, width, height);
139 m_width = width; 140 m_width = width;
140 m_height = height + m_bevel; 141 m_height = height;
141 setNoMaximize(); 142 setNoMaximize();
142} 143}
143 144
@@ -155,7 +156,7 @@ void FbRun::redrawLabel() {
155 assert(m_win); 156 assert(m_win);
156 157
157 XClearWindow(m_display, m_win); 158 XClearWindow(m_display, m_win);
158 drawString(m_bevel/2, m_height - m_bevel/2, 159 drawString(m_bevel/2, m_font.ascent() + m_bevel/2,
159 m_runtext.c_str(), m_runtext.size()); 160 m_runtext.c_str(), m_runtext.size());
160 161
161} 162}
@@ -164,7 +165,18 @@ void FbRun::drawString(int x, int y,
164 const char *text, size_t len) { 165 const char *text, size_t len) {
165 assert(m_win); 166 assert(m_win);
166 assert(m_gc); 167 assert(m_gc);
167 m_font.drawText(m_win, DefaultScreen(m_display), m_gc, text, len, x, y); 168 // check right boundary
169 // and adjust text drawing
170 size_t text_width = m_font.textWidth(text, len);
171 size_t startpos = 0;
172 if (text_width > m_width) {
173 for (; startpos < len; ++startpos) {
174 if (m_font.textWidth(text+startpos, len-startpos) < m_width)
175 break;
176 }
177 }
178
179 m_font.drawText(m_win, DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y);
168} 180}
169 181
170 182
@@ -202,20 +214,23 @@ void FbRun::handleEvent(XEvent * const xev) {
202 } else if (ks == XK_Return) { 214 } else if (ks == XK_Return) {
203 run(m_runtext); 215 run(m_runtext);
204 m_runtext = ""; // clear text 216 m_runtext = ""; // clear text
205 } else if (ks == XK_BackSpace && m_runtext.size() != 0) { 217 } else if (ks == XK_BackSpace) {
206 m_runtext.erase(m_runtext.size()-1); 218 if (m_runtext.size() != 0) { // we can't erase what we don't have ;)
207 redrawLabel(); 219 m_runtext.erase(m_runtext.size()-1);
220 redrawLabel();
221 }
208 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { 222 } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) {
209 m_runtext+=keychar[0]; // append character 223 m_runtext+=keychar[0]; // append character
210 redrawLabel(); 224 redrawLabel();
211 } else if (IsCursorKey(ks)) { 225 } else if (IsCursorKey(ks)) {
226
212 switch (ks) { 227 switch (ks) {
213 case XK_Up: 228 case XK_Up:
214 prevHistoryItem(); 229 prevHistoryItem();
215 break; 230 break;
216 case XK_Down: 231 case XK_Down:
217 nextHistoryItem(); 232 nextHistoryItem();
218 break; 233 break;
219 } 234 }
220 redrawLabel(); 235 redrawLabel();
221 } 236 }
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh
index 5c8a2dc..a7a3983 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.3 2002/11/12 19:20:31 fluxgen Exp $ 22// $Id: FbRun.hh,v 1.4 2002/11/13 16:43:52 fluxgen Exp $
23 23
24#ifndef FBRUN_HH 24#ifndef FBRUN_HH
25#define FBRUN_HH 25#define FBRUN_HH
@@ -77,11 +77,12 @@ private:
77 std::string m_runtext; ///< command to execute 77 std::string m_runtext; ///< command to execute
78 size_t m_width, m_height; ///< size of window 78 size_t m_width, m_height; ///< size of window
79 int m_bevel; ///< distance to window edge from font in pixels 79 int m_bevel; ///< distance to window edge from font in pixels
80 GC m_gc; 80 GC m_gc; ///< graphic context
81 bool m_end; 81 bool m_end; ///< marks when this object is done
82 std::vector<std::string> m_history; ///< history list of commands 82 std::vector<std::string> m_history; ///< history list of commands
83 size_t m_current_history_item; 83 size_t m_current_history_item; ///< holds current position in command history
84 std::string m_history_file; 84 std::string m_history_file; ///< holds filename for command history file
85 int m_drawstart_x; ///< for scrolling if cursor is to far to the right
85}; 86};
86 87
87#endif // FBRUN_HH 88#endif // FBRUN_HH