+ for (; it != end && ((*it)->layer() > client->layer() || m == *it); ++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);
+
+ changeStackingList();
+}
+
+void Screen::changeDesktop(unsigned int desktop)
+{
+ if (desktop >= _num_desktops) return;
+
+ printf("Moving to desktop %u\n", desktop);
+
+ unsigned int 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)
+ (*it)->showhide();
+
+ // force the callbacks to fire
+ if (!openbox->focusedClient())
+ openbox->setFocusedClient(0);
+}
+
+void Screen::changeNumDesktops(unsigned int 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) {
+ unsigned int d = (*it)->desktop();
+ if (d >= num && d != 0xffffffff) {
+ 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;
+
+ // change our struts/area to match
+ _area.resize(_num_desktops + 1);
+ _struts.resize(_num_desktops + 1);
+ updateStruts();
+
+ // the number of rows/columns will differ
+ updateDesktopLayout();
+
+ // change our desktop if we're on one that no longer exists!
+ if (_desktop >= _num_desktops)
+ changeDesktop(_num_desktops - 1);
+}
+
+
+void Screen::updateDesktopNames()
+{
+ unsigned long num = (unsigned) -1;
+
+ if (!otk::Property::get(_info->rootWindow(),
+ otk::Property::atoms.net_desktop_names,
+ otk::Property::utf8, &num, &_desktop_names))
+ _desktop_names.clear();
+ while (_desktop_names.size() < _num_desktops)
+ _desktop_names.push_back("Unnamed");
+}
+
+
+void Screen::setDesktopName(unsigned int i, const otk::ustring &name)
+{
+ if (i >= _num_desktops) return;
+
+ otk::Property::StringVect newnames = _desktop_names;
+ newnames[i] = name;
+ otk::Property::set(_info->rootWindow(),
+ otk::Property::atoms.net_desktop_names,
+ otk::Property::utf8, newnames);
+}
+
+otk::ustring Screen::desktopName(unsigned int i) const
+{
+ if (i >= _num_desktops) return "";
+ return _desktop_names[i];
+}
+
+const otk::Rect& Screen::area(unsigned int desktop) const {
+ assert(desktop < _num_desktops || desktop == 0xffffffff);
+ if (desktop < _num_desktops)
+ return _area[desktop];
+ else
+ return _area[_num_desktops];
+}
+
+void Screen::installColormap(bool install) const
+{
+ if (install)
+ XInstallColormap(**otk::display, _info->colormap());
+ else
+ XUninstallColormap(**otk::display, _info->colormap());
+}
+
+void Screen::showDesktop(bool show)
+{
+ if (show == _showing_desktop) return; // no change
+
+ // save the window focus, and restore it when leaving the show-desktop mode
+ static Window saved_focus = 0;
+ if (show) {
+ Client *c = openbox->focusedClient();
+ if (c) saved_focus = c->window();
+ }