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-2008 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"
21 #include "obt/internal.h"
22 #include "obt/keyboard.h"
34 Display* obt_display = NULL;
36 gboolean obt_display_error_occured = FALSE;
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 gboolean obt_display_extension_composite = FALSE;
49 gint obt_display_extension_composite_basep;
51 static gint xerror_handler(Display *d, XErrorEvent *e);
53 static gboolean xerror_ignore = FALSE;
55 gboolean obt_display_open(const char *display_name)
60 n = display_name ? g_strdup(display_name) : NULL;
61 obt_display = d = XOpenDisplay(n);
66 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
67 g_message("Failed to set display as close-on-exec");
68 XSetErrorHandler(xerror_handler);
70 /* read what extensions are present */
72 obt_display_extension_xkb =
73 XkbQueryExtension(d, &junk,
74 &obt_display_extension_xkb_basep, &junk,
76 if (!obt_display_extension_xkb)
77 g_message("XKB extension is not present on the server");
81 obt_display_extension_shape =
82 XShapeQueryExtension(d, &obt_display_extension_shape_basep,
84 if (!obt_display_extension_shape)
85 g_message("X Shape extension is not present on the server");
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");
98 obt_display_extension_randr =
99 XRRQueryExtension(d, &obt_display_extension_randr_basep,
101 if (!obt_display_extension_randr)
102 g_message("XRandR extension is not present on the server");
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");
114 #ifdef USE_XCOMPOSITE
115 if (XCompositeQueryExtension(d, &obt_display_extension_composite_basep,
118 gint major = 0, minor = 2;
119 XCompositeQueryVersion(d, &major, &minor);
120 /* Version 0.2 is the first version to have the
121 XCompositeNameWindowPixmap() request. */
122 if (major > 0 || minor >= 2)
123 obt_display_extension_composite = TRUE;
125 if (!obt_display_extension_composite)
126 g_message("X Composite extension is not present on the server or "
127 "is an incompatible version");
131 obt_keyboard_reload();
135 return obt_display != NULL;
138 void obt_display_close()
140 obt_keyboard_shutdown();
141 if (obt_display) XCloseDisplay(obt_display);
144 static gint xerror_handler(Display *d, XErrorEvent *e)
149 XGetErrorText(d, e->error_code, errtxt, 127);
150 if (!xerror_ignore) {
151 if (e->error_code == BadWindow)
152 /*g_message(_("X Error: %s\n"), errtxt)*/;
154 g_error("X Error: %s", errtxt);
156 g_message("Ignoring XError code %d '%s'", e->error_code, errtxt);
161 obt_display_error_occured = TRUE;
165 void obt_display_ignore_errors(gboolean ignore)
167 XSync(obt_display, FALSE);
168 xerror_ignore = ignore;
169 if (ignore) obt_display_error_occured = FALSE;