]> icculus.org git repositories - dana/openbox.git/blob - obt/display.c
Check for compositing manager support requested, and the required components.
[dana/openbox.git] / obt / display.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    obt/display.c for the Openbox window manager
4    Copyright (c) 2007-2008   Dana Jansens
5
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.
10
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.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "obt/display.h"
20 #include "obt/prop.h"
21 #include "obt/internal.h"
22 #include "obt/keyboard.h"
23 #include "obt/xqueue.h"
24
25 #ifdef HAVE_STRING_H
26 #  include <string.h>
27 #endif
28 #ifdef HAVE_FCNTL_H
29 #  include <fcntl.h>
30 #endif
31 #ifdef HAVE_UNISTD_H
32 #  include <unistd.h>
33 #endif
34
35 /* from xqueue.c */
36 extern void xqueue_init(void);
37 extern void xqueue_destroy(void);
38
39 Display* obt_display = NULL;
40
41 gboolean obt_display_error_occured = FALSE;
42
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;
61
62 static gint xerror_handler(Display *d, XErrorEvent *e);
63
64 static gboolean xerror_ignore = FALSE;
65
66 gboolean obt_display_open(const char *display_name)
67 {
68     gchar *n;
69     Display *d = NULL;
70
71     n = display_name ? g_strdup(display_name) : NULL;
72     obt_display = d = XOpenDisplay(n);
73     if (d) {
74         gint junk, major, minor;
75         (void)junk, (void)major, (void)minor;
76
77         if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
78             g_message("Failed to set display as close-on-exec");
79         XSetErrorHandler(xerror_handler);
80
81         /* read what extensions are present */
82 #ifdef XKB
83         major = XkbMajorVersion;
84         minor = XkbMinorVersion;
85         obt_display_extension_xkb =
86             XkbQueryExtension(d, &junk,
87                               &obt_display_extension_xkb_basep, &junk,
88                               &major, &minor);
89         if (!obt_display_extension_xkb)
90             g_message("XKB extension is not present on the server or too old");
91 #endif
92
93 #ifdef SHAPE
94         obt_display_extension_shape =
95             XShapeQueryExtension(d, &obt_display_extension_shape_basep,
96                                  &junk);
97         if (!obt_display_extension_shape)
98             g_message("X Shape extension is not present on the server");
99 #endif
100
101 #ifdef XINERAMA
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");
108 #endif
109
110 #ifdef XRANDR
111         obt_display_extension_randr =
112             XRRQueryExtension(d, &obt_display_extension_randr_basep,
113                               &junk);
114         if (!obt_display_extension_randr)
115             g_message("XRandR extension is not present on the server");
116 #endif
117
118 #ifdef SYNC
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");
124 #endif
125
126 #ifdef USE_COMPOSITING
127         if (XCompositeQueryExtension(d, &obt_display_extension_composite_basep,
128                                      &junk))
129         {
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;
136         }
137         if (!obt_display_extension_composite)
138             g_message("X Composite extension is not present on the server or "
139                       "is an incompatible version");
140
141         obt_display_extension_damage =
142             XDamageQueryExtension(d, &obt_display_extension_damage_basep,
143                                   &junk);
144         if (!obt_display_extension_damage)
145             g_message("X Damage extension is not present on the server");
146
147         obt_display_extension_render =
148             XRenderQueryExtension(d, &obt_display_extension_render_basep,
149                                   &junk);
150         if (!obt_display_extension_render)
151             g_message("X Render extension is not present on the server");
152
153         obt_display_extension_fixes =
154             XFixesQueryExtension(d, &obt_display_extension_fixes_basep,
155                                   &junk);
156         if (!obt_display_extension_fixes)
157             g_message("X Fixes extension is not present on the server");
158 #endif
159
160         obt_prop_startup();
161         obt_keyboard_reload();
162     }
163     g_free(n);
164
165     if (obt_display)
166         xqueue_init();
167
168     return obt_display != NULL;
169 }
170
171 void obt_display_close(void)
172 {
173     obt_keyboard_shutdown();
174     if (obt_display) {
175         xqueue_destroy();
176         XCloseDisplay(obt_display);
177     }
178 }
179
180 static gint xerror_handler(Display *d, XErrorEvent *e)
181 {
182 #ifdef DEBUG
183     gchar errtxt[128];
184
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)*/;
189         else
190             g_error("X Error: %s", errtxt);
191     } else
192         g_debug("Ignoring XError code %d '%s'", e->error_code, errtxt);
193 #else
194     (void)d; (void)e;
195 #endif
196
197     obt_display_error_occured = TRUE;
198     return 0;
199 }
200
201 void obt_display_ignore_errors(gboolean ignore)
202 {
203     XSync(obt_display, FALSE);
204     xerror_ignore = ignore;
205     if (ignore) obt_display_error_occured = FALSE;
206 }