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"
31 gboolean obt_display_error_occured
= FALSE
;
33 gboolean obt_display_extension_xkb
= FALSE
;
34 gint obt_display_extension_xkb_basep
;
35 gboolean obt_display_extension_shape
= FALSE
;
36 gint obt_display_extension_shape_basep
;
37 gboolean obt_display_extension_xinerama
= FALSE
;
38 gint obt_display_extension_xinerama_basep
;
39 gboolean obt_display_extension_randr
= FALSE
;
40 gint obt_display_extension_randr_basep
;
41 gboolean obt_display_extension_sync
= FALSE
;
42 gint obt_display_extension_sync_basep
;
44 static gint
xerror_handler(Display
*d
, XErrorEvent
*e
);
46 static gboolean xerror_ignore
= FALSE
;
48 Display
* obt_display_open(const char *display_name
)
53 n
= display_name
? g_strdup(display_name
) : NULL
;
59 if (fcntl(ConnectionNumber(d
), F_SETFD
, 1) == -1)
60 g_message("Failed to set display as close-on-exec");
61 XSetErrorHandler(xerror_handler
);
63 /* read what extensions are present */
65 obt_display_extension_xkb
=
66 XkbQueryExtension(d
, &junk
,
67 &obt_display_extension_xkb_basep
, &junk
,
69 if (!obt_display_extension_xkb
)
70 g_message("XKB extension is not present on the server");
74 obt_display_extension_shape
=
75 XShapeQueryExtension(d
, &obt_display_extension_shape_basep
,
77 if (!obt_display_extension_shape
)
78 g_message("X Shape extension is not present on the server");
82 obt_display_extension_xinerama
=
83 XineramaQueryExtension(d
,
84 &obt_display_extension_xinerama_basep
,
85 &junk
) && XineramaIsActive(d
);
86 if (!obt_display_extension_xinerama
)
87 g_message("Xinerama extension is not present on the server");
91 obt_display_extension_randr
=
92 XRRQueryExtension(d
, &obt_display_extension_randr_basep
,
94 if (!obt_display_extension_randr
)
95 g_message("XRandR extension is not present on the server");
99 obt_display_extension_sync
=
100 XSyncQueryExtension(d
, &obt_display_extension_sync_basep
,
101 &junk
) && XSyncInitialize(d
, &junk
, &junk
);
102 if (!obt_display_extension_sync
)
103 g_message("X Sync extension is not present on the server or is an "
104 "incompatible version");
112 void obt_display_close(Display
*d
)
114 if (d
) XCloseDisplay(d
);
117 static gint
xerror_handler(Display
*d
, XErrorEvent
*e
)
122 XGetErrorText(d
, e
->error_code
, errtxt
, 127);
123 if (!xerror_ignore
) {
124 if (e
->error_code
== BadWindow
)
125 /*g_message(_("X Error: %s\n"), errtxt)*/;
127 g_error("X Error: %s", errtxt
);
129 g_message("XError code %d '%s'", e
->error_code
, errtxt
);
134 obt_display_error_occured
= TRUE
;
138 void obt_display_ignore_errors(Display
*d
, gboolean ignore
)
141 xerror_ignore
= ignore
;
142 if (ignore
) obt_display_error_occured
= FALSE
;