1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
10 #include "otk/display.hh"
11 #include "otk/property.hh"
15 #include <X11/Xutil.h>
16 #include <X11/Xatom.h>
19 #define _(str) gettext(str)
22 #include <cstring> // for memcpy
29 Client::Client(int screen
, Window window
)
30 : otk::EventHandler(),
31 frame(0), _screen(screen
), _window(window
)
38 // update EVERYTHING the first time!!
41 _wmstate
= NormalState
;
44 _layer
= Layer_Normal
;
47 _disabled_decorations
= 0;
54 getState(); // do this before updateTransientFor! (for _modal)
59 getType(); // this can change the mwmhints for special cases
63 getGravity(); // get the attribute gravity
64 updateNormalHints(); // this may override the attribute gravity
66 // got the type, the mwmhints, the protocols, and the normal hints (min/max
67 // sizes), so we're ready to set up
68 // the decorations/functions
69 setupDecorAndFunctions();
71 // also get the initial_state and set _iconic if we aren't "starting"
72 // when we're "starting" that means we should use whatever state was already
73 // on the window over the initial map state, because it was already mapped
74 updateWMHints(openbox
->state() != Openbox::State_Starting
);
81 // this makes sure that these windows appear on all desktops
82 if (/*_type == Type_Dock ||*/ _type
== Type_Desktop
)
83 _desktop
= 0xffffffff;
85 // set the desktop hint, to make sure that it always exists, and to reflect
86 // any changes we've made here
87 otk::Property::set(_window
, otk::Property::atoms
.net_wm_desktop
,
88 otk::Property::atoms
.cardinal
, (unsigned)_desktop
);
95 assert(_nicons
> 0); // there should always be a default..
96 for (int j
= 0; j
< _nicons
; ++j
)
97 delete [] _icons
[j
].data
;
100 // clean up childrens' references
101 while (!_transients
.empty()) {
102 _transients
.front()->_transient_for
= 0;
103 _transients
.pop_front();
106 // clean up parents reference to this
108 _transient_for
->_transients
.remove(this); // remove from old parent
110 if (openbox
->state() != Openbox::State_Exiting
) {
111 // these values should not be persisted across a window unmapping/mapping
112 otk::Property::erase(_window
, otk::Property::atoms
.net_wm_desktop
);
113 otk::Property::erase(_window
, otk::Property::atoms
.net_wm_state
);
115 // if we're left in an iconic state, the client wont be mapped. this is
116 // bad, since we will no longer be managing the window on restart
118 XMapWindow(**otk::display
, _window
);
123 bool Client::validate() const
125 XSync(**otk::display
, false); // get all events on the server
128 if (XCheckTypedWindowEvent(**otk::display
, _window
, DestroyNotify
, &e
) ||
129 XCheckTypedWindowEvent(**otk::display
, _window
, UnmapNotify
, &e
)) {
130 XPutBackEvent(**otk::display
, &e
);
138 void Client::getGravity()
140 XWindowAttributes wattrib
;
143 ret
= XGetWindowAttributes(**otk::display
, _window
, &wattrib
);
144 assert(ret
!= BadWindow
);
145 _gravity
= wattrib
.win_gravity
;
149 void Client::getDesktop()
151 // defaults to the current desktop
152 _desktop
= openbox
->screen(_screen
)->desktop();
154 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_desktop
,
155 otk::Property::atoms
.cardinal
,
156 (long unsigned*)&_desktop
)) {
158 // printf("Window requested desktop: %ld\n", _desktop);
164 void Client::getType()
166 _type
= (WindowType
) -1;
169 unsigned long num
= (unsigned) -1;
170 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_window_type
,
171 otk::Property::atoms
.atom
, &num
, &val
)) {
172 // use the first value that we know about in the array
173 for (unsigned long i
= 0; i
< num
; ++i
) {
174 if (val
[i
] == otk::Property::atoms
.net_wm_window_type_desktop
)
175 _type
= Type_Desktop
;
176 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_dock
)
178 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_toolbar
)
179 _type
= Type_Toolbar
;
180 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_menu
)
182 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_utility
)
183 _type
= Type_Utility
;
184 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_splash
)
186 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_dialog
)
188 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_normal
)
190 else if (val
[i
] == otk::Property::atoms
.kde_net_wm_window_type_override
){
191 // prevent this window from getting any decor or functionality
192 _mwmhints
.flags
&= MwmFlag_Functions
| MwmFlag_Decorations
;
193 _mwmhints
.decorations
= 0;
194 _mwmhints
.functions
= 0;
196 if (_type
!= (WindowType
) -1)
197 break; // grab the first known type
202 if (_type
== (WindowType
) -1) {
204 * the window type hint was not set, which means we either classify ourself
205 * as a normal window or a dialog, depending on if we are a transient.
215 void Client::setupDecorAndFunctions()
217 // start with everything (cept fullscreen)
218 _decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
| Decor_Icon
|
219 Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
220 _functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
222 if (_delete_window
) {
223 _decorations
|= Decor_Close
;
224 _functions
|= Func_Close
;
227 if (!(_min_size
.width() < _max_size
.width() ||
228 _min_size
.height() < _max_size
.height())) {
229 _decorations
&= ~(Decor_Maximize
| Decor_Handle
);
230 _functions
&= ~(Func_Resize
| Func_Maximize
);
235 // normal windows retain all of the possible decorations and
236 // functionality, and are the only windows that you can fullscreen
237 _functions
|= Func_Fullscreen
;
241 // dialogs cannot be maximized
242 _decorations
&= ~Decor_Maximize
;
243 _functions
&= ~Func_Maximize
;
249 // these windows get less functionality
250 _decorations
&= ~(Decor_Iconify
| Decor_Handle
);
251 _functions
&= ~(Func_Iconify
| Func_Resize
);
257 // none of these windows are manipulated by the window manager
263 // Mwm Hints are applied subtractively to what has already been chosen for
264 // decor and functionality
265 if (_mwmhints
.flags
& MwmFlag_Decorations
) {
266 if (! (_mwmhints
.decorations
& MwmDecor_All
)) {
267 if (! (_mwmhints
.decorations
& MwmDecor_Border
))
268 _decorations
&= ~Decor_Border
;
269 if (! (_mwmhints
.decorations
& MwmDecor_Handle
))
270 _decorations
&= ~Decor_Handle
;
271 if (! (_mwmhints
.decorations
& MwmDecor_Title
))
272 _decorations
&= ~Decor_Titlebar
;
273 if (! (_mwmhints
.decorations
& MwmDecor_Iconify
))
274 _decorations
&= ~Decor_Iconify
;
275 if (! (_mwmhints
.decorations
& MwmDecor_Maximize
))
276 _decorations
&= ~Decor_Maximize
;
280 if (_mwmhints
.flags
& MwmFlag_Functions
) {
281 if (! (_mwmhints
.functions
& MwmFunc_All
)) {
282 if (! (_mwmhints
.functions
& MwmFunc_Resize
))
283 _functions
&= ~Func_Resize
;
284 if (! (_mwmhints
.functions
& MwmFunc_Move
))
285 _functions
&= ~Func_Move
;
286 if (! (_mwmhints
.functions
& MwmFunc_Iconify
))
287 _functions
&= ~Func_Iconify
;
288 if (! (_mwmhints
.functions
& MwmFunc_Maximize
))
289 _functions
&= ~Func_Maximize
;
290 // dont let mwm hints kill the close button
291 //if (! (_mwmhints.functions & MwmFunc_Close))
292 // _functions &= ~Func_Close;
296 // can't maximize without moving/resizing
297 if (!((_functions
& Func_Move
) && (_functions
& Func_Resize
)))
298 _functions
&= ~Func_Maximize
;
300 // finally, user specified disabled decorations are applied to subtract
302 if (_disabled_decorations
& Decor_Titlebar
)
303 _decorations
&= ~Decor_Titlebar
;
304 if (_disabled_decorations
& Decor_Handle
)
305 _decorations
&= ~Decor_Handle
;
306 if (_disabled_decorations
& Decor_Border
)
307 _decorations
&= ~Decor_Border
;
308 if (_disabled_decorations
& Decor_Iconify
)
309 _decorations
&= ~Decor_Iconify
;
310 if (_disabled_decorations
& Decor_Maximize
)
311 _decorations
&= ~Decor_Maximize
;
312 if (_disabled_decorations
& Decor_AllDesktops
)
313 _decorations
&= ~Decor_AllDesktops
;
314 if (_disabled_decorations
& Decor_Close
)
315 _decorations
&= ~Decor_Close
;
317 // if we don't have a titlebar, then we cannot shade!
318 if (!(_decorations
& Decor_Titlebar
))
319 _functions
&= ~Func_Shade
;
321 changeAllowedActions();
324 frame
->adjustSize(); // change the decors on the frame
325 frame
->adjustPosition(); // with more/less decorations, we may need to be
327 remaximize(); // with new decor, the window's maximized size may change
332 void Client::getMwmHints()
334 unsigned long num
= MwmHints::elements
;
335 unsigned long *hints
;
337 _mwmhints
.flags
= 0; // default to none
339 if (!otk::Property::get(_window
, otk::Property::atoms
.motif_wm_hints
,
340 otk::Property::atoms
.motif_wm_hints
, &num
,
341 (unsigned long **)&hints
))
344 if (num
>= MwmHints::elements
) {
345 // retrieved the hints
346 _mwmhints
.flags
= hints
[0];
347 _mwmhints
.functions
= hints
[1];
348 _mwmhints
.decorations
= hints
[2];
355 void Client::getArea()
357 XWindowAttributes wattrib
;
360 ret
= XGetWindowAttributes(**otk::display
, _window
, &wattrib
);
361 assert(ret
!= BadWindow
);
363 _area
= otk::Rect(wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
364 _border_width
= wattrib
.border_width
;
368 void Client::getState()
370 _modal
= _shaded
= _max_horz
= _max_vert
= _fullscreen
= _above
= _below
=
371 _iconic
= _skip_taskbar
= _skip_pager
= false;
373 unsigned long *state
;
374 unsigned long num
= (unsigned) -1;
376 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_state
,
377 otk::Property::atoms
.atom
, &num
, &state
)) {
378 for (unsigned long i
= 0; i
< num
; ++i
) {
379 if (state
[i
] == otk::Property::atoms
.net_wm_state_modal
)
381 else if (state
[i
] == otk::Property::atoms
.net_wm_state_shaded
)
383 else if (state
[i
] == otk::Property::atoms
.net_wm_state_hidden
)
385 else if (state
[i
] == otk::Property::atoms
.net_wm_state_skip_taskbar
)
386 _skip_taskbar
= true;
387 else if (state
[i
] == otk::Property::atoms
.net_wm_state_skip_pager
)
389 else if (state
[i
] == otk::Property::atoms
.net_wm_state_fullscreen
)
391 else if (state
[i
] == otk::Property::atoms
.net_wm_state_maximized_vert
)
393 else if (state
[i
] == otk::Property::atoms
.net_wm_state_maximized_horz
)
395 else if (state
[i
] == otk::Property::atoms
.net_wm_state_above
)
397 else if (state
[i
] == otk::Property::atoms
.net_wm_state_below
)
406 void Client::getShaped()
410 if (otk::display
->shape()) {
415 XShapeSelectInput(**otk::display
, _window
, ShapeNotifyMask
);
417 XShapeQueryExtents(**otk::display
, _window
, &s
, &foo
,
418 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
, &ufoo
);
425 void Client::calcLayer() {
428 if (_iconic
) l
= Layer_Icon
;
429 else if (_fullscreen
) l
= Layer_Fullscreen
;
430 else if (_type
== Type_Desktop
) l
= Layer_Desktop
;
431 else if (_type
== Type_Dock
) {
432 if (!_below
) l
= Layer_Top
;
433 else l
= Layer_Normal
;
435 else if (_above
) l
= Layer_Above
;
436 else if (_below
) l
= Layer_Below
;
437 else l
= Layer_Normal
;
443 if we don't have a frame, then we aren't mapped yet (and this would
446 openbox
->screen(_screen
)->raiseWindow(this);
452 void Client::updateProtocols()
457 _focus_notify
= false;
458 _delete_window
= false;
460 if (XGetWMProtocols(**otk::display
, _window
, &proto
, &num_return
)) {
461 for (int i
= 0; i
< num_return
; ++i
) {
462 if (proto
[i
] == otk::Property::atoms
.wm_delete_window
) {
463 // this means we can request the window to close
464 _delete_window
= true;
465 } else if (proto
[i
] == otk::Property::atoms
.wm_take_focus
)
466 // if this protocol is requested, then the window will be notified
467 // by the window manager whenever it receives focus
468 _focus_notify
= true;
475 void Client::updateNormalHints()
479 int oldgravity
= _gravity
;
484 _size_inc
= otk::Size(1, 1);
485 _base_size
= otk::Size(0, 0);
486 _min_size
= otk::Size(0, 0);
487 _max_size
= otk::Size(INT_MAX
, INT_MAX
);
489 // get the hints from the window
490 if (XGetWMNormalHints(**otk::display
, _window
, &size
, &ret
)) {
491 _positioned
= (size
.flags
& (PPosition
|USPosition
));
493 if (size
.flags
& PWinGravity
) {
494 _gravity
= size
.win_gravity
;
496 // if the client has a frame, i.e. has already been mapped and is
497 // changing its gravity
498 if (frame
&& _gravity
!= oldgravity
) {
499 // move our idea of the client's position based on its new gravity
500 int x
= frame
->area().x(), y
= frame
->area().y();
501 frame
->frameGravity(x
, y
);
502 _area
= otk::Rect(otk::Point(x
, y
), _area
.size());
506 if (size
.flags
& PAspect
) {
507 if (size
.min_aspect
.y
) _min_ratio
= size
.min_aspect
.x
/size
.min_aspect
.y
;
508 if (size
.max_aspect
.y
) _max_ratio
= size
.max_aspect
.x
/size
.max_aspect
.y
;
511 if (size
.flags
& PMinSize
)
512 _min_size
= otk::Size(size
.min_width
, size
.min_height
);
514 if (size
.flags
& PMaxSize
)
515 _max_size
= otk::Size(size
.max_width
, size
.max_height
);
517 if (size
.flags
& PBaseSize
)
518 _base_size
= otk::Size(size
.base_width
, size
.base_height
);
520 if (size
.flags
& PResizeInc
)
521 _size_inc
= otk::Size(size
.width_inc
, size
.height_inc
);
526 void Client::updateWMHints(bool initstate
)
530 // assume a window takes input if it doesnt specify
534 if ((hints
= XGetWMHints(**otk::display
, _window
)) != NULL
) {
535 if (hints
->flags
& InputHint
)
536 _can_focus
= hints
->input
;
538 // only do this when initstate is true!
539 if (initstate
&& (hints
->flags
& StateHint
))
540 _iconic
= hints
->initial_state
== IconicState
;
542 if (hints
->flags
& XUrgencyHint
)
545 if (hints
->flags
& WindowGroupHint
) {
546 if (hints
->window_group
!= _group
) {
547 // XXX: remove from the old group if there was one
548 _group
= hints
->window_group
;
549 // XXX: do stuff with the group
560 printf("DEBUG: Urgent Hint for 0x%lx: %s\n",
561 (long)_window
, _urgent
? "ON" : "OFF");
563 // fire the urgent callback if we're mapped, otherwise, wait until after
571 void Client::updateTitle()
576 if (!otk::Property::get(_window
, otk::Property::atoms
.net_wm_name
,
577 otk::Property::utf8
, &_title
)) {
579 otk::Property::get(_window
, otk::Property::atoms
.wm_name
,
580 otk::Property::ascii
, &_title
);
584 _title
= _("Unnamed Window");
587 frame
->adjustTitle();
591 void Client::updateIconTitle()
596 if (!otk::Property::get(_window
, otk::Property::atoms
.net_wm_icon_name
,
597 otk::Property::utf8
, &_icon_title
)) {
599 otk::Property::get(_window
, otk::Property::atoms
.wm_icon_name
,
600 otk::Property::ascii
, &_icon_title
);
604 _icon_title
= _("Unnamed Window");
608 void Client::updateClass()
611 _app_name
= _app_class
= _role
= "";
613 otk::Property::StringVect v
;
614 unsigned long num
= 2;
616 if (otk::Property::get(_window
, otk::Property::atoms
.wm_class
,
617 otk::Property::ascii
, &num
, &v
)) {
618 if (num
> 0) _app_name
= v
[0].c_str();
619 if (num
> 1) _app_class
= v
[1].c_str();
624 if (otk::Property::get(_window
, otk::Property::atoms
.wm_window_role
,
625 otk::Property::ascii
, &num
, &v
)) {
626 if (num
> 0) _role
= v
[0].c_str();
631 void Client::updateStrut()
633 unsigned long num
= 4;
635 if (!otk::Property::get(_window
, otk::Property::atoms
.net_wm_strut
,
636 otk::Property::atoms
.cardinal
, &num
, &data
))
640 _strut
.left
= data
[0];
641 _strut
.right
= data
[1];
642 _strut
.top
= data
[2];
643 _strut
.bottom
= data
[3];
645 // updating here is pointless while we're being mapped cuz we're not in
646 // the screen's client list yet
648 openbox
->screen(_screen
)->updateStruts();
655 void Client::updateTransientFor()
660 if (XGetTransientForHint(**otk::display
, _window
, &t
) &&
661 t
!= _window
) { // cant be transient to itself!
662 c
= openbox
->findClient(t
);
663 assert(c
!= this); // if this happens then we need to check for it
665 if (!c
/*XXX: && _group*/) {
666 // not transient to a client, see if it is transient for a group
667 if (//t == _group->leader() ||
669 t
== otk::display
->screenInfo(_screen
)->rootWindow()) {
670 // window is a transient for its group!
671 // XXX: for now this is treated as non-transient.
672 // this needs to be fixed!
677 // if anything has changed...
678 if (c
!= _transient_for
) {
680 _transient_for
->_transients
.remove(this); // remove from old parent
683 _transient_for
->_transients
.push_back(this); // add to new parent
688 void Client::updateIcons()
690 unsigned long num
= (unsigned) -1;
692 unsigned long w
, h
, i
= 0;
694 for (int j
= 0; j
< _nicons
; ++j
)
695 delete [] _icons
[j
].data
;
700 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_icon
,
701 otk::Property::atoms
.cardinal
, &num
, &data
)) {
702 // figure out how man valid icons are in here
703 while (num
- i
> 2) {
711 _icons
= new Icon
[_nicons
];
715 for (int j
= 0; j
< _nicons
; ++j
) {
716 w
= _icons
[j
].w
= data
[i
++];
717 h
= _icons
[j
].h
= data
[i
++];
718 _icons
[j
].data
= new unsigned long[w
* h
];
719 ::memcpy(_icons
[j
].data
, &data
[i
], w
* h
* sizeof(unsigned long));
723 printf("i: %lu\n", i
);
724 printf("bleffffffff\n");
730 // set the default icon(s) XXX load these from the py
732 _icons
= new Icon
[1];
738 assert(_nicons
> 0); // there should always be a default..
740 if (frame
) frame
->adjustIcon();
744 void Client::propertyHandler(const XPropertyEvent
&e
)
746 otk::EventHandler::propertyHandler(e
);
748 // validate cuz we query stuff off the client here
749 if (!validate()) return;
751 // compress changes to a single property into a single change
753 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
754 // XXX: it would be nice to compress ALL changes to a property, not just
755 // changes in a row without other props between.
756 if (ce
.xproperty
.atom
!= e
.atom
) {
757 XPutBackEvent(**otk::display
, &ce
);
762 if (e
.atom
== XA_WM_NORMAL_HINTS
) {
764 setupDecorAndFunctions(); // normal hints can make a window non-resizable
765 } else if (e
.atom
== XA_WM_HINTS
)
767 else if (e
.atom
== XA_WM_TRANSIENT_FOR
) {
768 updateTransientFor();
770 calcLayer(); // type may have changed, so update the layer
771 setupDecorAndFunctions();
773 else if (e
.atom
== otk::Property::atoms
.net_wm_name
||
774 e
.atom
== otk::Property::atoms
.wm_name
)
776 else if (e
.atom
== otk::Property::atoms
.net_wm_icon_name
||
777 e
.atom
== otk::Property::atoms
.wm_icon_name
)
779 else if (e
.atom
== otk::Property::atoms
.wm_class
)
781 else if (e
.atom
== otk::Property::atoms
.wm_protocols
) {
783 setupDecorAndFunctions();
785 else if (e
.atom
== otk::Property::atoms
.net_wm_strut
)
787 else if (e
.atom
== otk::Property::atoms
.net_wm_icon
)
792 void Client::setWMState(long state
)
794 if (state
== _wmstate
) return; // no change
807 void Client::setDesktop(unsigned int target
)
809 if (target
== _desktop
) return;
811 printf("Setting desktop %u\n", target
);
813 if (!(target
< openbox
->screen(_screen
)->numDesktops() ||
814 target
== 0xffffffff))
818 // set the desktop hint
819 otk::Property::set(_window
, otk::Property::atoms
.net_wm_desktop
,
820 otk::Property::atoms
.cardinal
, _desktop
);
821 frame
->adjustState(); // the frame can display the current desktop state
822 // 'move' the window to the new desktop
824 openbox
->screen(_screen
)->updateStruts();
828 void Client::showhide()
831 Screen
*s
= openbox
->screen(_screen
);
833 if (_iconic
) show
= false;
834 else if (!(_desktop
== s
->desktop() ||
835 _desktop
== 0xffffffff)) show
= false;
836 else if (normal() && s
->showingDesktop()) show
= false;
839 if (show
) frame
->show();
844 void Client::setState(StateAction action
, long data1
, long data2
)
846 bool shadestate
= _shaded
;
847 bool fsstate
= _fullscreen
;
848 bool maxh
= _max_horz
;
849 bool maxv
= _max_vert
;
851 if (!(action
== State_Add
|| action
== State_Remove
||
852 action
== State_Toggle
))
853 return; // an invalid action was passed to the client message, ignore it
855 for (int i
= 0; i
< 2; ++i
) {
856 Atom state
= i
== 0 ? data1
: data2
;
858 if (! state
) continue;
860 // if toggling, then pick whether we're adding or removing
861 if (action
== State_Toggle
) {
862 if (state
== otk::Property::atoms
.net_wm_state_modal
)
863 action
= _modal
? State_Remove
: State_Add
;
864 else if (state
== otk::Property::atoms
.net_wm_state_maximized_vert
)
865 action
= _max_vert
? State_Remove
: State_Add
;
866 else if (state
== otk::Property::atoms
.net_wm_state_maximized_horz
)
867 action
= _max_horz
? State_Remove
: State_Add
;
868 else if (state
== otk::Property::atoms
.net_wm_state_shaded
)
869 action
= _shaded
? State_Remove
: State_Add
;
870 else if (state
== otk::Property::atoms
.net_wm_state_skip_taskbar
)
871 action
= _skip_taskbar
? State_Remove
: State_Add
;
872 else if (state
== otk::Property::atoms
.net_wm_state_skip_pager
)
873 action
= _skip_pager
? State_Remove
: State_Add
;
874 else if (state
== otk::Property::atoms
.net_wm_state_fullscreen
)
875 action
= _fullscreen
? State_Remove
: State_Add
;
876 else if (state
== otk::Property::atoms
.net_wm_state_above
)
877 action
= _above
? State_Remove
: State_Add
;
878 else if (state
== otk::Property::atoms
.net_wm_state_below
)
879 action
= _below
? State_Remove
: State_Add
;
882 if (action
== State_Add
) {
883 if (state
== otk::Property::atoms
.net_wm_state_modal
) {
884 if (_modal
) continue;
886 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_vert
) {
888 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_horz
) {
889 if (_max_horz
) continue;
891 } else if (state
== otk::Property::atoms
.net_wm_state_shaded
) {
893 } else if (state
== otk::Property::atoms
.net_wm_state_skip_taskbar
) {
894 _skip_taskbar
= true;
895 } else if (state
== otk::Property::atoms
.net_wm_state_skip_pager
) {
897 } else if (state
== otk::Property::atoms
.net_wm_state_fullscreen
) {
899 } else if (state
== otk::Property::atoms
.net_wm_state_above
) {
900 if (_above
) continue;
902 } else if (state
== otk::Property::atoms
.net_wm_state_below
) {
903 if (_below
) continue;
907 } else { // action == State_Remove
908 if (state
== otk::Property::atoms
.net_wm_state_modal
) {
909 if (!_modal
) continue;
911 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_vert
) {
913 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_horz
) {
915 } else if (state
== otk::Property::atoms
.net_wm_state_shaded
) {
917 } else if (state
== otk::Property::atoms
.net_wm_state_skip_taskbar
) {
918 _skip_taskbar
= false;
919 } else if (state
== otk::Property::atoms
.net_wm_state_skip_pager
) {
921 } else if (state
== otk::Property::atoms
.net_wm_state_fullscreen
) {
923 } else if (state
== otk::Property::atoms
.net_wm_state_above
) {
924 if (!_above
) continue;
926 } else if (state
== otk::Property::atoms
.net_wm_state_below
) {
927 if (!_below
) continue;
932 if (maxh
!= _max_horz
|| maxv
!= _max_vert
) {
933 if (maxh
!= _max_horz
&& maxv
!= _max_vert
) { // toggling both
934 if (maxh
== maxv
) { // both going the same way
935 maximize(maxh
, 0, true);
937 maximize(maxh
, 1, true);
938 maximize(maxv
, 2, true);
940 } else { // toggling one
941 if (maxh
!= _max_horz
)
942 maximize(maxh
, 1, true);
944 maximize(maxv
, 2, true);
947 // change fullscreen state before shading, as it will affect if the window
949 if (fsstate
!= _fullscreen
)
950 fullscreen(fsstate
, true);
951 if (shadestate
!= _shaded
)
954 changeState(); // change the hint to relect these changes
958 void Client::toggleClientBorder(bool addborder
)
960 // adjust our idea of where the client is, based on its border. When the
961 // border is removed, the client should now be considered to be in a
962 // different position.
963 // when re-adding the border to the client, the same operation needs to be
965 int oldx
= _area
.x(), oldy
= _area
.y();
966 int x
= oldx
, y
= oldy
;
969 case NorthWestGravity
:
971 case SouthWestGravity
:
973 case NorthEastGravity
:
975 case SouthEastGravity
:
976 if (addborder
) x
-= _border_width
* 2;
977 else x
+= _border_width
* 2;
984 if (addborder
) x
-= _border_width
;
985 else x
+= _border_width
;
990 case NorthWestGravity
:
992 case NorthEastGravity
:
994 case SouthWestGravity
:
996 case SouthEastGravity
:
997 if (addborder
) y
-= _border_width
* 2;
998 else y
+= _border_width
* 2;
1005 if (addborder
) y
-= _border_width
;
1006 else y
+= _border_width
;
1009 _area
= otk::Rect(otk::Point(x
, y
), _area
.size());
1012 XSetWindowBorderWidth(**otk::display
, _window
, _border_width
);
1014 // move the client so it is back it the right spot _with_ its border!
1015 if (x
!= oldx
|| y
!= oldy
)
1016 XMoveWindow(**otk::display
, _window
, x
, y
);
1018 XSetWindowBorderWidth(**otk::display
, _window
, 0);
1022 void Client::clientMessageHandler(const XClientMessageEvent
&e
)
1024 otk::EventHandler::clientMessageHandler(e
);
1026 // validate cuz we query stuff off the client here
1027 if (!validate()) return;
1029 if (e
.format
!= 32) return;
1031 if (e
.message_type
== otk::Property::atoms
.wm_change_state
) {
1032 // compress changes into a single change
1033 bool compress
= false;
1035 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
1036 // XXX: it would be nice to compress ALL messages of a type, not just
1037 // messages in a row without other message types between.
1038 if (ce
.xclient
.message_type
!= e
.message_type
) {
1039 XPutBackEvent(**otk::display
, &ce
);
1045 setWMState(ce
.xclient
.data
.l
[0]); // use the found event
1047 setWMState(e
.data
.l
[0]); // use the original event
1048 } else if (e
.message_type
== otk::Property::atoms
.net_wm_desktop
) {
1049 // compress changes into a single change
1050 bool compress
= false;
1052 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
1053 // XXX: it would be nice to compress ALL messages of a type, not just
1054 // messages in a row without other message types between.
1055 if (ce
.xclient
.message_type
!= e
.message_type
) {
1056 XPutBackEvent(**otk::display
, &ce
);
1062 setDesktop(e
.data
.l
[0]); // use the found event
1064 setDesktop(e
.data
.l
[0]); // use the original event
1065 } else if (e
.message_type
== otk::Property::atoms
.net_wm_state
) {
1066 // can't compress these
1068 printf("net_wm_state %s %ld %ld for 0x%lx\n",
1069 (e
.data
.l
[0] == 0 ? "Remove" : e
.data
.l
[0] == 1 ? "Add" :
1070 e
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1071 e
.data
.l
[1], e
.data
.l
[2], _window
);
1073 setState((StateAction
)e
.data
.l
[0], e
.data
.l
[1], e
.data
.l
[2]);
1074 } else if (e
.message_type
== otk::Property::atoms
.net_close_window
) {
1076 printf("net_close_window for 0x%lx\n", _window
);
1079 } else if (e
.message_type
== otk::Property::atoms
.net_active_window
) {
1081 printf("net_active_window for 0x%lx\n", _window
);
1083 if (openbox
->screen(_screen
)->showingDesktop())
1084 openbox
->screen(_screen
)->showDesktop(false);
1087 else if (!frame
->visible()) // if its not visible for other reasons, then
1088 return; // don't mess with it
1092 openbox
->screen(_screen
)->raiseWindow(this);
1093 } else if (e
.message_type
== otk::Property::atoms
.openbox_active_window
) {
1094 if (openbox
->screen(_screen
)->showingDesktop())
1095 openbox
->screen(_screen
)->showDesktop(false);
1098 else if (!frame
->visible()) // if its not visible for other reasons, then
1099 return; // don't mess with it
1100 if (e
.data
.l
[0] && _shaded
)
1104 openbox
->screen(_screen
)->raiseWindow(this);
1110 void Client::shapeHandler(const XShapeEvent
&e
)
1112 otk::EventHandler::shapeHandler(e
);
1114 if (e
.kind
== ShapeBounding
) {
1116 frame
->adjustShape();
1122 void Client::resize(Corner anchor
, int w
, int h
)
1124 if (!(_functions
& Func_Resize
)) return;
1125 internal_resize(anchor
, w
, h
);
1129 void Client::internal_resize(Corner anchor
, int w
, int h
,
1130 bool user
, int x
, int y
)
1132 w
-= _base_size
.width();
1133 h
-= _base_size
.height();
1136 // for interactive resizing. have to move half an increment in each
1138 int mw
= w
% _size_inc
.width(); // how far we are towards the next size inc
1139 int mh
= h
% _size_inc
.height();
1140 int aw
= _size_inc
.width() / 2; // amount to add
1141 int ah
= _size_inc
.height() / 2;
1142 // don't let us move into a new size increment
1143 if (mw
+ aw
>= _size_inc
.width()) aw
= _size_inc
.width() - mw
- 1;
1144 if (mh
+ ah
>= _size_inc
.height()) ah
= _size_inc
.height() - mh
- 1;
1148 // if this is a user-requested resize, then check against min/max sizes
1149 // and aspect ratios
1151 // smaller than min size or bigger than max size?
1152 if (w
> _max_size
.width()) w
= _max_size
.width();
1153 if (w
< _min_size
.width()) w
= _min_size
.width();
1154 if (h
> _max_size
.height()) h
= _max_size
.height();
1155 if (h
< _min_size
.height()) h
= _min_size
.height();
1157 // adjust the height ot match the width for the aspect ratios
1159 if (h
* _min_ratio
> w
) h
= static_cast<int>(w
/ _min_ratio
);
1161 if (h
* _max_ratio
< w
) h
= static_cast<int>(w
/ _max_ratio
);
1164 // keep to the increments
1165 w
/= _size_inc
.width();
1166 h
/= _size_inc
.height();
1168 // you cannot resize to nothing
1172 // store the logical size
1173 _logical_size
= otk::Size(w
, h
);
1175 w
*= _size_inc
.width();
1176 h
*= _size_inc
.height();
1178 w
+= _base_size
.width();
1179 h
+= _base_size
.height();
1181 if (x
== INT_MIN
|| y
== INT_MIN
) {
1188 x
-= w
- _area
.width();
1191 y
-= h
- _area
.height();
1194 x
-= w
- _area
.width();
1195 y
-= h
- _area
.height();
1200 _area
= otk::Rect(_area
.position(), otk::Size(w
, h
));
1202 XResizeWindow(**otk::display
, _window
, w
, h
);
1204 // resize the frame to match the request
1205 frame
->adjustSize();
1206 internal_move(x
, y
);
1209 const Icon
*Client::icon(const otk::Size
&s
) const
1211 unsigned long req
= s
.width() * s
.height();
1212 // si is the smallest image >= req
1213 // li is the largest image < req
1214 unsigned long smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
1216 assert(_nicons
> 0); // there should always be a default..
1217 for (int i
= 0; i
< _nicons
; ++i
) {
1218 unsigned long size
= _icons
[i
].w
* _icons
[i
].h
;
1219 if (size
< smallest
&& size
>= req
) {
1223 if (size
> largest
&& size
<= req
) {
1228 if (smallest
== 0xffffffff) // didnt find one bigger than us...
1233 void Client::move(int x
, int y
)
1235 if (!(_functions
& Func_Move
)) return;
1236 frame
->frameGravity(x
, y
); // get the client's position based on x,y for the
1238 internal_move(x
, y
);
1242 void Client::internal_move(int x
, int y
)
1244 _area
= otk::Rect(otk::Point(x
, y
), _area
.size());
1246 // move the frame to be in the requested position
1247 if (frame
) { // this can be called while mapping, before frame exists
1248 frame
->adjustPosition();
1250 // send synthetic configure notify (we don't need to if we aren't mapped
1253 event
.type
= ConfigureNotify
;
1254 event
.xconfigure
.display
= **otk::display
;
1255 event
.xconfigure
.event
= _window
;
1256 event
.xconfigure
.window
= _window
;
1258 // root window coords with border in mind
1259 event
.xconfigure
.x
= x
- _border_width
+ frame
->size().left
;
1260 event
.xconfigure
.y
= y
- _border_width
+ frame
->size().top
;
1262 event
.xconfigure
.width
= _area
.width();
1263 event
.xconfigure
.height
= _area
.height();
1264 event
.xconfigure
.border_width
= _border_width
;
1265 event
.xconfigure
.above
= frame
->plate();
1266 event
.xconfigure
.override_redirect
= False
;
1267 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
, False
,
1268 StructureNotifyMask
, &event
);
1270 printf("Sent synthetic ConfigureNotify %d,%d %d,%d to 0x%lx\n",
1271 event
.xconfigure
.x
, event
.xconfigure
.y
, event
.xconfigure
.width
,
1272 event
.xconfigure
.height
, event
.xconfigure
.window
);
1278 void Client::close()
1282 if (!(_functions
& Func_Close
)) return;
1284 // XXX: itd be cool to do timeouts and shit here for killing the client's
1286 // like... if the window is around after 5 seconds, then the close button
1287 // turns a nice red, and if this function is called again, the client is
1288 // explicitly killed.
1290 ce
.xclient
.type
= ClientMessage
;
1291 ce
.xclient
.message_type
= otk::Property::atoms
.wm_protocols
;
1292 ce
.xclient
.display
= **otk::display
;
1293 ce
.xclient
.window
= _window
;
1294 ce
.xclient
.format
= 32;
1295 ce
.xclient
.data
.l
[0] = otk::Property::atoms
.wm_delete_window
;
1296 ce
.xclient
.data
.l
[1] = CurrentTime
;
1297 ce
.xclient
.data
.l
[2] = 0l;
1298 ce
.xclient
.data
.l
[3] = 0l;
1299 ce
.xclient
.data
.l
[4] = 0l;
1300 XSendEvent(**otk::display
, _window
, false, NoEventMask
, &ce
);
1304 void Client::changeState()
1306 unsigned long state
[2];
1307 state
[0] = _wmstate
;
1309 otk::Property::set(_window
, otk::Property::atoms
.wm_state
,
1310 otk::Property::atoms
.wm_state
, state
, 2);
1315 netstate
[num
++] = otk::Property::atoms
.net_wm_state_modal
;
1317 netstate
[num
++] = otk::Property::atoms
.net_wm_state_shaded
;
1319 netstate
[num
++] = otk::Property::atoms
.net_wm_state_hidden
;
1321 netstate
[num
++] = otk::Property::atoms
.net_wm_state_skip_taskbar
;
1323 netstate
[num
++] = otk::Property::atoms
.net_wm_state_skip_pager
;
1325 netstate
[num
++] = otk::Property::atoms
.net_wm_state_fullscreen
;
1327 netstate
[num
++] = otk::Property::atoms
.net_wm_state_maximized_vert
;
1329 netstate
[num
++] = otk::Property::atoms
.net_wm_state_maximized_horz
;
1331 netstate
[num
++] = otk::Property::atoms
.net_wm_state_above
;
1333 netstate
[num
++] = otk::Property::atoms
.net_wm_state_below
;
1334 otk::Property::set(_window
, otk::Property::atoms
.net_wm_state
,
1335 otk::Property::atoms
.atom
, netstate
, num
);
1340 frame
->adjustState();
1344 void Client::changeAllowedActions(void)
1349 actions
[num
++] = otk::Property::atoms
.net_wm_action_change_desktop
;
1351 if (_functions
& Func_Shade
)
1352 actions
[num
++] = otk::Property::atoms
.net_wm_action_shade
;
1353 if (_functions
& Func_Close
)
1354 actions
[num
++] = otk::Property::atoms
.net_wm_action_close
;
1355 if (_functions
& Func_Move
)
1356 actions
[num
++] = otk::Property::atoms
.net_wm_action_move
;
1357 if (_functions
& Func_Iconify
)
1358 actions
[num
++] = otk::Property::atoms
.net_wm_action_minimize
;
1359 if (_functions
& Func_Resize
)
1360 actions
[num
++] = otk::Property::atoms
.net_wm_action_resize
;
1361 if (_functions
& Func_Fullscreen
)
1362 actions
[num
++] = otk::Property::atoms
.net_wm_action_fullscreen
;
1363 if (_functions
& Func_Maximize
) {
1364 actions
[num
++] = otk::Property::atoms
.net_wm_action_maximize_horz
;
1365 actions
[num
++] = otk::Property::atoms
.net_wm_action_maximize_vert
;
1368 otk::Property::set(_window
, otk::Property::atoms
.net_wm_allowed_actions
,
1369 otk::Property::atoms
.atom
, actions
, num
);
1371 // make sure the window isn't breaking any rules now
1373 if (!(_functions
& Func_Shade
) && _shaded
)
1374 if (frame
) shade(false);
1375 else _shaded
= false;
1376 if (!(_functions
& Func_Iconify
) && _iconic
)
1377 if (frame
) setDesktop(openbox
->screen(_screen
)->desktop());
1378 else _iconic
= false;
1379 if (!(_functions
& Func_Fullscreen
) && _fullscreen
)
1380 if (frame
) fullscreen(false);
1381 else _fullscreen
= false;
1382 if (!(_functions
& Func_Maximize
) && (_max_horz
|| _max_vert
))
1383 if (frame
) maximize(false, 0);
1384 else _max_vert
= _max_horz
= false;
1388 void Client::remaximize()
1391 if (_max_horz
&& _max_vert
)
1398 return; // not maximized
1399 _max_horz
= _max_vert
= false;
1400 maximize(true, dir
, false);
1404 void Client::applyStartupState()
1406 // these are in a carefully crafted order..
1413 _fullscreen
= false;
1414 fullscreen(true, false);
1423 if (_max_vert
&& _max_horz
) {
1424 _max_vert
= _max_horz
= false;
1425 maximize(true, 0, false);
1426 } else if (_max_vert
) {
1428 maximize(true, 2, false);
1429 } else if (_max_horz
) {
1431 maximize(true, 1, false);
1434 if (_skip_taskbar
); // nothing to do for this
1435 if (_skip_pager
); // nothing to do for this
1436 if (_modal
); // nothing to do for this
1437 if (_above
); // nothing to do for this
1438 if (_below
); // nothing to do for this
1442 void Client::fireUrgent()
1444 // call the python UrgentWindow callbacks
1445 EventData
data(_screen
, this, EventAction::UrgentWindow
, 0);
1446 openbox
->bindings()->fireEvent(&data
);
1450 void Client::shade(bool shade
)
1452 if (!(_functions
& Func_Shade
) || // can't
1453 _shaded
== shade
) return; // already done
1455 // when we're iconic, don't change the wmstate
1457 _wmstate
= shade
? IconicState
: NormalState
;
1460 frame
->adjustSize();
1464 void Client::maximize(bool max
, int dir
, bool savearea
)
1466 assert(dir
== 0 || dir
== 1 || dir
== 2);
1467 if (!(_functions
& Func_Maximize
)) return; // can't
1469 // check if already done
1471 if (dir
== 0 && _max_horz
&& _max_vert
) return;
1472 if (dir
== 1 && _max_horz
) return;
1473 if (dir
== 2 && _max_vert
) return;
1475 if (dir
== 0 && !_max_horz
&& !_max_vert
) return;
1476 if (dir
== 1 && !_max_horz
) return;
1477 if (dir
== 2 && !_max_vert
) return;
1480 const otk::Rect
&a
= openbox
->screen(_screen
)->area(_desktop
);
1481 int x
= frame
->area().x(), y
= frame
->area().y(),
1482 w
= _area
.width(), h
= _area
.height();
1488 unsigned long n
= 4;
1495 // get the property off the window and use it for the dimentions we are
1497 if (otk::Property::get(_window
, otk::Property::atoms
.openbox_premax
,
1498 otk::Property::atoms
.cardinal
, &n
,
1499 (long unsigned**) &readdim
)) {
1502 dimensions
[0] = readdim
[0];
1503 dimensions
[2] = readdim
[2];
1506 dimensions
[1] = readdim
[1];
1507 dimensions
[3] = readdim
[3];
1513 otk::Property::set(_window
, otk::Property::atoms
.openbox_premax
,
1514 otk::Property::atoms
.cardinal
,
1515 (long unsigned*)dimensions
, 4);
1517 if (dir
== 0 || dir
== 1) { // horz
1521 if (dir
== 0 || dir
== 2) { // vert
1523 h
= a
.height() - frame
->size().top
- frame
->size().bottom
;
1527 long unsigned n
= 4;
1529 if (otk::Property::get(_window
, otk::Property::atoms
.openbox_premax
,
1530 otk::Property::atoms
.cardinal
, &n
,
1531 (long unsigned**) &dimensions
)) {
1533 if (dir
== 0 || dir
== 1) { // horz
1534 x
= (signed int)dimensions
[0];
1535 w
= (signed int)dimensions
[2];
1537 if (dir
== 0 || dir
== 2) { // vert
1538 y
= (signed int)dimensions
[1];
1539 h
= (signed int)dimensions
[3];
1544 // pick some fallbacks...
1545 if (dir
== 0 || dir
== 1) { // horz
1546 x
= a
.x() + a
.width() / 4;
1549 if (dir
== 0 || dir
== 2) { // vert
1550 y
= a
.y() + a
.height() / 4;
1556 if (dir
== 0 || dir
== 1) // horz
1558 if (dir
== 0 || dir
== 2) // vert
1561 if (!_max_horz
&& !_max_vert
)
1562 otk::Property::erase(_window
, otk::Property::atoms
.openbox_premax
);
1564 changeState(); // change the state hints on the client
1566 frame
->frameGravity(x
, y
); // figure out where the client should be going
1567 internal_resize(TopLeft
, w
, h
, true, x
, y
);
1571 void Client::fullscreen(bool fs
, bool savearea
)
1573 static FunctionFlags saved_func
;
1574 static DecorationFlags saved_decor
;
1576 if (!(_functions
& Func_Fullscreen
) || // can't
1577 _fullscreen
== fs
) return; // already done
1580 changeState(); // change the state hints on the client
1582 int x
= _area
.x(), y
= _area
.y(), w
= _area
.width(), h
= _area
.height();
1585 // save the functions and remove them
1586 saved_func
= _functions
;
1587 _functions
= _functions
& (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1588 // save the decorations and remove them
1589 saved_decor
= _decorations
;
1593 dimensions
[0] = _area
.x();
1594 dimensions
[1] = _area
.y();
1595 dimensions
[2] = _area
.width();
1596 dimensions
[3] = _area
.height();
1597 otk::Property::set(_window
, otk::Property::atoms
.openbox_premax
,
1598 otk::Property::atoms
.cardinal
,
1599 (long unsigned*)dimensions
, 4);
1601 const otk::ScreenInfo
*info
= otk::display
->screenInfo(_screen
);
1604 w
= info
->size().width();
1605 h
= info
->size().height();
1607 _functions
= saved_func
;
1608 _decorations
= saved_decor
;
1611 long unsigned n
= 4;
1613 if (otk::Property::get(_window
, otk::Property::atoms
.openbox_premax
,
1614 otk::Property::atoms
.cardinal
, &n
,
1615 (long unsigned**) &dimensions
)) {
1624 // pick some fallbacks...
1625 const otk::Rect
&a
= openbox
->screen(_screen
)->area(_desktop
);
1626 x
= a
.x() + a
.width() / 4;
1627 y
= a
.y() + a
.height() / 4;
1633 changeAllowedActions(); // based on the new _functions
1635 // when fullscreening, don't obey things like increments, fill the screen
1636 internal_resize(TopLeft
, w
, h
, !fs
, x
, y
);
1638 // raise (back) into our stacking layer
1639 openbox
->screen(_screen
)->raiseWindow(this);
1641 // try focus us when we go into fullscreen mode
1646 void Client::iconify(bool iconic
, bool curdesk
)
1648 if (_iconic
== iconic
) return; // nothing to do
1651 printf("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"), _window
);
1657 _wmstate
= IconicState
;
1659 // we unmap the client itself so that we can get MapRequest events, and
1660 // because the ICCCM tells us to!
1661 XUnmapWindow(**otk::display
, _window
);
1664 setDesktop(openbox
->screen(_screen
)->desktop());
1665 _wmstate
= NormalState
;
1666 XMapWindow(**otk::display
, _window
);
1670 openbox
->screen(_screen
)->updateStruts();
1674 void Client::disableDecorations(DecorationFlags flags
)
1676 _disabled_decorations
= flags
;
1677 setupDecorAndFunctions();
1681 void Client::installColormap(bool install
) const
1683 XWindowAttributes wa
;
1684 if (XGetWindowAttributes(**otk::display
, _window
, &wa
)) {
1686 XInstallColormap(**otk::display
, wa
.colormap
);
1688 XUninstallColormap(**otk::display
, wa
.colormap
);
1693 // recursively searches the client 'tree' for a modal client, always skips the
1694 // topmost node (the window you're starting with)
1695 Client
*Client::searchModalTree(Client
*node
, Client
*skip
)
1697 List::const_iterator it
, end
= node
->_transients
.end();
1700 for (it
= node
->_transients
.begin(); it
!= end
; ++it
) {
1701 if (*it
== skip
) continue; // circular?
1702 if ((ret
= searchModalTree(*it
, skip
))) return ret
; // got one
1703 if ((*it
)->_modal
) return *it
; // got one
1708 Client
*Client::findModalChild()
1710 return searchModalTree(this, this);
1714 bool Client::focus()
1716 // if we have a modal child, then focus it, not us
1717 Client
*c
= findModalChild();
1718 if (c
) return c
->focus();
1720 // won't try focus if the client doesn't want it, or if the window isn't
1721 // visible on the screen
1722 if (!(frame
->visible() && (_can_focus
|| _focus_notify
))) return false;
1724 if (_focused
) return true;
1726 // do a check to see if the window has already been unmapped or destroyed
1727 // do this intelligently while watching out for unmaps we've generated
1728 // (ignore_unmaps > 0)
1730 if (XCheckTypedWindowEvent(**otk::display
, _window
, DestroyNotify
, &ev
)) {
1731 XPutBackEvent(**otk::display
, &ev
);
1734 while (XCheckTypedWindowEvent(**otk::display
, _window
, UnmapNotify
, &ev
)) {
1735 if (ignore_unmaps
) {
1736 unmapHandler(ev
.xunmap
);
1738 XPutBackEvent(**otk::display
, &ev
);
1744 XSetInputFocus(**otk::display
, _window
,
1745 RevertToNone
, CurrentTime
);
1747 if (_focus_notify
) {
1749 ce
.xclient
.type
= ClientMessage
;
1750 ce
.xclient
.message_type
= otk::Property::atoms
.wm_protocols
;
1751 ce
.xclient
.display
= **otk::display
;
1752 ce
.xclient
.window
= _window
;
1753 ce
.xclient
.format
= 32;
1754 ce
.xclient
.data
.l
[0] = otk::Property::atoms
.wm_take_focus
;
1755 ce
.xclient
.data
.l
[1] = openbox
->lastTime();
1756 ce
.xclient
.data
.l
[2] = 0l;
1757 ce
.xclient
.data
.l
[3] = 0l;
1758 ce
.xclient
.data
.l
[4] = 0l;
1759 XSendEvent(**otk::display
, _window
, False
, NoEventMask
, &ce
);
1762 XSync(**otk::display
, False
);
1767 void Client::unfocus() const
1769 if (!_focused
) return;
1771 assert(openbox
->focusedClient() == this);
1772 openbox
->setFocusedClient(0);
1776 void Client::focusHandler(const XFocusChangeEvent
&e
)
1779 // printf("FocusIn for 0x%lx\n", e.window);
1782 otk::EventHandler::focusHandler(e
);
1785 frame
->adjustFocus();
1787 openbox
->setFocusedClient(this);
1791 void Client::unfocusHandler(const XFocusChangeEvent
&e
)
1794 // printf("FocusOut for 0x%lx\n", e.window);
1797 otk::EventHandler::unfocusHandler(e
);
1800 frame
->adjustFocus();
1802 if (openbox
->focusedClient() == this)
1803 openbox
->setFocusedClient(0);
1807 void Client::configureRequestHandler(const XConfigureRequestEvent
&ec
)
1810 printf("ConfigureRequest for 0x%lx\n", ec
.window
);
1813 otk::EventHandler::configureRequestHandler(ec
);
1816 XConfigureRequestEvent e
= ec
;
1818 while (XCheckTypedWindowEvent(**otk::display
, window(), ConfigureRequest
,
1820 // XXX if this causes bad things.. we can compress config req's with the
1822 e
.value_mask
|= ev
.xconfigurerequest
.value_mask
;
1823 if (ev
.xconfigurerequest
.value_mask
& CWX
)
1824 e
.x
= ev
.xconfigurerequest
.x
;
1825 if (ev
.xconfigurerequest
.value_mask
& CWY
)
1826 e
.y
= ev
.xconfigurerequest
.y
;
1827 if (ev
.xconfigurerequest
.value_mask
& CWWidth
)
1828 e
.width
= ev
.xconfigurerequest
.width
;
1829 if (ev
.xconfigurerequest
.value_mask
& CWHeight
)
1830 e
.height
= ev
.xconfigurerequest
.height
;
1831 if (ev
.xconfigurerequest
.value_mask
& CWBorderWidth
)
1832 e
.border_width
= ev
.xconfigurerequest
.border_width
;
1833 if (ev
.xconfigurerequest
.value_mask
& CWStackMode
)
1834 e
.detail
= ev
.xconfigurerequest
.detail
;
1837 // if we are iconic (or shaded (fvwm does this)) ignore the event
1838 if (_iconic
|| _shaded
) return;
1840 if (e
.value_mask
& CWBorderWidth
)
1841 _border_width
= e
.border_width
;
1843 // resize, then move, as specified in the EWMH section 7.7
1844 if (e
.value_mask
& (CWWidth
| CWHeight
)) {
1845 int w
= (e
.value_mask
& CWWidth
) ? e
.width
: _area
.width();
1846 int h
= (e
.value_mask
& CWHeight
) ? e
.height
: _area
.height();
1850 case NorthEastGravity
:
1854 case SouthWestGravity
:
1856 corner
= BottomLeft
;
1858 case SouthEastGravity
:
1859 corner
= BottomRight
;
1861 default: // NorthWest, Static, etc
1865 // if moving AND resizing ...
1866 if (e
.value_mask
& (CWX
| CWY
)) {
1867 int x
= (e
.value_mask
& CWX
) ? e
.x
: _area
.x();
1868 int y
= (e
.value_mask
& CWY
) ? e
.y
: _area
.y();
1869 internal_resize(corner
, w
, h
, false, x
, y
);
1870 } else // if JUST resizing...
1871 internal_resize(corner
, w
, h
, false);
1872 } else if (e
.value_mask
& (CWX
| CWY
)) { // if JUST moving...
1873 int x
= (e
.value_mask
& CWX
) ? e
.x
: _area
.x();
1874 int y
= (e
.value_mask
& CWY
) ? e
.y
: _area
.y();
1875 internal_move(x
, y
);
1878 if (e
.value_mask
& CWStackMode
) {
1882 openbox
->screen(_screen
)->lowerWindow(this);
1888 openbox
->screen(_screen
)->raiseWindow(this);
1895 void Client::unmapHandler(const XUnmapEvent
&e
)
1897 if (ignore_unmaps
) {
1899 // printf("Ignored UnmapNotify for 0x%lx (event 0x%lx)\n", e.window, e.event);
1906 printf("UnmapNotify for 0x%lx\n", e
.window
);
1909 otk::EventHandler::unmapHandler(e
);
1911 // this deletes us etc
1912 openbox
->screen(_screen
)->unmanageWindow(this);
1916 void Client::destroyHandler(const XDestroyWindowEvent
&e
)
1919 printf("DestroyNotify for 0x%lx\n", e
.window
);
1922 otk::EventHandler::destroyHandler(e
);
1924 // this deletes us etc
1925 openbox
->screen(_screen
)->unmanageWindow(this);
1929 void Client::reparentHandler(const XReparentEvent
&e
)
1931 // this is when the client is first taken captive in the frame
1932 if (e
.parent
== frame
->plate()) return;
1935 printf("ReparentNotify for 0x%lx\n", e
.window
);
1938 otk::EventHandler::reparentHandler(e
);
1941 This event is quite rare and is usually handled in unmapHandler.
1942 However, if the window is unmapped when the reparent event occurs,
1943 the window manager never sees it because an unmap event is not sent
1944 to an already unmapped window.
1947 // we don't want the reparent event, put it back on the stack for the X
1948 // server to deal with after we unmanage the window
1951 XPutBackEvent(**otk::display
, &ev
);
1953 // this deletes us etc
1954 openbox
->screen(_screen
)->unmanageWindow(this);
1957 void Client::mapRequestHandler(const XMapRequestEvent
&e
)
1960 printf("MapRequest for already managed 0x%lx\n", e
.window
);
1963 assert(_iconic
); // we shouldn't be able to get this unless we're iconic
1965 // move to the current desktop (uniconify)
1967 // XXX: should we focus/raise the window? (basically a net_wm_active_window)