1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 #include "otk/display.hh"
7 #include "otk/property.hh"
11 #include <X11/Xutil.h>
16 #define _(str) gettext(str)
21 OBClient::OBClient(Window window)
26 // update EVERYTHING the first time!!
28 // the state is kinda assumed to be normal. is this right? XXX
29 _wmstate = NormalState;
30 // no default decors or functions, each has to be enabled
31 _decorations = _functions = 0;
37 // set the decorations and functions
40 // normal windows retain all of the possible decorations and
42 _decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
43 Decor_Iconify | Decor_Maximize;
44 _functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize;
47 // dialogs cannot be maximized
48 _decorations &= ~Decor_Maximize;
49 _functions &= ~Func_Maximize;
55 // these windows get less functionality
56 _decorations &= ~(Decor_Iconify | Decor_Handle);
57 _functions &= ~(Func_Iconify | Func_Resize);
63 // none of these windows are manipulated by the window manager
69 getMwmHints(); // this fucks (in good ways) with the decors and functions
76 // XXX: updateTransientFor();
82 printf("Mapped window: 0x%lx\n"
83 " title: \t%s\t icon title: \t%s\n"
84 " app name: \t%s\t\t class: \t%s\n"
85 " position: \t%d, %d\t\t size: \t%d, %d\n"
86 " desktop: \t%lu\t\t group: \t0x%lx\n"
87 " type: \t%d\t\t min size \t%d, %d\n"
88 " base size \t%d, %d\t\t max size \t%d, %d\n"
89 " size incr \t%d, %d\t\t gravity \t%d\n"
90 " wm state \t%ld\t\t can be focused:\t%s\n"
91 " notify focus: \t%s\t\t urgent: \t%s\n"
92 " shaped: \t%s\t\t modal: \t%s\n"
93 " shaded: \t%s\t\t iconic: \t%s\n"
94 " vert maximized:\t%s\t\t horz maximized:\t%s\n"
95 " fullscreen: \t%s\t\t floating: \t%s\n"
96 " requested pos: \t%s\n",
102 _area.x(), _area.y(),
103 _area.width(), _area.height(),
113 _can_focus ? "yes" : "no",
114 _focus_notify ? "yes" : "no",
115 _urgent ? "yes" : "no",
116 _shaped ? "yes" : "no",
117 _modal ? "yes" : "no",
118 _shaded ? "yes" : "no",
119 _iconic ? "yes" : "no",
120 _max_vert ? "yes" : "no",
121 _max_horz ? "yes" : "no",
122 _fullscreen ? "yes" : "no",
123 _floating ? "yes" : "no",
124 _positioned ? "yes" : "no");
129 OBClient::~OBClient()
131 const otk::OBProperty *property = Openbox::instance->property();
133 // these values should not be persisted across a window unmapping/mapping
134 property->erase(_window, otk::OBProperty::net_wm_desktop);
135 property->erase(_window, otk::OBProperty::net_wm_state);
139 void OBClient::getDesktop()
141 const otk::OBProperty *property = Openbox::instance->property();
143 // defaults to the current desktop
144 _desktop = 0; // XXX: change this to the current desktop!
146 property->get(_window, otk::OBProperty::net_wm_desktop,
147 otk::OBProperty::Atom_Cardinal,
152 void OBClient::getType()
154 const otk::OBProperty *property = Openbox::instance->property();
156 _type = (WindowType) -1;
159 unsigned long num = (unsigned) -1;
160 if (property->get(_window, otk::OBProperty::net_wm_window_type,
161 otk::OBProperty::Atom_Atom,
163 // use the first value that we know about in the array
164 for (unsigned long i = 0; i < num; ++i) {
166 property->atom(otk::OBProperty::net_wm_window_type_desktop))
167 _type = Type_Desktop;
169 property->atom(otk::OBProperty::net_wm_window_type_dock))
172 property->atom(otk::OBProperty::net_wm_window_type_toolbar))
173 _type = Type_Toolbar;
175 property->atom(otk::OBProperty::net_wm_window_type_menu))
178 property->atom(otk::OBProperty::net_wm_window_type_utility))
179 _type = Type_Utility;
181 property->atom(otk::OBProperty::net_wm_window_type_splash))
184 property->atom(otk::OBProperty::net_wm_window_type_dialog))
187 property->atom(otk::OBProperty::net_wm_window_type_normal))
189 // else if (val[i] ==
190 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
191 // mwm_decorations = 0; // prevent this window from getting any decor
192 // XXX: make this work again
197 if (_type == (WindowType) -1) {
199 * the window type hint was not set, which means we either classify ourself
200 * as a normal window or a dialog, depending on if we are a transient.
202 // XXX: make this code work!
204 // _type = Type_Dialog;
211 void OBClient::getMwmHints()
213 const otk::OBProperty *property = Openbox::instance->property();
218 num = MwmHints::elements;
219 if (!property->get(_window, otk::OBProperty::motif_wm_hints,
220 otk::OBProperty::motif_wm_hints, &num,
221 (unsigned long **)&hints))
224 if (num < MwmHints::elements) {
229 // retrieved the hints
230 // Mwm Hints are applied subtractively to what has already been chosen for
231 // decor and functionality
233 if (hints->flags & MwmFlag_Decorations) {
234 if (! (hints->decorations & MwmDecor_All)) {
235 if (! (hints->decorations & MwmDecor_Border))
236 _decorations &= ~Decor_Border;
237 if (! (hints->decorations & MwmDecor_Handle))
238 _decorations &= ~Decor_Handle;
239 if (! (hints->decorations & MwmDecor_Title))
240 _decorations &= ~Decor_Titlebar;
241 if (! (hints->decorations & MwmDecor_Iconify))
242 _decorations &= ~Decor_Iconify;
243 if (! (hints->decorations & MwmDecor_Maximize))
244 _decorations &= ~Decor_Maximize;
248 if (hints->flags & MwmFlag_Functions) {
249 if (! (hints->functions & MwmFunc_All)) {
250 if (! (hints->functions & MwmFunc_Resize))
251 _functions &= ~Func_Resize;
252 if (! (hints->functions & MwmFunc_Move))
253 _functions &= ~Func_Move;
254 if (! (hints->functions & MwmFunc_Iconify))
255 _functions &= ~Func_Iconify;
256 if (! (hints->functions & MwmFunc_Maximize))
257 _functions &= ~Func_Maximize;
258 //if (! (hints->functions & MwmFunc_Close))
259 // _functions &= ~Func_Close;
266 void OBClient::getArea()
268 XWindowAttributes wattrib;
269 assert(XGetWindowAttributes(otk::OBDisplay::display, _window, &wattrib));
271 _area.setRect(wattrib.x, wattrib.y, wattrib.width, wattrib.height);
272 _border_width = wattrib.border_width;
276 void OBClient::getState()
278 const otk::OBProperty *property = Openbox::instance->property();
280 _modal = _shaded = _max_horz = _max_vert = _fullscreen = _floating = false;
282 unsigned long *state;
283 unsigned long num = (unsigned) -1;
285 if (property->get(_window, otk::OBProperty::net_wm_state,
286 otk::OBProperty::Atom_Atom, &num, &state)) {
287 for (unsigned long i = 0; i < num; ++i) {
288 if (state[i] == property->atom(otk::OBProperty::net_wm_state_modal))
291 property->atom(otk::OBProperty::net_wm_state_shaded))
294 property->atom(otk::OBProperty::net_wm_state_fullscreen))
297 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
300 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
309 void OBClient::getShaped()
313 if (otk::OBDisplay::shape()) {
317 XShapeQueryExtents(otk::OBDisplay::display, client.window, &_shaped, &foo,
318 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
324 void OBClient::updateProtocols()
326 const otk::OBProperty *property = Openbox::instance->property();
331 _focus_notify = false;
332 _decorations &= ~Decor_Close;
333 _functions &= ~Func_Close;
335 if (XGetWMProtocols(otk::OBDisplay::display, _window, &proto, &num_return)) {
336 for (int i = 0; i < num_return; ++i) {
337 if (proto[i] == property->atom(otk::OBProperty::wm_delete_window)) {
338 _decorations |= Decor_Close;
339 _functions |= Func_Close;
340 // XXX: update the decor?
341 } else if (proto[i] == property->atom(otk::OBProperty::wm_take_focus))
342 // if this protocol is requested, then the window will be notified
343 // by the window manager whenever it receives focus
344 _focus_notify = true;
351 void OBClient::updateNormalHints()
357 _gravity = NorthWestGravity;
359 _base_x = _base_y = 0;
361 _max_x = _max_y = INT_MAX;
363 // XXX: might want to cancel any interactive resizing of the window at this
366 // get the hints from the window
367 if (XGetWMNormalHints(otk::OBDisplay::display, _window, &size, &ret)) {
368 _positioned = (size.flags & (PPosition|USPosition));
370 if (size.flags & PWinGravity)
371 _gravity = size.win_gravity;
373 if (size.flags & PMinSize) {
374 _min_x = size.min_width;
375 _min_y = size.min_height;
378 if (size.flags & PMaxSize) {
379 _max_x = size.max_width;
380 _max_y = size.max_height;
383 if (size.flags & PBaseSize) {
384 _base_x = size.base_width;
385 _base_y = size.base_height;
388 if (size.flags & PResizeInc) {
389 _inc_x = size.width_inc;
390 _inc_y = size.height_inc;
396 void OBClient::updateWMHints()
400 // assume a window takes input if it doesnt specify
404 if ((hints = XGetWMHints(otk::OBDisplay::display, _window)) != NULL) {
405 if (hints->flags & InputHint)
406 _can_focus = hints->input;
408 if (hints->flags & XUrgencyHint)
411 if (hints->flags & WindowGroupHint) {
412 if (hints->window_group != _group) {
413 // XXX: remove from the old group if there was one
414 _group = hints->window_group;
415 // XXX: do stuff with the group
425 void OBClient::updateTitle()
427 const otk::OBProperty *property = Openbox::instance->property();
432 if (! property->get(_window, otk::OBProperty::net_wm_name,
433 otk::OBProperty::utf8, &_title)) {
435 property->get(_window, otk::OBProperty::wm_name,
436 otk::OBProperty::ascii, &_title);
440 _title = _("Unnamed Window");
444 void OBClient::updateIconTitle()
446 const otk::OBProperty *property = Openbox::instance->property();
451 if (! property->get(_window, otk::OBProperty::net_wm_icon_name,
452 otk::OBProperty::utf8, &_icon_title)) {
454 property->get(_window, otk::OBProperty::wm_icon_name,
455 otk::OBProperty::ascii, &_icon_title);
459 _icon_title = _("Unnamed Window");
463 void OBClient::updateClass()
465 const otk::OBProperty *property = Openbox::instance->property();
468 _app_name = _app_class = "";
470 otk::OBProperty::StringVect v;
471 unsigned long num = 2;
473 if (! property->get(_window, otk::OBProperty::wm_class,
474 otk::OBProperty::ascii, &num, &v))
477 if (num > 0) _app_name = v[0];
478 if (num > 1) _app_class = v[1];
482 void OBClient::update(const XPropertyEvent &e)
484 const otk::OBProperty *property = Openbox::instance->property();
486 if (e.atom == XA_WM_NORMAL_HINTS)
488 else if (e.atom == XA_WM_HINTS)
490 else if (e.atom == property->atom(otk::OBProperty::net_wm_name) ||
491 e.atom == property->atom(otk::OBProperty::wm_name))
493 else if (e.atom == property->atom(otk::OBProperty::net_wm_icon_name) ||
494 e.atom == property->atom(otk::OBProperty::wm_icon_name))
496 else if (e.atom == property->atom(otk::OBProperty::wm_class))
498 else if (e.atom == property->atom(otk::OBProperty::wm_protocols))
500 // XXX: transient for hint
505 void OBClient::setWMState(long state)
507 if (state == _wmstate) return; // no change
511 // XXX: cause it to iconify
514 // XXX: cause it to uniconify
521 void OBClient::setDesktop(long target)
524 //assert(target == 0xffffffff || target < MAX);
526 // XXX: move the window to the new desktop
531 void OBClient::setState(StateAction action, long data1, long data2)
533 const otk::OBProperty *property = Openbox::instance->property();
535 if (!(action == State_Add || action == State_Remove ||
536 action == State_Toggle))
537 return; // an invalid action was passed to the client message, ignore it
539 for (int i = 0; i < 2; ++i) {
540 Atom state = i == 0 ? data1 : data2;
542 if (! state) continue;
544 // if toggling, then pick whether we're adding or removing
545 if (action == State_Toggle) {
546 if (state == property->atom(otk::OBProperty::net_wm_state_modal))
547 action = _modal ? State_Remove : State_Add;
549 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
550 action = _max_vert ? State_Remove : State_Add;
552 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
553 action = _max_horz ? State_Remove : State_Add;
554 else if (state == property->atom(otk::OBProperty::net_wm_state_shaded))
555 action = _shaded ? State_Remove : State_Add;
557 property->atom(otk::OBProperty::net_wm_state_fullscreen))
558 action = _fullscreen ? State_Remove : State_Add;
559 else if (state == property->atom(otk::OBProperty::net_wm_state_floating))
560 action = _floating ? State_Remove : State_Add;
563 if (action == State_Add) {
564 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
565 if (_modal) continue;
567 // XXX: give it focus if another window has focus that shouldnt now
569 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
570 if (_max_vert) continue;
572 // XXX: resize the window etc
574 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
575 if (_max_horz) continue;
577 // XXX: resize the window etc
579 property->atom(otk::OBProperty::net_wm_state_shaded)) {
580 if (_shaded) continue;
582 // XXX: hide the client window
584 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
585 if (_fullscreen) continue;
587 // XXX: raise the window n shit
589 property->atom(otk::OBProperty::net_wm_state_floating)) {
590 if (_floating) continue;
592 // XXX: raise the window n shit
595 } else { // action == State_Remove
596 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
597 if (!_modal) continue;
600 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
601 if (!_max_vert) continue;
603 // XXX: resize the window etc
605 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
606 if (!_max_horz) continue;
608 // XXX: resize the window etc
610 property->atom(otk::OBProperty::net_wm_state_shaded)) {
611 if (!_shaded) continue;
613 // XXX: show the client window
615 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
616 if (!_fullscreen) continue;
618 // XXX: lower the window to its proper layer
620 property->atom(otk::OBProperty::net_wm_state_floating)) {
621 if (!_floating) continue;
623 // XXX: lower the window to its proper layer
630 void OBClient::update(const XClientMessageEvent &e)
632 if (e.format != 32) return;
634 const otk::OBProperty *property = Openbox::instance->property();
636 if (e.message_type == property->atom(otk::OBProperty::wm_change_state))
637 setWMState(e.data.l[0]);
638 else if (e.message_type ==
639 property->atom(otk::OBProperty::net_wm_desktop))
640 setDesktop(e.data.l[0]);
641 else if (e.message_type == property->atom(otk::OBProperty::net_wm_state))
642 setState((StateAction)e.data.l[0], e.data.l[1], e.data.l[2]);
646 void OBClient::setArea(const otk::Rect &area)