+ XSendEvent(**otk::display, _window, false, NoEventMask, &ce);
+}
+
+
+void Client::changeState()
+{
+ unsigned long state[2];
+ state[0] = _wmstate;
+ state[1] = None;
+ otk::Property::set(_window, otk::Property::atoms.wm_state,
+ otk::Property::atoms.wm_state, state, 2);
+
+ Atom netstate[10];
+ int num = 0;
+ if (_modal)
+ netstate[num++] = otk::Property::atoms.net_wm_state_modal;
+ if (_shaded)
+ netstate[num++] = otk::Property::atoms.net_wm_state_shaded;
+ if (_iconic)
+ netstate[num++] = otk::Property::atoms.net_wm_state_hidden;
+ if (_skip_taskbar)
+ netstate[num++] = otk::Property::atoms.net_wm_state_skip_taskbar;
+ if (_skip_pager)
+ netstate[num++] = otk::Property::atoms.net_wm_state_skip_pager;
+ if (_fullscreen)
+ netstate[num++] = otk::Property::atoms.net_wm_state_fullscreen;
+ if (_max_vert)
+ netstate[num++] = otk::Property::atoms.net_wm_state_maximized_vert;
+ if (_max_horz)
+ netstate[num++] = otk::Property::atoms.net_wm_state_maximized_horz;
+ if (_above)
+ netstate[num++] = otk::Property::atoms.net_wm_state_above;
+ if (_below)
+ netstate[num++] = otk::Property::atoms.net_wm_state_below;
+ otk::Property::set(_window, otk::Property::atoms.net_wm_state,
+ otk::Property::atoms.atom, netstate, num);
+
+ calcLayer();
+
+ if (frame)
+ frame->adjustState();
+}
+
+
+void Client::changeAllowedActions(void)
+{
+ Atom actions[9];
+ int num = 0;
+
+ actions[num++] = otk::Property::atoms.net_wm_action_change_desktop;
+
+ if (_functions & Func_Shade)
+ actions[num++] = otk::Property::atoms.net_wm_action_shade;
+ if (_functions & Func_Close)
+ actions[num++] = otk::Property::atoms.net_wm_action_close;
+ if (_functions & Func_Move)
+ actions[num++] = otk::Property::atoms.net_wm_action_move;
+ if (_functions & Func_Iconify)
+ actions[num++] = otk::Property::atoms.net_wm_action_minimize;
+ if (_functions & Func_Resize)
+ actions[num++] = otk::Property::atoms.net_wm_action_resize;
+ if (_functions & Func_Fullscreen)
+ actions[num++] = otk::Property::atoms.net_wm_action_fullscreen;
+ if (_functions & Func_Maximize) {
+ actions[num++] = otk::Property::atoms.net_wm_action_maximize_horz;
+ actions[num++] = otk::Property::atoms.net_wm_action_maximize_vert;
+ }
+
+ otk::Property::set(_window, otk::Property::atoms.net_wm_allowed_actions,
+ otk::Property::atoms.atom, actions, num);
+}
+
+
+void Client::applyStartupState()
+{
+ // these are in a carefully crafted order..
+
+ if (_iconic) {
+ printf("MAP ICONIC\n");
+ _iconic = false;
+ setDesktop(ICONIC_DESKTOP);
+ }
+ if (_fullscreen) {
+ _fullscreen = false;
+ fullscreen(true);
+ }
+ if (_shaded) {
+ _shaded = false;
+ shade(true);
+ }
+
+ if (_max_vert); // XXX: incomplete
+ if (_max_horz); // XXX: incomplete
+
+ if (_skip_taskbar); // nothing to do for this
+ if (_skip_pager); // nothing to do for this
+ if (_modal); // nothing to do for this
+ if (_above); // nothing to do for this
+ if (_below); // nothing to do for this
+}
+
+
+void Client::shade(bool shade)
+{
+ if (!(_functions & Func_Shade) || // can't
+ _shaded == shade) return; // already done
+
+ // when we're iconic, don't change the wmstate
+ if (!_iconic)
+ _wmstate = shade ? IconicState : NormalState;
+ _shaded = shade;
+ changeState();
+ frame->adjustSize();
+}
+
+
+void Client::fullscreen(bool fs)
+{
+ static FunctionFlags saved_func;
+ static DecorationFlags saved_decor;
+ static otk::Rect saved_area;
+ static otk::Point saved_logical_size;
+
+ if (!(_functions & Func_Fullscreen) || // can't
+ _fullscreen == fs) return; // already done
+
+ _fullscreen = fs;
+ changeState(); // change the state hints on the client
+
+ if (fs) {
+ // save the functions and remove them
+ saved_func = _functions;
+ _functions = _functions & (Func_Close | Func_Fullscreen | Func_Iconify);
+ // save the decorations and remove them
+ saved_decor = _decorations;
+ _decorations = 0;
+ // save the area and adjust it (we don't call internal resize here for
+ // constraints on the size, etc, we just make it fullscreen).
+ saved_area = _area;
+ const otk::ScreenInfo *info = otk::display->screenInfo(_screen);
+ _area.setRect(0, 0, info->width(), info->height());
+ saved_logical_size = _logical_size;
+ _logical_size.setPoint((info->width() - _base_size.x()) / _size_inc.x(),
+ (info->height() - _base_size.y()) / _size_inc.y());
+ } else {
+ _functions = saved_func;
+ _decorations = saved_decor;
+ _area = saved_area;
+ _logical_size = saved_logical_size;
+ }
+
+ changeAllowedActions(); // based on the new _functions
+
+ frame->adjustSize(); // drop/replace the decor's and resize
+ frame->adjustPosition(); // get (back) in position!
+
+ // raise (back) into our stacking layer
+ openbox->screen(_screen)->raiseWindow(this);
+
+ // try focus us when we go into fullscreen mode
+ if (fs) focus();
+}
+
+
+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;
+
+ // do a check to see if the window has already been unmapped or destroyed
+ XEvent ev;
+ if (XCheckTypedWindowEvent(**otk::display, _window, UnmapNotify, &ev) ||
+ XCheckTypedWindowEvent(**otk::display, _window, DestroyNotify, &ev)) {
+ XPutBackEvent(**otk::display, &ev);
+ return false;
+ }
+
+ if (_can_focus)
+ XSetInputFocus(**otk::display, _window,
+ RevertToNone, CurrentTime);
+
+ if (_focus_notify) {
+ XEvent ce;
+ ce.xclient.type = ClientMessage;
+ ce.xclient.message_type = otk::Property::atoms.wm_protocols;
+ ce.xclient.display = **otk::display;
+ ce.xclient.window = _window;
+ ce.xclient.format = 32;
+ ce.xclient.data.l[0] = otk::Property::atoms.wm_take_focus;
+ ce.xclient.data.l[1] = openbox->lastTime();
+ ce.xclient.data.l[2] = 0l;
+ ce.xclient.data.l[3] = 0l;
+ ce.xclient.data.l[4] = 0l;
+ XSendEvent(**otk::display, _window, False, NoEventMask, &ce);
+ }
+
+ return true;
+}
+
+
+void Client::unfocus() const
+{
+ if (!_focused) return;
+
+ assert(openbox->focusedClient() == this);
+ openbox->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->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->focusedClient() == this)
+ openbox->setFocusedClient(0);