From a4d46a4cac23f8fdf45443770e2d6866e32fca80 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Thu, 9 Jan 2003 21:55:58 +0000 Subject: removed bexec and fixed indent --- src/BaseDisplay.cc | 506 ++++++++++++++++++++++++++--------------------------- 1 file changed, 247 insertions(+), 259 deletions(-) diff --git a/src/BaseDisplay.cc b/src/BaseDisplay.cc index f10180f..0711d15 100644 --- a/src/BaseDisplay.cc +++ b/src/BaseDisplay.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: BaseDisplay.cc,v 1.25 2002/12/02 20:02:56 fluxgen Exp $ +// $Id: BaseDisplay.cc,v 1.26 2003/01/09 21:55:58 fluxgen Exp $ @@ -74,14 +74,14 @@ #endif // SA_INTERRUPT #endif // SA_NODEFER -#ifdef HAVE_SYS_WAIT_H +#ifdef HAVE_SYS_WAIT_H #include #include #endif // HAVE_SYS_WAIT_H #if defined(HAVE_PROCESS_H) && defined(__EMX__) #include -#endif // HAVE_PROCESS_H && __EMX__ +#endif // HAVE_PROCESS_H && __EMX__ #include using namespace std; @@ -91,367 +91,355 @@ using namespace std; static Bool internal_error = False; static Window last_bad_window = None; -#ifdef DEBUG + static int handleXErrors(Display *d, XErrorEvent *e) { +#ifdef DEBUG char errtxt[128]; XGetErrorText(d, e->error_code, errtxt, 128); fprintf(stderr, I18n::instance()-> getMessage( - FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXError, - "%s: X error: %s(%d) opcodes %d/%d\n resource 0x%lx\n"), + FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXError, + "%s: X error: %s(%d) opcodes %d/%d\n resource 0x%lx\n"), BaseDisplay::instance()->getApplicationName(), errtxt, e->error_code, e->request_code, e->minor_code, e->resourceid); -#else // !DEBUG - static int handleXErrors(Display *, XErrorEvent *e) { -#endif // DEBUG +#endif // !DEBUG - if (e->error_code == BadWindow) - last_bad_window = e->resourceid; + if (e->error_code == BadWindow) + last_bad_window = e->resourceid; - if (internal_error) - abort(); + if (internal_error) + abort(); - return(False); - } + return(False); +} -// convenience functions -#ifndef __EMX__ - void bexec(const char *command, char *displaystring) { - if (! fork()) { - setsid(); - putenv(displaystring); - execl("/bin/sh", "/bin/sh", "-c", command, 0); - exit(0); - } - } -#endif // !__EMX__ - BaseDisplay *BaseDisplay::s_singleton = 0; +BaseDisplay *BaseDisplay::s_singleton = 0; - BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name):FbTk::App(dpy_name), - m_startup(true), m_shutdown(false), - m_display_name(XDisplayName(dpy_name)), m_app_name(app_name), - m_server_grabs(0) - { - if (s_singleton != 0) - throw string("Can't create more than one instance of BaseDisplay!"); +BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name):FbTk::App(dpy_name), + m_startup(true), m_shutdown(false), + m_display_name(XDisplayName(dpy_name)), m_app_name(app_name), + m_server_grabs(0) +{ + if (s_singleton != 0) + throw string("Can't create more than one instance of BaseDisplay!"); - s_singleton = this; + s_singleton = this; - last_bad_window = None; - I18n *i18n = I18n::instance(); - - if (display() == 0) { - throw string( - i18n-> - getMessage( - FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXConnectFail, - "BaseDisplay::BaseDisplay: connection to X server failed.")); + last_bad_window = None; + I18n *i18n = I18n::instance(); + + if (display() == 0) { + throw string( + i18n-> + getMessage( + FBNLS::BaseDisplaySet, FBNLS::BaseDisplayXConnectFail, + "BaseDisplay::BaseDisplay: connection to X server failed.")); - } else if (fcntl(ConnectionNumber(display()), F_SETFD, 1) == -1) { - throw string( - i18n-> - getMessage( - FBNLS::BaseDisplaySet, FBNLS::BaseDisplayCloseOnExecFail, - "BaseDisplay::BaseDisplay: couldn't mark display connection " - "as close-on-exec")); + } else if (fcntl(ConnectionNumber(display()), F_SETFD, 1) == -1) { + throw string( + i18n-> + getMessage( + FBNLS::BaseDisplaySet, FBNLS::BaseDisplayCloseOnExecFail, + "BaseDisplay::BaseDisplay: couldn't mark display connection " + "as close-on-exec")); - } + } - number_of_screens = ScreenCount(display()); + number_of_screens = ScreenCount(display()); #ifdef SHAPE - shape.extensions = XShapeQueryExtension(display(), &shape.event_basep, - &shape.error_basep); + shape.extensions = XShapeQueryExtension(display(), &shape.event_basep, + &shape.error_basep); #else // !SHAPE - shape.extensions = False; + shape.extensions = False; #endif // SHAPE - XSetErrorHandler((XErrorHandler) handleXErrors); + XSetErrorHandler((XErrorHandler) handleXErrors); - for (int i = 0; i < number_of_screens; i++) { - ScreenInfo *screeninfo = new ScreenInfo(i); - screenInfoList.push_back(screeninfo); - } - } + for (int i = 0; i < number_of_screens; i++) { + ScreenInfo *screeninfo = new ScreenInfo(i); + screenInfoList.push_back(screeninfo); + } +} - BaseDisplay::~BaseDisplay() { +BaseDisplay::~BaseDisplay() { - ScreenInfoList::iterator it = screenInfoList.begin(); - ScreenInfoList::iterator it_end = screenInfoList.end(); - for (; it != it_end; ++it) { - delete (*it); - } - - s_singleton = 0; + ScreenInfoList::iterator it = screenInfoList.begin(); + ScreenInfoList::iterator it_end = screenInfoList.end(); + for (; it != it_end; ++it) { + delete (*it); } + + s_singleton = 0; +} - BaseDisplay *BaseDisplay::instance() { - if (s_singleton == 0) - throw string("BaseDisplay not created!"); +BaseDisplay *BaseDisplay::instance() { + if (s_singleton == 0) + throw string("BaseDisplay not created!"); - return s_singleton; - } + return s_singleton; +} - void BaseDisplay::eventLoop() { - run(); +void BaseDisplay::eventLoop() { + run(); - while ((! m_shutdown) && (! internal_error)) { - if (XPending(display())) { - XEvent e; - XNextEvent(display(), &e); + while ((! m_shutdown) && (! internal_error)) { + if (XPending(display())) { + XEvent e; + XNextEvent(display(), &e); - if (last_bad_window != None && e.xany.window == last_bad_window) { + if (last_bad_window != None && e.xany.window == last_bad_window) { #ifdef DEBUG - fprintf(stderr, - I18n::instance()-> - getMessage( - FBNLS::BaseDisplaySet, FBNLS::BaseDisplayBadWindowRemove, - "BaseDisplay::eventLoop(): removing bad window " - "from event queue\n")); + fprintf(stderr, + I18n::instance()-> + getMessage( + FBNLS::BaseDisplaySet, FBNLS::BaseDisplayBadWindowRemove, + "BaseDisplay::eventLoop(): removing bad window " + "from event queue\n")); #endif // DEBUG - } else { - last_bad_window = None; - handleEvent(&e); - } } else { - BTimer::updateTimers(ConnectionNumber(display())); //handle all timers + last_bad_window = None; + handleEvent(&e); } - } + } else { + FbTk::Timer::updateTimers(ConnectionNumber(display())); //handle all timers + } } +} - bool BaseDisplay::validateWindow(Window window) { - XEvent event; - if (XCheckTypedWindowEvent(display(), window, DestroyNotify, &event)) { - XPutBackEvent(display(), &event); - return false; - } - - return true; +bool BaseDisplay::validateWindow(Window window) { + XEvent event; + if (XCheckTypedWindowEvent(display(), window, DestroyNotify, &event)) { + XPutBackEvent(display(), &event); + return false; } + return true; +} - void BaseDisplay::grab() { - if (! m_server_grabs++) - XGrabServer(display()); - } +void BaseDisplay::grab() { + if (! m_server_grabs++) + XGrabServer(display()); +} - void BaseDisplay::ungrab() { - if (! --m_server_grabs) - XUngrabServer(display()); - if (m_server_grabs < 0) - m_server_grabs = 0; - } - ScreenInfo::ScreenInfo(int num) { - basedisplay = BaseDisplay::instance(); - Display * const disp = basedisplay->getXDisplay(); - screen_number = num; +void BaseDisplay::ungrab() { + if (! --m_server_grabs) + XUngrabServer(display()); + if (m_server_grabs < 0) + m_server_grabs = 0; +} - root_window = RootWindow(disp, screen_number); - depth = DefaultDepth(disp, screen_number); +ScreenInfo::ScreenInfo(int num) { + basedisplay = BaseDisplay::instance(); + Display * const disp = basedisplay->getXDisplay(); + screen_number = num; - width = - WidthOfScreen(ScreenOfDisplay(disp, screen_number)); - height = - HeightOfScreen(ScreenOfDisplay(disp, screen_number)); + root_window = RootWindow(disp, screen_number); + depth = DefaultDepth(disp, screen_number); - // search for a TrueColor Visual... if we can't find one... we will use the - // default visual for the screen - XVisualInfo vinfo_template, *vinfo_return; - int vinfo_nitems; + width = + WidthOfScreen(ScreenOfDisplay(disp, screen_number)); + height = + HeightOfScreen(ScreenOfDisplay(disp, screen_number)); - vinfo_template.screen = screen_number; - vinfo_template.c_class = TrueColor; + // search for a TrueColor Visual... if we can't find one... we will use the + // default visual for the screen + XVisualInfo vinfo_template, *vinfo_return; + int vinfo_nitems; - visual = (Visual *) 0; + vinfo_template.screen = screen_number; + vinfo_template.c_class = TrueColor; - if ((vinfo_return = XGetVisualInfo(disp, - VisualScreenMask | VisualClassMask, - &vinfo_template, &vinfo_nitems)) && - vinfo_nitems > 0) { + visual = (Visual *) 0; + + if ((vinfo_return = XGetVisualInfo(disp, + VisualScreenMask | VisualClassMask, + &vinfo_template, &vinfo_nitems)) && + vinfo_nitems > 0) { - for (int i = 0; i < vinfo_nitems; i++) { - if (depth < (vinfo_return + i)->depth) { - depth = (vinfo_return + i)->depth; - visual = (vinfo_return + i)->visual; - } + for (int i = 0; i < vinfo_nitems; i++) { + if (depth < (vinfo_return + i)->depth) { + depth = (vinfo_return + i)->depth; + visual = (vinfo_return + i)->visual; } + } - XFree(vinfo_return); - } + XFree(vinfo_return); + } - if (visual) { - m_colormap = XCreateColormap(disp, root_window, - visual, AllocNone); - } else { - visual = DefaultVisual(disp, screen_number); - m_colormap = DefaultColormap(disp, screen_number); - } + if (visual) { + m_colormap = XCreateColormap(disp, root_window, + visual, AllocNone); + } else { + visual = DefaultVisual(disp, screen_number); + m_colormap = DefaultColormap(disp, screen_number); + } #ifdef XINERAMA - // check if we have Xinerama extension enabled - if (XineramaIsActive(disp)) { - m_hasXinerama = true; - xineramaLastHead = 0; - xineramaInfos = - XineramaQueryScreens(disp, &xineramaNumHeads); - } else { - m_hasXinerama = false; - xineramaInfos = 0; // make sure we don't point anywhere we shouldn't - } -#endif // XINERAMA + // check if we have Xinerama extension enabled + if (XineramaIsActive(disp)) { + m_hasXinerama = true; + xineramaLastHead = 0; + xineramaInfos = + XineramaQueryScreens(disp, &xineramaNumHeads); + } else { + m_hasXinerama = false; + xineramaInfos = 0; // make sure we don't point anywhere we shouldn't } +#endif // XINERAMA +} - ScreenInfo::~ScreenInfo() { +ScreenInfo::~ScreenInfo() { #ifdef XINERAMA - if (m_hasXinerama) { // only free if we first had it - XFree(xineramaInfos); - xineramaInfos = 0; - } -#endif // XINERAMA + if (m_hasXinerama) { // only free if we first had it + XFree(xineramaInfos); + xineramaInfos = 0; } +#endif // XINERAMA +} #ifdef XINERAMA -//---------------- getHead --------------- -// Searches for the head at the coordinates -// x,y. If it fails or Xinerama isn't -// activated it'll return head nr 0 -//----------------------------------------- - unsigned int ScreenInfo::getHead(int x, int y) const { - - // is Xinerama extensions enabled? - if (hasXinerama()) { - // check if last head is still active -/* if ((xineramaInfos[xineramaLastHead].x_org <= x) && - ((xineramaInfos[xineramaLastHead].x_org + - xineramaInfos[xineramaLastHead].width) > x) && - (xineramaInfos[xineramaLastHead].y_org <= y) && - ((xineramaInfos[xineramaLastHead].y_org + - xineramaInfos[xineramaLastHead].height) > y)) { - return xineramaLastHead; - } else { */ - // go trough all the heads, and search - for (int i = 0; (signed) i < xineramaNumHeads; i++) { - if (xineramaInfos[i].x_org <= x && - (xineramaInfos[i].x_org + xineramaInfos[i].width) > x && - xineramaInfos[i].y_org <= y && - (xineramaInfos[i].y_org + xineramaInfos[i].height) > y) - // return (xineramaLastHead = i); - return i; - } - // } - } - - return 0; +/** + Searches for the head at the coordinates + x,y. If it fails or Xinerama isn't + activated it'll return head nr 0 +*/ +unsigned int ScreenInfo::getHead(int x, int y) const { + + // is Xinerama extensions enabled? + if (hasXinerama()) { + // check if last head is still active + /* if ((xineramaInfos[xineramaLastHead].x_org <= x) && + ((xineramaInfos[xineramaLastHead].x_org + + xineramaInfos[xineramaLastHead].width) > x) && + (xineramaInfos[xineramaLastHead].y_org <= y) && + ((xineramaInfos[xineramaLastHead].y_org + + xineramaInfos[xineramaLastHead].height) > y)) { + return xineramaLastHead; + } else { */ + // go trough all the heads, and search + for (int i = 0; (signed) i < xineramaNumHeads; i++) { + if (xineramaInfos[i].x_org <= x && + (xineramaInfos[i].x_org + xineramaInfos[i].width) > x && + xineramaInfos[i].y_org <= y && + (xineramaInfos[i].y_org + xineramaInfos[i].height) > y) + // return (xineramaLastHead = i); + return i; + } + // } } -//------------- getCurrHead -------------- -// Searches for the head that the pointer -// currently is on, if it isn't found -// the first one is returned -//---------------------------------------- - unsigned int ScreenInfo::getCurrHead(void) const { - - // is Xinerama extensions enabled? - if (hasXinerama()) { - int x, y, wX, wY; - unsigned int mask; - Window rRoot, rChild; - // get pointer cordinates - if ( (XQueryPointer(basedisplay->getXDisplay(), root_window, - &rRoot, &rChild, &x, &y, &wX, &wY, &mask)) != 0 ) { - return getHead(x, y); - } - } - - return 0; + return 0; +} + +/** + Searches for the head that the pointer + currently is on, if it isn't found + the first one is returned +*/ +unsigned int ScreenInfo::getCurrHead(void) const { + + // is Xinerama extensions enabled? + if (hasXinerama()) { + int x, y, wX, wY; + unsigned int mask; + Window rRoot, rChild; + // get pointer cordinates + if ( (XQueryPointer(basedisplay->getXDisplay(), root_window, + &rRoot, &rChild, &x, &y, &wX, &wY, &mask)) != 0 ) { + return getHead(x, y); + } } + return 0; +} + //----------- getHeadWidth ------------ // Returns the width of head //------------------------------------- - unsigned int ScreenInfo::getHeadWidth(unsigned int head) const { +unsigned int ScreenInfo::getHeadWidth(unsigned int head) const { - if (hasXinerama()) { - if ((signed) head >= xineramaNumHeads) { + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { #ifdef DEBUG - cerr << __FILE__ << ":" <<__LINE__ << ": " << - "Head: " << head << " doesn't exist!" << endl; + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; #endif // DEBUG - return xineramaInfos[xineramaNumHeads - 1].width; - } else - return xineramaInfos[head].width; - } + return xineramaInfos[xineramaNumHeads - 1].width; + } else + return xineramaInfos[head].width; + } - return getWidth(); + return getWidth(); - } +} //----------- getHeadHeight ------------ // Returns the heigt of head //-------------------------------------- - unsigned int ScreenInfo::getHeadHeight(unsigned int head) const { +unsigned int ScreenInfo::getHeadHeight(unsigned int head) const { - if (hasXinerama()) { - if ((signed) head >= xineramaNumHeads) { + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { #ifdef DEBUG - cerr << __FILE__ << ":" <<__LINE__ << ": " << - "Head: " << head << " doesn't exist!" << endl; + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; #endif // DEBUG - return xineramaInfos[xineramaNumHeads - 1].height; - } else - return xineramaInfos[head].height; - } - - return getHeight(); + return xineramaInfos[xineramaNumHeads - 1].height; + } else + return xineramaInfos[head].height; } + return getHeight(); +} + //----------- getHeadX ----------------- // Returns the X start of head nr head //-------------------------------------- - int ScreenInfo::getHeadX(unsigned int head) const { - if (hasXinerama()) { - if ((signed) head >= xineramaNumHeads) { +int ScreenInfo::getHeadX(unsigned int head) const { + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { #ifdef DEBUG - cerr << __FILE__ << ":" <<__LINE__ << ": " << - "Head: " << head << " doesn't exist!" << endl; + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; #endif // DEBUG - return xineramaInfos[head = xineramaNumHeads - 1].x_org; - } else - return xineramaInfos[head].x_org; - } - - return 0; + return xineramaInfos[head = xineramaNumHeads - 1].x_org; + } else + return xineramaInfos[head].x_org; } + return 0; +} + //----------- getHeadY ----------------- // Returns the Y start of head //-------------------------------------- - int ScreenInfo::getHeadY(unsigned int head) const { - if (hasXinerama()) { - if ((signed) head >= xineramaNumHeads) { +int ScreenInfo::getHeadY(unsigned int head) const { + if (hasXinerama()) { + if ((signed) head >= xineramaNumHeads) { #ifdef DEBUG - cerr << __FILE__ << ":" <<__LINE__ << ": " << - "Head: " << head << " doesn't exist!" << endl; + cerr << __FILE__ << ":" <<__LINE__ << ": " << + "Head: " << head << " doesn't exist!" << endl; #endif // DEBUG - return xineramaInfos[xineramaNumHeads - 1].y_org; - } else - return xineramaInfos[head].y_org; - } - - return 0; + return xineramaInfos[xineramaNumHeads - 1].y_org; + } else + return xineramaInfos[head].y_org; } + return 0; +} + #endif // XINERAMA -- cgit v0.11.2