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"
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
;
49 static gint
xerror_handler(Display
*d
, XErrorEvent
*e
);
51 static gboolean xerror_ignore
= FALSE
;
53 gboolean
obt_display_open(const char *display_name
)
58 n
= display_name
? g_strdup(display_name
) : NULL
;
59 obt_display
= d
= XOpenDisplay(n
);
61 gint junk
, major
, minor
;
62 (void)junk
, (void)major
, (void)minor
;
64 if (fcntl(ConnectionNumber(d
), F_SETFD
, 1) == -1)
65 g_message("Failed to set display as close-on-exec");
66 XSetErrorHandler(xerror_handler
);
68 /* read what extensions are present */
70 major
= XkbMajorVersion
;
71 minor
= XkbMinorVersion
;
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 or too old");
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");
115 obt_keyboard_reload();
119 return obt_display
!= NULL
;
122 void obt_display_close(void)
124 obt_keyboard_shutdown();
125 if (obt_display
) XCloseDisplay(obt_display
);
128 static gint
xerror_handler(Display
*d
, XErrorEvent
*e
)
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)*/;
138 g_error("X Error: %s", errtxt
);
140 g_debug("Ignoring XError code %d '%s'", e
->error_code
, errtxt
);
145 obt_display_error_occured
= TRUE
;
149 void obt_display_ignore_errors(gboolean ignore
)
151 XSync(obt_display
, FALSE
);
152 xerror_ignore
= ignore
;
153 if (ignore
) obt_display_error_occured
= FALSE
;