]> Dogcows Code - chaz/openbox/blob - src/screen.cc
rm a XXX
[chaz/openbox] / src / screen.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 extern "C" {
8 #ifdef HAVE_STDIO_H
9 # include <stdio.h>
10 #endif // HAVE_STDIO_H
11
12 #ifdef HAVE_STRING_H
13 # include <string.h>
14 #endif // HAVE_STRING_H
15
16 #ifdef HAVE_UNISTD_H
17 # include <sys/types.h>
18 # include <unistd.h>
19 #endif // HAVE_UNISTD_H
20
21 #include "gettext.h"
22 #define _(str) gettext(str)
23 }
24
25 #include "screen.hh"
26 #include "client.hh"
27 #include "openbox.hh"
28 #include "frame.hh"
29 #include "bindings.hh"
30 #include "python.hh"
31 #include "otk/display.hh"
32 #include "otk/property.hh"
33
34 #include <vector>
35 #include <algorithm>
36
37 static bool running;
38 static int anotherWMRunning(Display *display, XErrorEvent *) {
39 printf(_("Another window manager already running on display %s.\n"),
40 DisplayString(display));
41 running = true;
42 return -1;
43 }
44
45
46 namespace ob {
47
48
49 Screen::Screen(int screen)
50 : WidgetBase(WidgetBase::Type_Root),
51 _number(screen),
52 _style(screen, "")
53 {
54 assert(screen >= 0); assert(screen < ScreenCount(**otk::display));
55 _info = otk::display->screenInfo(screen);
56
57 ::running = false;
58 XErrorHandler old = XSetErrorHandler(::anotherWMRunning);
59 XSelectInput(**otk::display, _info->rootWindow(),
60 Screen::event_mask);
61 XSync(**otk::display, false);
62 XSetErrorHandler(old);
63
64 _managed = !::running;
65 if (! _managed) return; // was unable to manage the screen
66
67 printf(_("Managing screen %d: visual 0x%lx, depth %d\n"),
68 _number, XVisualIDFromVisual(_info->visual()), _info->depth());
69
70 otk::Property::set(_info->rootWindow(), otk::Property::atoms.openbox_pid,
71 otk::Property::atoms.cardinal, (unsigned long) getpid());
72
73 // set the mouse cursor for the root window (the default cursor)
74 XDefineCursor(**otk::display, _info->rootWindow(),
75 openbox->cursors().session);
76
77 // XXX: initialize the screen's style
78 /*
79 otk::ustring stylepath;
80 python_get_string("theme", &stylepath);
81 otk::Configuration sconfig(false);
82 sconfig.setFile(otk::expandTilde(stylepath.c_str()));
83 if (!sconfig.load()) {
84 sconfig.setFile(otk::expandTilde(DEFAULTSTYLE));
85 if (!sconfig.load()) {
86 printf(_("Unable to load default style: %s. Aborting.\n"), DEFAULTSTYLE);
87 ::exit(1);
88 }
89 }
90 _style.load(sconfig);
91 */
92 otk::display->renderControl(_number)->drawRoot(*_style.rootColor());
93
94 // set up notification of netwm support
95 changeSupportedAtoms();
96
97 // Set the netwm properties for geometry
98 unsigned long geometry[] = { _info->width(),
99 _info->height() };
100 otk::Property::set(_info->rootWindow(),
101 otk::Property::atoms.net_desktop_geometry,
102 otk::Property::atoms.cardinal, geometry, 2);
103
104 // Set the net_desktop_names property
105 std::vector<otk::ustring> names;
106 python_get_stringlist("desktop_names", &names);
107 otk::Property::set(_info->rootWindow(),
108 otk::Property::atoms.net_desktop_names,
109 otk::Property::utf8, names);
110 // the above set() will cause the updateDesktopNames to fire right away so
111 // we have a list of desktop names
112
113 if (!python_get_long("number_of_desktops", &_num_desktops))
114 _num_desktops = 1;
115 changeNumDesktops(_num_desktops); // set the hint
116
117 _desktop = 0;
118 changeDesktop(0); // set the hint
119
120 // create the window which gets focus when no clients get it
121 XSetWindowAttributes attr;
122 attr.override_redirect = true;
123 _focuswindow = XCreateWindow(**otk::display, _info->rootWindow(),
124 -100, -100, 1, 1, 0, 0, InputOnly,
125 _info->visual(), CWOverrideRedirect, &attr);
126 XMapRaised(**otk::display, _focuswindow);
127
128 // these may be further updated if any pre-existing windows are found in
129 // the manageExising() function
130 changeClientList(); // initialize the client lists, which will be empty
131 calcArea(); // initialize the available working area
132
133 // register this class as the event handler for the root window
134 openbox->registerHandler(_info->rootWindow(), this);
135
136 // call the python Startup callbacks
137 EventData data(_number, 0, EventAction::Startup, 0);
138 openbox->bindings()->fireEvent(&data);
139 }
140
141
142 Screen::~Screen()
143 {
144 if (! _managed) return;
145
146 XSelectInput(**otk::display, _info->rootWindow(), NoEventMask);
147
148 // unmanage all windows
149 while (!clients.empty())
150 unmanageWindow(clients.front());
151
152 // call the python Shutdown callbacks
153 EventData data(_number, 0, EventAction::Shutdown, 0);
154 openbox->bindings()->fireEvent(&data);
155
156 XDestroyWindow(**otk::display, _focuswindow);
157 XDestroyWindow(**otk::display, _supportwindow);
158 }
159
160
161 void Screen::manageExisting()
162 {
163 unsigned int i, j, nchild;
164 Window r, p, *children;
165 XQueryTree(**otk::display, _info->rootWindow(), &r, &p,
166 &children, &nchild);
167
168 // preen the window list of all icon windows... for better dockapp support
169 for (i = 0; i < nchild; i++) {
170 if (children[i] == None) continue;
171
172 XWMHints *wmhints = XGetWMHints(**otk::display,
173 children[i]);
174
175 if (wmhints) {
176 if ((wmhints->flags & IconWindowHint) &&
177 (wmhints->icon_window != children[i])) {
178 for (j = 0; j < nchild; j++) {
179 if (children[j] == wmhints->icon_window) {
180 children[j] = None;
181 break;
182 }
183 }
184 }
185
186 XFree(wmhints);
187 }
188 }
189
190 // manage shown windows
191 for (i = 0; i < nchild; ++i) {
192 if (children[i] == None)
193 continue;
194
195 XWindowAttributes attrib;
196 if (XGetWindowAttributes(**otk::display, children[i], &attrib)) {
197 if (attrib.override_redirect) continue;
198
199 if (attrib.map_state != IsUnmapped) {
200 manageWindow(children[i]);
201 }
202 }
203 }
204
205 XFree(children);
206 }
207
208
209 void Screen::updateStrut()
210 {
211 _strut.left = _strut.right = _strut.top = _strut.bottom = 0;
212
213 Client::List::iterator it, end = clients.end();
214 for (it = clients.begin(); it != end; ++it) {
215 const otk::Strut &s = (*it)->strut();
216 _strut.left = std::max(_strut.left, s.left);
217 _strut.right = std::max(_strut.right, s.right);
218 _strut.top = std::max(_strut.top, s.top);
219 _strut.bottom = std::max(_strut.bottom, s.bottom);
220 }
221 calcArea();
222 }
223
224
225 void Screen::calcArea()
226 {
227 otk::Rect old_area = _area;
228
229 /*
230 #ifdef XINERAMA
231 // reset to the full areas
232 if (isXineramaActive())
233 xineramaUsableArea = getXineramaAreas();
234 #endif // XINERAMA
235 */
236
237 _area.setRect(_strut.left, _strut.top,
238 _info->width() - (_strut.left + _strut.right),
239 _info->height() - (_strut.top + _strut.bottom));
240
241 /*
242 #ifdef XINERAMA
243 if (isXineramaActive()) {
244 // keep each of the ximerama-defined areas inside the strut
245 RectList::iterator xit, xend = xineramaUsableArea.end();
246 for (xit = xineramaUsableArea.begin(); xit != xend; ++xit) {
247 if (xit->x() < usableArea.x()) {
248 xit->setX(usableArea.x());
249 xit->setWidth(xit->width() - usableArea.x());
250 }
251 if (xit->y() < usableArea.y()) {
252 xit->setY(usableArea.y());
253 xit->setHeight(xit->height() - usableArea.y());
254 }
255 if (xit->x() + xit->width() > usableArea.width())
256 xit->setWidth(usableArea.width() - xit->x());
257 if (xit->y() + xit->height() > usableArea.height())
258 xit->setHeight(usableArea.height() - xit->y());
259 }
260 }
261 #endif // XINERAMA
262 */
263
264 if (old_area != _area)
265 // the area has changed, adjust all the maximized windows
266 for (it = clients.begin(); it != end; ++it)
267 (*it)->remaximize();
268
269 changeWorkArea();
270 }
271
272
273 void Screen::changeSupportedAtoms()
274 {
275 // create the netwm support window
276 _supportwindow = XCreateSimpleWindow(**otk::display,
277 _info->rootWindow(),
278 0, 0, 1, 1, 0, 0, 0);
279
280 // set supporting window
281 otk::Property::set(_info->rootWindow(),
282 otk::Property::atoms.net_supporting_wm_check,
283 otk::Property::atoms.window, _supportwindow);
284
285 //set properties on the supporting window
286 otk::Property::set(_supportwindow, otk::Property::atoms.net_wm_name,
287 otk::Property::utf8, "Openbox");
288 otk::Property::set(_supportwindow,
289 otk::Property::atoms.net_supporting_wm_check,
290 otk::Property::atoms.window, _supportwindow);
291
292
293 Atom supported[] = {
294 otk::Property::atoms.net_current_desktop,
295 otk::Property::atoms.net_number_of_desktops,
296 otk::Property::atoms.net_desktop_geometry,
297 otk::Property::atoms.net_desktop_viewport,
298 otk::Property::atoms.net_active_window,
299 otk::Property::atoms.net_workarea,
300 otk::Property::atoms.net_client_list,
301 otk::Property::atoms.net_client_list_stacking,
302 otk::Property::atoms.net_desktop_names,
303 otk::Property::atoms.net_close_window,
304 otk::Property::atoms.net_wm_name,
305 otk::Property::atoms.net_wm_visible_name,
306 otk::Property::atoms.net_wm_icon_name,
307 otk::Property::atoms.net_wm_visible_icon_name,
308 /*
309 otk::Property::atoms.net_wm_desktop,
310 */
311 otk::Property::atoms.net_wm_strut,
312 otk::Property::atoms.net_wm_window_type,
313 otk::Property::atoms.net_wm_window_type_desktop,
314 otk::Property::atoms.net_wm_window_type_dock,
315 otk::Property::atoms.net_wm_window_type_toolbar,
316 otk::Property::atoms.net_wm_window_type_menu,
317 otk::Property::atoms.net_wm_window_type_utility,
318 otk::Property::atoms.net_wm_window_type_splash,
319 otk::Property::atoms.net_wm_window_type_dialog,
320 otk::Property::atoms.net_wm_window_type_normal,
321 /*
322 otk::Property::atoms.net_wm_moveresize,
323 otk::Property::atoms.net_wm_moveresize_size_topleft,
324 otk::Property::atoms.net_wm_moveresize_size_topright,
325 otk::Property::atoms.net_wm_moveresize_size_bottomleft,
326 otk::Property::atoms.net_wm_moveresize_size_bottomright,
327 otk::Property::atoms.net_wm_moveresize_move,
328 */
329 otk::Property::atoms.net_wm_allowed_actions,
330 otk::Property::atoms.net_wm_action_move,
331 otk::Property::atoms.net_wm_action_resize,
332 otk::Property::atoms.net_wm_action_minimize,
333 otk::Property::atoms.net_wm_action_shade,
334 /* otk::Property::atoms.net_wm_action_stick,*/
335 otk::Property::atoms.net_wm_action_maximize_horz,
336 otk::Property::atoms.net_wm_action_maximize_vert,
337 otk::Property::atoms.net_wm_action_fullscreen,
338 otk::Property::atoms.net_wm_action_change_desktop,
339 otk::Property::atoms.net_wm_action_close,
340
341 otk::Property::atoms.net_wm_state,
342 otk::Property::atoms.net_wm_state_modal,
343 otk::Property::atoms.net_wm_state_maximized_vert,
344 otk::Property::atoms.net_wm_state_maximized_horz,
345 otk::Property::atoms.net_wm_state_shaded,
346 otk::Property::atoms.net_wm_state_skip_taskbar,
347 otk::Property::atoms.net_wm_state_skip_pager,
348 otk::Property::atoms.net_wm_state_hidden,
349 otk::Property::atoms.net_wm_state_fullscreen,
350 otk::Property::atoms.net_wm_state_above,
351 otk::Property::atoms.net_wm_state_below,
352 };
353 const int num_supported = sizeof(supported)/sizeof(Atom);
354
355 otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_supported,
356 otk::Property::atoms.atom, supported, num_supported);
357 }
358
359
360 void Screen::changeClientList()
361 {
362 Window *windows;
363 unsigned int size = clients.size();
364
365 // create an array of the window ids
366 if (size > 0) {
367 Window *win_it;
368
369 windows = new Window[size];
370 win_it = windows;
371 Client::List::const_iterator it = clients.begin();
372 const Client::List::const_iterator end = clients.end();
373 for (; it != end; ++it, ++win_it)
374 *win_it = (*it)->window();
375 } else
376 windows = (Window*) 0;
377
378 otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_client_list,
379 otk::Property::atoms.window, windows, size);
380
381 if (size)
382 delete [] windows;
383
384 changeStackingList();
385 }
386
387
388 void Screen::changeStackingList()
389 {
390 Window *windows;
391 unsigned int size = _stacking.size();
392
393 assert(size == clients.size()); // just making sure.. :)
394
395
396 // create an array of the window ids (from bottom to top, reverse order!)
397 if (size > 0) {
398 Window *win_it;
399
400 windows = new Window[size];
401 win_it = windows;
402 Client::List::const_reverse_iterator it = _stacking.rbegin();
403 const Client::List::const_reverse_iterator end = _stacking.rend();
404 for (; it != end; ++it, ++win_it)
405 *win_it = (*it)->window();
406 } else
407 windows = (Window*) 0;
408
409 otk::Property::set(_info->rootWindow(),
410 otk::Property::atoms.net_client_list_stacking,
411 otk::Property::atoms.window, windows, size);
412
413 if (size)
414 delete [] windows;
415 }
416
417
418 void Screen::changeWorkArea() {
419 unsigned long *dims = new unsigned long[4 * _num_desktops];
420 for (long i = 0; i < _num_desktops; ++i) {
421 // XXX: this could be different for each workspace
422 dims[(i * 4) + 0] = _area.x();
423 dims[(i * 4) + 1] = _area.y();
424 dims[(i * 4) + 2] = _area.width();
425 dims[(i * 4) + 3] = _area.height();
426 }
427 otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_workarea,
428 otk::Property::atoms.cardinal, dims, 4 * _num_desktops);
429 delete [] dims;
430 }
431
432
433 void Screen::manageWindow(Window window)
434 {
435 Client *client = 0;
436 XWMHints *wmhint;
437 XSetWindowAttributes attrib_set;
438 XEvent e;
439 XWindowAttributes attrib;
440
441 otk::display->grab();
442
443 // check if it has already been unmapped by the time we started mapping
444 // the grab does a sync so we don't have to here
445 if (XCheckTypedWindowEvent(**otk::display, window, DestroyNotify, &e) ||
446 XCheckTypedWindowEvent(**otk::display, window, UnmapNotify, &e)) {
447 XPutBackEvent(**otk::display, &e);
448
449 otk::display->ungrab();
450 return; // don't manage it
451 }
452
453 if (!XGetWindowAttributes(**otk::display, window, &attrib) ||
454 attrib.override_redirect) {
455 otk::display->ungrab();
456 return; // don't manage it
457 }
458
459 // is the window a docking app
460 if ((wmhint = XGetWMHints(**otk::display, window))) {
461 if ((wmhint->flags & StateHint) &&
462 wmhint->initial_state == WithdrawnState) {
463 //slit->addClient(w); // XXX: make dock apps work!
464
465 otk::display->ungrab();
466 XFree(wmhint);
467 return;
468 }
469 XFree(wmhint);
470 }
471
472 // choose the events we want to receive on the CLIENT window
473 attrib_set.event_mask = Client::event_mask;
474 attrib_set.do_not_propagate_mask = Client::no_propagate_mask;
475 XChangeWindowAttributes(**otk::display, window,
476 CWEventMask|CWDontPropagate, &attrib_set);
477
478 // create the Client class, which gets all of the hints on the window
479 client = new Client(_number, window);
480 // register for events
481 openbox->registerHandler(window, client);
482 // add to the wm's map
483 openbox->addClient(window, client);
484
485 // we dont want a border on the client
486 client->toggleClientBorder(false);
487
488 // specify that if we exit, the window should not be destroyed and should be
489 // reparented back to root automatically
490 XChangeSaveSet(**otk::display, window, SetModeInsert);
491
492 // create the decoration frame for the client window
493 client->frame = new Frame(client, &_style);
494 // register the plate for events (map req's)
495 // this involves removing itself from the handler list first, since it is
496 // auto added to the list, being a widget. we won't get any events on the
497 // plate except for events for the client (SubstructureRedirectMask)
498 openbox->clearHandler(client->frame->plate());
499 openbox->registerHandler(client->frame->plate(), client);
500
501 // add to the wm's map
502 openbox->addClient(client->frame->window(), client);
503 openbox->addClient(client->frame->plate(), client);
504 openbox->addClient(client->frame->titlebar(), client);
505 openbox->addClient(client->frame->label(), client);
506 openbox->addClient(client->frame->button_max(), client);
507 openbox->addClient(client->frame->button_iconify(), client);
508 openbox->addClient(client->frame->button_alldesk(), client);
509 openbox->addClient(client->frame->button_close(), client);
510 openbox->addClient(client->frame->handle(), client);
511 openbox->addClient(client->frame->grip_left(), client);
512 openbox->addClient(client->frame->grip_right(), client);
513
514 // reparent the client to the frame
515 client->frame->grabClient();
516
517 if (openbox->state() != Openbox::State_Starting) {
518 // position the window intelligenty .. hopefully :)
519 // call the python PLACEWINDOW binding
520 EventData data(_number, client, EventAction::PlaceWindow, 0);
521 openbox->bindings()->fireEvent(&data);
522 }
523
524 EventData ddata(_number, client, EventAction::DisplayingWindow, 0);
525 openbox->bindings()->fireEvent(&ddata);
526
527 // if on the current desktop.. (or all desktops)
528 if (client->desktop() == _desktop ||
529 client->desktop() == (signed)0xffffffff) {
530 client->frame->show();
531 }
532
533 client->applyStartupState();
534
535 otk::display->ungrab();
536
537 // add to the screen's list
538 clients.push_back(client);
539 // once the client is in the list, update our strut to include the new
540 // client's (it is good that this happens after window placement!)
541 updateStrut();
542 // this puts into the stacking order, then raises it
543 _stacking.push_back(client);
544 raiseWindow(client);
545 // update the root properties
546 changeClientList();
547
548 openbox->bindings()->grabButtons(true, client);
549
550 EventData ndata(_number, client, EventAction::NewWindow, 0);
551 openbox->bindings()->fireEvent(&ndata);
552
553 #ifdef DEBUG
554 printf("Managed window 0x%lx frame 0x%lx\n",
555 window, client->frame->window());
556 #endif
557 }
558
559
560 void Screen::unmanageWindow(Client *client)
561 {
562 Frame *frame = client->frame;
563
564 // call the python CLOSEWINDOW binding
565 EventData data(_number, client, EventAction::CloseWindow, 0);
566 openbox->bindings()->fireEvent(&data);
567
568 openbox->bindings()->grabButtons(false, client);
569
570 // remove from the wm's map
571 openbox->removeClient(client->window());
572 openbox->removeClient(frame->window());
573 openbox->removeClient(frame->plate());
574 openbox->removeClient(frame->titlebar());
575 openbox->removeClient(frame->label());
576 openbox->removeClient(frame->button_max());
577 openbox->removeClient(frame->button_iconify());
578 openbox->removeClient(frame->button_alldesk());
579 openbox->removeClient(frame->button_close());
580 openbox->removeClient(frame->handle());
581 openbox->removeClient(frame->grip_left());
582 openbox->removeClient(frame->grip_right());
583 // unregister for handling events
584 openbox->clearHandler(client->window());
585
586 // remove the window from our save set
587 XChangeSaveSet(**otk::display, client->window(), SetModeDelete);
588
589 // we dont want events no more
590 XSelectInput(**otk::display, client->window(), NoEventMask);
591
592 frame->hide();
593
594 // give the client its border back
595 client->toggleClientBorder(true);
596
597 // reparent the window out of the frame
598 frame->releaseClient();
599
600 #ifdef DEBUG
601 Window framewin = client->frame->window();
602 #endif
603 delete client->frame;
604 client->frame = 0;
605
606 // remove from the stacking order
607 _stacking.remove(client);
608
609 // remove from the screen's list
610 clients.remove(client);
611
612 // once the client is out of the list, update our strut to remove it's
613 // influence
614 updateStrut();
615
616 // unfocus the client (calls the focus callbacks)
617 client->unfocus();
618
619 #ifdef DEBUG
620 printf("Unmanaged window 0x%lx frame 0x%lx\n", client->window(), framewin);
621 #endif
622
623 delete client;
624
625 // update the root properties
626 changeClientList();
627 }
628
629 void Screen::lowerWindow(Client *client)
630 {
631 Window wins[2]; // only ever restack 2 windows.
632
633 assert(!_stacking.empty()); // this would be bad
634
635 Client::List::iterator it = --_stacking.end();
636 const Client::List::iterator end = _stacking.begin();
637
638 for (; it != end && (*it)->layer() < client->layer(); --it);
639 if (*it == client) return; // already the bottom, return
640
641 wins[0] = (*it)->frame->window();
642 wins[1] = client->frame->window();
643
644 _stacking.remove(client);
645 _stacking.insert(++it, client);
646
647 XRestackWindows(**otk::display, wins, 2);
648 changeStackingList();
649 }
650
651 void Screen::raiseWindow(Client *client)
652 {
653 Window wins[2]; // only ever restack 2 windows.
654
655 assert(!_stacking.empty()); // this would be bad
656
657 // remove the client before looking so we can't run into ourselves
658 _stacking.remove(client);
659
660 Client::List::iterator it = _stacking.begin();
661 const Client::List::iterator end = _stacking.end();
662
663 // the stacking list is from highest to lowest
664 for (; it != end && (*it)->layer() > client->layer(); ++it);
665
666 /*
667 if our new position is the top, we want to stack under the _focuswindow
668 otherwise, we want to stack under the previous window in the stack.
669 */
670 wins[0] = (it == _stacking.begin() ? _focuswindow :
671 ((*(--Client::List::const_iterator(it)))->frame->window()));
672 wins[1] = client->frame->window();
673
674 _stacking.insert(it, client);
675
676 XRestackWindows(**otk::display, wins, 2);
677 changeStackingList();
678 }
679
680 void Screen::changeDesktop(long desktop)
681 {
682 if (!(desktop >= 0 && desktop < _num_desktops)) return;
683
684 printf("Moving to desktop %ld\n", desktop);
685
686 long old = _desktop;
687
688 _desktop = desktop;
689 otk::Property::set(_info->rootWindow(),
690 otk::Property::atoms.net_current_desktop,
691 otk::Property::atoms.cardinal, _desktop);
692
693 if (old == _desktop) return;
694
695 Client::List::iterator it, end = clients.end();
696 for (it = clients.begin(); it != end; ++it) {
697 if ((*it)->desktop() == old) {
698 (*it)->frame->hide();
699 } else if ((*it)->desktop() == _desktop) {
700 (*it)->frame->show();
701 }
702 }
703
704 // force the callbacks to fire
705 if (!openbox->focusedClient())
706 openbox->setFocusedClient(0);
707 }
708
709 void Screen::changeNumDesktops(long num)
710 {
711 assert(num > 0);
712
713 if (!(num > 0)) return;
714
715 // XXX: move windows on desktops that will no longer exist!
716
717 _num_desktops = num;
718 otk::Property::set(_info->rootWindow(),
719 otk::Property::atoms.net_number_of_desktops,
720 otk::Property::atoms.cardinal, _num_desktops);
721
722 // set the viewport hint
723 unsigned long *viewport = new unsigned long[_num_desktops * 2];
724 memset(viewport, 0, sizeof(unsigned long) * _num_desktops * 2);
725 otk::Property::set(_info->rootWindow(),
726 otk::Property::atoms.net_desktop_viewport,
727 otk::Property::atoms.cardinal,
728 viewport, _num_desktops * 2);
729 delete [] viewport;
730
731 // update the work area hint
732 changeWorkArea();
733 }
734
735
736 void Screen::updateDesktopNames()
737 {
738 unsigned long num = (unsigned) -1;
739
740 if (!otk::Property::get(_info->rootWindow(),
741 otk::Property::atoms.net_desktop_names,
742 otk::Property::utf8, &num, &_desktop_names))
743 _desktop_names.clear();
744 while ((long)_desktop_names.size() < _num_desktops)
745 _desktop_names.push_back("Unnamed");
746 }
747
748
749 void Screen::setDesktopName(long i, const otk::ustring &name)
750 {
751 assert(i >= 0);
752
753 if (i >= _num_desktops) return;
754
755 otk::Property::StringVect newnames = _desktop_names;
756 newnames[i] = name;
757 otk::Property::set(_info->rootWindow(),
758 otk::Property::atoms.net_desktop_names,
759 otk::Property::utf8, newnames);
760 }
761
762
763 void Screen::propertyHandler(const XPropertyEvent &e)
764 {
765 otk::EventHandler::propertyHandler(e);
766
767 // compress changes to a single property into a single change
768 XEvent ce;
769 while (XCheckTypedEvent(**otk::display, e.type, &ce)) {
770 // XXX: it would be nice to compress ALL changes to a property, not just
771 // changes in a row without other props between.
772 if (ce.xproperty.atom != e.atom) {
773 XPutBackEvent(**otk::display, &ce);
774 break;
775 }
776 }
777
778 if (e.atom == otk::Property::atoms.net_desktop_names)
779 updateDesktopNames();
780 }
781
782
783 void Screen::clientMessageHandler(const XClientMessageEvent &e)
784 {
785 otk::EventHandler::clientMessageHandler(e);
786
787 if (e.format != 32) return;
788
789 if (e.message_type == otk::Property::atoms.net_current_desktop) {
790 changeDesktop(e.data.l[0]);
791 } else if (e.message_type == otk::Property::atoms.net_number_of_desktops) {
792 changeNumDesktops(e.data.l[0]);
793 }
794 // XXX: so many client messages to handle here! ..or not.. they go to clients
795 }
796
797
798 void Screen::mapRequestHandler(const XMapRequestEvent &e)
799 {
800 otk::EventHandler::mapRequestHandler(e);
801
802 #ifdef DEBUG
803 printf("MapRequest for 0x%lx\n", e.window);
804 #endif // DEBUG
805
806 Client *c = openbox->findClient(e.window);
807 if (c) {
808 #ifdef DEBUG
809 printf("DEBUG: MAP REQUEST CAUGHT IN SCREEN. IGNORED.\n");
810 #endif
811 } else
812 manageWindow(e.window);
813 }
814
815 }
This page took 0.071761 seconds and 5 git commands to generate.