all repos — fluxbox @ 8094f4d1a9b48c1edb8d39386e4788e0eb284ae6

custom fork of the fluxbox windowmanager

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
Thomas Lübking thomas.luebking@gmail.com
commit

8094f4d1a9b48c1edb8d39386e4788e0eb284ae6

parent

0ca5daf997d08b415c7ea9149489ccf3366e3a74

2 files changed, 31 insertions(+), 15 deletions(-)

jump to
M doc/asciidoc/fbrun.txtdoc/asciidoc/fbrun.txt

@@ -54,6 +54,9 @@

*-nearmouse*:: Position the window under the mouse cursor +*-center*:: + Position the window on the screen center + *-fg* 'color':: Foreground text color. The default is *black*
M util/fbrun/main.ccutil/fbrun/main.cc

@@ -61,6 +61,7 @@ " -h [height] Window height in pixels"<<endl<<

" -display [display string] Display name"<<endl<< " -pos [x] [y] Window position in pixels"<<endl<< " -nearmouse Window position near mouse"<<endl<< + " -center Window position on screen center"<<endl<< " -fg [color name] Foreground text color"<<endl<< " -bg [color name] Background color"<<endl<< " -na Disable antialias"<<endl<<

@@ -77,6 +78,7 @@ size_t width = 200, height = 32; // default size of window

bool set_height = false, set_width=false; // use height/width of font by default bool set_pos = false; // set position bool near_mouse = false; // popup near mouse + bool center = false; bool print = false; bool preselect = false; bool autocomplete = getenv("FBRUN_AUTOCOMPLETE");

@@ -113,6 +115,9 @@ set_pos = true;

} else if (arg == "-nearmouse" || arg == "--nearmouse") { set_pos = true; near_mouse = true; + } else if (arg == "-center" || arg == "--center") { + set_pos = true; + center = true; } else if (strcmp(argv[i], "-fg") == 0 && i+1 < argc) { foreground = argv[++i]; } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) {

@@ -171,7 +176,7 @@ fbrun.setText(text);

if (preselect) fbrun.selectAll(); - if (near_mouse) { + if (near_mouse || center) { int wx, wy; unsigned int mask;

@@ -179,15 +184,15 @@ Window ret_win;

Window child_win; Display* dpy = FbTk::App::instance()->display(); + int root_x = 0; + int root_y = 0; + unsigned int root_w = WidthOfScreen(DefaultScreenOfDisplay(dpy)); + unsigned int root_h = HeightOfScreen(DefaultScreenOfDisplay(dpy)); if (XQueryPointer(dpy, DefaultRootWindow(dpy), &ret_win, &child_win, &x, &y, &wx, &wy, &mask)) { - int root_x = 0; - int root_y = 0; - unsigned int root_w = WidthOfScreen(DefaultScreenOfDisplay(dpy)); - unsigned int root_h = HeightOfScreen(DefaultScreenOfDisplay(dpy)); #ifdef XINERAMA if(XineramaIsActive(dpy)) { XineramaScreenInfo* screen_info = 0;

@@ -211,18 +216,26 @@ XFree(screen_info);

} } #endif // XINERAMA - x-= fbrun.width()/2; - y-= fbrun.height()/2; + } else if (!center) { + set_pos = false; + } - if (x < root_x) - x = root_x; - if (x + fbrun.width() > root_x + root_w) - x = root_x + root_w - fbrun.width(); - if (y < root_y) - y = root_y; - if (y + fbrun.height() > root_y + root_h) - y = root_y + root_h - fbrun.height(); + if (center) { + x = root_x + root_w/2; + y = root_y + root_h/2; } + + x-= fbrun.width()/2; + y-= fbrun.height()/2; + + if (x < root_x) + x = root_x; + if (x + fbrun.width() > root_x + root_w) + x = root_x + root_w - fbrun.width(); + if (y < root_y) + y = root_y; + if (y + fbrun.height() > root_y + root_h) + y = root_y + root_h - fbrun.height(); } if (set_pos)