// main.cc for FbRun // Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #include "FbRun.hh" #include "FbTk/App.hh" #include "FbTk/StringUtil.hh" #include "FbTk/Color.hh" #ifdef XINERAMA extern "C" { #include } #endif // XINERAMA #include #include #ifdef HAVE_CSTRING #include #else #include #endif #ifdef HAVE_CSTDLIB #include #else #include #endif using std::cerr; using std::endl; using std::string; void showUsage(const char *progname) { cerr<<"fbrun 1.5 : (c) 2002-2015 Henrik Kinnunen"<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)) { #ifdef XINERAMA if(XineramaIsActive(dpy)) { XineramaScreenInfo* screen_info = 0; int number = 0; screen_info = XineramaQueryScreens(dpy, &number); if (screen_info) { for(int i= 0; i < number; i++) { if (x >= screen_info[i].x_org && x < screen_info[i].x_org + screen_info[i].width && y >= screen_info[i].y_org && y < screen_info[i].y_org + screen_info[i].height) { root_x = screen_info[i].x_org; root_y = screen_info[i].y_org; root_w = screen_info[i].width; root_h = screen_info[i].height; break; } } XFree(screen_info); } } #endif // XINERAMA } 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) fbrun.move(x, y); fbrun.lockPosition(set_pos); fbrun.show(); application.eventLoop(); } catch (string & errstr) { cerr<<"Error: "<