aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorThomas Lübking <thomas.luebking@gmail.com>2016-07-23 12:35:09 (GMT)
committerThomas Lübking <thomas.luebking@gmail.com>2016-07-23 14:58:04 (GMT)
commit8094f4d1a9b48c1edb8d39386e4788e0eb284ae6 (patch)
tree128727a928f37780b1cc9149156c90bf5b973134 /util
parent0ca5daf997d08b415c7ea9149489ccf3366e3a74 (diff)
downloadfluxbox-8094f4d1a9b48c1edb8d39386e4788e0eb284ae6.zip
fluxbox-8094f4d1a9b48c1edb8d39386e4788e0eb284ae6.tar.bz2
Allow to center fbrun
While any window can be centered using the apps file, fbrun can serve many purposes and sometimes (runner) makes sense being centered, sometimes (button/menu triggered input) near the mouse, sometimes ("application") regularily placed. REQUEST: 282
Diffstat (limited to 'util')
-rw-r--r--util/fbrun/main.cc45
1 files changed, 29 insertions, 16 deletions
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc
index 0bc02c6..4022ef6 100644
--- a/util/fbrun/main.cc
+++ b/util/fbrun/main.cc
@@ -61,6 +61,7 @@ void showUsage(const char *progname) {
61 " -display [display string] Display name"<<endl<< 61 " -display [display string] Display name"<<endl<<
62 " -pos [x] [y] Window position in pixels"<<endl<< 62 " -pos [x] [y] Window position in pixels"<<endl<<
63 " -nearmouse Window position near mouse"<<endl<< 63 " -nearmouse Window position near mouse"<<endl<<
64 " -center Window position on screen center"<<endl<<
64 " -fg [color name] Foreground text color"<<endl<< 65 " -fg [color name] Foreground text color"<<endl<<
65 " -bg [color name] Background color"<<endl<< 66 " -bg [color name] Background color"<<endl<<
66 " -na Disable antialias"<<endl<< 67 " -na Disable antialias"<<endl<<
@@ -77,6 +78,7 @@ int main(int argc, char **argv) {
77 bool set_height = false, set_width=false; // use height/width of font by default 78 bool set_height = false, set_width=false; // use height/width of font by default
78 bool set_pos = false; // set position 79 bool set_pos = false; // set position
79 bool near_mouse = false; // popup near mouse 80 bool near_mouse = false; // popup near mouse
81 bool center = false;
80 bool print = false; 82 bool print = false;
81 bool preselect = false; 83 bool preselect = false;
82 bool autocomplete = getenv("FBRUN_AUTOCOMPLETE"); 84 bool autocomplete = getenv("FBRUN_AUTOCOMPLETE");
@@ -113,6 +115,9 @@ int main(int argc, char **argv) {
113 } else if (arg == "-nearmouse" || arg == "--nearmouse") { 115 } else if (arg == "-nearmouse" || arg == "--nearmouse") {
114 set_pos = true; 116 set_pos = true;
115 near_mouse = true; 117 near_mouse = true;
118 } else if (arg == "-center" || arg == "--center") {
119 set_pos = true;
120 center = true;
116 } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) { 121 } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) {
117 foreground = argv[++i]; 122 foreground = argv[++i];
118 } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) { 123 } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) {
@@ -171,7 +176,7 @@ int main(int argc, char **argv) {
171 if (preselect) 176 if (preselect)
172 fbrun.selectAll(); 177 fbrun.selectAll();
173 178
174 if (near_mouse) { 179 if (near_mouse || center) {
175 180
176 int wx, wy; 181 int wx, wy;
177 unsigned int mask; 182 unsigned int mask;
@@ -179,15 +184,15 @@ int main(int argc, char **argv) {
179 Window child_win; 184 Window child_win;
180 185
181 Display* dpy = FbTk::App::instance()->display(); 186 Display* dpy = FbTk::App::instance()->display();
187 int root_x = 0;
188 int root_y = 0;
189 unsigned int root_w = WidthOfScreen(DefaultScreenOfDisplay(dpy));
190 unsigned int root_h = HeightOfScreen(DefaultScreenOfDisplay(dpy));
182 191
183 if (XQueryPointer(dpy, DefaultRootWindow(dpy), 192 if (XQueryPointer(dpy, DefaultRootWindow(dpy),
184 &ret_win, &child_win, 193 &ret_win, &child_win,
185 &x, &y, &wx, &wy, &mask)) { 194 &x, &y, &wx, &wy, &mask)) {
186 195
187 int root_x = 0;
188 int root_y = 0;
189 unsigned int root_w = WidthOfScreen(DefaultScreenOfDisplay(dpy));
190 unsigned int root_h = HeightOfScreen(DefaultScreenOfDisplay(dpy));
191#ifdef XINERAMA 196#ifdef XINERAMA
192 if(XineramaIsActive(dpy)) { 197 if(XineramaIsActive(dpy)) {
193 XineramaScreenInfo* screen_info = 0; 198 XineramaScreenInfo* screen_info = 0;
@@ -211,18 +216,26 @@ int main(int argc, char **argv) {
211 } 216 }
212 } 217 }
213#endif // XINERAMA 218#endif // XINERAMA
214 x-= fbrun.width()/2; 219 } else if (!center) {
215 y-= fbrun.height()/2; 220 set_pos = false;
216 221 }
217 if (x < root_x) 222
218 x = root_x; 223 if (center) {
219 if (x + fbrun.width() > root_x + root_w) 224 x = root_x + root_w/2;
220 x = root_x + root_w - fbrun.width(); 225 y = root_y + root_h/2;
221 if (y < root_y)
222 y = root_y;
223 if (y + fbrun.height() > root_y + root_h)
224 y = root_y + root_h - fbrun.height();
225 } 226 }
227
228 x-= fbrun.width()/2;
229 y-= fbrun.height()/2;
230
231 if (x < root_x)
232 x = root_x;
233 if (x + fbrun.width() > root_x + root_w)
234 x = root_x + root_w - fbrun.width();
235 if (y < root_y)
236 y = root_y;
237 if (y + fbrun.height() > root_y + root_h)
238 y = root_y + root_h - fbrun.height();
226 } 239 }
227 240
228 if (set_pos) 241 if (set_pos)