move the xerror handling into the libobt
authorDana Jansens <danakj@orodu.net>
Tue, 24 Jul 2007 00:55:19 +0000 (20:55 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 20 Jan 2008 06:36:54 +0000 (01:36 -0500)
Makefile.am
obt/display.c
obt/display.h
openbox/client.c
openbox/event.c
openbox/grab.c
openbox/mouse.c
openbox/openbox.c
openbox/screen.c
openbox/xerror.c [deleted file]
openbox/xerror.h [deleted file]

index b547eaa..6c2140e 100644 (file)
@@ -286,10 +286,7 @@ openbox_openbox_SOURCES = \
        openbox/translate.c \
        openbox/translate.h \
        openbox/window.c \
-       openbox/window.h \
-       openbox/xerror.c \
-       openbox/xerror.h
-
+       openbox/window.h
 
 ## gnome-panel-control ##
 
index 049b6ae..b638f9c 100644 (file)
@@ -17,7 +17,6 @@
 */
 
 #include "obt/display.h"
-#include "obt/util.h"
 
 #ifdef HAVE_STRING_H
 #  include <string.h>
 #  include <unistd.h>
 #endif
 
+static gint xerror_handler(Display *d, XErrorEvent *e);
+
+static gboolean xerror_ignore = FALSE;
+static gboolean xerror_occured = FALSE;
+
 Display* obt_display_open(const char *display_name)
 {
     gchar *n;
@@ -39,6 +43,7 @@ Display* obt_display_open(const char *display_name)
     if (d) {
         if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
             g_message("Failed to set display as close-on-exec");
+        XSetErrorHandler(xerror_handler);
     }
     g_free(n);
 
@@ -49,3 +54,36 @@ void obt_display_close(Display *d)
 {
     if (d) XCloseDisplay(d);
 }
+
+static gint xerror_handler(Display *d, XErrorEvent *e)
+{
+#ifdef DEBUG
+    gchar errtxt[128];
+
+    XGetErrorText(d, e->error_code, errtxt, 127);
+    if (!xerror_ignore) {
+        if (e->error_code == BadWindow)
+            /*g_message(_("X Error: %s\n"), errtxt)*/;
+        else
+            g_error("X Error: %s", errtxt);
+    } else
+        g_message("XError code %d '%s'", e->error_code, errtxt);
+#else
+    (void)d; (void)e;
+#endif
+
+    xerror_occured = TRUE;
+    return 0;
+}
+
+void obt_display_ignore_errors(Display *d, gboolean ignore)
+{
+    XSync(d, FALSE);
+    xerror_ignore = ignore;
+    if (ignore) xerror_occured = FALSE;
+}
+
+gboolean obt_display_error_occured()
+{
+    return xerror_occured;
+}
index a42630e..aafa0fc 100644 (file)
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
 Display* obt_display_open(const char *display_name);
 void     obt_display_close(Display *d);
 
+void     obt_display_ignore_errors(Display *d, gboolean ignore);
+gboolean obt_display_error_occured();
+
 G_END_DECLS
 
 #endif /*__obt_instance_h*/
index 63245a3..025dd12 100644 (file)
@@ -21,7 +21,6 @@
 #include "debug.h"
 #include "startupnotify.h"
 #include "dock.h"
-#include "xerror.h"
 #include "screen.h"
 #include "moveresize.h"
 #include "ping.h"
@@ -42,6 +41,7 @@
 #include "mouse.h"
 #include "render/render.h"
 #include "gettext.h"
+#include "obt/display.h"
 
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>
@@ -2124,7 +2124,7 @@ void client_update_icons(ObClient *self)
             if (hints->flags & IconPixmapHint) {
                 self->nicons = 1;
                 self->icons = g_new(ObClientIcon, self->nicons);
-                xerror_set_ignore(TRUE);
+                obt_display_ignore_errors(ob_display, TRUE);
                 if (!RrPixmapToRGBA(ob_rr_inst,
                                     hints->icon_pixmap,
                                     (hints->flags & IconMaskHint ?
@@ -2136,7 +2136,7 @@ void client_update_icons(ObClient *self)
                     g_free(self->icons);
                     self->nicons = 0;
                 }
-                xerror_set_ignore(FALSE);
+                obt_display_ignore_errors(ob_display, FALSE);
             }
             XFree(hints);
         }
@@ -3612,8 +3612,7 @@ gboolean client_focus(ObClient *self)
     */
     event_cancel_all_key_grabs();
 
-    xerror_set_ignore(TRUE);
-    xerror_occured = FALSE;
+    obt_display_ignore_errors(ob_display, TRUE);
 
     if (self->can_focus) {
         /* This can cause a BadMatch error with CurrentTime, or if an app
@@ -3637,10 +3636,11 @@ gboolean client_focus(ObClient *self)
         XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
     }
 
-    xerror_set_ignore(FALSE);
+    obt_display_ignore_errors(ob_display, FALSE);
 
-    ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d\n", xerror_occured);
-    return !xerror_occured;
+    ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d\n",
+                  obt_display_error_occured());
+    return !obt_display_error_occured();
 }
 
 static void client_present(ObClient *self, gboolean here, gboolean raise,
index 2e7feab..5aa7392 100644 (file)
@@ -24,7 +24,6 @@
 #include "dock.h"
 #include "actions.h"
 #include "client.h"
-#include "xerror.h"
 #include "prop.h"
 #include "config.h"
 #include "screen.h"
@@ -43,6 +42,7 @@
 #include "extensions.h"
 #include "translate.h"
 #include "ping.h"
+#include "obt/display.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
@@ -594,7 +594,7 @@ static void event_process(const XEvent *ec, gpointer data)
             Window win, root;
             gint i;
             guint u;
-            xerror_set_ignore(TRUE);
+            obt_display_ignore_errors(ob_display, TRUE);
             if (XGetInputFocus(ob_display, &win, &i) != 0 &&
                 XGetGeometry(ob_display, win, &root, &i,&i,&u,&u,&u,&u) != 0 &&
                 root != RootWindow(ob_display, ob_screen))
@@ -606,7 +606,7 @@ static void event_process(const XEvent *ec, gpointer data)
             else
                 ob_debug_type(OB_DEBUG_FOCUS,
                               "Focus went to a black hole !\n");
-            xerror_set_ignore(FALSE);
+            obt_display_ignore_errors(ob_display, FALSE);
             /* nothing is focused */
             focus_set_client(NULL);
         } else {
@@ -684,10 +684,10 @@ static void event_process(const XEvent *ec, gpointer data)
 
         /* we are not to be held responsible if someone sends us an
            invalid request! */
-        xerror_set_ignore(TRUE);
+        obt_display_ignore_errors(ob_display, TRUE);
         XConfigureWindow(ob_display, window,
                          e->xconfigurerequest.value_mask, &xwc);
-        xerror_set_ignore(FALSE);
+        obt_display_ignore_errors(ob_display, FALSE);
     }
 #ifdef SYNC
     else if (extensions_sync &&
index 43e9a81..d84ef94 100644 (file)
@@ -21,9 +21,9 @@
 #include "modkeys.h"
 #include "openbox.h"
 #include "event.h"
-#include "xerror.h"
 #include "screen.h"
 #include "debug.h"
+#include "obt/display.h"
 
 #include <glib.h>
 #include <X11/Xlib.h>
@@ -174,13 +174,13 @@ void grab_button_full(guint button, guint state, Window win, guint mask,
 {
     guint i;
 
-    xerror_set_ignore(TRUE); /* can get BadAccess from these */
-    xerror_occured = FALSE;
+    /* can get BadAccess from these */
+    obt_display_ignore_errors(ob_display, TRUE);
     for (i = 0; i < MASK_LIST_SIZE; ++i)
         XGrabButton(ob_display, button, state | mask_list[i], win, False, mask,
                     pointer_mode, GrabModeAsync, None, ob_cursor(cur));
-    xerror_set_ignore(FALSE);
-    if (xerror_occured)
+    obt_display_ignore_errors(ob_display, FALSE);
+    if (obt_display_error_occured())
         ob_debug("Failed to grab button %d modifiers %d", button, state);
 }
 
@@ -196,13 +196,13 @@ void grab_key(guint keycode, guint state, Window win, gint keyboard_mode)
 {
     guint i;
 
-    xerror_set_ignore(TRUE); /* can get BadAccess' from these */
-    xerror_occured = FALSE;
+    /* can get BadAccess' from these */
+    obt_display_ignore_errors(ob_display, TRUE);
     for (i = 0; i < MASK_LIST_SIZE; ++i)
         XGrabKey(ob_display, keycode, state | mask_list[i], win, FALSE,
                  GrabModeAsync, keyboard_mode);
-    xerror_set_ignore(FALSE);
-    if (xerror_occured)
+    obt_display_ignore_errors(ob_display, FALSE);
+    if (obt_display_error_occured())
         ob_debug("Failed to grab keycode %d modifiers %d", keycode, state);
 }
 
index 6661558..782ea62 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "openbox.h"
 #include "config.h"
-#include "xerror.h"
 #include "actions.h"
 #include "event.h"
 #include "client.h"
@@ -29,6 +28,7 @@
 #include "translate.h"
 #include "mouse.h"
 #include "gettext.h"
+#include "obt/display.h"
 
 #include <glib.h>
 
@@ -257,10 +257,10 @@ void mouse_event(ObClient *client, XEvent *e)
             Window wjunk;
             guint ujunk, b, w, h;
             /* this can cause errors to occur when the window closes */
-            xerror_set_ignore(TRUE);
+            obt_display_ignore_errors(ob_display, TRUE);
             junk1 = XGetGeometry(ob_display, e->xbutton.window,
                                  &wjunk, &junk1, &junk2, &w, &h, &b, &ujunk);
-            xerror_set_ignore(FALSE);
+            obt_display_ignore_errors(ob_display, FALSE);
             if (junk1) {
                 if (e->xbutton.x >= (signed)-b &&
                     e->xbutton.y >= (signed)-b &&
index aa30e9a..f00cd2b 100644 (file)
@@ -25,7 +25,6 @@
 #include "event.h"
 #include "menu.h"
 #include "client.h"
-#include "xerror.h"
 #include "prop.h"
 #include "screen.h"
 #include "actions.h"
@@ -185,9 +184,6 @@ gint main(gint argc, gchar **argv)
     if (!XSetLocaleModifiers(""))
         g_message(_("Cannot set locale modifiers for the X server."));
 
-    /* set our error handler */
-    XSetErrorHandler(xerror_handler);
-
     /* set the DISPLAY environment variable for any lauched children, to the
        display we're using, so they open in the right place. */
     putenv(g_strdup_printf("DISPLAY=%s", DisplayString(ob_display)));
index e008ffe..d287c9f 100644 (file)
@@ -20,7 +20,6 @@
 #include "debug.h"
 #include "openbox.h"
 #include "dock.h"
-#include "xerror.h"
 #include "prop.h"
 #include "grab.h"
 #include "startupnotify.h"
@@ -37,6 +36,7 @@
 #include "extensions.h"
 #include "render/render.h"
 #include "gettext.h"
+#include "obt/display.h"
 
 #include <X11/Xlib.h>
 #ifdef HAVE_UNISTD_H
@@ -103,15 +103,14 @@ static gboolean replace_wm(void)
                       ob_screen);
             return FALSE;
         }
-        xerror_set_ignore(TRUE);
-        xerror_occured = FALSE;
+        obt_display_ignore_errors(ob_display, TRUE);
 
         /* We want to find out when the current selection owner dies */
         XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask);
         XSync(ob_display, FALSE);
 
-        xerror_set_ignore(FALSE);
-        if (xerror_occured)
+        obt_display_ignore_errors(ob_display, FALSE);
+        if (obt_display_error_occured())
             current_wm_sn_owner = None;
     }
 
@@ -181,12 +180,11 @@ gboolean screen_annex(void)
         return FALSE;
     }
 
-    xerror_set_ignore(TRUE);
-    xerror_occured = FALSE;
+    obt_display_ignore_errors(ob_display, TRUE);
     XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
                  ROOT_EVENTMASK);
-    xerror_set_ignore(FALSE);
-    if (xerror_occured) {
+    obt_display_ignore_errors(ob_display, FALSE);
+    if (obt_display_error_occured()) {
         g_message(_("A window manager is already running on screen %d"),
                   ob_screen);
 
@@ -1246,12 +1244,12 @@ void screen_install_colormap(ObClient *client, gboolean install)
         else
             XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
     } else {
-        xerror_set_ignore(TRUE);
+        obt_display_ignore_errors(ob_display, TRUE);
         if (install)
             XInstallColormap(RrDisplay(ob_rr_inst), client->colormap);
         else
             XUninstallColormap(RrDisplay(ob_rr_inst), client->colormap);
-        xerror_set_ignore(FALSE);
+        obt_display_ignore_errors(ob_display, FALSE);
     }
 }
 
diff --git a/openbox/xerror.c b/openbox/xerror.c
deleted file mode 100644 (file)
index 2657b8e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
-
-   xerror.c for the Openbox window manager
-   Copyright (c) 2006        Mikael Magnusson
-   Copyright (c) 2003-2007   Dana Jansens
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   See the COPYING file for a copy of the GNU General Public License.
-*/
-
-#include "openbox.h"
-#include "gettext.h"
-#include "debug.h"
-#include "xerror.h"
-#include <glib.h>
-#include <X11/Xlib.h>
-
-static gboolean xerror_ignore = FALSE;
-gboolean xerror_occured = FALSE;
-
-gint xerror_handler(Display *d, XErrorEvent *e)
-{
-#ifdef DEBUG
-    gchar errtxt[128];
-
-    XGetErrorText(d, e->error_code, errtxt, 127);
-    if (!xerror_ignore) {
-        if (e->error_code == BadWindow)
-            /*g_message(_("X Error: %s\n"), errtxt)*/;
-        else
-            g_error(_("X Error: %s"), errtxt);
-    } else
-        ob_debug("XError code %d '%s'\n", e->error_code, errtxt);
-#else
-    (void)d; (void)e;
-#endif
-
-    xerror_occured = TRUE;
-    return 0;
-}
-
-void xerror_set_ignore(gboolean ignore)
-{
-    XSync(ob_display, FALSE);
-    xerror_ignore = ignore;
-}
diff --git a/openbox/xerror.h b/openbox/xerror.h
deleted file mode 100644 (file)
index de1aa5a..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
-
-   xerror.h for the Openbox window manager
-   Copyright (c) 2003-2007   Dana Jansens
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   See the COPYING file for a copy of the GNU General Public License.
-*/
-
-#ifndef __xerror_h
-#define __xerror_h
-
-#include <X11/Xlib.h>
-#include <glib.h>
-
-/* can be used to track errors */
-extern gboolean xerror_occured;
-
-gint xerror_handler(Display *, XErrorEvent *);
-
-void xerror_set_ignore(gboolean ignore);
-
-#endif