From a2f5a826a1ed79102cd59a9ef17724fb90afe86b Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 23 Jul 2007 20:55:19 -0400 Subject: [PATCH] move the xerror handling into the libobt --- Makefile.am | 5 +---- obt/display.c | 40 +++++++++++++++++++++++++++++++++- obt/display.h | 3 +++ openbox/client.c | 16 +++++++------- openbox/event.c | 10 ++++----- openbox/grab.c | 18 ++++++++-------- openbox/mouse.c | 6 +++--- openbox/openbox.c | 4 ---- openbox/screen.c | 20 ++++++++--------- openbox/xerror.c | 55 ----------------------------------------------- openbox/xerror.h | 32 --------------------------- 11 files changed, 77 insertions(+), 132 deletions(-) delete mode 100644 openbox/xerror.c delete mode 100644 openbox/xerror.h diff --git a/Makefile.am b/Makefile.am index b547eaa1..6c2140ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 ## diff --git a/obt/display.c b/obt/display.c index 049b6aef..b638f9cd 100644 --- a/obt/display.c +++ b/obt/display.c @@ -17,7 +17,6 @@ */ #include "obt/display.h" -#include "obt/util.h" #ifdef HAVE_STRING_H # include @@ -29,6 +28,11 @@ # include #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; +} diff --git a/obt/display.h b/obt/display.h index a42630e1..aafa0fcd 100644 --- a/obt/display.h +++ b/obt/display.h @@ -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*/ diff --git a/openbox/client.c b/openbox/client.c index 63245a3c..025dd129 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -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 @@ -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, diff --git a/openbox/event.c b/openbox/event.c index 2e7feab7..5aa73921 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -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 #include @@ -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 && diff --git a/openbox/grab.c b/openbox/grab.c index 43e9a815..d84ef94f 100644 --- a/openbox/grab.c +++ b/openbox/grab.c @@ -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 #include @@ -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); } diff --git a/openbox/mouse.c b/openbox/mouse.c index 66615585..782ea62c 100644 --- a/openbox/mouse.c +++ b/openbox/mouse.c @@ -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 @@ -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 && diff --git a/openbox/openbox.c b/openbox/openbox.c index aa30e9af..f00cd2bd 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -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))); diff --git a/openbox/screen.c b/openbox/screen.c index e008ffe5..d287c9fc 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -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 #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 index 2657b8ea..00000000 --- a/openbox/xerror.c +++ /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 -#include - -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 index de1aa5a8..00000000 --- a/openbox/xerror.h +++ /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 -#include - -/* can be used to track errors */ -extern gboolean xerror_occured; - -gint xerror_handler(Display *, XErrorEvent *); - -void xerror_set_ignore(gboolean ignore); - -#endif -- 2.45.2