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"
58 " requested pos: \t%s\n",
65 _area
.width(), _area
.height(),
75 _can_focus
? "yes" : "no",
76 _focus_notify
? "yes" : "no",
77 _urgent
? "yes" : "no",
78 _shaped
? "yes" : "no",
79 _modal
? "yes" : "no",
80 _shaded
? "yes" : "no",
81 _iconic
? "yes" : "no",
82 _max_vert
? "yes" : "no",
83 _max_horz
? "yes" : "no",
84 _fullscreen
? "yes" : "no",
85 _floating
? "yes" : "no",
86 _positioned
? "yes" : "no");
93 const otk::OBProperty
*property
= Openbox::instance
->property();
95 // these values should not be persisted across a window unmapping/mapping
96 property
->erase(_window
, otk::OBProperty::net_wm_desktop
);
97 property
->erase(_window
, otk::OBProperty::net_wm_state
);
101 void OBClient::getDesktop()
103 const otk::OBProperty
*property
= Openbox::instance
->property();
105 // defaults to the current desktop
106 _desktop
= 0; // XXX: change this to the current desktop!
108 property
->get(_window
, otk::OBProperty::net_wm_desktop
,
109 otk::OBProperty::Atom_Cardinal
,
114 void OBClient::getType()
116 const otk::OBProperty
*property
= Openbox::instance
->property();
118 _type
= (WindowType
) -1;
121 unsigned long num
= (unsigned) -1;
122 if (property
->get(_window
, otk::OBProperty::net_wm_window_type
,
123 otk::OBProperty::Atom_Atom
,
125 // use the first value that we know about in the array
126 for (unsigned long i
= 0; i
< num
; ++i
) {
128 property
->atom(otk::OBProperty::net_wm_window_type_desktop
))
129 _type
= Type_Desktop
;
131 property
->atom(otk::OBProperty::net_wm_window_type_dock
))
134 property
->atom(otk::OBProperty::net_wm_window_type_toolbar
))
135 _type
= Type_Toolbar
;
137 property
->atom(otk::OBProperty::net_wm_window_type_menu
))
140 property
->atom(otk::OBProperty::net_wm_window_type_utility
))
141 _type
= Type_Utility
;
143 property
->atom(otk::OBProperty::net_wm_window_type_splash
))
146 property
->atom(otk::OBProperty::net_wm_window_type_dialog
))
149 property
->atom(otk::OBProperty::net_wm_window_type_normal
))
151 // else if (val[i] ==
152 // property->atom(otk::OBProperty::kde_net_wm_window_type_override))
153 // mwm_decorations = 0; // prevent this window from getting any decor
154 // XXX: make this work again
159 if (_type
== (WindowType
) -1) {
161 * the window type hint was not set, which means we either classify ourself
162 * as a normal window or a dialog, depending on if we are a transient.
164 // XXX: make this code work!
166 // _type = Type_Dialog;
173 void OBClient::getArea()
175 XWindowAttributes wattrib
;
176 assert(XGetWindowAttributes(otk::OBDisplay::display
, _window
, &wattrib
));
178 _area
.setRect(wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
182 void OBClient::getState()
184 const otk::OBProperty
*property
= Openbox::instance
->property();
186 _modal
= _shaded
= _max_horz
= _max_vert
= _fullscreen
= _floating
= false;
188 unsigned long *state
;
189 unsigned long num
= (unsigned) -1;
191 if (property
->get(_window
, otk::OBProperty::net_wm_state
,
192 otk::OBProperty::Atom_Atom
, &num
, &state
)) {
193 for (unsigned long i
= 0; i
< num
; ++i
) {
194 if (state
[i
] == property
->atom(otk::OBProperty::net_wm_state_modal
))
197 property
->atom(otk::OBProperty::net_wm_state_shaded
))
200 property
->atom(otk::OBProperty::net_wm_state_fullscreen
))
203 property
->atom(otk::OBProperty::net_wm_state_maximized_vert
))
206 property
->atom(otk::OBProperty::net_wm_state_maximized_horz
))
215 void OBClient::getShaped()
219 if (otk::OBDisplay::shape()) {
223 XShapeQueryExtents(otk::OBDisplay::display
, client
.window
, &_shaped
, &foo
,
224 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
, &ufoo
);
230 void OBClient::updateNormalHints()
236 _gravity
= NorthWestGravity
;
238 _base_x
= _base_y
= 0;
240 _max_x
= _max_y
= INT_MAX
;
242 // get the hints from the window
243 if (XGetWMNormalHints(otk::OBDisplay::display
, _window
, &size
, &ret
)) {
244 _positioned
= (size
.flags
& (PPosition
|USPosition
));
246 if (size
.flags
& PWinGravity
)
247 _gravity
= size
.win_gravity
;
249 if (size
.flags
& PMinSize
) {
250 _min_x
= size
.min_width
;
251 _min_y
= size
.min_height
;
254 if (size
.flags
& PMaxSize
) {
255 _max_x
= size
.max_width
;
256 _max_y
= size
.max_height
;
259 if (size
.flags
& PBaseSize
) {
260 _base_x
= size
.base_width
;
261 _base_y
= size
.base_height
;
264 if (size
.flags
& PResizeInc
) {
265 _inc_x
= size
.width_inc
;
266 _inc_y
= size
.height_inc
;
272 void OBClient::updateWMHints()
276 // assume a window takes input if it doesnt specify
280 if ((hints
= XGetWMHints(otk::OBDisplay::display
, _window
)) != NULL
) {
281 if (hints
->flags
& InputHint
)
282 _can_focus
= hints
->input
;
284 if (hints
->flags
& XUrgencyHint
)
287 if (hints
->flags
& WindowGroupHint
) {
288 if (hints
->window_group
!= _group
) {
289 // XXX: remove from the old group if there was one
290 _group
= hints
->window_group
;
291 // XXX: do stuff with the group
301 void OBClient::updateTitle()
303 const otk::OBProperty
*property
= Openbox::instance
->property();
308 if (! property
->get(_window
, otk::OBProperty::net_wm_name
,
309 otk::OBProperty::utf8
, &_title
)) {
311 property
->get(_window
, otk::OBProperty::wm_name
,
312 otk::OBProperty::ascii
, &_title
);
316 _title
= _("Unnamed Window");
320 void OBClient::updateClass()
322 const otk::OBProperty
*property
= Openbox::instance
->property();
325 _app_name
= _app_class
= "";
327 otk::OBProperty::StringVect v
;
328 unsigned long num
= 2;
330 if (! property
->get(_window
, otk::OBProperty::wm_class
,
331 otk::OBProperty::ascii
, &num
, &v
))
334 if (num
> 0) _app_name
= v
[0];
335 if (num
> 1) _app_class
= v
[1];
339 void OBClient::update(const XPropertyEvent
&e
)
341 const otk::OBProperty
*property
= Openbox::instance
->property();
343 if (e
.atom
== XA_WM_NORMAL_HINTS
)
345 else if (e
.atom
== XA_WM_HINTS
)
347 else if (e
.atom
== property
->atom(otk::OBProperty::net_wm_name
) ||
348 e
.atom
== property
->atom(otk::OBProperty::wm_name
) ||
349 e
.atom
== property
->atom(otk::OBProperty::net_wm_icon_name
) ||
350 e
.atom
== property
->atom(otk::OBProperty::wm_icon_name
))
352 else if (e
.atom
== property
->atom(otk::OBProperty::wm_class
))
354 // XXX: transient for hint
358 void OBClient::setWMState(long state
)
360 if (state
== _wmstate
) return; // no change
364 // XXX: cause it to iconify
367 // XXX: cause it to uniconify
374 void OBClient::setDesktop(long target
)
377 //assert(target == 0xffffffff || target < MAX);
379 // XXX: move the window to the new desktop
384 void OBClient::setState(StateAction action
, long data1
, long data2
)
386 const otk::OBProperty
*property
= Openbox::instance
->property();
388 if (!(action
== State_Add
|| action
== State_Remove
||
389 action
== State_Toggle
))
390 return; // an invalid action was passed to the client message, ignore it
392 for (int i
= 0; i
< 2; ++i
) {
393 Atom state
= i
== 0 ? data1
: data2
;
395 if (! state
) continue;
397 // if toggling, then pick whether we're adding or removing
398 if (action
== State_Toggle
) {
399 if (state
== property
->atom(otk::OBProperty::net_wm_state_modal
))
400 action
= _modal
? State_Remove
: State_Add
;
402 property
->atom(otk::OBProperty::net_wm_state_maximized_vert
))
403 action
= _max_vert
? State_Remove
: State_Add
;
405 property
->atom(otk::OBProperty::net_wm_state_maximized_horz
))
406 action
= _max_horz
? State_Remove
: State_Add
;
407 else if (state
== property
->atom(otk::OBProperty::net_wm_state_shaded
))
408 action
= _shaded
? State_Remove
: State_Add
;
410 property
->atom(otk::OBProperty::net_wm_state_fullscreen
))
411 action
= _fullscreen
? State_Remove
: State_Add
;
412 else if (state
== property
->atom(otk::OBProperty::net_wm_state_floating
))
413 action
= _floating
? State_Remove
: State_Add
;
416 if (action
== State_Add
) {
417 if (state
== property
->atom(otk::OBProperty::net_wm_state_modal
)) {
418 if (_modal
) continue;
420 // XXX: give it focus if another window has focus that shouldnt now
422 property
->atom(otk::OBProperty::net_wm_state_maximized_vert
)){
423 if (_max_vert
) continue;
425 // XXX: resize the window etc
427 property
->atom(otk::OBProperty::net_wm_state_maximized_horz
)){
428 if (_max_horz
) continue;
430 // XXX: resize the window etc
432 property
->atom(otk::OBProperty::net_wm_state_shaded
)) {
433 if (_shaded
) continue;
435 // XXX: hide the client window
437 property
->atom(otk::OBProperty::net_wm_state_fullscreen
)) {
438 if (_fullscreen
) continue;
440 // XXX: raise the window n shit
442 property
->atom(otk::OBProperty::net_wm_state_floating
)) {
443 if (_floating
) continue;
445 // XXX: raise the window n shit
448 } else { // action == State_Remove
449 if (state
== property
->atom(otk::OBProperty::net_wm_state_modal
)) {
450 if (!_modal
) continue;
453 property
->atom(otk::OBProperty::net_wm_state_maximized_vert
)){
454 if (!_max_vert
) continue;
456 // XXX: resize the window etc
458 property
->atom(otk::OBProperty::net_wm_state_maximized_horz
)){
459 if (!_max_horz
) continue;
461 // XXX: resize the window etc
463 property
->atom(otk::OBProperty::net_wm_state_shaded
)) {
464 if (!_shaded
) continue;
466 // XXX: show the client window
468 property
->atom(otk::OBProperty::net_wm_state_fullscreen
)) {
469 if (!_fullscreen
) continue;
471 // XXX: lower the window to its proper layer
473 property
->atom(otk::OBProperty::net_wm_state_floating
)) {
474 if (!_floating
) continue;
476 // XXX: lower the window to its proper layer
483 void OBClient::update(const XClientMessageEvent
&e
)
485 if (e
.format
!= 32) return;
487 const otk::OBProperty
*property
= Openbox::instance
->property();
489 if (e
.message_type
== property
->atom(otk::OBProperty::wm_change_state
))
490 setWMState(e
.data
.l
[0]);
491 else if (e
.message_type
==
492 property
->atom(otk::OBProperty::net_wm_desktop
))
493 setDesktop(e
.data
.l
[0]);
494 else if (e
.message_type
== property
->atom(otk::OBProperty::net_wm_state
))
495 setState((StateAction
)e
.data
.l
[0], e
.data
.l
[1], e
.data
.l
[2]);
499 void OBClient::setArea(const otk::Rect
&area
)