+ changeClientList();
+}
+
+void Screen::lowerWindow(Client *client)
+{
+ Window wins[2]; // only ever restack 2 windows.
+
+ assert(!_stacking.empty()); // this would be bad
+
+ Client::List::iterator it = --_stacking.end();
+ const Client::List::iterator end = _stacking.begin();
+
+ for (; it != end && (*it)->layer() < client->layer(); --it);
+ if (*it == client) return; // already the bottom, return
+
+ wins[0] = (*it)->frame->window();
+ wins[1] = client->frame->window();
+
+ _stacking.remove(client);
+ _stacking.insert(++it, client);
+
+ XRestackWindows(**otk::display, wins, 2);
+ changeStackingList();
+}
+
+void Screen::raiseWindow(Client *client)
+{
+ Window wins[2]; // only ever restack 2 windows.
+
+ assert(!_stacking.empty()); // this would be bad
+
+ // remove the client before looking so we can't run into ourselves
+ _stacking.remove(client);
+
+ Client::List::iterator it = _stacking.begin();
+ const Client::List::iterator end = _stacking.end();
+
+ // the stacking list is from highest to lowest
+ 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 :
+ ((*(--Client::List::const_iterator(it)))->frame->window()));
+ wins[1] = client->frame->window();
+
+ _stacking.insert(it, client);
+
+ XRestackWindows(**otk::display, wins, 2);
+ changeStackingList();
+}
+
+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;
+
+ Client::List::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;
+
+ // XXX: move windows on desktops that will no longer exist!
+
+ _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();
+}
+
+
+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 ((long)_desktop_names.size() < _num_desktops)
+ _desktop_names.push_back("Unnamed");
+}
+
+
+void Screen::setDesktopName(long i, const otk::ustring &name)
+{
+ assert(i >= 0);
+
+ 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);
+}
+
+
+void Screen::propertyHandler(const XPropertyEvent &e)
+{
+ otk::EventHandler::propertyHandler(e);
+
+ // compress changes to a single property into a single change
+ XEvent ce;
+ while (XCheckTypedEvent(**otk::display, e.type, &ce)) {
+ // XXX: it would be nice to compress ALL changes to a property, not just
+ // changes in a row without other props between.
+ if (ce.xproperty.atom != e.atom) {
+ XPutBackEvent(**otk::display, &ce);
+ break;
+ }
+ }
+
+ if (e.atom == otk::Property::atoms.net_desktop_names)
+ updateDesktopNames();
+}
+
+
+void Screen::clientMessageHandler(const XClientMessageEvent &e)
+{
+ otk::EventHandler::clientMessageHandler(e);
+
+ if (e.format != 32) return;
+
+ if (e.message_type == otk::Property::atoms.net_current_desktop) {
+ changeDesktop(e.data.l[0]);
+ } else if (e.message_type == otk::Property::atoms.net_number_of_desktops) {
+ changeNumDesktops(e.data.l[0]);
+ }
+ // XXX: so many client messages to handle here! ..or not.. they go to clients
+}
+
+
+void Screen::mapRequestHandler(const XMapRequestEvent &e)
+{
+ otk::EventHandler::mapRequestHandler(e);
+
+#ifdef DEBUG
+ printf("MapRequest for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ Client *c = openbox->findClient(e.window);
+ if (c) {
+#ifdef DEBUG
+ printf("DEBUG: MAP REQUEST CAUGHT IN SCREEN. IGNORED.\n");
+#endif
+ } else
+ manageWindow(e.window);