1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
10 #include "otk/display.hh"
11 #include "otk/property.hh"
15 #include <X11/Xutil.h>
20 #define _(str) gettext(str)
25 OBClient::OBClient(int screen, Window window)
26 : _screen(screen), _window(window)
30 // update EVERYTHING the first time!!
32 // the state is kinda assumed to be normal. is this right? XXX
33 _wmstate = NormalState;
34 // no default decors or functions, each has to be enabled
35 _decorations = _functions = 0;
41 // set the decorations and functions
44 // normal windows retain all of the possible decorations and
46 _decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
47 Decor_Iconify | Decor_Maximize;
48 _functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize;
51 // dialogs cannot be maximized
52 _decorations &= ~Decor_Maximize;
53 _functions &= ~Func_Maximize;
59 // these windows get less functionality
60 _decorations &= ~(Decor_Iconify | Decor_Handle);
61 _functions &= ~(Func_Iconify | Func_Resize);
67 // none of these windows are manipulated by the window manager
73 getMwmHints(); // this fucks (in good ways) with the decors and functions
80 // XXX: updateTransientFor();
87 printf("Mapped window: 0x%lx\n"
88 " title: \t%s\t icon title: \t%s\n"
89 " app name: \t%s\t\t class: \t%s\n"
90 " position: \t%d, %d\t\t size: \t%d, %d\n"
91 " desktop: \t%lu\t\t group: \t0x%lx\n"
92 " type: \t%d\t\t min size \t%d, %d\n"
93 " base size \t%d, %d\t\t max size \t%d, %d\n"
94 " size incr \t%d, %d\t\t gravity \t%d\n"
95 " wm state \t%ld\t\t can be focused:\t%s\n"
96 " notify focus: \t%s\t\t urgent: \t%s\n"
97 " shaped: \t%s\t\t modal: \t%s\n"
98 " shaded: \t%s\t\t iconic: \t%s\n"
99 " vert maximized:\t%s\t\t horz maximized:\t%s\n"
100 " fullscreen: \t%s\t\t floating: \t%s\n"
101 " requested pos: \t%s\n",
107 _area.x(), _area.y(),
108 _area.width(), _area.height(),
118 _can_focus ? "yes" : "no",
119 _focus_notify ? "yes" : "no",
120 _urgent ? "yes" : "no",
121 _shaped ? "yes" : "no",
122 _modal ? "yes" : "no",
123 _shaded ? "yes" : "no",
124 _iconic ? "yes" : "no",
125 _max_vert ? "yes" : "no",
126 _max_horz ? "yes" : "no",
127 _fullscreen ? "yes" : "no",
128 _floating ? "yes" : "no",
129 _positioned ? "yes" : "no");
135 OBClient::~OBClient()
137 const otk::OBProperty *property = Openbox::instance->property();
139 // these values should not be persisted across a window unmapping/mapping
140 property->erase(_window, otk::OBProperty::net_wm_desktop);
141 property->erase(_window, otk::OBProperty::net_wm_state);
145 void OBClient::getDesktop()
147 const otk::OBProperty *property = Openbox::instance->property();
149 // defaults to the current desktop
150 _desktop = 0; // XXX: change this to the current desktop!
152 property->get(_window, otk::OBProperty::net_wm_desktop,
153 otk::OBProperty::Atom_Cardinal,
158 void OBClient::getType()
160 const otk::OBProperty *property = Openbox::instance->property();
162 _type = (WindowType) -1;
165 unsigned long num = (unsigned) -1;
166 if (property->get(_window, otk::OBProperty::net_wm_window_type,
167 otk::OBProperty::Atom_Atom,
169 // use the first value that we know about in the array
170 for (unsigned long i = 0; i < num; ++i) {
172 property->atom(otk::OBProperty::net_wm_window_type_desktop))
173 _type = Type_Desktop;
175 property->atom(otk::OBProperty::net_wm_window_type_dock))
178 property->atom(otk::OBProperty::net_wm_window_type_toolbar))
179 _type = Type_Toolbar;
181 property->atom(otk::OBProperty::net_wm_window_type_menu))
184 property->atom(otk::OBProperty::net_wm_window_type_utility))
185 _type = Type_Utility;
187 property->atom(otk::OBProperty::net_wm_window_type_splash))
190 property->atom(otk::OBProperty::net_wm_window_type_dialog))
193 property->atom(otk::OBProperty::net_wm_window_type_normal))
195 // else if (val[i] ==
196 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
197 // mwm_decorations = 0; // prevent this window from getting any decor
198 // XXX: make this work again
203 if (_type == (WindowType) -1) {
205 * the window type hint was not set, which means we either classify ourself
206 * as a normal window or a dialog, depending on if we are a transient.
208 // XXX: make this code work!
210 // _type = Type_Dialog;
217 void OBClient::getMwmHints()
219 const otk::OBProperty *property = Openbox::instance->property();
224 num = MwmHints::elements;
225 if (!property->get(_window, otk::OBProperty::motif_wm_hints,
226 otk::OBProperty::motif_wm_hints, &num,
227 (unsigned long **)&hints))
230 if (num < MwmHints::elements) {
235 // retrieved the hints
236 // Mwm Hints are applied subtractively to what has already been chosen for
237 // decor and functionality
239 if (hints->flags & MwmFlag_Decorations) {
240 if (! (hints->decorations & MwmDecor_All)) {
241 if (! (hints->decorations & MwmDecor_Border))
242 _decorations &= ~Decor_Border;
243 if (! (hints->decorations & MwmDecor_Handle))
244 _decorations &= ~Decor_Handle;
245 if (! (hints->decorations & MwmDecor_Title))
246 _decorations &= ~Decor_Titlebar;
247 if (! (hints->decorations & MwmDecor_Iconify))
248 _decorations &= ~Decor_Iconify;
249 if (! (hints->decorations & MwmDecor_Maximize))
250 _decorations &= ~Decor_Maximize;
254 if (hints->flags & MwmFlag_Functions) {
255 if (! (hints->functions & MwmFunc_All)) {
256 if (! (hints->functions & MwmFunc_Resize))
257 _functions &= ~Func_Resize;
258 if (! (hints->functions & MwmFunc_Move))
259 _functions &= ~Func_Move;
260 if (! (hints->functions & MwmFunc_Iconify))
261 _functions &= ~Func_Iconify;
262 if (! (hints->functions & MwmFunc_Maximize))
263 _functions &= ~Func_Maximize;
264 //if (! (hints->functions & MwmFunc_Close))
265 // _functions &= ~Func_Close;
272 void OBClient::getArea()
274 XWindowAttributes wattrib;
275 assert(XGetWindowAttributes(otk::OBDisplay::display, _window, &wattrib));
277 _area.setRect(wattrib.x, wattrib.y, wattrib.width, wattrib.height);
278 _border_width = wattrib.border_width;
282 void OBClient::getState()
284 const otk::OBProperty *property = Openbox::instance->property();
286 _modal = _shaded = _max_horz = _max_vert = _fullscreen = _floating = false;
288 unsigned long *state;
289 unsigned long num = (unsigned) -1;
291 if (property->get(_window, otk::OBProperty::net_wm_state,
292 otk::OBProperty::Atom_Atom, &num, &state)) {
293 for (unsigned long i = 0; i < num; ++i) {
294 if (state[i] == property->atom(otk::OBProperty::net_wm_state_modal))
297 property->atom(otk::OBProperty::net_wm_state_shaded))
300 property->atom(otk::OBProperty::net_wm_state_fullscreen))
303 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
306 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
315 void OBClient::getShaped()
319 if (otk::OBDisplay::shape()) {
324 XShapeSelectInput(otk::OBDisplay::display, _window, ShapeNotifyMask);
326 XShapeQueryExtents(otk::OBDisplay::display, _window, &s, &foo,
327 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
334 void OBClient::updateProtocols()
336 const otk::OBProperty *property = Openbox::instance->property();
341 _focus_notify = false;
342 _decorations &= ~Decor_Close;
343 _functions &= ~Func_Close;
345 if (XGetWMProtocols(otk::OBDisplay::display, _window, &proto, &num_return)) {
346 for (int i = 0; i < num_return; ++i) {
347 if (proto[i] == property->atom(otk::OBProperty::wm_delete_window)) {
348 _decorations |= Decor_Close;
349 _functions |= Func_Close;
350 // XXX: update the decor?
351 } else if (proto[i] == property->atom(otk::OBProperty::wm_take_focus))
352 // if this protocol is requested, then the window will be notified
353 // by the window manager whenever it receives focus
354 _focus_notify = true;
361 void OBClient::updateNormalHints()
367 _gravity = NorthWestGravity;
369 _base_x = _base_y = 0;
371 _max_x = _max_y = INT_MAX;
373 // XXX: might want to cancel any interactive resizing of the window at this
376 // get the hints from the window
377 if (XGetWMNormalHints(otk::OBDisplay::display, _window, &size, &ret)) {
378 _positioned = (size.flags & (PPosition|USPosition));
380 if (size.flags & PWinGravity)
381 _gravity = size.win_gravity;
383 if (size.flags & PMinSize) {
384 _min_x = size.min_width;
385 _min_y = size.min_height;
388 if (size.flags & PMaxSize) {
389 _max_x = size.max_width;
390 _max_y = size.max_height;
393 if (size.flags & PBaseSize) {
394 _base_x = size.base_width;
395 _base_y = size.base_height;
398 if (size.flags & PResizeInc) {
399 _inc_x = size.width_inc;
400 _inc_y = size.height_inc;
406 void OBClient::updateWMHints()
410 // assume a window takes input if it doesnt specify
414 if ((hints = XGetWMHints(otk::OBDisplay::display, _window)) != NULL) {
415 if (hints->flags & InputHint)
416 _can_focus = hints->input;
418 if (hints->flags & XUrgencyHint)
421 if (hints->flags & WindowGroupHint) {
422 if (hints->window_group != _group) {
423 // XXX: remove from the old group if there was one
424 _group = hints->window_group;
425 // XXX: do stuff with the group
435 void OBClient::updateTitle()
437 const otk::OBProperty *property = Openbox::instance->property();
442 if (! property->get(_window, otk::OBProperty::net_wm_name,
443 otk::OBProperty::utf8, &_title)) {
445 property->get(_window, otk::OBProperty::wm_name,
446 otk::OBProperty::ascii, &_title);
450 _title = _("Unnamed Window");
454 void OBClient::updateIconTitle()
456 const otk::OBProperty *property = Openbox::instance->property();
461 if (! property->get(_window, otk::OBProperty::net_wm_icon_name,
462 otk::OBProperty::utf8, &_icon_title)) {
464 property->get(_window, otk::OBProperty::wm_icon_name,
465 otk::OBProperty::ascii, &_icon_title);
469 _icon_title = _("Unnamed Window");
473 void OBClient::updateClass()
475 const otk::OBProperty *property = Openbox::instance->property();
478 _app_name = _app_class = "";
480 otk::OBProperty::StringVect v;
481 unsigned long num = 2;
483 if (! property->get(_window, otk::OBProperty::wm_class,
484 otk::OBProperty::ascii, &num, &v))
487 if (num > 0) _app_name = v[0];
488 if (num > 1) _app_class = v[1];
492 void OBClient::update(const XPropertyEvent &e)
494 const otk::OBProperty *property = Openbox::instance->property();
496 if (e.atom == XA_WM_NORMAL_HINTS)
498 else if (e.atom == XA_WM_HINTS)
500 else if (e.atom == property->atom(otk::OBProperty::net_wm_name) ||
501 e.atom == property->atom(otk::OBProperty::wm_name))
503 else if (e.atom == property->atom(otk::OBProperty::net_wm_icon_name) ||
504 e.atom == property->atom(otk::OBProperty::wm_icon_name))
506 else if (e.atom == property->atom(otk::OBProperty::wm_class))
508 else if (e.atom == property->atom(otk::OBProperty::wm_protocols))
510 // XXX: transient for hint
515 void OBClient::setWMState(long state)
517 if (state == _wmstate) return; // no change
521 // XXX: cause it to iconify
524 // XXX: cause it to uniconify
531 void OBClient::setDesktop(long target)
534 //assert(target == 0xffffffff || target < MAX);
536 // XXX: move the window to the new desktop
541 void OBClient::setState(StateAction action, long data1, long data2)
543 const otk::OBProperty *property = Openbox::instance->property();
545 if (!(action == State_Add || action == State_Remove ||
546 action == State_Toggle))
547 return; // an invalid action was passed to the client message, ignore it
549 for (int i = 0; i < 2; ++i) {
550 Atom state = i == 0 ? data1 : data2;
552 if (! state) continue;
554 // if toggling, then pick whether we're adding or removing
555 if (action == State_Toggle) {
556 if (state == property->atom(otk::OBProperty::net_wm_state_modal))
557 action = _modal ? State_Remove : State_Add;
559 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
560 action = _max_vert ? State_Remove : State_Add;
562 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
563 action = _max_horz ? State_Remove : State_Add;
564 else if (state == property->atom(otk::OBProperty::net_wm_state_shaded))
565 action = _shaded ? State_Remove : State_Add;
567 property->atom(otk::OBProperty::net_wm_state_fullscreen))
568 action = _fullscreen ? State_Remove : State_Add;
569 else if (state == property->atom(otk::OBProperty::net_wm_state_floating))
570 action = _floating ? State_Remove : State_Add;
573 if (action == State_Add) {
574 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
575 if (_modal) continue;
577 // XXX: give it focus if another window has focus that shouldnt now
579 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
580 if (_max_vert) continue;
582 // XXX: resize the window etc
584 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
585 if (_max_horz) continue;
587 // XXX: resize the window etc
589 property->atom(otk::OBProperty::net_wm_state_shaded)) {
590 if (_shaded) continue;
592 // XXX: hide the client window
594 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
595 if (_fullscreen) continue;
597 // XXX: raise the window n shit
599 property->atom(otk::OBProperty::net_wm_state_floating)) {
600 if (_floating) continue;
602 // XXX: raise the window n shit
605 } else { // action == State_Remove
606 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
607 if (!_modal) continue;
610 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
611 if (!_max_vert) continue;
613 // XXX: resize the window etc
615 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
616 if (!_max_horz) continue;
618 // XXX: resize the window etc
620 property->atom(otk::OBProperty::net_wm_state_shaded)) {
621 if (!_shaded) continue;
623 // XXX: show the client window
625 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
626 if (!_fullscreen) continue;
628 // XXX: lower the window to its proper layer
630 property->atom(otk::OBProperty::net_wm_state_floating)) {
631 if (!_floating) continue;
633 // XXX: lower the window to its proper layer
640 void OBClient::update(const XClientMessageEvent &e)
642 if (e.format != 32) return;
644 const otk::OBProperty *property = Openbox::instance->property();
646 if (e.message_type == property->atom(otk::OBProperty::wm_change_state))
647 setWMState(e.data.l[0]);
648 else if (e.message_type ==
649 property->atom(otk::OBProperty::net_wm_desktop))
650 setDesktop(e.data.l[0]);
651 else if (e.message_type == property->atom(otk::OBProperty::net_wm_state))
652 setState((StateAction)e.data.l[0], e.data.l[1], e.data.l[2]);
656 #if defined(SHAPE) || defined(DOXYGEN_IGNORE)
657 void OBClient::update(const XShapeEvent &e)
664 void OBClient::setArea(const otk::Rect &area)