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
);
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 obt_display_extension_xkb
=
71 XkbQueryExtension(d
, &junk
,
72 &obt_display_extension_xkb_basep
, &junk
,
74 if (!obt_display_extension_xkb
)
75 g_message("XKB extension is not present on the server");
79 obt_display_extension_shape
=
80 XShapeQueryExtension(d
, &obt_display_extension_shape_basep
,
82 if (!obt_display_extension_shape
)
83 g_message("X Shape extension is not present on the server");
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");
96 obt_display_extension_randr
=
97 XRRQueryExtension(d
, &obt_display_extension_randr_basep
,
99 if (!obt_display_extension_randr
)
100 g_message("XRandR extension is not present on the server");
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");
113 obt_keyboard_reload();
117 return obt_display
!= NULL
;
120 void obt_display_close()
122 obt_keyboard_shutdown();
123 if (obt_display
) XCloseDisplay(obt_display
);
126 static gint
xerror_handler(Display
*d
, XErrorEvent
*e
)
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)*/;
136 g_error("X Error: %s", errtxt
);
138 g_message("XError code %d '%s'", e
->error_code
, errtxt
);
143 obt_display_error_occured
= TRUE
;
147 void obt_display_ignore_errors(gboolean ignore
)
149 XSync(obt_display
, FALSE
);
150 xerror_ignore
= ignore
;
151 if (ignore
) obt_display_error_occured
= FALSE
;