1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
11 #include "otk/display.hh"
12 #include "otk/property.hh"
13 #include "otk/util.hh"
17 # include <sys/types.h>
19 #endif // HAVE_UNISTD_H
22 #define _(str) gettext(str)
31 static int anotherWMRunning(Display *display, XErrorEvent *) {
32 printf(_("Another window manager already running on display %s.\n"),
33 DisplayString(display));
42 Screen::Screen(int screen)
45 assert(screen >= 0); assert(screen < ScreenCount(**otk::display));
46 _info = otk::display->screenInfo(screen);
49 XErrorHandler old = XSetErrorHandler(::anotherWMRunning);
50 XSelectInput(**otk::display, _info->rootWindow(),
52 XSync(**otk::display, false);
53 XSetErrorHandler(old);
55 _managed = !::running;
56 if (! _managed) return; // was unable to manage the screen
59 printf(_("Managing screen %d: visual 0x%lx, depth %d\n"),
60 _number, XVisualIDFromVisual(_info->visual()), _info->depth());
63 otk::Property::set(_info->rootWindow(), otk::Property::atoms.openbox_pid,
64 otk::Property::atoms.cardinal, (unsigned long) getpid());
66 // set the mouse cursor for the root window (the default cursor)
67 XDefineCursor(**otk::display, _info->rootWindow(),
68 openbox->cursors().session);
70 // set up notification of netwm support
71 changeSupportedAtoms();
73 // Set the netwm properties for geometry
74 unsigned long geometry[] = { _info->size().width(),
75 _info->size().height() };
76 otk::Property::set(_info->rootWindow(),
77 otk::Property::atoms.net_desktop_geometry,
78 otk::Property::atoms.cardinal, geometry, 2);
82 changeNumDesktops(4); // set the hint
83 changeDesktop(0); // set the hint
85 // don't start in showing-desktop mode
86 _showing_desktop = false;
87 otk::Property::set(_info->rootWindow(),
88 otk::Property::atoms.net_showing_desktop,
89 otk::Property::atoms.cardinal, 0);
91 // create the window which gets focus when no clients get it
92 XSetWindowAttributes attr;
93 attr.override_redirect = true;
94 _focuswindow = XCreateWindow(**otk::display, _info->rootWindow(),
95 -100, -100, 1, 1, 0, 0, InputOnly,
96 _info->visual(), CWOverrideRedirect, &attr);
97 XMapRaised(**otk::display, _focuswindow);
99 // these may be further updated if any pre-existing windows are found in
100 // the manageExising() function
101 changeClientList(); // initialize the client lists, which will be empty
103 updateDesktopLayout();
105 // register this class as the event handler for the root window
106 openbox->registerHandler(_info->rootWindow(), this);
108 // call the python Startup callbacks
109 EventData data(_number, 0, EventAction::Startup, 0);
110 openbox->bindings()->fireEvent(&data);
116 if (! _managed) return;
118 XSelectInput(**otk::display, _info->rootWindow(), NoEventMask);
120 // unmanage all windows
121 while (!clients.empty())
122 unmanageWindow(clients.front());
124 // call the python Shutdown callbacks
125 EventData data(_number, 0, EventAction::Shutdown, 0);
126 openbox->bindings()->fireEvent(&data);
128 XDestroyWindow(**otk::display, _focuswindow);
129 XDestroyWindow(**otk::display, _supportwindow);
133 void Screen::manageExisting()
135 unsigned int i, j, nchild;
136 Window r, p, *children;
137 XQueryTree(**otk::display, _info->rootWindow(), &r, &p,
140 // preen the window list of all icon windows... for better dockapp support
141 for (i = 0; i < nchild; i++) {
142 if (children[i] == None) continue;
144 XWMHints *wmhints = XGetWMHints(**otk::display,
148 if ((wmhints->flags & IconWindowHint) &&
149 (wmhints->icon_window != children[i])) {
150 for (j = 0; j < nchild; j++) {
151 if (children[j] == wmhints->icon_window) {
162 // manage shown windows
163 for (i = 0; i < nchild; ++i) {
164 if (children[i] == None)
167 XWindowAttributes attrib;
168 if (XGetWindowAttributes(**otk::display, children[i], &attrib)) {
169 if (attrib.override_redirect) continue;
171 if (attrib.map_state != IsUnmapped) {
172 manageWindow(children[i]);
180 void Screen::updateDesktopLayout()
182 //const unsigned long _NET_WM_ORIENTATION_HORZ = 0;
183 const unsigned long _NET_WM_ORIENTATION_VERT = 1;
184 //const unsigned long _NET_WM_TOPLEFT = 0;
185 const unsigned long _NET_WM_TOPRIGHT = 1;
186 const unsigned long _NET_WM_BOTTOMRIGHT = 2;
187 const unsigned long _NET_WM_BOTTOMLEFT = 3;
190 _layout.orientation = DesktopLayout::Horizontal;
191 _layout.start_corner = DesktopLayout::TopLeft;
193 _layout.columns = _num_desktops;
195 unsigned long *data, num = 4;
196 if (otk::Property::get(_info->rootWindow(),
197 otk::Property::atoms.net_desktop_layout,
198 otk::Property::atoms.cardinal,
201 if (data[0] == _NET_WM_ORIENTATION_VERT)
202 _layout.orientation = DesktopLayout::Vertical;
203 if (data[3] == _NET_WM_TOPRIGHT)
204 _layout.start_corner = DesktopLayout::TopRight;
205 else if (data[3] == _NET_WM_BOTTOMRIGHT)
206 _layout.start_corner = DesktopLayout::BottomRight;
207 else if (data[3] == _NET_WM_BOTTOMLEFT)
208 _layout.start_corner = DesktopLayout::BottomLeft;
210 // fill in a zero rows/columns
211 if (!(data[1] == 0 && data[2] == 0)) { // both 0's is bad data..
213 data[1] = (_num_desktops + _num_desktops % data[2]) / data[2];
214 } else if (data[2] == 0) {
215 data[2] = (_num_desktops + _num_desktops % data[1]) / data[1];
217 _layout.columns = data[1];
218 _layout.rows = data[2];
222 if (_layout.orientation == DesktopLayout::Horizontal) {
223 if (_layout.rows > _num_desktops) _layout.rows = _num_desktops;
224 if (_layout.columns > (_num_desktops + _num_desktops % _layout.rows) /
226 _layout.columns = (_num_desktops + _num_desktops % _layout.rows) /
229 if (_layout.columns > _num_desktops) _layout.columns = _num_desktops;
230 if (_layout.rows > (_num_desktops + _num_desktops % _layout.columns) /
232 _layout.rows = (_num_desktops + _num_desktops % _layout.columns) /
240 void Screen::updateStruts()
243 void operator()(otk::Strut &self, const otk::Strut &other) {
244 self.left = std::max(self.left, other.left);
245 self.right = std::max(self.right, other.right);
246 self.top = std::max(self.top, other.top);
247 self.bottom = std::max(self.bottom, other.bottom);
251 StrutList::iterator sit, send = _struts.end();
253 for (sit = _struts.begin(); sit != send; ++sit)
254 sit->left = sit->right = sit->top = sit->bottom = 0;
256 std::list<Client*>::const_iterator it, end = clients.end();
257 for (it = clients.begin(); it != end; ++it) {
258 if ((*it)->iconic()) continue; // these dont count in the strut
260 unsigned int desk = (*it)->desktop();
261 const otk::Strut &s = (*it)->strut();
263 if (desk == 0xffffffff)
264 for (unsigned int i = 0, e = _struts.size(); i < e; ++i)
265 apply(_struts[i], s);
266 else if (desk < _struts.size())
267 apply(_struts[desk], s);
269 assert(false); // invalid desktop otherwise..
270 // apply to the 'all desktops' strut
271 apply(_struts.back(), s);
277 void Screen::changeWorkArea()
279 unsigned long *dims = new unsigned long[4 * _num_desktops];
280 for (unsigned int i = 0; i < _num_desktops + 1; ++i) {
281 otk::Rect old_area = _area[i];
284 // reset to the full areas
285 if (isXineramaActive())
286 xineramaUsableArea = getXineramaAreas();
290 _area[i] = otk::Rect(_struts[i].left, _struts[i].top,
291 _info->size().width() - (_struts[i].left +
293 _info->size().height() - (_struts[i].top +
298 if (isXineramaActive()) {
299 // keep each of the ximerama-defined areas inside the strut
300 RectList::iterator xit, xend = xineramaUsableArea.end();
301 for (xit = xineramaUsableArea.begin(); xit != xend; ++xit) {
302 if (xit->x() < usableArea.x()) {
303 xit->setX(usableArea.x());
304 xit->setWidth(xit->width() - usableArea.x());
306 if (xit->y() < usableArea.y()) {
307 xit->setY(usableArea.y());
308 xit->setHeight(xit->height() - usableArea.y());
310 if (xit->x() + xit->width() > usableArea.width())
311 xit->setWidth(usableArea.width() - xit->x());
312 if (xit->y() + xit->height() > usableArea.height())
313 xit->setHeight(usableArea.height() - xit->y());
318 if (old_area != _area[i]) {
319 // the area has changed, adjust all the maximized windows
320 std::list<Client*>::iterator it, end = clients.end();
321 for (it = clients.begin(); it != end; ++it)
322 if (i < _num_desktops) {
323 if ((*it)->desktop() == i)
326 // the 'all desktops' size
327 if ((*it)->desktop() == 0xffffffff)
332 // don't set these for the 'all desktops' area
333 if (i < _num_desktops) {
334 dims[(i * 4) + 0] = _area[i].x();
335 dims[(i * 4) + 1] = _area[i].y();
336 dims[(i * 4) + 2] = _area[i].width();
337 dims[(i * 4) + 3] = _area[i].height();
340 otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_workarea,
341 otk::Property::atoms.cardinal, dims, 4 * _num_desktops);
346 void Screen::changeSupportedAtoms()
348 // create the netwm support window
349 _supportwindow = XCreateSimpleWindow(**otk::display,
351 0, 0, 1, 1, 0, 0, 0);
353 // set supporting window
354 otk::Property::set(_info->rootWindow(),
355 otk::Property::atoms.net_supporting_wm_check,
356 otk::Property::atoms.window, _supportwindow);
358 //set properties on the supporting window
359 otk::Property::set(_supportwindow, otk::Property::atoms.net_wm_name,
360 otk::Property::utf8, "Openbox");
361 otk::Property::set(_supportwindow,
362 otk::Property::atoms.net_supporting_wm_check,
363 otk::Property::atoms.window, _supportwindow);
367 otk::Property::atoms.net_current_desktop,
368 otk::Property::atoms.net_number_of_desktops,
369 otk::Property::atoms.net_desktop_geometry,
370 otk::Property::atoms.net_desktop_viewport,
371 otk::Property::atoms.net_active_window,
372 otk::Property::atoms.net_workarea,
373 otk::Property::atoms.net_client_list,
374 otk::Property::atoms.net_client_list_stacking,
375 otk::Property::atoms.net_desktop_names,
376 otk::Property::atoms.net_close_window,
377 otk::Property::atoms.net_desktop_layout,
378 otk::Property::atoms.net_showing_desktop,
379 otk::Property::atoms.net_wm_name,
380 otk::Property::atoms.net_wm_visible_name,
381 otk::Property::atoms.net_wm_icon_name,
382 otk::Property::atoms.net_wm_visible_icon_name,
383 otk::Property::atoms.net_wm_desktop,
384 otk::Property::atoms.net_wm_strut,
385 otk::Property::atoms.net_wm_window_type,
386 otk::Property::atoms.net_wm_window_type_desktop,
387 otk::Property::atoms.net_wm_window_type_dock,
388 otk::Property::atoms.net_wm_window_type_toolbar,
389 otk::Property::atoms.net_wm_window_type_menu,
390 otk::Property::atoms.net_wm_window_type_utility,
391 otk::Property::atoms.net_wm_window_type_splash,
392 otk::Property::atoms.net_wm_window_type_dialog,
393 otk::Property::atoms.net_wm_window_type_normal,
395 otk::Property::atoms.net_wm_moveresize,
396 otk::Property::atoms.net_wm_moveresize_size_topleft,
397 otk::Property::atoms.net_wm_moveresize_size_topright,
398 otk::Property::atoms.net_wm_moveresize_size_bottomleft,
399 otk::Property::atoms.net_wm_moveresize_size_bottomright,
400 otk::Property::atoms.net_wm_moveresize_move,
402 otk::Property::atoms.net_wm_allowed_actions,
403 otk::Property::atoms.net_wm_action_move,
404 otk::Property::atoms.net_wm_action_resize,
405 otk::Property::atoms.net_wm_action_minimize,
406 otk::Property::atoms.net_wm_action_shade,
407 /* otk::Property::atoms.net_wm_action_stick,*/
408 otk::Property::atoms.net_wm_action_maximize_horz,
409 otk::Property::atoms.net_wm_action_maximize_vert,
410 otk::Property::atoms.net_wm_action_fullscreen,
411 otk::Property::atoms.net_wm_action_change_desktop,
412 otk::Property::atoms.net_wm_action_close,
414 otk::Property::atoms.net_wm_state,
415 otk::Property::atoms.net_wm_state_modal,
416 otk::Property::atoms.net_wm_state_maximized_vert,
417 otk::Property::atoms.net_wm_state_maximized_horz,
418 otk::Property::atoms.net_wm_state_shaded,
419 otk::Property::atoms.net_wm_state_skip_taskbar,
420 otk::Property::atoms.net_wm_state_skip_pager,
421 otk::Property::atoms.net_wm_state_hidden,
422 otk::Property::atoms.net_wm_state_fullscreen,
423 otk::Property::atoms.net_wm_state_above,
424 otk::Property::atoms.net_wm_state_below,
426 const int num_supported = sizeof(supported)/sizeof(Atom);
428 otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_supported,
429 otk::Property::atoms.atom, supported, num_supported);
433 void Screen::changeClientList()
436 unsigned int size = clients.size();
438 // create an array of the window ids
442 windows = new Window[size];
444 std::list<Client*>::const_iterator it = clients.begin();
445 const std::list<Client*>::const_iterator end = clients.end();
446 for (; it != end; ++it, ++win_it)
447 *win_it = (*it)->window();
449 windows = (Window*) 0;
451 otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_client_list,
452 otk::Property::atoms.window, windows, size);
457 changeStackingList();
461 void Screen::changeStackingList()
464 unsigned int size = _stacking.size();
466 assert(size == clients.size()); // just making sure.. :)
469 // create an array of the window ids (from bottom to top, reverse order!)
473 windows = new Window[size];
475 std::list<Client*>::const_reverse_iterator it = _stacking.rbegin();
476 const std::list<Client*>::const_reverse_iterator end = _stacking.rend();
477 for (; it != end; ++it, ++win_it)
478 *win_it = (*it)->window();
480 windows = (Window*) 0;
482 otk::Property::set(_info->rootWindow(),
483 otk::Property::atoms.net_client_list_stacking,
484 otk::Property::atoms.window, windows, size);
491 void Screen::manageWindow(Window window)
495 XSetWindowAttributes attrib_set;
497 XWindowAttributes attrib;
499 otk::display->grab();
501 // check if it has already been unmapped by the time we started mapping
502 // the grab does a sync so we don't have to here
503 if (XCheckTypedWindowEvent(**otk::display, window, DestroyNotify, &e) ||
504 XCheckTypedWindowEvent(**otk::display, window, UnmapNotify, &e)) {
505 XPutBackEvent(**otk::display, &e);
507 otk::display->ungrab();
508 return; // don't manage it
511 if (!XGetWindowAttributes(**otk::display, window, &attrib) ||
512 attrib.override_redirect) {
513 otk::display->ungrab();
514 return; // don't manage it
517 // is the window a docking app
518 if ((wmhint = XGetWMHints(**otk::display, window))) {
519 if ((wmhint->flags & StateHint) &&
520 wmhint->initial_state == WithdrawnState) {
521 //slit->addClient(w); // XXX: make dock apps work!
523 otk::display->ungrab();
530 // choose the events we want to receive on the CLIENT window
531 attrib_set.event_mask = Client::event_mask;
532 attrib_set.do_not_propagate_mask = Client::no_propagate_mask;
533 XChangeWindowAttributes(**otk::display, window,
534 CWEventMask|CWDontPropagate, &attrib_set);
536 // create the Client class, which gets all of the hints on the window
537 client = new Client(_number, window);
538 // register for events
539 openbox->registerHandler(window, client);
540 // add to the wm's map
541 openbox->addClient(window, client);
543 // we dont want a border on the client
544 client->toggleClientBorder(false);
546 // specify that if we exit, the window should not be destroyed and should be
547 // reparented back to root automatically
548 XChangeSaveSet(**otk::display, window, SetModeInsert);
550 // create the decoration frame for the client window
551 client->frame = new Frame(client);
552 // register the plate for events (map req's)
553 // this involves removing itself from the handler list first, since it is
554 // auto added to the list, being a widget. we won't get any events on the
555 // plate except for events for the client (SubstructureRedirectMask)
556 openbox->clearHandler(client->frame->plate());
557 openbox->registerHandler(client->frame->plate(), client);
559 // add to the wm's map
560 Window *w = client->frame->allWindows();
561 for (unsigned int i = 0; w[i]; ++i)
562 openbox->addClient(w[i], client);
565 // reparent the client to the frame
566 client->frame->grabClient();
568 if (openbox->state() != Openbox::State_Starting) {
569 // position the window intelligenty .. hopefully :)
570 // call the python PLACEWINDOW binding
571 EventData data(_number, client, EventAction::PlaceWindow, 0);
572 openbox->bindings()->fireEvent(&data);
575 EventData ddata(_number, client, EventAction::DisplayingWindow, 0);
576 openbox->bindings()->fireEvent(&ddata);
580 client->applyStartupState();
582 otk::display->ungrab();
584 // add to the screen's list
585 clients.push_back(client);
586 // once the client is in the list, update our strut to include the new
587 // client's (it is good that this happens after window placement!)
589 // this puts into the stacking order, then raises it
590 _stacking.push_back(client);
592 // update the root properties
595 openbox->bindings()->grabButtons(true, client);
597 EventData ndata(_number, client, EventAction::NewWindow, 0);
598 openbox->bindings()->fireEvent(&ndata);
601 printf("Managed window 0x%lx frame 0x%lx\n",
602 window, client->frame->window());
607 void Screen::unmanageWindow(Client *client)
609 Frame *frame = client->frame;
611 // call the python CLOSEWINDOW binding
612 EventData data(_number, client, EventAction::CloseWindow, 0);
613 openbox->bindings()->fireEvent(&data);
615 openbox->bindings()->grabButtons(false, client);
617 // remove from the wm's map
618 openbox->removeClient(client->window());
619 Window *w = frame->allWindows();
620 for (unsigned int i = 0; w[i]; ++i)
621 openbox->addClient(w[i], client);
623 // unregister for handling events
624 openbox->clearHandler(client->window());
626 // remove the window from our save set
627 XChangeSaveSet(**otk::display, client->window(), SetModeDelete);
629 // we dont want events no more
630 XSelectInput(**otk::display, client->window(), NoEventMask);
634 // give the client its border back
635 client->toggleClientBorder(true);
637 // reparent the window out of the frame
638 frame->releaseClient();
641 Window framewin = client->frame->window();
643 delete client->frame;
646 // remove from the stacking order
647 _stacking.remove(client);
649 // remove from the screen's list
650 clients.remove(client);
652 // once the client is out of the list, update our strut to remove it's
656 // unset modal before dropping our focus
657 client->_modal = false;
659 // unfocus the client (calls the focus callbacks)
660 if (client->focused()) client->unfocus();
663 printf("Unmanaged window 0x%lx frame 0x%lx\n", client->window(), framewin);
668 // update the root properties
672 void Screen::lowerWindow(Client *client)
674 Window wins[2]; // only ever restack 2 windows.
676 assert(!_stacking.empty()); // this would be bad
678 std::list<Client*>::iterator it = --_stacking.end();
679 const std::list<Client*>::iterator end = _stacking.begin();
681 if (client->modal() && client->transientFor()) {
682 // don't let a modal window lower below its transient_for
683 it = std::find(_stacking.begin(), _stacking.end(), client->transientFor());
684 assert(it != _stacking.end());
686 wins[0] = (it == _stacking.begin() ? _focuswindow :
687 ((*(--std::list<Client*>::const_iterator(it)))->
689 wins[1] = client->frame->window();
690 if (wins[0] == wins[1]) return; // already right above the window
692 _stacking.remove(client);
693 _stacking.insert(it, client);
695 for (; it != end && (*it)->layer() < client->layer(); --it);
696 if (*it == client) return; // already the bottom, return
698 wins[0] = (*it)->frame->window();
699 wins[1] = client->frame->window();
701 _stacking.remove(client);
702 _stacking.insert(++it, client);
705 XRestackWindows(**otk::display, wins, 2);
706 changeStackingList();
709 void Screen::raiseWindow(Client *client)
711 Window wins[2]; // only ever restack 2 windows.
713 assert(!_stacking.empty()); // this would be bad
715 Client *m = client->findModalChild();
716 // if we have a modal child, raise it instead, we'll go along tho later
717 if (m) raiseWindow(m);
719 // remove the client before looking so we can't run into ourselves
720 _stacking.remove(client);
722 std::list<Client*>::iterator it = _stacking.begin();
723 const std::list<Client*>::iterator end = _stacking.end();
725 // the stacking list is from highest to lowest
726 for (; it != end && ((*it)->layer() > client->layer() || m == *it); ++it);
729 if our new position is the top, we want to stack under the _focuswindow
730 otherwise, we want to stack under the previous window in the stack.
732 wins[0] = (it == _stacking.begin() ? _focuswindow :
733 ((*(--std::list<Client*>::const_iterator(it)))->frame->window()));
734 wins[1] = client->frame->window();
736 _stacking.insert(it, client);
738 XRestackWindows(**otk::display, wins, 2);
740 changeStackingList();
743 void Screen::changeDesktop(unsigned int desktop)
745 if (desktop >= _num_desktops) return;
747 printf("Moving to desktop %u\n", desktop);
749 unsigned int old = _desktop;
752 otk::Property::set(_info->rootWindow(),
753 otk::Property::atoms.net_current_desktop,
754 otk::Property::atoms.cardinal, _desktop);
756 if (old == _desktop) return;
758 std::list<Client*>::iterator it, end = clients.end();
759 for (it = clients.begin(); it != end; ++it)
762 // force the callbacks to fire
763 if (!openbox->focusedClient())
764 openbox->setFocusedClient(0);
767 void Screen::changeNumDesktops(unsigned int num)
771 if (!(num > 0)) return;
773 // move windows on desktops that will no longer exist!
774 std::list<Client*>::iterator it, end = clients.end();
775 for (it = clients.begin(); it != end; ++it) {
776 unsigned int d = (*it)->desktop();
777 if (d >= num && d != 0xffffffff) {
779 ce.xclient.type = ClientMessage;
780 ce.xclient.message_type = otk::Property::atoms.net_wm_desktop;
781 ce.xclient.display = **otk::display;
782 ce.xclient.window = (*it)->window();
783 ce.xclient.format = 32;
784 ce.xclient.data.l[0] = num - 1;
785 XSendEvent(**otk::display, _info->rootWindow(), false,
786 SubstructureNotifyMask | SubstructureRedirectMask, &ce);
791 otk::Property::set(_info->rootWindow(),
792 otk::Property::atoms.net_number_of_desktops,
793 otk::Property::atoms.cardinal, _num_desktops);
795 // set the viewport hint
796 unsigned long *viewport = new unsigned long[_num_desktops * 2];
797 memset(viewport, 0, sizeof(unsigned long) * _num_desktops * 2);
798 otk::Property::set(_info->rootWindow(),
799 otk::Property::atoms.net_desktop_viewport,
800 otk::Property::atoms.cardinal,
801 viewport, _num_desktops * 2);
804 // change our struts/area to match
805 _area.resize(_num_desktops + 1);
806 _struts.resize(_num_desktops + 1);
809 // the number of rows/columns will differ
810 updateDesktopLayout();
812 // may be some unnamed desktops that we need to fill in with names
813 updateDesktopNames();
815 // change our desktop if we're on one that no longer exists!
816 if (_desktop >= _num_desktops)
817 changeDesktop(_num_desktops - 1);
821 void Screen::updateDesktopNames()
825 if (!otk::Property::get(_info->rootWindow(),
826 otk::Property::atoms.net_desktop_names,
827 otk::Property::utf8, &num, &_desktop_names))
828 _desktop_names.clear();
829 while (_desktop_names.size() < _num_desktops)
830 _desktop_names.push_back("Unnamed");
834 const otk::Rect& Screen::area(unsigned int desktop) const {
835 assert(desktop < _num_desktops || desktop == 0xffffffff);
836 if (desktop < _num_desktops)
837 return _area[desktop];
839 return _area[_num_desktops];
842 void Screen::installColormap(bool install) const
845 XInstallColormap(**otk::display, _info->colormap());
847 XUninstallColormap(**otk::display, _info->colormap());
850 void Screen::showDesktop(bool show)
852 if (show == _showing_desktop) return; // no change
854 // save the window focus, and restore it when leaving the show-desktop mode
855 static Window saved_focus = 0;
857 Client *c = openbox->focusedClient();
858 if (c) saved_focus = c->window();
861 _showing_desktop = show;
863 std::list<Client*>::iterator it, end = clients.end();
864 for (it = clients.begin(); it != end; ++it) {
865 if ((*it)->type() == Client::Type_Desktop) {
873 Client *f = openbox->focusedClient();
874 if (!f || f->type() == Client::Type_Desktop) {
875 Client *c = openbox->findClient(saved_focus);
880 otk::Property::set(_info->rootWindow(),
881 otk::Property::atoms.net_showing_desktop,
882 otk::Property::atoms.cardinal,
886 void Screen::propertyHandler(const XPropertyEvent &e)
888 otk::EventHandler::propertyHandler(e);
890 // compress changes to a single property into a single change
892 while (XCheckTypedWindowEvent(**otk::display, _info->rootWindow(),
894 // XXX: it would be nice to compress ALL changes to a property, not just
895 // changes in a row without other props between.
896 if (ce.xproperty.atom != e.atom) {
897 XPutBackEvent(**otk::display, &ce);
902 if (e.atom == otk::Property::atoms.net_desktop_names)
903 updateDesktopNames();
904 else if (e.atom == otk::Property::atoms.net_desktop_layout)
905 updateDesktopLayout();
909 void Screen::clientMessageHandler(const XClientMessageEvent &e)
911 otk::EventHandler::clientMessageHandler(e);
913 if (e.format != 32) return;
915 if (e.message_type == otk::Property::atoms.net_current_desktop) {
916 changeDesktop(e.data.l[0]);
917 } else if (e.message_type == otk::Property::atoms.net_number_of_desktops) {
918 changeNumDesktops(e.data.l[0]);
919 } else if (e.message_type == otk::Property::atoms.net_showing_desktop) {
920 showDesktop(e.data.l[0] != 0);
925 void Screen::mapRequestHandler(const XMapRequestEvent &e)
927 otk::EventHandler::mapRequestHandler(e);
930 printf("MapRequest for 0x%lx\n", e.window);
933 Client *c = openbox->findClient(e.window);
936 printf("DEBUG: MAP REQUEST CAUGHT IN SCREEN. IGNORED.\n");
939 if (_showing_desktop)
940 showDesktop(false); // leave showing-the-desktop mode
941 manageWindow(e.window);