+ XFree(wmhint);
+ }
+
+ // choose the events we want to receive on the CLIENT window
+ attrib_set.event_mask = Client::event_mask;
+ attrib_set.do_not_propagate_mask = Client::no_propagate_mask;
+ XChangeWindowAttributes(otk::Display::display, window,
+ CWEventMask|CWDontPropagate, &attrib_set);
+
+ // create the Client class, which gets all of the hints on the window
+ client = new Client(_number, window);
+ // register for events
+ openbox->registerHandler(window, client);
+ // add to the wm's map
+ openbox->addClient(window, client);
+
+ // we dont want a border on the client
+ client->toggleClientBorder(false);
+
+ // specify that if we exit, the window should not be destroyed and should be
+ // reparented back to root automatically
+ XChangeSaveSet(otk::Display::display, window, SetModeInsert);
+
+ if (!(openbox->state() == Openbox::State_Starting ||
+ client->positionRequested())) {
+ // position the window intelligenty .. hopefully :)
+ // call the python PLACEWINDOW binding
+ EventData data(_number, client, EventPlaceWindow, 0);
+ openbox->bindings()->fireEvent(&data);
+ }
+
+ // create the decoration frame for the client window
+ client->frame = new Frame(client, &_style);
+
+ // add to the wm's map
+ openbox->addClient(client->frame->window(), client);
+ openbox->addClient(client->frame->plate(), client);
+ openbox->addClient(client->frame->titlebar(), client);
+ openbox->addClient(client->frame->label(), client);
+ openbox->addClient(client->frame->button_max(), client);
+ openbox->addClient(client->frame->button_iconify(), client);
+ openbox->addClient(client->frame->button_stick(), client);
+ openbox->addClient(client->frame->button_close(), client);
+ openbox->addClient(client->frame->handle(), client);
+ openbox->addClient(client->frame->grip_left(), client);
+ openbox->addClient(client->frame->grip_right(), client);
+
+ // reparent the client to the frame
+ client->frame->grabClient();
+
+ // if on the current desktop.. (or all desktops)
+ if (client->desktop() == _desktop ||
+ client->desktop() == (signed)0xffffffff) {
+ client->frame->show();
+ }
+
+ // XXX: handle any requested states such as maximized
+
+ otk::Display::ungrab();
+
+ // add to the screen's list
+ clients.push_back(client);
+ // this puts into the stacking order, then raises it
+ _stacking.push_back(client);
+ restack(true, client);
+ // update the root properties
+ changeClientList();
+
+ openbox->bindings()->grabButtons(true, client);
+
+ // call the python NEWWINDOW binding
+ EventData data(_number, client, EventNewWindow, 0);
+ openbox->bindings()->fireEvent(&data);
+
+#ifdef DEBUG
+ printf("Managed window 0x%lx\n", window);
+#endif
+}
+
+
+void Screen::unmanageWindow(Client *client)
+{
+ Frame *frame = client->frame;
+
+ // call the python CLOSEWINDOW binding
+ EventData data(_number, client, EventCloseWindow, 0);
+ openbox->bindings()->fireEvent(&data);
+
+ openbox->bindings()->grabButtons(false, client);
+
+ // remove from the wm's map
+ openbox->removeClient(client->window());
+ openbox->removeClient(frame->window());
+ openbox->removeClient(frame->plate());
+ openbox->removeClient(frame->titlebar());
+ openbox->removeClient(frame->label());
+ openbox->removeClient(frame->button_max());
+ openbox->removeClient(frame->button_iconify());
+ openbox->removeClient(frame->button_stick());
+ openbox->removeClient(frame->button_close());
+ openbox->removeClient(frame->handle());
+ openbox->removeClient(frame->grip_left());
+ openbox->removeClient(frame->grip_right());
+ // unregister for handling events
+ openbox->clearHandler(client->window());
+
+ // remove the window from our save set
+ XChangeSaveSet(otk::Display::display, client->window(), SetModeDelete);
+
+ // we dont want events no more
+ XSelectInput(otk::Display::display, client->window(), NoEventMask);
+
+ frame->hide();
+
+ // give the client its border back
+ client->toggleClientBorder(true);
+
+ // reparent the window out of the frame
+ frame->releaseClient();
+
+ delete client->frame;
+ client->frame = 0;
+
+ // remove from the stacking order
+ _stacking.remove(client);
+
+ // remove from the screen's list
+ clients.remove(client);
+
+ // unfocus the client (calls the focus callbacks)
+ client->unfocus();
+
+#ifdef DEBUG
+ printf("Unmanaged window 0x%lx\n", client->window());
+#endif
+
+ delete client;
+
+ // update the root properties
+ changeClientList();
+}
+
+void Screen::restack(bool raise, Client *client)
+{
+ const int layer = client->layer();
+ std::vector<Window> wins;
+
+ _stacking.remove(client);
+
+ // the stacking list is from highest to lowest
+
+ Client::List::iterator it = _stacking.begin(), end = _stacking.end();
+ // insert the windows above this window
+ for (; it != end; ++it) {
+ if ((*it)->layer() < layer || (raise && (*it)->layer() == layer))
+ break;
+ wins.push_back((*it)->frame->window());
+ }
+ // insert our client
+ wins.push_back(client->frame->window());
+ _stacking.insert(it, client);
+ // insert the remaining below this window
+ for (; it != end; ++it)
+ wins.push_back((*it)->frame->window());
+
+ XRestackWindows(otk::Display::display, &wins[0], wins.size());
+ 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;
+ openbox->property()->set(_info->rootWindow(),
+ otk::Property::net_current_desktop,
+ otk::Property::Atom_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;
+ openbox->property()->set(_info->rootWindow(),
+ otk::Property::net_number_of_desktops,
+ otk::Property::Atom_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);
+ openbox->property()->set(_info->rootWindow(),
+ otk::Property::net_desktop_viewport,
+ otk::Property::Atom_Cardinal,
+ viewport, _num_desktops * 2);
+ delete [] viewport;
+
+ // update the work area hint
+ changeWorkArea();
+}
+
+
+void Screen::updateDesktopNames()
+{
+ const otk::Property *property = openbox->property();
+
+ unsigned long num = (unsigned) -1;
+
+ if (!property->get(_info->rootWindow(),
+ otk::Property::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;
+
+ const otk::Property *property = openbox->property();
+
+ otk::Property::StringVect newnames = _desktop_names;
+ newnames[i] = name;
+ property->set(_info->rootWindow(), otk::Property::net_desktop_names,
+ otk::Property::utf8, newnames);
+}
+
+
+void Screen::propertyHandler(const XPropertyEvent &e)
+{
+ otk::EventHandler::propertyHandler(e);
+
+ const otk::Property *property = openbox->property();
+
+ // compress changes to a single property into a single change
+ XEvent ce;
+ while (XCheckTypedEvent(otk::Display::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::display, &ce);
+ break;
+ }
+ }
+
+ if (e.atom == property->atom(otk::Property::net_desktop_names))
+ updateDesktopNames();