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 gint obt_display_extension_damage_error;
58 gboolean obt_display_extension_render = FALSE;
59 gint obt_display_extension_render_basep;
60 gboolean obt_display_extension_fixes = FALSE;
61 gint obt_display_extension_fixes_basep;
63 static gint xerror_handler(Display *d, XErrorEvent *e);
65 static gboolean xerror_ignore = FALSE;
67 gboolean obt_display_open(const char *display_name)
72 n = display_name ? g_strdup(display_name) : NULL;
73 obt_display = d = XOpenDisplay(n);
75 gint junk, major, minor;
76 (void)junk, (void)major, (void)minor;
78 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
79 g_message("Failed to set display as close-on-exec");
80 XSetErrorHandler(xerror_handler);
82 /* read what extensions are present */
84 major = XkbMajorVersion;
85 minor = XkbMinorVersion;
86 obt_display_extension_xkb =
87 XkbQueryExtension(d, &junk,
88 &obt_display_extension_xkb_basep, &junk,
90 if (!obt_display_extension_xkb)
91 g_message("XKB extension is not present on the server or too old");
95 obt_display_extension_shape =
96 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
98 if (!obt_display_extension_shape)
99 g_message("X Shape extension is not present on the server");
103 obt_display_extension_xinerama =
104 XineramaQueryExtension(d,
105 &obt_display_extension_xinerama_basep,
106 &junk) && XineramaIsActive(d);
107 if (!obt_display_extension_xinerama)
108 g_message("Xinerama extension is not present on the server");
112 obt_display_extension_randr =
113 XRRQueryExtension(d, &obt_display_extension_randr_basep,
115 if (!obt_display_extension_randr)
116 g_message("XRandR extension is not present on the server");
120 obt_display_extension_sync =
121 XSyncQueryExtension(d, &obt_display_extension_sync_basep,
122 &junk) && XSyncInitialize(d, &junk, &junk);
123 if (!obt_display_extension_sync)
124 g_message("X Sync extension is not present on the server");
127 #ifdef USE_COMPOSITING
128 if (XCompositeQueryExtension(d, &obt_display_extension_composite_basep,
131 gint major = 0, minor = 2;
132 XCompositeQueryVersion(d, &major, &minor);
133 /* Version 0.2 is the first version to have the
134 XCompositeNameWindowPixmap() request. */
135 if (major > 0 || minor >= 2)
136 obt_display_extension_composite = TRUE;
138 if (!obt_display_extension_composite)
139 g_message("X Composite extension is not present on the server or "
140 "is an incompatible version");
142 obt_display_extension_damage =
143 XDamageQueryExtension(d, &obt_display_extension_damage_basep,
144 &obt_display_extension_damage_error);
145 if (!obt_display_extension_damage)
146 g_message("X Damage extension is not present on the server");
148 obt_display_extension_render =
149 XRenderQueryExtension(d, &obt_display_extension_render_basep,
151 if (!obt_display_extension_render)
152 g_message("X Render extension is not present on the server");
154 obt_display_extension_fixes =
155 XFixesQueryExtension(d, &obt_display_extension_fixes_basep,
157 if (!obt_display_extension_fixes)
158 g_message("X Fixes extension is not present on the server");
162 obt_keyboard_reload();
169 return obt_display != NULL;
172 void obt_display_close(void)
174 obt_keyboard_shutdown();
177 XCloseDisplay(obt_display);
181 static gint xerror_handler(Display *d, XErrorEvent *e)
186 XGetErrorText(d, e->error_code, errtxt, 127);
187 if (!xerror_ignore) {
188 if (e->error_code == BadWindow ||
189 (obt_display_extension_damage &&
190 e->error_code - obt_display_extension_damage_error == BadDamage))
192 /*g_error("X Error: %d '%s'", e->error_code, errtxt);*/
195 g_error("X Error: %s", errtxt);
197 g_debug("Ignoring XError code %d '%s'", e->error_code, errtxt);
202 obt_display_error_occured = TRUE;
206 void obt_display_ignore_errors(gboolean ignore)
208 XSync(obt_display, FALSE);
209 xerror_ignore = ignore;
210 if (ignore) obt_display_error_occured = FALSE;