+ for (; it != end && (*it)->layer() > client->layer(); ++it);
+
+ /*
+ if our new position is the top, we want to stack under the _focuswindow
+ otherwise, we want to stack under the previous window in the stack.
+ */
+ wins[0] = (it == _stacking.begin() ? _focuswindow :
+ ((*(--ClientList::const_iterator(it)))->frame->window()));
+ wins[1] = client->frame->window();
+
+ _stacking.insert(it, client);
+
+ XRestackWindows(**otk::display, wins, 2);
+
+ // if the window has a modal child, then raise it after us to put it on top
+ if (client->modalChild())
+ raiseWindow(client->modalChild());
+ else
+ changeStackingList(); // no need to do this twice!
+}
+
+void Screen::changeDesktop(long desktop)
+{
+ if (!(desktop >= 0 && desktop < _num_desktops)) return;
+
+ printf("Moving to desktop %ld\n", desktop);
+
+ long old = _desktop;
+
+ _desktop = desktop;
+ otk::Property::set(_info->rootWindow(),
+ otk::Property::atoms.net_current_desktop,
+ otk::Property::atoms.cardinal, _desktop);
+
+ if (old == _desktop) return;
+
+ ClientList::iterator it, end = clients.end();
+ for (it = clients.begin(); it != end; ++it) {
+ if ((*it)->desktop() == old) {
+ (*it)->frame->hide();
+ } else if ((*it)->desktop() == _desktop) {
+ (*it)->frame->show();
+ }
+ }
+
+ // force the callbacks to fire
+ if (!openbox->focusedClient())
+ openbox->setFocusedClient(0);
+}
+
+void Screen::changeNumDesktops(long num)
+{
+ assert(num > 0);
+
+ if (!(num > 0)) return;
+
+ // move windows on desktops that will no longer exist!
+ ClientList::iterator it, end = clients.end();
+ for (it = clients.begin(); it != end; ++it) {
+ int d = (*it)->desktop();
+ if (d >= num && !(d == (signed) 0xffffffff ||
+ d == Client::ICONIC_DESKTOP)) {
+ XEvent ce;
+ ce.xclient.type = ClientMessage;
+ ce.xclient.message_type = otk::Property::atoms.net_wm_desktop;
+ ce.xclient.display = **otk::display;
+ ce.xclient.window = (*it)->window();
+ ce.xclient.format = 32;
+ ce.xclient.data.l[0] = num - 1;
+ XSendEvent(**otk::display, _info->rootWindow(), False,
+ SubstructureNotifyMask | SubstructureRedirectMask, &ce);
+ }
+ }
+
+ _num_desktops = num;
+ otk::Property::set(_info->rootWindow(),
+ otk::Property::atoms.net_number_of_desktops,
+ otk::Property::atoms.cardinal, _num_desktops);
+
+ // set the viewport hint
+ unsigned long *viewport = new unsigned long[_num_desktops * 2];
+ memset(viewport, 0, sizeof(unsigned long) * _num_desktops * 2);
+ otk::Property::set(_info->rootWindow(),
+ otk::Property::atoms.net_desktop_viewport,
+ otk::Property::atoms.cardinal,
+ viewport, _num_desktops * 2);
+ delete [] viewport;
+
+ // update the work area hint
+ changeWorkArea();
+
+ // change our desktop if we're on one that no longer exists!
+ if (_desktop >= num)
+ changeDesktop(num - 1);
+}
+
+
+void Screen::updateDesktopNames()
+{
+ unsigned long num = (unsigned) -1;