aboutsummaryrefslogtreecommitdiff
path: root/util/fbrun/main.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-12-05 00:07:39 (GMT)
committerfluxgen <fluxgen>2002-12-05 00:07:39 (GMT)
commit248639a7aaa1c2330d9c9c20d8ae0f8c6841e77d (patch)
treeaa30c049a4b2ed6004b4a4258864c6d5b045586c /util/fbrun/main.cc
parentd0f0e2d438760a4d41020687a5878639a6e3c2aa (diff)
downloadfluxbox_pavel-248639a7aaa1c2330d9c9c20d8ae0f8c6841e77d.zip
fluxbox_pavel-248639a7aaa1c2330d9c9c20d8ae0f8c6841e77d.tar.bz2
indentation and minor fbtk updates
Diffstat (limited to 'util/fbrun/main.cc')
-rw-r--r--util/fbrun/main.cc219
1 files changed, 102 insertions, 117 deletions
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 @@
31using namespace std; 32using namespace std;
32 33
33void showUsage(const char *progname) { 34void 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
53int main(int argc, char **argv) { 54int 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}