X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fdisplay.cc;h=9ab8ed2f0b898ab2e8c23aee9e895d8db4120a6f;hb=1e58c863bbaddd2f2dbebfde740ca842e8837a1c;hp=af03801ea761c20a08f6905f1898a790843f9da5;hpb=406c79aea1b6f9c8bd1bbeb253ebc7cb97fc7e25;p=chaz%2Fopenbox diff --git a/otk/display.cc b/otk/display.cc index af03801e..9ab8ed2f 100644 --- a/otk/display.cc +++ b/otk/display.cc @@ -1,8 +1,6 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif +#include "config.h" #include "display.hh" #include "screeninfo.hh" @@ -24,10 +22,6 @@ extern "C" { #include #endif // XINERAMA -#ifdef HAVE_STDIO_H -# include -#endif // HAVE_STDIO_H - #ifdef HAVE_SIGNAL_H # include #endif // HAVE_SIGNAL_H @@ -41,10 +35,12 @@ extern "C" { # include #endif // HAVE_UNISTD_H -#include "gettext.h" +#include "../src/gettext.h" #define _(str) gettext(str) } +#include + namespace otk { @@ -52,21 +48,22 @@ Display *display = (Display*) 0; static int xerrorHandler(::Display *d, XErrorEvent *e) { + if (!display->ignoreErrors()) { #ifdef DEBUG - char errtxt[128]; - - //if (e->error_code != BadWindow) - { - XGetErrorText(d, e->error_code, errtxt, 128); - printf("X Error: %s\n", errtxt); - if (e->error_code != BadWindow) - abort(); - } + char errtxt[128]; + + //if (e->error_code != BadWindow) + { + XGetErrorText(d, e->error_code, errtxt, 127); + printf("X Error: %s\n", errtxt); + if (e->error_code != BadWindow) + abort(); + } #else - (void)d; - (void)e; + (void)d; + (void)e; #endif - + } return false; } @@ -128,16 +125,15 @@ DISPLAY environment variable approriately.\n\n")); #endif // XINERAMA // get lock masks that are defined by the display (not constant) - XModifierKeymap *modmap; - - modmap = XGetModifierMapping(_display); - if (modmap && modmap->max_keypermod > 0) { + _modmap = XGetModifierMapping(_display); + assert(_modmap); + if (_modmap && _modmap->max_keypermod > 0) { const int mask_table[] = { ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask }; const size_t size = (sizeof(mask_table) / sizeof(mask_table[0])) * - modmap->max_keypermod; + _modmap->max_keypermod; // get the values of the keyboard lock modifiers // Note: Caps lock is not retrieved the same way as Scroll and Num lock // since it doesn't need to be. @@ -145,17 +141,15 @@ DISPLAY environment variable approriately.\n\n")); const KeyCode scroll_lock = XKeysymToKeycode(_display, XK_Scroll_Lock); for (size_t cnt = 0; cnt < size; ++cnt) { - if (! modmap->modifiermap[cnt]) continue; + if (! _modmap->modifiermap[cnt]) continue; - if (num_lock == modmap->modifiermap[cnt]) - _num_lock_mask = mask_table[cnt / modmap->max_keypermod]; - if (scroll_lock == modmap->modifiermap[cnt]) - _scroll_lock_mask = mask_table[cnt / modmap->max_keypermod]; + if (num_lock == _modmap->modifiermap[cnt]) + _num_lock_mask = mask_table[cnt / _modmap->max_keypermod]; + if (scroll_lock == _modmap->modifiermap[cnt]) + _scroll_lock_mask = mask_table[cnt / _modmap->max_keypermod]; } } - if (modmap) XFreeModifiermap(modmap); - _mask_list[0] = 0; _mask_list[1] = LockMask; _mask_list[2] = _num_lock_mask; @@ -181,6 +175,8 @@ Display::~Display() while (_grab_count > 0) ungrab(); + XFreeModifiermap(_modmap); + for (int i = 0; i < ScreenCount(_display); ++i) { delete _rendercontrol_list[i]; delete _screeninfo_list[i]; @@ -217,10 +213,19 @@ const RenderControl *Display::renderControl(int snum) const } +void Display::setIgnoreErrors(bool t) +{ + _ignore_errors = t; + // sync up so that anything already sent is/isn't ignored! + XSync(_display, false); +} + void Display::grab() { - if (_grab_count == 0) + if (_grab_count == 0) { XGrabServer(_display); + XSync(_display, false); // make sure it kicks in + } _grab_count++; } @@ -229,8 +234,10 @@ void Display::ungrab() { if (_grab_count == 0) return; _grab_count--; - if (_grab_count == 0) + if (_grab_count == 0) { XUngrabServer(_display); + XFlush(_display); // ungrab as soon as possible + } } @@ -293,4 +300,9 @@ void Display::ungrabKey(unsigned int keycode, unsigned int modifiers, grab_window); } +void Display::ungrabAllKeys(Window grab_window) const +{ + XUngrabKey(_display, AnyKey, AnyModifier, grab_window); +} + }