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.cc163
1 files changed, 163 insertions, 0 deletions
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc
new file mode 100644
index 0000000..d04b4a0
--- /dev/null
+++ b/util/fbrun/main.cc
@@ -0,0 +1,163 @@
1// main.cc for FbRun
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen@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.1 2002/08/20 02:04:34 fluxgen Exp $
23
24#include "FbRun.hh"
25
26#include <string>
27#include <iostream>
28using namespace std;
29
30void showUsage(const char *progname) {
31 cerr<<"fbrun 1.1.0 : (c) 2002 Henrik Kinnunen"<<endl;
32 cerr<<"Usage: "<<
33 progname<<" [arguments]"<<endl<<
34 "Arguments: "<<endl<<
35 " -font [font name] Text font"<<endl<<
36 " -title [title name] Set title"<<endl<<
37 " -text [text] Text input"<<endl<<
38 " -w [width] Window width in pixels"<<endl<<
39 " -h [height] Window height in pixels"<<endl<<
40 " -display [display string] Display name"<<endl<<
41 " -pos [x] [y] Window position in pixels"<<endl<<
42 " -fg [color name] Foreground text color"<<endl<<
43 " -bg [color name] Background color"<<endl<<
44 " -help Show this help"<<endl<<endl<<
45 "Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
46}
47
48int main(int argc, char **argv) {
49 int x = 0, y = 0; // default pos of window
50 size_t width = 200, height = 32; // default size of window
51 bool set_height = false; // use height of font by default
52 bool set_pos = false; // set position
53 string fontname; // font name
54 string title("Run program"); // default title
55 string text; // default input text
56 string foreground("black"); // text color
57 string background("white"); // text background color
58 string display_name; // name of the display connection
59
60 // parse arguments
61 for (int i=1; i<argc; i++) {
62 if (strcmp(argv[i], "-font") == 0 && i+1 < argc) {
63 ++i;
64 fontname = argv[i];
65 } else if (strcmp(argv[i], "-title") == 0 && i+1 < argc) {
66 ++i;
67 title = argv[i];
68 } else if (strcmp(argv[i], "-text") == 0 && i+1 < argc) {
69 ++i;
70 text = argv[i];
71 } else if (strcmp(argv[i], "-w") == 0 && i+1 < argc) {
72 ++i;
73 width = atoi(argv[i]);
74 } else if (strcmp(argv[i], "-h") == 0 && i+1 < argc) {
75 ++i;
76 height = atoi(argv[i]);
77 set_height = true; // mark true else the height of font will be used
78 } else if (strcmp(argv[i], "-display") == 0 && i+1 < argc) {
79 ++i;
80 display_name = argv[i];
81 } else if (strcmp(argv[i], "-pos") == 0 && i+2 < argc) {
82 ++i;
83 x = atoi(argv[i]);
84 ++i;
85 y = atoi(argv[i]);
86 set_pos = true;
87 } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) {
88 ++i;
89 foreground = argv[i];
90 } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) {
91 ++i;
92 background = argv[i];
93 } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
94 showUsage(argv[0]);
95 exit(0);
96 } else {
97 cerr<<"Invalid argument: "<<argv[i]<<endl;
98 showUsage(argv[0]);
99 exit(0);
100 }
101
102 }
103
104 try {
105
106 Display *disp = 0;
107
108 // establish display connection
109 disp = XOpenDisplay(display_name.c_str());
110 if (disp == 0)
111 throw string("Can't open display: " + display_name);
112
113 FbRun fbrun(disp);
114 if (fontname.size() != 0) {
115 if (!fbrun.loadFont(fontname.c_str())) {
116 cerr<<"Failed to load font: "<<fontname<<endl;
117 cerr<<"Falling back to \"fixed\""<<endl;
118 }
119 }
120
121 // get color
122 XColor xc_foreground, xc_background;
123 if (XParseColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
124 foreground.c_str(),
125 &xc_foreground) == 0) {
126 cerr<<"Faild to lookup color: "<<foreground<<endl;
127 }
128
129 if (XParseColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
130 background.c_str(),
131 &xc_background) == 0) {
132 cerr<<"Faild to lookup color: "<<background<<endl;
133 }
134
135 XAllocColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
136 &xc_foreground);
137 XAllocColor(disp, DefaultColormap(disp, DefaultScreen(disp)),
138 &xc_background);
139
140 fbrun.setForeground(xc_foreground);
141 fbrun.setBackground(xc_background);
142
143 if (set_height)
144 fbrun.resize(width, height);
145
146 fbrun.setTitle(title);
147 fbrun.setText(text);
148 fbrun.show();
149
150 if (set_pos)
151 fbrun.move(x, y);
152
153 XEvent event;
154 // main loop
155 while (!fbrun.end()) {
156 XNextEvent(disp, &event);
157 fbrun.handleEvent(&event);
158 }
159
160 } catch (string errstr) {
161 cerr<<"Error: "<<errstr<<endl;
162 }
163}