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;
43 // XXX: updateTransientFor();
48 printf("Mapped window: 0x%lx\n"
49 " title: \t%s\t icon title: \t%s\n"
50 " app name: \t%s\t\t class: \t%s\n"
51 " position: \t%d, %d\t\t size: \t%d, %d\n"
52 " desktop: \t%lu\t\t group: \t0x%lx\n"
53 " type: \t%d\t\t min size \t%d, %d\n"
54 " base size \t%d, %d\t\t max size \t%d, %d\n"
55 " size incr \t%d, %d\t\t gravity \t%d\n"
56 " wm state \t%ld\t\t can be focused:\t%s\n"
57 " notify focus: \t%s\t\t urgent: \t%s\n"
58 " shaped: \t%s\t\t modal: \t%s\n"
59 " shaded: \t%s\t\t iconic: \t%s\n"
60 " vert maximized:\t%s\t\t horz maximized:\t%s\n"
61 " fullscreen: \t%s\t\t floating: \t%s\n"
62 " requested pos: \t%s\n",
69 _area.width(), _area.height(),
79 _can_focus ? "yes" : "no",
80 _focus_notify ? "yes" : "no",
81 _urgent ? "yes" : "no",
82 _shaped ? "yes" : "no",
83 _modal ? "yes" : "no",
84 _shaded ? "yes" : "no",
85 _iconic ? "yes" : "no",
86 _max_vert ? "yes" : "no",
87 _max_horz ? "yes" : "no",
88 _fullscreen ? "yes" : "no",
89 _floating ? "yes" : "no",
90 _positioned ? "yes" : "no");
97 const otk::OBProperty *property = Openbox::instance->property();
99 // these values should not be persisted across a window unmapping/mapping
100 property->erase(_window, otk::OBProperty::net_wm_desktop);
101 property->erase(_window, otk::OBProperty::net_wm_state);
105 void OBClient::getDesktop()
107 const otk::OBProperty *property = Openbox::instance->property();
109 // defaults to the current desktop
110 _desktop = 0; // XXX: change this to the current desktop!
112 property->get(_window, otk::OBProperty::net_wm_desktop,
113 otk::OBProperty::Atom_Cardinal,
118 void OBClient::getType()
120 const otk::OBProperty *property = Openbox::instance->property();
122 _type = (WindowType) -1;
125 unsigned long num = (unsigned) -1;
126 if (property->get(_window, otk::OBProperty::net_wm_window_type,
127 otk::OBProperty::Atom_Atom,
129 // use the first value that we know about in the array
130 for (unsigned long i = 0; i < num; ++i) {
132 property->atom(otk::OBProperty::net_wm_window_type_desktop))
133 _type = Type_Desktop;
135 property->atom(otk::OBProperty::net_wm_window_type_dock))
138 property->atom(otk::OBProperty::net_wm_window_type_toolbar))
139 _type = Type_Toolbar;
141 property->atom(otk::OBProperty::net_wm_window_type_menu))
144 property->atom(otk::OBProperty::net_wm_window_type_utility))
145 _type = Type_Utility;
147 property->atom(otk::OBProperty::net_wm_window_type_splash))
150 property->atom(otk::OBProperty::net_wm_window_type_dialog))
153 property->atom(otk::OBProperty::net_wm_window_type_normal))
155 // else if (val[i] ==
156 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
157 // mwm_decorations = 0; // prevent this window from getting any decor
158 // XXX: make this work again
163 if (_type == (WindowType) -1) {
165 * the window type hint was not set, which means we either classify ourself
166 * as a normal window or a dialog, depending on if we are a transient.
168 // XXX: make this code work!
170 // _type = Type_Dialog;
175 // set the decorations and functions based on the type of the window
179 void OBClient::getMWMHints()
181 const otk::OBProperty *property = Openbox::instance->property();
186 num = MwmHints::elements;
187 if (!property->get(_window, otk::OBProperty::motif_wm_hints,
188 otk::OBProperty::motif_wm_hints, &num,
189 (unsigned long **)&hints))
192 if (num < MwmHints::elements) {
197 // retrieved the hints
198 // Mwm Hints are applied subtractively to what has already been chosen for
199 // decor and functionality
201 if (hints->flags & MwmDecorations) {
202 if (! (hints->decorations & MwmDecor_All)) {
203 if (! (hints->decorations & MwmDecor_Border))
204 _decorations &= ~Decor_Border;
205 if (! (hints->decorations & MwmDecor_Handle))
206 _decorations &= ~Decor_Handle;
207 if (! (hints->decorations & MwmDecor_Title))
208 _decorations &= ~Decor_Titlebar;
209 if (! (hints->decorations & MwmDecor_Iconify))
210 _decorations &= ~Decor_Iconify;
211 if (! (hints->decorations & MwmDecor_Maximize))
212 _decorations &= ~Decor_Maximize;
216 _mwm_functions = 0xffffffff; // everything!
218 if (hints->flags & MwmFunctions) {
219 if (! (hints->functions & MwmFunc_All)) {
220 _mwm_functions = hints->functions;
222 if (! (hints->functions & MwmFunc_Resize))
223 functions &= ~Func_Resize;
224 if (! (hints->functions & MwmFunc_Move))
225 functions &= ~Func_Move;
226 if (! (hints->functions & MwmFunc_Iconify))
227 functions &= ~Func_Iconify;
228 if (! (hints->functions & MwmFunc_Maximize))
229 functions &= ~Func_Maximize;
230 if (! (hints->functions & MwmFunc_Close))
231 functions &= ~Func_Close;
238 void OBClient::getArea()
240 XWindowAttributes wattrib;
241 assert(XGetWindowAttributes(otk::OBDisplay::display, _window, &wattrib));
243 _area.setRect(wattrib.x, wattrib.y, wattrib.width, wattrib.height);
244 _border_width = wattrib.border_width;
248 void OBClient::getState()
250 const otk::OBProperty *property = Openbox::instance->property();
252 _modal = _shaded = _max_horz = _max_vert = _fullscreen = _floating = false;
254 unsigned long *state;
255 unsigned long num = (unsigned) -1;
257 if (property->get(_window, otk::OBProperty::net_wm_state,
258 otk::OBProperty::Atom_Atom, &num, &state)) {
259 for (unsigned long i = 0; i < num; ++i) {
260 if (state[i] == property->atom(otk::OBProperty::net_wm_state_modal))
263 property->atom(otk::OBProperty::net_wm_state_shaded))
266 property->atom(otk::OBProperty::net_wm_state_fullscreen))
269 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
272 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
281 void OBClient::getShaped()
285 if (otk::OBDisplay::shape()) {
289 XShapeQueryExtents(otk::OBDisplay::display, client.window, &_shaped, &foo,
290 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
296 void OBClient::updateProtocols()
298 const otk::OBProperty *property = Openbox::instance->property();
303 _focus_notify = false;
305 if (XGetWMProtocols(otk::OBDisplay::display, _window, &proto, &num_return)) {
306 for (int i = 0; i < num_return; ++i) {
307 if (proto[i] == property->atom(otk::OBProperty::wm_delete_window)) {
308 // add the close button/functionality only if the mwm hints didnt
310 if (_mwm_functions & MwmFunc_Close) {
311 decorations |= Decor_Close;
312 functions |= Func_Close;
313 // XXX: update the decor?
315 } else if (proto[i] == property->atom(otk::OBProperty::wm_take_focus))
316 // if this protocol is requested, then the window will be notified
317 // by the window manager whenever it receives focus
318 _focus_notify = true;
325 void OBClient::updateNormalHints()
331 _gravity = NorthWestGravity;
333 _base_x = _base_y = 0;
335 _max_x = _max_y = INT_MAX;
337 // XXX: might want to cancel any interactive resizing of the window at this
340 // get the hints from the window
341 if (XGetWMNormalHints(otk::OBDisplay::display, _window, &size, &ret)) {
342 _positioned = (size.flags & (PPosition|USPosition));
344 if (size.flags & PWinGravity)
345 _gravity = size.win_gravity;
347 if (size.flags & PMinSize) {
348 _min_x = size.min_width;
349 _min_y = size.min_height;
352 if (size.flags & PMaxSize) {
353 _max_x = size.max_width;
354 _max_y = size.max_height;
357 if (size.flags & PBaseSize) {
358 _base_x = size.base_width;
359 _base_y = size.base_height;
362 if (size.flags & PResizeInc) {
363 _inc_x = size.width_inc;
364 _inc_y = size.height_inc;
370 void OBClient::updateWMHints()
374 // assume a window takes input if it doesnt specify
378 if ((hints = XGetWMHints(otk::OBDisplay::display, _window)) != NULL) {
379 if (hints->flags & InputHint)
380 _can_focus = hints->input;
382 if (hints->flags & XUrgencyHint)
385 if (hints->flags & WindowGroupHint) {
386 if (hints->window_group != _group) {
387 // XXX: remove from the old group if there was one
388 _group = hints->window_group;
389 // XXX: do stuff with the group
399 void OBClient::updateTitle()
401 const otk::OBProperty *property = Openbox::instance->property();
406 if (! property->get(_window, otk::OBProperty::net_wm_name,
407 otk::OBProperty::utf8, &_title)) {
409 property->get(_window, otk::OBProperty::wm_name,
410 otk::OBProperty::ascii, &_title);
414 _title = _("Unnamed Window");
418 void OBClient::updateClass()
420 const otk::OBProperty *property = Openbox::instance->property();
423 _app_name = _app_class = "";
425 otk::OBProperty::StringVect v;
426 unsigned long num = 2;
428 if (! property->get(_window, otk::OBProperty::wm_class,
429 otk::OBProperty::ascii, &num, &v))
432 if (num > 0) _app_name = v[0];
433 if (num > 1) _app_class = v[1];
437 void OBClient::update(const XPropertyEvent &e)
439 const otk::OBProperty *property = Openbox::instance->property();
441 if (e.atom == XA_WM_NORMAL_HINTS)
443 else if (e.atom == XA_WM_HINTS)
445 else if (e.atom == property->atom(otk::OBProperty::net_wm_name) ||
446 e.atom == property->atom(otk::OBProperty::wm_name) ||
447 e.atom == property->atom(otk::OBProperty::net_wm_icon_name) ||
448 e.atom == property->atom(otk::OBProperty::wm_icon_name))
450 else if (e.atom == property->atom(otk::OBProperty::wm_class))
452 else if (e.atom == property->atom(otk::OBProperty::wm_protocols))
454 // XXX: transient for hint
459 void OBClient::setWMState(long state)
461 if (state == _wmstate) return; // no change
465 // XXX: cause it to iconify
468 // XXX: cause it to uniconify
475 void OBClient::setDesktop(long target)
478 //assert(target == 0xffffffff || target < MAX);
480 // XXX: move the window to the new desktop
485 void OBClient::setState(StateAction action, long data1, long data2)
487 const otk::OBProperty *property = Openbox::instance->property();
489 if (!(action == State_Add || action == State_Remove ||
490 action == State_Toggle))
491 return; // an invalid action was passed to the client message, ignore it
493 for (int i = 0; i < 2; ++i) {
494 Atom state = i == 0 ? data1 : data2;
496 if (! state) continue;
498 // if toggling, then pick whether we're adding or removing
499 if (action == State_Toggle) {
500 if (state == property->atom(otk::OBProperty::net_wm_state_modal))
501 action = _modal ? State_Remove : State_Add;
503 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
504 action = _max_vert ? State_Remove : State_Add;
506 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
507 action = _max_horz ? State_Remove : State_Add;
508 else if (state == property->atom(otk::OBProperty::net_wm_state_shaded))
509 action = _shaded ? State_Remove : State_Add;
511 property->atom(otk::OBProperty::net_wm_state_fullscreen))
512 action = _fullscreen ? State_Remove : State_Add;
513 else if (state == property->atom(otk::OBProperty::net_wm_state_floating))
514 action = _floating ? State_Remove : State_Add;
517 if (action == State_Add) {
518 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
519 if (_modal) continue;
521 // XXX: give it focus if another window has focus that shouldnt now
523 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
524 if (_max_vert) continue;
526 // XXX: resize the window etc
528 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
529 if (_max_horz) continue;
531 // XXX: resize the window etc
533 property->atom(otk::OBProperty::net_wm_state_shaded)) {
534 if (_shaded) continue;
536 // XXX: hide the client window
538 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
539 if (_fullscreen) continue;
541 // XXX: raise the window n shit
543 property->atom(otk::OBProperty::net_wm_state_floating)) {
544 if (_floating) continue;
546 // XXX: raise the window n shit
549 } else { // action == State_Remove
550 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
551 if (!_modal) continue;
554 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
555 if (!_max_vert) continue;
557 // XXX: resize the window etc
559 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
560 if (!_max_horz) continue;
562 // XXX: resize the window etc
564 property->atom(otk::OBProperty::net_wm_state_shaded)) {
565 if (!_shaded) continue;
567 // XXX: show the client window
569 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
570 if (!_fullscreen) continue;
572 // XXX: lower the window to its proper layer
574 property->atom(otk::OBProperty::net_wm_state_floating)) {
575 if (!_floating) continue;
577 // XXX: lower the window to its proper layer
584 void OBClient::update(const XClientMessageEvent &e)
586 if (e.format != 32) return;
588 const otk::OBProperty *property = Openbox::instance->property();
590 if (e.message_type == property->atom(otk::OBProperty::wm_change_state))
591 setWMState(e.data.l[0]);
592 else if (e.message_type ==
593 property->atom(otk::OBProperty::net_wm_desktop))
594 setDesktop(e.data.l[0]);
595 else if (e.message_type == property->atom(otk::OBProperty::net_wm_state))
596 setState((StateAction)e.data.l[0], e.data.l[1], e.data.l[2]);
600 void OBClient::setArea(const otk::Rect &area)