move the code for tracking what extensions are available on the display into the libobt
@@ -113,8 +113,12 @@
## obt ## obt_libobt_la_CPPFLAGS = \ + $(XINERAMA_CFLAGS) \ + $(XKB_CFLAGS) \ + $(XRANDR_CFLAGS) \ + $(XSHAPE_CFLAGS) \ + $(XSYNC_CFLAGS) \ $(GLIB_CFLAGS) \ - $(XML_CFLAGS) \ -DG_LOG_DOMAIN=\"Obt\" \ -DLOCALEDIR=\"$(localedir)\" \ -DDATADIR=\"$(datadir)\" \@@ -122,10 +126,13 @@ -DCONFIGDIR=\"$(configdir)\"
obt_libobt_la_LDFLAGS = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) obt_libobt_la_LIBADD = \ - $(GLIB_LIBS) \ - $(XML_LIBS) + $(XINERAMA_LIBS) \ + $(XKB_LIBS) \ + $(XRANDR_LIBS) \ + $(XSHAPE_LIBS) \ + $(XSYNC_LIBS) \ + $(GLIB_LIBS) obt_libobt_la_SOURCES = \ - obt/obt.h \ obt/display.h \ obt/display.c \ obt/mainloop.h \@@ -136,11 +143,6 @@ ## openbox ##
openbox_openbox_CPPFLAGS = \ $(SM_CFLAGS) \ - $(XINERAMA_CFLAGS) \ - $(XKB_CFLAGS) \ - $(XRANDR_CFLAGS) \ - $(XSHAPE_CFLAGS) \ - $(XSYNC_CFLAGS) \ $(X_CFLAGS) \ $(XCURSOR_CFLAGS) \ $(SM_CFLAGS) \@@ -154,11 +156,6 @@ -DCONFIGDIR=\"$(configdir)\" \
-DG_LOG_DOMAIN=\"Openbox\" openbox_openbox_LDADD = \ $(SM_LIBS) \ - $(XINERAMA_LIBS) \ - $(XKB_LIBS) \ - $(XRANDR_LIBS) \ - $(XSHAPE_LIBS) \ - $(XSYNC_LIBS) \ $(GLIB_LIBS) \ $(X_LIBS) \ $(XCURSOR_LIBS) \@@ -228,8 +225,6 @@ openbox/dock.c \
openbox/dock.h \ openbox/event.c \ openbox/event.h \ - openbox/extensions.c \ - openbox/extensions.h \ openbox/focus.c \ openbox/focus.h \ openbox/focus_cycle.c \@@ -399,7 +394,6 @@ render/mask.h \
render/render.h \ render/theme.h \ parser/parse.h \ - obt/obt.h \ obt/display.h \ obt/mainloop.h \ obt/util.h
@@ -28,10 +28,22 @@ #ifdef HAVE_UNISTD_H
# include <unistd.h> #endif +gboolean obt_display_error_occured = FALSE; + +gboolean obt_display_extension_xkb = FALSE; +gint obt_display_extension_xkb_basep; +gboolean obt_display_extension_shape = FALSE; +gint obt_display_extension_shape_basep; +gboolean obt_display_extension_xinerama = FALSE; +gint obt_display_extension_xinerama_basep; +gboolean obt_display_extension_randr = FALSE; +gint obt_display_extension_randr_basep; +gboolean obt_display_extension_sync = FALSE; +gint obt_display_extension_sync_basep; + 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) {@@ -41,9 +53,56 @@
n = display_name ? g_strdup(display_name) : NULL; d = XOpenDisplay(n); if (d) { + gint junk; + (void)junk; + if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1) g_message("Failed to set display as close-on-exec"); XSetErrorHandler(xerror_handler); + + /* read what extensions are present */ +#ifdef XKB + obt_display_extension_xkb = + XkbQueryExtension(d, &junk, + &obt_display_extension_xkb_basep, &junk, + NULL, NULL); + if (!obt_display_extension_xkb) + g_message("XKB extension is not present on the server"); +#endif + +#ifdef SHAPE + obt_display_extension_shape = + XShapeQueryExtension(d, &obt_display_extension_shape_basep, + &junk); + if (!obt_display_extension_shape) + g_message("X Shape extension is not present on the server"); +#endif + +#ifdef XINERAMA + obt_display_extension_xinerama = + XineramaQueryExtension(d, + &obt_display_extension_xinerama_basep, + &junk) && XineramaIsActive(d); + if (!obt_display_extension_xinerama) + g_message("Xinerama extension is not present on the server"); +#endif + +#ifdef XRANDR + obt_display_extension_randr = + XRRQueryExtension(d, &obt_display_extension_randr_basep, + &junk); + if (!obt_display_extension_randr) + g_message("XRandR extension is not present on the server"); +#endif + +#ifdef SYNC + obt_display_extension_sync = + XSyncQueryExtension(d, &obt_display_extension_sync_basep, + &junk) && XSyncInitialize(d, &junk, &junk); + if (!obt_display_extension_sync) + g_message("X Sync extension is not present on the server or is an " + "incompatible version"); +#endif } g_free(n);@@ -72,7 +131,7 @@ #else
(void)d; (void)e; #endif - xerror_occured = TRUE; + obt_display_error_occured = TRUE; return 0; }@@ -80,10 +139,5 @@ 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; + if (ignore) obt_display_error_occured = FALSE; }
@@ -16,20 +16,49 @@
See the COPYING file for a copy of the GNU General Public License. */ -#ifndef __obt_instance_h -#define __obt_instance_h +#ifndef __obt_display_h +#define __obt_display_h #include <X11/Xlib.h> #include <glib.h> +#include <X11/Xutil.h> /* shape.h uses Region which is in here */ +#ifdef XKB +#include <X11/XKBlib.h> +#endif +#ifdef SHAPE +#include <X11/extensions/shape.h> +#endif +#ifdef XINERAMA +#include <X11/extensions/Xinerama.h> +#endif +#ifdef XRANDR +#include <X11/extensions/Xrandr.h> +#endif +#ifdef SYNC +#include <X11/extensions/sync.h> +#endif + G_BEGIN_DECLS +extern gboolean obt_display_error_occured; + +extern gboolean obt_display_extension_xkb; +extern gint obt_display_extension_xkb_basep; +extern gboolean obt_display_extension_shape; +extern gint obt_display_extension_shape_basep; +extern gboolean obt_display_extension_xinerama; +extern gint obt_display_extension_xinerama_basep; +extern gboolean obt_display_extension_randr; +extern gint obt_display_extension_randr_basep; +extern gboolean obt_display_extension_sync; +extern gint obt_display_extension_sync_basep; + 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*/ +#endif /*__obt_display_h*/
@@ -1,25 +0,0 @@
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - obt.h for the Openbox window manager - Copyright (c) 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 __obt_h -#define __obt_h - -#include "obt/instance.h" -#include "obt/util.h" - -#endif /*__obt_h*/
@@ -26,7 +26,6 @@ #include "moveresize.h"
#include "ping.h" #include "place.h" #include "prop.h" -#include "extensions.h" #include "frame.h" #include "session.h" #include "event.h"@@ -1262,7 +1261,7 @@ static void client_get_shaped(ObClient *self)
{ self->shaped = FALSE; #ifdef SHAPE - if (extensions_shape) { + if (obt_display_extension_shape) { gint foo; guint ufoo; gint s;@@ -3639,8 +3638,8 @@
obt_display_ignore_errors(ob_display, FALSE); ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d\n", - obt_display_error_occured()); - return !obt_display_error_occured(); + obt_display_error_occured); + return !obt_display_error_occured; } static void client_present(ObClient *self, gboolean here, gboolean raise,
@@ -39,7 +39,6 @@ #include "focus_cycle.h"
#include "moveresize.h" #include "group.h" #include "stacking.h" -#include "extensions.h" #include "translate.h" #include "ping.h" #include "obt/display.h"@@ -180,7 +179,9 @@ window = e->xconfigure.window;
break; default: #ifdef XKB - if (extensions_xkb && e->type == extensions_xkb_event_basep) { + if (obt_display_extension_xkb && + e->type == obt_display_extension_xkb_basep) + { switch (((XkbAnyEvent*)e)->xkb_type) { case XkbBellNotify: window = ((XkbBellNotifyEvent*)e)->window;@@ -190,8 +191,8 @@ }
} else #endif #ifdef SYNC - if (extensions_sync && - e->type == extensions_sync_event_basep + XSyncAlarmNotify) + if (obt_display_extension_sync && + e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { window = None; } else@@ -229,8 +230,8 @@ t = e->xcrossing.time;
break; default: #ifdef SYNC - if (extensions_sync && - e->type == extensions_sync_event_basep + XSyncAlarmNotify) + if (obt_display_extension_sync && + e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { t = ((XSyncAlarmNotifyEvent*)e)->time; }@@ -690,8 +691,8 @@ e->xconfigurerequest.value_mask, &xwc);
obt_display_ignore_errors(ob_display, FALSE); } #ifdef SYNC - else if (extensions_sync && - e->type == extensions_sync_event_basep + XSyncAlarmNotify) + else if (obt_display_extension_sync && + e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { XSyncAlarmNotifyEvent *se = (XSyncAlarmNotifyEvent*)e; if (se->alarm == moveresize_alarm && moveresize_in_progress)@@ -1585,7 +1586,9 @@ break;
default: ; #ifdef SHAPE - if (extensions_shape && e->type == extensions_shape_event_basep) { + if (obt_display_extension_shape && + e->type == obt_display_extension_shape_basep) + { client->shaped = ((XShapeEvent*)e)->shaped; frame_adjust_shape(client->frame); }
@@ -1,133 +0,0 @@
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - extensions.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 "geom.h" -#include "extensions.h" -#include "screen.h" -#include "debug.h" - -gboolean extensions_xkb = FALSE; -gint extensions_xkb_event_basep; -gboolean extensions_shape = FALSE; -gint extensions_shape_event_basep; -gboolean extensions_xinerama = FALSE; -gint extensions_xinerama_event_basep; -gboolean extensions_randr = FALSE; -gint extensions_randr_event_basep; -gboolean extensions_sync = FALSE; -gint extensions_sync_event_basep; - -void extensions_query_all(void) -{ - gint junk; - (void)junk; - -#ifdef XKB - extensions_xkb = - XkbQueryExtension(ob_display, &junk, &extensions_xkb_event_basep, - &junk, NULL, NULL); - if (!extensions_xkb) - ob_debug("XKB extension is not present on the server\n"); -#endif - -#ifdef SHAPE - extensions_shape = - XShapeQueryExtension(ob_display, &extensions_shape_event_basep, - &junk); - if (!extensions_shape) - ob_debug("X Shape extension is not present on the server\n"); -#endif - -#ifdef XINERAMA - extensions_xinerama = - XineramaQueryExtension(ob_display, &extensions_xinerama_event_basep, - &junk) && XineramaIsActive(ob_display); - if (!extensions_xinerama) - ob_debug("Xinerama extension is not present on the server\n"); -#endif - -#ifdef XRANDR - extensions_randr = - XRRQueryExtension(ob_display, &extensions_randr_event_basep, - &junk); - if (!extensions_randr) - ob_debug("XRandR extension is not present on the server\n"); -#endif - -#ifdef SYNC - extensions_sync = - XSyncQueryExtension(ob_display, &extensions_sync_event_basep, - &junk) && - XSyncInitialize(ob_display, &junk, &junk); - if (!extensions_sync) - ob_debug("X Sync extension is not present on the server or is an " - "incompatible version\n"); -#endif -} - -void extensions_xinerama_screens(Rect **xin_areas, guint *nxin) -{ - guint i; - gint l, r, t, b; - if (ob_debug_xinerama) { - g_print("Using fake xinerama !\n"); - gint w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)); - gint h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)); - *nxin = 2; - *xin_areas = g_new(Rect, *nxin + 1); - RECT_SET((*xin_areas)[0], 0, 0, w/2, h); - RECT_SET((*xin_areas)[1], w/2, 0, w-(w/2), h); - } - else -#ifdef XINERAMA - if (extensions_xinerama) { - guint i; - gint n; - XineramaScreenInfo *info = XineramaQueryScreens(ob_display, &n); - *nxin = n; - *xin_areas = g_new(Rect, *nxin + 1); - for (i = 0; i < *nxin; ++i) - RECT_SET((*xin_areas)[i], info[i].x_org, info[i].y_org, - info[i].width, info[i].height); - XFree(info); - } - else -#endif - { - *nxin = 1; - *xin_areas = g_new(Rect, *nxin + 1); - RECT_SET((*xin_areas)[0], 0, 0, - WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)), - HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen))); - } - - /* returns one extra with the total area in it */ - l = (*xin_areas)[0].x; - t = (*xin_areas)[0].y; - r = (*xin_areas)[0].x + (*xin_areas)[0].width - 1; - b = (*xin_areas)[0].y + (*xin_areas)[0].height - 1; - for (i = 1; i < *nxin; ++i) { - l = MIN(l, (*xin_areas)[i].x); - t = MIN(l, (*xin_areas)[i].y); - r = MAX(r, (*xin_areas)[i].x + (*xin_areas)[i].width - 1); - b = MAX(b, (*xin_areas)[i].y + (*xin_areas)[i].height - 1); - } - RECT_SET((*xin_areas)[*nxin], l, t, r - l + 1, b - t + 1); -}
@@ -1,74 +0,0 @@
-/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - - extensions.h 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. -*/ - -#ifndef __extensions_h -#define __extensions_h - -#include "geom.h" - -#include <X11/Xlib.h> -#include <X11/Xutil.h> /* shape.h uses Region which is in here */ -#ifdef XKB -#include <X11/XKBlib.h> -#endif -#ifdef SHAPE -#include <X11/extensions/shape.h> -#endif -#ifdef XINERAMA -#include <X11/extensions/Xinerama.h> -#endif -#ifdef XRANDR -#include <X11/extensions/Xrandr.h> -#endif -#ifdef SYNC -#include <X11/extensions/sync.h> -#endif - -#include <glib.h> - -/*! Does the display have the XKB extension? */ -extern gboolean extensions_xkb; -/*! Base for events for the XKB extension */ -extern gint extensions_xkb_event_basep; - -/*! Does the display have the Shape extension? */ -extern gboolean extensions_shape; -/*! Base for events for the Shape extension */ -extern gint extensions_shape_event_basep; - -/*! Does the display have the Xinerama extension? */ -extern gboolean extensions_xinerama; -/*! Base for events for the Xinerama extension */ -extern gint extensions_xinerama_event_basep; - -/*! Does the display have the RandR extension? */ -extern gboolean extensions_randr; -/*! Base for events for the Randr extension */ -extern gint extensions_randr_event_basep; - -/*! Does the display have the Sync extension? */ -extern gboolean extensions_sync; -/*! Base for events for the Sync extension */ -extern gint extensions_sync_event_basep; - -void extensions_query_all(); - -void extensions_xinerama_screens(Rect **areas, guint *nxin); - -#endif
@@ -20,7 +20,6 @@
#include "frame.h" #include "client.h" #include "openbox.h" -#include "extensions.h" #include "prop.h" #include "grab.h" #include "config.h"@@ -30,6 +29,7 @@ #include "focus_cycle_indicator.h"
#include "moveresize.h" #include "screen.h" #include "render/theme.h" +#include "obt/display.h" #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask | \ ButtonPressMask | ButtonReleaseMask | \
@@ -180,7 +180,7 @@ 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)); obt_display_ignore_errors(ob_display, FALSE); - if (obt_display_error_occured()) + if (obt_display_error_occured) ob_debug("Failed to grab button %d modifiers %d", button, state); }@@ -202,7 +202,7 @@ for (i = 0; i < MASK_LIST_SIZE; ++i)
XGrabKey(ob_display, keycode, state | mask_list[i], win, FALSE, GrabModeAsync, keyboard_mode); obt_display_ignore_errors(ob_display, FALSE); - if (obt_display_error_occured()) + if (obt_display_error_occured) ob_debug("Failed to grab keycode %d modifiers %d", keycode, state); }
@@ -31,9 +31,9 @@ #include "moveresize.h"
#include "config.h" #include "event.h" #include "debug.h" -#include "extensions.h" #include "render/render.h" #include "render/theme.h" +#include "obt/display.h" #include <X11/Xlib.h> #include <glib.h>@@ -250,7 +250,7 @@
moveresize_in_progress = TRUE; #ifdef SYNC - if (config_resize_redraw && !moving && extensions_sync && + if (config_resize_redraw && !moving && obt_display_extension_sync && moveresize_client->sync_request && moveresize_client->sync_counter) { /* Initialize values for the resize syncing, and create an alarm for@@ -365,7 +365,7 @@ return;
} #ifdef SYNC - if (config_resize_redraw && extensions_sync && + if (config_resize_redraw && obt_display_extension_sync && moveresize_client->sync_request && moveresize_client->sync_counter) { XEvent ce;@@ -923,7 +923,7 @@ }
} } #ifdef SYNC - else if (e->type == extensions_sync_event_basep + XSyncAlarmNotify) + else if (e->type == obt_display_extension_sync_basep + XSyncAlarmNotify) { waiting_for_sync = FALSE; /* we got our sync... */ do_resize(); /* ...so try resize if there is more change pending */
@@ -37,7 +37,6 @@ #include "moveresize.h"
#include "frame.h" #include "keyboard.h" #include "mouse.h" -#include "extensions.h" #include "menuframe.h" #include "grab.h" #include "group.h"@@ -207,9 +206,7 @@ cursors[OB_CURSOR_WEST] = load_cursor("left_side", XC_left_side);
cursors[OB_CURSOR_NORTHWEST] = load_cursor("top_left_corner", XC_top_left_corner); - prop_startup(); /* get atoms values for the display */ - extensions_query_all(); /* find which extensions are present */ if (screen_annex()) { /* it will be ours! */ do {
@@ -33,7 +33,6 @@ #include "frame.h"
#include "event.h" #include "focus.h" #include "popup.h" -#include "extensions.h" #include "render/render.h" #include "gettext.h" #include "obt/display.h"@@ -110,7 +109,7 @@ XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask);
XSync(ob_display, FALSE); obt_display_ignore_errors(ob_display, FALSE); - if (obt_display_error_occured()) + if (obt_display_error_occured) current_wm_sn_owner = None; }@@ -184,7 +183,7 @@ obt_display_ignore_errors(ob_display, TRUE);
XSelectInput(ob_display, RootWindow(ob_display, ob_screen), ROOT_EVENTMASK); obt_display_ignore_errors(ob_display, FALSE); - if (obt_display_error_occured()) { + if (obt_display_error_occured) { g_message(_("A window manager is already running on screen %d"), ob_screen);@@ -1291,6 +1290,55 @@ ss->strut->side = MIN(max, ss->strut->side); \
} \ } +static void get_xinerama_screens(Rect **xin_areas, guint *nxin) +{ + guint i; + gint l, r, t, b; + + if (ob_debug_xinerama) { + g_print("Using fake xinerama !\n"); + gint w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)); + gint h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)); + *nxin = 2; + *xin_areas = g_new(Rect, *nxin + 1); + RECT_SET((*xin_areas)[0], 0, 0, w/2, h); + RECT_SET((*xin_areas)[1], w/2, 0, w-(w/2), h); + } +#ifdef XINERAMA + else if (obt_display_extension_xinerama) { + guint i; + gint n; + XineramaScreenInfo *info = XineramaQueryScreens(ob_display, &n); + *nxin = n; + *xin_areas = g_new(Rect, *nxin + 1); + for (i = 0; i < *nxin; ++i) + RECT_SET((*xin_areas)[i], info[i].x_org, info[i].y_org, + info[i].width, info[i].height); + XFree(info); + } +#endif + else { + *nxin = 1; + *xin_areas = g_new(Rect, *nxin + 1); + RECT_SET((*xin_areas)[0], 0, 0, + WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)), + HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen))); + } + + /* returns one extra with the total area in it */ + l = (*xin_areas)[0].x; + t = (*xin_areas)[0].y; + r = (*xin_areas)[0].x + (*xin_areas)[0].width - 1; + b = (*xin_areas)[0].y + (*xin_areas)[0].height - 1; + for (i = 1; i < *nxin; ++i) { + l = MIN(l, (*xin_areas)[i].x); + t = MIN(l, (*xin_areas)[i].y); + r = MAX(r, (*xin_areas)[i].x + (*xin_areas)[i].width - 1); + b = MAX(b, (*xin_areas)[i].y + (*xin_areas)[i].height - 1); + } + RECT_SET((*xin_areas)[*nxin], l, t, r - l + 1, b - t + 1); +} + void screen_update_areas(void) { guint i, j;@@ -1299,7 +1347,7 @@ GList *it;
GSList *sit; g_free(monitor_area); - extensions_xinerama_screens(&monitor_area, &screen_num_monitors); + get_xinerama_screens(&monitor_area, &screen_num_monitors); /* set up the user-specified margins */ config_margins.top_start = RECT_LEFT(monitor_area[screen_num_monitors]);