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
);
48 XErrorHandler old
= XSetErrorHandler(::anotherWMRunning
);
49 XSelectInput(**otk::display
, _info
->rootWindow(),
51 XSync(**otk::display
, false);
52 XSetErrorHandler(old
);
54 _managed
= !::running
;
55 if (! _managed
) return; // was unable to manage the screen
58 printf(_("Managing screen %d: visual 0x%lx, depth %d\n"),
59 _number
, XVisualIDFromVisual(_info
->visual()), _info
->depth());
62 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.openbox_pid
,
63 otk::Property::atoms
.cardinal
, (unsigned long) getpid());
65 // set the mouse cursor for the root window (the default cursor)
66 XDefineCursor(**otk::display
, _info
->rootWindow(),
67 openbox
->cursors().session
);
69 // XXX: initialize the screen's style
71 otk::ustring stylepath;
72 python_get_string("THEME", &stylepath);
73 otk::Configuration sconfig(false);
74 sconfig.setFile(otk::expandTilde(stylepath.c_str()));
75 if (!sconfig.load()) {
76 sconfig.setFile(otk::expandTilde(DEFAULTSTYLE));
77 if (!sconfig.load()) {
78 printf(_("Unable to load default style: %s. Aborting.\n"), DEFAULTSTYLE);
84 otk::display
->renderControl(_number
)->
85 drawRoot(*otk::RenderStyle::style(_number
)->rootColor());
87 // set up notification of netwm support
88 changeSupportedAtoms();
90 // Set the netwm properties for geometry
91 unsigned long geometry
[] = { _info
->size().width(),
92 _info
->size().height() };
93 otk::Property::set(_info
->rootWindow(),
94 otk::Property::atoms
.net_desktop_geometry
,
95 otk::Property::atoms
.cardinal
, geometry
, 2);
97 // Set the net_desktop_names property
98 std::vector
<otk::ustring
> names
;
99 python_get_stringlist("DESKTOP_NAMES", &names
);
100 otk::Property::set(_info
->rootWindow(),
101 otk::Property::atoms
.net_desktop_names
,
102 otk::Property::utf8
, names
);
103 // the above set() will cause the updateDesktopNames to fire right away so
104 // we have a list of desktop names
108 if (!python_get_long("NUMBER_OF_DESKTOPS", &_num_desktops
))
110 changeNumDesktops(_num_desktops
); // set the hint
112 changeDesktop(0); // set the hint
114 // create the window which gets focus when no clients get it
115 XSetWindowAttributes attr
;
116 attr
.override_redirect
= true;
117 _focuswindow
= XCreateWindow(**otk::display
, _info
->rootWindow(),
118 -100, -100, 1, 1, 0, 0, InputOnly
,
119 _info
->visual(), CWOverrideRedirect
, &attr
);
120 XMapRaised(**otk::display
, _focuswindow
);
122 // these may be further updated if any pre-existing windows are found in
123 // the manageExising() function
124 changeClientList(); // initialize the client lists, which will be empty
126 // register this class as the event handler for the root window
127 openbox
->registerHandler(_info
->rootWindow(), this);
129 // call the python Startup callbacks
130 EventData
data(_number
, 0, EventAction::Startup
, 0);
131 openbox
->bindings()->fireEvent(&data
);
137 if (! _managed
) return;
139 XSelectInput(**otk::display
, _info
->rootWindow(), NoEventMask
);
141 // unmanage all windows
142 while (!clients
.empty())
143 unmanageWindow(clients
.front());
145 // call the python Shutdown callbacks
146 EventData
data(_number
, 0, EventAction::Shutdown
, 0);
147 openbox
->bindings()->fireEvent(&data
);
149 XDestroyWindow(**otk::display
, _focuswindow
);
150 XDestroyWindow(**otk::display
, _supportwindow
);
154 void Screen::manageExisting()
156 unsigned int i
, j
, nchild
;
157 Window r
, p
, *children
;
158 XQueryTree(**otk::display
, _info
->rootWindow(), &r
, &p
,
161 // preen the window list of all icon windows... for better dockapp support
162 for (i
= 0; i
< nchild
; i
++) {
163 if (children
[i
] == None
) continue;
165 XWMHints
*wmhints
= XGetWMHints(**otk::display
,
169 if ((wmhints
->flags
& IconWindowHint
) &&
170 (wmhints
->icon_window
!= children
[i
])) {
171 for (j
= 0; j
< nchild
; j
++) {
172 if (children
[j
] == wmhints
->icon_window
) {
183 // manage shown windows
184 for (i
= 0; i
< nchild
; ++i
) {
185 if (children
[i
] == None
)
188 XWindowAttributes attrib
;
189 if (XGetWindowAttributes(**otk::display
, children
[i
], &attrib
)) {
190 if (attrib
.override_redirect
) continue;
192 if (attrib
.map_state
!= IsUnmapped
) {
193 manageWindow(children
[i
]);
202 void Screen::updateStruts()
205 void operator()(otk::Strut
&self
, const otk::Strut
&other
) {
206 self
.left
= std::max(self
.left
, other
.left
);
207 self
.right
= std::max(self
.right
, other
.right
);
208 self
.top
= std::max(self
.top
, other
.top
);
209 self
.bottom
= std::max(self
.bottom
, other
.bottom
);
213 StrutList::iterator sit
, send
= _struts
.end();
215 for (sit
= _struts
.begin(); sit
!= send
; ++sit
)
216 sit
->left
= sit
->right
= sit
->top
= sit
->bottom
= 0;
218 ClientList::const_iterator it
, end
= clients
.end();
219 for (it
= clients
.begin(); it
!= end
; ++it
) {
220 long desk
= (*it
)->desktop();
221 const otk::Strut
&s
= (*it
)->strut();
223 if (desk
== (signed) 0xffffffff)
224 for (unsigned int i
= 0, e
= _struts
.size(); i
< e
; ++i
)
225 apply(_struts
[i
], s
);
226 else if ((unsigned)desk
< _struts
.size())
227 apply(_struts
[desk
], s
);
228 else if (desk
== Client::ICONIC_DESKTOP
)
229 continue; // skip for the 'all desktops' strut
231 assert(false); // invalid desktop otherwise..
232 // apply to the 'all desktops' strut
233 apply(_struts
.back(), s
);
239 void Screen::changeWorkArea()
241 unsigned long *dims
= new unsigned long[4 * _num_desktops
];
242 for (long i
= 0; i
< _num_desktops
+ 1; ++i
) {
243 otk::Rect old_area
= _area
[i
];
246 // reset to the full areas
247 if (isXineramaActive())
248 xineramaUsableArea = getXineramaAreas();
252 _area
[i
] = otk::Rect(_struts
[i
].left
, _struts
[i
].top
,
253 _info
->size().width() - (_struts
[i
].left
+
255 _info
->size().height() - (_struts
[i
].top
+
260 if (isXineramaActive()) {
261 // keep each of the ximerama-defined areas inside the strut
262 RectList::iterator xit, xend = xineramaUsableArea.end();
263 for (xit = xineramaUsableArea.begin(); xit != xend; ++xit) {
264 if (xit->x() < usableArea.x()) {
265 xit->setX(usableArea.x());
266 xit->setWidth(xit->width() - usableArea.x());
268 if (xit->y() < usableArea.y()) {
269 xit->setY(usableArea.y());
270 xit->setHeight(xit->height() - usableArea.y());
272 if (xit->x() + xit->width() > usableArea.width())
273 xit->setWidth(usableArea.width() - xit->x());
274 if (xit->y() + xit->height() > usableArea.height())
275 xit->setHeight(usableArea.height() - xit->y());
280 if (old_area
!= _area
[i
]) {
281 // the area has changed, adjust all the maximized windows
282 ClientList::iterator it
, end
= clients
.end();
283 for (it
= clients
.begin(); it
!= end
; ++it
)
284 if (i
< _num_desktops
) {
285 if ((*it
)->desktop() == i
)
288 // the 'all desktops' size
289 if ((*it
)->desktop() == (signed) 0xffffffff)
294 // don't set these for the 'all desktops' area
295 if (i
< _num_desktops
) {
296 dims
[(i
* 4) + 0] = _area
[i
].x();
297 dims
[(i
* 4) + 1] = _area
[i
].y();
298 dims
[(i
* 4) + 2] = _area
[i
].width();
299 dims
[(i
* 4) + 3] = _area
[i
].height();
302 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.net_workarea
,
303 otk::Property::atoms
.cardinal
, dims
, 4 * _num_desktops
);
308 void Screen::changeSupportedAtoms()
310 // create the netwm support window
311 _supportwindow
= XCreateSimpleWindow(**otk::display
,
313 0, 0, 1, 1, 0, 0, 0);
315 // set supporting window
316 otk::Property::set(_info
->rootWindow(),
317 otk::Property::atoms
.net_supporting_wm_check
,
318 otk::Property::atoms
.window
, _supportwindow
);
320 //set properties on the supporting window
321 otk::Property::set(_supportwindow
, otk::Property::atoms
.net_wm_name
,
322 otk::Property::utf8
, "Openbox");
323 otk::Property::set(_supportwindow
,
324 otk::Property::atoms
.net_supporting_wm_check
,
325 otk::Property::atoms
.window
, _supportwindow
);
329 otk::Property::atoms
.net_current_desktop
,
330 otk::Property::atoms
.net_number_of_desktops
,
331 otk::Property::atoms
.net_desktop_geometry
,
332 otk::Property::atoms
.net_desktop_viewport
,
333 otk::Property::atoms
.net_active_window
,
334 otk::Property::atoms
.net_workarea
,
335 otk::Property::atoms
.net_client_list
,
336 otk::Property::atoms
.net_client_list_stacking
,
337 otk::Property::atoms
.net_desktop_names
,
338 otk::Property::atoms
.net_close_window
,
339 otk::Property::atoms
.net_wm_name
,
340 otk::Property::atoms
.net_wm_visible_name
,
341 otk::Property::atoms
.net_wm_icon_name
,
342 otk::Property::atoms
.net_wm_visible_icon_name
,
344 otk::Property::atoms.net_wm_desktop,
346 otk::Property::atoms
.net_wm_strut
,
347 otk::Property::atoms
.net_wm_window_type
,
348 otk::Property::atoms
.net_wm_window_type_desktop
,
349 otk::Property::atoms
.net_wm_window_type_dock
,
350 otk::Property::atoms
.net_wm_window_type_toolbar
,
351 otk::Property::atoms
.net_wm_window_type_menu
,
352 otk::Property::atoms
.net_wm_window_type_utility
,
353 otk::Property::atoms
.net_wm_window_type_splash
,
354 otk::Property::atoms
.net_wm_window_type_dialog
,
355 otk::Property::atoms
.net_wm_window_type_normal
,
357 otk::Property::atoms.net_wm_moveresize,
358 otk::Property::atoms.net_wm_moveresize_size_topleft,
359 otk::Property::atoms.net_wm_moveresize_size_topright,
360 otk::Property::atoms.net_wm_moveresize_size_bottomleft,
361 otk::Property::atoms.net_wm_moveresize_size_bottomright,
362 otk::Property::atoms.net_wm_moveresize_move,
364 otk::Property::atoms
.net_wm_allowed_actions
,
365 otk::Property::atoms
.net_wm_action_move
,
366 otk::Property::atoms
.net_wm_action_resize
,
367 otk::Property::atoms
.net_wm_action_minimize
,
368 otk::Property::atoms
.net_wm_action_shade
,
369 /* otk::Property::atoms.net_wm_action_stick,*/
370 otk::Property::atoms
.net_wm_action_maximize_horz
,
371 otk::Property::atoms
.net_wm_action_maximize_vert
,
372 otk::Property::atoms
.net_wm_action_fullscreen
,
373 otk::Property::atoms
.net_wm_action_change_desktop
,
374 otk::Property::atoms
.net_wm_action_close
,
376 otk::Property::atoms
.net_wm_state
,
377 otk::Property::atoms
.net_wm_state_modal
,
378 otk::Property::atoms
.net_wm_state_maximized_vert
,
379 otk::Property::atoms
.net_wm_state_maximized_horz
,
380 otk::Property::atoms
.net_wm_state_shaded
,
381 otk::Property::atoms
.net_wm_state_skip_taskbar
,
382 otk::Property::atoms
.net_wm_state_skip_pager
,
383 otk::Property::atoms
.net_wm_state_hidden
,
384 otk::Property::atoms
.net_wm_state_fullscreen
,
385 otk::Property::atoms
.net_wm_state_above
,
386 otk::Property::atoms
.net_wm_state_below
,
388 const int num_supported
= sizeof(supported
)/sizeof(Atom
);
390 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.net_supported
,
391 otk::Property::atoms
.atom
, supported
, num_supported
);
395 void Screen::changeClientList()
398 unsigned int size
= clients
.size();
400 // create an array of the window ids
404 windows
= new Window
[size
];
406 ClientList::const_iterator it
= clients
.begin();
407 const ClientList::const_iterator end
= clients
.end();
408 for (; it
!= end
; ++it
, ++win_it
)
409 *win_it
= (*it
)->window();
411 windows
= (Window
*) 0;
413 otk::Property::set(_info
->rootWindow(), otk::Property::atoms
.net_client_list
,
414 otk::Property::atoms
.window
, windows
, size
);
419 changeStackingList();
423 void Screen::changeStackingList()
426 unsigned int size
= _stacking
.size();
428 assert(size
== clients
.size()); // just making sure.. :)
431 // create an array of the window ids (from bottom to top, reverse order!)
435 windows
= new Window
[size
];
437 ClientList::const_reverse_iterator it
= _stacking
.rbegin();
438 const ClientList::const_reverse_iterator end
= _stacking
.rend();
439 for (; it
!= end
; ++it
, ++win_it
)
440 *win_it
= (*it
)->window();
442 windows
= (Window
*) 0;
444 otk::Property::set(_info
->rootWindow(),
445 otk::Property::atoms
.net_client_list_stacking
,
446 otk::Property::atoms
.window
, windows
, size
);
453 void Screen::manageWindow(Window window
)
457 XSetWindowAttributes attrib_set
;
459 XWindowAttributes attrib
;
461 otk::display
->grab();
463 // check if it has already been unmapped by the time we started mapping
464 // the grab does a sync so we don't have to here
465 if (XCheckTypedWindowEvent(**otk::display
, window
, DestroyNotify
, &e
) ||
466 XCheckTypedWindowEvent(**otk::display
, window
, UnmapNotify
, &e
)) {
467 XPutBackEvent(**otk::display
, &e
);
469 otk::display
->ungrab();
470 return; // don't manage it
473 if (!XGetWindowAttributes(**otk::display
, window
, &attrib
) ||
474 attrib
.override_redirect
) {
475 otk::display
->ungrab();
476 return; // don't manage it
479 // is the window a docking app
480 if ((wmhint
= XGetWMHints(**otk::display
, window
))) {
481 if ((wmhint
->flags
& StateHint
) &&
482 wmhint
->initial_state
== WithdrawnState
) {
483 //slit->addClient(w); // XXX: make dock apps work!
485 otk::display
->ungrab();
492 // choose the events we want to receive on the CLIENT window
493 attrib_set
.event_mask
= Client::event_mask
;
494 attrib_set
.do_not_propagate_mask
= Client::no_propagate_mask
;
495 XChangeWindowAttributes(**otk::display
, window
,
496 CWEventMask
|CWDontPropagate
, &attrib_set
);
498 // create the Client class, which gets all of the hints on the window
499 client
= new Client(_number
, window
);
500 // register for events
501 openbox
->registerHandler(window
, client
);
502 // add to the wm's map
503 openbox
->addClient(window
, client
);
505 // we dont want a border on the client
506 client
->toggleClientBorder(false);
508 // specify that if we exit, the window should not be destroyed and should be
509 // reparented back to root automatically
510 XChangeSaveSet(**otk::display
, window
, SetModeInsert
);
512 // create the decoration frame for the client window
513 client
->frame
= new Frame(client
);
514 // register the plate for events (map req's)
515 // this involves removing itself from the handler list first, since it is
516 // auto added to the list, being a widget. we won't get any events on the
517 // plate except for events for the client (SubstructureRedirectMask)
518 openbox
->clearHandler(client
->frame
->plate());
519 openbox
->registerHandler(client
->frame
->plate(), client
);
521 // add to the wm's map
522 Window
*w
= client
->frame
->allWindows();
523 for (unsigned int i
= 0; w
[i
]; ++i
)
524 openbox
->addClient(w
[i
], client
);
527 // reparent the client to the frame
528 client
->frame
->grabClient();
530 if (openbox
->state() != Openbox::State_Starting
) {
531 // position the window intelligenty .. hopefully :)
532 // call the python PLACEWINDOW binding
533 EventData
data(_number
, client
, EventAction::PlaceWindow
, 0);
534 openbox
->bindings()->fireEvent(&data
);
537 EventData
ddata(_number
, client
, EventAction::DisplayingWindow
, 0);
538 openbox
->bindings()->fireEvent(&ddata
);
540 // if on the current desktop.. (or all desktops)
541 if (client
->desktop() == _desktop
||
542 client
->desktop() == (signed)0xffffffff) {
543 client
->frame
->show();
546 client
->applyStartupState();
548 otk::display
->ungrab();
550 // add to the screen's list
551 clients
.push_back(client
);
552 // once the client is in the list, update our strut to include the new
553 // client's (it is good that this happens after window placement!)
555 // this puts into the stacking order, then raises it
556 _stacking
.push_back(client
);
558 // update the root properties
561 openbox
->bindings()->grabButtons(true, client
);
563 EventData
ndata(_number
, client
, EventAction::NewWindow
, 0);
564 openbox
->bindings()->fireEvent(&ndata
);
567 printf("Managed window 0x%lx frame 0x%lx\n",
568 window
, client
->frame
->window());
573 void Screen::unmanageWindow(Client
*client
)
575 Frame
*frame
= client
->frame
;
577 // call the python CLOSEWINDOW binding
578 EventData
data(_number
, client
, EventAction::CloseWindow
, 0);
579 openbox
->bindings()->fireEvent(&data
);
581 openbox
->bindings()->grabButtons(false, client
);
583 // remove from the wm's map
584 openbox
->removeClient(client
->window());
585 Window
*w
= frame
->allWindows();
586 for (unsigned int i
= 0; w
[i
]; ++i
)
587 openbox
->addClient(w
[i
], client
);
589 // unregister for handling events
590 openbox
->clearHandler(client
->window());
592 // remove the window from our save set
593 XChangeSaveSet(**otk::display
, client
->window(), SetModeDelete
);
595 // we dont want events no more
596 XSelectInput(**otk::display
, client
->window(), NoEventMask
);
600 // give the client its border back
601 client
->toggleClientBorder(true);
603 // reparent the window out of the frame
604 frame
->releaseClient();
607 Window framewin
= client
->frame
->window();
609 delete client
->frame
;
612 // remove from the stacking order
613 _stacking
.remove(client
);
615 // remove from the screen's list
616 clients
.remove(client
);
618 // once the client is out of the list, update our strut to remove it's
622 // unset modal before dropping our focus
623 client
->_modal
= false;
625 // unfocus the client (calls the focus callbacks)
629 printf("Unmanaged window 0x%lx frame 0x%lx\n", client
->window(), framewin
);
634 // update the root properties
638 void Screen::lowerWindow(Client
*client
)
640 Window wins
[2]; // only ever restack 2 windows.
642 assert(!_stacking
.empty()); // this would be bad
644 ClientList::iterator it
= --_stacking
.end();
645 const ClientList::iterator end
= _stacking
.begin();
647 if (client
->modal() && client
->transientFor()) {
648 // don't let a modal window lower below its transient_for
649 it
= std::find(_stacking
.begin(), _stacking
.end(), client
->transientFor());
650 assert(it
!= _stacking
.end());
652 wins
[0] = (it
== _stacking
.begin() ? _focuswindow
:
653 ((*(--ClientList::const_iterator(it
)))->frame
->window()));
654 wins
[1] = client
->frame
->window();
655 if (wins
[0] == wins
[1]) return; // already right above the window
657 _stacking
.remove(client
);
658 _stacking
.insert(it
, client
);
660 for (; it
!= end
&& (*it
)->layer() < client
->layer(); --it
);
661 if (*it
== client
) return; // already the bottom, return
663 wins
[0] = (*it
)->frame
->window();
664 wins
[1] = client
->frame
->window();
666 _stacking
.remove(client
);
667 _stacking
.insert(++it
, client
);
670 XRestackWindows(**otk::display
, wins
, 2);
671 changeStackingList();
674 void Screen::raiseWindow(Client
*client
)
676 Window wins
[2]; // only ever restack 2 windows.
678 assert(!_stacking
.empty()); // this would be bad
680 Client
*m
= client
->findModalChild();
681 // if we have a modal child, raise it instead, we'll go along tho later
682 if (m
) raiseWindow(m
);
684 // remove the client before looking so we can't run into ourselves
685 _stacking
.remove(client
);
687 ClientList::iterator it
= _stacking
.begin();
688 const ClientList::iterator end
= _stacking
.end();
690 // the stacking list is from highest to lowest
691 // for (;it != end, ++it) {
692 // if ((*it)->layer() <= client->layer() && m != *it) break;
694 for (; it
!= end
&& ((*it
)->layer() > client
->layer() || m
== *it
); ++it
);
697 if our new position is the top, we want to stack under the _focuswindow
698 otherwise, we want to stack under the previous window in the stack.
700 wins
[0] = (it
== _stacking
.begin() ? _focuswindow
:
701 ((*(--ClientList::const_iterator(it
)))->frame
->window()));
702 wins
[1] = client
->frame
->window();
704 _stacking
.insert(it
, client
);
706 XRestackWindows(**otk::display
, wins
, 2);
708 changeStackingList();
711 void Screen::changeDesktop(long desktop
)
713 if (!(desktop
>= 0 && desktop
< _num_desktops
)) return;
715 printf("Moving to desktop %ld\n", desktop
);
720 otk::Property::set(_info
->rootWindow(),
721 otk::Property::atoms
.net_current_desktop
,
722 otk::Property::atoms
.cardinal
, _desktop
);
724 if (old
== _desktop
) return;
726 ClientList::iterator it
, end
= clients
.end();
727 for (it
= clients
.begin(); it
!= end
; ++it
) {
728 if ((*it
)->desktop() == old
) {
729 (*it
)->frame
->hide();
730 } else if ((*it
)->desktop() == _desktop
) {
731 (*it
)->frame
->show();
735 // force the callbacks to fire
736 if (!openbox
->focusedClient())
737 openbox
->setFocusedClient(0);
740 void Screen::changeNumDesktops(long num
)
744 if (!(num
> 0)) return;
746 // move windows on desktops that will no longer exist!
747 ClientList::iterator it
, end
= clients
.end();
748 for (it
= clients
.begin(); it
!= end
; ++it
) {
749 int d
= (*it
)->desktop();
750 if (d
>= num
&& !(d
== (signed) 0xffffffff ||
751 d
== Client::ICONIC_DESKTOP
)) {
753 ce
.xclient
.type
= ClientMessage
;
754 ce
.xclient
.message_type
= otk::Property::atoms
.net_wm_desktop
;
755 ce
.xclient
.display
= **otk::display
;
756 ce
.xclient
.window
= (*it
)->window();
757 ce
.xclient
.format
= 32;
758 ce
.xclient
.data
.l
[0] = num
- 1;
759 XSendEvent(**otk::display
, _info
->rootWindow(), False
,
760 SubstructureNotifyMask
| SubstructureRedirectMask
, &ce
);
765 otk::Property::set(_info
->rootWindow(),
766 otk::Property::atoms
.net_number_of_desktops
,
767 otk::Property::atoms
.cardinal
, _num_desktops
);
769 // set the viewport hint
770 unsigned long *viewport
= new unsigned long[_num_desktops
* 2];
771 memset(viewport
, 0, sizeof(unsigned long) * _num_desktops
* 2);
772 otk::Property::set(_info
->rootWindow(),
773 otk::Property::atoms
.net_desktop_viewport
,
774 otk::Property::atoms
.cardinal
,
775 viewport
, _num_desktops
* 2);
778 // change our struts/area to match
779 _area
.resize(_num_desktops
+ 1);
780 _struts
.resize(_num_desktops
+ 1);
783 // change our desktop if we're on one that no longer exists!
784 if (_desktop
>= _num_desktops
)
785 changeDesktop(_num_desktops
- 1);
789 void Screen::updateDesktopNames()
791 unsigned long num
= (unsigned) -1;
793 if (!otk::Property::get(_info
->rootWindow(),
794 otk::Property::atoms
.net_desktop_names
,
795 otk::Property::utf8
, &num
, &_desktop_names
))
796 _desktop_names
.clear();
797 while ((long)_desktop_names
.size() < _num_desktops
)
798 _desktop_names
.push_back("Unnamed");
802 void Screen::setDesktopName(long i
, const otk::ustring
&name
)
806 if (i
>= _num_desktops
) return;
808 otk::Property::StringVect newnames
= _desktop_names
;
810 otk::Property::set(_info
->rootWindow(),
811 otk::Property::atoms
.net_desktop_names
,
812 otk::Property::utf8
, newnames
);
816 const otk::Rect
& Screen::area(long desktop
) const {
817 assert(desktop
>= 0 || desktop
== (signed) 0xffffffff);
818 assert(desktop
< _num_desktops
|| desktop
== (signed) 0xffffffff);
819 if (desktop
>= 0 && desktop
< _num_desktops
)
820 return _area
[desktop
];
822 return _area
[_num_desktops
];
825 void Screen::installColormap(bool install
) const
828 XInstallColormap(**otk::display
, _info
->colormap());
830 XUninstallColormap(**otk::display
, _info
->colormap());
834 void Screen::propertyHandler(const XPropertyEvent
&e
)
836 otk::EventHandler::propertyHandler(e
);
838 // compress changes to a single property into a single change
840 while (XCheckTypedWindowEvent(**otk::display
, _info
->rootWindow(),
842 // XXX: it would be nice to compress ALL changes to a property, not just
843 // changes in a row without other props between.
844 if (ce
.xproperty
.atom
!= e
.atom
) {
845 XPutBackEvent(**otk::display
, &ce
);
850 if (e
.atom
== otk::Property::atoms
.net_desktop_names
)
851 updateDesktopNames();
855 void Screen::clientMessageHandler(const XClientMessageEvent
&e
)
857 otk::EventHandler::clientMessageHandler(e
);
859 if (e
.format
!= 32) return;
861 if (e
.message_type
== otk::Property::atoms
.net_current_desktop
) {
862 changeDesktop(e
.data
.l
[0]);
863 } else if (e
.message_type
== otk::Property::atoms
.net_number_of_desktops
) {
864 changeNumDesktops(e
.data
.l
[0]);
869 void Screen::mapRequestHandler(const XMapRequestEvent
&e
)
871 otk::EventHandler::mapRequestHandler(e
);
874 printf("MapRequest for 0x%lx\n", e
.window
);
877 Client
*c
= openbox
->findClient(e
.window
);
880 printf("DEBUG: MAP REQUEST CAUGHT IN SCREEN. IGNORED.\n");
883 manageWindow(e
.window
);