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;
39 // XXX: updateTransientFor();
44 printf("Mapped window: 0x%lx\n"
45 " title: \t%s\t icon title: \t%s\n"
46 " app name: \t%s\t\t class: \t%s\n"
47 " position: \t%d, %d\t\t size: \t%d, %d\n"
48 " desktop: \t%lu\t\t group: \t0x%lx\n"
49 " type: \t%d\t\t min size \t%d, %d\n"
50 " base size \t%d, %d\t\t max size \t%d, %d\n"
51 " size incr \t%d, %d\t\t gravity \t%d\n"
52 " wm state \t%ld\t\t can be focused:\t%s\n"
53 " notify focus: \t%s\t\t urgent: \t%s\n"
54 " shaped: \t%s\t\t modal: \t%s\n"
55 " shaded: \t%s\t\t iconic: \t%s\n"
56 " vert maximized:\t%s\t\t horz maximized:\t%s\n"
57 " fullscreen: \t%s\t\t floating: \t%s\n",
64 _area.width(), _area.height(),
74 _can_focus ? "yes" : "no",
75 _focus_notify ? "yes" : "no",
76 _urgent ? "yes" : "no",
77 _shaped ? "yes" : "no",
78 _modal ? "yes" : "no",
79 _shaded ? "yes" : "no",
80 _iconic ? "yes" : "no",
81 _max_vert ? "yes" : "no",
82 _max_horz ? "yes" : "no",
83 _fullscreen ? "yes" : "no",
84 _floating ? "yes" : "no");
91 const otk::OBProperty *property = Openbox::instance->property();
93 // these values should not be persisted across a window unmapping/mapping
94 property->erase(_window, otk::OBProperty::net_wm_desktop);
95 property->erase(_window, otk::OBProperty::net_wm_state);
99 void OBClient::getDesktop()
101 const otk::OBProperty *property = Openbox::instance->property();
103 // defaults to the current desktop
104 _desktop = 0; // XXX: change this to the current desktop!
106 property->get(_window, otk::OBProperty::net_wm_desktop,
107 otk::OBProperty::Atom_Cardinal,
112 void OBClient::getType()
114 const otk::OBProperty *property = Openbox::instance->property();
116 _type = (WindowType) -1;
119 unsigned long num = (unsigned) -1;
120 if (property->get(_window, otk::OBProperty::net_wm_window_type,
121 otk::OBProperty::Atom_Atom,
123 // use the first value that we know about in the array
124 for (unsigned long i = 0; i < num; ++i) {
126 property->atom(otk::OBProperty::net_wm_window_type_desktop))
127 _type = Type_Desktop;
129 property->atom(otk::OBProperty::net_wm_window_type_dock))
132 property->atom(otk::OBProperty::net_wm_window_type_toolbar))
133 _type = Type_Toolbar;
135 property->atom(otk::OBProperty::net_wm_window_type_menu))
138 property->atom(otk::OBProperty::net_wm_window_type_utility))
139 _type = Type_Utility;
141 property->atom(otk::OBProperty::net_wm_window_type_splash))
144 property->atom(otk::OBProperty::net_wm_window_type_dialog))
147 property->atom(otk::OBProperty::net_wm_window_type_normal))
149 // else if (val[i] ==
150 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
151 // mwm_decorations = 0; // prevent this window from getting any decor
152 // XXX: make this work again
157 if (_type == (WindowType) -1) {
159 * the window type hint was not set, which means we either classify ourself
160 * as a normal window or a dialog, depending on if we are a transient.
162 // XXX: make this code work!
164 // _type = Type_Dialog;
171 void OBClient::getArea()
173 XWindowAttributes wattrib;
174 assert(XGetWindowAttributes(otk::OBDisplay::display, _window, &wattrib));
176 _area.setRect(wattrib.x, wattrib.y, wattrib.width, wattrib.height);
180 void OBClient::getState()
182 const otk::OBProperty *property = Openbox::instance->property();
184 _modal = _shaded = _max_horz = _max_vert = _fullscreen = _floating = false;
186 unsigned long *state;
187 unsigned long num = (unsigned) -1;
189 if (property->get(_window, otk::OBProperty::net_wm_state,
190 otk::OBProperty::Atom_Atom, &num, &state)) {
191 for (unsigned long i = 0; i < num; ++i) {
192 if (state[i] == property->atom(otk::OBProperty::net_wm_state_modal))
195 property->atom(otk::OBProperty::net_wm_state_shaded))
198 property->atom(otk::OBProperty::net_wm_state_fullscreen))
201 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
204 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
213 void OBClient::getShaped()
217 if (otk::OBDisplay::shape()) {
221 XShapeQueryExtents(otk::OBDisplay::display, client.window, &_shaped, &foo,
222 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo, &ufoo);
228 void OBClient::updateNormalHints()
234 _gravity = NorthWestGravity;
236 _base_x = _base_y = 0;
238 _max_x = _max_y = INT_MAX;
240 // get the hints from the window
241 if (XGetWMNormalHints(otk::OBDisplay::display, _window, &size, &ret)) {
242 if (size.flags & PWinGravity)
243 _gravity = size.win_gravity;
244 if (size.flags & PMinSize) {
245 _min_x = size.min_width;
246 _min_y = size.min_height;
248 if (size.flags & PMaxSize) {
249 _max_x = size.max_width;
250 _max_y = size.max_height;
252 if (size.flags & PBaseSize) {
253 _base_x = size.base_width;
254 _base_y = size.base_height;
256 if (size.flags & PResizeInc) {
257 _inc_x = size.width_inc;
258 _inc_y = size.height_inc;
264 void OBClient::updateWMHints()
268 // assume a window takes input if it doesnt specify
272 if ((hints = XGetWMHints(otk::OBDisplay::display, _window)) != NULL) {
273 if (hints->flags & InputHint)
274 _can_focus = hints->input;
276 if (hints->flags & XUrgencyHint)
279 if (hints->flags & WindowGroupHint) {
280 if (hints->window_group != _group) {
281 // XXX: remove from the old group if there was one
282 _group = hints->window_group;
283 // XXX: do stuff with the group
293 void OBClient::updateTitle()
295 const otk::OBProperty *property = Openbox::instance->property();
300 if (! property->get(_window, otk::OBProperty::net_wm_name,
301 otk::OBProperty::utf8, &_title)) {
303 property->get(_window, otk::OBProperty::wm_name,
304 otk::OBProperty::ascii, &_title);
308 _title = _("Unnamed Window");
312 void OBClient::updateClass()
314 const otk::OBProperty *property = Openbox::instance->property();
317 _app_name = _app_class = "";
319 otk::OBProperty::StringVect v;
320 unsigned long num = 2;
322 if (! property->get(_window, otk::OBProperty::wm_class,
323 otk::OBProperty::ascii, &num, &v))
326 if (num > 0) _app_name = v[0];
327 if (num > 1) _app_class = v[1];
331 void OBClient::update(const XPropertyEvent &e)
333 const otk::OBProperty *property = Openbox::instance->property();
335 if (e.atom == XA_WM_NORMAL_HINTS)
337 else if (e.atom == XA_WM_HINTS)
339 else if (e.atom == property->atom(otk::OBProperty::net_wm_name) ||
340 e.atom == property->atom(otk::OBProperty::wm_name) ||
341 e.atom == property->atom(otk::OBProperty::net_wm_icon_name) ||
342 e.atom == property->atom(otk::OBProperty::wm_icon_name))
344 else if (e.atom == property->atom(otk::OBProperty::wm_class))
346 // XXX: transient for hint
350 void OBClient::setWMState(long state)
352 if (state == _wmstate) return; // no change
356 // XXX: cause it to iconify
359 // XXX: cause it to uniconify
366 void OBClient::setDesktop(long target)
369 //assert(target == 0xffffffff || target < MAX);
371 // XXX: move the window to the new desktop
376 void OBClient::setState(StateAction action, long data1, long data2)
378 const otk::OBProperty *property = Openbox::instance->property();
380 if (!(action == State_Add || action == State_Remove ||
381 action == State_Toggle))
382 return; // an invalid action was passed to the client message, ignore it
384 for (int i = 0; i < 2; ++i) {
385 Atom state = i == 0 ? data1 : data2;
387 if (! state) continue;
389 // if toggling, then pick whether we're adding or removing
390 if (action == State_Toggle) {
391 if (state == property->atom(otk::OBProperty::net_wm_state_modal))
392 action = _modal ? State_Remove : State_Add;
394 property->atom(otk::OBProperty::net_wm_state_maximized_vert))
395 action = _max_vert ? State_Remove : State_Add;
397 property->atom(otk::OBProperty::net_wm_state_maximized_horz))
398 action = _max_horz ? State_Remove : State_Add;
399 else if (state == property->atom(otk::OBProperty::net_wm_state_shaded))
400 action = _shaded ? State_Remove : State_Add;
402 property->atom(otk::OBProperty::net_wm_state_fullscreen))
403 action = _fullscreen ? State_Remove : State_Add;
404 else if (state == property->atom(otk::OBProperty::net_wm_state_floating))
405 action = _floating ? State_Remove : State_Add;
408 if (action == State_Add) {
409 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
410 if (_modal) continue;
412 // XXX: give it focus if another window has focus that shouldnt now
414 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
415 if (_max_vert) continue;
417 // XXX: resize the window etc
419 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
420 if (_max_horz) continue;
422 // XXX: resize the window etc
424 property->atom(otk::OBProperty::net_wm_state_shaded)) {
425 if (_shaded) continue;
427 // XXX: hide the client window
429 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
430 if (_fullscreen) continue;
432 // XXX: raise the window n shit
434 property->atom(otk::OBProperty::net_wm_state_floating)) {
435 if (_floating) continue;
437 // XXX: raise the window n shit
440 } else { // action == State_Remove
441 if (state == property->atom(otk::OBProperty::net_wm_state_modal)) {
442 if (!_modal) continue;
445 property->atom(otk::OBProperty::net_wm_state_maximized_vert)){
446 if (!_max_vert) continue;
448 // XXX: resize the window etc
450 property->atom(otk::OBProperty::net_wm_state_maximized_horz)){
451 if (!_max_horz) continue;
453 // XXX: resize the window etc
455 property->atom(otk::OBProperty::net_wm_state_shaded)) {
456 if (!_shaded) continue;
458 // XXX: show the client window
460 property->atom(otk::OBProperty::net_wm_state_fullscreen)) {
461 if (!_fullscreen) continue;
463 // XXX: lower the window to its proper layer
465 property->atom(otk::OBProperty::net_wm_state_floating)) {
466 if (!_floating) continue;
468 // XXX: lower the window to its proper layer
475 void OBClient::update(const XClientMessageEvent &e)
477 if (e.format != 32) return;
479 const otk::OBProperty *property = Openbox::instance->property();
481 if (e.message_type == property->atom(otk::OBProperty::wm_change_state))
482 setWMState(e.data.l[0]);
483 else if (e.message_type ==
484 property->atom(otk::OBProperty::net_wm_desktop))
485 setDesktop(e.data.l[0]);
486 else if (e.message_type == property->atom(otk::OBProperty::net_wm_state))
487 setState((StateAction)e.data.l[0], e.data.l[1], e.data.l[2]);
491 void OBClient::setArea(const otk::Rect &area)