+ if (!(_can_focus || _focus_notify) || _focused) return false;
+
+ if (_can_focus)
+ XSetInputFocus(otk::OBDisplay::display, _window, RevertToNone, CurrentTime);
+
+ if (_focus_notify) {
+ XEvent ce;
+ const otk::OBProperty *property = Openbox::instance->property();
+
+ ce.xclient.type = ClientMessage;
+ ce.xclient.message_type = property->atom(otk::OBProperty::wm_protocols);
+ ce.xclient.display = otk::OBDisplay::display;
+ ce.xclient.window = _window;
+ ce.xclient.format = 32;
+ ce.xclient.data.l[0] = property->atom(otk::OBProperty::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::OBDisplay::display, _window, False, NoEventMask, &ce);
+ }
+
+ return true;
+}
+
+
+void OBClient::unfocus()
+{
+ if (!_focused) return;
+
+ assert(Openbox::instance->focusedClient() == this);
+ Openbox::instance->setFocusedClient(0);
+}
+
+
+void OBClient::focusHandler(const XFocusChangeEvent &e)
+{
+#ifdef DEBUG
+ printf("FocusIn for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ OtkEventHandler::focusHandler(e);
+
+ frame->focus();
+ _focused = true;
+
+ Openbox::instance->setFocusedClient(this);
+}
+
+
+void OBClient::unfocusHandler(const XFocusChangeEvent &e)
+{
+#ifdef DEBUG
+ printf("FocusOut for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ OtkEventHandler::unfocusHandler(e);
+
+ frame->unfocus();
+ _focused = false;
+
+ if (Openbox::instance->focusedClient() == this) {
+ printf("UNFOCUSED!\n");
+ Openbox::instance->setFocusedClient(this);
+ }
+}
+
+
+void OBClient::configureRequestHandler(const XConfigureRequestEvent &e)
+{
+#ifdef DEBUG
+ printf("ConfigureRequest for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ OtkEventHandler::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;
+ }
+
+ resize(corner, w, h);
+ }
+
+ 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();
+ move(x, y);
+ }
+
+ if (e.value_mask & CWStackMode) {
+ switch (e.detail) {
+ case Below:
+ case BottomIf:
+ // XXX: lower the window
+ break;
+
+ case Above:
+ case TopIf:
+ default:
+ // XXX: raise the window
+ break;
+ }
+ }
+}
+
+
+void OBClient::unmapHandler(const XUnmapEvent &e)
+{
+#ifdef DEBUG
+ printf("UnmapNotify for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ if (ignore_unmaps) {
+ ignore_unmaps--;
+ return;
+ }
+
+ OtkEventHandler::unmapHandler(e);
+
+ // this deletes us etc
+ Openbox::instance->screen(_screen)->unmanageWindow(this);
+}
+
+
+void OBClient::destroyHandler(const XDestroyWindowEvent &e)
+{
+#ifdef DEBUG
+ printf("DestroyNotify for 0x%lx\n", e.window);
+#endif // DEBUG
+
+ OtkEventHandler::destroyHandler(e);
+
+ // this deletes us etc
+ Openbox::instance->screen(_screen)->unmanageWindow(this);
+}
+
+
+void OBClient::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
+
+ OtkEventHandler::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.
+ */
+
+ // this deletes us etc
+ Openbox::instance->screen(_screen)->unmanageWindow(this);