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)
32 // update EVERYTHING the first time!!
34 // the state is kinda assumed to be normal. is this right? XXX
35 _wmstate = NormalState;
36 // no default decors or functions, each has to be enabled
37 _decorations = _functions = 0;
43 // set the decorations and functions
46 // normal windows retain all of the possible decorations and
48 _decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
49 Decor_Iconify | Decor_Maximize;
50 _functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize;
53 // dialogs cannot be maximized
54 _decorations &= ~Decor_Maximize;
55 _functions &= ~Func_Maximize;
61 // these windows get less functionality
62 _decorations &= ~(Decor_Iconify | Decor_Handle);
63 _functions &= ~(Func_Iconify | Func_Resize);
69 // none of these windows are manipulated by the window manager
75 getMwmHints(); // this fucks (in good ways) with the decors and functions
82 // XXX: updateTransientFor();
89 printf("Mapped window: 0x%lx\n"
90 " title: \t%s\t icon title: \t%s\n"
91 " app name: \t%s\t\t class: \t%s\n"
92 " position: \t%d, %d\t\t size: \t%d, %d\n"
93 " desktop: \t%lu\t\t group: \t0x%lx\n"
94 " type: \t%d\t\t min size \t%d, %d\n"
95 " base size \t%d, %d\t\t max size \t%d, %d\n"
96 " size incr \t%d, %d\t\t gravity \t%d\n"
97 " wm state \t%ld\t\t can be focused:\t%s\n"
98 " notify focus: \t%s\t\t urgent: \t%s\n"
99 " shaped: \t%s\t\t modal: \t%s\n"
100 " shaded: \t%s\t\t iconic: \t%s\n"
101 " vert maximized:\t%s\t\t horz maximized:\t%s\n"
102 " fullscreen: \t%s\t\t floating: \t%s\n"
103 " requested pos: \t%s\n",
109 _area.x(), _area.y(),
110 _area.width(), _area.height(),
120 _can_focus ? "yes" : "no",
121 _focus_notify ? "yes" : "no",
122 _urgent ? "yes" : "no",
123 _shaped ? "yes" : "no",
124 _modal ? "yes" : "no",
125 _shaded ? "yes" : "no",
126 _iconic ? "yes" : "no",
127 _max_vert ? "yes" : "no",
128 _max_horz ? "yes" : "no",
129 _fullscreen ? "yes" : "no",
130 _floating ? "yes" : "no",
131 _positioned ? "yes" : "no");
137 OBClient::~OBClient()
139 const otk::OBProperty *property = Openbox::instance->property();
141 // these values should not be persisted across a window unmapping/mapping
142 property->erase(_window, otk::OBProperty::net_wm_desktop);
143 property->erase(_window, otk::OBProperty::net_wm_state);
147 void OBClient::getDesktop()
149 const otk::OBProperty *property = Openbox::instance->property();
151 // defaults to the current desktop
152 _desktop = 0; // XXX: change this to the current desktop!
154 property->get(_window, otk::OBProperty::net_wm_desktop,
155 otk::OBProperty::Atom_Cardinal,
160 void OBClient::getType()
162 const otk::OBProperty *property = Openbox::instance->property();
164 _type = (WindowType) -1;
167 unsigned long num = (unsigned) -1;
168 if (property->get(_window, otk::OBProperty::net_wm_window_type,
169 otk::OBProperty::Atom_Atom,
171 // use the first value that we know about in the array
172 for (unsigned long i = 0; i < num; ++i) {
174 property->atom(otk::OBProperty::net_wm_window_type_desktop))
175 _type = Type_Desktop;
177 property->atom(otk::OBProperty::net_wm_window_type_dock))
180 property->atom(otk::OBProperty::net_wm_window_type_toolbar))
181 _type = Type_Toolbar;
183 property->atom(otk::OBProperty::net_wm_window_type_menu))
186 property->atom(otk::OBProperty::net_wm_window_type_utility))
187 _type = Type_Utility;
189 property->atom(otk::OBProperty::net_wm_window_type_splash))
192 property->atom(otk::OBProperty::net_wm_window_type_dialog))
195 property->atom(otk::OBProperty::net_wm_window_type_normal))
197 // else if (val[i] ==
198 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
199 // mwm_decorations = 0; // prevent this window from getting any decor
200 // XXX: make this work again
205 if (_type == (WindowType) -1) {
207 * the window type hint was not set, which means we either classify ourself
208 * as a normal window or a dialog, depending on if we are a transient.
210 // XXX: make this code work!
212 // _type = Type_Dialog;
219 void OBClient::getMwmHints()
221 const otk::OBProperty *property = Openbox::instance->property();
226 num = MwmHints::elements;
227 if (!property->get(_window, otk::OBProperty::motif_wm_hints,
228 otk::OBProperty::motif_wm_hints, &num,
229 (unsigned long **)&hints))
232 if (num < MwmHints::elements) {
237 // retrieved the hints
238 // Mwm Hints are applied subtractively to what has already been chosen for
239 // decor and functionality
241 if (hints->flags & MwmFlag_Decorations) {
242 if (! (hints->decorations & MwmDecor_All)) {
243 if (! (hints->decorations & MwmDecor_Border))
244 _decorations &= ~Decor_Border;
245 if (! (hints->decorations & MwmDecor_Handle))
246 _decorations &= ~Decor_Handle;
247 if (! (hints->decorations & MwmDecor_Title))
248 _decorations &= ~Decor_Titlebar;
249 if (! (hints->decorations & MwmDecor_Iconify))
250 _decorations &= ~Decor_Iconify;
251 if (! (hints->decorations & MwmDecor_Maximize))
252 _decorations &= ~Decor_Maximize;
256 if (hints->flags & MwmFlag_Functions) {
257 if (! (hints->functions & MwmFunc_All)) {
258 if (! (hints->functions & MwmFunc_Resize))
259 _functions &= ~Func_Resize;
260 if (! (hints->functions & MwmFunc_Move))
261 _functions &= ~Func_Move;
262 if (! (hints->functions & MwmFunc_Iconify))
263 _functions &= ~Func_Iconify;
264 if (! (hints->functions & MwmFunc_Maximize))
265 _functions &= ~Func_Maximize;
266 //if (! (hints->functions & MwmFunc_Close))
267 // _functions &= ~Func_Close;
274 void OBClient::getArea()
276 XWindowAttributes wattrib;
279 ret = XGetWindowAttributes(otk::OBDisplay::display, _window, &wattrib);
280 assert(ret != BadWindow);
282 _area.setRect(wattrib.x, wattrib.y, wattrib.width, wattrib.height);
283 _border_width = wattrib.border_width;
287 void OBClient::getState()
289 const otk::OBProperty *property = Openbox::instance->property();
291 _modal = _shaded = _max_horz = _max_vert = _fullscreen = _floating = false;
293 unsigned long *state;
294 unsigned long num = (unsigned) -1;
296 if (property->get(_window, otk::OBProperty::net_wm_state,
297 otk::OBProperty::Atom_Atom, &num, &state)) {
298 for (unsigned long i = 0; i < num; ++i) {
299 if (state[i] == property->atom(otk::OBProperty::net_wm_state_modal))
302 property->atom(otk::OBProperty::net_wm_state_shaded))
305 property->atom(otk::OBProperty::net_wm_state_fullscreen))
308 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
311 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
320 void OBClient::getShaped()
324 if (otk::OBDisplay::shape()) {
329 XShapeSelectInput(otk::OBDisplay::display, _window, ShapeNotifyMask);
331 XShapeQueryExtents(otk::OBDisplay::display, _window, &s, &foo,
332 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
339 void OBClient::updateProtocols()
341 const otk::OBProperty *property = Openbox::instance->property();
346 _focus_notify = false;
347 _decorations &= ~Decor_Close;
348 _functions &= ~Func_Close;
350 if (XGetWMProtocols(otk::OBDisplay::display, _window, &proto, &num_return)) {
351 for (int i = 0; i < num_return; ++i) {
352 if (proto[i] == property->atom(otk::OBProperty::wm_delete_window)) {
353 _decorations |= Decor_Close;
354 _functions |= Func_Close;
355 // XXX: update the decor?
356 } else if (proto[i] == property->atom(otk::OBProperty::wm_take_focus))
357 // if this protocol is requested, then the window will be notified
358 // by the window manager whenever it receives focus
359 _focus_notify = true;
366 void OBClient::updateNormalHints()
372 _gravity = NorthWestGravity;
374 _base_x = _base_y = 0;
376 _max_x = _max_y = INT_MAX;
378 // XXX: might want to cancel any interactive resizing of the window at this
381 // get the hints from the window
382 if (XGetWMNormalHints(otk::OBDisplay::display, _window, &size, &ret)) {
383 _positioned = (size.flags & (PPosition|USPosition));
385 if (size.flags & PWinGravity)
386 _gravity = size.win_gravity;
388 if (size.flags & PMinSize) {
389 _min_x = size.min_width;
390 _min_y = size.min_height;
393 if (size.flags & PMaxSize) {
394 _max_x = size.max_width;
395 _max_y = size.max_height;
398 if (size.flags & PBaseSize) {
399 _base_x = size.base_width;
400 _base_y = size.base_height;
403 if (size.flags & PResizeInc) {
404 _inc_x = size.width_inc;
405 _inc_y = size.height_inc;
411 void OBClient::updateWMHints()
415 // assume a window takes input if it doesnt specify
419 if ((hints = XGetWMHints(otk::OBDisplay::display, _window)) != NULL) {
420 if (hints->flags & InputHint)
421 _can_focus = hints->input;
423 if (hints->flags & XUrgencyHint)
426 if (hints->flags & WindowGroupHint) {
427 if (hints->window_group != _group) {
428 // XXX: remove from the old group if there was one
429 _group = hints->window_group;
430 // XXX: do stuff with the group
440 void OBClient::updateTitle()
442 const otk::OBProperty *property = Openbox::instance->property();
447 if (! property->get(_window, otk::OBProperty::net_wm_name,
448 otk::OBProperty::utf8, &_title)) {
450 property->get(_window, otk::OBProperty::wm_name,
451 otk::OBProperty::ascii, &_title);
455 _title = _("Unnamed Window");
459 void OBClient::updateIconTitle()
461 const otk::OBProperty *property = Openbox::instance->property();
466 if (! property->get(_window, otk::OBProperty::net_wm_icon_name,
467 otk::OBProperty::utf8, &_icon_title)) {
469 property->get(_window, otk::OBProperty::wm_icon_name,
470 otk::OBProperty::ascii, &_icon_title);
474 _icon_title = _("Unnamed Window");
478 void OBClient::updateClass()
480 const otk::OBProperty *property = Openbox::instance->property();
483 _app_name = _app_class = "";
485 otk::OBProperty::StringVect v;
486 unsigned long num = 2;
488 if (! property->get(_window, otk::OBProperty::wm_class,
489 otk::OBProperty::ascii, &num, &v))
492 if (num > 0) _app_name = v[0];
493 if (num > 1) _app_class = v[1];
497 void OBClient::update(const XPropertyEvent &e)
499 const otk::OBProperty *property = Openbox::instance->property();
501 if (e.atom == XA_WM_NORMAL_HINTS)
503 else if (e.atom == XA_WM_HINTS)
505 else if (e.atom == property->atom(otk::OBProperty::net_wm_name) ||
506 e.atom == property->atom(otk::OBProperty::wm_name))
508 else if (e.atom == property->atom(otk::OBProperty::net_wm_icon_name) ||
509 e.atom == property->atom(otk::OBProperty::wm_icon_name))
511 else if (e.atom == property->atom(otk::OBProperty::wm_class))
513 else if (e.atom == property->atom(otk::OBProperty::wm_protocols))
515 // XXX: transient for hint
520 void OBClient::setWMState(long state)
522 if (state == _wmstate) return; // no change
526 // XXX: cause it to iconify
529 // XXX: cause it to uniconify
536 void OBClient::setDesktop(long target)
539 //assert(target == 0xffffffff || target < MAX);
541 // XXX: move the window to the new desktop
546 void OBClient::setState(StateAction action, long data1, long data2)
548 const otk::OBProperty *property = Openbox::instance->property();
550 if (!(action == State_Add || action == State_Remove ||
551 action == State_Toggle))
552 return; // an invalid action was passed to the client message, ignore it
554 for (int i = 0; i < 2; ++i) {
555 Atom state = i == 0 ? data1 : data2;
557 if (! state) continue;
559 // if toggling, then pick whether we're adding or removing
560 if (action == State_Toggle) {
561 if (state == property->atom(otk::OBProperty::net_wm_state_modal))
562 action = _modal ? State_Remove : State_Add;
564 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
565 action = _max_vert ? State_Remove : State_Add;
567 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
568 action = _max_horz ? State_Remove : State_Add;
569 else if (state == property->atom(otk::OBProperty::net_wm_state_shaded))
570 action = _shaded ? State_Remove : State_Add;
572 property->atom(otk::OBProperty::net_wm_state_fullscreen))
573 action = _fullscreen ? State_Remove : State_Add;
574 else if (state == property->atom(otk::OBProperty::net_wm_state_floating))
575 action = _floating ? State_Remove : State_Add;
578 if (action == State_Add) {
579 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
580 if (_modal) continue;
582 // XXX: give it focus if another window has focus that shouldnt now
584 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
585 if (_max_vert) continue;
587 // XXX: resize the window etc
589 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
590 if (_max_horz) continue;
592 // XXX: resize the window etc
594 property->atom(otk::OBProperty::net_wm_state_shaded)) {
595 if (_shaded) continue;
597 // XXX: hide the client window
599 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
600 if (_fullscreen) continue;
602 // XXX: raise the window n shit
604 property->atom(otk::OBProperty::net_wm_state_floating)) {
605 if (_floating) continue;
607 // XXX: raise the window n shit
610 } else { // action == State_Remove
611 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
612 if (!_modal) continue;
615 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
616 if (!_max_vert) continue;
618 // XXX: resize the window etc
620 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
621 if (!_max_horz) continue;
623 // XXX: resize the window etc
625 property->atom(otk::OBProperty::net_wm_state_shaded)) {
626 if (!_shaded) continue;
628 // XXX: show the client window
630 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
631 if (!_fullscreen) continue;
633 // XXX: lower the window to its proper layer
635 property->atom(otk::OBProperty::net_wm_state_floating)) {
636 if (!_floating) continue;
638 // XXX: lower the window to its proper layer
645 void OBClient::update(const XClientMessageEvent &e)
647 if (e.format != 32) return;
649 const otk::OBProperty *property = Openbox::instance->property();
651 if (e.message_type == property->atom(otk::OBProperty::wm_change_state))
652 setWMState(e.data.l[0]);
653 else if (e.message_type ==
654 property->atom(otk::OBProperty::net_wm_desktop))
655 setDesktop(e.data.l[0]);
656 else if (e.message_type == property->atom(otk::OBProperty::net_wm_state))
657 setState((StateAction)e.data.l[0], e.data.l[1], e.data.l[2]);
661 #if defined(SHAPE) || defined(DOXYGEN_IGNORE)
662 void OBClient::update(const XShapeEvent &e)
669 void OBClient::setArea(const otk::Rect &area)