+ // remove from the stacking order
+ _stacking.remove(client);
+
+ // remove from the screen's list
+ clients.remove(client);
+
+ // once the client is out of the list, update our strut to remove it's
+ // influence
+ updateStruts();
+
+ // unset modal before dropping our focus
+ client->_modal = false;
+
+ // unfocus the client (calls the focus callbacks)
+ if (client->focused()) client->unfocus();
+
+#ifdef DEBUG
+ printf("Unmanaged window 0x%lx frame 0x%lx\n", client->window(), framewin);
+#endif
+
+ delete client;
+
+ // update the root properties
+ changeClientList();
+}
+
+void Screen::lowerWindow(Client *client)
+{
+ Window wins[2]; // only ever restack 2 windows.
+
+ assert(!_stacking.empty()); // this would be bad
+
+ std::list<Client*>::iterator it = --_stacking.end();
+ const std::list<Client*>::iterator end = _stacking.begin();
+
+ if (client->modal() && client->transientFor()) {
+ // don't let a modal window lower below its transient_for
+ it = std::find(_stacking.begin(), _stacking.end(), client->transientFor());
+ assert(it != _stacking.end());
+
+ wins[0] = (it == _stacking.begin() ? _focuswindow :
+ ((*(--std::list<Client*>::const_iterator(it)))->
+ frame->window()));
+ wins[1] = client->frame->window();
+ if (wins[0] == wins[1]) return; // already right above the window
+
+ _stacking.remove(client);
+ _stacking.insert(it, client);
+ } else {
+ 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
+
+ Client *m = client->findModalChild();
+ // if we have a modal child, raise it instead, we'll go along tho later
+ if (m) raiseWindow(m);
+
+ // remove the client before looking so we can't run into ourselves
+ _stacking.remove(client);
+
+ std::list<Client*>::iterator it = _stacking.begin();
+ const std::list<Client*>::iterator end = _stacking.end();
+
+ // the stacking list is from highest to lowest
+ 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 :
+ ((*(--std::list<Client*>::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;
+
+ std::list<Client*>::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!
+ std::list<Client*>::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();
+
+ // may be some unnamed desktops that we need to fill in with names
+ updateDesktopNames();
+
+ // 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;
+
+ 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");
+}
+
+
+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();
+ }
+
+ _showing_desktop = show;
+
+ std::list<Client*>::iterator it, end = clients.end();
+ for (it = clients.begin(); it != end; ++it) {
+ if ((*it)->type() == Client::Type_Desktop) {
+ if (show)
+ (*it)->focus();
+ } else
+ (*it)->showhide();
+ }
+
+ if (!show) {
+ Client *f = openbox->focusedClient();
+ if (!f || f->type() == Client::Type_Desktop) {
+ Client *c = openbox->findClient(saved_focus);
+ if (c) c->focus();
+ }
+ }
+
+ otk::Property::set(_info->rootWindow(),
+ otk::Property::atoms.net_showing_desktop,
+ otk::Property::atoms.cardinal,
+ show ? 1 : 0);
+}
+
+void Screen::propertyHandler(const XPropertyEvent &e)
+{
+ otk::EventHandler::propertyHandler(e);
+
+ // compress changes to a single property into a single change
+ XEvent ce;
+ while (XCheckTypedWindowEvent(**otk::display, _info->rootWindow(),
+ 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);