aboutsummaryrefslogtreecommitdiff
path: root/util/fbrun/FbRun.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-25 01:18:00 (GMT)
committerfluxgen <fluxgen>2003-08-25 01:18:00 (GMT)
commit103110fc4f171538b2f8422aaa21afa91b03dc95 (patch)
treea426dc792ed0df835b0cf9b7d1b2603eb9e45a3d /util/fbrun/FbRun.cc
parent41763a8da3f75407663499f891aa3c794f3a74f8 (diff)
downloadfluxbox_pavel-103110fc4f171538b2f8422aaa21afa91b03dc95.zip
fluxbox_pavel-103110fc4f171538b2f8422aaa21afa91b03dc95.tar.bz2
added pixmap
Diffstat (limited to 'util/fbrun/FbRun.cc')
-rw-r--r--util/fbrun/FbRun.cc120
1 files changed, 72 insertions, 48 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc
index a9e155d..caf51ce 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.16 2003/08/24 23:47:31 fluxgen Exp $ 22// $Id: FbRun.cc,v 1.17 2003/08/25 01:18:00 fluxgen Exp $
23 23
24#include "FbRun.hh" 24#include "FbRun.hh"
25 25
@@ -27,6 +27,15 @@
27#include "EventManager.hh" 27#include "EventManager.hh"
28#include "Color.hh" 28#include "Color.hh"
29 29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif // HAVE_CONFIG_H
33
34#ifdef HAVE_XPM
35#include <X11/xpm.h>
36#include "fbrun.xpm"
37#endif // HAVE_XPM
38
30#include <X11/Xlib.h> 39#include <X11/Xlib.h>
31#include <X11/keysym.h> 40#include <X11/keysym.h>
32#include <X11/Xutil.h> 41#include <X11/Xutil.h>
@@ -35,16 +44,18 @@
35#include <unistd.h> 44#include <unistd.h>
36 45
37#include <iostream> 46#include <iostream>
47#include <iterator>
38#include <fstream> 48#include <fstream>
39#include <cassert> 49#include <cassert>
40 50
41using namespace std; 51using namespace std;
42FbRun::FbRun(int x, int y, size_t width): 52FbRun::FbRun(int x, int y, size_t width):
53 FbTk::FbWindow((int)DefaultScreen(FbTk::App::instance()->display()),
54 x, y,
55 width, 10,
56 KeyPressMask | ExposureMask),
43 m_font("fixed"), 57 m_font("fixed"),
44 m_display(FbTk::App::instance()->display()), 58 m_display(FbTk::App::instance()->display()),
45 m_win((int)DefaultScreen(m_display), x, y, //screen num and position
46 width + m_bevel, m_font.height() + 2, // size
47 KeyPressMask|ExposureMask), // eventmask
48 m_bevel(4), 59 m_bevel(4),
49 m_gc(DefaultGC(m_display, DefaultScreen(m_display))), 60 m_gc(DefaultGC(m_display, DefaultScreen(m_display))),
50 m_end(false), 61 m_end(false),
@@ -52,30 +63,52 @@ FbRun::FbRun(int x, int y, size_t width):
52 m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)), 63 m_cursor(XCreateFontCursor(FbTk::App::instance()->display(), XC_xterm)),
53 m_start_pos(0), 64 m_start_pos(0),
54 m_end_pos(0), 65 m_end_pos(0),
55 m_cursor_pos(0) 66 m_cursor_pos(0),
56{ 67 m_pixmap(0) {
57 m_win.setCursor(m_cursor); 68
69 setCursor(m_cursor);
58 // setting nomaximize in local resize 70 // setting nomaximize in local resize
59 resize(width, m_font.height()); 71 resize(width, m_font.height());
60 FbTk::EventManager::instance()->registerEventHandler(*this, m_win.window()); 72 FbTk::EventManager::instance()->add(*this, *this);
61 // setup class name 73 // setup class name
62 XClassHint *class_hint = XAllocClassHint(); 74 XClassHint *class_hint = XAllocClassHint();
63 if (class_hint == 0) 75 if (class_hint == 0)
64 throw string("Out of memory"); 76 throw string("Out of memory");
65 class_hint->res_name = "fbrun"; 77 class_hint->res_name = "fbrun";
66 class_hint->res_class = "FbRun"; 78 class_hint->res_class = "FbRun";
67 XSetClassHint(m_display, m_win.window(), class_hint); 79 XSetClassHint(m_display, window(), class_hint);
80
68 XFree(class_hint); 81 XFree(class_hint);
82#ifdef HAVE_XPM
83 Pixmap mask = 0;
84 XpmCreatePixmapFromData(m_display,
85 window(),
86 fbrun_xpm,
87 &m_pixmap,
88 &mask,
89 0); // attribs
90 if (mask != 0)
91 XFreePixmap(m_display, mask);
92#endif // HAVE_XPM
93
94 XWMHints wmhints;
95 wmhints.flags = IconPixmapHint;
96 wmhints.icon_pixmap = m_pixmap;
97 XSetWMHints(m_display, window(), &wmhints);
69} 98}
70 99
71 100
72FbRun::~FbRun() { 101FbRun::~FbRun() {
73 hide(); 102 hide();
74 FbTk::EventManager::instance()->unregisterEventHandler(m_win.window()); 103 if (m_pixmap != 0)
104 XFreePixmap(FbTk::App::instance()->display(), m_pixmap);
75} 105}
76 106
77void FbRun::run(const std::string &command) { 107void FbRun::run(const std::string &command) {
78 //fork and execute program 108 FbTk::App::instance()->end(); // end application
109 m_end = true; // mark end of processing
110
111 // fork and execute program
79 if (!fork()) { 112 if (!fork()) {
80 setsid(); 113 setsid();
81 execl("/bin/sh", "/bin/sh", "-c", command.c_str(), 0); 114 execl("/bin/sh", "/bin/sh", "-c", command.c_str(), 0);
@@ -93,10 +126,12 @@ void FbRun::run(const std::string &command) {
93 && m_runtext == m_history[m_current_history_item]) { 126 && m_runtext == m_history[m_current_history_item]) {
94 // m_current_history_item is the duplicate 127 // m_current_history_item is the duplicate
95 } else { 128 } else {
96 int i; 129 m_current_history_item = 0;
97 for (i = 0; i < m_history.size(); i++) 130 for (; m_current_history_item < m_history.size();
98 if (m_runtext == m_history[i]) break; 131 ++m_current_history_item) {
99 m_current_history_item = i; 132 if (m_history[m_current_history_item] == m_runtext)
133 break;
134 }
100 } 135 }
101 136
102 // now m_current_history_item points at the duplicate, or 137 // now m_current_history_item points at the duplicate, or
@@ -110,14 +145,13 @@ void FbRun::run(const std::string &command) {
110 // write the history items that come after current 145 // write the history items that come after current
111 for (i++; i < m_history.size(); i++) 146 for (i++; i < m_history.size(); i++)
112 inoutfile<<m_history[i]<<endl; 147 inoutfile<<m_history[i]<<endl;
148
113 // and append the current one back to the end 149 // and append the current one back to the end
114 inoutfile<<m_runtext<<endl; 150 inoutfile<<m_runtext<<endl;
115 inoutfile.close();
116 } else 151 } else
117 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; 152 cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl;
118 } 153 }
119 FbTk::App::instance()->end(); // end application 154
120 m_end = true; // mark end of processing
121} 155}
122 156
123bool FbRun::loadHistory(const char *filename) { 157bool FbRun::loadHistory(const char *filename) {
@@ -150,17 +184,17 @@ bool FbRun::loadFont(const string &fontname) {
150 return false; 184 return false;
151 185
152 // resize to fit new font height 186 // resize to fit new font height
153 resize(m_win.width(), m_font.height() + m_bevel); 187 resize(width(), m_font.height() + m_bevel);
154 return true; 188 return true;
155} 189}
156 190
157void FbRun::setForeground(const FbTk::Color &color) { 191void FbRun::setForegroundColor(const FbTk::Color &color) {
158 XSetForeground(m_display, m_gc, color.pixel()); 192 XSetForeground(m_display, m_gc, color.pixel());
159 redrawLabel(); 193 redrawLabel();
160} 194}
161 195
162void FbRun::setBackground(const FbTk::Color &color) { 196void FbRun::setBackgroundColor(const FbTk::Color &color) {
163 m_win.setBackgroundColor(color); 197 FbTk::FbWindow::setBackgroundColor(color);
164 redrawLabel(); 198 redrawLabel();
165} 199}
166 200
@@ -170,28 +204,16 @@ void FbRun::setText(const string &text) {
170} 204}
171 205
172void FbRun::setTitle(const string &title) { 206void FbRun::setTitle(const string &title) {
173 m_win.setName(title.c_str()); 207 setName(title.c_str());
174}
175
176void FbRun::move(int x, int y) {
177 m_win.move(x, y);
178} 208}
179 209
180void FbRun::resize(size_t width, size_t height) { 210void FbRun::resize(size_t width, size_t height) {
181 m_win.resize(width, height); 211 FbTk::FbWindow::resize(width, height);
182 setNoMaximize(); 212 setNoMaximize();
183} 213}
184 214
185void FbRun::show() {
186 m_win.show();
187}
188
189void FbRun::hide() {
190 m_win.hide();
191}
192
193void FbRun::redrawLabel() { 215void FbRun::redrawLabel() {
194 m_win.clear(); 216 clear();
195 drawString(m_bevel/2, m_font.ascent() + m_bevel/2, 217 drawString(m_bevel/2, m_font.ascent() + m_bevel/2,
196 m_runtext.c_str(), m_runtext.size()); 218 m_runtext.c_str(), m_runtext.size());
197 219
@@ -201,10 +223,12 @@ void FbRun::drawString(int x, int y,
201 const char *text, size_t len) { 223 const char *text, size_t len) {
202 assert(m_gc); 224 assert(m_gc);
203 225
204 m_font.drawText(m_win.window(), DefaultScreen(m_display), m_gc, text + m_start_pos, m_end_pos - m_start_pos, x, y - 2); 226 m_font.drawText(window(), screenNumber(),
227 m_gc, text + m_start_pos,
228 m_end_pos - m_start_pos, x, y - 2);
205 // draw cursor position 229 // draw cursor position
206 int cursor_pos = m_font.textWidth(text + m_start_pos, m_cursor_pos) + 1; 230 int cursor_pos = m_font.textWidth(text + m_start_pos, m_cursor_pos) + 1;
207 m_win.drawLine(m_gc, cursor_pos, 0, cursor_pos, m_font.height()); 231 drawLine(m_gc, cursor_pos, 0, cursor_pos, m_font.height());
208} 232}
209 233
210void FbRun::keyPressEvent(XKeyEvent &ke) { 234void FbRun::keyPressEvent(XKeyEvent &ke) {
@@ -304,11 +328,11 @@ void FbRun::setNoMaximize() {
304 // we don't need to maximize this window 328 // we don't need to maximize this window
305 XSizeHints sh; 329 XSizeHints sh;
306 sh.flags = PMaxSize | PMinSize; 330 sh.flags = PMaxSize | PMinSize;
307 sh.max_width = m_win.width(); 331 sh.max_width = width();
308 sh.max_height = m_win.height(); 332 sh.max_height = height();
309 sh.min_width = m_win.width(); 333 sh.min_width = width();
310 sh.min_height = m_win.height(); 334 sh.min_height = height();
311 XSetWMNormalHints(m_display, m_win.window(), &sh); 335 XSetWMNormalHints(m_display, window(), &sh);
312} 336}
313 337
314void FbRun::prevHistoryItem() { 338void FbRun::prevHistoryItem() {
@@ -449,7 +473,7 @@ void FbRun::adjustEndPos() {
449 m_end_pos = m_runtext.size(); 473 m_end_pos = m_runtext.size();
450 const char *text = m_runtext.c_str(); 474 const char *text = m_runtext.c_str();
451 int text_width = m_font.textWidth(text + m_start_pos, m_end_pos - m_start_pos); 475 int text_width = m_font.textWidth(text + m_start_pos, m_end_pos - m_start_pos);
452 while (text_width > m_win.width()) { 476 while (text_width > width()) {
453 m_end_pos--; 477 m_end_pos--;
454 text_width = m_font.textWidth(text + m_start_pos, m_end_pos - m_start_pos); 478 text_width = m_font.textWidth(text + m_start_pos, m_end_pos - m_start_pos);
455 } 479 }
@@ -458,10 +482,10 @@ void FbRun::adjustEndPos() {
458void FbRun::adjustStartPos() { 482void FbRun::adjustStartPos() {
459 const char *text = m_runtext.c_str(); 483 const char *text = m_runtext.c_str();
460 int text_width = m_font.textWidth(text + m_start_pos, m_end_pos - m_start_pos); 484 int text_width = m_font.textWidth(text + m_start_pos, m_end_pos - m_start_pos);
461 if (text_width < m_win.width()) return; 485 if (text_width < width()) return;
462 int start_pos = 0; 486 int start_pos = 0;
463 text_width = m_font.textWidth(text + start_pos, m_end_pos - start_pos); 487 text_width = m_font.textWidth(text + start_pos, m_end_pos - start_pos);
464 while (text_width > m_win.width()) { 488 while (text_width > width()) {
465 start_pos++; 489 start_pos++;
466 text_width = m_font.textWidth(text + start_pos, m_end_pos - start_pos); 490 text_width = m_font.textWidth(text + start_pos, m_end_pos - start_pos);
467 } 491 }