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"
34 Display* obt_display = NULL;
36 gboolean obt_display_error_occured = FALSE;
38 gboolean obt_display_extension_xkb = FALSE;
39 gint obt_display_extension_xkb_basep;
40 gboolean obt_display_extension_shape = FALSE;
41 gint obt_display_extension_shape_basep;
42 gboolean obt_display_extension_xinerama = FALSE;
43 gint obt_display_extension_xinerama_basep;
44 gboolean obt_display_extension_randr = FALSE;
45 gint obt_display_extension_randr_basep;
46 gboolean obt_display_extension_sync = FALSE;
47 gint obt_display_extension_sync_basep;
48 gboolean obt_display_extension_composite = FALSE;
49 gint obt_display_extension_composite_basep;
50 gboolean obt_display_extension_damage = FALSE;
51 gint obt_display_extension_damage_basep;
52 gboolean obt_display_extension_render = FALSE;
53 gint obt_display_extension_render_basep;
54 gboolean obt_display_extension_fixes = FALSE;
55 gint obt_display_extension_fixes_basep;
57 static gint xerror_handler(Display *d, XErrorEvent *e);
59 static gboolean xerror_ignore = FALSE;
61 gboolean obt_display_open(const char *display_name)
66 n = display_name ? g_strdup(display_name) : NULL;
67 obt_display = d = XOpenDisplay(n);
72 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
73 g_message("Failed to set display as close-on-exec");
74 XSetErrorHandler(xerror_handler);
76 /* read what extensions are present */
78 obt_display_extension_xkb =
79 XkbQueryExtension(d, &junk,
80 &obt_display_extension_xkb_basep, &junk,
82 if (!obt_display_extension_xkb)
83 g_message("XKB extension is not present on the server");
87 obt_display_extension_shape =
88 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
90 if (!obt_display_extension_shape)
91 g_message("X Shape extension is not present on the server");
95 obt_display_extension_xinerama =
96 XineramaQueryExtension(d,
97 &obt_display_extension_xinerama_basep,
98 &junk) && XineramaIsActive(d);
99 if (!obt_display_extension_xinerama)
100 g_message("Xinerama extension is not present on the server");
104 obt_display_extension_randr =
105 XRRQueryExtension(d, &obt_display_extension_randr_basep,
107 if (!obt_display_extension_randr)
108 g_message("XRandR extension is not present on the server");
112 obt_display_extension_sync =
113 XSyncQueryExtension(d, &obt_display_extension_sync_basep,
114 &junk) && XSyncInitialize(d, &junk, &junk);
115 if (!obt_display_extension_sync)
116 g_message("X Sync extension is not present on the server");
119 #ifdef USE_COMPOSITING
120 if (XCompositeQueryExtension(d, &obt_display_extension_composite_basep,
123 gint major = 0, minor = 2;
124 XCompositeQueryVersion(d, &major, &minor);
125 /* Version 0.2 is the first version to have the
126 XCompositeNameWindowPixmap() request. */
127 if (major > 0 || minor >= 2)
128 obt_display_extension_composite = TRUE;
130 if (!obt_display_extension_composite)
131 g_message("X Composite extension is not present on the server or "
132 "is an incompatible version");
134 obt_display_extension_damage =
135 XDamageQueryExtension(d, &obt_display_extension_damage_basep,
137 if (!obt_display_extension_damage)
138 g_message("X Damage extension is not present on the server");
140 obt_display_extension_render =
141 XRenderQueryExtension(d, &obt_display_extension_render_basep,
143 if (!obt_display_extension_render)
144 g_message("X Render extension is not present on the server");
146 obt_display_extension_fixes =
147 XFixesQueryExtension(d, &obt_display_extension_fixes_basep,
149 if (!obt_display_extension_fixes)
150 g_message("X Fixes extension is not present on the server");
154 obt_keyboard_reload();
158 return obt_display != NULL;
161 void obt_display_close()
163 obt_keyboard_shutdown();
164 if (obt_display) XCloseDisplay(obt_display);
167 static gint xerror_handler(Display *d, XErrorEvent *e)
172 XGetErrorText(d, e->error_code, errtxt, 127);
173 if (!xerror_ignore) {
174 if (e->error_code == BadWindow)
175 /*g_message(_("X Error: %s\n"), errtxt)*/;
177 g_error("X Error: %s", errtxt);
179 g_message("Ignoring XError code %d '%s'", e->error_code, errtxt);
184 obt_display_error_occured = TRUE;
188 void obt_display_ignore_errors(gboolean ignore)
190 XSync(obt_display, FALSE);
191 xerror_ignore = ignore;
192 if (ignore) obt_display_error_occured = FALSE;