]> Dogcows Code - chaz/openbox/blob - obt/display.c
Button proper freeing/newing.
[chaz/openbox] / 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 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
54 static gint xerror_handler(Display *d, XErrorEvent *e);
55
56 static gboolean xerror_ignore = FALSE;
57
58 gboolean obt_display_open(const char *display_name)
59 {
60 gchar *n;
61 Display *d = NULL;
62
63 n = display_name ? g_strdup(display_name) : NULL;
64 obt_display = d = XOpenDisplay(n);
65 if (d) {
66 gint junk, major, minor;
67 (void)junk, (void)major, (void)minor;
68
69 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
70 g_message("Failed to set display as close-on-exec");
71 XSetErrorHandler(xerror_handler);
72
73 /* read what extensions are present */
74 #ifdef XKB
75 major = XkbMajorVersion;
76 minor = XkbMinorVersion;
77 obt_display_extension_xkb =
78 XkbQueryExtension(d, &junk,
79 &obt_display_extension_xkb_basep, &junk,
80 &major, &minor);
81 if (!obt_display_extension_xkb)
82 g_message("XKB extension is not present on the server or too old");
83 #endif
84
85 #ifdef SHAPE
86 obt_display_extension_shape =
87 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
88 &junk);
89 if (!obt_display_extension_shape)
90 g_message("X Shape extension is not present on the server");
91 #endif
92
93 #ifdef XINERAMA
94 obt_display_extension_xinerama =
95 XineramaQueryExtension(d,
96 &obt_display_extension_xinerama_basep,
97 &junk) && XineramaIsActive(d);
98 if (!obt_display_extension_xinerama)
99 g_message("Xinerama extension is not present on the server");
100 #endif
101
102 #ifdef XRANDR
103 obt_display_extension_randr =
104 XRRQueryExtension(d, &obt_display_extension_randr_basep,
105 &junk);
106 if (!obt_display_extension_randr)
107 g_message("XRandR extension is not present on the server");
108 #endif
109
110 #ifdef SYNC
111 obt_display_extension_sync =
112 XSyncQueryExtension(d, &obt_display_extension_sync_basep,
113 &junk) && XSyncInitialize(d, &junk, &junk);
114 if (!obt_display_extension_sync)
115 g_message("X Sync extension is not present on the server or is an "
116 "incompatible version");
117 #endif
118
119 obt_prop_startup();
120 obt_keyboard_reload();
121 }
122 g_free(n);
123
124 if (obt_display)
125 xqueue_init();
126
127 return obt_display != NULL;
128 }
129
130 void obt_display_close(void)
131 {
132 obt_keyboard_shutdown();
133 if (obt_display) {
134 xqueue_destroy();
135 XCloseDisplay(obt_display);
136 }
137 }
138
139 static gint xerror_handler(Display *d, XErrorEvent *e)
140 {
141 #ifdef DEBUG
142 gchar errtxt[128];
143
144 XGetErrorText(d, e->error_code, errtxt, 127);
145 if (!xerror_ignore) {
146 if (e->error_code == BadWindow)
147 /*g_debug(_("X Error: %s\n"), errtxt)*/;
148 else
149 g_error("X Error: %s", errtxt);
150 } else
151 g_debug("Ignoring XError code %d '%s'", e->error_code, errtxt);
152 #else
153 (void)d; (void)e;
154 #endif
155
156 obt_display_error_occured = TRUE;
157 return 0;
158 }
159
160 void obt_display_ignore_errors(gboolean ignore)
161 {
162 XSync(obt_display, FALSE);
163 xerror_ignore = ignore;
164 if (ignore) obt_display_error_occured = FALSE;
165 }
This page took 0.040449 seconds and 4 git commands to generate.