]> Dogcows Code - chaz/openbox/blobdiff - otk/display.cc
alloc colors only when needed, and free them properly on destruction
[chaz/openbox] / otk / display.cc
index be8696bfe5a2182c645570368dea9d168c19ad77..9ab8ed2f0b898ab2e8c23aee9e895d8db4120a6f 100644 (file)
@@ -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 <X11/extensions/Xinerama.h>
 #endif // XINERAMA
 
-#ifdef    HAVE_STDIO_H
-#  include <stdio.h>
-#endif // HAVE_STDIO_H
-
 #ifdef    HAVE_SIGNAL_H
 #  include <signal.h>
 #endif // HAVE_SIGNAL_H
@@ -41,10 +35,12 @@ extern "C" {
 #  include <unistd.h>
 #endif // HAVE_UNISTD_H
 
-#include "gettext.h"
+#include "../src/gettext.h"
 #define _(str) gettext(str)
 }
 
+#include <cstdio>
+
 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;
 }
 
@@ -216,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++;
 }
 
@@ -228,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
+  }
 }
 
 
@@ -292,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);
+}
+
 }
This page took 0.024988 seconds and 4 git commands to generate.