all repos — openbox @ a2f5a826a1ed79102cd59a9ef17724fb90afe86b

openbox fork - make it a bit more like ryudo

move the xerror handling into the libobt
Dana Jansens danakj@orodu.net
commit

a2f5a826a1ed79102cd59a9ef17724fb90afe86b

parent

452627a51ce38229533dfe5d8eeb877b0918d02c

M Makefile.amMakefile.am

@@ -286,10 +286,7 @@ openbox/startupnotify.h \

openbox/translate.c \ openbox/translate.h \ openbox/window.c \ - openbox/window.h \ - openbox/xerror.c \ - openbox/xerror.h - + openbox/window.h ## gnome-panel-control ##
M obt/display.cobt/display.c

@@ -17,7 +17,6 @@ See the COPYING file for a copy of the GNU General Public License.

*/ #include "obt/display.h" -#include "obt/util.h" #ifdef HAVE_STRING_H # include <string.h>

@@ -29,6 +28,11 @@ #ifdef HAVE_UNISTD_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 @@ d = XOpenDisplay(n);

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; +}
M obt/display.hobt/display.h

@@ -27,6 +27,9 @@

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*/
M openbox/client.copenbox/client.c

@@ -21,7 +21,6 @@ #include "client.h"

#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 "keyboard.h"

#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 @@ if ((hints = XGetWMHints(ob_display, self->window))) {

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 @@ {

g_free(self->icons); self->nicons = 0; } - xerror_set_ignore(FALSE); + obt_display_ignore_errors(ob_display, FALSE); } XFree(hints); }

@@ -3612,8 +3612,7 @@ interactive grab.

*/ 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 @@ ce.xclient.data.l[4] = 0l;

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,
M openbox/event.copenbox/event.c

@@ -24,7 +24,6 @@ #include "openbox.h"

#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 "stacking.h"

#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 @@ is not being managed, or a window on another screen. */

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 @@ }

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 @@ xwc.stack_mode = e->xconfigurerequest.detail;

/* 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 &&
M openbox/grab.copenbox/grab.c

@@ -21,9 +21,9 @@ #include "grab.h"

#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 @@ gint pointer_mode, ObCursor cur)

{ 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); }
M openbox/mouse.copenbox/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 "frame.h"

#include "translate.h" #include "mouse.h" #include "gettext.h" +#include "obt/display.h" #include <glib.h>

@@ -257,10 +257,10 @@ gint junk1, junk2;

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 &&
M openbox/openbox.copenbox/openbox.c

@@ -25,7 +25,6 @@ #include "modkeys.h"

#include "event.h" #include "menu.h" #include "client.h" -#include "xerror.h" #include "prop.h" #include "screen.h" #include "actions.h"

@@ -184,9 +183,6 @@ if (!XSupportsLocale())

g_message(_("X server does not support locale.")); 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. */
M openbox/screen.copenbox/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 "popup.h"

#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 @@ g_message(_("A window manager is already running on screen %d"),

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 @@ XDestroyWindow(ob_display, screen_support_win);

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 @@ XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));

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); } }
D openbox/xerror.c

@@ -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; -}
D openbox/xerror.h

@@ -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