1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
11 #include "bindings.hh"
12 #include "otk/display.hh"
13 #include "otk/property.hh"
17 #include <X11/Xutil.h>
18 #include <X11/Xatom.h>
21 #define _(str) gettext(str)
30 Client::Client(int screen
, Window window
)
31 : otk::EventHandler(),
32 frame(0), _screen(screen
), _window(window
)
39 // update EVERYTHING the first time!!
42 _wmstate
= NormalState
;
45 _layer
= Layer_Normal
;
48 _disabled_decorations
= 0;
55 getState(); // do this before updateTransientFor! (for _modal)
60 getType(); // this can change the mwmhints for special cases
64 getGravity(); // get the attribute gravity
65 updateNormalHints(); // this may override the attribute gravity
67 // got the type, the mwmhints, the protocols, and the normal hints (min/max
68 // sizes), so we're ready to set up
69 // the decorations/functions
70 setupDecorAndFunctions();
72 // also get the initial_state and set _iconic if we aren't "starting"
73 // when we're "starting" that means we should use whatever state was already
74 // on the window over the initial map state, because it was already mapped
75 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
);
96 // clean up childrens' references
97 while (!_transients
.empty()) {
98 _transients
.front()->_transient_for
= 0;
99 _transients
.pop_front();
102 // clean up parents reference to this
104 _transient_for
->_transients
.remove(this); // remove from old parent
106 if (openbox
->state() != Openbox::State_Exiting
) {
107 // these values should not be persisted across a window unmapping/mapping
108 otk::Property::erase(_window
, otk::Property::atoms
.net_wm_desktop
);
109 otk::Property::erase(_window
, otk::Property::atoms
.net_wm_state
);
111 // if we're left in an iconic state, the client wont be mapped. this is
112 // bad, since we will no longer be managing the window on restart
114 XMapWindow(**otk::display
, _window
);
119 bool Client::validate() const
121 XSync(**otk::display
, false); // get all events on the server
124 if (XCheckTypedWindowEvent(**otk::display
, _window
, DestroyNotify
, &e
) ||
125 XCheckTypedWindowEvent(**otk::display
, _window
, UnmapNotify
, &e
)) {
126 XPutBackEvent(**otk::display
, &e
);
134 void Client::getGravity()
136 XWindowAttributes wattrib
;
139 ret
= XGetWindowAttributes(**otk::display
, _window
, &wattrib
);
140 assert(ret
!= BadWindow
);
141 _gravity
= wattrib
.win_gravity
;
145 void Client::getDesktop()
147 // defaults to the current desktop
148 _desktop
= openbox
->screen(_screen
)->desktop();
150 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_desktop
,
151 otk::Property::atoms
.cardinal
,
152 (long unsigned*)&_desktop
)) {
154 // printf("Window requested desktop: %ld\n", _desktop);
160 void Client::getType()
162 _type
= (WindowType
) -1;
165 unsigned long num
= (unsigned) -1;
166 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_window_type
,
167 otk::Property::atoms
.atom
, &num
, &val
)) {
168 // use the first value that we know about in the array
169 for (unsigned long i
= 0; i
< num
; ++i
) {
170 if (val
[i
] == otk::Property::atoms
.net_wm_window_type_desktop
)
171 _type
= Type_Desktop
;
172 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_dock
)
174 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_toolbar
)
175 _type
= Type_Toolbar
;
176 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_menu
)
178 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_utility
)
179 _type
= Type_Utility
;
180 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_splash
)
182 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_dialog
)
184 else if (val
[i
] == otk::Property::atoms
.net_wm_window_type_normal
)
186 else if (val
[i
] == otk::Property::atoms
.kde_net_wm_window_type_override
){
187 // prevent this window from getting any decor or functionality
188 _mwmhints
.flags
&= MwmFlag_Functions
| MwmFlag_Decorations
;
189 _mwmhints
.decorations
= 0;
190 _mwmhints
.functions
= 0;
192 if (_type
!= (WindowType
) -1)
193 break; // grab the first known type
198 if (_type
== (WindowType
) -1) {
200 * the window type hint was not set, which means we either classify ourself
201 * as a normal window or a dialog, depending on if we are a transient.
211 void Client::setupDecorAndFunctions()
213 // start with everything (cept fullscreen)
214 _decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
215 Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
216 _functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
218 if (_delete_window
) {
219 _decorations
|= Decor_Close
;
220 _functions
|= Func_Close
;
223 if (!(_min_size
.width() < _max_size
.width() ||
224 _min_size
.height() < _max_size
.height())) {
225 _decorations
&= ~(Decor_Maximize
| Decor_Handle
);
226 _functions
&= ~(Func_Resize
| Func_Maximize
);
231 // normal windows retain all of the possible decorations and
232 // functionality, and are the only windows that you can fullscreen
233 _functions
|= Func_Fullscreen
;
237 // dialogs cannot be maximized
238 _decorations
&= ~Decor_Maximize
;
239 _functions
&= ~Func_Maximize
;
245 // these windows get less functionality
246 _decorations
&= ~(Decor_Iconify
| Decor_Handle
);
247 _functions
&= ~(Func_Iconify
| Func_Resize
);
253 // none of these windows are manipulated by the window manager
259 // Mwm Hints are applied subtractively to what has already been chosen for
260 // decor and functionality
261 if (_mwmhints
.flags
& MwmFlag_Decorations
) {
262 if (! (_mwmhints
.decorations
& MwmDecor_All
)) {
263 if (! (_mwmhints
.decorations
& MwmDecor_Border
))
264 _decorations
&= ~Decor_Border
;
265 if (! (_mwmhints
.decorations
& MwmDecor_Handle
))
266 _decorations
&= ~Decor_Handle
;
267 if (! (_mwmhints
.decorations
& MwmDecor_Title
))
268 _decorations
&= ~Decor_Titlebar
;
269 if (! (_mwmhints
.decorations
& MwmDecor_Iconify
))
270 _decorations
&= ~Decor_Iconify
;
271 if (! (_mwmhints
.decorations
& MwmDecor_Maximize
))
272 _decorations
&= ~Decor_Maximize
;
276 if (_mwmhints
.flags
& MwmFlag_Functions
) {
277 if (! (_mwmhints
.functions
& MwmFunc_All
)) {
278 if (! (_mwmhints
.functions
& MwmFunc_Resize
))
279 _functions
&= ~Func_Resize
;
280 if (! (_mwmhints
.functions
& MwmFunc_Move
))
281 _functions
&= ~Func_Move
;
282 if (! (_mwmhints
.functions
& MwmFunc_Iconify
))
283 _functions
&= ~Func_Iconify
;
284 if (! (_mwmhints
.functions
& MwmFunc_Maximize
))
285 _functions
&= ~Func_Maximize
;
286 // dont let mwm hints kill the close button
287 //if (! (_mwmhints.functions & MwmFunc_Close))
288 // _functions &= ~Func_Close;
292 // can't maximize without moving/resizing
293 if (!((_functions
& Func_Move
) && (_functions
& Func_Resize
)))
294 _functions
&= ~Func_Maximize
;
296 // finally, user specified disabled decorations are applied to subtract
298 if (_disabled_decorations
& Decor_Titlebar
)
299 _decorations
&= ~Decor_Titlebar
;
300 if (_disabled_decorations
& Decor_Handle
)
301 _decorations
&= ~Decor_Handle
;
302 if (_disabled_decorations
& Decor_Border
)
303 _decorations
&= ~Decor_Border
;
304 if (_disabled_decorations
& Decor_Iconify
)
305 _decorations
&= ~Decor_Iconify
;
306 if (_disabled_decorations
& Decor_Maximize
)
307 _decorations
&= ~Decor_Maximize
;
308 if (_disabled_decorations
& Decor_AllDesktops
)
309 _decorations
&= ~Decor_AllDesktops
;
310 if (_disabled_decorations
& Decor_Close
)
311 _decorations
&= ~Decor_Close
;
313 // if we don't have a titlebar, then we cannot shade!
314 if (!(_decorations
& Decor_Titlebar
))
315 _functions
&= ~Func_Shade
;
317 changeAllowedActions();
320 frame
->adjustSize(); // change the decors on the frame
321 frame
->adjustPosition(); // with more/less decorations, we may need to be
323 remaximize(); // with new decor, the window's maximized size may change
328 void Client::getMwmHints()
330 unsigned long num
= MwmHints::elements
;
331 unsigned long *hints
;
333 _mwmhints
.flags
= 0; // default to none
335 if (!otk::Property::get(_window
, otk::Property::atoms
.motif_wm_hints
,
336 otk::Property::atoms
.motif_wm_hints
, &num
,
337 (unsigned long **)&hints
))
340 if (num
>= MwmHints::elements
) {
341 // retrieved the hints
342 _mwmhints
.flags
= hints
[0];
343 _mwmhints
.functions
= hints
[1];
344 _mwmhints
.decorations
= hints
[2];
351 void Client::getArea()
353 XWindowAttributes wattrib
;
356 ret
= XGetWindowAttributes(**otk::display
, _window
, &wattrib
);
357 assert(ret
!= BadWindow
);
359 _area
= otk::Rect(wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
360 _border_width
= wattrib
.border_width
;
364 void Client::getState()
366 _modal
= _shaded
= _max_horz
= _max_vert
= _fullscreen
= _above
= _below
=
367 _iconic
= _skip_taskbar
= _skip_pager
= false;
369 unsigned long *state
;
370 unsigned long num
= (unsigned) -1;
372 if (otk::Property::get(_window
, otk::Property::atoms
.net_wm_state
,
373 otk::Property::atoms
.atom
, &num
, &state
)) {
374 for (unsigned long i
= 0; i
< num
; ++i
) {
375 if (state
[i
] == otk::Property::atoms
.net_wm_state_modal
)
377 else if (state
[i
] == otk::Property::atoms
.net_wm_state_shaded
)
379 else if (state
[i
] == otk::Property::atoms
.net_wm_state_hidden
)
381 else if (state
[i
] == otk::Property::atoms
.net_wm_state_skip_taskbar
)
382 _skip_taskbar
= true;
383 else if (state
[i
] == otk::Property::atoms
.net_wm_state_skip_pager
)
385 else if (state
[i
] == otk::Property::atoms
.net_wm_state_fullscreen
)
387 else if (state
[i
] == otk::Property::atoms
.net_wm_state_maximized_vert
)
389 else if (state
[i
] == otk::Property::atoms
.net_wm_state_maximized_horz
)
391 else if (state
[i
] == otk::Property::atoms
.net_wm_state_above
)
393 else if (state
[i
] == otk::Property::atoms
.net_wm_state_below
)
402 void Client::getShaped()
406 if (otk::display
->shape()) {
411 XShapeSelectInput(**otk::display
, _window
, ShapeNotifyMask
);
413 XShapeQueryExtents(**otk::display
, _window
, &s
, &foo
,
414 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
, &ufoo
);
421 void Client::calcLayer() {
424 if (_iconic
) l
= Layer_Icon
;
425 else if (_fullscreen
) l
= Layer_Fullscreen
;
426 else if (_type
== Type_Desktop
) l
= Layer_Desktop
;
427 else if (_type
== Type_Dock
) {
428 if (!_below
) l
= Layer_Top
;
429 else l
= Layer_Normal
;
431 else if (_above
) l
= Layer_Above
;
432 else if (_below
) l
= Layer_Below
;
433 else l
= Layer_Normal
;
439 if we don't have a frame, then we aren't mapped yet (and this would
442 openbox
->screen(_screen
)->raiseWindow(this);
448 void Client::updateProtocols()
453 _focus_notify
= false;
454 _delete_window
= false;
456 if (XGetWMProtocols(**otk::display
, _window
, &proto
, &num_return
)) {
457 for (int i
= 0; i
< num_return
; ++i
) {
458 if (proto
[i
] == otk::Property::atoms
.wm_delete_window
) {
459 // this means we can request the window to close
460 _delete_window
= true;
461 } else if (proto
[i
] == otk::Property::atoms
.wm_take_focus
)
462 // if this protocol is requested, then the window will be notified
463 // by the window manager whenever it receives focus
464 _focus_notify
= true;
471 void Client::updateNormalHints()
475 int oldgravity
= _gravity
;
480 _size_inc
= otk::Size(1, 1);
481 _base_size
= otk::Size(0, 0);
482 _min_size
= otk::Size(0, 0);
483 _max_size
= otk::Size(INT_MAX
, INT_MAX
);
485 // get the hints from the window
486 if (XGetWMNormalHints(**otk::display
, _window
, &size
, &ret
)) {
487 _positioned
= (size
.flags
& (PPosition
|USPosition
));
489 if (size
.flags
& PWinGravity
) {
490 _gravity
= size
.win_gravity
;
492 // if the client has a frame, i.e. has already been mapped and is
493 // changing its gravity
494 if (frame
&& _gravity
!= oldgravity
) {
495 // move our idea of the client's position based on its new gravity
496 int x
= frame
->area().x(), y
= frame
->area().y();
497 frame
->frameGravity(x
, y
);
498 _area
= otk::Rect(otk::Point(x
, y
), _area
.size());
502 if (size
.flags
& PAspect
) {
503 if (size
.min_aspect
.y
) _min_ratio
= size
.min_aspect
.x
/size
.min_aspect
.y
;
504 if (size
.max_aspect
.y
) _max_ratio
= size
.max_aspect
.x
/size
.max_aspect
.y
;
507 if (size
.flags
& PMinSize
)
508 _min_size
= otk::Size(size
.min_width
, size
.min_height
);
510 if (size
.flags
& PMaxSize
)
511 _max_size
= otk::Size(size
.max_width
, size
.max_height
);
513 if (size
.flags
& PBaseSize
)
514 _base_size
= otk::Size(size
.base_width
, size
.base_height
);
516 if (size
.flags
& PResizeInc
)
517 _size_inc
= otk::Size(size
.width_inc
, size
.height_inc
);
522 void Client::updateWMHints(bool initstate
)
526 // assume a window takes input if it doesnt specify
530 if ((hints
= XGetWMHints(**otk::display
, _window
)) != NULL
) {
531 if (hints
->flags
& InputHint
)
532 _can_focus
= hints
->input
;
534 // only do this when initstate is true!
535 if (initstate
&& (hints
->flags
& StateHint
))
536 _iconic
= hints
->initial_state
== IconicState
;
538 if (hints
->flags
& XUrgencyHint
)
541 if (hints
->flags
& WindowGroupHint
) {
542 if (hints
->window_group
!= _group
) {
543 // XXX: remove from the old group if there was one
544 _group
= hints
->window_group
;
545 // XXX: do stuff with the group
556 printf("DEBUG: Urgent Hint for 0x%lx: %s\n",
557 (long)_window
, _urgent
? "ON" : "OFF");
559 // fire the urgent callback if we're mapped, otherwise, wait until after
567 void Client::updateTitle()
572 if (!otk::Property::get(_window
, otk::Property::atoms
.net_wm_name
,
573 otk::Property::utf8
, &_title
)) {
575 otk::Property::get(_window
, otk::Property::atoms
.wm_name
,
576 otk::Property::ascii
, &_title
);
580 _title
= _("Unnamed Window");
583 frame
->adjustTitle();
587 void Client::updateIconTitle()
592 if (!otk::Property::get(_window
, otk::Property::atoms
.net_wm_icon_name
,
593 otk::Property::utf8
, &_icon_title
)) {
595 otk::Property::get(_window
, otk::Property::atoms
.wm_icon_name
,
596 otk::Property::ascii
, &_icon_title
);
600 _icon_title
= _("Unnamed Window");
604 void Client::updateClass()
607 _app_name
= _app_class
= _role
= "";
609 otk::Property::StringVect v
;
610 unsigned long num
= 2;
612 if (otk::Property::get(_window
, otk::Property::atoms
.wm_class
,
613 otk::Property::ascii
, &num
, &v
)) {
614 if (num
> 0) _app_name
= v
[0].c_str();
615 if (num
> 1) _app_class
= v
[1].c_str();
620 if (otk::Property::get(_window
, otk::Property::atoms
.wm_window_role
,
621 otk::Property::ascii
, &num
, &v
)) {
622 if (num
> 0) _role
= v
[0].c_str();
627 void Client::updateStrut()
629 unsigned long num
= 4;
631 if (!otk::Property::get(_window
, otk::Property::atoms
.net_wm_strut
,
632 otk::Property::atoms
.cardinal
, &num
, &data
))
636 _strut
.left
= data
[0];
637 _strut
.right
= data
[1];
638 _strut
.top
= data
[2];
639 _strut
.bottom
= data
[3];
641 // updating here is pointless while we're being mapped cuz we're not in
642 // the screen's client list yet
644 openbox
->screen(_screen
)->updateStrut();
651 void Client::updateTransientFor()
656 if (XGetTransientForHint(**otk::display
, _window
, &t
) &&
657 t
!= _window
) { // cant be transient to itself!
658 c
= openbox
->findClient(t
);
659 assert(c
!= this); // if this happens then we need to check for it
661 if (!c
/*XXX: && _group*/) {
662 // not transient to a client, see if it is transient for a group
663 if (//t == _group->leader() ||
665 t
== otk::display
->screenInfo(_screen
)->rootWindow()) {
666 // window is a transient for its group!
667 // XXX: for now this is treated as non-transient.
668 // this needs to be fixed!
673 // if anything has changed...
674 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
691 void Client::propertyHandler(const XPropertyEvent
&e
)
693 otk::EventHandler::propertyHandler(e
);
695 // validate cuz we query stuff off the client here
696 if (!validate()) return;
698 // compress changes to a single property into a single change
700 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
701 // XXX: it would be nice to compress ALL changes to a property, not just
702 // changes in a row without other props between.
703 if (ce
.xproperty
.atom
!= e
.atom
) {
704 XPutBackEvent(**otk::display
, &ce
);
709 if (e
.atom
== XA_WM_NORMAL_HINTS
) {
711 setupDecorAndFunctions(); // normal hints can make a window non-resizable
712 } else if (e
.atom
== XA_WM_HINTS
)
714 else if (e
.atom
== XA_WM_TRANSIENT_FOR
) {
715 updateTransientFor();
717 calcLayer(); // type may have changed, so update the layer
718 setupDecorAndFunctions();
720 else if (e
.atom
== otk::Property::atoms
.net_wm_name
||
721 e
.atom
== otk::Property::atoms
.wm_name
)
723 else if (e
.atom
== otk::Property::atoms
.net_wm_icon_name
||
724 e
.atom
== otk::Property::atoms
.wm_icon_name
)
726 else if (e
.atom
== otk::Property::atoms
.wm_class
)
728 else if (e
.atom
== otk::Property::atoms
.wm_protocols
) {
730 setupDecorAndFunctions();
732 else if (e
.atom
== otk::Property::atoms
.net_wm_strut
)
737 void Client::setWMState(long state
)
739 if (state
== _wmstate
) return; // no change
743 setDesktop(ICONIC_DESKTOP
);
746 setDesktop(openbox
->screen(_screen
)->desktop());
752 void Client::setDesktop(long target
)
754 if (target
== _desktop
) return;
756 printf("Setting desktop %ld\n", target
);
758 if (!(target
>= 0 || target
== (signed)0xffffffff ||
759 target
== ICONIC_DESKTOP
))
764 // set the desktop hint, but not if we're iconifying
765 if (_desktop
!= ICONIC_DESKTOP
)
766 otk::Property::set(_window
, otk::Property::atoms
.net_wm_desktop
,
767 otk::Property::atoms
.cardinal
, (unsigned)_desktop
);
769 // 'move' the window to the new desktop
770 if (_desktop
== openbox
->screen(_screen
)->desktop() ||
771 _desktop
== (signed)0xffffffff)
776 // Handle Iconic state. Iconic state is maintained by the client being a
777 // member of the ICONIC_DESKTOP, so this is where we make iconifying and
778 // uniconifying happen.
779 bool i
= _desktop
== ICONIC_DESKTOP
;
780 if (i
!= _iconic
) { // has the state changed?
783 _wmstate
= IconicState
;
785 // we unmap the client itself so that we can get MapRequest events, and
786 // because the ICCCM tells us to!
787 XUnmapWindow(**otk::display
, _window
);
789 _wmstate
= NormalState
;
790 XMapWindow(**otk::display
, _window
);
795 frame
->adjustState();
799 Client
*Client::findModalChild(Client
*skip
) const
803 // find a modal child recursively and try focus it
804 List::const_iterator it
, end
= _transients
.end();
805 for (it
= _transients
.begin(); it
!= end
; ++it
)
806 if ((*it
)->_modal
&& *it
!= skip
)
807 return *it
; // got one
808 // none of our direct children are modal, let them try check
809 for (it
= _transients
.begin(); it
!= end
; ++it
)
810 if ((ret
= (*it
)->findModalChild()))
811 return ret
; // got one
816 void Client::setModal(bool modal
)
818 if (modal
== _modal
) return;
822 while (c
->_transient_for
) {
823 c
= c
->_transient_for
;
824 if (c
== this) break; // circular?
825 if (c
->_modal_child
) break; // already has a modal child
826 c
->_modal_child
= this;
829 // try find a replacement modal dialog
830 Client
*replacement
= 0;
833 while (c
->_transient_for
) // go up the tree
834 c
= c
->_transient_for
;
835 replacement
= c
->findModalChild(this); // find a modal child, skipping this
836 assert(replacement
!= this);
839 while (c
->_transient_for
) {
840 c
= c
->_transient_for
;
841 if (c
== this) break; // circular?
842 if (c
->_modal_child
!= this) break; // has a different modal child
843 if (c
== replacement
) break; // found the replacement itself
844 c
->_modal_child
= replacement
;
851 void Client::setState(StateAction action
, long data1
, long data2
)
853 bool shadestate
= _shaded
;
854 bool fsstate
= _fullscreen
;
855 bool maxh
= _max_horz
;
856 bool maxv
= _max_vert
;
859 if (!(action
== State_Add
|| action
== State_Remove
||
860 action
== State_Toggle
))
861 return; // an invalid action was passed to the client message, ignore it
863 for (int i
= 0; i
< 2; ++i
) {
864 Atom state
= i
== 0 ? data1
: data2
;
866 if (! state
) continue;
868 // if toggling, then pick whether we're adding or removing
869 if (action
== State_Toggle
) {
870 if (state
== otk::Property::atoms
.net_wm_state_modal
)
871 action
= _modal
? State_Remove
: State_Add
;
872 else if (state
== otk::Property::atoms
.net_wm_state_maximized_vert
)
873 action
= _max_vert
? State_Remove
: State_Add
;
874 else if (state
== otk::Property::atoms
.net_wm_state_maximized_horz
)
875 action
= _max_horz
? State_Remove
: State_Add
;
876 else if (state
== otk::Property::atoms
.net_wm_state_shaded
)
877 action
= _shaded
? State_Remove
: State_Add
;
878 else if (state
== otk::Property::atoms
.net_wm_state_skip_taskbar
)
879 action
= _skip_taskbar
? State_Remove
: State_Add
;
880 else if (state
== otk::Property::atoms
.net_wm_state_skip_pager
)
881 action
= _skip_pager
? State_Remove
: State_Add
;
882 else if (state
== otk::Property::atoms
.net_wm_state_fullscreen
)
883 action
= _fullscreen
? State_Remove
: State_Add
;
884 else if (state
== otk::Property::atoms
.net_wm_state_above
)
885 action
= _above
? State_Remove
: State_Add
;
886 else if (state
== otk::Property::atoms
.net_wm_state_below
)
887 action
= _below
? State_Remove
: State_Add
;
890 if (action
== State_Add
) {
891 if (state
== otk::Property::atoms
.net_wm_state_modal
) {
892 if (_modal
) continue;
894 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_vert
) {
896 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_horz
) {
897 if (_max_horz
) continue;
899 } else if (state
== otk::Property::atoms
.net_wm_state_shaded
) {
901 } else if (state
== otk::Property::atoms
.net_wm_state_skip_taskbar
) {
902 _skip_taskbar
= true;
903 } else if (state
== otk::Property::atoms
.net_wm_state_skip_pager
) {
905 } else if (state
== otk::Property::atoms
.net_wm_state_fullscreen
) {
907 } else if (state
== otk::Property::atoms
.net_wm_state_above
) {
908 if (_above
) continue;
910 } else if (state
== otk::Property::atoms
.net_wm_state_below
) {
911 if (_below
) continue;
915 } else { // action == State_Remove
916 if (state
== otk::Property::atoms
.net_wm_state_modal
) {
917 if (!_modal
) continue;
919 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_vert
) {
921 } else if (state
== otk::Property::atoms
.net_wm_state_maximized_horz
) {
923 } else if (state
== otk::Property::atoms
.net_wm_state_shaded
) {
925 } else if (state
== otk::Property::atoms
.net_wm_state_skip_taskbar
) {
926 _skip_taskbar
= false;
927 } else if (state
== otk::Property::atoms
.net_wm_state_skip_pager
) {
929 } else if (state
== otk::Property::atoms
.net_wm_state_fullscreen
) {
931 } else if (state
== otk::Property::atoms
.net_wm_state_above
) {
932 if (!_above
) continue;
934 } else if (state
== otk::Property::atoms
.net_wm_state_below
) {
935 if (!_below
) continue;
940 if (maxh
!= _max_horz
|| maxv
!= _max_vert
) {
941 if (maxh
!= _max_horz
&& maxv
!= _max_vert
) { // toggling both
942 if (maxh
== maxv
) { // both going the same way
943 maximize(maxh
, 0, true);
945 maximize(maxh
, 1, true);
946 maximize(maxv
, 2, true);
948 } else { // toggling one
949 if (maxh
!= _max_horz
)
950 maximize(maxh
, 1, true);
952 maximize(maxv
, 2, true);
957 // change fullscreen state before shading, as it will affect if the window
959 if (fsstate
!= _fullscreen
)
960 fullscreen(fsstate
, true);
961 if (shadestate
!= _shaded
)
964 changeState(); // change the hint to relect these changes
968 void Client::toggleClientBorder(bool addborder
)
970 // adjust our idea of where the client is, based on its border. When the
971 // border is removed, the client should now be considered to be in a
972 // different position.
973 // when re-adding the border to the client, the same operation needs to be
975 int oldx
= _area
.x(), oldy
= _area
.y();
976 int x
= oldx
, y
= oldy
;
979 case NorthWestGravity
:
981 case SouthWestGravity
:
983 case NorthEastGravity
:
985 case SouthEastGravity
:
986 if (addborder
) x
-= _border_width
* 2;
987 else x
+= _border_width
* 2;
994 if (addborder
) x
-= _border_width
;
995 else x
+= _border_width
;
1000 case NorthWestGravity
:
1002 case NorthEastGravity
:
1004 case SouthWestGravity
:
1006 case SouthEastGravity
:
1007 if (addborder
) y
-= _border_width
* 2;
1008 else y
+= _border_width
* 2;
1015 if (addborder
) y
-= _border_width
;
1016 else y
+= _border_width
;
1019 _area
= otk::Rect(otk::Point(x
, y
), _area
.size());
1022 XSetWindowBorderWidth(**otk::display
, _window
, _border_width
);
1024 // move the client so it is back it the right spot _with_ its border!
1025 if (x
!= oldx
|| y
!= oldy
)
1026 XMoveWindow(**otk::display
, _window
, x
, y
);
1028 XSetWindowBorderWidth(**otk::display
, _window
, 0);
1032 void Client::clientMessageHandler(const XClientMessageEvent
&e
)
1034 otk::EventHandler::clientMessageHandler(e
);
1036 // validate cuz we query stuff off the client here
1037 if (!validate()) return;
1039 if (e
.format
!= 32) return;
1041 if (e
.message_type
== otk::Property::atoms
.wm_change_state
) {
1042 // compress changes into a single change
1043 bool compress
= false;
1045 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
1046 // XXX: it would be nice to compress ALL messages of a type, not just
1047 // messages in a row without other message types between.
1048 if (ce
.xclient
.message_type
!= e
.message_type
) {
1049 XPutBackEvent(**otk::display
, &ce
);
1055 setWMState(ce
.xclient
.data
.l
[0]); // use the found event
1057 setWMState(e
.data
.l
[0]); // use the original event
1058 } else if (e
.message_type
== otk::Property::atoms
.net_wm_desktop
) {
1059 // compress changes into a single change
1060 bool compress
= false;
1062 while (XCheckTypedEvent(**otk::display
, e
.type
, &ce
)) {
1063 // XXX: it would be nice to compress ALL messages of a type, not just
1064 // messages in a row without other message types between.
1065 if (ce
.xclient
.message_type
!= e
.message_type
) {
1066 XPutBackEvent(**otk::display
, &ce
);
1072 setDesktop(e
.data
.l
[0]); // use the found event
1074 setDesktop(e
.data
.l
[0]); // use the original event
1075 } else if (e
.message_type
== otk::Property::atoms
.net_wm_state
) {
1076 // can't compress these
1078 printf("net_wm_state %s %ld %ld for 0x%lx\n",
1079 (e
.data
.l
[0] == 0 ? "Remove" : e
.data
.l
[0] == 1 ? "Add" :
1080 e
.data
.l
[0] == 2 ? "Toggle" : "INVALID"),
1081 e
.data
.l
[1], e
.data
.l
[2], _window
);
1083 setState((StateAction
)e
.data
.l
[0], e
.data
.l
[1], e
.data
.l
[2]);
1084 } else if (e
.message_type
== otk::Property::atoms
.net_close_window
) {
1086 printf("net_close_window for 0x%lx\n", _window
);
1089 } else if (e
.message_type
== otk::Property::atoms
.net_active_window
) {
1091 printf("net_active_window for 0x%lx\n", _window
);
1094 setDesktop(openbox
->screen(_screen
)->desktop());
1098 openbox
->screen(_screen
)->raiseWindow(this);
1099 } else if (e
.message_type
== otk::Property::atoms
.openbox_active_window
) {
1101 setDesktop(openbox
->screen(_screen
)->desktop());
1102 if (e
.data
.l
[0] && _shaded
)
1106 openbox
->screen(_screen
)->raiseWindow(this);
1112 void Client::shapeHandler(const XShapeEvent
&e
)
1114 otk::EventHandler::shapeHandler(e
);
1116 if (e
.kind
== ShapeBounding
) {
1118 frame
->adjustShape();
1124 void Client::resize(Corner anchor
, int w
, int h
)
1126 if (!(_functions
& Func_Resize
)) return;
1127 internal_resize(anchor
, w
, h
);
1131 void Client::internal_resize(Corner anchor
, int w
, int h
,
1132 bool user
, int x
, int y
)
1134 w
-= _base_size
.width();
1135 h
-= _base_size
.height();
1138 // for interactive resizing. have to move half an increment in each
1140 int mw
= w
% _size_inc
.width(); // how far we are towards the next size inc
1141 int mh
= h
% _size_inc
.height();
1142 int aw
= _size_inc
.width() / 2; // amount to add
1143 int ah
= _size_inc
.height() / 2;
1144 // don't let us move into a new size increment
1145 if (mw
+ aw
>= _size_inc
.width()) aw
= _size_inc
.width() - mw
- 1;
1146 if (mh
+ ah
>= _size_inc
.height()) ah
= _size_inc
.height() - mh
- 1;
1150 // if this is a user-requested resize, then check against min/max sizes
1151 // and aspect ratios
1153 // smaller than min size or bigger than max size?
1154 if (w
< _min_size
.width()) w
= _min_size
.width();
1155 else if (w
> _max_size
.width()) w
= _max_size
.width();
1156 if (h
< _min_size
.height()) h
= _min_size
.height();
1157 else if (h
> _max_size
.height()) h
= _max_size
.height();
1159 // adjust the height ot match the width for the aspect ratios
1161 if (h
* _min_ratio
> w
) h
= static_cast<int>(w
/ _min_ratio
);
1163 if (h
* _max_ratio
< w
) h
= static_cast<int>(w
/ _max_ratio
);
1166 // keep to the increments
1167 w
/= _size_inc
.width();
1168 h
/= _size_inc
.height();
1170 // you cannot resize to nothing
1174 // store the logical size
1175 _logical_size
= otk::Size(w
, h
);
1177 w
*= _size_inc
.width();
1178 h
*= _size_inc
.height();
1180 w
+= _base_size
.width();
1181 h
+= _base_size
.height();
1183 if (x
== INT_MIN
|| y
== INT_MIN
) {
1190 x
-= w
- _area
.width();
1193 y
-= h
- _area
.height();
1196 x
-= w
- _area
.width();
1197 y
-= h
- _area
.height();
1202 _area
= otk::Rect(_area
.position(), otk::Size(w
, h
));
1204 XResizeWindow(**otk::display
, _window
, w
, h
);
1206 // resize the frame to match the request
1207 frame
->adjustSize();
1208 internal_move(x
, y
);
1212 void Client::move(int x
, int y
)
1214 if (!(_functions
& Func_Move
)) return;
1215 frame
->frameGravity(x
, y
); // get the client's position based on x,y for the
1217 internal_move(x
, y
);
1221 void Client::internal_move(int x
, int y
)
1223 _area
= otk::Rect(otk::Point(x
, y
), _area
.size());
1225 // move the frame to be in the requested position
1226 if (frame
) { // this can be called while mapping, before frame exists
1227 frame
->adjustPosition();
1229 // send synthetic configure notify (we don't need to if we aren't mapped
1232 event
.type
= ConfigureNotify
;
1233 event
.xconfigure
.display
= **otk::display
;
1234 event
.xconfigure
.event
= _window
;
1235 event
.xconfigure
.window
= _window
;
1237 // root window coords with border in mind
1238 event
.xconfigure
.x
= x
- _border_width
+ frame
->size().left
;
1239 event
.xconfigure
.y
= y
- _border_width
+ frame
->size().top
;
1241 event
.xconfigure
.width
= _area
.width();
1242 event
.xconfigure
.height
= _area
.height();
1243 event
.xconfigure
.border_width
= _border_width
;
1244 event
.xconfigure
.above
= frame
->plate();
1245 event
.xconfigure
.override_redirect
= False
;
1246 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
, False
,
1247 StructureNotifyMask
, &event
);
1249 printf("Sent synthetic ConfigureNotify %d,%d %d,%d to 0x%lx\n",
1250 event
.xconfigure
.x
, event
.xconfigure
.y
, event
.xconfigure
.width
,
1251 event
.xconfigure
.height
, event
.xconfigure
.window
);
1257 void Client::close()
1261 if (!(_functions
& Func_Close
)) return;
1263 // XXX: itd be cool to do timeouts and shit here for killing the client's
1265 // like... if the window is around after 5 seconds, then the close button
1266 // turns a nice red, and if this function is called again, the client is
1267 // explicitly killed.
1269 ce
.xclient
.type
= ClientMessage
;
1270 ce
.xclient
.message_type
= otk::Property::atoms
.wm_protocols
;
1271 ce
.xclient
.display
= **otk::display
;
1272 ce
.xclient
.window
= _window
;
1273 ce
.xclient
.format
= 32;
1274 ce
.xclient
.data
.l
[0] = otk::Property::atoms
.wm_delete_window
;
1275 ce
.xclient
.data
.l
[1] = CurrentTime
;
1276 ce
.xclient
.data
.l
[2] = 0l;
1277 ce
.xclient
.data
.l
[3] = 0l;
1278 ce
.xclient
.data
.l
[4] = 0l;
1279 XSendEvent(**otk::display
, _window
, false, NoEventMask
, &ce
);
1283 void Client::changeState()
1285 unsigned long state
[2];
1286 state
[0] = _wmstate
;
1288 otk::Property::set(_window
, otk::Property::atoms
.wm_state
,
1289 otk::Property::atoms
.wm_state
, state
, 2);
1294 netstate
[num
++] = otk::Property::atoms
.net_wm_state_modal
;
1296 netstate
[num
++] = otk::Property::atoms
.net_wm_state_shaded
;
1298 netstate
[num
++] = otk::Property::atoms
.net_wm_state_hidden
;
1300 netstate
[num
++] = otk::Property::atoms
.net_wm_state_skip_taskbar
;
1302 netstate
[num
++] = otk::Property::atoms
.net_wm_state_skip_pager
;
1304 netstate
[num
++] = otk::Property::atoms
.net_wm_state_fullscreen
;
1306 netstate
[num
++] = otk::Property::atoms
.net_wm_state_maximized_vert
;
1308 netstate
[num
++] = otk::Property::atoms
.net_wm_state_maximized_horz
;
1310 netstate
[num
++] = otk::Property::atoms
.net_wm_state_above
;
1312 netstate
[num
++] = otk::Property::atoms
.net_wm_state_below
;
1313 otk::Property::set(_window
, otk::Property::atoms
.net_wm_state
,
1314 otk::Property::atoms
.atom
, netstate
, num
);
1319 frame
->adjustState();
1323 void Client::changeAllowedActions(void)
1328 actions
[num
++] = otk::Property::atoms
.net_wm_action_change_desktop
;
1330 if (_functions
& Func_Shade
)
1331 actions
[num
++] = otk::Property::atoms
.net_wm_action_shade
;
1332 if (_functions
& Func_Close
)
1333 actions
[num
++] = otk::Property::atoms
.net_wm_action_close
;
1334 if (_functions
& Func_Move
)
1335 actions
[num
++] = otk::Property::atoms
.net_wm_action_move
;
1336 if (_functions
& Func_Iconify
)
1337 actions
[num
++] = otk::Property::atoms
.net_wm_action_minimize
;
1338 if (_functions
& Func_Resize
)
1339 actions
[num
++] = otk::Property::atoms
.net_wm_action_resize
;
1340 if (_functions
& Func_Fullscreen
)
1341 actions
[num
++] = otk::Property::atoms
.net_wm_action_fullscreen
;
1342 if (_functions
& Func_Maximize
) {
1343 actions
[num
++] = otk::Property::atoms
.net_wm_action_maximize_horz
;
1344 actions
[num
++] = otk::Property::atoms
.net_wm_action_maximize_vert
;
1347 otk::Property::set(_window
, otk::Property::atoms
.net_wm_allowed_actions
,
1348 otk::Property::atoms
.atom
, actions
, num
);
1350 // make sure the window isn't breaking any rules now
1352 if (!(_functions
& Func_Shade
) && _shaded
)
1353 if (frame
) shade(false);
1354 else _shaded
= false;
1355 if (!(_functions
& Func_Iconify
) && _iconic
)
1356 if (frame
) setDesktop(openbox
->screen(_screen
)->desktop());
1357 else _iconic
= false;
1358 if (!(_functions
& Func_Fullscreen
) && _fullscreen
)
1359 if (frame
) fullscreen(false);
1360 else _fullscreen
= false;
1361 if (!(_functions
& Func_Maximize
) && (_max_horz
|| _max_vert
))
1362 if (frame
) maximize(false, 0);
1363 else _max_vert
= _max_horz
= false;
1367 void Client::remaximize()
1370 if (_max_horz
&& _max_vert
)
1377 return; // not maximized
1378 _max_horz
= _max_vert
= false;
1379 maximize(true, dir
, false);
1383 void Client::applyStartupState()
1385 // these are in a carefully crafted order..
1394 setDesktop(ICONIC_DESKTOP
);
1397 _fullscreen
= false;
1398 fullscreen(true, false);
1407 if (_max_vert
&& _max_horz
) {
1408 _max_vert
= _max_horz
= false;
1409 maximize(true, 0, false);
1410 } else if (_max_vert
) {
1412 maximize(true, 2, false);
1413 } else if (_max_horz
) {
1415 maximize(true, 1, false);
1418 if (_skip_taskbar
); // nothing to do for this
1419 if (_skip_pager
); // nothing to do for this
1420 if (_modal
); // nothing to do for this
1421 if (_above
); // nothing to do for this
1422 if (_below
); // nothing to do for this
1426 void Client::fireUrgent()
1428 // call the python UrgentWindow callbacks
1429 EventData
data(_screen
, this, EventAction::UrgentWindow
, 0);
1430 openbox
->bindings()->fireEvent(&data
);
1434 void Client::shade(bool shade
)
1436 if (!(_functions
& Func_Shade
) || // can't
1437 _shaded
== shade
) return; // already done
1439 // when we're iconic, don't change the wmstate
1441 _wmstate
= shade
? IconicState
: NormalState
;
1444 frame
->adjustSize();
1448 void Client::maximize(bool max
, int dir
, bool savearea
)
1450 assert(dir
== 0 || dir
== 1 || dir
== 2);
1451 if (!(_functions
& Func_Maximize
)) return; // can't
1453 // check if already done
1455 if (dir
== 0 && _max_horz
&& _max_vert
) return;
1456 if (dir
== 1 && _max_horz
) return;
1457 if (dir
== 2 && _max_vert
) return;
1459 if (dir
== 0 && !_max_horz
&& !_max_vert
) return;
1460 if (dir
== 1 && !_max_horz
) return;
1461 if (dir
== 2 && !_max_vert
) return;
1464 const otk::Rect
&a
= openbox
->screen(_screen
)->area();
1465 int x
= frame
->area().x(), y
= frame
->area().y(),
1466 w
= _area
.width(), h
= _area
.height();
1472 unsigned long n
= 4;
1479 // get the property off the window and use it for the dimentions we are
1481 if (otk::Property::get(_window
, otk::Property::atoms
.openbox_premax
,
1482 otk::Property::atoms
.cardinal
, &n
,
1483 (long unsigned**) &readdim
)) {
1486 dimensions
[0] = readdim
[0];
1487 dimensions
[2] = readdim
[2];
1490 dimensions
[1] = readdim
[1];
1491 dimensions
[3] = readdim
[3];
1497 otk::Property::set(_window
, otk::Property::atoms
.openbox_premax
,
1498 otk::Property::atoms
.cardinal
,
1499 (long unsigned*)dimensions
, 4);
1501 if (dir
== 0 || dir
== 1) { // horz
1505 if (dir
== 0 || dir
== 2) { // vert
1507 h
= a
.height() - frame
->size().top
- frame
->size().bottom
;
1511 long unsigned n
= 4;
1513 if (otk::Property::get(_window
, otk::Property::atoms
.openbox_premax
,
1514 otk::Property::atoms
.cardinal
, &n
,
1515 (long unsigned**) &dimensions
)) {
1517 if (dir
== 0 || dir
== 1) { // horz
1518 x
= (signed int)dimensions
[0];
1519 w
= (signed int)dimensions
[2];
1521 if (dir
== 0 || dir
== 2) { // vert
1522 y
= (signed int)dimensions
[1];
1523 h
= (signed int)dimensions
[3];
1528 // pick some fallbacks...
1529 if (dir
== 0 || dir
== 1) { // horz
1530 x
= a
.x() + a
.width() / 4;
1533 if (dir
== 0 || dir
== 2) { // vert
1534 y
= a
.y() + a
.height() / 4;
1540 if (dir
== 0 || dir
== 1) // horz
1542 if (dir
== 0 || dir
== 2) // vert
1545 if (!_max_horz
&& !_max_vert
)
1546 otk::Property::erase(_window
, otk::Property::atoms
.openbox_premax
);
1548 changeState(); // change the state hints on the client
1550 frame
->frameGravity(x
, y
); // figure out where the client should be going
1551 internal_resize(TopLeft
, w
, h
, true, x
, y
);
1555 void Client::fullscreen(bool fs
, bool savearea
)
1557 static FunctionFlags saved_func
;
1558 static DecorationFlags saved_decor
;
1560 if (!(_functions
& Func_Fullscreen
) || // can't
1561 _fullscreen
== fs
) return; // already done
1564 changeState(); // change the state hints on the client
1566 int x
= _area
.x(), y
= _area
.y(), w
= _area
.width(), h
= _area
.height();
1569 // save the functions and remove them
1570 saved_func
= _functions
;
1571 _functions
= _functions
& (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1572 // save the decorations and remove them
1573 saved_decor
= _decorations
;
1577 dimensions
[0] = _area
.x();
1578 dimensions
[1] = _area
.y();
1579 dimensions
[2] = _area
.width();
1580 dimensions
[3] = _area
.height();
1581 otk::Property::set(_window
, otk::Property::atoms
.openbox_premax
,
1582 otk::Property::atoms
.cardinal
,
1583 (long unsigned*)dimensions
, 4);
1585 const otk::ScreenInfo
*info
= otk::display
->screenInfo(_screen
);
1588 w
= info
->size().width();
1589 h
= info
->size().height();
1591 _functions
= saved_func
;
1592 _decorations
= saved_decor
;
1595 long unsigned n
= 4;
1597 if (otk::Property::get(_window
, otk::Property::atoms
.openbox_premax
,
1598 otk::Property::atoms
.cardinal
, &n
,
1599 (long unsigned**) &dimensions
)) {
1608 // pick some fallbacks...
1609 const otk::Rect
&a
= openbox
->screen(_screen
)->area();
1610 x
= a
.x() + a
.width() / 4;
1611 y
= a
.y() + a
.height() / 4;
1617 changeAllowedActions(); // based on the new _functions
1619 // when fullscreening, don't obey things like increments, fill the screen
1620 internal_resize(TopLeft
, w
, h
, !fs
, x
, y
);
1622 // raise (back) into our stacking layer
1623 openbox
->screen(_screen
)->raiseWindow(this);
1625 // try focus us when we go into fullscreen mode
1630 void Client::disableDecorations(DecorationFlags flags
)
1632 _disabled_decorations
= flags
;
1633 setupDecorAndFunctions();
1637 void Client::installColormap(bool install
) const
1639 XWindowAttributes wa
;
1640 if (XGetWindowAttributes(**otk::display
, _window
, &wa
)) {
1642 XInstallColormap(**otk::display
, wa
.colormap
);
1644 XUninstallColormap(**otk::display
, wa
.colormap
);
1649 bool Client::focus()
1651 // if we have a modal child, then focus it, not us
1653 return _modal_child
->focus();
1655 // won't try focus if the client doesn't want it, or if the window isn't
1656 // visible on the screen
1657 if (!(frame
->visible() && (_can_focus
|| _focus_notify
))) return false;
1659 if (_focused
) return true;
1661 // do a check to see if the window has already been unmapped or destroyed
1662 // do this intelligently while watching out for unmaps we've generated
1663 // (ignore_unmaps > 0)
1665 if (XCheckTypedWindowEvent(**otk::display
, _window
, DestroyNotify
, &ev
)) {
1666 XPutBackEvent(**otk::display
, &ev
);
1669 while (XCheckTypedWindowEvent(**otk::display
, _window
, UnmapNotify
, &ev
)) {
1670 if (ignore_unmaps
) {
1671 unmapHandler(ev
.xunmap
);
1673 XPutBackEvent(**otk::display
, &ev
);
1679 XSetInputFocus(**otk::display
, _window
,
1680 RevertToNone
, CurrentTime
);
1682 if (_focus_notify
) {
1684 ce
.xclient
.type
= ClientMessage
;
1685 ce
.xclient
.message_type
= otk::Property::atoms
.wm_protocols
;
1686 ce
.xclient
.display
= **otk::display
;
1687 ce
.xclient
.window
= _window
;
1688 ce
.xclient
.format
= 32;
1689 ce
.xclient
.data
.l
[0] = otk::Property::atoms
.wm_take_focus
;
1690 ce
.xclient
.data
.l
[1] = openbox
->lastTime();
1691 ce
.xclient
.data
.l
[2] = 0l;
1692 ce
.xclient
.data
.l
[3] = 0l;
1693 ce
.xclient
.data
.l
[4] = 0l;
1694 XSendEvent(**otk::display
, _window
, False
, NoEventMask
, &ce
);
1697 XSync(**otk::display
, False
);
1702 void Client::unfocus() const
1704 if (!_focused
) return;
1706 assert(openbox
->focusedClient() == this);
1707 openbox
->setFocusedClient(0);
1711 void Client::focusHandler(const XFocusChangeEvent
&e
)
1714 // printf("FocusIn for 0x%lx\n", e.window);
1717 otk::EventHandler::focusHandler(e
);
1720 frame
->adjustFocus();
1722 openbox
->setFocusedClient(this);
1726 void Client::unfocusHandler(const XFocusChangeEvent
&e
)
1729 // printf("FocusOut for 0x%lx\n", e.window);
1732 otk::EventHandler::unfocusHandler(e
);
1735 frame
->adjustFocus();
1737 if (openbox
->focusedClient() == this)
1738 openbox
->setFocusedClient(0);
1742 void Client::configureRequestHandler(const XConfigureRequestEvent
&ec
)
1745 printf("ConfigureRequest for 0x%lx\n", ec
.window
);
1748 otk::EventHandler::configureRequestHandler(ec
);
1751 XConfigureRequestEvent e
= ec
;
1753 while (XCheckTypedWindowEvent(**otk::display
, window(), ConfigureRequest
,
1755 // XXX if this causes bad things.. we can compress config req's with the
1757 e
.value_mask
|= ev
.xconfigurerequest
.value_mask
;
1758 if (ev
.xconfigurerequest
.value_mask
& CWX
)
1759 e
.x
= ev
.xconfigurerequest
.x
;
1760 if (ev
.xconfigurerequest
.value_mask
& CWY
)
1761 e
.y
= ev
.xconfigurerequest
.y
;
1762 if (ev
.xconfigurerequest
.value_mask
& CWWidth
)
1763 e
.width
= ev
.xconfigurerequest
.width
;
1764 if (ev
.xconfigurerequest
.value_mask
& CWHeight
)
1765 e
.height
= ev
.xconfigurerequest
.height
;
1766 if (ev
.xconfigurerequest
.value_mask
& CWBorderWidth
)
1767 e
.border_width
= ev
.xconfigurerequest
.border_width
;
1768 if (ev
.xconfigurerequest
.value_mask
& CWStackMode
)
1769 e
.detail
= ev
.xconfigurerequest
.detail
;
1772 // if we are iconic (or shaded (fvwm does this)) ignore the event
1773 if (_iconic
|| _shaded
) return;
1775 if (e
.value_mask
& CWBorderWidth
)
1776 _border_width
= e
.border_width
;
1778 // resize, then move, as specified in the EWMH section 7.7
1779 if (e
.value_mask
& (CWWidth
| CWHeight
)) {
1780 int w
= (e
.value_mask
& CWWidth
) ? e
.width
: _area
.width();
1781 int h
= (e
.value_mask
& CWHeight
) ? e
.height
: _area
.height();
1785 case NorthEastGravity
:
1789 case SouthWestGravity
:
1791 corner
= BottomLeft
;
1793 case SouthEastGravity
:
1794 corner
= BottomRight
;
1796 default: // NorthWest, Static, etc
1800 // if moving AND resizing ...
1801 if (e
.value_mask
& (CWX
| CWY
)) {
1802 int x
= (e
.value_mask
& CWX
) ? e
.x
: _area
.x();
1803 int y
= (e
.value_mask
& CWY
) ? e
.y
: _area
.y();
1804 internal_resize(corner
, w
, h
, false, x
, y
);
1805 } else // if JUST resizing...
1806 internal_resize(corner
, w
, h
, false);
1807 } else if (e
.value_mask
& (CWX
| CWY
)) { // if JUST moving...
1808 int x
= (e
.value_mask
& CWX
) ? e
.x
: _area
.x();
1809 int y
= (e
.value_mask
& CWY
) ? e
.y
: _area
.y();
1810 internal_move(x
, y
);
1813 if (e
.value_mask
& CWStackMode
) {
1817 openbox
->screen(_screen
)->lowerWindow(this);
1823 openbox
->screen(_screen
)->raiseWindow(this);
1830 void Client::unmapHandler(const XUnmapEvent
&e
)
1832 if (ignore_unmaps
) {
1834 // printf("Ignored UnmapNotify for 0x%lx (event 0x%lx)\n", e.window, e.event);
1841 printf("UnmapNotify for 0x%lx\n", e
.window
);
1844 otk::EventHandler::unmapHandler(e
);
1846 // this deletes us etc
1847 openbox
->screen(_screen
)->unmanageWindow(this);
1851 void Client::destroyHandler(const XDestroyWindowEvent
&e
)
1854 printf("DestroyNotify for 0x%lx\n", e
.window
);
1857 otk::EventHandler::destroyHandler(e
);
1859 // this deletes us etc
1860 openbox
->screen(_screen
)->unmanageWindow(this);
1864 void Client::reparentHandler(const XReparentEvent
&e
)
1866 // this is when the client is first taken captive in the frame
1867 if (e
.parent
== frame
->plate()) return;
1870 printf("ReparentNotify for 0x%lx\n", e
.window
);
1873 otk::EventHandler::reparentHandler(e
);
1876 This event is quite rare and is usually handled in unmapHandler.
1877 However, if the window is unmapped when the reparent event occurs,
1878 the window manager never sees it because an unmap event is not sent
1879 to an already unmapped window.
1882 // we don't want the reparent event, put it back on the stack for the X
1883 // server to deal with after we unmanage the window
1886 XPutBackEvent(**otk::display
, &ev
);
1888 // this deletes us etc
1889 openbox
->screen(_screen
)->unmanageWindow(this);
1892 void Client::mapRequestHandler(const XMapRequestEvent
&e
)
1895 printf("MapRequest for already managed 0x%lx\n", e
.window
);
1898 assert(_iconic
); // we shouldn't be able to get this unless we're iconic
1900 // move to the current desktop (uniconify)
1901 setDesktop(openbox
->screen(_screen
)->desktop());
1902 // XXX: should we focus/raise the window? (basically a net_wm_active_window)