]> Dogcows Code - chaz/openbox/blob - obt/display.c
its OBT_VERSION not OB_VERSION anymore
[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;
62 (void)junk;
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 obt_display_extension_xkb =
71 XkbQueryExtension(d, &junk,
72 &obt_display_extension_xkb_basep, &junk,
73 NULL, NULL);
74 if (!obt_display_extension_xkb)
75 g_message("XKB extension is not present on the server");
76 #endif
77
78 #ifdef SHAPE
79 obt_display_extension_shape =
80 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
81 &junk);
82 if (!obt_display_extension_shape)
83 g_message("X Shape extension is not present on the server");
84 #endif
85
86 #ifdef XINERAMA
87 obt_display_extension_xinerama =
88 XineramaQueryExtension(d,
89 &obt_display_extension_xinerama_basep,
90 &junk) && XineramaIsActive(d);
91 if (!obt_display_extension_xinerama)
92 g_message("Xinerama extension is not present on the server");
93 #endif
94
95 #ifdef XRANDR
96 obt_display_extension_randr =
97 XRRQueryExtension(d, &obt_display_extension_randr_basep,
98 &junk);
99 if (!obt_display_extension_randr)
100 g_message("XRandR extension is not present on the server");
101 #endif
102
103 #ifdef SYNC
104 obt_display_extension_sync =
105 XSyncQueryExtension(d, &obt_display_extension_sync_basep,
106 &junk) && XSyncInitialize(d, &junk, &junk);
107 if (!obt_display_extension_sync)
108 g_message("X Sync extension is not present on the server or is an "
109 "incompatible version");
110 #endif
111
112 obt_prop_startup();
113 obt_keyboard_reload();
114 }
115 g_free(n);
116
117 return obt_display != NULL;
118 }
119
120 void obt_display_close()
121 {
122 obt_keyboard_shutdown();
123 if (obt_display) XCloseDisplay(obt_display);
124 }
125
126 static gint xerror_handler(Display *d, XErrorEvent *e)
127 {
128 #ifdef DEBUG
129 gchar errtxt[128];
130
131 XGetErrorText(d, e->error_code, errtxt, 127);
132 if (!xerror_ignore) {
133 if (e->error_code == BadWindow)
134 /*g_message(_("X Error: %s\n"), errtxt)*/;
135 else
136 g_error("X Error: %s", errtxt);
137 } else
138 g_message("XError code %d '%s'", e->error_code, errtxt);
139 #else
140 (void)d; (void)e;
141 #endif
142
143 obt_display_error_occured = TRUE;
144 return 0;
145 }
146
147 void obt_display_ignore_errors(gboolean ignore)
148 {
149 XSync(obt_display, FALSE);
150 xerror_ignore = ignore;
151 if (ignore) obt_display_error_occured = FALSE;
152 }
This page took 0.037054 seconds and 4 git commands to generate.