1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 obt/display.c for the Openbox window manager
4 Copyright (c) 2007 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
19 #include "obt/display.h"
32 Display* obt_display = NULL;
34 gboolean obt_display_error_occured = FALSE;
36 gboolean obt_display_extension_xkb = FALSE;
37 gint obt_display_extension_xkb_basep;
38 gboolean obt_display_extension_shape = FALSE;
39 gint obt_display_extension_shape_basep;
40 gboolean obt_display_extension_xinerama = FALSE;
41 gint obt_display_extension_xinerama_basep;
42 gboolean obt_display_extension_randr = FALSE;
43 gint obt_display_extension_randr_basep;
44 gboolean obt_display_extension_sync = FALSE;
45 gint obt_display_extension_sync_basep;
47 static gint xerror_handler(Display *d, XErrorEvent *e);
49 static gboolean xerror_ignore = FALSE;
51 gboolean obt_display_open(const char *display_name)
56 n = display_name ? g_strdup(display_name) : NULL;
57 obt_display = d = XOpenDisplay(n);
62 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
63 g_message("Failed to set display as close-on-exec");
64 XSetErrorHandler(xerror_handler);
66 /* read what extensions are present */
68 obt_display_extension_xkb =
69 XkbQueryExtension(d, &junk,
70 &obt_display_extension_xkb_basep, &junk,
72 if (!obt_display_extension_xkb)
73 g_message("XKB extension is not present on the server");
77 obt_display_extension_shape =
78 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
80 if (!obt_display_extension_shape)
81 g_message("X Shape extension is not present on the server");
85 obt_display_extension_xinerama =
86 XineramaQueryExtension(d,
87 &obt_display_extension_xinerama_basep,
88 &junk) && XineramaIsActive(d);
89 if (!obt_display_extension_xinerama)
90 g_message("Xinerama extension is not present on the server");
94 obt_display_extension_randr =
95 XRRQueryExtension(d, &obt_display_extension_randr_basep,
97 if (!obt_display_extension_randr)
98 g_message("XRandR extension is not present on the server");
102 obt_display_extension_sync =
103 XSyncQueryExtension(d, &obt_display_extension_sync_basep,
104 &junk) && XSyncInitialize(d, &junk, &junk);
105 if (!obt_display_extension_sync)
106 g_message("X Sync extension is not present on the server or is an "
107 "incompatible version");
114 return obt_display != NULL;
117 void obt_display_close()
119 if (obt_display) XCloseDisplay(obt_display);
122 static gint xerror_handler(Display *d, XErrorEvent *e)
127 XGetErrorText(d, e->error_code, errtxt, 127);
128 if (!xerror_ignore) {
129 if (e->error_code == BadWindow)
130 /*g_message(_("X Error: %s\n"), errtxt)*/;
132 g_error("X Error: %s", errtxt);
134 g_message("XError code %d '%s'", e->error_code, errtxt);
139 obt_display_error_occured = TRUE;
143 void obt_display_ignore_errors(gboolean ignore)
145 XSync(obt_display, FALSE);
146 xerror_ignore = ignore;
147 if (ignore) obt_display_error_occured = FALSE;