1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
7 # include <sys/types.h>
9 #endif // HAVE_UNISTD_H
12 #define _(str) gettext(str)
19 #include "bindings.hh"
21 #include "otk/display.hh"
22 #include "otk/property.hh"
30 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
31 printf(_("Another window manager already running on display %s.\n"),
32 DisplayString(display
));
41 Screen::Screen(int screen
)
44 assert(screen
>= 0); assert(screen
< ScreenCount(**otk::display
));
45 _info
= otk::display
->screenInfo(screen
);
47 _showing_desktop
= false;
50 XErrorHandler old
= XSetErrorHandler(::anotherWMRunning
);
51 XSelectInput(**otk::display
, _info
->rootWindow(),
53 XSync(**otk::display
, false);
54 XSetErrorHandler(old
);
56 _managed
= !::running
;
57 if (! _managed
) return; // was unable to manage the screen
60 printf(_("Managing screen %d: visual 0x%lx, depth %d\n"),
61 _number
, XVisualIDFromVisual(_info
->visual()), _info
->depth());
64 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.openbox_pid
,
65 otk::Property::atoms
.cardinal
, (unsigned long) getpid());
67 // set the mouse cursor for the root window (the default cursor)
68 XDefineCursor(**otk::display
, _info
->rootWindow(),
69 openbox
->cursors().session
);
71 // XXX: initialize the screen's style
73 otk::ustring stylepath;
74 python_get_string("THEME", &stylepath);
75 otk::Configuration sconfig(false);
76 sconfig.setFile(otk::expandTilde(stylepath.c_str()));
77 if (!sconfig.load()) {
78 sconfig.setFile(otk::expandTilde(DEFAULTSTYLE));
79 if (!sconfig.load()) {
80 printf(_("Unable to load default style: %s. Aborting.\n"), DEFAULTSTYLE);
86 otk::display
->renderControl(_number
)->
87 drawRoot(*otk::RenderStyle::style(_number
)->rootColor());
89 // set up notification of netwm support
90 changeSupportedAtoms();
92 // Set the netwm properties for geometry
93 unsigned long geometry
[] = { _info
->size().width(),
94 _info
->size().height() };
95 otk::Property::set(_info
->rootWindow(),
96 otk::Property::atoms
.net_desktop_geometry
,
97 otk::Property::atoms
.cardinal
, geometry
, 2);
99 // Set the net_desktop_names property
100 std::vector
<otk::ustring
> names
;
101 python_get_stringlist("DESKTOP_NAMES", &names
);
102 otk::Property::set(_info
->rootWindow(),
103 otk::Property::atoms
.net_desktop_names
,
104 otk::Property::utf8
, names
);
105 // the above set() will cause the updateDesktopNames to fire right away so
106 // we have a list of desktop names
110 if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&_num_desktops
))
112 changeNumDesktops(_num_desktops
); // set the hint
114 changeDesktop(0); // set the hint
116 // create the window which gets focus when no clients get it
117 XSetWindowAttributes attr
;
118 attr
.override_redirect
= true;
119 _focuswindow
= XCreateWindow(**otk::display
, _info
->rootWindow(),
120 -100, -100, 1, 1, 0, 0, InputOnly
,
121 _info
->visual(), CWOverrideRedirect
, &attr
);
122 XMapRaised(**otk::display
, _focuswindow
);
124 // these may be further updated if any pre-existing windows are found in
125 // the manageExising() function
126 changeClientList(); // initialize the client lists, which will be empty
128 updateDesktopLayout();
130 // register this class as the event handler for the root window
131 openbox
->registerHandler(_info
->rootWindow(), this);
133 // call the python Startup callbacks
134 EventData
data(_number
, 0, EventAction::Startup
, 0);
135 openbox
->bindings()->fireEvent(&data
);
141 if (! _managed
) return;
143 XSelectInput(**otk::display
, _info
->rootWindow(), NoEventMask
);
145 // unmanage all windows
146 while (!clients
.empty())
147 unmanageWindow(clients
.front());
149 // call the python Shutdown callbacks
150 EventData
data(_number
, 0, EventAction::Shutdown
, 0);
151 openbox
->bindings()->fireEvent(&data
);
153 XDestroyWindow(**otk::display
, _focuswindow
);
154 XDestroyWindow(**otk::display
, _supportwindow
);
158 void Screen::manageExisting()
160 unsigned int i
, j
, nchild
;
161 Window r
, p
, *children
;
162 XQueryTree(**otk::display
, _info
->rootWindow(), &r
, &p
,
165 // preen the window list of all icon windows... for better dockapp support
166 for (i
= 0; i
< nchild
; i
++) {
167 if (children
[i
] == None
) continue;
169 XWMHints
*wmhints
= XGetWMHints(**otk::display
,
173 if ((wmhints
->flags
& IconWindowHint
) &&
174 (wmhints
->icon_window
!= children
[i
])) {
175 for (j
= 0; j
< nchild
; j
++) {
176 if (children
[j
] == wmhints
->icon_window
) {
187 // manage shown windows
188 for (i
= 0; i
< nchild
; ++i
) {
189 if (children
[i
] == None
)
192 XWindowAttributes attrib
;
193 if (XGetWindowAttributes(**otk::display
, children
[i
], &attrib
)) {
194 if (attrib
.override_redirect
) continue;
196 if (attrib
.map_state
!= IsUnmapped
) {
197 manageWindow(children
[i
]);
205 void Screen::updateDesktopLayout()
207 //const unsigned long _NET_WM_ORIENTATION_HORZ = 0;
208 const unsigned long _NET_WM_ORIENTATION_VERT
= 1;
209 //const unsigned long _NET_WM_TOPLEFT = 0;
210 const unsigned long _NET_WM_TOPRIGHT
= 1;
211 const unsigned long _NET_WM_BOTTOMRIGHT
= 2;
212 const unsigned long _NET_WM_BOTTOMLEFT
= 3;
215 _layout
.orientation
= DesktopLayout::Horizontal
;
216 _layout
.start_corner
= DesktopLayout::TopLeft
;
218 _layout
.columns
= _num_desktops
;
220 unsigned long *data
, num
= 4;
221 if (otk::Property::get(_info
->rootWindow(),
222 otk::Property::atoms
.net_desktop_layout
,
223 otk::Property::atoms
.cardinal
,
226 if (data
[0] == _NET_WM_ORIENTATION_VERT
)
227 _layout
.orientation
= DesktopLayout::Vertical
;
228 if (data
[3] == _NET_WM_TOPRIGHT
)
229 _layout
.start_corner
= DesktopLayout::TopRight
;
230 else if (data
[3] == _NET_WM_BOTTOMRIGHT
)
231 _layout
.start_corner
= DesktopLayout::BottomRight
;
232 else if (data
[3] == _NET_WM_BOTTOMLEFT
)
233 _layout
.start_corner
= DesktopLayout::BottomLeft
;
235 // fill in a zero rows/columns
236 if (!(data
[1] == 0 && data
[2] == 0)) { // both 0's is bad data..
238 data
[1] = (_num_desktops
+ _num_desktops
% data
[2]) / data
[2];
239 } else if (data
[2] == 0) {
240 data
[2] = (_num_desktops
+ _num_desktops
% data
[1]) / data
[1];
242 _layout
.columns
= data
[1];
243 _layout
.rows
= data
[2];
247 if (_layout
.orientation
== DesktopLayout::Horizontal
) {
248 if (_layout
.rows
> _num_desktops
) _layout
.rows
= _num_desktops
;
249 if (_layout
.columns
> (_num_desktops
+ _num_desktops
% _layout
.rows
) /
251 _layout
.columns
= (_num_desktops
+ _num_desktops
% _layout
.rows
) /
254 if (_layout
.columns
> _num_desktops
) _layout
.columns
= _num_desktops
;
255 if (_layout
.rows
> (_num_desktops
+ _num_desktops
% _layout
.columns
) /
257 _layout
.rows
= (_num_desktops
+ _num_desktops
% _layout
.columns
) /
265 void Screen::updateStruts()
268 void operator()(otk::Strut
&self
, const otk::Strut
&other
) {
269 self
.left
= std::max(self
.left
, other
.left
);
270 self
.right
= std::max(self
.right
, other
.right
);
271 self
.top
= std::max(self
.top
, other
.top
);
272 self
.bottom
= std::max(self
.bottom
, other
.bottom
);
276 StrutList::iterator sit
, send
= _struts
.end();
278 for (sit
= _struts
.begin(); sit
!= send
; ++sit
)
279 sit
->left
= sit
->right
= sit
->top
= sit
->bottom
= 0;
281 ClientList::const_iterator it
, end
= clients
.end();
282 for (it
= clients
.begin(); it
!= end
; ++it
) {
283 if ((*it
)->iconic()) continue; // these dont count in the strut
285 unsigned int desk
= (*it
)->desktop();
286 const otk::Strut
&s
= (*it
)->strut();
288 if (desk
== 0xffffffff)
289 for (unsigned int i
= 0, e
= _struts
.size(); i
< e
; ++i
)
290 apply(_struts
[i
], s
);
291 else if (desk
< _struts
.size())
292 apply(_struts
[desk
], s
);
294 assert(false); // invalid desktop otherwise..
295 // apply to the 'all desktops' strut
296 apply(_struts
.back(), s
);
302 void Screen::changeWorkArea()
304 unsigned long *dims
= new unsigned long[4 * _num_desktops
];
305 for (unsigned int i
= 0; i
< _num_desktops
+ 1; ++i
) {
306 otk::Rect old_area
= _area
[i
];
309 // reset to the full areas
310 if (isXineramaActive())
311 xineramaUsableArea = getXineramaAreas();
315 _area
[i
] = otk::Rect(_struts
[i
].left
, _struts
[i
].top
,
316 _info
->size().width() - (_struts
[i
].left
+
318 _info
->size().height() - (_struts
[i
].top
+
323 if (isXineramaActive()) {
324 // keep each of the ximerama-defined areas inside the strut
325 RectList::iterator xit, xend = xineramaUsableArea.end();
326 for (xit = xineramaUsableArea.begin(); xit != xend; ++xit) {
327 if (xit->x() < usableArea.x()) {
328 xit->setX(usableArea.x());
329 xit->setWidth(xit->width() - usableArea.x());
331 if (xit->y() < usableArea.y()) {
332 xit->setY(usableArea.y());
333 xit->setHeight(xit->height() - usableArea.y());
335 if (xit->x() + xit->width() > usableArea.width())
336 xit->setWidth(usableArea.width() - xit->x());
337 if (xit->y() + xit->height() > usableArea.height())
338 xit->setHeight(usableArea.height() - xit->y());
343 if (old_area
!= _area
[i
]) {
344 // the area has changed, adjust all the maximized windows
345 ClientList::iterator it
, end
= clients
.end();
346 for (it
= clients
.begin(); it
!= end
; ++it
)
347 if (i
< _num_desktops
) {
348 if ((*it
)->desktop() == i
)
351 // the 'all desktops' size
352 if ((*it
)->desktop() == 0xffffffff)
357 // don't set these for the 'all desktops' area
358 if (i
< _num_desktops
) {
359 dims
[(i
* 4) + 0] = _area
[i
].x();
360 dims
[(i
* 4) + 1] = _area
[i
].y();
361 dims
[(i
* 4) + 2] = _area
[i
].width();
362 dims
[(i
* 4) + 3] = _area
[i
].height();
365 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.net_workarea
,
366 otk::Property::atoms
.cardinal
, dims
, 4 * _num_desktops
);
371 void Screen::changeSupportedAtoms()
373 // create the netwm support window
374 _supportwindow
= XCreateSimpleWindow(**otk::display
,
376 0, 0, 1, 1, 0, 0, 0);
378 // set supporting window
379 otk::Property::set(_info
->rootWindow(),
380 otk::Property::atoms
.net_supporting_wm_check
,
381 otk::Property::atoms
.window
, _supportwindow
);
383 //set properties on the supporting window
384 otk::Property::set(_supportwindow
, otk::Property::atoms
.net_wm_name
,
385 otk::Property::utf8
, "Openbox");
386 otk::Property::set(_supportwindow
,
387 otk::Property::atoms
.net_supporting_wm_check
,
388 otk::Property::atoms
.window
, _supportwindow
);
392 otk::Property::atoms
.net_current_desktop
,
393 otk::Property::atoms
.net_number_of_desktops
,
394 otk::Property::atoms
.net_desktop_geometry
,
395 otk::Property::atoms
.net_desktop_viewport
,
396 otk::Property::atoms
.net_active_window
,
397 otk::Property::atoms
.net_workarea
,
398 otk::Property::atoms
.net_client_list
,
399 otk::Property::atoms
.net_client_list_stacking
,
400 otk::Property::atoms
.net_desktop_names
,
401 otk::Property::atoms
.net_close_window
,
402 otk::Property::atoms
.net_desktop_layout
,
403 otk::Property::atoms
.net_showing_desktop
,
404 otk::Property::atoms
.net_wm_name
,
405 otk::Property::atoms
.net_wm_visible_name
,
406 otk::Property::atoms
.net_wm_icon_name
,
407 otk::Property::atoms
.net_wm_visible_icon_name
,
408 otk::Property::atoms
.net_wm_desktop
,
409 otk::Property::atoms
.net_wm_strut
,
410 otk::Property::atoms
.net_wm_window_type
,
411 otk::Property::atoms
.net_wm_window_type_desktop
,
412 otk::Property::atoms
.net_wm_window_type_dock
,
413 otk::Property::atoms
.net_wm_window_type_toolbar
,
414 otk::Property::atoms
.net_wm_window_type_menu
,
415 otk::Property::atoms
.net_wm_window_type_utility
,
416 otk::Property::atoms
.net_wm_window_type_splash
,
417 otk::Property::atoms
.net_wm_window_type_dialog
,
418 otk::Property::atoms
.net_wm_window_type_normal
,
420 otk::Property::atoms.net_wm_moveresize,
421 otk::Property::atoms.net_wm_moveresize_size_topleft,
422 otk::Property::atoms.net_wm_moveresize_size_topright,
423 otk::Property::atoms.net_wm_moveresize_size_bottomleft,
424 otk::Property::atoms.net_wm_moveresize_size_bottomright,
425 otk::Property::atoms.net_wm_moveresize_move,
427 otk::Property::atoms
.net_wm_allowed_actions
,
428 otk::Property::atoms
.net_wm_action_move
,
429 otk::Property::atoms
.net_wm_action_resize
,
430 otk::Property::atoms
.net_wm_action_minimize
,
431 otk::Property::atoms
.net_wm_action_shade
,
432 /* otk::Property::atoms.net_wm_action_stick,*/
433 otk::Property::atoms
.net_wm_action_maximize_horz
,
434 otk::Property::atoms
.net_wm_action_maximize_vert
,
435 otk::Property::atoms
.net_wm_action_fullscreen
,
436 otk::Property::atoms
.net_wm_action_change_desktop
,
437 otk::Property::atoms
.net_wm_action_close
,
439 otk::Property::atoms
.net_wm_state
,
440 otk::Property::atoms
.net_wm_state_modal
,
441 otk::Property::atoms
.net_wm_state_maximized_vert
,
442 otk::Property::atoms
.net_wm_state_maximized_horz
,
443 otk::Property::atoms
.net_wm_state_shaded
,
444 otk::Property::atoms
.net_wm_state_skip_taskbar
,
445 otk::Property::atoms
.net_wm_state_skip_pager
,
446 otk::Property::atoms
.net_wm_state_hidden
,
447 otk::Property::atoms
.net_wm_state_fullscreen
,
448 otk::Property::atoms
.net_wm_state_above
,
449 otk::Property::atoms
.net_wm_state_below
,
451 const int num_supported
= sizeof(supported
)/sizeof(Atom
);
453 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.net_supported
,
454 otk::Property::atoms
.atom
, supported
, num_supported
);
458 void Screen::changeClientList()
461 unsigned int size
= clients
.size();
463 // create an array of the window ids
467 windows
= new Window
[size
];
469 ClientList::const_iterator it
= clients
.begin();
470 const ClientList::const_iterator end
= clients
.end();
471 for (; it
!= end
; ++it
, ++win_it
)
472 *win_it
= (*it
)->window();
474 windows
= (Window
*) 0;
476 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.net_client_list
,
477 otk::Property::atoms
.window
, windows
, size
);
482 changeStackingList();
486 void Screen::changeStackingList()
489 unsigned int size
= _stacking
.size();
491 assert(size
== clients
.size()); // just making sure.. :)
494 // create an array of the window ids (from bottom to top, reverse order!)
498 windows
= new Window
[size
];
500 ClientList::const_reverse_iterator it
= _stacking
.rbegin();
501 const ClientList::const_reverse_iterator end
= _stacking
.rend();
502 for (; it
!= end
; ++it
, ++win_it
)
503 *win_it
= (*it
)->window();
505 windows
= (Window
*) 0;
507 otk::Property::set(_info
->rootWindow(),
508 otk::Property::atoms
.net_client_list_stacking
,
509 otk::Property::atoms
.window
, windows
, size
);
516 void Screen::manageWindow(Window window
)
520 XSetWindowAttributes attrib_set
;
522 XWindowAttributes attrib
;
524 otk::display
->grab();
526 // check if it has already been unmapped by the time we started mapping
527 // the grab does a sync so we don't have to here
528 if (XCheckTypedWindowEvent(**otk::display
, window
, DestroyNotify
, &e
) ||
529 XCheckTypedWindowEvent(**otk::display
, window
, UnmapNotify
, &e
)) {
530 XPutBackEvent(**otk::display
, &e
);
532 otk::display
->ungrab();
533 return; // don't manage it
536 if (!XGetWindowAttributes(**otk::display
, window
, &attrib
) ||
537 attrib
.override_redirect
) {
538 otk::display
->ungrab();
539 return; // don't manage it
542 // is the window a docking app
543 if ((wmhint
= XGetWMHints(**otk::display
, window
))) {
544 if ((wmhint
->flags
& StateHint
) &&
545 wmhint
->initial_state
== WithdrawnState
) {
546 //slit->addClient(w); // XXX: make dock apps work!
548 otk::display
->ungrab();
555 // choose the events we want to receive on the CLIENT window
556 attrib_set
.event_mask
= Client::event_mask
;
557 attrib_set
.do_not_propagate_mask
= Client::no_propagate_mask
;
558 XChangeWindowAttributes(**otk::display
, window
,
559 CWEventMask
|CWDontPropagate
, &attrib_set
);
561 // create the Client class, which gets all of the hints on the window
562 client
= new Client(_number
, window
);
563 // register for events
564 openbox
->registerHandler(window
, client
);
565 // add to the wm's map
566 openbox
->addClient(window
, client
);
568 // we dont want a border on the client
569 client
->toggleClientBorder(false);
571 // specify that if we exit, the window should not be destroyed and should be
572 // reparented back to root automatically
573 XChangeSaveSet(**otk::display
, window
, SetModeInsert
);
575 // create the decoration frame for the client window
576 client
->frame
= new Frame(client
);
577 // register the plate for events (map req's)
578 // this involves removing itself from the handler list first, since it is
579 // auto added to the list, being a widget. we won't get any events on the
580 // plate except for events for the client (SubstructureRedirectMask)
581 openbox
->clearHandler(client
->frame
->plate());
582 openbox
->registerHandler(client
->frame
->plate(), client
);
584 // add to the wm's map
585 Window
*w
= client
->frame
->allWindows();
586 for (unsigned int i
= 0; w
[i
]; ++i
)
587 openbox
->addClient(w
[i
], client
);
590 // reparent the client to the frame
591 client
->frame
->grabClient();
593 if (openbox
->state() != Openbox::State_Starting
) {
594 // position the window intelligenty .. hopefully :)
595 // call the python PLACEWINDOW binding
596 EventData
data(_number
, client
, EventAction::PlaceWindow
, 0);
597 openbox
->bindings()->fireEvent(&data
);
600 EventData
ddata(_number
, client
, EventAction::DisplayingWindow
, 0);
601 openbox
->bindings()->fireEvent(&ddata
);
605 client
->applyStartupState();
607 otk::display
->ungrab();
609 // add to the screen's list
610 clients
.push_back(client
);
611 // once the client is in the list, update our strut to include the new
612 // client's (it is good that this happens after window placement!)
614 // this puts into the stacking order, then raises it
615 _stacking
.push_back(client
);
617 // update the root properties
620 openbox
->bindings()->grabButtons(true, client
);
622 EventData
ndata(_number
, client
, EventAction::NewWindow
, 0);
623 openbox
->bindings()->fireEvent(&ndata
);
626 printf("Managed window 0x%lx frame 0x%lx\n",
627 window
, client
->frame
->window());
632 void Screen::unmanageWindow(Client
*client
)
634 Frame
*frame
= client
->frame
;
636 // call the python CLOSEWINDOW binding
637 EventData
data(_number
, client
, EventAction::CloseWindow
, 0);
638 openbox
->bindings()->fireEvent(&data
);
640 openbox
->bindings()->grabButtons(false, client
);
642 // remove from the wm's map
643 openbox
->removeClient(client
->window());
644 Window
*w
= frame
->allWindows();
645 for (unsigned int i
= 0; w
[i
]; ++i
)
646 openbox
->addClient(w
[i
], client
);
648 // unregister for handling events
649 openbox
->clearHandler(client
->window());
651 // remove the window from our save set
652 XChangeSaveSet(**otk::display
, client
->window(), SetModeDelete
);
654 // we dont want events no more
655 XSelectInput(**otk::display
, client
->window(), NoEventMask
);
659 // give the client its border back
660 client
->toggleClientBorder(true);
662 // reparent the window out of the frame
663 frame
->releaseClient();
666 Window framewin
= client
->frame
->window();
668 delete client
->frame
;
671 // remove from the stacking order
672 _stacking
.remove(client
);
674 // remove from the screen's list
675 clients
.remove(client
);
677 // once the client is out of the list, update our strut to remove it's
681 // unset modal before dropping our focus
682 client
->_modal
= false;
684 // unfocus the client (calls the focus callbacks)
688 printf("Unmanaged window 0x%lx frame 0x%lx\n", client
->window(), framewin
);
693 // update the root properties
697 void Screen::lowerWindow(Client
*client
)
699 Window wins
[2]; // only ever restack 2 windows.
701 assert(!_stacking
.empty()); // this would be bad
703 ClientList::iterator it
= --_stacking
.end();
704 const ClientList::iterator end
= _stacking
.begin();
706 if (client
->modal() && client
->transientFor()) {
707 // don't let a modal window lower below its transient_for
708 it
= std::find(_stacking
.begin(), _stacking
.end(), client
->transientFor());
709 assert(it
!= _stacking
.end());
711 wins
[0] = (it
== _stacking
.begin() ? _focuswindow
:
712 ((*(--ClientList::const_iterator(it
)))->frame
->window()));
713 wins
[1] = client
->frame
->window();
714 if (wins
[0] == wins
[1]) return; // already right above the window
716 _stacking
.remove(client
);
717 _stacking
.insert(it
, client
);
719 for (; it
!= end
&& (*it
)->layer() < client
->layer(); --it
);
720 if (*it
== client
) return; // already the bottom, return
722 wins
[0] = (*it
)->frame
->window();
723 wins
[1] = client
->frame
->window();
725 _stacking
.remove(client
);
726 _stacking
.insert(++it
, client
);
729 XRestackWindows(**otk::display
, wins
, 2);
730 changeStackingList();
733 void Screen::raiseWindow(Client
*client
)
735 Window wins
[2]; // only ever restack 2 windows.
737 assert(!_stacking
.empty()); // this would be bad
739 Client
*m
= client
->findModalChild();
740 // if we have a modal child, raise it instead, we'll go along tho later
741 if (m
) raiseWindow(m
);
743 // remove the client before looking so we can't run into ourselves
744 _stacking
.remove(client
);
746 ClientList::iterator it
= _stacking
.begin();
747 const ClientList::iterator end
= _stacking
.end();
749 // the stacking list is from highest to lowest
750 for (; it
!= end
&& ((*it
)->layer() > client
->layer() || m
== *it
); ++it
);
753 if our new position is the top, we want to stack under the _focuswindow
754 otherwise, we want to stack under the previous window in the stack.
756 wins
[0] = (it
== _stacking
.begin() ? _focuswindow
:
757 ((*(--ClientList::const_iterator(it
)))->frame
->window()));
758 wins
[1] = client
->frame
->window();
760 _stacking
.insert(it
, client
);
762 XRestackWindows(**otk::display
, wins
, 2);
764 changeStackingList();
767 void Screen::changeDesktop(unsigned int desktop
)
769 if (desktop
>= _num_desktops
) return;
771 printf("Moving to desktop %u\n", desktop
);
773 unsigned int old
= _desktop
;
776 otk::Property::set(_info
->rootWindow(),
777 otk::Property::atoms
.net_current_desktop
,
778 otk::Property::atoms
.cardinal
, _desktop
);
780 if (old
== _desktop
) return;
782 ClientList::iterator it
, end
= clients
.end();
783 for (it
= clients
.begin(); it
!= end
; ++it
)
786 // force the callbacks to fire
787 if (!openbox
->focusedClient())
788 openbox
->setFocusedClient(0);
791 void Screen::changeNumDesktops(unsigned int num
)
795 if (!(num
> 0)) return;
797 // move windows on desktops that will no longer exist!
798 ClientList::iterator it
, end
= clients
.end();
799 for (it
= clients
.begin(); it
!= end
; ++it
) {
800 unsigned int d
= (*it
)->desktop();
801 if (d
>= num
&& d
!= 0xffffffff) {
803 ce
.xclient
.type
= ClientMessage
;
804 ce
.xclient
.message_type
= otk::Property::atoms
.net_wm_desktop
;
805 ce
.xclient
.display
= **otk::display
;
806 ce
.xclient
.window
= (*it
)->window();
807 ce
.xclient
.format
= 32;
808 ce
.xclient
.data
.l
[0] = num
- 1;
809 XSendEvent(**otk::display
, _info
->rootWindow(), False
,
810 SubstructureNotifyMask
| SubstructureRedirectMask
, &ce
);
815 otk::Property::set(_info
->rootWindow(),
816 otk::Property::atoms
.net_number_of_desktops
,
817 otk::Property::atoms
.cardinal
, _num_desktops
);
819 // set the viewport hint
820 unsigned long *viewport
= new unsigned long[_num_desktops
* 2];
821 memset(viewport
, 0, sizeof(unsigned long) * _num_desktops
* 2);
822 otk::Property::set(_info
->rootWindow(),
823 otk::Property::atoms
.net_desktop_viewport
,
824 otk::Property::atoms
.cardinal
,
825 viewport
, _num_desktops
* 2);
828 // change our struts/area to match
829 _area
.resize(_num_desktops
+ 1);
830 _struts
.resize(_num_desktops
+ 1);
833 // the number of rows/columns will differ
834 updateDesktopLayout();
836 // change our desktop if we're on one that no longer exists!
837 if (_desktop
>= _num_desktops
)
838 changeDesktop(_num_desktops
- 1);
842 void Screen::updateDesktopNames()
844 unsigned long num
= (unsigned) -1;
846 if (!otk::Property::get(_info
->rootWindow(),
847 otk::Property::atoms
.net_desktop_names
,
848 otk::Property::utf8
, &num
, &_desktop_names
))
849 _desktop_names
.clear();
850 while (_desktop_names
.size() < _num_desktops
)
851 _desktop_names
.push_back("Unnamed");
855 void Screen::setDesktopName(unsigned int i
, const otk::ustring
&name
)
857 if (i
>= _num_desktops
) return;
859 otk::Property::StringVect newnames
= _desktop_names
;
861 otk::Property::set(_info
->rootWindow(),
862 otk::Property::atoms
.net_desktop_names
,
863 otk::Property::utf8
, newnames
);
867 const otk::Rect
& Screen::area(unsigned int desktop
) const {
868 assert(desktop
< _num_desktops
|| desktop
== 0xffffffff);
869 if (desktop
< _num_desktops
)
870 return _area
[desktop
];
872 return _area
[_num_desktops
];
875 void Screen::installColormap(bool install
) const
878 XInstallColormap(**otk::display
, _info
->colormap());
880 XUninstallColormap(**otk::display
, _info
->colormap());
883 void Screen::showDesktop(bool show
)
885 if (show
== _showing_desktop
) return; // no change
887 // save the window focus, and restore it when leaving the show-desktop mode
888 static Window saved_focus
= 0;
890 Client
*c
= openbox
->focusedClient();
891 if (c
) saved_focus
= c
->window();
893 Client
*c
= openbox
->findClient(saved_focus
);
897 _showing_desktop
= show
;
898 ClientList::iterator it
, end
= clients
.end();
899 for (it
= clients
.begin(); it
!= end
; ++it
) {
900 if ((*it
)->type() == Client::Type_Desktop
) {
908 void Screen::propertyHandler(const XPropertyEvent
&e
)
910 otk::EventHandler::propertyHandler(e
);
912 // compress changes to a single property into a single change
914 while (XCheckTypedWindowEvent(**otk::display
, _info
->rootWindow(),
916 // XXX: it would be nice to compress ALL changes to a property, not just
917 // changes in a row without other props between.
918 if (ce
.xproperty
.atom
!= e
.atom
) {
919 XPutBackEvent(**otk::display
, &ce
);
924 if (e
.atom
== otk::Property::atoms
.net_desktop_names
)
925 updateDesktopNames();
926 else if (e
.atom
== otk::Property::atoms
.net_desktop_layout
)
927 updateDesktopLayout();
931 void Screen::clientMessageHandler(const XClientMessageEvent
&e
)
933 otk::EventHandler::clientMessageHandler(e
);
935 if (e
.format
!= 32) return;
937 if (e
.message_type
== otk::Property::atoms
.net_current_desktop
) {
938 changeDesktop(e
.data
.l
[0]);
939 } else if (e
.message_type
== otk::Property::atoms
.net_number_of_desktops
) {
940 changeNumDesktops(e
.data
.l
[0]);
941 } else if (e
.message_type
== otk::Property::atoms
.net_showing_desktop
) {
942 showDesktop(e
.data
.l
[0] != 0);
947 void Screen::mapRequestHandler(const XMapRequestEvent
&e
)
949 otk::EventHandler::mapRequestHandler(e
);
952 printf("MapRequest for 0x%lx\n", e
.window
);
955 Client
*c
= openbox
->findClient(e
.window
);
958 printf("DEBUG: MAP REQUEST CAUGHT IN SCREEN. IGNORED.\n");
961 if (_showing_desktop
)
962 showDesktop(false); // leave showing-the-desktop mode
963 manageWindow(e
.window
);