We use congfigure.ac not configure.am
[openbox.git] / obt / display.c
blob8b06cbfcf6cac47d213fe5a7ec33f12e6fbd1359
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 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"
20 #include "obt/prop.h"
21 #include "obt/internal.h"
22 #include "obt/keyboard.h"
23 #include "obt/xqueue.h"
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
35 /* from xqueue.c */
36 extern void xqueue_init(void);
37 extern void xqueue_destroy(void);
39 Display* obt_display = NULL;
41 gboolean obt_display_error_occured = FALSE;
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;
54 static gint xerror_handler(Display *d, XErrorEvent *e);
56 static gboolean xerror_ignore = FALSE;
58 gboolean obt_display_open(const char *display_name)
60 gchar *n;
61 Display *d = NULL;
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;
69 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
70 g_message("Failed to set display as close-on-exec");
71 XSetErrorHandler(xerror_handler);
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
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
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
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
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
119 obt_prop_startup();
120 obt_keyboard_reload();
122 g_free(n);
124 if (obt_display)
125 xqueue_init();
127 return obt_display != NULL;
130 void obt_display_close(void)
132 obt_keyboard_shutdown();
133 if (obt_display) {
134 xqueue_destroy();
135 XCloseDisplay(obt_display);
139 static gint xerror_handler(Display *d, XErrorEvent *e)
141 #ifdef DEBUG
142 gchar errtxt[128];
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
156 obt_display_error_occured = TRUE;
157 return 0;
160 void obt_display_ignore_errors(gboolean ignore)
162 XSync(obt_display, FALSE);
163 xerror_ignore = ignore;
164 if (ignore) obt_display_error_occured = FALSE;