diff options
author | fluxgen <fluxgen> | 2002-12-05 00:07:39 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-12-05 00:07:39 (GMT) |
commit | 248639a7aaa1c2330d9c9c20d8ae0f8c6841e77d (patch) | |
tree | aa30c049a4b2ed6004b4a4258864c6d5b045586c /util | |
parent | d0f0e2d438760a4d41020687a5878639a6e3c2aa (diff) | |
download | fluxbox-248639a7aaa1c2330d9c9c20d8ae0f8c6841e77d.zip fluxbox-248639a7aaa1c2330d9c9c20d8ae0f8c6841e77d.tar.bz2 |
indentation and minor fbtk updates
Diffstat (limited to 'util')
-rw-r--r-- | util/fbrun/FbRun.cc | 321 | ||||
-rw-r--r-- | util/fbrun/FbRun.hh | 112 | ||||
-rw-r--r-- | util/fbrun/main.cc | 219 |
3 files changed, 299 insertions, 353 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 1dc5ae7..0ce297a 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc | |||
@@ -19,12 +19,13 @@ | |||
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.8 2002/11/27 21:56:56 fluxgen Exp $ | 22 | // $Id: FbRun.cc,v 1.9 2002/12/05 00:07:39 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 | #include "EventManager.hh" |
28 | #include "Color.hh" | ||
28 | 29 | ||
29 | #include <X11/Xlib.h> | 30 | #include <X11/Xlib.h> |
30 | #include <X11/keysym.h> | 31 | #include <X11/keysym.h> |
@@ -37,248 +38,208 @@ | |||
37 | 38 | ||
38 | using namespace std; | 39 | using namespace std; |
39 | FbRun::FbRun(int x, int y, size_t width): | 40 | FbRun::FbRun(int x, int y, size_t width): |
40 | m_font("fixed"), | 41 | m_font("fixed"), |
41 | m_win(None), | 42 | m_win((int)0, x, y, //screen num and position |
42 | m_display(FbTk::App::instance()->display()), | 43 | width + m_bevel, m_font.height(), // size |
43 | m_bevel(4), | 44 | KeyPressMask|ExposureMask), // eventmask |
44 | m_gc(DefaultGC(m_display, DefaultScreen(m_display))), | 45 | m_display(FbTk::App::instance()->display()), |
45 | m_end(false), | 46 | m_bevel(4), |
46 | m_current_history_item(0) { | 47 | m_gc(DefaultGC(m_display, DefaultScreen(m_display))), |
47 | createWindow(x, y, width + m_bevel, m_font.height()); | 48 | m_end(false), |
49 | m_current_history_item(0) { | ||
50 | // setting nomaximize in local resize | ||
51 | resize(width, m_font.height()); | ||
52 | FbTk::EventManager::instance()->registerEventHandler(*this, m_win.window()); | ||
48 | } | 53 | } |
49 | 54 | ||
50 | FbRun::~FbRun() { | 55 | FbRun::~FbRun() { |
51 | hide(); | 56 | hide(); |
52 | FbTk::EventManager::instance()->unregisterEventHandler(m_win); | 57 | FbTk::EventManager::instance()->unregisterEventHandler(m_win.window()); |
53 | XDestroyWindow(m_display, m_win); | ||
54 | } | 58 | } |
55 | 59 | ||
56 | void FbRun::run(const std::string &command) { | 60 | void FbRun::run(const std::string &command) { |
57 | //fork and execute program | 61 | //fork and execute program |
58 | if (!fork()) { | 62 | if (!fork()) { |
59 | setsid(); | 63 | setsid(); |
60 | execl("/bin/sh", "/bin/sh", "-c", command.c_str(), 0); | 64 | execl("/bin/sh", "/bin/sh", "-c", command.c_str(), 0); |
61 | exit(0); //exit fork | 65 | exit(0); //exit child |
62 | } | 66 | } |
63 | 67 | ||
64 | hide(); // hide gui | 68 | hide(); // hide gui |
65 | 69 | ||
66 | // save command history to file | 70 | // save command history to file |
67 | if (m_runtext.size() != 0) { // no need to save empty command | 71 | if (m_runtext.size() != 0) { // no need to save empty command |
68 | // open file in append mode | 72 | // open file in append mode |
69 | ofstream outfile(m_history_file.c_str(), ios::app); | 73 | ofstream outfile(m_history_file.c_str(), ios::app); |
70 | if (outfile) | 74 | if (outfile) |
71 | outfile<<m_runtext<<endl; | 75 | outfile<<m_runtext<<endl; |
72 | else | 76 | else |
73 | cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; | 77 | cerr<<"FbRun Warning: Can't write command history to file: "<<m_history_file<<endl; |
74 | } | 78 | } |
75 | FbTk::App::instance()->end(); // end application | 79 | FbTk::App::instance()->end(); // end application |
76 | m_end = true; // mark end of processing | 80 | m_end = true; // mark end of processing |
77 | } | 81 | } |
78 | 82 | ||
79 | bool FbRun::loadHistory(const char *filename) { | 83 | bool FbRun::loadHistory(const char *filename) { |
80 | if (filename == 0) | 84 | if (filename == 0) |
81 | return false; | 85 | return false; |
82 | ifstream infile(filename); | 86 | ifstream infile(filename); |
83 | if (!infile) { | 87 | if (!infile) { |
84 | //even though we fail to load file, we should try save to it | 88 | //even though we fail to load file, we should try save to it |
85 | m_history_file = filename; | 89 | m_history_file = filename; |
86 | return false; | 90 | return false; |
87 | } | 91 | } |
88 | // clear old history and load new one from file | 92 | // clear old history and load new one from file |
89 | m_history.clear(); | 93 | m_history.clear(); |
90 | // each line is a command | 94 | // each line is a command |
91 | string line; | 95 | string line; |
92 | while (!infile.eof()) { | 96 | while (!infile.eof()) { |
93 | getline(infile, line); | 97 | getline(infile, line); |
94 | if (line.size()) // don't add empty lines | 98 | if (line.size()) // don't add empty lines |
95 | m_history.push_back(line); | 99 | m_history.push_back(line); |
96 | } | 100 | } |
97 | // set no current histor to display | 101 | // set no current histor to display |
98 | m_current_history_item = m_history.size(); | 102 | m_current_history_item = m_history.size(); |
99 | // set history file | 103 | // set history file |
100 | m_history_file = filename; | 104 | m_history_file = filename; |
101 | return true; | 105 | return true; |
102 | } | 106 | } |
103 | 107 | ||
104 | bool FbRun::loadFont(const string &fontname) { | 108 | bool FbRun::loadFont(const string &fontname) { |
105 | if (!m_font.load(fontname.c_str())) | 109 | if (!m_font.load(fontname.c_str())) |
106 | return false; | 110 | return false; |
107 | 111 | ||
108 | // resize to fit new font height | 112 | // resize to fit new font height |
109 | resize(m_width, m_font.height() + m_bevel); | 113 | resize(m_win.width(), m_font.height() + m_bevel); |
110 | return true; | 114 | return true; |
111 | } | 115 | } |
112 | 116 | ||
113 | void FbRun::setForeground(const XColor &color) { | 117 | void FbRun::setForeground(const FbTk::Color &color) { |
114 | XSetForeground(m_display, m_gc, color.pixel); | 118 | XSetForeground(m_display, m_gc, color.pixel()); |
115 | redrawLabel(); | 119 | redrawLabel(); |
116 | } | 120 | } |
117 | 121 | ||
118 | void FbRun::setBackground(const XColor &color) { | 122 | void FbRun::setBackground(const FbTk::Color &color) { |
119 | XSetWindowBackground(m_display, m_win, color.pixel); | 123 | m_win.setBackgroundColor(color); |
120 | redrawLabel(); | 124 | redrawLabel(); |
121 | } | 125 | } |
122 | 126 | ||
123 | 127 | ||
124 | void FbRun::setText(const string &text) { | 128 | void FbRun::setText(const string &text) { |
125 | m_runtext = text; | 129 | m_runtext = text; |
126 | redrawLabel(); | 130 | redrawLabel(); |
127 | } | 131 | } |
128 | 132 | ||
129 | void FbRun::setTitle(const string &title) { | 133 | void FbRun::setTitle(const string &title) { |
130 | assert(m_win); | 134 | m_win.setName(title.c_str()); |
131 | XStoreName(m_display, m_win, const_cast<char *>(title.c_str())); | ||
132 | } | 135 | } |
133 | 136 | ||
134 | void FbRun::move(int x, int y) { | 137 | void FbRun::move(int x, int y) { |
135 | XMoveWindow(m_display, m_win, x, y); | 138 | m_win.move(x, y); |
136 | } | 139 | } |
137 | 140 | ||
138 | void FbRun::resize(size_t width, size_t height) { | 141 | void FbRun::resize(size_t width, size_t height) { |
139 | assert(m_win); | 142 | m_win.resize(width, height); |
140 | XResizeWindow(m_display, m_win, width, height); | 143 | setNoMaximize(); |
141 | m_width = width; | ||
142 | m_height = height; | ||
143 | setNoMaximize(); | ||
144 | } | 144 | } |
145 | 145 | ||
146 | void FbRun::show() { | 146 | void FbRun::show() { |
147 | assert(m_win); | 147 | m_win.show(); |
148 | XMapWindow(m_display, m_win); | ||
149 | } | 148 | } |
150 | 149 | ||
151 | void FbRun::hide() { | 150 | void FbRun::hide() { |
152 | assert(m_win); | 151 | m_win.hide(); |
153 | XUnmapWindow(m_display, m_win); | ||
154 | } | 152 | } |
155 | 153 | ||
156 | void FbRun::redrawLabel() { | 154 | void FbRun::redrawLabel() { |
157 | assert(m_win); | 155 | m_win.clear(); |
158 | 156 | drawString(m_bevel/2, m_font.ascent() + m_bevel/2, | |
159 | XClearWindow(m_display, m_win); | 157 | m_runtext.c_str(), m_runtext.size()); |
160 | drawString(m_bevel/2, m_font.ascent() + m_bevel/2, | ||
161 | m_runtext.c_str(), m_runtext.size()); | ||
162 | 158 | ||
163 | } | 159 | } |
164 | 160 | ||
165 | void FbRun::drawString(int x, int y, | 161 | void FbRun::drawString(int x, int y, |
166 | const char *text, size_t len) { | 162 | const char *text, size_t len) { |
167 | assert(m_win); | 163 | assert(m_gc); |
168 | assert(m_gc); | ||
169 | // check right boundary | ||
170 | // and adjust text drawing | ||
171 | size_t text_width = m_font.textWidth(text, len); | ||
172 | size_t startpos = 0; | ||
173 | if (text_width > m_width) { | ||
174 | for (; startpos < len; ++startpos) { | ||
175 | if (m_font.textWidth(text+startpos, len-startpos) < m_width) | ||
176 | break; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | m_font.drawText(m_win, DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y); | ||
181 | } | ||
182 | |||
183 | |||
184 | void FbRun::createWindow(int x, int y, size_t width, size_t height) { | ||
185 | m_win = XCreateSimpleWindow(m_display, // display | ||
186 | DefaultRootWindow(m_display), // parent windows | ||
187 | x, y, | ||
188 | width, height, | ||
189 | 1, // border_width | ||
190 | 0, // border | ||
191 | WhitePixel(m_display, DefaultScreen(m_display))); // background | ||
192 | |||
193 | if (m_win == None) | ||
194 | throw string("Failed to create FbRun window!"); | ||
195 | |||
196 | XSelectInput(m_display, m_win, KeyPressMask|ExposureMask); | ||
197 | |||
198 | FbTk::EventManager::instance()->registerEventHandler(*this, m_win); | ||
199 | |||
200 | setNoMaximize(); | ||
201 | 164 | ||
202 | m_width = width; | 165 | // check right boundary and adjust text drawing |
203 | m_height = height; | 166 | size_t text_width = m_font.textWidth(text, len); |
167 | size_t startpos = 0; | ||
168 | if (text_width > m_win.width()) { | ||
169 | for (; startpos < len; ++startpos) { | ||
170 | if (m_font.textWidth(text+startpos, len-startpos) < m_win.width()) | ||
171 | break; | ||
172 | } | ||
173 | } | ||
204 | 174 | ||
175 | m_font.drawText(m_win.window(), DefaultScreen(m_display), m_gc, text + startpos, len-startpos, x, y); | ||
205 | } | 176 | } |
206 | 177 | ||
207 | void FbRun::keyPressEvent(XKeyEvent &ke) { | 178 | void FbRun::keyPressEvent(XKeyEvent &ke) { |
208 | KeySym ks; | 179 | KeySym ks; |
209 | char keychar[1]; | 180 | char keychar[1]; |
210 | XLookupString(&ke, keychar, 1, &ks, 0); | 181 | XLookupString(&ke, keychar, 1, &ks, 0); |
211 | if (ks == XK_Escape) { | 182 | if (ks == XK_Escape) { |
212 | m_end = true; | 183 | m_end = true; |
213 | hide(); | 184 | hide(); |
214 | return; // no more processing | 185 | FbTk::App::instance()->end(); // end program |
215 | } else if (ks == XK_Return) { | 186 | return; // no more processing |
216 | run(m_runtext); | 187 | } else if (ks == XK_Return) { |
217 | m_runtext = ""; // clear text | 188 | run(m_runtext); |
218 | } else if (ks == XK_BackSpace) { | 189 | m_runtext = ""; // clear text |
219 | if (m_runtext.size() != 0) { // we can't erase what we don't have ;) | 190 | } else if (ks == XK_BackSpace) { |
220 | m_runtext.erase(m_runtext.size()-1); | 191 | if (m_runtext.size() != 0) { // we can't erase what we don't have ;) |
221 | redrawLabel(); | 192 | m_runtext.erase(m_runtext.size()-1); |
222 | } | 193 | redrawLabel(); |
223 | } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { | 194 | } |
224 | m_runtext+=keychar[0]; // append character | 195 | } else if (! IsModifierKey(ks) && !IsCursorKey(ks)) { |
225 | redrawLabel(); | 196 | m_runtext+=keychar[0]; // append character |
226 | } else if (IsCursorKey(ks)) { | 197 | redrawLabel(); |
198 | } else if (IsCursorKey(ks)) { | ||
227 | 199 | ||
228 | switch (ks) { | 200 | switch (ks) { |
229 | case XK_Up: | 201 | case XK_Up: |
230 | prevHistoryItem(); | 202 | prevHistoryItem(); |
231 | break; | 203 | break; |
232 | case XK_Down: | 204 | case XK_Down: |
233 | nextHistoryItem(); | 205 | nextHistoryItem(); |
234 | break; | 206 | break; |
235 | } | 207 | } |
236 | redrawLabel(); | 208 | redrawLabel(); |
237 | } | 209 | } |
238 | } | 210 | } |
239 | 211 | ||
240 | void FbRun::exposeEvent(XExposeEvent &ev) { | 212 | void FbRun::exposeEvent(XExposeEvent &ev) { |
241 | redrawLabel(); | 213 | redrawLabel(); |
242 | } | 214 | } |
243 | 215 | ||
244 | void FbRun::getSize(size_t &width, size_t &height) { | ||
245 | XWindowAttributes attr; | ||
246 | XGetWindowAttributes(m_display, m_win, &attr); | ||
247 | width = attr.width; | ||
248 | height = attr.height; | ||
249 | } | ||
250 | 216 | ||
251 | void FbRun::setNoMaximize() { | 217 | void FbRun::setNoMaximize() { |
252 | 218 | // we don't need to maximize this window | |
253 | size_t width, height; | 219 | XSizeHints sh; |
254 | 220 | sh.flags = PMaxSize | PMinSize; | |
255 | getSize(width, height); | 221 | sh.max_width = m_win.width(); |
256 | 222 | sh.max_height = m_win.height(); | |
257 | // we don't need to maximize this window | 223 | sh.min_width = m_win.width(); |
258 | XSizeHints sh; | 224 | sh.min_height = m_win.height(); |
259 | sh.flags = PMaxSize | PMinSize; | 225 | XSetWMNormalHints(m_display, m_win.window(), &sh); |
260 | sh.max_width = width; | ||
261 | sh.max_height = height; | ||
262 | sh.min_width = width; | ||
263 | sh.min_height = height; | ||
264 | XSetWMNormalHints(m_display, m_win, &sh); | ||
265 | } | 226 | } |
266 | 227 | ||
267 | void FbRun::prevHistoryItem() { | 228 | void FbRun::prevHistoryItem() { |
268 | 229 | ||
269 | if (m_current_history_item > 0 && m_history.size() > 0) | 230 | if (m_current_history_item > 0 && m_history.size() > 0) |
270 | m_current_history_item--; | 231 | m_current_history_item--; |
271 | if (m_current_history_item < m_history.size()) | 232 | if (m_current_history_item < m_history.size()) |
272 | m_runtext = m_history[m_current_history_item]; | 233 | m_runtext = m_history[m_current_history_item]; |
273 | } | 234 | } |
274 | 235 | ||
275 | void FbRun::nextHistoryItem() { | 236 | void FbRun::nextHistoryItem() { |
276 | m_current_history_item++; | 237 | m_current_history_item++; |
277 | if (m_current_history_item >= m_history.size()) { | 238 | if (m_current_history_item >= m_history.size()) { |
278 | m_current_history_item = m_history.size(); | 239 | m_current_history_item = m_history.size(); |
279 | m_runtext = ""; | 240 | m_runtext = ""; |
280 | return; | 241 | return; |
281 | } else | 242 | } else |
282 | m_runtext = m_history[m_current_history_item]; | 243 | m_runtext = m_history[m_current_history_item]; |
283 | 244 | ||
284 | } | 245 | } |
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh index 41e5925..a577e45 100644 --- a/util/fbrun/FbRun.hh +++ b/util/fbrun/FbRun.hh | |||
@@ -19,79 +19,79 @@ | |||
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.7 2002/11/27 21:56:02 fluxgen Exp $ | 22 | // $Id: FbRun.hh,v 1.8 2002/12/05 00:07:38 fluxgen Exp $ |
23 | 23 | ||
24 | #ifndef FBRUN_HH | 24 | #ifndef FBRUN_HH |
25 | #define FBRUN_HH | 25 | #define FBRUN_HH |
26 | 26 | ||
27 | #include "EventHandler.hh" | 27 | #include "EventHandler.hh" |
28 | #include "Font.hh" | 28 | #include "Font.hh" |
29 | #include "FbWindow.hh" | ||
29 | 30 | ||
30 | #include <string> | 31 | #include <string> |
31 | #include <vector> | 32 | #include <vector> |
32 | 33 | ||
33 | /** | 34 | /** |
34 | Creates and managed a run window | 35 | Creates and managed a run window |
35 | */ | 36 | */ |
36 | class FbRun: public FbTk::EventHandler { | 37 | class FbRun: public FbTk::EventHandler { |
37 | public: | 38 | public: |
38 | FbRun(int x = 0, int y = 0, size_t width = 200); | 39 | FbRun(int x = 0, int y = 0, size_t width = 200); |
39 | ~FbRun(); | 40 | ~FbRun(); |
40 | void handleEvent(XEvent * const ev); | 41 | void handleEvent(XEvent * const ev); |
41 | void setText(const std::string &text); | 42 | void setText(const std::string &text); |
42 | void setTitle(const std::string &title); | 43 | void setTitle(const std::string &title); |
43 | void move(int x, int y); | 44 | void move(int x, int y); |
44 | void resize(size_t width, size_t height); | 45 | void resize(size_t width, size_t height); |
45 | size_t height() const { return m_height; } | 46 | size_t height() const { return m_win.height(); } |
46 | size_t width() const { return m_width; } | 47 | size_t width() const { return m_win.width(); } |
47 | /// hide window | 48 | /// hide window |
48 | void hide(); | 49 | void hide(); |
49 | /// show window | 50 | /// show window |
50 | void show(); | 51 | void show(); |
51 | /// load and reconfigure for new font | 52 | /// load and reconfigure for new font |
52 | bool loadFont(const std::string &fontname); | 53 | bool loadFont(const std::string &fontname); |
53 | void setForeground(const XColor &color); | 54 | void setForeground(const FbTk::Color &color); |
54 | void setBackground(const XColor &color); | 55 | void setBackground(const FbTk::Color &color); |
55 | void setAntialias(bool val) { m_font.setAntialias(val); } | 56 | void setAntialias(bool val) { m_font.setAntialias(val); } |
56 | const FbTk::Font &font() const { return m_font; } | 57 | const FbTk::Font &font() const { return m_font; } |
57 | /// execute command and exit | 58 | /// execute command and exit |
58 | void run(const std::string &execstring); | 59 | void run(const std::string &execstring); |
59 | /// is this application done? | 60 | /// is this application done? |
60 | bool end() const { return m_end; } | 61 | bool end() const { return m_end; } |
61 | /** | 62 | /** |
62 | loads history file. | 63 | loads history file. |
63 | @return true on success, else false | 64 | @return true on success, else false |
64 | */ | 65 | */ |
65 | bool loadHistory(const char *filename); | 66 | bool loadHistory(const char *filename); |
66 | /** | 67 | /** |
67 | @name events | 68 | @name events |
68 | */ | 69 | */ |
69 | ///@{ | 70 | ///@{ |
70 | void exposeEvent(XExposeEvent &ev); | 71 | void exposeEvent(XExposeEvent &ev); |
71 | void keyPressEvent(XKeyEvent &ev); | 72 | void keyPressEvent(XKeyEvent &ev); |
72 | ///@} | 73 | ///@} |
73 | 74 | ||
74 | private: | 75 | private: |
75 | void nextHistoryItem(); | 76 | void nextHistoryItem(); |
76 | void prevHistoryItem(); | 77 | void prevHistoryItem(); |
77 | void drawString(int x, int y, const char *text, size_t len); | 78 | void drawString(int x, int y, const char *text, size_t len); |
78 | void getSize(size_t &width, size_t &height); | 79 | void getSize(size_t &width, size_t &height); |
79 | void createWindow(int x, int y, size_t width, size_t height); | 80 | void createWindow(int x, int y, size_t width, size_t height); |
80 | void redrawLabel(); | 81 | void redrawLabel(); |
81 | /// set no maximizable for this window | 82 | /// set no maximizable for this window |
82 | void setNoMaximize(); | 83 | void setNoMaximize(); |
83 | 84 | ||
84 | FbTk::Font m_font; ///< font used to draw command text | 85 | FbTk::Font m_font; ///< font used to draw command text |
85 | Window m_win; ///< toplevel window | 86 | FbTk::FbWindow m_win; ///< toplevel window |
86 | Display *m_display; ///< display connection | 87 | Display *m_display; ///< display connection |
87 | std::string m_runtext; ///< command to execute | 88 | std::string m_runtext; ///< command to execute |
88 | size_t m_width, m_height; ///< size of window | 89 | int m_bevel; ///< distance to window edge from font in pixels |
89 | int m_bevel; ///< distance to window edge from font in pixels | 90 | GC m_gc; ///< graphic context |
90 | GC m_gc; ///< graphic context | 91 | bool m_end; ///< marks when this object is done |
91 | bool m_end; ///< marks when this object is done | 92 | std::vector<std::string> m_history; ///< history list of commands |
92 | std::vector<std::string> m_history; ///< history list of commands | 93 | size_t m_current_history_item; ///< holds current position in command history |
93 | size_t m_current_history_item; ///< holds current position in command history | 94 | std::string m_history_file; ///< holds filename for command history file |
94 | std::string m_history_file; ///< holds filename for command history file | ||
95 | }; | 95 | }; |
96 | 96 | ||
97 | #endif // FBRUN_HH | 97 | #endif // FBRUN_HH |
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc index 9c73aa5..ff9402c 100644 --- a/util/fbrun/main.cc +++ b/util/fbrun/main.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: main.cc,v 1.7 2002/11/27 21:54:11 fluxgen Exp $ | 22 | // $Id: main.cc,v 1.8 2002/12/05 00:07:39 fluxgen Exp $ |
23 | 23 | ||
24 | #include "FbRun.hh" | 24 | #include "FbRun.hh" |
25 | #include "App.hh" | 25 | #include "App.hh" |
26 | #include "StringUtil.hh" | 26 | #include "StringUtil.hh" |
27 | #include "Color.hh" | ||
27 | 28 | ||
28 | #include <string> | 29 | #include <string> |
29 | #include <iostream> | 30 | #include <iostream> |
@@ -31,134 +32,118 @@ | |||
31 | using namespace std; | 32 | using namespace std; |
32 | 33 | ||
33 | void showUsage(const char *progname) { | 34 | void showUsage(const char *progname) { |
34 | cerr<<"fbrun 1.1.2 : (c) 2002 Henrik Kinnunen"<<endl; | 35 | cerr<<"fbrun 1.1.2 : (c) 2002 Henrik Kinnunen"<<endl; |
35 | cerr<<"Usage: "<< | 36 | cerr<<"Usage: "<< |
36 | progname<<" [arguments]"<<endl<< | 37 | progname<<" [arguments]"<<endl<< |
37 | "Arguments: "<<endl<< | 38 | "Arguments: "<<endl<< |
38 | " -font [font name] Text font"<<endl<< | 39 | " -font [font name] Text font"<<endl<< |
39 | " -title [title name] Set title"<<endl<< | 40 | " -title [title name] Set title"<<endl<< |
40 | " -text [text] Text input"<<endl<< | 41 | " -text [text] Text input"<<endl<< |
41 | " -w [width] Window width in pixels"<<endl<< | 42 | " -w [width] Window width in pixels"<<endl<< |
42 | " -h [height] Window height in pixels"<<endl<< | 43 | " -h [height] Window height in pixels"<<endl<< |
43 | " -display [display string] Display name"<<endl<< | 44 | " -display [display string] Display name"<<endl<< |
44 | " -pos [x] [y] Window position in pixels"<<endl<< | 45 | " -pos [x] [y] Window position in pixels"<<endl<< |
45 | " -fg [color name] Foreground text color"<<endl<< | 46 | " -fg [color name] Foreground text color"<<endl<< |
46 | " -bg [color name] Background color"<<endl<< | 47 | " -bg [color name] Background color"<<endl<< |
47 | " -a Antialias"<<endl<< | 48 | " -a Antialias"<<endl<< |
48 | " -hf [history file] History file to load (default ~/.fluxbox/history)"<<endl<< | 49 | " -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<< |
49 | " -help Show this help"<<endl<<endl<< | 50 | " -help Show this help"<<endl<<endl<< |
50 | "Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl; | 51 | "Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl; |
51 | } | 52 | } |
52 | 53 | ||
53 | int main(int argc, char **argv) { | 54 | int main(int argc, char **argv) { |
54 | int x = 0, y = 0; // default pos of window | 55 | int x = 0, y = 0; // default pos of window |
55 | size_t width = 200, height = 32; // default size of window | 56 | size_t width = 200, height = 32; // default size of window |
56 | bool set_height = false, set_width=false; // use height/width of font by default | 57 | bool set_height = false, set_width=false; // use height/width of font by default |
57 | bool set_pos = false; // set position | 58 | bool set_pos = false; // set position |
58 | bool antialias = false; // antialias text | 59 | bool antialias = false; // antialias text |
59 | string fontname; // font name | 60 | string fontname; // font name |
60 | string title("Run program"); // default title | 61 | string title("Run program"); // default title |
61 | string text; // default input text | 62 | string text; // default input text |
62 | string foreground("black"); // text color | 63 | string foreground("black"); // text color |
63 | string background("white"); // text background color | 64 | string background("white"); // text background color |
64 | string display_name; // name of the display connection | 65 | string display_name; // name of the display connection |
65 | string history_file("~/.fluxbox/fbrun_history"); // command history file | 66 | string history_file("~/.fluxbox/fbrun_history"); // command history file |
66 | // parse arguments | 67 | // parse arguments |
67 | for (int i=1; i<argc; i++) { | 68 | for (int i=1; i<argc; i++) { |
68 | if (strcmp(argv[i], "-font") == 0 && i+1 < argc) { | 69 | if (strcmp(argv[i], "-font") == 0 && i+1 < argc) { |
69 | fontname = argv[++i]; | 70 | fontname = argv[++i]; |
70 | } else if (strcmp(argv[i], "-title") == 0 && i+1 < argc) { | 71 | } else if (strcmp(argv[i], "-title") == 0 && i+1 < argc) { |
71 | title = argv[++i]; | 72 | title = argv[++i]; |
72 | } else if (strcmp(argv[i], "-text") == 0 && i+1 < argc) { | 73 | } else if (strcmp(argv[i], "-text") == 0 && i+1 < argc) { |
73 | text = argv[++i]; | 74 | text = argv[++i]; |
74 | } else if (strcmp(argv[i], "-w") == 0 && i+1 < argc) { | 75 | } else if (strcmp(argv[i], "-w") == 0 && i+1 < argc) { |
75 | width = atoi(argv[++i]); | 76 | width = atoi(argv[++i]); |
76 | set_width = true; | 77 | set_width = true; |
77 | } else if (strcmp(argv[i], "-h") == 0 && i+1 < argc) { | 78 | } else if (strcmp(argv[i], "-h") == 0 && i+1 < argc) { |
78 | height = atoi(argv[++i]); | 79 | height = atoi(argv[++i]); |
79 | set_height = true; // mark true else the height of font will be used | 80 | set_height = true; // mark true else the height of font will be used |
80 | } else if (strcmp(argv[i], "-display") == 0 && i+1 < argc) { | 81 | } else if (strcmp(argv[i], "-display") == 0 && i+1 < argc) { |
81 | display_name = argv[++i]; | 82 | display_name = argv[++i]; |
82 | } else if (strcmp(argv[i], "-pos") == 0 && i+2 < argc) { | 83 | } else if (strcmp(argv[i], "-pos") == 0 && i+2 < argc) { |
83 | x = atoi(argv[++i]); | 84 | x = atoi(argv[++i]); |
84 | y = atoi(argv[++i]); | 85 | y = atoi(argv[++i]); |
85 | set_pos = true; | 86 | set_pos = true; |
86 | } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) { | 87 | } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) { |
87 | foreground = argv[++i]; | 88 | foreground = argv[++i]; |
88 | } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) { | 89 | } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) { |
89 | background = argv[++i]; | 90 | background = argv[++i]; |
90 | } else if (strcmp(argv[i], "-a") == 0) { | 91 | } else if (strcmp(argv[i], "-a") == 0) { |
91 | antialias = true; | 92 | antialias = true; |
92 | } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) { | 93 | } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) { |
93 | history_file = argv[++i]; | 94 | history_file = argv[++i]; |
94 | } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { | 95 | } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { |
95 | showUsage(argv[0]); | 96 | showUsage(argv[0]); |
96 | exit(0); | 97 | exit(0); |
97 | } else { | 98 | } else { |
98 | cerr<<"Invalid argument: "<<argv[i]<<endl; | 99 | cerr<<"Invalid argument: "<<argv[i]<<endl; |
99 | showUsage(argv[0]); | 100 | showUsage(argv[0]); |
100 | exit(0); | 101 | exit(0); |
101 | } | 102 | } |
102 | 103 | ||
103 | } | 104 | } |
104 | 105 | ||
105 | try { | 106 | try { |
106 | 107 | ||
107 | FbTk::App application(display_name.c_str()); | 108 | FbTk::App application(display_name.c_str()); |
108 | Display *disp = application.display(); | 109 | FbRun fbrun; |
109 | |||
110 | FbRun fbrun; | ||
111 | 110 | ||
112 | if (fontname.size() != 0) { | 111 | if (fontname.size() != 0) { |
113 | if (!fbrun.loadFont(fontname.c_str())) { | 112 | if (!fbrun.loadFont(fontname.c_str())) { |
114 | cerr<<"Failed to load font: "<<fontname<<endl; | 113 | cerr<<"Failed to load font: "<<fontname<<endl; |
115 | cerr<<"Falling back to \"fixed\""<<endl; | 114 | cerr<<"Falling back to \"fixed\""<<endl; |
116 | } | 115 | } |
117 | } | 116 | } |
118 | 117 | ||
119 | // get color | 118 | // get color |
120 | XColor xc_foreground, xc_background; | 119 | XColor xc_foreground, xc_background; |
121 | if (XParseColor(disp, DefaultColormap(disp, DefaultScreen(disp)), | 120 | FbTk::Color fg_color(foreground.c_str(), 0); |
122 | foreground.c_str(), | 121 | FbTk::Color bg_color(background.c_str(), 0); |
123 | &xc_foreground) == 0) { | ||
124 | cerr<<"Faild to lookup color: "<<foreground<<endl; | ||
125 | } | ||
126 | |||
127 | if (XParseColor(disp, DefaultColormap(disp, DefaultScreen(disp)), | ||
128 | background.c_str(), | ||
129 | &xc_background) == 0) { | ||
130 | cerr<<"Faild to lookup color: "<<background<<endl; | ||
131 | } | ||
132 | |||
133 | XAllocColor(disp, DefaultColormap(disp, DefaultScreen(disp)), | ||
134 | &xc_foreground); | ||
135 | XAllocColor(disp, DefaultColormap(disp, DefaultScreen(disp)), | ||
136 | &xc_background); | ||
137 | 122 | ||
138 | fbrun.setForeground(xc_foreground); | 123 | fbrun.setForeground(fg_color); |
139 | fbrun.setBackground(xc_background); | 124 | fbrun.setBackground(bg_color); |
140 | 125 | ||
141 | if (set_height) | 126 | if (set_height) |
142 | fbrun.resize(fbrun.width(), height); | 127 | fbrun.resize(fbrun.width(), height); |
143 | if (set_width) | 128 | if (set_width) |
144 | fbrun.resize(width, fbrun.height()); | 129 | fbrun.resize(width, fbrun.height()); |
145 | if (antialias) | 130 | if (antialias) |
146 | fbrun.setAntialias(antialias); | 131 | fbrun.setAntialias(antialias); |
147 | // expand and load command history | 132 | // expand and load command history |
148 | string expanded_filename = StringUtil::expandFilename(history_file); | 133 | string expanded_filename = StringUtil::expandFilename(history_file); |
149 | if (!fbrun.loadHistory(expanded_filename.c_str())) | 134 | if (!fbrun.loadHistory(expanded_filename.c_str())) |
150 | cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl; | 135 | cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl; |
151 | 136 | ||
152 | fbrun.setTitle(title); | 137 | fbrun.setTitle(title); |
153 | fbrun.setText(text); | 138 | fbrun.setText(text); |
154 | fbrun.show(); | 139 | fbrun.show(); |
155 | 140 | ||
156 | if (set_pos) | 141 | if (set_pos) |
157 | fbrun.move(x, y); | 142 | fbrun.move(x, y); |
158 | 143 | ||
159 | application.eventLoop(); | 144 | application.eventLoop(); |
160 | 145 | ||
161 | } catch (string errstr) { | 146 | } catch (string errstr) { |
162 | cerr<<"Error: "<<errstr<<endl; | 147 | cerr<<"Error: "<<errstr<<endl; |
163 | } | 148 | } |
164 | } | 149 | } |