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-2008 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"
21 #include "obt/internal.h"
22 #include "obt/keyboard.h"
23 #include "obt/xqueue.h"
36 extern void xqueue_init(void);
37 extern void xqueue_destroy(void);
39 Display* obt_display = NULL;
41 gboolean obt_display_error_occured = FALSE;
43 gboolean obt_display_extension_xkb = FALSE;
44 gint obt_display_extension_xkb_basep;
45 gboolean obt_display_extension_shape = FALSE;
46 gint obt_display_extension_shape_basep;
47 gboolean obt_display_extension_xinerama = FALSE;
48 gint obt_display_extension_xinerama_basep;
49 gboolean obt_display_extension_randr = FALSE;
50 gint obt_display_extension_randr_basep;
51 gboolean obt_display_extension_sync = FALSE;
52 gint obt_display_extension_sync_basep;
53 gboolean obt_display_extension_composite = FALSE;
54 gint obt_display_extension_composite_basep;
55 gboolean obt_display_extension_damage = FALSE;
56 gint obt_display_extension_damage_basep;
57 gboolean obt_display_extension_render = FALSE;
58 gint obt_display_extension_render_basep;
59 gboolean obt_display_extension_fixes = FALSE;
60 gint obt_display_extension_fixes_basep;
62 static gint xerror_handler(Display *d, XErrorEvent *e);
64 static gboolean xerror_ignore = FALSE;
66 gboolean obt_display_open(const char *display_name)
71 n = display_name ? g_strdup(display_name) : NULL;
72 obt_display = d = XOpenDisplay(n);
74 gint junk, major, minor;
75 (void)junk, (void)major, (void)minor;
77 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
78 g_message("Failed to set display as close-on-exec");
79 XSetErrorHandler(xerror_handler);
81 /* read what extensions are present */
83 major = XkbMajorVersion;
84 minor = XkbMinorVersion;
85 obt_display_extension_xkb =
86 XkbQueryExtension(d, &junk,
87 &obt_display_extension_xkb_basep, &junk,
89 if (!obt_display_extension_xkb)
90 g_message("XKB extension is not present on the server or too old");
94 obt_display_extension_shape =
95 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
97 if (!obt_display_extension_shape)
98 g_message("X Shape extension is not present on the server");
102 obt_display_extension_xinerama =
103 XineramaQueryExtension(d,
104 &obt_display_extension_xinerama_basep,
105 &junk) && XineramaIsActive(d);
106 if (!obt_display_extension_xinerama)
107 g_message("Xinerama extension is not present on the server");
111 obt_display_extension_randr =
112 XRRQueryExtension(d, &obt_display_extension_randr_basep,
114 if (!obt_display_extension_randr)
115 g_message("XRandR extension is not present on the server");
119 obt_display_extension_sync =
120 XSyncQueryExtension(d, &obt_display_extension_sync_basep,
121 &junk) && XSyncInitialize(d, &junk, &junk);
122 if (!obt_display_extension_sync)
123 g_message("X Sync extension is not present on the server");
126 #ifdef USE_COMPOSITING
127 if (XCompositeQueryExtension(d, &obt_display_extension_composite_basep,
130 gint major = 0, minor = 2;
131 XCompositeQueryVersion(d, &major, &minor);
132 /* Version 0.2 is the first version to have the
133 XCompositeNameWindowPixmap() request. */
134 if (major > 0 || minor >= 2)
135 obt_display_extension_composite = TRUE;
137 if (!obt_display_extension_composite)
138 g_message("X Composite extension is not present on the server or "
139 "is an incompatible version");
141 obt_display_extension_damage =
142 XDamageQueryExtension(d, &obt_display_extension_damage_basep,
144 if (!obt_display_extension_damage)
145 g_message("X Damage extension is not present on the server");
147 obt_display_extension_render =
148 XRenderQueryExtension(d, &obt_display_extension_render_basep,
150 if (!obt_display_extension_render)
151 g_message("X Render extension is not present on the server");
153 obt_display_extension_fixes =
154 XFixesQueryExtension(d, &obt_display_extension_fixes_basep,
156 if (!obt_display_extension_fixes)
157 g_message("X Fixes extension is not present on the server");
161 obt_keyboard_reload();
168 return obt_display != NULL;
171 void obt_display_close(void)
173 obt_keyboard_shutdown();
176 XCloseDisplay(obt_display);
180 static gint xerror_handler(Display *d, XErrorEvent *e)
185 XGetErrorText(d, e->error_code, errtxt, 127);
186 if (!xerror_ignore) {
187 if (e->error_code == BadWindow)
188 /*g_debug(_("X Error: %s\n"), errtxt)*/;
190 g_error("X Error: %s", errtxt);
192 g_debug("Ignoring XError code %d '%s'", e->error_code, errtxt);
197 obt_display_error_occured = TRUE;
201 void obt_display_ignore_errors(gboolean ignore)
203 XSync(obt_display, FALSE);
204 xerror_ignore = ignore;
205 if (ignore) obt_display_error_occured = FALSE;