2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
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:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
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.
22
// $Id: main.cc 4043 2005-06-03 07:25:48Z mathias $
26
#include "StringUtil.hh"
31
#include <X11/extensions/Xinerama.h>
40
void showUsage(const char *progname) {
41
cerr<<"fbrun 1.5 : (c) 2002-2004 Henrik Kinnunen"<<endl;
43
progname<<" [arguments]"<<endl<<
45
" -font [font name] Text font"<<endl<<
46
" -title [title name] Set title"<<endl<<
47
" -text [text] Text input"<<endl<<
48
" -w [width] Window width in pixels"<<endl<<
49
" -h [height] Window height in pixels"<<endl<<
50
" -display [display string] Display name"<<endl<<
51
" -pos [x] [y] Window position in pixels"<<endl<<
52
" -nearmouse Window position near mouse"<<endl<<
53
" -fg [color name] Foreground text color"<<endl<<
54
" -bg [color name] Background color"<<endl<<
55
" -na Disable antialias"<<endl<<
56
" -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<<
57
" -help Show this help"<<endl<<endl<<
58
"Example: fbrun -fg black -bg white -text xterm -title \"run xterm\""<<endl;
61
int main(int argc, char **argv) {
62
int x = 0, y = 0; // default pos of window
63
size_t width = 200, height = 32; // default size of window
64
bool set_height = false, set_width=false; // use height/width of font by default
65
bool set_pos = false; // set position
66
bool near_mouse = false; // popup near mouse
67
bool antialias = true; // antialias text
68
string fontname; // font name
69
string title("Run program"); // default title
70
string text; // default input text
71
string foreground("black"); // text color
72
string background("white"); // text background color
73
string display_name; // name of the display connection
74
string history_file("~/.fluxbox/fbrun_history"); // command history file
76
for (int i=1; i<argc; i++) {
77
if (strcmp(argv[i], "-font") == 0 && i+1 < argc) {
79
} else if (strcmp(argv[i], "-title") == 0 && i+1 < argc) {
81
} else if (strcmp(argv[i], "-text") == 0 && i+1 < argc) {
83
} else if (strcmp(argv[i], "-w") == 0 && i+1 < argc) {
84
width = atoi(argv[++i]);
86
} else if (strcmp(argv[i], "-h") == 0 && i+1 < argc) {
87
height = atoi(argv[++i]);
88
set_height = true; // mark true else the height of font will be used
89
} else if (strcmp(argv[i], "-display") == 0 && i+1 < argc) {
90
display_name = argv[++i];
91
} else if (strcmp(argv[i], "-pos") == 0 && i+2 < argc) {
95
} else if (strcmp(argv[i], "-nearmouse") == 0) {
98
} else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) {
99
foreground = argv[++i];
100
} else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) {
101
background = argv[++i];
102
} else if (strcmp(argv[i], "-na") == 0) {
104
} else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) {
105
history_file = argv[++i];
106
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
110
cerr<<"Invalid argument: "<<argv[i]<<endl;
119
FbTk::App application(display_name.c_str());
122
//fbrun.setAntialias(antialias);
124
if (fontname.size() != 0) {
125
if (!fbrun.loadFont(fontname.c_str())) {
126
cerr<<"Failed to load font: "<<fontname<<endl;
127
cerr<<"Falling back to \"fixed\""<<endl;
132
XColor xc_foreground, xc_background;
133
FbTk::Color fg_color(foreground.c_str(), 0);
134
FbTk::Color bg_color(background.c_str(), 0);
136
fbrun.setForegroundColor(fg_color);
137
fbrun.setBackgroundColor(bg_color);
140
fbrun.resize(fbrun.width(), height);
142
fbrun.resize(width, fbrun.height());
144
// fbrun.setAntialias(antialias);
145
// expand and load command history
146
string expanded_filename = FbTk::StringUtil::expandFilename(history_file);
147
if (!fbrun.loadHistory(expanded_filename.c_str()))
148
cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl;
150
fbrun.setTitle(title);
160
Display* dpy = FbTk::App::instance()->display();
162
if (XQueryPointer(dpy, DefaultRootWindow(dpy),
163
&ret_win, &child_win,
164
&x, &y, &wx, &wy, &mask)) {
168
unsigned int root_w = WidthOfScreen(DefaultScreenOfDisplay(dpy));
169
unsigned int root_h = HeightOfScreen(DefaultScreenOfDisplay(dpy));
171
if(XineramaIsActive(dpy)) {
172
XineramaScreenInfo* screen_info = 0;
174
screen_info = XineramaQueryScreens(dpy, &number);
176
for(int i= 0; i < number; i++) {
177
if (x >= screen_info[i].x_org &&
178
x < screen_info[i].x_org + screen_info[i].width &&
179
y >= screen_info[i].y_org &&
180
y < screen_info[i].y_org + screen_info[i].height) {
181
root_x = screen_info[i].x_org;
182
root_y = screen_info[i].y_org;
183
root_w = screen_info[i].width;
184
root_h = screen_info[i].height;
194
y-= fbrun.height()/2;
198
if (x + fbrun.width() > root_x + root_w)
199
x = root_x + root_w - fbrun.width();
202
if (y + fbrun.height() > root_y + root_h)
203
y = root_y + root_h - fbrun.height();
212
application.eventLoop();
214
} catch (string errstr) {
215
cerr<<"Error: "<<errstr<<endl;