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"
23 #include "obt/xqueue.h"
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
)
63 n
= display_name
? g_strdup(display_name
) : NULL
;
64 obt_display
= d
= XOpenDisplay(n
);
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 */
75 major
= XkbMajorVersion
;
76 minor
= XkbMinorVersion
;
77 obt_display_extension_xkb
=
78 XkbQueryExtension(d
, &junk
,
79 &obt_display_extension_xkb_basep
, &junk
,
81 if (!obt_display_extension_xkb
)
82 g_message("XKB extension is not present on the server or too old");
86 obt_display_extension_shape
=
87 XShapeQueryExtension(d
, &obt_display_extension_shape_basep
,
89 if (!obt_display_extension_shape
)
90 g_message("X Shape extension is not present on the server");
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");
103 obt_display_extension_randr
=
104 XRRQueryExtension(d
, &obt_display_extension_randr_basep
,
106 if (!obt_display_extension_randr
)
107 g_message("XRandR extension is not present on the server");
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");
120 obt_keyboard_reload();
127 return obt_display
!= NULL
;
130 void obt_display_close(void)
132 obt_keyboard_shutdown();
135 XCloseDisplay(obt_display
);
139 static gint
xerror_handler(Display
*d
, XErrorEvent
*e
)
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)*/;
149 g_error("X Error: %s", errtxt
);
151 g_debug("Ignoring XError code %d '%s'", e
->error_code
, errtxt
);
156 obt_display_error_occured
= TRUE
;
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
;