]> Dogcows Code - chaz/openbox/blob - src/BaseDisplay.cc
confine the mouse to the window for button grabs so that alt-click-drag on a window...
[chaz/openbox] / src / BaseDisplay.cc
1 // BaseDisplay.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef HAVE_CONFIG_H
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include <X11/Xlib.h>
34 #include <X11/Xatom.h>
35 #include <X11/Xutil.h>
36 #include <X11/cursorfont.h>
37 #include <X11/keysym.h>
38
39 #ifdef SHAPE
40 # include <X11/extensions/shape.h>
41 #endif // SHAPE
42
43 #ifdef HAVE_FCNTL_H
44 # include <fcntl.h>
45 #endif // HAVE_FCNTL_H
46
47 #ifdef HAVE_STDIO_H
48 # include <stdio.h>
49 #endif // HAVE_STDIO_H
50
51 #ifdef HAVE_STDLIB_H
52 # include <stdlib.h>
53 #endif // HAVE_STDLIB_H
54
55 #ifdef HAVE_STRING_H
56 # include <string.h>
57 #endif // HAVE_STRING_H
58
59 #ifdef HAVE_UNISTD_H
60 # include <sys/types.h>
61 # include <unistd.h>
62 #endif // HAVE_UNISTD_H
63
64 #ifdef HAVE_SYS_SELECT_H
65 # include <sys/select.h>
66 #endif // HAVE_SYS_SELECT_H
67
68 #ifdef HAVE_SIGNAL_H
69 # include <signal.h>
70 #endif // HAVE_SIGNAL_H
71
72 #ifndef SA_NODEFER
73 # ifdef SA_INTERRUPT
74 # define SA_NODEFER SA_INTERRUPT
75 # else // !SA_INTERRUPT
76 # define SA_NODEFER (0)
77 # endif // SA_INTERRUPT
78 #endif // SA_NODEFER
79
80 #ifdef HAVE_SYS_WAIT_H
81 # include <sys/types.h>
82 # include <sys/wait.h>
83 #endif // HAVE_SYS_WAIT_H
84
85 #if defined(HAVE_PROCESS_H) && defined(__EMX__)
86 # include <process.h>
87 #endif // HAVE_PROCESS_H __EMX__
88
89 #include "i18n.h"
90 #include "BaseDisplay.h"
91 #include "Timer.h"
92
93 #include <algorithm>
94
95 // X error handler to handle any and all X errors while the application is
96 // running
97 static Bool internal_error = False;
98 static Window last_bad_window = None;
99
100 BaseDisplay *base_display;
101
102 static int handleXErrors(Display *d, XErrorEvent *e) {
103 #ifdef DEBUG
104 char errtxt[128];
105
106 XGetErrorText(d, e->error_code, errtxt, 128);
107 fprintf(stderr, i18n->getMessage(BaseDisplaySet, BaseDisplayXError,
108 "%s: X error: %s(%d) opcodes %d/%d\n resource 0x%lx\n"),
109 base_display->getApplicationName(), errtxt, e->error_code,
110 e->request_code, e->minor_code, e->resourceid);
111 #endif // DEBUG
112
113 if (e->error_code == BadWindow) last_bad_window = e->resourceid;
114 if (internal_error) abort();
115
116 return(False);
117 }
118
119
120 // signal handler to allow for proper and gentle shutdown
121
122 #ifndef HAVE_SIGACTION
123 static RETSIGTYPE signalhandler(int sig) {
124 #else // HAVE_SIGACTION
125 static void signalhandler(int sig) {
126 #endif // HAVE_SIGACTION
127
128 static int re_enter = 0;
129
130 switch (sig) {
131 case SIGCHLD:
132 int status;
133 waitpid(-1, &status, WNOHANG | WUNTRACED);
134
135 #ifndef HAVE_SIGACTION
136 // assume broken, braindead sysv signal semantics
137 signal(SIGCHLD, (RETSIGTYPE (*)(int)) signalhandler);
138 #endif // HAVE_SIGACTION
139
140 break;
141
142 default:
143 if (base_display->handleSignal(sig)) {
144
145 #ifndef HAVE_SIGACTION
146 // assume broken, braindead sysv signal semantics
147 signal(sig, (RETSIGTYPE (*)(int)) signalhandler);
148 #endif // HAVE_SIGACTION
149
150 return;
151 }
152
153 fprintf(stderr, i18n->getMessage(BaseDisplaySet, BaseDisplaySignalCaught,
154 "%s: signal %d caught\n"),
155 base_display->getApplicationName(), sig);
156
157 if (! base_display->isStartup() && ! re_enter) {
158 internal_error = True;
159
160 re_enter = 1;
161 fprintf(stderr, i18n->getMessage(BaseDisplaySet, BaseDisplayShuttingDown,
162 "shutting down\n"));
163 base_display->shutdown();
164 }
165
166 if (sig != SIGTERM && sig != SIGINT) {
167 fprintf(stderr, i18n->getMessage(BaseDisplaySet, BaseDisplayAborting,
168 "aborting... dumping core\n"));
169 abort();
170 }
171
172 exit(0);
173
174 break;
175 }
176 }
177
178
179 // convenience functions
180 #ifndef __EMX__
181 void bexec(const char *command, char* displaystring) {
182 if (! fork()) {
183 setsid();
184 putenv(displaystring);
185 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
186 exit(0);
187 }
188 }
189 #endif // !__EMX__
190
191 char *bstrdup(const char *s) {
192 const int l = strlen(s) + 1;
193 char *n = new char[l];
194 strncpy(n, s, l);
195 return n;
196 }
197
198 BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) {
199 application_name = bstrdup(app_name);
200
201 _startup = True;
202 _shutdown = False;
203 server_grabs = 0;
204 last_bad_window = None;
205
206 ::base_display = this;
207
208 #ifdef HAVE_SIGACTION
209 struct sigaction action;
210
211 action.sa_handler = signalhandler;
212 action.sa_mask = sigset_t();
213 action.sa_flags = SA_NOCLDSTOP | SA_NODEFER;
214
215 sigaction(SIGPIPE, &action, NULL);
216 sigaction(SIGSEGV, &action, NULL);
217 sigaction(SIGFPE, &action, NULL);
218 sigaction(SIGTERM, &action, NULL);
219 sigaction(SIGINT, &action, NULL);
220 sigaction(SIGCHLD, &action, NULL);
221 sigaction(SIGHUP, &action, NULL);
222 sigaction(SIGUSR1, &action, NULL);
223 sigaction(SIGUSR2, &action, NULL);
224 #else // !HAVE_SIGACTION
225 signal(SIGPIPE, (RETSIGTYPE (*)(int)) signalhandler);
226 signal(SIGSEGV, (RETSIGTYPE (*)(int)) signalhandler);
227 signal(SIGFPE, (RETSIGTYPE (*)(int)) signalhandler);
228 signal(SIGTERM, (RETSIGTYPE (*)(int)) signalhandler);
229 signal(SIGINT, (RETSIGTYPE (*)(int)) signalhandler);
230 signal(SIGUSR1, (RETSIGTYPE (*)(int)) signalhandler);
231 signal(SIGUSR2, (RETSIGTYPE (*)(int)) signalhandler);
232 signal(SIGHUP, (RETSIGTYPE (*)(int)) signalhandler);
233 signal(SIGCHLD, (RETSIGTYPE (*)(int)) signalhandler);
234 #endif // HAVE_SIGACTION
235
236 if (! (display = XOpenDisplay(dpy_name))) {
237 fprintf(stderr, i18n->getMessage(BaseDisplaySet, BaseDisplayXConnectFail,
238 "BaseDisplay::BaseDisplay: connection to X server failed.\n"));
239 ::exit(2);
240 } else if (fcntl(ConnectionNumber(display), F_SETFD, 1) == -1) {
241 fprintf(stderr,
242 i18n->getMessage(BaseDisplaySet, BaseDisplayCloseOnExecFail,
243 "BaseDisplay::BaseDisplay: couldn't mark display connection "
244 "as close-on-exec\n"));
245 ::exit(2);
246 }
247
248 number_of_screens = ScreenCount(display);
249 display_name = XDisplayName(dpy_name);
250
251 #ifdef SHAPE
252 shape.extensions = XShapeQueryExtension(display, &shape.event_basep,
253 &shape.error_basep);
254 #else // !SHAPE
255 shape.extensions = False;
256 #endif // SHAPE
257
258 xa_wm_colormap_windows =
259 XInternAtom(display, "WM_COLORMAP_WINDOWS", False);
260 xa_wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
261 xa_wm_state = XInternAtom(display, "WM_STATE", False);
262 xa_wm_change_state = XInternAtom(display, "WM_CHANGE_STATE", False);
263 xa_wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
264 xa_wm_take_focus = XInternAtom(display, "WM_TAKE_FOCUS", False);
265 motif_wm_hints = XInternAtom(display, "_MOTIF_WM_HINTS", False);
266
267 openbox_hints = XInternAtom(display, "_BLACKBOX_HINTS", False);
268 openbox_attributes = XInternAtom(display, "_BLACKBOX_ATTRIBUTES", False);
269 openbox_change_attributes =
270 XInternAtom(display, "_BLACKBOX_CHANGE_ATTRIBUTES", False);
271
272 openbox_structure_messages =
273 XInternAtom(display, "_BLACKBOX_STRUCTURE_MESSAGES", False);
274 openbox_notify_startup =
275 XInternAtom(display, "_BLACKBOX_NOTIFY_STARTUP", False);
276 openbox_notify_window_add =
277 XInternAtom(display, "_BLACKBOX_NOTIFY_WINDOW_ADD", False);
278 openbox_notify_window_del =
279 XInternAtom(display, "_BLACKBOX_NOTIFY_WINDOW_DEL", False);
280 openbox_notify_current_workspace =
281 XInternAtom(display, "_BLACKBOX_NOTIFY_CURRENT_WORKSPACE", False);
282 openbox_notify_workspace_count =
283 XInternAtom(display, "_BLACKBOX_NOTIFY_WORKSPACE_COUNT", False);
284 openbox_notify_window_focus =
285 XInternAtom(display, "_BLACKBOX_NOTIFY_WINDOW_FOCUS", False);
286 openbox_notify_window_raise =
287 XInternAtom(display, "_BLACKBOX_NOTIFY_WINDOW_RAISE", False);
288 openbox_notify_window_lower =
289 XInternAtom(display, "_BLACKBOX_NOTIFY_WINDOW_LOWER", False);
290
291 openbox_change_workspace =
292 XInternAtom(display, "_BLACKBOX_CHANGE_WORKSPACE", False);
293 openbox_change_window_focus =
294 XInternAtom(display, "_BLACKBOX_CHANGE_WINDOW_FOCUS", False);
295 openbox_cycle_window_focus =
296 XInternAtom(display, "_BLACKBOX_CYCLE_WINDOW_FOCUS", False);
297
298 #ifdef NEWWMSPEC
299
300 net_supported = XInternAtom(display, "_NET_SUPPORTED", False);
301 net_client_list = XInternAtom(display, "_NET_CLIENT_LIST", False);
302 net_client_list_stacking = XInternAtom(display, "_NET_CLIENT_LIST_STACKING", False);
303 net_number_of_desktops = XInternAtom(display, "_NET_NUMBER_OF_DESKTOPS", False);
304 net_desktop_geometry = XInternAtom(display, "_NET_DESKTOP_GEOMETRY", False);
305 net_desktop_viewport = XInternAtom(display, "_NET_DESKTOP_VIEWPORT", False);
306 net_current_desktop = XInternAtom(display, "_NET_CURRENT_DESKTOP", False);
307 net_desktop_names = XInternAtom(display, "_NET_DESKTOP_NAMES", False);
308 net_active_window = XInternAtom(display, "_NET_ACTIVE_WINDOW", False);
309 net_workarea = XInternAtom(display, "_NET_WORKAREA", False);
310 net_supporting_wm_check = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
311 net_virtual_roots = XInternAtom(display, "_NET_VIRTUAL_ROOTS", False);
312
313 net_close_window = XInternAtom(display, "_NET_CLOSE_WINDOW", False);
314 net_wm_moveresize = XInternAtom(display, "_NET_WM_MOVERESIZE", False);
315
316 net_properties = XInternAtom(display, "_NET_PROPERTIES", False);
317 net_wm_name = XInternAtom(display, "_NET_WM_NAME", False);
318 net_wm_desktop = XInternAtom(display, "_NET_WM_DESKTOP", False);
319 net_wm_window_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
320 net_wm_state = XInternAtom(display, "_NET_WM_STATE", False);
321 net_wm_strut = XInternAtom(display, "_NET_WM_STRUT", False);
322 net_wm_icon_geometry = XInternAtom(display, "_NET_WM_ICON_GEOMETRY", False);
323 net_wm_icon = XInternAtom(display, "_NET_WM_ICON", False);
324 net_wm_pid = XInternAtom(display, "_NET_WM_PID", False);
325 net_wm_handled_icons = XInternAtom(display, "_NET_WM_HANDLED_ICONS", False);
326
327 net_wm_ping = XInternAtom(display, "_NET_WM_PING", False);
328
329 #endif // NEWWMSPEC
330
331 cursor.session = XCreateFontCursor(display, XC_left_ptr);
332 cursor.move = XCreateFontCursor(display, XC_fleur);
333 cursor.ll_angle = XCreateFontCursor(display, XC_ll_angle);
334 cursor.lr_angle = XCreateFontCursor(display, XC_lr_angle);
335 cursor.ul_angle = XCreateFontCursor(display, XC_ul_angle);
336 cursor.ur_angle = XCreateFontCursor(display, XC_ur_angle);
337
338 XSetErrorHandler((XErrorHandler) handleXErrors);
339
340 screenInfoList.reserve(ScreenCount(display));
341 for (unsigned int s = 0; s < number_of_screens; s++)
342 screenInfoList.push_back(new ScreenInfo(*this, s));
343
344 #ifndef NOCLOBBER
345 NumLockMask = ScrollLockMask = 0;
346
347 const XModifierKeymap* const modmap = XGetModifierMapping(display);
348 if (modmap && modmap->max_keypermod > 0) {
349 const int mask_table[] = {
350 ShiftMask, LockMask, ControlMask, Mod1Mask,
351 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
352 };
353 const size_t size = (sizeof(mask_table) / sizeof(mask_table[0])) *
354 modmap->max_keypermod;
355 // get the values of the keyboard lock modifiers
356 // Note: Caps lock is not retrieved the same way as Scroll and Num lock
357 // since it doesn't need to be.
358 const KeyCode num_lock_code = XKeysymToKeycode(display, XK_Num_Lock);
359 const KeyCode scroll_lock_code = XKeysymToKeycode(display, XK_Scroll_Lock);
360
361 for (size_t cnt = 0; cnt < size; ++cnt) {
362 if (! modmap->modifiermap[cnt]) continue;
363
364 if (num_lock_code == modmap->modifiermap[cnt])
365 NumLockMask = mask_table[cnt / modmap->max_keypermod];
366 if (scroll_lock_code == modmap->modifiermap[cnt])
367 ScrollLockMask = mask_table[cnt / modmap->max_keypermod];
368 }
369 }
370
371 MaskList[0] = 0;
372 MaskList[1] = LockMask;
373 MaskList[2] = NumLockMask;
374 MaskList[3] = ScrollLockMask;
375 MaskList[4] = LockMask | NumLockMask;
376 MaskList[5] = NumLockMask | ScrollLockMask;
377 MaskList[6] = LockMask | ScrollLockMask;
378 MaskList[7] = LockMask | NumLockMask | ScrollLockMask;
379 MaskListLength = sizeof(MaskList) / sizeof(MaskList[0]);
380
381 if (modmap) XFreeModifiermap(const_cast<XModifierKeymap*>(modmap));
382 #else
383 NumLockMask = Mod2Mask;
384 ScrollLockMask = Mod5Mask;
385 #endif // NOCLOBBER
386 }
387
388
389 BaseDisplay::~BaseDisplay(void) {
390 std::for_each(screenInfoList.begin(), screenInfoList.end(),
391 PointerAssassin());
392 // we don't create the BTimers, we don't delete them
393
394 if (application_name != NULL)
395 delete [] application_name;
396
397 XCloseDisplay(display);
398 }
399
400
401 void BaseDisplay::eventLoop(void) {
402 run();
403
404 int xfd = ConnectionNumber(display);
405
406 while ((! _shutdown) && (! internal_error)) {
407 if (XPending(display)) {
408 XEvent e;
409 XNextEvent(display, &e);
410
411 if (last_bad_window != None && e.xany.window == last_bad_window) {
412 #ifdef DEBUG
413 fprintf(stderr, i18n->getMessage(BaseDisplaySet,
414 BaseDisplayBadWindowRemove,
415 "BaseDisplay::eventLoop(): removing bad window "
416 "from event queue\n"));
417 #endif // DEBUG
418 } else {
419 last_bad_window = None;
420 process_event(&e);
421 }
422 } else {
423 fd_set rfds;
424 timeval now, tm, *timeout = (timeval *) 0;
425
426 FD_ZERO(&rfds);
427 FD_SET(xfd, &rfds);
428
429 if (!timerList.empty()) {
430 gettimeofday(&now, 0);
431
432 tm.tv_sec = tm.tv_usec = 0l;
433
434 BTimer *timer = timerList.front();
435 ASSERT(timer != NULL);
436
437 tm.tv_sec = timer->getStartTime().tv_sec +
438 timer->getTimeout().tv_sec - now.tv_sec;
439 tm.tv_usec = timer->getStartTime().tv_usec +
440 timer->getTimeout().tv_usec - now.tv_usec;
441
442 while (tm.tv_usec >= 1000000) {
443 tm.tv_sec++;
444 tm.tv_usec -= 1000000;
445 }
446
447 while (tm.tv_usec < 0) {
448 if (tm.tv_sec > 0) {
449 tm.tv_sec--;
450 tm.tv_usec += 1000000;
451 } else {
452 tm.tv_usec = 0;
453 break;
454 }
455 }
456
457 timeout = &tm;
458 }
459
460 select(xfd + 1, &rfds, 0, 0, timeout);
461
462 // check for timer timeout
463 gettimeofday(&now, 0);
464
465 TimerList::iterator it;
466 for (it = timerList.begin(); it != timerList.end(); ) {
467 BTimer *timer = *it;
468 ++it; // the timer may be removed from the list, so move ahead now
469 ASSERT(timer != NULL);
470 tm.tv_sec = timer->getStartTime().tv_sec +
471 timer->getTimeout().tv_sec;
472 tm.tv_usec = timer->getStartTime().tv_usec +
473 timer->getTimeout().tv_usec;
474
475 if ((now.tv_sec < tm.tv_sec) ||
476 (now.tv_sec == tm.tv_sec && now.tv_usec < tm.tv_usec))
477 break;
478
479 timer->fireTimeout();
480
481 // restart the current timer so that the start time is updated
482 if (! timer->doOnce())
483 timer->start();
484 else {
485 timer->stop();
486 // delete timer; // USE THIS?
487 }
488 }
489 }
490 }
491 }
492
493
494 const Bool BaseDisplay::validateWindow(Window window) {
495 XEvent event;
496 if (XCheckTypedWindowEvent(display, window, DestroyNotify, &event)) {
497 XPutBackEvent(display, &event);
498
499 return False;
500 }
501
502 return True;
503 }
504
505
506 void BaseDisplay::grab(void) {
507 if (! server_grabs++)
508 XGrabServer(display);
509 }
510
511
512 void BaseDisplay::ungrab(void) {
513 if (! --server_grabs)
514 XUngrabServer(display);
515 }
516
517
518 void BaseDisplay::addTimer(BTimer *timer) {
519 ASSERT(timer != (BTimer *) 0);
520
521 TimerList::iterator it;
522 for (it = timerList.begin(); it != timerList.end(); ++it) {
523 BTimer *tmp = *it;
524 if ((tmp->getTimeout().tv_sec > timer->getTimeout().tv_sec) ||
525 ((tmp->getTimeout().tv_sec == timer->getTimeout().tv_sec) &&
526 (tmp->getTimeout().tv_usec >= timer->getTimeout().tv_usec)))
527 break;
528 }
529
530 timerList.insert(it, timer);
531 }
532
533
534 void BaseDisplay::removeTimer(BTimer *timer) {
535 timerList.remove(timer);
536 }
537
538
539 /*
540 * Grabs a button, but also grabs the button in every possible combination with
541 * the keyboard lock keys, so that they do not cancel out the event.
542 */
543 void BaseDisplay::grabButton(unsigned int button, unsigned int modifiers,
544 Window grab_window, Bool owner_events,
545 unsigned int event_mask, int pointer_mode,
546 int keybaord_mode, Window confine_to,
547 Cursor cursor) const
548 {
549 #ifndef NOCLOBBER
550 for (size_t cnt = 0; cnt < MaskListLength; ++cnt)
551 XGrabButton(display, button, modifiers | MaskList[cnt], grab_window,
552 owner_events, event_mask, pointer_mode, keybaord_mode,
553 confine_to, cursor);
554 #else // NOCLOBBER
555 XGrabButton(display, button, modifiers, grab_window,
556 owner_events, event_mask, pointer_mode, keybaord_mode,
557 confine_to, cursor);
558 #endif // NOCLOBBER
559 }
560
561 /*
562 * Releases the grab on a button, and ungrabs all possible combinations of the
563 * keyboard lock keys.
564 */
565 void BaseDisplay::ungrabButton(unsigned int button, unsigned int modifiers,
566 Window grab_window) const {
567 #ifndef NOCLOBBER
568 for (size_t cnt = 0; cnt < MaskListLength; ++cnt)
569 XUngrabButton(display, button, modifiers | MaskList[cnt], grab_window);
570 #else // NOCLOBBER
571 XUngrabButton(display, button, modifiers, grab_window);
572 #endif // NOCLOBBER
573 }
574
575
576 ScreenInfo::ScreenInfo(BaseDisplay &d, int num) : basedisplay(d),
577 screen_number(num)
578 {
579
580 root_window = RootWindow(basedisplay.getXDisplay(), screen_number);
581 depth = DefaultDepth(basedisplay.getXDisplay(), screen_number);
582
583 m_size = Size(WidthOfScreen(ScreenOfDisplay(basedisplay.getXDisplay(),
584 screen_number)),
585 HeightOfScreen(ScreenOfDisplay(basedisplay.getXDisplay(),
586 screen_number)));
587
588 // search for a TrueColor Visual... if we can't find one... we will use the
589 // default visual for the screen
590 XVisualInfo vinfo_template, *vinfo_return;
591 int vinfo_nitems;
592
593 vinfo_template.screen = screen_number;
594 vinfo_template.c_class = TrueColor;
595
596 visual = (Visual *) 0;
597
598 if ((vinfo_return = XGetVisualInfo(basedisplay.getXDisplay(),
599 VisualScreenMask | VisualClassMask,
600 &vinfo_template, &vinfo_nitems)) &&
601 vinfo_nitems > 0) {
602 for (int i = 0; i < vinfo_nitems; i++) {
603 if (depth < (vinfo_return + i)->depth) {
604 depth = (vinfo_return + i)->depth;
605 visual = (vinfo_return + i)->visual;
606 }
607 }
608
609 XFree(vinfo_return);
610 }
611
612 if (visual) {
613 colormap = XCreateColormap(basedisplay.getXDisplay(), root_window,
614 visual, AllocNone);
615 } else {
616 visual = DefaultVisual(basedisplay.getXDisplay(), screen_number);
617 colormap = DefaultColormap(basedisplay.getXDisplay(), screen_number);
618 }
619 }
This page took 0.061602 seconds and 4 git commands to generate.