aboutsummaryrefslogtreecommitdiff
path: root/util/fbrun/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbrun/main.cc')
-rw-r--r--util/fbrun/main.cc151
1 files changed, 151 insertions, 0 deletions
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc
new file mode 100644
index 0000000..b68ea83
--- /dev/null
+++ b/util/fbrun/main.cc
@@ -0,0 +1,151 @@
1// main.cc for FbRun
2// Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen(at)linuxmail.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: main.cc,v 1.11 2003/12/01 18:58:53 fluxgen Exp $
23
24#include "FbRun.hh"
25#include "App.hh"
26#include "StringUtil.hh"
27#include "Color.hh"
28
29#include <string>
30#include <iostream>
31
32using namespace std;
33
34void showUsage(const char *progname) {
35 cerr<<"fbrun 1.1.3 : (c) 2002-2003 Henrik Kinnunen"<<endl;
36 cerr<<"Usage: "<<
37 progname<<" [arguments]"<<endl<<
38 "Arguments: "<<endl<<
39 " -font [font name] Text font"<<endl<<
40 " -title [title name] Set title"<<endl<<
41 " -text [text] Text input"<<endl<<
42 " -w [width] Window width in pixels"<<endl<<
43 " -h [height] Window height in pixels"<<endl<<
44 " -display [display string] Display name"<<endl<<
45 " -pos [x] [y] Window position in pixels"<<endl<<
46 " -fg [color name] Foreground text color"<<endl<<
47 " -bg [color name] Background color"<<endl<<
48 " -na Disable antialias"<<endl<<
49 " -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<<
50 " -help Show this help"<<endl<<endl<<
51 "Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
52}
53
54int main(int argc, char **argv) {
55 int x = 0, y = 0; // default pos of window
56 size_t width = 200, height = 32; // default size of window
57 bool set_height = false, set_width=false; // use height/width of font by default
58 bool set_pos = false; // set position
59 bool antialias = true; // antialias text
60 string fontname; // font name
61 string title("Run program"); // default title
62 string text; // default input text
63 string foreground("black"); // text color
64 string background("white"); // text background color
65 string display_name; // name of the display connection
66 string history_file("~/.fluxbox/fbrun_history"); // command history file
67 // parse arguments
68 for (int i=1; i<argc; i++) {
69 if (strcmp(argv[i], "-font") == 0 && i+1 < argc) {
70 fontname = argv[++i];
71 } else if (strcmp(argv[i], "-title") == 0 && i+1 < argc) {
72 title = argv[++i];
73 } else if (strcmp(argv[i], "-text") == 0 && i+1 < argc) {
74 text = argv[++i];
75 } else if (strcmp(argv[i], "-w") == 0 && i+1 < argc) {
76 width = atoi(argv[++i]);
77 set_width = true;
78 } else if (strcmp(argv[i], "-h") == 0 && i+1 < argc) {
79 height = atoi(argv[++i]);
80 set_height = true; // mark true else the height of font will be used
81 } else if (strcmp(argv[i], "-display") == 0 && i+1 < argc) {
82 display_name = argv[++i];
83 } else if (strcmp(argv[i], "-pos") == 0 && i+2 < argc) {
84 x = atoi(argv[++i]);
85 y = atoi(argv[++i]);
86 set_pos = true;
87 } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) {
88 foreground = argv[++i];
89 } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) {
90 background = argv[++i];
91 } else if (strcmp(argv[i], "-na") == 0) {
92 antialias = false;
93 } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) {
94 history_file = argv[++i];
95 } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
96 showUsage(argv[0]);
97 exit(0);
98 } else {
99 cerr<<"Invalid argument: "<<argv[i]<<endl;
100 showUsage(argv[0]);
101 exit(0);
102 }
103
104 }
105
106 try {
107
108 FbTk::App application(display_name.c_str());
109 FbRun fbrun;
110
111 fbrun.setAntialias(antialias);
112
113 if (fontname.size() != 0) {
114 if (!fbrun.loadFont(fontname.c_str())) {
115 cerr<<"Failed to load font: "<<fontname<<endl;
116 cerr<<"Falling back to \"fixed\""<<endl;
117 }
118 }
119
120 // get color
121 XColor xc_foreground, xc_background;
122 FbTk::Color fg_color(foreground.c_str(), 0);
123 FbTk::Color bg_color(background.c_str(), 0);
124
125 fbrun.setForegroundColor(fg_color);
126 fbrun.setBackgroundColor(bg_color);
127
128 if (set_height)
129 fbrun.resize(fbrun.width(), height);
130 if (set_width)
131 fbrun.resize(width, fbrun.height());
132 if (antialias)
133 fbrun.setAntialias(antialias);
134 // expand and load command history
135 string expanded_filename = FbTk::StringUtil::expandFilename(history_file);
136 if (!fbrun.loadHistory(expanded_filename.c_str()))
137 cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl;
138
139 fbrun.setTitle(title);
140 fbrun.setText(text);
141 fbrun.show();
142
143 if (set_pos)
144 fbrun.move(x, y);
145
146 application.eventLoop();
147
148 } catch (string errstr) {
149 cerr<<"Error: "<<errstr<<endl;
150 }
151}