15 #include "x11GraphicsPipe.h"
16 #include "x11GraphicsWindow.h"
17 #include "config_x11display.h"
18 #include "frameBufferProperties.h"
22 bool x11GraphicsPipe::_error_handlers_installed =
false;
23 x11GraphicsPipe::ErrorHandlerFunc *x11GraphicsPipe::_prev_error_handler;
24 x11GraphicsPipe::IOErrorHandlerFunc *x11GraphicsPipe::_prev_io_error_handler;
25 bool x11GraphicsPipe::_x_error_messages_enabled =
true;
26 int x11GraphicsPipe::_x_error_count = 0;
36 x11GraphicsPipe(
const string &display) {
37 string display_spec = display;
38 if (display_spec.empty()) {
39 display_spec = display_cfg;
41 if (display_spec.empty()) {
44 if (display_spec.empty()) {
45 display_spec =
":0.0";
50 setlocale(LC_ALL,
"");
55 setlocale(LC_NUMERIC,
"C");
58 _supported_types = OT_window | OT_buffer | OT_texture_buffer;
61 _root = (X11_Window)NULL;
63 _hidden_cursor = None;
65 install_error_handlers();
67 _display = XOpenDisplay(display_spec.c_str());
69 x11display_cat.error()
70 <<
"Could not open display \"" << display_spec <<
"\".\n";
79 if (!XSupportsLocale()) {
80 x11display_cat.warning()
81 <<
"X does not support locale " << setlocale(LC_ALL, NULL) <<
"\n";
83 XSetLocaleModifiers(
"");
85 _screen = DefaultScreen(_display);
86 _root = RootWindow(_display, _screen);
87 _display_width = DisplayWidth(_display, _screen);
88 _display_height = DisplayHeight(_display, _screen);
93 int num_sizes, num_rates;
95 xrrs = XRRSizes(_display, 0, &num_sizes);
96 _display_information->_total_display_modes = 0;
97 for (
int i = 0; i < num_sizes; ++i) {
98 XRRRates(_display, 0, i, &num_rates);
99 _display_information->_total_display_modes += num_rates;
104 _display_information->_display_mode_array =
new DisplayMode[_display_information->_total_display_modes];
105 for (
int i = 0; i < num_sizes; ++i) {
107 rates = XRRRates(_display, 0, i, &num_rates);
108 for (
int j = 0; j < num_rates; ++j) {
109 DisplayMode* dm = _display_information->_display_mode_array + counter;
110 dm->width = xrrs[i].width;
111 dm->height = xrrs[i].height;
112 dm->refresh_rate = rates[j];
113 dm->bits_per_pixel = -1;
114 dm->fullscreen_only =
false;
122 _im = XOpenIM(_display, NULL, NULL, NULL);
123 if (_im == (XIM)NULL) {
124 x11display_cat.warning()
125 <<
"Couldn't open input method.\n";
142 _wm_delete_window = XInternAtom(_display,
"WM_DELETE_WINDOW",
false);
143 _net_wm_pid = XInternAtom(_display,
"_NET_WM_PID",
false);
144 _net_wm_window_type = XInternAtom(_display,
"_NET_WM_WINDOW_TYPE",
false);
145 _net_wm_window_type_splash = XInternAtom(_display,
"_NET_WM_WINDOW_TYPE_SPLASH",
false);
146 _net_wm_window_type_fullscreen = XInternAtom(_display,
"_NET_WM_WINDOW_TYPE_FULLSCREEN",
false);
147 _net_wm_state = XInternAtom(_display,
"_NET_WM_STATE",
false);
148 _net_wm_state_fullscreen = XInternAtom(_display,
"_NET_WM_STATE_FULLSCREEN",
false);
149 _net_wm_state_above = XInternAtom(_display,
"_NET_WM_STATE_ABOVE",
false);
150 _net_wm_state_below = XInternAtom(_display,
"_NET_WM_STATE_BELOW",
false);
151 _net_wm_state_add = XInternAtom(_display,
"_NET_WM_STATE_ADD",
false);
152 _net_wm_state_remove = XInternAtom(_display,
"_NET_WM_STATE_REMOVE",
false);
162 release_hidden_cursor();
167 XCloseDisplay(_display);
179 GraphicsPipe::PreferredWindowThread
201 void x11GraphicsPipe::
202 make_hidden_cursor() {
203 nassertv(_hidden_cursor == None);
205 unsigned int x_size, y_size;
206 XQueryBestCursor(_display, _root, 1, 1, &x_size, &y_size);
208 Pixmap empty = XCreatePixmap(_display, _root, x_size, y_size, 1);
211 memset(&black, 0,
sizeof(black));
213 _hidden_cursor = XCreatePixmapCursor(_display, empty, empty,
214 &black, &black, x_size, y_size);
215 XFreePixmap(_display, empty);
224 void x11GraphicsPipe::
225 release_hidden_cursor() {
226 if (_hidden_cursor != None) {
227 XFreeCursor(_display, _hidden_cursor);
228 _hidden_cursor = None;
243 void x11GraphicsPipe::
244 install_error_handlers() {
245 if (_error_handlers_installed) {
249 _prev_error_handler = (ErrorHandlerFunc *)XSetErrorHandler(error_handler);
250 _prev_io_error_handler = (IOErrorHandlerFunc *)XSetIOErrorHandler(io_error_handler);
251 _error_handlers_installed =
true;
260 int x11GraphicsPipe::
261 error_handler(X11_Display *display, XErrorEvent *error) {
264 static const int msg_len = 80;
266 XGetErrorText(display, error->error_code, msg, msg_len);
268 if (!_x_error_messages_enabled) {
269 if (x11display_cat.is_debug()) {
270 x11display_cat.debug()
276 x11display_cat.error()
294 int x11GraphicsPipe::
295 io_error_handler(X11_Display *display) {
296 x11display_cat.fatal()
297 <<
"X fatal error on display " << (
void *)display <<
"\n";
A lightweight reentrant mutex.
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
static string get_environment_variable(const string &var)
Returns the definition of the indicated environment variable, or the empty string if the variable is ...
TypeHandle is the identifier used to differentiate C++ class types.