+ const otk::Property *property = Openbox::instance->property();
+
+ unsigned long state[2];
+ state[0] = _wmstate;
+ state[1] = None;
+ property->set(_window, otk::Property::wm_state, otk::Property::wm_state,
+ state, 2);
+
+ Atom netstate[10];
+ int num = 0;
+ if (_modal)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_modal);
+ if (_shaded)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_shaded);
+ if (_iconic)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_hidden);
+ if (_skip_taskbar)
+ netstate[num++] =
+ property->atom(otk::Property::net_wm_state_skip_taskbar);
+ if (_skip_pager)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_skip_pager);
+ if (_fullscreen)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_fullscreen);
+ if (_max_vert)
+ netstate[num++] =
+ property->atom(otk::Property::net_wm_state_maximized_vert);
+ if (_max_horz)
+ netstate[num++] =
+ property->atom(otk::Property::net_wm_state_maximized_horz);
+ if (_above)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_above);
+ if (_below)
+ netstate[num++] = property->atom(otk::Property::net_wm_state_below);
+ property->set(_window, otk::Property::net_wm_state,
+ otk::Property::Atom_Atom, netstate, num);
+
+ calcLayer();
+}
+
+
+void Client::shade(bool shade)
+{
+ if (shade == _shaded) return; // already done
+
+ _wmstate = shade ? IconicState : NormalState;
+ _shaded = shade;
+ changeState();
+ frame->adjustSize();
+}
+
+
+bool Client::focus() const
+{
+ // won't try focus if the client doesn't want it, or if the window isn't
+ // visible on the screen
+ if (!(frame->isVisible() && (_can_focus || _focus_notify))) return false;
+
+ if (_focused) return true;
+
+ if (_can_focus)
+ XSetInputFocus(otk::Display::display, _window,
+ RevertToNone, CurrentTime);
+
+ if (_focus_notify) {
+ XEvent ce;
+ const otk::Property *property = Openbox::instance->property();
+
+ ce.xclient.type = ClientMessage;
+ ce.xclient.message_type = property->atom(otk::Property::wm_protocols);
+ ce.xclient.display = otk::Display::display;
+ ce.xclient.window = _window;
+ ce.xclient.format = 32;
+ ce.xclient.data.l[0] = property->atom(otk::Property::wm_take_focus);
+ ce.xclient.data.l[1] = Openbox::instance->lastTime();
+ ce.xclient.data.l[2] = 0l;
+ ce.xclient.data.l[3] = 0l;
+ ce.xclient.data.l[4] = 0l;
+ XSendEvent(otk::Display::display, _window, False, NoEventMask, &ce);
+ }
+
+ return true;
+}
+
+
+void Client::unfocus() const
+{
+ if (!_focused) return;
+
+ assert(Openbox::instance->focusedClient() == this);
+ Openbox::instance->setFocusedClient(0);
+}
+
+
+void Client::focusHandler(const XFocusChangeEvent &e)
+{
+#ifdef DEBUG
+// printf("FocusIn for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ otk::EventHandler::focusHandler(e);
+
+ frame->focus();
+ _focused = true;
+
+ Openbox::instance->setFocusedClient(this);
+}
+
+
+void Client::unfocusHandler(const XFocusChangeEvent &e)
+{
+#ifdef DEBUG
+// printf("FocusOut for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ otk::EventHandler::unfocusHandler(e);
+
+ frame->unfocus();
+ _focused = false;
+
+ if (Openbox::instance->focusedClient() == this)
+ Openbox::instance->setFocusedClient(0);
+}
+
+
+void Client::configureRequestHandler(const XConfigureRequestEvent &e)
+{
+#ifdef DEBUG
+ printf("ConfigureRequest for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ otk::EventHandler::configureRequestHandler(e);
+
+ // XXX: if we are iconic (or shaded? (fvwm does that)) ignore the event
+
+ if (e.value_mask & CWBorderWidth)
+ _border_width = e.border_width;
+
+ // resize, then move, as specified in the EWMH section 7.7
+ if (e.value_mask & (CWWidth | CWHeight)) {
+ int w = (e.value_mask & CWWidth) ? e.width : _area.width();
+ int h = (e.value_mask & CWHeight) ? e.height : _area.height();
+
+ Corner corner;
+ switch (_gravity) {
+ case NorthEastGravity:
+ case EastGravity:
+ corner = TopRight;
+ break;
+ case SouthWestGravity:
+ case SouthGravity:
+ corner = BottomLeft;
+ break;
+ case SouthEastGravity:
+ corner = BottomRight;
+ break;
+ default: // NorthWest, Static, etc
+ corner = TopLeft;
+ }
+
+ // if moving AND resizing ...
+ if (e.value_mask & (CWX | CWY)) {
+ int x = (e.value_mask & CWX) ? e.x : _area.x();
+ int y = (e.value_mask & CWY) ? e.y : _area.y();
+ resize(corner, w, h, x, y);
+ } else // if JUST resizing...
+ resize(corner, w, h);
+ } else if (e.value_mask & (CWX | CWY)) { // if JUST moving...
+ int x = (e.value_mask & CWX) ? e.x : _area.x();
+ int y = (e.value_mask & CWY) ? e.y : _area.y();
+ move(x, y);
+ }
+
+ if (e.value_mask & CWStackMode) {
+ switch (e.detail) {
+ case Below:
+ case BottomIf:
+ Openbox::instance->screen(_screen)->restack(false, this); // lower
+ break;
+
+ case Above:
+ case TopIf:
+ default:
+ Openbox::instance->screen(_screen)->restack(true, this); // raise
+ break;
+ }
+ }
+}
+
+
+void Client::unmapHandler(const XUnmapEvent &e)
+{
+ if (ignore_unmaps) {
+#ifdef DEBUG
+ printf("Ignored UnmapNotify for 0x%lx (event 0x%lx)\n", e.window, e.event);
+#endif // DEBUG
+ ignore_unmaps--;
+ return;
+ }
+
+#ifdef DEBUG
+ printf("UnmapNotify for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ otk::EventHandler::unmapHandler(e);
+
+ // this deletes us etc
+ Openbox::instance->screen(_screen)->unmanageWindow(this);
+}
+
+
+void Client::destroyHandler(const XDestroyWindowEvent &e)
+{
+#ifdef DEBUG
+ printf("DestroyNotify for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ otk::EventHandler::destroyHandler(e);
+
+ // this deletes us etc
+ Openbox::instance->screen(_screen)->unmanageWindow(this);
+}
+
+
+void Client::reparentHandler(const XReparentEvent &e)
+{
+ // this is when the client is first taken captive in the frame
+ if (e.parent == frame->plate()) return;
+
+#ifdef DEBUG
+ printf("ReparentNotify for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ otk::EventHandler::reparentHandler(e);
+
+ /*
+ This event is quite rare and is usually handled in unmapHandler.
+ However, if the window is unmapped when the reparent event occurs,
+ the window manager never sees it because an unmap event is not sent
+ to an already unmapped window.
+ */
+
+ // we don't want the reparent event, put it back on the stack for the X
+ // server to deal with after we unmanage the window
+ XEvent ev;
+ ev.xreparent = e;
+ XPutBackEvent(otk::Display::display, &ev);
+
+ // this deletes us etc
+ Openbox::instance->screen(_screen)->unmanageWindow(this);