From 8094f4d1a9b48c1edb8d39386e4788e0eb284ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sat, 23 Jul 2016 14:35:09 +0200 Subject: [PATCH] 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 --- doc/asciidoc/fbrun.txt | 3 +++ util/fbrun/main.cc | 45 +++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/doc/asciidoc/fbrun.txt b/doc/asciidoc/fbrun.txt index ee09d6da..113f79ea 100644 --- a/doc/asciidoc/fbrun.txt +++ b/doc/asciidoc/fbrun.txt @@ -54,6 +54,9 @@ OPTIONS *-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* diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc index 0bc02c67..4022ef69 100644 --- a/util/fbrun/main.cc +++ b/util/fbrun/main.cc @@ -61,6 +61,7 @@ void showUsage(const char *progname) { " -display [display string] Display name"<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 @@ int main(int argc, char **argv) { } } #endif // XINERAMA - 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(); + } else if (!center) { + set_pos = false; } + + 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)