+ Window *windows;
+ unsigned int size = _stacking.size();
+
+ assert(size == clients.size()); // just making sure.. :)
+
+
+ // create an array of the window ids (from bottom to top, reverse order!)
+ if (size > 0) {
+ Window *win_it;
+
+ windows = new Window[size];
+ win_it = windows;
+ Client::List::const_reverse_iterator it = _stacking.rbegin();
+ const Client::List::const_reverse_iterator end = _stacking.rend();
+ for (; it != end; ++it, ++win_it)
+ *win_it = (*it)->window();
+ } else
+ windows = (Window*) 0;
+
+ otk::Property::set(_info->rootWindow(),
+ otk::Property::atoms.net_client_list_stacking,
+ otk::Property::atoms.window, windows, size);
+
+ if (size)
+ delete [] windows;
+}
+
+
+void Screen::changeWorkArea() {
+ unsigned long *dims = new unsigned long[4 * _num_desktops];
+ for (long i = 0; i < _num_desktops; ++i) {
+ // XXX: this could be different for each workspace
+ dims[(i * 4) + 0] = _area.x();
+ dims[(i * 4) + 1] = _area.y();
+ dims[(i * 4) + 2] = _area.width();
+ dims[(i * 4) + 3] = _area.height();
+ }
+ otk::Property::set(_info->rootWindow(), otk::Property::atoms.net_workarea,
+ otk::Property::atoms.cardinal, dims, 4 * _num_desktops);
+ delete [] dims;
+}
+
+
+void Screen::manageWindow(Window window)
+{
+ Client *client = 0;
+ XWMHints *wmhint;
+ XSetWindowAttributes attrib_set;
+
+ otk::display->grab();
+
+ // is the window a docking app
+ if ((wmhint = XGetWMHints(**otk::display, window))) {
+ if ((wmhint->flags & StateHint) &&
+ wmhint->initial_state == WithdrawnState) {
+ //slit->addClient(w); // XXX: make dock apps work!
+ otk::display->ungrab();
+
+ XFree(wmhint);
+ return;
+ }
+ 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, 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, window, SetModeInsert);
+
+ // 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 (!(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);
+ }
+
+ // if on the current desktop.. (or all desktops)
+ if (client->desktop() == _desktop ||
+ client->desktop() == (signed)0xffffffff) {
+ client->frame->show();
+ }
+
+ client->applyStartupState();
+
+ 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);
+ raiseWindow(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, client->window(), SetModeDelete);
+
+ // we dont want events no more
+ XSelectInput(**otk::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::lowerWindow(Client *client)
+{
+ Window wins[2]; // only ever restack 2 windows.
+
+ assert(!_stacking.empty()); // this would be bad
+
+ Client::List::iterator it = --_stacking.end();
+ Client::List::const_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();
+ Client::List::const_iterator end = _stacking.end();
+
+ // the stacking list is from highest to lowest
+ for (; it != end && (*it)->layer() > client->layer(); ++it);
+