X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FBaseDisplay.cc;h=aa2d974ee83b2ef17e0f2b356d9e26e3caefc3e4;hb=6954842d84539c1b345d575a39c5dbd5ab0a1227;hp=6726cbace53068a4af16709b14b4b67127364771;hpb=8794d357e67abddf9fda9db77b235e294d0ec590;p=chaz%2Fopenbox diff --git a/src/BaseDisplay.cc b/src/BaseDisplay.cc index 6726cbac..aa2d974e 100644 --- a/src/BaseDisplay.cc +++ b/src/BaseDisplay.cc @@ -78,7 +78,7 @@ extern "C" { #endif // HAVE_SYS_WAIT_H } -#include +#include using std::string; #include "i18n.hh" @@ -91,12 +91,11 @@ using std::string; // X error handler to handle any and all X errors while the application is // running static bool internal_error = False; -static Window last_bad_window = None; BaseDisplay *base_display; -#ifdef DEBUG static int handleXErrors(Display *d, XErrorEvent *e) { +#ifdef DEBUG char errtxt[128]; XGetErrorText(d, e->error_code, errtxt, 128); @@ -106,10 +105,11 @@ static int handleXErrors(Display *d, XErrorEvent *e) { base_display->getApplicationName(), errtxt, e->error_code, e->request_code, e->minor_code, e->resourceid); #else -static int handleXErrors(Display *, XErrorEvent *e) { + // shutup gcc + (void) d; + (void) e; #endif // DEBUG - if (e->error_code == BadWindow) last_bad_window = e->resourceid; if (internal_error) abort(); return(False); @@ -179,7 +179,6 @@ BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name) { application_name = app_name; run_state = STARTUP; - last_bad_window = None; ::base_display = this; @@ -239,6 +238,7 @@ BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name) { for (int i = 0; i < ScreenCount(display); ++i) screenInfoList.push_back(ScreenInfo(this, i)); +#ifndef NOCLOBBER NumLockMask = ScrollLockMask = 0; const XModifierKeymap* const modmap = XGetModifierMapping(display); @@ -276,6 +276,10 @@ BaseDisplay::BaseDisplay(const char *app_name, const char *dpy_name) { MaskListLength = sizeof(MaskList) / sizeof(MaskList[0]); if (modmap) XFreeModifiermap(const_cast(modmap)); +#else // NOCLOBBER + NumLockMask = 0; + ScrollLockMask = 0; +#endif // NOCLOBBER gccache = 0; } @@ -297,11 +301,6 @@ void BaseDisplay::eventLoop(void) { if (XPending(display)) { XEvent e; XNextEvent(display, &e); - - if (last_bad_window != None && e.xany.window == last_bad_window) - continue; - - last_bad_window = None; process_event(&e); } else { fd_set rfds; @@ -366,11 +365,16 @@ void BaseDisplay::grabButton(unsigned int button, unsigned int modifiers, unsigned int event_mask, int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor) const { - for (size_t cnt = 0; cnt < MaskListLength; ++cnt) { +#ifndef NOCLOBBER + for (size_t cnt = 0; cnt < MaskListLength; ++cnt) XGrabButton(display, button, modifiers | MaskList[cnt], grab_window, owner_events, event_mask, pointer_mode, keyboard_mode, confine_to, cursor); - } +#else // NOCLOBBER + XGrabButton(display, button, modifiers, grab_window, + owner_events, event_mask, pointer_mode, keyboard_mode, + confine_to, cursor); +#endif // NOCLOBBER } /* @@ -379,9 +383,12 @@ void BaseDisplay::grabButton(unsigned int button, unsigned int modifiers, */ void BaseDisplay::ungrabButton(unsigned int button, unsigned int modifiers, Window grab_window) const { - for (size_t cnt = 0; cnt < MaskListLength; ++cnt) { +#ifndef NOCLOBBER + for (size_t cnt = 0; cnt < MaskListLength; ++cnt) XUngrabButton(display, button, modifiers | MaskList[cnt], grab_window); - } +#else // NOCLOBBER + XUngrabButton(display, button, modifiers, grab_window); +#endif // NOCLOBBER } @@ -404,43 +411,55 @@ ScreenInfo::ScreenInfo(BaseDisplay *d, unsigned int num) { screen_number = num; root_window = RootWindow(basedisplay->getXDisplay(), screen_number); - depth = DefaultDepth(basedisplay->getXDisplay(), screen_number); rect.setSize(WidthOfScreen(ScreenOfDisplay(basedisplay->getXDisplay(), screen_number)), HeightOfScreen(ScreenOfDisplay(basedisplay->getXDisplay(), screen_number))); + /* + If the default depth is at least 8 we will use that, + otherwise we try to find the largest TrueColor visual. + Preference is given to 24 bit over larger depths if 24 bit is an option. + */ - // 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; - - vinfo_template.screen = screen_number; - vinfo_template.c_class = TrueColor; - - visual = (Visual *) 0; - - vinfo_return = XGetVisualInfo(basedisplay->getXDisplay(), - VisualScreenMask | VisualClassMask, - &vinfo_template, &vinfo_nitems); - if (vinfo_return && 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; + depth = DefaultDepth(basedisplay->getXDisplay(), screen_number); + visual = DefaultVisual(basedisplay->getXDisplay(), screen_number); + colormap = DefaultColormap(basedisplay->getXDisplay(), screen_number); + + if (depth < 8) { + // 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; + int best = -1; + + vinfo_template.screen = screen_number; + vinfo_template.c_class = TrueColor; + + vinfo_return = XGetVisualInfo(basedisplay->getXDisplay(), + VisualScreenMask | VisualClassMask, + &vinfo_template, &vinfo_nitems); + if (vinfo_return) { + int max_depth = 1; + for (int i = 0; i < vinfo_nitems; ++i) { + if (vinfo_return[i].depth > max_depth) { + if (max_depth == 24 && vinfo_return[i].depth > 24) + break; // prefer 24 bit over 32 + max_depth = vinfo_return[i].depth; + best = i; + } } + if (max_depth < depth) best = -1; } - XFree(vinfo_return); - } + if (best != -1) { + depth = vinfo_return[best].depth; + visual = vinfo_return[best].visual; + colormap = XCreateColormap(basedisplay->getXDisplay(), root_window, + visual, AllocNone); + } - if (visual) { - colormap = XCreateColormap(basedisplay->getXDisplay(), root_window, - visual, AllocNone); - } else { - visual = DefaultVisual(basedisplay->getXDisplay(), screen_number); - colormap = DefaultColormap(basedisplay->getXDisplay(), screen_number); + XFree(vinfo_return); } // get the default display string and strip the screen number @@ -449,7 +468,6 @@ ScreenInfo::ScreenInfo(BaseDisplay *d, unsigned int num) { if (pos != string::npos) default_string.resize(pos); - std::ostringstream formatter; - formatter << "DISPLAY=" << default_string << '.' << screen_number; - display_string = formatter.str(); + display_string = string("DISPLAY=") + default_string + '.' + + itostring(static_cast(screen_number)); }