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