X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fdisplay.c;h=8b06cbfcf6cac47d213fe5a7ec33f12e6fbd1359;hb=80b6d4ac5d6a039a8e3976a52490200ed803566e;hp=b638f9cdf23c1305fef45860ce554c238aa8c9f0;hpb=a2f5a826a1ed79102cd59a9ef17724fb90afe86b;p=chaz%2Fopenbox diff --git a/obt/display.c b/obt/display.c index b638f9cd..8b06cbfc 100644 --- a/obt/display.c +++ b/obt/display.c @@ -17,6 +17,10 @@ */ #include "obt/display.h" +#include "obt/prop.h" +#include "obt/internal.h" +#include "obt/keyboard.h" +#include "obt/xqueue.h" #ifdef HAVE_STRING_H # include @@ -28,31 +32,108 @@ # include #endif +/* from xqueue.c */ +extern void xqueue_init(void); +extern void xqueue_destroy(void); + +Display* obt_display = NULL; + +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) +gboolean obt_display_open(const char *display_name) { gchar *n; Display *d = NULL; n = display_name ? g_strdup(display_name) : NULL; - d = XOpenDisplay(n); + obt_display = d = XOpenDisplay(n); if (d) { + gint junk, major, minor; + (void)junk, (void)major, (void)minor; + 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 + major = XkbMajorVersion; + minor = XkbMinorVersion; + obt_display_extension_xkb = + XkbQueryExtension(d, &junk, + &obt_display_extension_xkb_basep, &junk, + &major, &minor); + if (!obt_display_extension_xkb) + g_message("XKB extension is not present on the server or too old"); +#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 + + obt_prop_startup(); + obt_keyboard_reload(); } g_free(n); - return d; + if (obt_display) + xqueue_init(); + + return obt_display != NULL; } -void obt_display_close(Display *d) +void obt_display_close(void) { - if (d) XCloseDisplay(d); + obt_keyboard_shutdown(); + if (obt_display) { + xqueue_destroy(); + XCloseDisplay(obt_display); + } } static gint xerror_handler(Display *d, XErrorEvent *e) @@ -63,27 +144,22 @@ static gint xerror_handler(Display *d, XErrorEvent *e) XGetErrorText(d, e->error_code, errtxt, 127); if (!xerror_ignore) { if (e->error_code == BadWindow) - /*g_message(_("X Error: %s\n"), errtxt)*/; + /*g_debug(_("X Error: %s\n"), errtxt)*/; else g_error("X Error: %s", errtxt); } else - g_message("XError code %d '%s'", e->error_code, errtxt); + g_debug("Ignoring XError code %d '%s'", e->error_code, errtxt); #else (void)d; (void)e; #endif - xerror_occured = TRUE; + obt_display_error_occured = TRUE; return 0; } -void obt_display_ignore_errors(Display *d, gboolean ignore) +void obt_display_ignore_errors(gboolean ignore) { - XSync(d, FALSE); + XSync(obt_display, FALSE); xerror_ignore = ignore; - if (ignore) xerror_occured = FALSE; -} - -gboolean obt_display_error_occured() -{ - return xerror_occured; + if (ignore) obt_display_error_occured = FALSE; }