1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Window.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh at debian.org>
4 // Copyright (c) 1997 - 2000, 2002 Brad Hughes <bhughes at trolltech.com>
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
25 # include "../config.h"
26 #endif // HAVE_CONFIG_H
29 #include <X11/Xatom.h>
30 #include <X11/keysym.h>
34 #endif // HAVE_STRING_H
39 # endif // HAVE_STDIO_H
46 #include "blackbox.hh"
49 #include "Iconmenu.hh"
55 #include "Windowmenu.hh"
56 #include "Workspace.hh"
62 * Initializes the class with default values/the window's set initial values.
64 BlackboxWindow::BlackboxWindow(Blackbox
*b
, Window w
, BScreen
*s
) {
65 // fprintf(stderr, "BlackboxWindow size: %d bytes\n",
66 // sizeof(BlackboxWindow));
69 fprintf(stderr
, "BlackboxWindow::BlackboxWindow(): creating 0x%lx\n", w
);
73 set timer to zero... it is initialized properly later, so we check
74 if timer is zero in the destructor, and assume that the window is not
75 fully constructed if timer is zero...
81 xatom
= blackbox
->getXAtom();
83 if (! validateClient()) {
88 // set the eventmask early in the game so that we make sure we get
89 // all the events we are interested in
90 XSetWindowAttributes attrib_set
;
91 attrib_set
.event_mask
= PropertyChangeMask
| FocusChangeMask
|
93 attrib_set
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
95 XChangeWindowAttributes(blackbox
->getXDisplay(), client
.window
,
96 CWEventMask
|CWDontPropagate
, &attrib_set
);
98 // fetch client size and placement
99 XWindowAttributes wattrib
;
100 if ((! XGetWindowAttributes(blackbox
->getXDisplay(),
101 client
.window
, &wattrib
)) ||
102 (! wattrib
.screen
) || wattrib
.override_redirect
) {
105 "BlackboxWindow::BlackboxWindow(): XGetWindowAttributes failed\n");
112 flags
.moving
= flags
.resizing
= flags
.shaded
= flags
.visible
=
113 flags
.iconic
= flags
.focused
= flags
.stuck
= flags
.modal
=
114 flags
.send_focus_message
= flags
.shaped
= flags
.skip_taskbar
=
115 flags
.skip_pager
= flags
.fullscreen
= False
;
118 blackbox_attrib
.workspace
= window_number
= BSENTINEL
;
120 blackbox_attrib
.flags
= blackbox_attrib
.attrib
= blackbox_attrib
.stack
121 = blackbox_attrib
.decoration
= 0l;
122 blackbox_attrib
.premax_x
= blackbox_attrib
.premax_y
= 0;
123 blackbox_attrib
.premax_w
= blackbox_attrib
.premax_h
= 0;
126 frame
.window
= frame
.plate
= frame
.title
= frame
.handle
= None
;
127 frame
.close_button
= frame
.iconify_button
= frame
.maximize_button
= None
;
128 frame
.right_grip
= frame
.left_grip
= None
;
130 frame
.ulabel_pixel
= frame
.flabel_pixel
= frame
.utitle_pixel
=
131 frame
.ftitle_pixel
= frame
.uhandle_pixel
= frame
.fhandle_pixel
=
132 frame
.ubutton_pixel
= frame
.fbutton_pixel
= frame
.pbutton_pixel
=
133 frame
.uborder_pixel
= frame
.fborder_pixel
= frame
.ugrip_pixel
=
134 frame
.fgrip_pixel
= 0;
135 frame
.utitle
= frame
.ftitle
= frame
.uhandle
= frame
.fhandle
= None
;
136 frame
.ulabel
= frame
.flabel
= frame
.ubutton
= frame
.fbutton
= None
;
137 frame
.pbutton
= frame
.ugrip
= frame
.fgrip
= decorations
;
139 decorations
= Decor_Titlebar
| Decor_Border
| Decor_Handle
|
140 Decor_Iconify
| Decor_Maximize
;
141 functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
;
143 client
.wm_hint_flags
= client
.normal_hint_flags
= 0;
144 client
.transient_for
= 0;
147 get the initial size and location of client window (relative to the
148 _root window_). This position is the reference point used with the
149 window's gravity to find the window's initial position.
151 client
.rect
.setRect(wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
152 client
.old_bw
= wattrib
.border_width
;
155 lastButtonPressTime
= 0;
157 timer
= new BTimer(blackbox
, this);
158 timer
->setTimeout(blackbox
->getAutoRaiseDelay());
160 if (! getBlackboxHints()) {
165 // get size, aspect, minimum/maximum size and other hints set by the
171 if (client
.initial_state
== WithdrawnState
) {
172 screen
->getSlit()->addClient(client
.window
);
177 if (isKDESystrayWindow()) {
178 screen
->addSystrayWindow(client
.window
);
183 frame
.window
= createToplevelWindow();
184 frame
.plate
= createChildWindow(frame
.window
);
185 associateClientWindow();
187 blackbox
->saveWindowSearch(frame
.window
, this);
188 blackbox
->saveWindowSearch(frame
.plate
, this);
189 blackbox
->saveWindowSearch(client
.window
, this);
191 screen
->addStrut(&client
.strut
);
194 // determine if this is a transient window
197 // determine the window's type, so we can decide its decorations and
198 // functionality, or if we should not manage it at all
201 // adjust the window decorations/behavior based on the window type
202 switch (window_type
) {
204 // desktop windows are not managed by us, we just make sure they stay on the
209 // docks (such as kicker) cannot be moved, and appear on all workspaces
210 functions
&= ~(Func_Move
);
215 // these windows have minimal decorations, only a titlebar, and cannot
216 // be resized or iconified
217 decorations
&= ~(Decor_Maximize
| Decor_Handle
| Decor_Border
|
219 functions
&= ~(Func_Resize
| Func_Maximize
| Func_Iconify
);
223 // splash screens have no functionality or decorations, they are left up
224 // to the application which created them
230 // dialogs cannot be maximized, and don't display a handle
231 decorations
&= ~(Decor_Maximize
| Decor_Handle
);
232 functions
&= ~Func_Maximize
;
236 // normal windows retain all of the possible decorations and functionality
240 // further adjeust the window's decorations/behavior based on window sizes
241 if ((client
.normal_hint_flags
& PMinSize
) &&
242 (client
.normal_hint_flags
& PMaxSize
) &&
243 client
.max_width
<= client
.min_width
&&
244 client
.max_height
<= client
.min_height
) {
245 decorations
&= ~(Decor_Maximize
| Decor_Handle
);
246 functions
&= ~(Func_Resize
| Func_Maximize
);
252 bool place_window
= True
;
253 if (blackbox
->isStartup() || isTransient() ||
254 client
.normal_hint_flags
& (PPosition
|USPosition
)) {
255 applyGravity(frame
.rect
);
257 if (blackbox
->isStartup() ||
258 client
.rect
.intersects(screen
->availableArea()))
259 place_window
= False
;
262 if (decorations
& Decor_Titlebar
)
265 if (decorations
& Decor_Handle
)
269 if (blackbox
->hasShapeExtensions() && flags
.shaped
) {
274 if ((! screen
->isSloppyFocus()) || screen
->doClickRaise()) {
275 // grab button 1 for changing focus/raising
276 blackbox
->grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
277 GrabModeSync
, GrabModeSync
, None
, None
);
280 if (functions
& Func_Move
)
281 blackbox
->grabButton(Button1
, Mod1Mask
, frame
.window
, True
,
282 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
283 GrabModeAsync
, frame
.window
,
284 blackbox
->getMoveCursor());
285 blackbox
->grabButton(Button2
, Mod1Mask
, frame
.window
, True
,
286 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
,
288 if (functions
& Func_Resize
)
289 blackbox
->grabButton(Button3
, Mod1Mask
, frame
.window
, True
,
290 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
292 blackbox
->getLowerRightAngleCursor());
297 if (decorations
& Decor_Titlebar
)
298 XMapSubwindows(blackbox
->getXDisplay(), frame
.title
);
299 XMapSubwindows(blackbox
->getXDisplay(), frame
.window
);
301 windowmenu
= new Windowmenu(this);
303 if (blackbox_attrib
.workspace
>= screen
->getWorkspaceCount())
304 screen
->getCurrentWorkspace()->addWindow(this, place_window
);
306 screen
->getWorkspace(blackbox_attrib
.workspace
)->
307 addWindow(this, place_window
);
309 if (! place_window
) {
310 // don't need to call configure if we are letting the workspace
312 configure(frame
.rect
.x(), frame
.rect
.y(),
313 frame
.rect
.width(), frame
.rect
.height());
316 // preserve the window's initial state on first map, and its current state
319 if (client
.wm_hint_flags
& StateHint
)
320 current_state
= client
.initial_state
;
322 current_state
= NormalState
;
325 // get sticky state from our parent window if we've got one
326 if (isTransient() && client
.transient_for
!= (BlackboxWindow
*) ~0ul &&
327 client
.transient_for
->isStuck() != flags
.stuck
)
331 flags
.shaded
= False
;
335 Because the iconic'ness of shaded windows is lost, we need to set the
336 state to NormalState so that shaded windows on other workspaces will not
337 get shown on the first workspace.
338 At this point in the life of a window, current_state should only be set
339 to IconicState if the window was an *icon*, not if it was shaded.
341 current_state
= NormalState
;
349 if (flags
.maximized
&& (functions
& Func_Maximize
)) {
354 When the window is mapped (and also when its attributes are restored), the
355 current_state that was set here will be used.
356 It is set to Normal if the window is to be mapped or it is set to Iconic
357 if the window is to be iconified.
358 *Note* that for sticky windows, the same rules apply here, they are in
359 fact never set to Iconic since there is no way for us to tell if a sticky
360 window was iconified previously.
367 BlackboxWindow::~BlackboxWindow(void) {
369 fprintf(stderr
, "BlackboxWindow::~BlackboxWindow: destroying 0x%lx\n",
373 if (! timer
) // window not managed...
376 screen
->removeStrut(&client
.strut
);
377 screen
->updateAvailableArea();
379 // We don't need to worry about resizing because resizing always grabs the X
380 // server. This should only ever happen if using opaque moving.
388 if (client
.window_group
) {
389 BWindowGroup
*group
= blackbox
->searchGroup(client
.window_group
);
390 if (group
) group
->removeWindow(this);
393 // remove ourselves from our transient_for
395 if (client
.transient_for
!= (BlackboxWindow
*) ~0ul) {
396 client
.transient_for
->client
.transientList
.remove(this);
398 client
.transient_for
= (BlackboxWindow
*) 0;
401 if (client
.transientList
.size() > 0) {
402 // reset transient_for for all transients
403 BlackboxWindowList::iterator it
, end
= client
.transientList
.end();
404 for (it
= client
.transientList
.begin(); it
!= end
; ++it
) {
405 (*it
)->client
.transient_for
= (BlackboxWindow
*) 0;
416 blackbox
->removeWindowSearch(frame
.plate
);
417 XDestroyWindow(blackbox
->getXDisplay(), frame
.plate
);
421 blackbox
->removeWindowSearch(frame
.window
);
422 XDestroyWindow(blackbox
->getXDisplay(), frame
.window
);
425 blackbox
->removeWindowSearch(client
.window
);
430 * Creates a new top level window, with a given location, size, and border
432 * Returns: the newly created window
434 Window
BlackboxWindow::createToplevelWindow(void) {
435 XSetWindowAttributes attrib_create
;
436 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
| CWColormap
|
437 CWOverrideRedirect
| CWEventMask
;
439 attrib_create
.background_pixmap
= None
;
440 attrib_create
.colormap
= screen
->getColormap();
441 attrib_create
.override_redirect
= True
;
442 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
443 ButtonMotionMask
| EnterWindowMask
;
445 return XCreateWindow(blackbox
->getXDisplay(), screen
->getRootWindow(),
446 -1, -1, 1, 1, frame
.border_w
, screen
->getDepth(),
447 InputOutput
, screen
->getVisual(), create_mask
,
453 * Creates a child window, and optionally associates a given cursor with
456 Window
BlackboxWindow::createChildWindow(Window parent
, Cursor cursor
) {
457 XSetWindowAttributes attrib_create
;
458 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
|
461 attrib_create
.background_pixmap
= None
;
462 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
463 ButtonMotionMask
| ExposureMask
;
466 create_mask
|= CWCursor
;
467 attrib_create
.cursor
= cursor
;
470 return XCreateWindow(blackbox
->getXDisplay(), parent
, 0, 0, 1, 1, 0,
471 screen
->getDepth(), InputOutput
, screen
->getVisual(),
472 create_mask
, &attrib_create
);
476 void BlackboxWindow::associateClientWindow(void) {
477 XSetWindowBorderWidth(blackbox
->getXDisplay(), client
.window
, 0);
481 XChangeSaveSet(blackbox
->getXDisplay(), client
.window
, SetModeInsert
);
483 XSelectInput(blackbox
->getXDisplay(), frame
.plate
, SubstructureRedirectMask
);
485 XGrabServer(blackbox
->getXDisplay());
486 XSelectInput(blackbox
->getXDisplay(), client
.window
, NoEventMask
);
487 XReparentWindow(blackbox
->getXDisplay(), client
.window
, frame
.plate
, 0, 0);
488 XSelectInput(blackbox
->getXDisplay(), client
.window
,
489 PropertyChangeMask
| FocusChangeMask
| StructureNotifyMask
);
490 XUngrabServer(blackbox
->getXDisplay());
492 XRaiseWindow(blackbox
->getXDisplay(), frame
.plate
);
493 XMapSubwindows(blackbox
->getXDisplay(), frame
.plate
);
497 if (blackbox
->hasShapeExtensions()) {
498 XShapeSelectInput(blackbox
->getXDisplay(), client
.window
,
505 XShapeQueryExtents(blackbox
->getXDisplay(), client
.window
, &shaped
,
506 &foo
, &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
,
508 flags
.shaped
= shaped
;
514 void BlackboxWindow::decorate(void) {
517 texture
= &(screen
->getWindowStyle()->b_focus
);
518 frame
.fbutton
= texture
->render(frame
.button_w
, frame
.button_w
,
521 frame
.fbutton_pixel
= texture
->color().pixel();
523 texture
= &(screen
->getWindowStyle()->b_unfocus
);
524 frame
.ubutton
= texture
->render(frame
.button_w
, frame
.button_w
,
527 frame
.ubutton_pixel
= texture
->color().pixel();
529 texture
= &(screen
->getWindowStyle()->b_pressed
);
530 frame
.pbutton
= texture
->render(frame
.button_w
, frame
.button_w
,
533 frame
.pbutton_pixel
= texture
->color().pixel();
535 if (decorations
& Decor_Titlebar
) {
536 texture
= &(screen
->getWindowStyle()->t_focus
);
537 frame
.ftitle
= texture
->render(frame
.inside_w
, frame
.title_h
,
540 frame
.ftitle_pixel
= texture
->color().pixel();
542 texture
= &(screen
->getWindowStyle()->t_unfocus
);
543 frame
.utitle
= texture
->render(frame
.inside_w
, frame
.title_h
,
546 frame
.utitle_pixel
= texture
->color().pixel();
548 XSetWindowBorder(blackbox
->getXDisplay(), frame
.title
,
549 screen
->getBorderColor()->pixel());
554 if (decorations
& Decor_Border
) {
555 frame
.fborder_pixel
= screen
->getWindowStyle()->f_focus
.pixel();
556 frame
.uborder_pixel
= screen
->getWindowStyle()->f_unfocus
.pixel();
557 blackbox_attrib
.flags
|= AttribDecoration
;
558 blackbox_attrib
.decoration
= DecorNormal
;
560 blackbox_attrib
.flags
|= AttribDecoration
;
561 blackbox_attrib
.decoration
= DecorNone
;
564 if (decorations
& Decor_Handle
) {
565 texture
= &(screen
->getWindowStyle()->h_focus
);
566 frame
.fhandle
= texture
->render(frame
.inside_w
, frame
.handle_h
,
569 frame
.fhandle_pixel
= texture
->color().pixel();
571 texture
= &(screen
->getWindowStyle()->h_unfocus
);
572 frame
.uhandle
= texture
->render(frame
.inside_w
, frame
.handle_h
,
575 frame
.uhandle_pixel
= texture
->color().pixel();
577 texture
= &(screen
->getWindowStyle()->g_focus
);
578 frame
.fgrip
= texture
->render(frame
.grip_w
, frame
.handle_h
, frame
.fgrip
);
580 frame
.fgrip_pixel
= texture
->color().pixel();
582 texture
= &(screen
->getWindowStyle()->g_unfocus
);
583 frame
.ugrip
= texture
->render(frame
.grip_w
, frame
.handle_h
, frame
.ugrip
);
585 frame
.ugrip_pixel
= texture
->color().pixel();
587 XSetWindowBorder(blackbox
->getXDisplay(), frame
.handle
,
588 screen
->getBorderColor()->pixel());
589 XSetWindowBorder(blackbox
->getXDisplay(), frame
.left_grip
,
590 screen
->getBorderColor()->pixel());
591 XSetWindowBorder(blackbox
->getXDisplay(), frame
.right_grip
,
592 screen
->getBorderColor()->pixel());
595 XSetWindowBorder(blackbox
->getXDisplay(), frame
.window
,
596 screen
->getBorderColor()->pixel());
600 void BlackboxWindow::decorateLabel(void) {
603 texture
= &(screen
->getWindowStyle()->l_focus
);
604 frame
.flabel
= texture
->render(frame
.label_w
, frame
.label_h
, frame
.flabel
);
606 frame
.flabel_pixel
= texture
->color().pixel();
608 texture
= &(screen
->getWindowStyle()->l_unfocus
);
609 frame
.ulabel
= texture
->render(frame
.label_w
, frame
.label_h
, frame
.ulabel
);
611 frame
.ulabel_pixel
= texture
->color().pixel();
615 void BlackboxWindow::createHandle(void) {
616 frame
.handle
= createChildWindow(frame
.window
);
617 blackbox
->saveWindowSearch(frame
.handle
, this);
620 createChildWindow(frame
.handle
, blackbox
->getLowerLeftAngleCursor());
621 blackbox
->saveWindowSearch(frame
.left_grip
, this);
624 createChildWindow(frame
.handle
, blackbox
->getLowerRightAngleCursor());
625 blackbox
->saveWindowSearch(frame
.right_grip
, this);
629 void BlackboxWindow::destroyHandle(void) {
631 screen
->getImageControl()->removeImage(frame
.fhandle
);
634 screen
->getImageControl()->removeImage(frame
.uhandle
);
637 screen
->getImageControl()->removeImage(frame
.fgrip
);
640 screen
->getImageControl()->removeImage(frame
.ugrip
);
642 blackbox
->removeWindowSearch(frame
.left_grip
);
643 blackbox
->removeWindowSearch(frame
.right_grip
);
645 XDestroyWindow(blackbox
->getXDisplay(), frame
.left_grip
);
646 XDestroyWindow(blackbox
->getXDisplay(), frame
.right_grip
);
647 frame
.left_grip
= frame
.right_grip
= None
;
649 blackbox
->removeWindowSearch(frame
.handle
);
650 XDestroyWindow(blackbox
->getXDisplay(), frame
.handle
);
655 void BlackboxWindow::createTitlebar(void) {
656 frame
.title
= createChildWindow(frame
.window
);
657 frame
.label
= createChildWindow(frame
.title
);
658 blackbox
->saveWindowSearch(frame
.title
, this);
659 blackbox
->saveWindowSearch(frame
.label
, this);
661 if (decorations
& Decor_Iconify
) createIconifyButton();
662 if (decorations
& Decor_Maximize
) createMaximizeButton();
663 if (decorations
& Decor_Close
) createCloseButton();
667 void BlackboxWindow::destroyTitlebar(void) {
668 if (frame
.close_button
)
669 destroyCloseButton();
671 if (frame
.iconify_button
)
672 destroyIconifyButton();
674 if (frame
.maximize_button
)
675 destroyMaximizeButton();
678 screen
->getImageControl()->removeImage(frame
.ftitle
);
681 screen
->getImageControl()->removeImage(frame
.utitle
);
684 screen
->getImageControl()->removeImage(frame
.flabel
);
687 screen
->getImageControl()->removeImage(frame
.ulabel
);
690 screen
->getImageControl()->removeImage(frame
.fbutton
);
693 screen
->getImageControl()->removeImage(frame
.ubutton
);
696 screen
->getImageControl()->removeImage(frame
.pbutton
);
698 blackbox
->removeWindowSearch(frame
.title
);
699 blackbox
->removeWindowSearch(frame
.label
);
701 XDestroyWindow(blackbox
->getXDisplay(), frame
.label
);
702 XDestroyWindow(blackbox
->getXDisplay(), frame
.title
);
703 frame
.title
= frame
.label
= None
;
707 void BlackboxWindow::createCloseButton(void) {
708 if (frame
.title
!= None
) {
709 frame
.close_button
= createChildWindow(frame
.title
);
710 blackbox
->saveWindowSearch(frame
.close_button
, this);
715 void BlackboxWindow::destroyCloseButton(void) {
716 blackbox
->removeWindowSearch(frame
.close_button
);
717 XDestroyWindow(blackbox
->getXDisplay(), frame
.close_button
);
718 frame
.close_button
= None
;
722 void BlackboxWindow::createIconifyButton(void) {
723 if (frame
.title
!= None
) {
724 frame
.iconify_button
= createChildWindow(frame
.title
);
725 blackbox
->saveWindowSearch(frame
.iconify_button
, this);
730 void BlackboxWindow::destroyIconifyButton(void) {
731 blackbox
->removeWindowSearch(frame
.iconify_button
);
732 XDestroyWindow(blackbox
->getXDisplay(), frame
.iconify_button
);
733 frame
.iconify_button
= None
;
737 void BlackboxWindow::createMaximizeButton(void) {
738 if (frame
.title
!= None
) {
739 frame
.maximize_button
= createChildWindow(frame
.title
);
740 blackbox
->saveWindowSearch(frame
.maximize_button
, this);
745 void BlackboxWindow::destroyMaximizeButton(void) {
746 blackbox
->removeWindowSearch(frame
.maximize_button
);
747 XDestroyWindow(blackbox
->getXDisplay(), frame
.maximize_button
);
748 frame
.maximize_button
= None
;
752 void BlackboxWindow::positionButtons(bool redecorate_label
) {
753 string layout
= blackbox
->getTitlebarLayout();
756 bool hasclose
, hasiconify
, hasmaximize
, haslabel
;
757 hasclose
= hasiconify
= hasmaximize
= haslabel
= false;
759 string::const_iterator it
, end
;
760 for (it
= layout
.begin(), end
= layout
.end(); it
!= end
; ++it
) {
763 if (! hasclose
&& (decorations
& Decor_Close
)) {
769 if (! hasiconify
&& (decorations
& Decor_Iconify
)) {
775 if (! hasmaximize
&& (decorations
& Decor_Maximize
)) {
787 if (! hasclose
&& frame
.close_button
)
788 destroyCloseButton();
789 if (! hasiconify
&& frame
.iconify_button
)
790 destroyIconifyButton();
791 if (! hasmaximize
&& frame
.maximize_button
)
792 destroyMaximizeButton();
794 parsed
+= 'L'; // require that the label be in the layout
796 const unsigned int bsep
= frame
.bevel_w
+ 1; // separation between elements
797 const unsigned int by
= frame
.bevel_w
+ 1;
798 const unsigned int ty
= frame
.bevel_w
;
800 frame
.label_w
= frame
.inside_w
- bsep
* 2 -
801 (frame
.button_w
+ bsep
) * (parsed
.size() - 1);
803 unsigned int x
= bsep
;
804 for (it
= parsed
.begin(), end
= parsed
.end(); it
!= end
; ++it
) {
807 if (! frame
.close_button
) createCloseButton();
808 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.close_button
, x
, by
,
809 frame
.button_w
, frame
.button_w
);
810 x
+= frame
.button_w
+ bsep
;
813 if (! frame
.iconify_button
) createIconifyButton();
814 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.iconify_button
, x
, by
,
815 frame
.button_w
, frame
.button_w
);
816 x
+= frame
.button_w
+ bsep
;
819 if (! frame
.maximize_button
) createMaximizeButton();
820 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.maximize_button
, x
, by
,
821 frame
.button_w
, frame
.button_w
);
822 x
+= frame
.button_w
+ bsep
;
825 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.label
, x
, ty
,
826 frame
.label_w
, frame
.label_h
);
827 x
+= frame
.label_w
+ bsep
;
832 if (redecorate_label
) decorateLabel();
838 void BlackboxWindow::reconfigure(void) {
841 client
.rect
.setPos(frame
.rect
.left() + frame
.margin
.left
,
842 frame
.rect
.top() + frame
.margin
.top
);
849 configure(frame
.rect
.x(), frame
.rect
.y(),
850 frame
.rect
.width(), frame
.rect
.height());
853 windowmenu
->move(windowmenu
->getX(), frame
.rect
.y() + frame
.title_h
);
854 windowmenu
->reconfigure();
859 void BlackboxWindow::updateFocusModel(void) {
860 if ((! screen
->isSloppyFocus()) || screen
->doClickRaise()) {
861 // grab button 1 for changing focus/raising
862 blackbox
->grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
863 GrabModeSync
, GrabModeSync
, None
, None
);
865 blackbox
->ungrabButton(Button1
, 0, frame
.plate
);
870 void BlackboxWindow::positionWindows(void) {
871 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.window
,
872 frame
.rect
.x(), frame
.rect
.y(), frame
.inside_w
,
873 (flags
.shaded
) ? frame
.title_h
: frame
.inside_h
);
874 XSetWindowBorderWidth(blackbox
->getXDisplay(), frame
.window
,
876 XSetWindowBorderWidth(blackbox
->getXDisplay(), frame
.plate
,
878 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.plate
,
879 frame
.margin
.left
- frame
.mwm_border_w
- frame
.border_w
,
880 frame
.margin
.top
- frame
.mwm_border_w
- frame
.border_w
,
881 client
.rect
.width(), client
.rect
.height());
882 XMoveResizeWindow(blackbox
->getXDisplay(), client
.window
,
883 0, 0, client
.rect
.width(), client
.rect
.height());
885 if (decorations
& Decor_Titlebar
) {
886 if (frame
.title
== None
) createTitlebar();
888 XSetWindowBorderWidth(blackbox
->getXDisplay(), frame
.title
,
890 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.title
, -frame
.border_w
,
891 -frame
.border_w
, frame
.inside_w
, frame
.title_h
);
894 XMapSubwindows(blackbox
->getXDisplay(), frame
.title
);
895 XMapWindow(blackbox
->getXDisplay(), frame
.title
);
896 } else if (frame
.title
) {
899 if (decorations
& Decor_Handle
) {
900 if (frame
.handle
== None
) createHandle();
901 XSetWindowBorderWidth(blackbox
->getXDisplay(), frame
.handle
,
903 XSetWindowBorderWidth(blackbox
->getXDisplay(), frame
.left_grip
,
905 XSetWindowBorderWidth(blackbox
->getXDisplay(), frame
.right_grip
,
908 // use client.rect here so the value is correct even if shaded
909 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.handle
,
911 client
.rect
.height() + frame
.margin
.top
+
912 frame
.mwm_border_w
- frame
.border_w
,
913 frame
.inside_w
, frame
.handle_h
);
914 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.left_grip
,
915 -frame
.border_w
, -frame
.border_w
,
916 frame
.grip_w
, frame
.handle_h
);
917 XMoveResizeWindow(blackbox
->getXDisplay(), frame
.right_grip
,
918 frame
.inside_w
- frame
.grip_w
- frame
.border_w
,
919 -frame
.border_w
, frame
.grip_w
, frame
.handle_h
);
921 XMapSubwindows(blackbox
->getXDisplay(), frame
.handle
);
922 XMapWindow(blackbox
->getXDisplay(), frame
.handle
);
923 } else if (frame
.handle
) {
929 void BlackboxWindow::updateStrut(void) {
930 unsigned long num
= 4;
932 if (! xatom
->getValue(client
.window
, XAtom::net_wm_strut
, XAtom::cardinal
,
937 client
.strut
.left
= data
[0];
938 client
.strut
.right
= data
[1];
939 client
.strut
.top
= data
[2];
940 client
.strut
.bottom
= data
[3];
942 screen
->updateAvailableArea();
949 void BlackboxWindow::getWindowType(void) {
951 if (xatom
->getValue(client
.window
, XAtom::net_wm_window_type
, XAtom::atom
,
953 if (val
== xatom
->getAtom(XAtom::net_wm_window_type_desktop
))
954 window_type
= Type_Desktop
;
955 else if (val
== xatom
->getAtom(XAtom::net_wm_window_type_dock
))
956 window_type
= Type_Dock
;
957 else if (val
== xatom
->getAtom(XAtom::net_wm_window_type_toolbar
))
958 window_type
= Type_Toolbar
;
959 else if (val
== xatom
->getAtom(XAtom::net_wm_window_type_menu
))
960 window_type
= Type_Menu
;
961 else if (val
== xatom
->getAtom(XAtom::net_wm_window_type_utility
))
962 window_type
= Type_Utility
;
963 else if (val
== xatom
->getAtom(XAtom::net_wm_window_type_splash
))
964 window_type
= Type_Splash
;
965 else if (val
== xatom
->getAtom(XAtom::net_wm_window_type_dialog
))
966 window_type
= Type_Dialog
;
967 else //if (val[0] == xatom->getAtom(XAtom::net_wm_window_type_normal))
968 window_type
= Type_Normal
;
973 * the window type hint was not set, which means we either classify ourself
974 * as a normal window or a dialog, depending on if we are a transient.
977 window_type
= Type_Dialog
;
979 window_type
= Type_Normal
;
983 void BlackboxWindow::getWMName(void) {
984 if (xatom
->getValue(client
.window
, XAtom::net_wm_name
,
985 XAtom::utf8
, client
.title
) &&
986 !client
.title
.empty()) {
987 xatom
->eraseValue(client
.window
, XAtom::net_wm_visible_name
);
990 //fall through to using WM_NAME
991 if (xatom
->getValue(client
.window
, XAtom::wm_name
, XAtom::ansi
, client
.title
)
992 && !client
.title
.empty()) {
993 xatom
->eraseValue(client
.window
, XAtom::net_wm_visible_name
);
996 // fall back to an internal default
997 client
.title
= i18n(WindowSet
, WindowUnnamed
, "Unnamed");
998 xatom
->setValue(client
.window
, XAtom::net_wm_visible_name
, XAtom::utf8
,
1003 void BlackboxWindow::getWMIconName(void) {
1004 if (xatom
->getValue(client
.window
, XAtom::net_wm_icon_name
,
1005 XAtom::utf8
, client
.icon_title
) &&
1006 !client
.icon_title
.empty()) {
1007 xatom
->eraseValue(client
.window
, XAtom::net_wm_visible_icon_name
);
1010 //fall through to using WM_ICON_NAME
1011 if (xatom
->getValue(client
.window
, XAtom::wm_icon_name
, XAtom::ansi
,
1012 client
.icon_title
) &&
1013 !client
.icon_title
.empty()) {
1014 xatom
->eraseValue(client
.window
, XAtom::net_wm_visible_icon_name
);
1017 // fall back to using the main name
1018 client
.icon_title
= client
.title
;
1019 xatom
->setValue(client
.window
, XAtom::net_wm_visible_icon_name
, XAtom::utf8
,
1025 * Retrieve which WM Protocols are supported by the client window.
1026 * If the WM_DELETE_WINDOW protocol is supported, add the close button to the
1027 * window's decorations and allow the close behavior.
1028 * If the WM_TAKE_FOCUS protocol is supported, save a value that indicates
1031 void BlackboxWindow::getWMProtocols(void) {
1035 if (XGetWMProtocols(blackbox
->getXDisplay(), client
.window
,
1036 &proto
, &num_return
)) {
1037 for (int i
= 0; i
< num_return
; ++i
) {
1038 if (proto
[i
] == xatom
->getAtom(XAtom::wm_delete_window
)) {
1039 decorations
|= Decor_Close
;
1040 functions
|= Func_Close
;
1041 } else if (proto
[i
] == xatom
->getAtom(XAtom::wm_take_focus
))
1042 flags
.send_focus_message
= True
;
1043 else if (proto
[i
] == xatom
->getAtom(XAtom::blackbox_structure_messages
))
1044 screen
->addNetizen(new Netizen(screen
, client
.window
));
1053 * Gets the value of the WM_HINTS property.
1054 * If the property is not set, then use a set of default values.
1056 void BlackboxWindow::getWMHints(void) {
1057 focus_mode
= F_Passive
;
1058 client
.initial_state
= NormalState
;
1060 // remove from current window group
1061 if (client
.window_group
) {
1062 BWindowGroup
*group
= blackbox
->searchGroup(client
.window_group
);
1063 if (group
) group
->removeWindow(this);
1065 client
.window_group
= None
;
1067 XWMHints
*wmhint
= XGetWMHints(blackbox
->getXDisplay(), client
.window
);
1072 if (wmhint
->flags
& InputHint
) {
1073 if (wmhint
->input
== True
) {
1074 if (flags
.send_focus_message
)
1075 focus_mode
= F_LocallyActive
;
1077 if (flags
.send_focus_message
)
1078 focus_mode
= F_GloballyActive
;
1080 focus_mode
= F_NoInput
;
1084 if (wmhint
->flags
& StateHint
)
1085 client
.initial_state
= wmhint
->initial_state
;
1087 if (wmhint
->flags
& WindowGroupHint
) {
1088 client
.window_group
= wmhint
->window_group
;
1090 // add window to the appropriate group
1091 BWindowGroup
*group
= blackbox
->searchGroup(client
.window_group
);
1092 if (! group
) // no group found, create it!
1093 group
= new BWindowGroup(blackbox
, client
.window_group
);
1094 group
->addWindow(this);
1097 client
.wm_hint_flags
= wmhint
->flags
;
1103 * Gets the value of the WM_NORMAL_HINTS property.
1104 * If the property is not set, then use a set of default values.
1106 void BlackboxWindow::getWMNormalHints(void) {
1108 XSizeHints sizehint
;
1110 client
.min_width
= client
.min_height
=
1111 client
.width_inc
= client
.height_inc
= 1;
1112 client
.base_width
= client
.base_height
= 0;
1115 use the full screen, not the strut modified size. otherwise when the
1116 availableArea changes max_width/height will be incorrect and lead to odd
1119 const Rect
& screen_area
= screen
->getRect();
1120 client
.max_width
= screen_area
.width();
1122 client
.max_height
= screen_area
.height();
1123 client
.min_aspect_x
= client
.min_aspect_y
=
1124 client
.max_aspect_x
= client
.max_aspect_y
= 1;
1125 client
.win_gravity
= NorthWestGravity
;
1127 if (! XGetWMNormalHints(blackbox
->getXDisplay(), client
.window
,
1128 &sizehint
, &icccm_mask
))
1131 client
.normal_hint_flags
= sizehint
.flags
;
1133 if (sizehint
.flags
& PMinSize
) {
1134 client
.min_width
= sizehint
.min_width
;
1135 client
.min_height
= sizehint
.min_height
;
1138 if (sizehint
.flags
& PMaxSize
) {
1139 client
.max_width
= sizehint
.max_width
;
1140 client
.max_height
= sizehint
.max_height
;
1143 if (sizehint
.flags
& PResizeInc
) {
1144 client
.width_inc
= sizehint
.width_inc
;
1145 client
.height_inc
= sizehint
.height_inc
;
1148 if (sizehint
.flags
& PAspect
) {
1149 client
.min_aspect_x
= sizehint
.min_aspect
.x
;
1150 client
.min_aspect_y
= sizehint
.min_aspect
.y
;
1151 client
.max_aspect_x
= sizehint
.max_aspect
.x
;
1152 client
.max_aspect_y
= sizehint
.max_aspect
.y
;
1155 if (sizehint
.flags
& PBaseSize
) {
1156 client
.base_width
= sizehint
.base_width
;
1157 client
.base_height
= sizehint
.base_height
;
1160 if (sizehint
.flags
& PWinGravity
)
1161 client
.win_gravity
= sizehint
.win_gravity
;
1166 * Gets the NETWM hints for the class' contained window.
1168 void BlackboxWindow::getNetWMHints(void) {
1169 unsigned long workspace
;
1171 if (xatom
->getValue(client
.window
, XAtom::net_wm_desktop
, XAtom::cardinal
,
1173 if (workspace
== 0xffffffff)
1176 blackbox_attrib
.workspace
= workspace
;
1179 unsigned long *state
;
1180 unsigned long num
= (unsigned) -1;
1181 if (xatom
->getValue(client
.window
, XAtom::net_wm_state
, XAtom::atom
,
1185 for (unsigned long i
= 0; i
< num
; ++i
) {
1186 if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_modal
))
1188 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_shaded
))
1189 flags
.shaded
= True
;
1190 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_skip_taskbar
))
1191 flags
.skip_taskbar
= True
;
1192 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_skip_pager
))
1193 flags
.skip_pager
= True
;
1194 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_fullscreen
))
1195 flags
.fullscreen
= True
;
1196 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_hidden
))
1197 setState(IconicState
);
1198 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_maximized_vert
))
1200 else if (state
[i
] == xatom
->getAtom(XAtom::net_wm_state_maximized_horz
))
1204 flags
.maximized
= 1;
1206 flags
.maximized
= 2;
1208 flags
.maximized
= 3;
1216 * Gets the MWM hints for the class' contained window.
1217 * This is used while initializing the window to its first state, and not
1219 * Returns: true if the MWM hints are successfully retreived and applied;
1220 * false if they are not.
1222 void BlackboxWindow::getMWMHints(void) {
1226 num
= PropMwmHintsElements
;
1227 if (! xatom
->getValue(client
.window
, XAtom::motif_wm_hints
,
1228 XAtom::motif_wm_hints
, num
,
1229 (unsigned long **)&mwm_hint
))
1231 if (num
< PropMwmHintsElements
) {
1236 if (mwm_hint
->flags
& MwmHintsDecorations
) {
1237 if (mwm_hint
->decorations
& MwmDecorAll
) {
1238 decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
1239 Decor_Iconify
| Decor_Maximize
| Decor_Close
;
1243 if (mwm_hint
->decorations
& MwmDecorBorder
)
1244 decorations
|= Decor_Border
;
1245 if (mwm_hint
->decorations
& MwmDecorHandle
)
1246 decorations
|= Decor_Handle
;
1247 if (mwm_hint
->decorations
& MwmDecorTitle
)
1248 decorations
|= Decor_Titlebar
;
1249 if (mwm_hint
->decorations
& MwmDecorIconify
)
1250 decorations
|= Decor_Iconify
;
1251 if (mwm_hint
->decorations
& MwmDecorMaximize
)
1252 decorations
|= Decor_Maximize
;
1256 if (mwm_hint
->flags
& MwmHintsFunctions
) {
1257 if (mwm_hint
->functions
& MwmFuncAll
) {
1258 functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
1263 if (mwm_hint
->functions
& MwmFuncResize
)
1264 functions
|= Func_Resize
;
1265 if (mwm_hint
->functions
& MwmFuncMove
)
1266 functions
|= Func_Move
;
1267 if (mwm_hint
->functions
& MwmFuncIconify
)
1268 functions
|= Func_Iconify
;
1269 if (mwm_hint
->functions
& MwmFuncMaximize
)
1270 functions
|= Func_Maximize
;
1271 if (mwm_hint
->functions
& MwmFuncClose
)
1272 functions
|= Func_Close
;
1280 * Gets the blackbox hints from the class' contained window.
1281 * This is used while initializing the window to its first state, and not
1283 * Returns: true if the hints are successfully retreived and applied; false if
1286 bool BlackboxWindow::getBlackboxHints(void) {
1288 BlackboxHints
*blackbox_hint
;
1290 num
= PropBlackboxHintsElements
;
1291 if (! xatom
->getValue(client
.window
, XAtom::blackbox_hints
,
1292 XAtom::blackbox_hints
, num
,
1293 (unsigned long **)&blackbox_hint
))
1295 if (num
< PropBlackboxHintsElements
) {
1296 delete [] blackbox_hint
;
1300 if (blackbox_hint
->flags
& AttribShaded
)
1301 flags
.shaded
= (blackbox_hint
->attrib
& AttribShaded
);
1303 if ((blackbox_hint
->flags
& AttribMaxHoriz
) &&
1304 (blackbox_hint
->flags
& AttribMaxVert
))
1305 flags
.maximized
= (blackbox_hint
->attrib
&
1306 (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1307 else if (blackbox_hint
->flags
& AttribMaxVert
)
1308 flags
.maximized
= (blackbox_hint
->attrib
& AttribMaxVert
) ? 2 : 0;
1309 else if (blackbox_hint
->flags
& AttribMaxHoriz
)
1310 flags
.maximized
= (blackbox_hint
->attrib
& AttribMaxHoriz
) ? 3 : 0;
1312 if (blackbox_hint
->flags
& AttribOmnipresent
)
1313 flags
.stuck
= (blackbox_hint
->attrib
& AttribOmnipresent
);
1315 if (blackbox_hint
->flags
& AttribWorkspace
)
1316 blackbox_attrib
.workspace
= blackbox_hint
->workspace
;
1318 // if (blackbox_hint->flags & AttribStack)
1319 // don't yet have always on top/bottom for blackbox yet... working
1322 if (blackbox_hint
->flags
& AttribDecoration
) {
1323 switch (blackbox_hint
->decoration
) {
1325 // clear all decorations except close
1326 decorations
&= Decor_Close
;
1327 // clear all functions except close
1328 functions
&= Func_Close
;
1333 decorations
|= Decor_Titlebar
| Decor_Iconify
;
1334 decorations
&= ~(Decor_Border
| Decor_Handle
| Decor_Maximize
);
1335 functions
|= Func_Move
| Func_Iconify
;
1336 functions
&= ~(Func_Resize
| Func_Maximize
);
1341 decorations
|= Decor_Titlebar
;
1342 decorations
&= ~(Decor_Iconify
| Decor_Border
| Decor_Handle
);
1343 functions
|= Func_Move
;
1344 functions
&= ~(Func_Resize
| Func_Maximize
| Func_Iconify
);
1350 decorations
|= Decor_Titlebar
| Decor_Border
| Decor_Handle
|
1351 Decor_Iconify
| Decor_Maximize
;
1352 functions
|= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
;
1360 delete [] blackbox_hint
;
1366 void BlackboxWindow::getTransientInfo(void) {
1367 if (client
.transient_for
&&
1368 client
.transient_for
!= (BlackboxWindow
*) ~0ul) {
1369 // the transient for hint was removed, so we need to tell our
1370 // previous transient_for that we are going away
1371 client
.transient_for
->client
.transientList
.remove(this);
1374 // we have no transient_for until we find a new one
1375 client
.transient_for
= 0;
1378 if (! XGetTransientForHint(blackbox
->getXDisplay(), client
.window
,
1380 // transient_for hint not set
1384 if (trans_for
== client
.window
) {
1385 // wierd client... treat this window as a normal window
1389 if (trans_for
== None
|| trans_for
== screen
->getRootWindow()) {
1390 // this is an undocumented interpretation of the ICCCM. a transient
1391 // associated with None/Root/itself is assumed to be a modal root
1392 // transient. we don't support the concept of a global transient,
1393 // so we just associate this transient with nothing, and perhaps
1394 // we will add support later for global modality.
1395 client
.transient_for
= (BlackboxWindow
*) ~0ul;
1400 client
.transient_for
= blackbox
->searchWindow(trans_for
);
1401 if (! client
.transient_for
&&
1402 client
.window_group
&& trans_for
== client
.window_group
) {
1403 // no direct transient_for, perhaps this is a group transient?
1404 BWindowGroup
*group
= blackbox
->searchGroup(client
.window_group
);
1405 if (group
) client
.transient_for
= group
->find(screen
);
1408 if (! client
.transient_for
|| client
.transient_for
== this) {
1409 // no transient_for found, or we have a wierd client that wants to be
1410 // a transient for itself, so we treat this window as a normal window
1411 client
.transient_for
= (BlackboxWindow
*) 0;
1415 // register ourselves with our new transient_for
1416 client
.transient_for
->client
.transientList
.push_back(this);
1417 flags
.stuck
= client
.transient_for
->flags
.stuck
;
1421 bool BlackboxWindow::isKDESystrayWindow(void) {
1423 if (xatom
->getValue(client
.window
, XAtom::kde_net_wm_system_tray_window_for
,
1424 XAtom::window
, systray
) && systray
)
1430 BlackboxWindow
*BlackboxWindow::getTransientFor(void) const {
1431 if (client
.transient_for
&&
1432 client
.transient_for
!= (BlackboxWindow
*) ~0ul)
1433 return client
.transient_for
;
1438 void BlackboxWindow::configure(int dx
, int dy
,
1439 unsigned int dw
, unsigned int dh
) {
1440 bool send_event
= False
;
1442 if (dw
!= frame
.rect
.width() || dh
!= frame
.rect
.height()) {
1443 frame
.rect
.setRect(dx
, dy
, dw
, dh
);
1444 frame
.inside_w
= frame
.rect
.width() - (frame
.border_w
* 2);
1445 frame
.inside_h
= frame
.rect
.height() - (frame
.border_w
* 2);
1447 if (frame
.rect
.right() <= 0 || frame
.rect
.bottom() <= 0)
1448 frame
.rect
.setPos(0, 0);
1450 client
.rect
.setCoords(frame
.rect
.left() + frame
.margin
.left
,
1451 frame
.rect
.top() + frame
.margin
.top
,
1452 frame
.rect
.right() - frame
.margin
.right
,
1453 frame
.rect
.bottom() - frame
.margin
.bottom
);
1456 if (blackbox
->hasShapeExtensions() && flags
.shaped
) {
1463 redrawWindowFrame();
1464 } else if (frame
.rect
.x() != dx
|| frame
.rect
.y() != dy
) {
1467 frame
.rect
.setPos(dx
, dy
);
1469 XMoveWindow(blackbox
->getXDisplay(), frame
.window
,
1470 frame
.rect
.x(), frame
.rect
.y());
1473 if (send_event
&& ! flags
.moving
) {
1474 client
.rect
.setPos(frame
.rect
.left() + frame
.margin
.left
,
1475 frame
.rect
.top() + frame
.margin
.top
);
1478 event
.type
= ConfigureNotify
;
1480 event
.xconfigure
.display
= blackbox
->getXDisplay();
1481 event
.xconfigure
.event
= client
.window
;
1482 event
.xconfigure
.window
= client
.window
;
1483 event
.xconfigure
.x
= client
.rect
.x();
1484 event
.xconfigure
.y
= client
.rect
.y();
1485 event
.xconfigure
.width
= client
.rect
.width();
1486 event
.xconfigure
.height
= client
.rect
.height();
1487 event
.xconfigure
.border_width
= client
.old_bw
;
1488 event
.xconfigure
.above
= frame
.window
;
1489 event
.xconfigure
.override_redirect
= False
;
1491 XSendEvent(blackbox
->getXDisplay(), client
.window
, False
,
1492 StructureNotifyMask
, &event
);
1494 screen
->updateNetizenConfigNotify(&event
);
1500 void BlackboxWindow::configureShape(void) {
1501 XShapeCombineShape(blackbox
->getXDisplay(), frame
.window
, ShapeBounding
,
1502 frame
.margin
.left
- frame
.border_w
,
1503 frame
.margin
.top
- frame
.border_w
,
1504 client
.window
, ShapeBounding
, ShapeSet
);
1507 XRectangle xrect
[2];
1509 if (decorations
& Decor_Titlebar
) {
1510 xrect
[0].x
= xrect
[0].y
= -frame
.border_w
;
1511 xrect
[0].width
= frame
.rect
.width();
1512 xrect
[0].height
= frame
.title_h
+ (frame
.border_w
* 2);
1516 if (decorations
& Decor_Handle
) {
1517 xrect
[1].x
= -frame
.border_w
;
1518 xrect
[1].y
= frame
.rect
.height() - frame
.margin
.bottom
+
1519 frame
.mwm_border_w
- frame
.border_w
;
1520 xrect
[1].width
= frame
.rect
.width();
1521 xrect
[1].height
= frame
.handle_h
+ (frame
.border_w
* 2);
1525 XShapeCombineRectangles(blackbox
->getXDisplay(), frame
.window
,
1526 ShapeBounding
, 0, 0, xrect
, num
,
1527 ShapeUnion
, Unsorted
);
1532 bool BlackboxWindow::setInputFocus(void) {
1533 if (flags
.focused
) return True
;
1535 assert(! flags
.iconic
);
1537 // if the window is not visible, mark the window as wanting focus rather
1538 // than give it focus.
1539 if (! flags
.visible
) {
1540 Workspace
*wkspc
= screen
->getWorkspace(blackbox_attrib
.workspace
);
1541 wkspc
->setLastFocusedWindow(this);
1545 if (! frame
.rect
.intersects(screen
->getRect())) {
1546 // client is outside the screen, move it to the center
1547 configure((screen
->getWidth() - frame
.rect
.width()) / 2,
1548 (screen
->getHeight() - frame
.rect
.height()) / 2,
1549 frame
.rect
.width(), frame
.rect
.height());
1552 if (client
.transientList
.size() > 0) {
1553 // transfer focus to any modal transients
1554 BlackboxWindowList::iterator it
, end
= client
.transientList
.end();
1555 for (it
= client
.transientList
.begin(); it
!= end
; ++it
) {
1556 if ((*it
)->flags
.modal
) return (*it
)->setInputFocus();
1561 if (focus_mode
== F_LocallyActive
|| focus_mode
== F_Passive
) {
1562 XSetInputFocus(blackbox
->getXDisplay(), client
.window
,
1563 RevertToPointerRoot
, CurrentTime
);
1565 blackbox
->setFocusedWindow(this);
1567 /* we could set the focus to none, since the window doesn't accept focus,
1568 * but we shouldn't set focus to nothing since this would surely make
1574 if (flags
.send_focus_message
) {
1576 ce
.xclient
.type
= ClientMessage
;
1577 ce
.xclient
.message_type
= xatom
->getAtom(XAtom::wm_protocols
);
1578 ce
.xclient
.display
= blackbox
->getXDisplay();
1579 ce
.xclient
.window
= client
.window
;
1580 ce
.xclient
.format
= 32;
1581 ce
.xclient
.data
.l
[0] = xatom
->getAtom(XAtom::wm_take_focus
);
1582 ce
.xclient
.data
.l
[1] = blackbox
->getLastTime();
1583 ce
.xclient
.data
.l
[2] = 0l;
1584 ce
.xclient
.data
.l
[3] = 0l;
1585 ce
.xclient
.data
.l
[4] = 0l;
1586 XSendEvent(blackbox
->getXDisplay(), client
.window
, False
,
1594 void BlackboxWindow::iconify(void) {
1595 if (flags
.iconic
) return;
1597 // We don't need to worry about resizing because resizing always grabs the X
1598 // server. This should only ever happen if using opaque moving.
1602 if (windowmenu
) windowmenu
->hide();
1605 * we don't want this XUnmapWindow call to generate an UnmapNotify event, so
1606 * we need to clear the event mask on client.window for a split second.
1607 * HOWEVER, since X11 is asynchronous, the window could be destroyed in that
1608 * split second, leaving us with a ghost window... so, we need to do this
1609 * while the X server is grabbed
1611 XGrabServer(blackbox
->getXDisplay());
1612 XSelectInput(blackbox
->getXDisplay(), client
.window
, NoEventMask
);
1613 XUnmapWindow(blackbox
->getXDisplay(), client
.window
);
1614 XSelectInput(blackbox
->getXDisplay(), client
.window
,
1615 PropertyChangeMask
| FocusChangeMask
| StructureNotifyMask
);
1616 XUngrabServer(blackbox
->getXDisplay());
1618 XUnmapWindow(blackbox
->getXDisplay(), frame
.window
);
1619 flags
.visible
= False
;
1620 flags
.iconic
= True
;
1622 setState(IconicState
);
1624 screen
->getWorkspace(blackbox_attrib
.workspace
)->removeWindow(this);
1626 if (isTransient()) {
1627 if (client
.transient_for
!= (BlackboxWindow
*) ~0ul &&
1628 ! client
.transient_for
->flags
.iconic
) {
1629 // iconify our transient_for
1630 client
.transient_for
->iconify();
1634 screen
->addIcon(this);
1636 if (client
.transientList
.size() > 0) {
1637 // iconify all transients
1638 BlackboxWindowList::iterator it
, end
= client
.transientList
.end();
1639 for (it
= client
.transientList
.begin(); it
!= end
; ++it
) {
1640 if (! (*it
)->flags
.iconic
) (*it
)->iconify();
1646 void BlackboxWindow::show(void) {
1647 flags
.visible
= True
;
1648 flags
.iconic
= False
;
1650 current_state
= (flags
.shaded
) ? IconicState
: NormalState
;
1651 setState(current_state
);
1653 XMapWindow(blackbox
->getXDisplay(), client
.window
);
1654 XMapSubwindows(blackbox
->getXDisplay(), frame
.window
);
1655 XMapWindow(blackbox
->getXDisplay(), frame
.window
);
1659 void BlackboxWindow::deiconify(bool reassoc
, bool raise
) {
1660 if (flags
.iconic
|| reassoc
)
1661 screen
->reassociateWindow(this, BSENTINEL
, False
);
1662 else if (blackbox_attrib
.workspace
!= screen
->getCurrentWorkspace()->getID())
1667 // reassociate and deiconify all transients
1668 if (reassoc
&& client
.transientList
.size() > 0) {
1669 BlackboxWindowList::iterator it
, end
= client
.transientList
.end();
1670 for (it
= client
.transientList
.begin(); it
!= end
; ++it
) {
1671 (*it
)->deiconify(True
, False
);
1676 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
1680 void BlackboxWindow::close(void) {
1682 ce
.xclient
.type
= ClientMessage
;
1683 ce
.xclient
.message_type
= xatom
->getAtom(XAtom::wm_protocols
);
1684 ce
.xclient
.display
= blackbox
->getXDisplay();
1685 ce
.xclient
.window
= client
.window
;
1686 ce
.xclient
.format
= 32;
1687 ce
.xclient
.data
.l
[0] = xatom
->getAtom(XAtom::wm_delete_window
);
1688 ce
.xclient
.data
.l
[1] = CurrentTime
;
1689 ce
.xclient
.data
.l
[2] = 0l;
1690 ce
.xclient
.data
.l
[3] = 0l;
1691 ce
.xclient
.data
.l
[4] = 0l;
1692 XSendEvent(blackbox
->getXDisplay(), client
.window
, False
, NoEventMask
, &ce
);
1696 void BlackboxWindow::withdraw(void) {
1697 // We don't need to worry about resizing because resizing always grabs the X
1698 // server. This should only ever happen if using opaque moving.
1702 flags
.visible
= False
;
1703 flags
.iconic
= False
;
1705 setState(current_state
);
1707 XUnmapWindow(blackbox
->getXDisplay(), frame
.window
);
1709 XGrabServer(blackbox
->getXDisplay());
1711 XSelectInput(blackbox
->getXDisplay(), client
.window
, NoEventMask
);
1712 XUnmapWindow(blackbox
->getXDisplay(), client
.window
);
1713 XSelectInput(blackbox
->getXDisplay(), client
.window
,
1714 PropertyChangeMask
| FocusChangeMask
| StructureNotifyMask
);
1716 XUngrabServer(blackbox
->getXDisplay());
1718 if (windowmenu
) windowmenu
->hide();
1722 void BlackboxWindow::maximize(unsigned int button
) {
1723 // We don't need to worry about resizing because resizing always grabs the X
1724 // server. This should only ever happen if using opaque moving.
1728 // handle case where menu is open then the max button is used instead
1729 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
1731 if (flags
.maximized
) {
1732 flags
.maximized
= 0;
1734 blackbox_attrib
.flags
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1735 blackbox_attrib
.attrib
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1738 when a resize finishes, maximize(0) is called to clear any maximization
1739 flags currently set. Otherwise it still thinks it is maximized.
1740 so we do not need to call configure() because resizing will handle it
1742 if (! flags
.resizing
)
1743 configure(blackbox_attrib
.premax_x
, blackbox_attrib
.premax_y
,
1744 blackbox_attrib
.premax_w
, blackbox_attrib
.premax_h
);
1746 blackbox_attrib
.premax_x
= blackbox_attrib
.premax_y
= 0;
1747 blackbox_attrib
.premax_w
= blackbox_attrib
.premax_h
= 0;
1749 redrawAllButtons(); // in case it is not called in configure()
1750 setState(current_state
);
1754 blackbox_attrib
.premax_x
= frame
.rect
.x();
1755 blackbox_attrib
.premax_y
= frame
.rect
.y();
1756 blackbox_attrib
.premax_w
= frame
.rect
.width();
1757 // use client.rect so that clients can be restored even if shaded
1758 blackbox_attrib
.premax_h
=
1759 client
.rect
.height() + frame
.margin
.top
+ frame
.margin
.bottom
;
1761 const Rect
&screen_area
= screen
->availableArea();
1762 frame
.changing
= screen_area
;
1766 blackbox_attrib
.flags
|= AttribMaxHoriz
| AttribMaxVert
;
1767 blackbox_attrib
.attrib
|= AttribMaxHoriz
| AttribMaxVert
;
1771 blackbox_attrib
.flags
|= AttribMaxVert
;
1772 blackbox_attrib
.attrib
|= AttribMaxVert
;
1774 frame
.changing
.setX(frame
.rect
.x());
1775 frame
.changing
.setWidth(frame
.rect
.width());
1779 blackbox_attrib
.flags
|= AttribMaxHoriz
;
1780 blackbox_attrib
.attrib
|= AttribMaxHoriz
;
1782 frame
.changing
.setY(frame
.rect
.y());
1783 frame
.changing
.setHeight(frame
.rect
.height());
1790 blackbox_attrib
.flags
^= AttribShaded
;
1791 blackbox_attrib
.attrib
^= AttribShaded
;
1792 flags
.shaded
= False
;
1795 flags
.maximized
= button
;
1797 configure(frame
.changing
.x(), frame
.changing
.y(),
1798 frame
.changing
.width(), frame
.changing
.height());
1800 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
1801 redrawAllButtons(); // in case it is not called in configure()
1802 setState(current_state
);
1806 // re-maximizes the window to take into account availableArea changes
1807 void BlackboxWindow::remaximize(void) {
1808 // save the original dimensions because maximize will wipe them out
1809 int premax_x
= blackbox_attrib
.premax_x
,
1810 premax_y
= blackbox_attrib
.premax_y
,
1811 premax_w
= blackbox_attrib
.premax_w
,
1812 premax_h
= blackbox_attrib
.premax_h
;
1814 unsigned int button
= flags
.maximized
;
1815 flags
.maximized
= 0; // trick maximize() into working
1818 // restore saved values
1819 blackbox_attrib
.premax_x
= premax_x
;
1820 blackbox_attrib
.premax_y
= premax_y
;
1821 blackbox_attrib
.premax_w
= premax_w
;
1822 blackbox_attrib
.premax_h
= premax_h
;
1826 void BlackboxWindow::setWorkspace(unsigned int n
) {
1827 blackbox_attrib
.flags
|= AttribWorkspace
;
1828 blackbox_attrib
.workspace
= n
;
1829 xatom
->setValue(client
.window
, XAtom::net_wm_desktop
, XAtom::cardinal
, n
);
1833 void BlackboxWindow::shade(void) {
1835 XResizeWindow(blackbox
->getXDisplay(), frame
.window
,
1836 frame
.inside_w
, frame
.inside_h
);
1837 flags
.shaded
= False
;
1838 blackbox_attrib
.flags
^= AttribShaded
;
1839 blackbox_attrib
.attrib
^= AttribShaded
;
1841 setState(NormalState
);
1843 // set the frame rect to the normal size
1844 frame
.rect
.setHeight(client
.rect
.height() + frame
.margin
.top
+
1845 frame
.margin
.bottom
);
1847 if (! (decorations
& Decor_Titlebar
))
1848 return; // can't shade it without a titlebar!
1850 XResizeWindow(blackbox
->getXDisplay(), frame
.window
,
1851 frame
.inside_w
, frame
.title_h
);
1852 flags
.shaded
= True
;
1853 blackbox_attrib
.flags
|= AttribShaded
;
1854 blackbox_attrib
.attrib
|= AttribShaded
;
1856 setState(IconicState
);
1858 // set the frame rect to the shaded size
1859 frame
.rect
.setHeight(frame
.title_h
+ (frame
.border_w
* 2));
1865 * (Un)Sticks a window and its relatives.
1867 void BlackboxWindow::stick(void) {
1869 blackbox_attrib
.flags
^= AttribOmnipresent
;
1870 blackbox_attrib
.attrib
^= AttribOmnipresent
;
1872 flags
.stuck
= False
;
1875 screen
->reassociateWindow(this, BSENTINEL
, True
);
1877 // temporary fix since sticky windows suck. set the hint to what we
1878 // actually hold in our data.
1879 xatom
->setValue(client
.window
, XAtom::net_wm_desktop
, XAtom::cardinal
,
1880 blackbox_attrib
.workspace
);
1882 setState(current_state
);
1886 blackbox_attrib
.flags
|= AttribOmnipresent
;
1887 blackbox_attrib
.attrib
|= AttribOmnipresent
;
1889 // temporary fix since sticky windows suck. set the hint to a different
1890 // value than that contained in the class' data.
1891 xatom
->setValue(client
.window
, XAtom::net_wm_desktop
, XAtom::cardinal
,
1894 setState(current_state
);
1897 if (isTransient() && client
.transient_for
!= (BlackboxWindow
*) ~0ul &&
1898 client
.transient_for
->isStuck() != flags
.stuck
)
1899 client
.transient_for
->stick();
1900 // go down the chain
1901 BlackboxWindowList::iterator it
;
1902 const BlackboxWindowList::iterator end
= client
.transientList
.end();
1903 for (it
= client
.transientList
.begin(); it
!= end
; ++it
)
1904 if ((*it
)->isStuck() != flags
.stuck
)
1909 void BlackboxWindow::redrawWindowFrame(void) const {
1910 if (decorations
& Decor_Titlebar
) {
1911 if (flags
.focused
) {
1913 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1914 frame
.title
, frame
.ftitle
);
1916 XSetWindowBackground(blackbox
->getXDisplay(),
1917 frame
.title
, frame
.ftitle_pixel
);
1920 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1921 frame
.title
, frame
.utitle
);
1923 XSetWindowBackground(blackbox
->getXDisplay(),
1924 frame
.title
, frame
.utitle_pixel
);
1926 XClearWindow(blackbox
->getXDisplay(), frame
.title
);
1932 if (decorations
& Decor_Handle
) {
1933 if (flags
.focused
) {
1935 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1936 frame
.handle
, frame
.fhandle
);
1938 XSetWindowBackground(blackbox
->getXDisplay(),
1939 frame
.handle
, frame
.fhandle_pixel
);
1942 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1943 frame
.left_grip
, frame
.fgrip
);
1944 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1945 frame
.right_grip
, frame
.fgrip
);
1947 XSetWindowBackground(blackbox
->getXDisplay(),
1948 frame
.left_grip
, frame
.fgrip_pixel
);
1949 XSetWindowBackground(blackbox
->getXDisplay(),
1950 frame
.right_grip
, frame
.fgrip_pixel
);
1954 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1955 frame
.handle
, frame
.uhandle
);
1957 XSetWindowBackground(blackbox
->getXDisplay(),
1958 frame
.handle
, frame
.uhandle_pixel
);
1961 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1962 frame
.left_grip
, frame
.ugrip
);
1963 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
1964 frame
.right_grip
, frame
.ugrip
);
1966 XSetWindowBackground(blackbox
->getXDisplay(),
1967 frame
.left_grip
, frame
.ugrip_pixel
);
1968 XSetWindowBackground(blackbox
->getXDisplay(),
1969 frame
.right_grip
, frame
.ugrip_pixel
);
1972 XClearWindow(blackbox
->getXDisplay(), frame
.handle
);
1973 XClearWindow(blackbox
->getXDisplay(), frame
.left_grip
);
1974 XClearWindow(blackbox
->getXDisplay(), frame
.right_grip
);
1977 if (decorations
& Decor_Border
) {
1979 XSetWindowBorder(blackbox
->getXDisplay(),
1980 frame
.plate
, frame
.fborder_pixel
);
1982 XSetWindowBorder(blackbox
->getXDisplay(),
1983 frame
.plate
, frame
.uborder_pixel
);
1988 void BlackboxWindow::setFocusFlag(bool focus
) {
1989 // only focus a window if it is visible
1990 if (focus
&& !flags
.visible
)
1993 flags
.focused
= focus
;
1995 redrawWindowFrame();
1997 if (screen
->isSloppyFocus() && screen
->doAutoRaise()) {
1998 if (isFocused()) timer
->start();
2003 blackbox
->setFocusedWindow(this);
2007 void BlackboxWindow::installColormap(bool install
) {
2008 int i
= 0, ncmap
= 0;
2009 Colormap
*cmaps
= XListInstalledColormaps(blackbox
->getXDisplay(),
2010 client
.window
, &ncmap
);
2012 XWindowAttributes wattrib
;
2013 if (XGetWindowAttributes(blackbox
->getXDisplay(),
2014 client
.window
, &wattrib
)) {
2016 // install the window's colormap
2017 for (i
= 0; i
< ncmap
; i
++) {
2018 if (*(cmaps
+ i
) == wattrib
.colormap
)
2019 // this window is using an installed color map... do not install
2022 // otherwise, install the window's colormap
2024 XInstallColormap(blackbox
->getXDisplay(), wattrib
.colormap
);
2026 // uninstall the window's colormap
2027 for (i
= 0; i
< ncmap
; i
++) {
2028 if (*(cmaps
+ i
) == wattrib
.colormap
)
2029 // we found the colormap to uninstall
2030 XUninstallColormap(blackbox
->getXDisplay(), wattrib
.colormap
);
2040 void BlackboxWindow::setAllowedActions(void) {
2044 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_shade
);
2045 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_change_desktop
);
2046 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_close
);
2048 if (functions
& Func_Move
)
2049 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_move
);
2050 if (functions
& Func_Resize
)
2051 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_resize
);
2052 if (functions
& Func_Maximize
) {
2053 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_maximize_horz
);
2054 actions
[num
++] = xatom
->getAtom(XAtom::net_wm_action_maximize_vert
);
2057 xatom
->setValue(client
.window
, XAtom::net_wm_allowed_actions
, XAtom::atom
,
2062 void BlackboxWindow::setState(unsigned long new_state
) {
2063 current_state
= new_state
;
2065 unsigned long state
[2];
2066 state
[0] = current_state
;
2068 xatom
->setValue(client
.window
, XAtom::wm_state
, XAtom::wm_state
, state
, 2);
2070 xatom
->setValue(client
.window
, XAtom::blackbox_attributes
,
2071 XAtom::blackbox_attributes
, (unsigned long *)&blackbox_attrib
,
2072 PropBlackboxAttributesElements
);
2077 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_modal
);
2079 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_shaded
);
2081 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_hidden
);
2082 if (flags
.skip_taskbar
)
2083 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_skip_taskbar
);
2084 if (flags
.skip_pager
)
2085 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_skip_pager
);
2086 if (flags
.fullscreen
)
2087 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_fullscreen
);
2088 if (flags
.maximized
== 1 || flags
.maximized
== 2)
2089 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_maximized_vert
);
2090 if (flags
.maximized
== 1 || flags
.maximized
== 3)
2091 netstate
[num
++] = xatom
->getAtom(XAtom::net_wm_state_maximized_horz
);
2092 xatom
->setValue(client
.window
, XAtom::net_wm_state
, XAtom::atom
,
2097 bool BlackboxWindow::getState(void) {
2098 bool ret
= xatom
->getValue(client
.window
, XAtom::wm_state
, XAtom::wm_state
,
2100 if (! ret
) current_state
= 0;
2105 void BlackboxWindow::restoreAttributes(void) {
2106 unsigned long num
= PropBlackboxAttributesElements
;
2107 BlackboxAttributes
*net
;
2108 if (! xatom
->getValue(client
.window
, XAtom::blackbox_attributes
,
2109 XAtom::blackbox_attributes
, num
,
2110 (unsigned long **)&net
))
2112 if (num
< PropBlackboxAttributesElements
) {
2117 if (net
->flags
& AttribShaded
&& net
->attrib
& AttribShaded
) {
2118 flags
.shaded
= False
;
2122 Because the iconic'ness of shaded windows is lost, we need to set the
2123 state to NormalState so that shaded windows on other workspaces will not
2124 get shown on the first workspace.
2125 At this point in the life of a window, current_state should only be set
2126 to IconicState if the window was an *icon*, not if it was shaded.
2128 current_state
= NormalState
;
2131 if ((net
->workspace
!= screen
->getCurrentWorkspaceID()) &&
2132 (net
->workspace
< screen
->getWorkspaceCount()))
2133 screen
->reassociateWindow(this, net
->workspace
, True
);
2135 if ((blackbox_attrib
.workspace
!= screen
->getCurrentWorkspaceID()) &&
2136 (blackbox_attrib
.workspace
< screen
->getWorkspaceCount())) {
2137 // set to WithdrawnState so it will be mapped on the new workspace
2138 if (current_state
== NormalState
) current_state
= WithdrawnState
;
2139 } else if (current_state
== WithdrawnState
) {
2140 // the window is on this workspace and is Withdrawn, so it is waiting to
2142 current_state
= NormalState
;
2145 if (net
->flags
& AttribOmnipresent
&& net
->attrib
& AttribOmnipresent
) {
2146 flags
.stuck
= False
;
2149 // if the window was on another workspace, it was going to be hidden. this
2150 // specifies that the window should be mapped since it is sticky.
2151 if (current_state
== WithdrawnState
) current_state
= NormalState
;
2154 if (net
->flags
& AttribMaxHoriz
|| net
->flags
& AttribMaxVert
) {
2155 int x
= net
->premax_x
, y
= net
->premax_y
;
2156 unsigned int w
= net
->premax_w
, h
= net
->premax_h
;
2157 flags
.maximized
= 0;
2160 if ((net
->flags
& AttribMaxHoriz
) &&
2161 (net
->flags
& AttribMaxVert
))
2162 m
= (net
->attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
2163 else if (net
->flags
& AttribMaxVert
)
2164 m
= (net
->attrib
& AttribMaxVert
) ? 2 : 0;
2165 else if (net
->flags
& AttribMaxHoriz
)
2166 m
= (net
->attrib
& AttribMaxHoriz
) ? 3 : 0;
2170 blackbox_attrib
.premax_x
= x
;
2171 blackbox_attrib
.premax_y
= y
;
2172 blackbox_attrib
.premax_w
= w
;
2173 blackbox_attrib
.premax_h
= h
;
2176 // with the state set it will then be the map event's job to read the
2177 // window's state and behave accordingly
2184 * Positions the Rect r according the the client window position and
2187 void BlackboxWindow::applyGravity(Rect
&r
) {
2188 // apply horizontal window gravity
2189 switch (client
.win_gravity
) {
2191 case NorthWestGravity
:
2192 case SouthWestGravity
:
2194 r
.setX(client
.rect
.x());
2200 r
.setX(client
.rect
.x() - (frame
.margin
.left
+ frame
.margin
.right
) / 2);
2203 case NorthEastGravity
:
2204 case SouthEastGravity
:
2206 r
.setX(client
.rect
.x() - frame
.margin
.left
- frame
.margin
.right
);
2211 r
.setX(client
.rect
.x() - frame
.margin
.left
);
2215 // apply vertical window gravity
2216 switch (client
.win_gravity
) {
2218 case NorthWestGravity
:
2219 case NorthEastGravity
:
2221 r
.setY(client
.rect
.y());
2227 r
.setY(client
.rect
.y() - (frame
.margin
.top
+ frame
.margin
.bottom
) / 2);
2230 case SouthWestGravity
:
2231 case SouthEastGravity
:
2233 r
.setY(client
.rect
.y() - frame
.margin
.top
- frame
.margin
.bottom
);
2238 r
.setY(client
.rect
.y() - frame
.margin
.top
);
2245 * The reverse of the applyGravity function.
2247 * Positions the Rect r according to the frame window position and
2250 void BlackboxWindow::restoreGravity(Rect
&r
) {
2251 // restore horizontal window gravity
2252 switch (client
.win_gravity
) {
2254 case NorthWestGravity
:
2255 case SouthWestGravity
:
2257 r
.setX(frame
.rect
.x());
2263 r
.setX(frame
.rect
.x() + (frame
.margin
.left
+ frame
.margin
.right
) / 2);
2266 case NorthEastGravity
:
2267 case SouthEastGravity
:
2269 r
.setX(frame
.rect
.x() + frame
.margin
.left
+ frame
.margin
.right
);
2274 r
.setX(frame
.rect
.x() + frame
.margin
.left
);
2278 // restore vertical window gravity
2279 switch (client
.win_gravity
) {
2281 case NorthWestGravity
:
2282 case NorthEastGravity
:
2284 r
.setY(frame
.rect
.y());
2290 r
.setY(frame
.rect
.y() + (frame
.margin
.top
+ frame
.margin
.bottom
) / 2);
2293 case SouthWestGravity
:
2294 case SouthEastGravity
:
2296 r
.setY(frame
.rect
.y() + frame
.margin
.top
+ frame
.margin
.bottom
);
2301 r
.setY(frame
.rect
.y() + frame
.margin
.top
);
2307 void BlackboxWindow::redrawLabel(void) const {
2308 if (flags
.focused
) {
2310 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2311 frame
.label
, frame
.flabel
);
2313 XSetWindowBackground(blackbox
->getXDisplay(),
2314 frame
.label
, frame
.flabel_pixel
);
2317 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2318 frame
.label
, frame
.ulabel
);
2320 XSetWindowBackground(blackbox
->getXDisplay(),
2321 frame
.label
, frame
.ulabel_pixel
);
2323 XClearWindow(blackbox
->getXDisplay(), frame
.label
);
2325 WindowStyle
*style
= screen
->getWindowStyle();
2327 int pos
= frame
.bevel_w
* 2;
2328 style
->doJustify(client
.title
.c_str(), pos
, frame
.label_w
, frame
.bevel_w
* 4);
2329 style
->font
->drawString(frame
.label
, pos
, 1,
2330 (flags
.focused
? style
->l_text_focus
:
2331 style
->l_text_unfocus
),
2336 void BlackboxWindow::redrawAllButtons(void) const {
2337 if (frame
.iconify_button
) redrawIconifyButton(False
);
2338 if (frame
.maximize_button
) redrawMaximizeButton(flags
.maximized
);
2339 if (frame
.close_button
) redrawCloseButton(False
);
2343 void BlackboxWindow::redrawIconifyButton(bool pressed
) const {
2345 if (flags
.focused
) {
2347 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2348 frame
.iconify_button
, frame
.fbutton
);
2350 XSetWindowBackground(blackbox
->getXDisplay(),
2351 frame
.iconify_button
, frame
.fbutton_pixel
);
2354 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2355 frame
.iconify_button
, frame
.ubutton
);
2357 XSetWindowBackground(blackbox
->getXDisplay(), frame
.iconify_button
,
2358 frame
.ubutton_pixel
);
2362 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2363 frame
.iconify_button
, frame
.pbutton
);
2365 XSetWindowBackground(blackbox
->getXDisplay(),
2366 frame
.iconify_button
, frame
.pbutton_pixel
);
2368 XClearWindow(blackbox
->getXDisplay(), frame
.iconify_button
);
2370 BPen
pen((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus
:
2371 screen
->getWindowStyle()->b_pic_unfocus
);
2372 XDrawRectangle(blackbox
->getXDisplay(), frame
.iconify_button
, pen
.gc(),
2373 2, (frame
.button_w
- 5), (frame
.button_w
- 5), 2);
2377 void BlackboxWindow::redrawMaximizeButton(bool pressed
) const {
2379 if (flags
.focused
) {
2381 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2382 frame
.maximize_button
, frame
.fbutton
);
2384 XSetWindowBackground(blackbox
->getXDisplay(), frame
.maximize_button
,
2385 frame
.fbutton_pixel
);
2388 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2389 frame
.maximize_button
, frame
.ubutton
);
2391 XSetWindowBackground(blackbox
->getXDisplay(), frame
.maximize_button
,
2392 frame
.ubutton_pixel
);
2396 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2397 frame
.maximize_button
, frame
.pbutton
);
2399 XSetWindowBackground(blackbox
->getXDisplay(), frame
.maximize_button
,
2400 frame
.pbutton_pixel
);
2402 XClearWindow(blackbox
->getXDisplay(), frame
.maximize_button
);
2404 BPen
pen((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus
:
2405 screen
->getWindowStyle()->b_pic_unfocus
);
2406 XDrawRectangle(blackbox
->getXDisplay(), frame
.maximize_button
, pen
.gc(),
2407 2, 2, (frame
.button_w
- 5), (frame
.button_w
- 5));
2408 XDrawLine(blackbox
->getXDisplay(), frame
.maximize_button
, pen
.gc(),
2409 2, 3, (frame
.button_w
- 3), 3);
2413 void BlackboxWindow::redrawCloseButton(bool pressed
) const {
2415 if (flags
.focused
) {
2417 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(), frame
.close_button
,
2420 XSetWindowBackground(blackbox
->getXDisplay(), frame
.close_button
,
2421 frame
.fbutton_pixel
);
2424 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(), frame
.close_button
,
2427 XSetWindowBackground(blackbox
->getXDisplay(), frame
.close_button
,
2428 frame
.ubutton_pixel
);
2432 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
2433 frame
.close_button
, frame
.pbutton
);
2435 XSetWindowBackground(blackbox
->getXDisplay(),
2436 frame
.close_button
, frame
.pbutton_pixel
);
2438 XClearWindow(blackbox
->getXDisplay(), frame
.close_button
);
2440 BPen
pen((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus
:
2441 screen
->getWindowStyle()->b_pic_unfocus
);
2442 XDrawLine(blackbox
->getXDisplay(), frame
.close_button
, pen
.gc(),
2443 2, 2, (frame
.button_w
- 3), (frame
.button_w
- 3));
2444 XDrawLine(blackbox
->getXDisplay(), frame
.close_button
, pen
.gc(),
2445 2, (frame
.button_w
- 3), (frame
.button_w
- 3), 2);
2449 void BlackboxWindow::mapRequestEvent(const XMapRequestEvent
*re
) {
2450 if (re
->window
!= client
.window
)
2454 fprintf(stderr
, "BlackboxWindow::mapRequestEvent() for 0x%lx\n",
2458 switch (current_state
) {
2463 case WithdrawnState
:
2472 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
2473 if (! blackbox
->isStartup() && (isTransient() || screen
->doFocusNew())) {
2474 XSync(blackbox
->getXDisplay(), False
); // make sure the frame is mapped..
2482 void BlackboxWindow::unmapNotifyEvent(const XUnmapEvent
*ue
) {
2483 if (ue
->window
!= client
.window
)
2487 fprintf(stderr
, "BlackboxWindow::unmapNotifyEvent() for 0x%lx\n",
2491 screen
->unmanageWindow(this, False
);
2495 void BlackboxWindow::destroyNotifyEvent(const XDestroyWindowEvent
*de
) {
2496 if (de
->window
!= client
.window
)
2500 fprintf(stderr
, "BlackboxWindow::destroyNotifyEvent() for 0x%lx\n",
2504 screen
->unmanageWindow(this, False
);
2508 void BlackboxWindow::reparentNotifyEvent(const XReparentEvent
*re
) {
2509 if (re
->window
!= client
.window
|| re
->parent
== frame
.plate
)
2513 fprintf(stderr
, "BlackboxWindow::reparentNotifyEvent(): reparent 0x%lx to "
2514 "0x%lx.\n", client
.window
, re
->parent
);
2519 XPutBackEvent(blackbox
->getXDisplay(), &ev
);
2520 screen
->unmanageWindow(this, True
);
2524 void BlackboxWindow::propertyNotifyEvent(Atom atom
) {
2527 case XA_WM_CLIENT_MACHINE
:
2531 case XA_WM_TRANSIENT_FOR
: {
2532 // determine if this is a transient window
2535 // adjust the window decorations based on transience
2536 if (isTransient()) {
2537 decorations
&= ~(Decor_Maximize
| Decor_Handle
);
2538 functions
&= ~Func_Maximize
;
2539 setAllowedActions();
2550 case XA_WM_ICON_NAME
:
2552 if (flags
.iconic
) screen
->propagateWindowName(this);
2555 case XAtom::net_wm_name
:
2559 if (decorations
& Decor_Titlebar
)
2562 screen
->propagateWindowName(this);
2565 case XA_WM_NORMAL_HINTS
: {
2568 if ((client
.normal_hint_flags
& PMinSize
) &&
2569 (client
.normal_hint_flags
& PMaxSize
)) {
2570 if (client
.max_width
<= client
.min_width
&&
2571 client
.max_height
<= client
.min_height
) {
2572 decorations
&= ~(Decor_Maximize
| Decor_Handle
);
2573 functions
&= ~(Func_Resize
| Func_Maximize
);
2575 decorations
|= Decor_Maximize
| Decor_Handle
;
2576 functions
|= Func_Resize
| Func_Maximize
;
2578 setAllowedActions();
2581 Rect old_rect
= frame
.rect
;
2585 if (old_rect
!= frame
.rect
)
2592 if (atom
== xatom
->getAtom(XAtom::wm_protocols
)) {
2595 if ((decorations
& Decor_Close
) && (! frame
.close_button
)) {
2596 createCloseButton();
2597 if (decorations
& Decor_Titlebar
) {
2598 positionButtons(True
);
2599 XMapSubwindows(blackbox
->getXDisplay(), frame
.title
);
2601 if (windowmenu
) windowmenu
->reconfigure();
2603 } else if (atom
== xatom
->getAtom(XAtom::net_wm_strut
)) {
2612 void BlackboxWindow::exposeEvent(const XExposeEvent
*ee
) {
2613 if (frame
.label
== ee
->window
&& (decorations
& Decor_Titlebar
))
2615 else if (frame
.close_button
== ee
->window
)
2616 redrawCloseButton(False
);
2617 else if (frame
.maximize_button
== ee
->window
)
2618 redrawMaximizeButton(flags
.maximized
);
2619 else if (frame
.iconify_button
== ee
->window
)
2620 redrawIconifyButton(False
);
2624 void BlackboxWindow::configureRequestEvent(const XConfigureRequestEvent
*cr
) {
2625 if (cr
->window
!= client
.window
|| flags
.iconic
)
2628 if (cr
->value_mask
& CWBorderWidth
)
2629 client
.old_bw
= cr
->border_width
;
2631 if (cr
->value_mask
& (CWX
| CWY
| CWWidth
| CWHeight
)) {
2632 Rect req
= frame
.rect
;
2634 if (cr
->value_mask
& (CWX
| CWY
)) {
2635 if (cr
->value_mask
& CWX
)
2636 client
.rect
.setX(cr
->x
);
2637 if (cr
->value_mask
& CWY
)
2638 client
.rect
.setY(cr
->y
);
2643 if (cr
->value_mask
& CWWidth
)
2644 req
.setWidth(cr
->width
+ frame
.margin
.left
+ frame
.margin
.right
);
2646 if (cr
->value_mask
& CWHeight
)
2647 req
.setHeight(cr
->height
+ frame
.margin
.top
+ frame
.margin
.bottom
);
2649 configure(req
.x(), req
.y(), req
.width(), req
.height());
2652 if (cr
->value_mask
& CWStackMode
) {
2653 switch (cr
->detail
) {
2656 screen
->getWorkspace(blackbox_attrib
.workspace
)->lowerWindow(this);
2662 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
2669 void BlackboxWindow::buttonPressEvent(const XButtonEvent
*be
) {
2670 if (frame
.maximize_button
== be
->window
) {
2671 redrawMaximizeButton(True
);
2672 } else if (be
->button
== 1 || (be
->button
== 3 && be
->state
== Mod1Mask
)) {
2673 if (! flags
.focused
)
2676 if (frame
.iconify_button
== be
->window
) {
2677 redrawIconifyButton(True
);
2678 } else if (frame
.close_button
== be
->window
) {
2679 redrawCloseButton(True
);
2680 } else if (frame
.plate
== be
->window
) {
2681 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
2683 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
2685 XAllowEvents(blackbox
->getXDisplay(), ReplayPointer
, be
->time
);
2687 if (frame
.title
== be
->window
|| frame
.label
== be
->window
) {
2688 if (((be
->time
- lastButtonPressTime
) <=
2689 blackbox
->getDoubleClickInterval()) ||
2690 (be
->state
& ControlMask
)) {
2691 lastButtonPressTime
= 0;
2694 lastButtonPressTime
= be
->time
;
2698 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
2700 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
2702 } else if (be
->button
== 2 && (be
->window
!= frame
.iconify_button
) &&
2703 (be
->window
!= frame
.close_button
)) {
2704 screen
->getWorkspace(blackbox_attrib
.workspace
)->lowerWindow(this);
2705 } else if (windowmenu
&& be
->button
== 3 &&
2706 (frame
.title
== be
->window
|| frame
.label
== be
->window
||
2707 frame
.handle
== be
->window
|| frame
.window
== be
->window
)) {
2710 if (frame
.title
== be
->window
|| frame
.label
== be
->window
) {
2711 mx
= be
->x_root
- (windowmenu
->getWidth() / 2);
2712 my
= frame
.rect
.y() + frame
.title_h
+ frame
.border_w
;
2713 } else if (frame
.handle
== be
->window
) {
2714 mx
= be
->x_root
- (windowmenu
->getWidth() / 2);
2715 my
= frame
.rect
.bottom() - frame
.handle_h
- (frame
.border_w
* 3) -
2716 windowmenu
->getHeight();
2718 mx
= be
->x_root
- (windowmenu
->getWidth() / 2);
2720 if (be
->y
<= static_cast<signed>(frame
.bevel_w
))
2721 my
= frame
.rect
.y() + frame
.title_h
;
2723 my
= be
->y_root
- (windowmenu
->getHeight() / 2);
2726 // snap the window menu into a corner if necessary - we check the
2727 // position of the menu with the coordinates of the client to
2728 // make the comparisions easier.
2729 // XXX: this needs some work!
2730 if (mx
> client
.rect
.right() -
2731 static_cast<signed>(windowmenu
->getWidth()))
2732 mx
= frame
.rect
.right() - windowmenu
->getWidth() - frame
.border_w
+ 1;
2733 if (mx
< client
.rect
.left())
2734 mx
= frame
.rect
.x();
2736 if (my
> client
.rect
.bottom() -
2737 static_cast<signed>(windowmenu
->getHeight()))
2738 my
= frame
.rect
.bottom() - windowmenu
->getHeight() - frame
.border_w
+ 1;
2739 if (my
< client
.rect
.top())
2740 my
= frame
.rect
.y() + ((decorations
& Decor_Titlebar
) ?
2744 if (! windowmenu
->isVisible()) {
2745 windowmenu
->move(mx
, my
);
2747 XRaiseWindow(blackbox
->getXDisplay(), windowmenu
->getWindowID());
2748 XRaiseWindow(blackbox
->getXDisplay(),
2749 windowmenu
->getSendToMenu()->getWindowID());
2755 } else if (be
->button
== 4) {
2756 if ((be
->window
== frame
.label
||
2757 be
->window
== frame
.title
) &&
2761 } else if (be
->button
== 5) {
2762 if ((be
->window
== frame
.label
||
2763 be
->window
== frame
.title
) &&
2770 void BlackboxWindow::buttonReleaseEvent(const XButtonEvent
*re
) {
2771 if (re
->window
== frame
.maximize_button
) {
2772 if ((re
->x
>= 0 && re
->x
<= static_cast<signed>(frame
.button_w
)) &&
2773 (re
->y
>= 0 && re
->y
<= static_cast<signed>(frame
.button_w
))) {
2774 maximize(re
->button
);
2776 redrawMaximizeButton(flags
.maximized
);
2778 } else if (re
->window
== frame
.iconify_button
) {
2779 if ((re
->x
>= 0 && re
->x
<= static_cast<signed>(frame
.button_w
)) &&
2780 (re
->y
>= 0 && re
->y
<= static_cast<signed>(frame
.button_w
))) {
2783 redrawIconifyButton(False
);
2785 } else if (re
->window
== frame
.close_button
) {
2786 if ((re
->x
>= 0 && re
->x
<= static_cast<signed>(frame
.button_w
)) &&
2787 (re
->y
>= 0 && re
->y
<= static_cast<signed>(frame
.button_w
)))
2789 redrawCloseButton(False
);
2790 } else if (flags
.moving
) {
2792 } else if (flags
.resizing
) {
2794 } else if (re
->window
== frame
.window
) {
2795 if (re
->button
== 2 && re
->state
== Mod1Mask
)
2796 XUngrabPointer(blackbox
->getXDisplay(), CurrentTime
);
2802 void BlackboxWindow::beginMove(int x_root
, int y_root
) {
2803 assert(! (flags
.resizing
|| flags
.moving
));
2806 Only one window can be moved/resized at a time. If another window is already
2807 being moved or resized, then stop it before whating to work with this one.
2809 BlackboxWindow
*changing
= blackbox
->getChangingWindow();
2810 if (changing
&& changing
!= this) {
2811 if (changing
->flags
.moving
)
2812 changing
->endMove();
2813 else // if (changing->flags.resizing)
2814 changing
->endResize();
2817 XGrabPointer(blackbox
->getXDisplay(), frame
.window
, False
,
2818 PointerMotionMask
| ButtonReleaseMask
,
2819 GrabModeAsync
, GrabModeAsync
,
2820 None
, blackbox
->getMoveCursor(), CurrentTime
);
2822 if (windowmenu
&& windowmenu
->isVisible())
2825 flags
.moving
= True
;
2826 blackbox
->setChangingWindow(this);
2828 if (! screen
->doOpaqueMove()) {
2829 XGrabServer(blackbox
->getXDisplay());
2831 frame
.changing
= frame
.rect
;
2832 screen
->showPosition(frame
.changing
.x(), frame
.changing
.y());
2834 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
2838 frame
.changing
.width() - 1,
2839 frame
.changing
.height() - 1);
2842 frame
.grab_x
= x_root
- frame
.rect
.x() - frame
.border_w
;
2843 frame
.grab_y
= y_root
- frame
.rect
.y() - frame
.border_w
;
2847 void BlackboxWindow::doMove(int x_root
, int y_root
) {
2848 assert(flags
.moving
);
2849 assert(blackbox
->getChangingWindow() == this);
2851 int dx
= x_root
- frame
.grab_x
, dy
= y_root
- frame
.grab_y
;
2852 dx
-= frame
.border_w
;
2853 dy
-= frame
.border_w
;
2855 const int snap_distance
= screen
->getEdgeSnapThreshold();
2857 if (snap_distance
) {
2859 const int wleft
= dx
,
2860 wright
= dx
+ frame
.rect
.width() - 1,
2862 wbottom
= dy
+ frame
.rect
.height() - 1;
2864 if (screen
->getWindowToWindowSnap()) {
2865 Workspace
*w
= screen
->getWorkspace(getWorkspaceNumber());
2868 // try snap to another window
2869 for (unsigned int i
= 0, c
= w
->getCount(); i
< c
; ++i
) {
2870 BlackboxWindow
*snapwin
= w
->getWindow(i
);
2871 if (snapwin
== this)
2872 continue; // don't snap to self
2874 bool snapped
= False
;
2876 const Rect
&winrect
= snapwin
->frameRect();
2877 int dleft
= std::abs(wright
- winrect
.left()),
2878 dright
= std::abs(wleft
- winrect
.right()),
2879 dtop
= std::abs(wbottom
- winrect
.top()),
2880 dbottom
= std::abs(wtop
- winrect
.bottom());
2882 if (wtop
>= (signed)(winrect
.y() - frame
.rect
.height() + 1) &&
2883 wtop
< (signed)(winrect
.y() + winrect
.height() - 1)) {
2885 // snap left of other window?
2886 if (dleft
< snap_distance
&& dleft
<= dright
) {
2887 dx
= winrect
.left() - frame
.rect
.width();
2890 // snap right of other window?
2891 else if (dright
< snap_distance
) {
2892 dx
= winrect
.right() + 1;
2897 if (screen
->getWindowCornerSnap()) {
2898 // try corner-snap to its other sides
2899 dtop
= std::abs(wtop
- winrect
.top());
2900 dbottom
= std::abs(wbottom
- winrect
.bottom());
2901 if (dtop
< snap_distance
&& dtop
<= dbottom
)
2903 else if (dbottom
< snap_distance
)
2904 dy
= winrect
.bottom() - frame
.rect
.height() + 1;
2911 if (wleft
>= (signed)(winrect
.x() - frame
.rect
.width() + 1) &&
2912 wleft
< (signed)(winrect
.x() + winrect
.width() - 1)) {
2914 // snap top of other window?
2915 if (dtop
< snap_distance
&& dtop
<= dbottom
) {
2916 dy
= winrect
.top() - frame
.rect
.height();
2919 // snap bottom of other window?
2920 else if (dbottom
< snap_distance
) {
2921 dy
= winrect
.bottom() + 1;
2926 if (screen
->getWindowCornerSnap()) {
2927 // try corner-snap to its other sides
2928 dleft
= std::abs(wleft
- winrect
.left());
2929 dright
= std::abs(wright
- winrect
.right());
2930 if (dleft
< snap_distance
&& dleft
<= dright
)
2931 dx
= winrect
.left();
2932 else if (dright
< snap_distance
)
2933 dx
= winrect
.right() - frame
.rect
.width() + 1;
2942 // try snap to the screen's available area
2943 Rect srect
= screen
->availableArea();
2945 int dleft
= std::abs(wleft
- srect
.left()),
2946 dright
= std::abs(wright
- srect
.right()),
2947 dtop
= std::abs(wtop
- srect
.top()),
2948 dbottom
= std::abs(wbottom
- srect
.bottom());
2951 if (dleft
< snap_distance
&& dleft
<= dright
)
2954 else if (dright
< snap_distance
)
2955 dx
= srect
.right() - frame
.rect
.width() + 1;
2958 if (dtop
< snap_distance
&& dtop
<= dbottom
)
2961 else if (dbottom
< snap_distance
)
2962 dy
= srect
.bottom() - frame
.rect
.height() + 1;
2964 srect
= screen
->getRect(); // now get the full screen
2966 dleft
= std::abs(wleft
- srect
.left()),
2967 dright
= std::abs(wright
- srect
.right()),
2968 dtop
= std::abs(wtop
- srect
.top()),
2969 dbottom
= std::abs(wbottom
- srect
.bottom());
2972 if (dleft
< snap_distance
&& dleft
<= dright
)
2975 else if (dright
< snap_distance
)
2976 dx
= srect
.right() - frame
.rect
.width() + 1;
2979 if (dtop
< snap_distance
&& dtop
<= dbottom
)
2982 else if (dbottom
< snap_distance
)
2983 dy
= srect
.bottom() - frame
.rect
.height() + 1;
2986 if (screen
->doOpaqueMove()) {
2987 configure(dx
, dy
, frame
.rect
.width(), frame
.rect
.height());
2989 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
2993 frame
.changing
.width() - 1,
2994 frame
.changing
.height() - 1);
2996 frame
.changing
.setPos(dx
, dy
);
2998 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
3002 frame
.changing
.width() - 1,
3003 frame
.changing
.height() - 1);
3006 screen
->showPosition(dx
, dy
);
3010 void BlackboxWindow::endMove(void) {
3011 assert(flags
.moving
);
3012 assert(blackbox
->getChangingWindow() == this);
3014 flags
.moving
= False
;
3015 blackbox
->setChangingWindow(0);
3017 if (! screen
->doOpaqueMove()) {
3018 /* when drawing the rubber band, we need to make sure we only draw inside
3019 * the frame... frame.changing_* contain the new coords for the window,
3020 * so we need to subtract 1 from changing_w/changing_h every where we
3021 * draw the rubber band (for both moving and resizing)
3023 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
3024 screen
->getOpGC(), frame
.changing
.x(), frame
.changing
.y(),
3025 frame
.changing
.width() - 1, frame
.changing
.height() - 1);
3026 XUngrabServer(blackbox
->getXDisplay());
3028 configure(frame
.changing
.x(), frame
.changing
.y(),
3029 frame
.changing
.width(), frame
.changing
.height());
3031 configure(frame
.rect
.x(), frame
.rect
.y(),
3032 frame
.rect
.width(), frame
.rect
.height());
3034 screen
->hideGeometry();
3036 XUngrabPointer(blackbox
->getXDisplay(), CurrentTime
);
3038 // if there are any left over motions from the move, drop them now
3039 XSync(blackbox
->getXDisplay(), false); // make sure we don't miss any
3041 while (XCheckTypedWindowEvent(blackbox
->getXDisplay(), frame
.window
,
3046 void BlackboxWindow::beginResize(int x_root
, int y_root
, Corner dir
) {
3047 assert(! (flags
.resizing
|| flags
.moving
));
3050 Only one window can be moved/resized at a time. If another window is already
3051 being moved or resized, then stop it before whating to work with this one.
3053 BlackboxWindow
*changing
= blackbox
->getChangingWindow();
3054 if (changing
&& changing
!= this) {
3055 if (changing
->flags
.moving
)
3056 changing
->endMove();
3057 else // if (changing->flags.resizing)
3058 changing
->endResize();
3066 switch (resize_dir
) {
3069 cursor
= blackbox
->getLowerLeftAngleCursor();
3074 cursor
= blackbox
->getLowerRightAngleCursor();
3078 anchor
= BottomRight
;
3079 cursor
= blackbox
->getUpperLeftAngleCursor();
3083 anchor
= BottomLeft
;
3084 cursor
= blackbox
->getUpperRightAngleCursor();
3088 assert(false); // unhandled Corner
3091 XGrabServer(blackbox
->getXDisplay());
3092 XGrabPointer(blackbox
->getXDisplay(), frame
.window
, False
,
3093 PointerMotionMask
| ButtonReleaseMask
,
3094 GrabModeAsync
, GrabModeAsync
, None
, cursor
, CurrentTime
);
3096 flags
.resizing
= True
;
3097 blackbox
->setChangingWindow(this);
3100 frame
.changing
= frame
.rect
;
3102 constrain(anchor
, &gw
, &gh
);
3104 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
3105 screen
->getOpGC(), frame
.changing
.x(), frame
.changing
.y(),
3106 frame
.changing
.width() - 1, frame
.changing
.height() - 1);
3108 screen
->showGeometry(gw
, gh
);
3110 frame
.grab_x
= x_root
;
3111 frame
.grab_y
= y_root
;
3115 void BlackboxWindow::doResize(int x_root
, int y_root
) {
3116 assert(flags
.resizing
);
3117 assert(blackbox
->getChangingWindow() == this);
3119 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
3120 screen
->getOpGC(), frame
.changing
.x(), frame
.changing
.y(),
3121 frame
.changing
.width() - 1, frame
.changing
.height() - 1);
3126 switch (resize_dir
) {
3129 frame
.changing
.setSize(frame
.rect
.width() - (x_root
- frame
.grab_x
),
3130 frame
.rect
.height() + (y_root
- frame
.grab_y
));
3134 frame
.changing
.setSize(frame
.rect
.width() + (x_root
- frame
.grab_x
),
3135 frame
.rect
.height() + (y_root
- frame
.grab_y
));
3138 anchor
= BottomRight
;
3139 frame
.changing
.setSize(frame
.rect
.width() - (x_root
- frame
.grab_x
),
3140 frame
.rect
.height() - (y_root
- frame
.grab_y
));
3143 anchor
= BottomLeft
;
3144 frame
.changing
.setSize(frame
.rect
.width() + (x_root
- frame
.grab_x
),
3145 frame
.rect
.height() - (y_root
- frame
.grab_y
));
3149 assert(false); // unhandled Corner
3152 constrain(anchor
, &gw
, &gh
);
3154 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
3155 screen
->getOpGC(), frame
.changing
.x(), frame
.changing
.y(),
3156 frame
.changing
.width() - 1, frame
.changing
.height() - 1);
3158 screen
->showGeometry(gw
, gh
);
3162 void BlackboxWindow::endResize(void) {
3163 assert(flags
.resizing
);
3164 assert(blackbox
->getChangingWindow() == this);
3166 XDrawRectangle(blackbox
->getXDisplay(), screen
->getRootWindow(),
3167 screen
->getOpGC(), frame
.changing
.x(), frame
.changing
.y(),
3168 frame
.changing
.width() - 1, frame
.changing
.height() - 1);
3169 XUngrabServer(blackbox
->getXDisplay());
3171 // unset maximized state after resized when fully maximized
3172 if (flags
.maximized
== 1)
3175 flags
.resizing
= False
;
3176 blackbox
->setChangingWindow(0);
3178 configure(frame
.changing
.x(), frame
.changing
.y(),
3179 frame
.changing
.width(), frame
.changing
.height());
3180 screen
->hideGeometry();
3182 XUngrabPointer(blackbox
->getXDisplay(), CurrentTime
);
3184 // if there are any left over motions from the resize, drop them now
3185 XSync(blackbox
->getXDisplay(), false); // make sure we don't miss any
3187 while (XCheckTypedWindowEvent(blackbox
->getXDisplay(), frame
.window
,
3192 void BlackboxWindow::motionNotifyEvent(const XMotionEvent
*me
) {
3194 doMove(me
->x_root
, me
->y_root
);
3195 } else if (flags
.resizing
) {
3196 doResize(me
->x_root
, me
->y_root
);
3198 if (! flags
.resizing
&& (me
->state
& Button1Mask
) &&
3199 (functions
& Func_Move
) &&
3200 (frame
.title
== me
->window
|| frame
.label
== me
->window
||
3201 frame
.handle
== me
->window
|| frame
.window
== me
->window
)) {
3202 beginMove(me
->x_root
, me
->y_root
);
3203 } else if ((functions
& Func_Resize
) &&
3204 (((me
->state
& Button1Mask
) &&
3205 (me
->window
== frame
.right_grip
||
3206 me
->window
== frame
.left_grip
)) ||
3207 (me
->state
& (Mod1Mask
| Button3Mask
) &&
3208 me
->window
== frame
.window
))) {
3209 beginResize(me
->x_root
, me
->y_root
,
3210 (me
->window
== frame
.left_grip
) ? BottomLeft
: BottomRight
);
3217 void BlackboxWindow::shapeEvent(XShapeEvent
*) {
3218 if (blackbox
->hasShapeExtensions() && flags
.shaped
) {
3225 bool BlackboxWindow::validateClient(void) const {
3226 XSync(blackbox
->getXDisplay(), False
);
3229 if (XCheckTypedWindowEvent(blackbox
->getXDisplay(), client
.window
,
3230 DestroyNotify
, &e
) ||
3231 XCheckTypedWindowEvent(blackbox
->getXDisplay(), client
.window
,
3233 XPutBackEvent(blackbox
->getXDisplay(), &e
);
3242 void BlackboxWindow::restore(bool remap
) {
3243 XChangeSaveSet(blackbox
->getXDisplay(), client
.window
, SetModeDelete
);
3244 XSelectInput(blackbox
->getXDisplay(), client
.window
, NoEventMask
);
3245 XSelectInput(blackbox
->getXDisplay(), frame
.plate
, NoEventMask
);
3247 restoreGravity(client
.rect
);
3249 XUnmapWindow(blackbox
->getXDisplay(), frame
.window
);
3250 XUnmapWindow(blackbox
->getXDisplay(), client
.window
);
3252 XSetWindowBorderWidth(blackbox
->getXDisplay(), client
.window
, client
.old_bw
);
3255 if (XCheckTypedWindowEvent(blackbox
->getXDisplay(), client
.window
,
3256 ReparentNotify
, &ev
)) {
3259 // according to the ICCCM - if the client doesn't reparent to
3260 // root, then we have to do it for them
3261 XReparentWindow(blackbox
->getXDisplay(), client
.window
,
3262 screen
->getRootWindow(),
3263 client
.rect
.x(), client
.rect
.y());
3266 if (remap
) XMapWindow(blackbox
->getXDisplay(), client
.window
);
3270 // timer for autoraise
3271 void BlackboxWindow::timeout(void) {
3272 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
3276 void BlackboxWindow::changeBlackboxHints(BlackboxHints
*net
) {
3277 if ((net
->flags
& AttribShaded
) &&
3278 ((blackbox_attrib
.attrib
& AttribShaded
) !=
3279 (net
->attrib
& AttribShaded
)))
3282 if (flags
.visible
&& // watch out for requests when we can not be seen
3283 (net
->flags
& (AttribMaxVert
| AttribMaxHoriz
)) &&
3284 ((blackbox_attrib
.attrib
& (AttribMaxVert
| AttribMaxHoriz
)) !=
3285 (net
->attrib
& (AttribMaxVert
| AttribMaxHoriz
)))) {
3286 if (flags
.maximized
) {
3291 if ((net
->flags
& AttribMaxHoriz
) && (net
->flags
& AttribMaxVert
))
3292 button
= ((net
->attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0);
3293 else if (net
->flags
& AttribMaxVert
)
3294 button
= ((net
->attrib
& AttribMaxVert
) ? 2 : 0);
3295 else if (net
->flags
& AttribMaxHoriz
)
3296 button
= ((net
->attrib
& AttribMaxHoriz
) ? 3 : 0);
3302 if ((net
->flags
& AttribOmnipresent
) &&
3303 ((blackbox_attrib
.attrib
& AttribOmnipresent
) !=
3304 (net
->attrib
& AttribOmnipresent
)))
3307 if ((net
->flags
& AttribWorkspace
) &&
3308 (blackbox_attrib
.workspace
!= net
->workspace
)) {
3309 screen
->reassociateWindow(this, net
->workspace
, True
);
3311 if (screen
->getCurrentWorkspaceID() != net
->workspace
) {
3315 screen
->getWorkspace(blackbox_attrib
.workspace
)->raiseWindow(this);
3319 if (net
->flags
& AttribDecoration
) {
3320 switch (net
->decoration
) {
3322 // clear all decorations except close
3323 decorations
&= Decor_Close
;
3329 decorations
|= Decor_Titlebar
| Decor_Border
| Decor_Iconify
;
3331 decorations
= ((functions
& Func_Resize
) && !isTransient() ?
3332 decorations
| Decor_Handle
:
3333 decorations
&= ~Decor_Handle
);
3334 decorations
= (functions
& Func_Maximize
?
3335 decorations
| Decor_Maximize
:
3336 decorations
&= ~Decor_Maximize
);
3341 decorations
|= Decor_Titlebar
| Decor_Iconify
;
3342 decorations
&= ~(Decor_Border
| Decor_Handle
);
3344 decorations
= (functions
& Func_Maximize
?
3345 decorations
| Decor_Maximize
:
3346 decorations
&= ~Decor_Maximize
);
3351 decorations
|= Decor_Titlebar
;
3352 decorations
&= ~(Decor_Iconify
| Decor_Border
);
3354 decorations
= ((functions
& Func_Resize
) && !isTransient() ?
3355 decorations
| Decor_Handle
:
3356 decorations
&= ~Decor_Handle
);
3357 decorations
= (functions
& Func_Maximize
?
3358 decorations
| Decor_Maximize
:
3359 decorations
&= ~Decor_Maximize
);
3364 // we can not be shaded if we lack a titlebar
3365 if (flags
.shaded
&& ! (decorations
& Decor_Titlebar
))
3368 if (flags
.visible
&& frame
.window
) {
3369 XMapSubwindows(blackbox
->getXDisplay(), frame
.window
);
3370 XMapWindow(blackbox
->getXDisplay(), frame
.window
);
3374 setState(current_state
);
3380 * Set the sizes of all components of the window frame
3381 * (the window decorations).
3382 * These values are based upon the current style settings and the client
3383 * window's dimensions.
3385 void BlackboxWindow::upsize(void) {
3386 frame
.bevel_w
= screen
->getBevelWidth();
3388 if (decorations
& Decor_Border
) {
3389 frame
.border_w
= screen
->getBorderWidth();
3390 if (! isTransient())
3391 frame
.mwm_border_w
= screen
->getFrameWidth();
3393 frame
.mwm_border_w
= 0;
3395 frame
.mwm_border_w
= frame
.border_w
= 0;
3398 if (decorations
& Decor_Titlebar
) {
3399 // the height of the titlebar is based upon the height of the font being
3400 // used to display the window's title
3401 WindowStyle
*style
= screen
->getWindowStyle();
3402 frame
.title_h
= style
->font
->height() + (frame
.bevel_w
* 2) + 2;
3404 frame
.label_h
= frame
.title_h
- (frame
.bevel_w
* 2);
3405 frame
.button_w
= (frame
.label_h
- 2);
3407 // set the top frame margin
3408 frame
.margin
.top
= frame
.border_w
+ frame
.title_h
+
3409 frame
.border_w
+ frame
.mwm_border_w
;
3415 // set the top frame margin
3416 frame
.margin
.top
= frame
.border_w
+ frame
.mwm_border_w
;
3419 // set the left/right frame margin
3420 frame
.margin
.left
= frame
.margin
.right
= frame
.border_w
+ frame
.mwm_border_w
;
3422 if (decorations
& Decor_Handle
) {
3423 frame
.grip_w
= frame
.button_w
* 2;
3424 frame
.handle_h
= screen
->getHandleWidth();
3426 // set the bottom frame margin
3427 frame
.margin
.bottom
= frame
.border_w
+ frame
.handle_h
+
3428 frame
.border_w
+ frame
.mwm_border_w
;
3433 // set the bottom frame margin
3434 frame
.margin
.bottom
= frame
.border_w
+ frame
.mwm_border_w
;
3438 We first get the normal dimensions and use this to define the inside_w/h
3439 then we modify the height if shading is in effect.
3440 If the shade state is not considered then frame.rect gets reset to the
3441 normal window size on a reconfigure() call resulting in improper
3442 dimensions appearing in move/resize and other events.
3445 height
= client
.rect
.height() + frame
.margin
.top
+ frame
.margin
.bottom
,
3446 width
= client
.rect
.width() + frame
.margin
.left
+ frame
.margin
.right
;
3448 frame
.inside_w
= width
- (frame
.border_w
* 2);
3449 frame
.inside_h
= height
- (frame
.border_w
* 2);
3452 height
= frame
.title_h
+ (frame
.border_w
* 2);
3453 frame
.rect
.setSize(width
, height
);
3458 * Calculate the size of the client window and constrain it to the
3459 * size specified by the size hints of the client window.
3461 * The logical width and height are placed into pw and ph, if they
3462 * are non-zero. Logical size refers to the users perception of
3463 * the window size (for example an xterm resizes in cells, not in pixels).
3465 * The physical geometry is placed into frame.changing_{x,y,width,height}.
3466 * Physical geometry refers to the geometry of the window in pixels.
3468 void BlackboxWindow::constrain(Corner anchor
, int *pw
, int *ph
) {
3469 // frame.changing represents the requested frame size, we need to
3470 // strip the frame margin off and constrain the client size
3471 frame
.changing
.setCoords(frame
.changing
.left() + frame
.margin
.left
,
3472 frame
.changing
.top() + frame
.margin
.top
,
3473 frame
.changing
.right() - frame
.margin
.right
,
3474 frame
.changing
.bottom() - frame
.margin
.bottom
);
3476 int dw
= frame
.changing
.width(), dh
= frame
.changing
.height(),
3477 base_width
= (client
.base_width
) ? client
.base_width
: client
.min_width
,
3478 base_height
= (client
.base_height
) ? client
.base_height
:
3482 if (dw
< static_cast<signed>(client
.min_width
)) dw
= client
.min_width
;
3483 if (dh
< static_cast<signed>(client
.min_height
)) dh
= client
.min_height
;
3484 if (dw
> static_cast<signed>(client
.max_width
)) dw
= client
.max_width
;
3485 if (dh
> static_cast<signed>(client
.max_height
)) dh
= client
.max_height
;
3488 dw
/= client
.width_inc
;
3490 dh
/= client
.height_inc
;
3493 if (client
.width_inc
== 1)
3494 *pw
= dw
+ base_width
;
3499 if (client
.height_inc
== 1)
3500 *ph
= dh
+ base_height
;
3505 dw
*= client
.width_inc
;
3507 dh
*= client
.height_inc
;
3510 frame
.changing
.setSize(dw
, dh
);
3512 // add the frame margin back onto frame.changing
3513 frame
.changing
.setCoords(frame
.changing
.left() - frame
.margin
.left
,
3514 frame
.changing
.top() - frame
.margin
.top
,
3515 frame
.changing
.right() + frame
.margin
.right
,
3516 frame
.changing
.bottom() + frame
.margin
.bottom
);
3518 // move frame.changing to the specified anchor
3526 dx
= frame
.rect
.right() - frame
.changing
.right();
3530 dy
= frame
.rect
.bottom() - frame
.changing
.bottom();
3534 dx
= frame
.rect
.right() - frame
.changing
.right();
3535 dy
= frame
.rect
.bottom() - frame
.changing
.bottom();
3539 assert(false); // unhandled corner
3541 frame
.changing
.setPos(frame
.changing
.x() + dx
, frame
.changing
.y() + dy
);
3545 void WindowStyle::doJustify(const std::string
&text
, int &start_pos
,
3546 unsigned int max_length
,
3547 unsigned int modifier
) const {
3548 size_t text_len
= text
.size();
3549 unsigned int length
;
3552 length
= font
->measureString(string(text
, 0, text_len
)) + modifier
;
3553 } while (length
> max_length
&& text_len
-- > 0);
3557 start_pos
+= max_length
- length
;
3561 start_pos
+= (max_length
- length
) / 2;
3571 BWindowGroup::BWindowGroup(Blackbox
*b
, Window _group
)
3572 : blackbox(b
), group(_group
) {
3573 XWindowAttributes wattrib
;
3574 if (! XGetWindowAttributes(blackbox
->getXDisplay(), group
, &wattrib
)) {
3575 // group window doesn't seem to exist anymore
3581 watch for destroy notify on the group window (in addition to
3582 any other events we are looking for)
3584 since some managed windows can also be window group controllers,
3585 we need to make sure that we don't clobber the event mask for the
3588 XSelectInput(blackbox
->getXDisplay(), group
,
3589 wattrib
.your_event_mask
| StructureNotifyMask
);
3591 blackbox
->saveGroupSearch(group
, this);
3595 BWindowGroup::~BWindowGroup(void) {
3596 blackbox
->removeGroupSearch(group
);
3601 BWindowGroup::find(BScreen
*screen
, bool allow_transients
) const {
3602 BlackboxWindow
*ret
= blackbox
->getFocusedWindow();
3604 // does the focus window match (or any transient_fors)?
3606 if (ret
->getScreen() == screen
&& ret
->getGroupWindow() == group
) {
3607 if (ret
->isTransient() && allow_transients
) break;
3608 else if (! ret
->isTransient()) break;
3611 ret
= ret
->getTransientFor();
3614 if (ret
) return ret
;
3616 // the focus window didn't match, look in the group's window list
3617 BlackboxWindowList::const_iterator it
, end
= windowList
.end();
3618 for (it
= windowList
.begin(); it
!= end
; ++it
) {
3620 if (ret
->getScreen() == screen
&& ret
->getGroupWindow() == group
) {
3621 if (ret
->isTransient() && allow_transients
) break;
3622 else if (! ret
->isTransient()) break;