1 // Window.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
33 #include <X11/Xatom.h>
34 #include <X11/keysym.h>
38 #endif // HAVE_STRING_H
43 # endif // HAVE_STDIO_H
52 #include "Windowmenu.h"
53 #include "Workspace.h"
60 * Initializes the class with default values/the window's set initial values.
62 OpenboxWindow::OpenboxWindow(Openbox
&o
, Window w
, BScreen
*s
) : openbox(o
) {
64 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowCreating
,
65 "OpenboxWindow::OpenboxWindow(): creating 0x%lx\n"),
70 display
= openbox
.getXDisplay();
73 if (! validateClient()) return;
75 // fetch client size and placement
76 XWindowAttributes wattrib
;
77 if ((! XGetWindowAttributes(display
, client
.window
, &wattrib
)) ||
78 (! wattrib
.screen
) || wattrib
.override_redirect
) {
81 i18n
->getMessage(WindowSet
, WindowXGetWindowAttributesFail
,
82 "OpenboxWindow::OpenboxWindow(): XGetWindowAttributes "
93 screen
= openbox
.searchScreen(RootWindowOfScreen(wattrib
.screen
));
96 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowCannotFindScreen
,
97 "OpenboxWindow::OpenboxWindow(): can't find screen\n"
98 "\tfor root window 0x%lx\n"),
99 RootWindowOfScreen(wattrib
.screen
));
107 flags
.moving
= flags
.resizing
= flags
.shaded
= flags
.visible
=
108 flags
.iconic
= flags
.transient
= flags
.focused
=
109 flags
.stuck
= flags
.modal
= flags
.send_focus_message
=
110 flags
.shaped
= flags
.managed
= False
;
113 openbox_attrib
.workspace
= workspace_number
= window_number
= -1;
115 openbox_attrib
.flags
= openbox_attrib
.attrib
= openbox_attrib
.stack
116 = openbox_attrib
.decoration
= 0l;
117 openbox_attrib
.premax_x
= openbox_attrib
.premax_y
= 0;
118 openbox_attrib
.premax_w
= openbox_attrib
.premax_h
= 0;
120 frame
.window
= frame
.plate
= frame
.title
= frame
.handle
= None
;
121 frame
.close_button
= frame
.iconify_button
= frame
.maximize_button
= None
;
122 frame
.right_grip
= frame
.left_grip
= None
;
124 frame
.utitle
= frame
.ftitle
= frame
.uhandle
= frame
.fhandle
= None
;
125 frame
.ulabel
= frame
.flabel
= frame
.ubutton
= frame
.fbutton
= None
;
126 frame
.pbutton
= frame
.ugrip
= frame
.fgrip
= None
;
128 decorations
.titlebar
= decorations
.border
= decorations
.handle
= True
;
129 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= True
;
130 functions
.resize
= functions
.move
= functions
.iconify
=
131 functions
.maximize
= True
;
132 functions
.close
= decorations
.close
= False
;
134 client
.wm_hint_flags
= client
.normal_hint_flags
= 0;
135 client
.transient_for
= client
.transient
= 0;
137 client
.title_len
= 0;
138 client
.icon_title
= 0;
139 client
.mwm_hint
= (MwmHints
*) 0;
140 client
.openbox_hint
= (OpenboxHints
*) 0;
142 // get the initial size and location of client window (relative to the
143 // _root window_). This position is the reference point used with the
144 // window's gravity to find the window's initial position.
145 client
.x
= wattrib
.x
;
146 client
.y
= wattrib
.y
;
147 client
.width
= wattrib
.width
;
148 client
.height
= wattrib
.height
;
149 client
.old_bw
= wattrib
.border_width
;
152 lastButtonPressTime
= 0;
153 image_ctrl
= screen
->getImageControl();
155 timer
= new BTimer(openbox
, *this);
156 timer
->setTimeout(openbox
.getAutoRaiseDelay());
157 timer
->fireOnce(True
);
160 if (! client
.openbox_hint
)
163 // get size, aspect, minimum/maximum size and other hints set by the
170 if (client
.initial_state
== WithdrawnState
) {
171 screen
->getSlit()->addClient(client
.window
);
178 flags
.managed
= True
;
179 openbox
.saveWindowSearch(client
.window
, this);
181 // determine if this is a transient window
183 if (XGetTransientForHint(display
, client
.window
, &win
)) {
184 if (win
&& (win
!= client
.window
)) {
186 if ((tr
= openbox
.searchWindow(win
))) {
187 while (tr
->client
.transient
) tr
= tr
->client
.transient
;
188 client
.transient_for
= tr
;
189 tr
->client
.transient
= this;
190 flags
.stuck
= client
.transient_for
->flags
.stuck
;
191 flags
.transient
= True
;
192 } else if (win
== client
.window_group
) {
193 if ((tr
= openbox
.searchGroup(win
, this))) {
194 while (tr
->client
.transient
) tr
= tr
->client
.transient
;
195 client
.transient_for
= tr
;
196 tr
->client
.transient
= this;
197 flags
.stuck
= client
.transient_for
->flags
.stuck
;
198 flags
.transient
= True
;
203 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
206 // adjust the window decorations based on transience and window sizes
208 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
210 if ((client
.normal_hint_flags
& PMinSize
) &&
211 (client
.normal_hint_flags
& PMaxSize
) &&
212 client
.max_width
<= client
.min_width
&&
213 client
.max_height
<= client
.min_height
) {
214 decorations
.maximize
= decorations
.handle
=
215 functions
.resize
= functions
.maximize
= False
;
219 Bool place_window
= True
;
220 if (openbox
.isStartup() || flags
.transient
||
221 client
.normal_hint_flags
& (PPosition
|USPosition
)) {
224 if ((openbox
.isStartup()) ||
226 (signed) (frame
.y
+ frame
.y_border
) >= 0 &&
227 frame
.x
<= (signed) screen
->size().w() &&
228 frame
.y
<= (signed) screen
->size().h()))
229 place_window
= False
;
232 frame
.window
= createToplevelWindow(frame
.x
, frame
.y
, frame
.width
,
235 openbox
.saveWindowSearch(frame
.window
, this);
237 frame
.plate
= createChildWindow(frame
.window
);
238 openbox
.saveWindowSearch(frame
.plate
, this);
240 if (decorations
.titlebar
) {
241 frame
.title
= createChildWindow(frame
.window
);
242 frame
.label
= createChildWindow(frame
.title
);
243 openbox
.saveWindowSearch(frame
.title
, this);
244 openbox
.saveWindowSearch(frame
.label
, this);
247 if (decorations
.handle
) {
248 frame
.handle
= createChildWindow(frame
.window
);
249 openbox
.saveWindowSearch(frame
.handle
, this);
252 createChildWindow(frame
.handle
, openbox
.getLowerLeftAngleCursor());
253 openbox
.saveWindowSearch(frame
.left_grip
, this);
256 createChildWindow(frame
.handle
, openbox
.getLowerRightAngleCursor());
257 openbox
.saveWindowSearch(frame
.right_grip
, this);
260 associateClientWindow();
262 if (! screen
->sloppyFocus())
263 openbox
.grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
264 GrabModeSync
, GrabModeSync
, None
, None
);
266 openbox
.grabButton(Button1
, Mod1Mask
, frame
.window
, True
,
267 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
268 GrabModeAsync
, None
, openbox
.getMoveCursor());
269 openbox
.grabButton(Button2
, Mod1Mask
, frame
.window
, True
,
270 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
, None
);
271 openbox
.grabButton(Button3
, Mod1Mask
, frame
.window
, True
,
272 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
273 GrabModeAsync
, None
, None
);
276 XRaiseWindow(display
, frame
.plate
);
277 XMapSubwindows(display
, frame
.plate
);
278 if (decorations
.titlebar
) XMapSubwindows(display
, frame
.title
);
279 XMapSubwindows(display
, frame
.window
);
281 if (decorations
.menu
)
282 windowmenu
= new Windowmenu(*this);
286 if (workspace_number
< 0 || workspace_number
>= screen
->getWorkspaceCount())
287 screen
->getCurrentWorkspace()->addWindow(this, place_window
);
289 screen
->getWorkspace(workspace_number
)->addWindow(this, place_window
);
291 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
294 flags
.shaded
= False
;
298 if (flags
.maximized
&& functions
.maximize
) {
299 unsigned int button
= flags
.maximized
;
310 OpenboxWindow::~OpenboxWindow(void) {
311 if (flags
.moving
|| flags
.resizing
) {
312 screen
->hideGeometry();
313 XUngrabPointer(display
, CurrentTime
);
316 if (workspace_number
!= -1 && window_number
!= -1)
317 screen
->getWorkspace(workspace_number
)->removeWindow(this);
318 else if (flags
.iconic
)
319 screen
->removeIcon(this);
322 if (timer
->isTiming()) timer
->stop();
326 if (windowmenu
) delete windowmenu
;
329 delete [] client
.title
;
331 if (client
.icon_title
)
332 delete [] client
.icon_title
;
335 XFree(client
.mwm_hint
);
337 if (client
.openbox_hint
)
338 XFree(client
.openbox_hint
);
340 if (client
.window_group
)
341 openbox
.removeGroupSearch(client
.window_group
);
343 if (flags
.transient
&& client
.transient_for
)
344 client
.transient_for
->client
.transient
= client
.transient
;
345 if (client
.transient
)
346 client
.transient
->client
.transient_for
= client
.transient_for
;
348 if (frame
.close_button
) {
349 openbox
.removeWindowSearch(frame
.close_button
);
350 XDestroyWindow(display
, frame
.close_button
);
353 if (frame
.iconify_button
) {
354 openbox
.removeWindowSearch(frame
.iconify_button
);
355 XDestroyWindow(display
, frame
.iconify_button
);
358 if (frame
.maximize_button
) {
359 openbox
.removeWindowSearch(frame
.maximize_button
);
360 XDestroyWindow(display
, frame
.maximize_button
);
365 image_ctrl
->removeImage(frame
.ftitle
);
368 image_ctrl
->removeImage(frame
.utitle
);
371 image_ctrl
->removeImage(frame
.flabel
);
374 image_ctrl
->removeImage(frame
.ulabel
);
376 openbox
.removeWindowSearch(frame
.label
);
377 openbox
.removeWindowSearch(frame
.title
);
378 XDestroyWindow(display
, frame
.label
);
379 XDestroyWindow(display
, frame
.title
);
384 image_ctrl
->removeImage(frame
.fhandle
);
387 image_ctrl
->removeImage(frame
.uhandle
);
390 image_ctrl
->removeImage(frame
.fgrip
);
393 image_ctrl
->removeImage(frame
.ugrip
);
395 openbox
.removeWindowSearch(frame
.handle
);
396 openbox
.removeWindowSearch(frame
.right_grip
);
397 openbox
.removeWindowSearch(frame
.left_grip
);
398 XDestroyWindow(display
, frame
.right_grip
);
399 XDestroyWindow(display
, frame
.left_grip
);
400 XDestroyWindow(display
, frame
.handle
);
404 image_ctrl
->removeImage(frame
.fbutton
);
407 image_ctrl
->removeImage(frame
.ubutton
);
410 image_ctrl
->removeImage(frame
.pbutton
);
413 openbox
.removeWindowSearch(frame
.plate
);
414 XDestroyWindow(display
, frame
.plate
);
418 openbox
.removeWindowSearch(frame
.window
);
419 XDestroyWindow(display
, frame
.window
);
423 openbox
.removeWindowSearch(client
.window
);
424 screen
->removeNetizen(client
.window
);
430 * Creates a new top level window, with a given location, size, and border
432 * Returns: the newly created window
434 Window
OpenboxWindow::createToplevelWindow(int x
, int y
, unsigned int width
,
436 unsigned int borderwidth
)
438 XSetWindowAttributes attrib_create
;
439 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
| CWColormap
|
440 CWOverrideRedirect
| CWEventMask
;
442 attrib_create
.background_pixmap
= None
;
443 attrib_create
.colormap
= screen
->getColormap();
444 attrib_create
.override_redirect
= True
;
445 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
446 ButtonMotionMask
| EnterWindowMask
;
448 return XCreateWindow(display
, screen
->getRootWindow(), x
, y
, width
, height
,
449 borderwidth
, screen
->getDepth(), InputOutput
,
450 screen
->getVisual(), create_mask
,
456 * Creates a child window, and optionally associates a given cursor with
459 Window
OpenboxWindow::createChildWindow(Window parent
, Cursor cursor
) {
460 XSetWindowAttributes attrib_create
;
461 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
|
464 attrib_create
.background_pixmap
= None
;
465 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
466 ButtonMotionMask
| ExposureMask
|
467 EnterWindowMask
| LeaveWindowMask
;
470 create_mask
|= CWCursor
;
471 attrib_create
.cursor
= cursor
;
474 return XCreateWindow(display
, parent
, 0, 0, 1, 1, 0, screen
->getDepth(),
475 InputOutput
, screen
->getVisual(), create_mask
,
480 void OpenboxWindow::associateClientWindow(void) {
481 XSetWindowBorderWidth(display
, client
.window
, 0);
485 XChangeSaveSet(display
, client
.window
, SetModeInsert
);
486 XSetWindowAttributes attrib_set
;
488 XSelectInput(display
, frame
.plate
, NoEventMask
);
489 XReparentWindow(display
, client
.window
, frame
.plate
, 0, 0);
490 XSelectInput(display
, frame
.plate
, SubstructureRedirectMask
);
494 attrib_set
.event_mask
= PropertyChangeMask
| StructureNotifyMask
|
496 attrib_set
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
499 XChangeWindowAttributes(display
, client
.window
, CWEventMask
|CWDontPropagate
,
503 if (openbox
.hasShapeExtensions()) {
504 XShapeSelectInput(display
, client
.window
, ShapeNotifyMask
);
509 XShapeQueryExtents(display
, client
.window
, &flags
.shaped
, &foo
, &foo
,
510 &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
, &ufoo
);
513 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
514 frame
.mwm_border_w
, frame
.y_border
+
515 frame
.mwm_border_w
, client
.window
,
516 ShapeBounding
, ShapeSet
);
520 xrect
[0].x
= xrect
[0].y
= 0;
521 xrect
[0].width
= frame
.width
;
522 xrect
[0].height
= frame
.y_border
;
524 if (decorations
.handle
) {
526 xrect
[1].y
= frame
.y_handle
;
527 xrect
[1].width
= frame
.width
;
528 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
532 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
533 xrect
, num
, ShapeUnion
, Unsorted
);
538 if (decorations
.iconify
) createIconifyButton();
539 if (decorations
.maximize
) createMaximizeButton();
540 if (decorations
.close
) createCloseButton();
543 if (frame
.close_button
)
544 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.ubutton
);
545 if (frame
.maximize_button
)
546 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
548 if (frame
.iconify_button
)
549 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.ubutton
);
551 if (frame
.close_button
)
552 XSetWindowBackground(display
, frame
.close_button
, frame
.ubutton_pixel
);
553 if (frame
.maximize_button
)
554 XSetWindowBackground(display
, frame
.maximize_button
,
555 frame
.ubutton_pixel
);
556 if (frame
.iconify_button
)
557 XSetWindowBackground(display
, frame
.iconify_button
, frame
.ubutton_pixel
);
562 void OpenboxWindow::decorate(void) {
563 Pixmap tmp
= frame
.fbutton
;
564 BTexture
*texture
= &(screen
->getWindowStyle()->b_focus
);
565 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
566 frame
.fbutton
= None
;
567 frame
.fbutton_pixel
= texture
->getColor()->getPixel();
570 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
572 if (tmp
) image_ctrl
->removeImage(tmp
);
575 texture
= &(screen
->getWindowStyle()->b_unfocus
);
576 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
577 frame
.ubutton
= None
;
578 frame
.ubutton_pixel
= texture
->getColor()->getPixel();
581 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
583 if (tmp
) image_ctrl
->removeImage(tmp
);
586 texture
= &(screen
->getWindowStyle()->b_pressed
);
587 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
588 frame
.pbutton
= None
;
589 frame
.pbutton_pixel
= texture
->getColor()->getPixel();
592 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
594 if (tmp
) image_ctrl
->removeImage(tmp
);
596 if (decorations
.titlebar
) {
598 texture
= &(screen
->getWindowStyle()->t_focus
);
599 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
601 frame
.ftitle_pixel
= texture
->getColor()->getPixel();
604 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
606 if (tmp
) image_ctrl
->removeImage(tmp
);
609 texture
= &(screen
->getWindowStyle()->t_unfocus
);
610 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
612 frame
.utitle_pixel
= texture
->getColor()->getPixel();
615 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
617 if (tmp
) image_ctrl
->removeImage(tmp
);
619 XSetWindowBorder(display
, frame
.title
,
620 screen
->getBorderColor()->getPixel());
625 if (decorations
.border
) {
626 frame
.fborder_pixel
= screen
->getWindowStyle()->f_focus
.getPixel();
627 frame
.uborder_pixel
= screen
->getWindowStyle()->f_unfocus
.getPixel();
628 openbox_attrib
.flags
|= AttribDecoration
;
629 openbox_attrib
.decoration
= DecorNormal
;
631 openbox_attrib
.flags
|= AttribDecoration
;
632 openbox_attrib
.decoration
= DecorNone
;
635 if (decorations
.handle
) {
637 texture
= &(screen
->getWindowStyle()->h_focus
);
638 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
639 frame
.fhandle
= None
;
640 frame
.fhandle_pixel
= texture
->getColor()->getPixel();
643 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
645 if (tmp
) image_ctrl
->removeImage(tmp
);
648 texture
= &(screen
->getWindowStyle()->h_unfocus
);
649 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
650 frame
.uhandle
= None
;
651 frame
.uhandle_pixel
= texture
->getColor()->getPixel();
654 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
656 if (tmp
) image_ctrl
->removeImage(tmp
);
659 texture
= &(screen
->getWindowStyle()->g_focus
);
660 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
662 frame
.fgrip_pixel
= texture
->getColor()->getPixel();
665 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
667 if (tmp
) image_ctrl
->removeImage(tmp
);
670 texture
= &(screen
->getWindowStyle()->g_unfocus
);
671 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
673 frame
.ugrip_pixel
= texture
->getColor()->getPixel();
676 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
678 if (tmp
) image_ctrl
->removeImage(tmp
);
680 XSetWindowBorder(display
, frame
.handle
,
681 screen
->getBorderColor()->getPixel());
682 XSetWindowBorder(display
, frame
.left_grip
,
683 screen
->getBorderColor()->getPixel());
684 XSetWindowBorder(display
, frame
.right_grip
,
685 screen
->getBorderColor()->getPixel());
688 XSetWindowBorder(display
, frame
.window
,
689 screen
->getBorderColor()->getPixel());
693 void OpenboxWindow::decorateLabel(void) {
694 Pixmap tmp
= frame
.flabel
;
695 BTexture
*texture
= &(screen
->getWindowStyle()->l_focus
);
696 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
698 frame
.flabel_pixel
= texture
->getColor()->getPixel();
701 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
703 if (tmp
) image_ctrl
->removeImage(tmp
);
706 texture
= &(screen
->getWindowStyle()->l_unfocus
);
707 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
709 frame
.ulabel_pixel
= texture
->getColor()->getPixel();
712 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
714 if (tmp
) image_ctrl
->removeImage(tmp
);
718 void OpenboxWindow::createCloseButton(void) {
719 if (decorations
.close
&& frame
.title
!= None
) {
720 frame
.close_button
= createChildWindow(frame
.title
);
721 openbox
.saveWindowSearch(frame
.close_button
, this);
726 void OpenboxWindow::createIconifyButton(void) {
727 if (decorations
.iconify
&& frame
.title
!= None
) {
728 frame
.iconify_button
= createChildWindow(frame
.title
);
729 openbox
.saveWindowSearch(frame
.iconify_button
, this);
734 void OpenboxWindow::createMaximizeButton(void) {
735 if (decorations
.maximize
&& frame
.title
!= None
) {
736 frame
.maximize_button
= createChildWindow(frame
.title
);
737 openbox
.saveWindowSearch(frame
.maximize_button
, this);
742 void OpenboxWindow::positionButtons(Bool redecorate_label
) {
743 const char *format
= openbox
.getTitleBarLayout();
744 const unsigned int bw
= frame
.bevel_w
+ 1;
745 const unsigned int by
= frame
.bevel_w
+ 1;
746 unsigned int bx
= frame
.bevel_w
+ 1;
747 unsigned int bcount
= strlen(format
) - 1;
749 if (!decorations
.close
)
751 if (!decorations
.maximize
)
753 if (!decorations
.iconify
)
755 frame
.label_w
= frame
.width
- bx
* 2 - (frame
.button_w
+ bw
) * bcount
;
757 bool hasclose
, hasiconify
, hasmaximize
;
758 hasclose
= hasiconify
= hasmaximize
= false;
760 for (int i
= 0; format
[i
] != '\0' && i
< 4; i
++) {
763 if (decorations
.close
&& frame
.close_button
!= None
) {
764 XMoveResizeWindow(display
, frame
.close_button
, bx
, by
,
765 frame
.button_w
, frame
.button_h
);
766 XMapWindow(display
, frame
.close_button
);
767 XClearWindow(display
, frame
.close_button
);
768 bx
+= frame
.button_w
+ bw
;
770 } else if (frame
.close_button
)
771 XUnmapWindow(display
, frame
.close_button
);
774 if (decorations
.iconify
&& frame
.iconify_button
!= None
) {
775 XMoveResizeWindow(display
, frame
.iconify_button
, bx
, by
,
776 frame
.button_w
, frame
.button_h
);
777 XMapWindow(display
, frame
.iconify_button
);
778 XClearWindow(display
, frame
.iconify_button
);
779 bx
+= frame
.button_w
+ bw
;
781 } else if (frame
.close_button
)
782 XUnmapWindow(display
, frame
.close_button
);
785 if (decorations
.maximize
&& frame
.maximize_button
!= None
) {
786 XMoveResizeWindow(display
, frame
.maximize_button
, bx
, by
,
787 frame
.button_w
, frame
.button_h
);
788 XMapWindow(display
, frame
.maximize_button
);
789 XClearWindow(display
, frame
.maximize_button
);
790 bx
+= frame
.button_w
+ bw
;
792 } else if (frame
.close_button
)
793 XUnmapWindow(display
, frame
.close_button
);
796 XMoveResizeWindow(display
, frame
.label
, bx
, by
- 1,
797 frame
.label_w
, frame
.label_h
);
798 bx
+= frame
.label_w
+ bw
;
804 openbox
.removeWindowSearch(frame
.close_button
);
805 XDestroyWindow(display
, frame
.close_button
);
808 openbox
.removeWindowSearch(frame
.iconify_button
);
809 XDestroyWindow(display
, frame
.iconify_button
);
812 openbox
.removeWindowSearch(frame
.maximize_button
);
813 XDestroyWindow(display
, frame
.maximize_button
);
815 if (redecorate_label
)
822 void OpenboxWindow::reconfigure(void) {
825 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
826 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
830 if (i18n
->multibyte()) {
831 XRectangle ink
, logical
;
832 XmbTextExtents(screen
->getWindowStyle()->fontset
,
833 client
.title
, client
.title_len
, &ink
, &logical
);
834 client
.title_text_w
= logical
.width
;
836 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
837 client
.title
, client
.title_len
);
839 client
.title_text_w
+= (frame
.bevel_w
* 4);
845 XClearWindow(display
, frame
.window
);
846 setFocusFlag(flags
.focused
);
848 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
850 if (! screen
->sloppyFocus())
851 openbox
.grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
852 GrabModeSync
, GrabModeSync
, None
, None
);
854 openbox
.ungrabButton(Button1
, 0, frame
.plate
);
857 windowmenu
->move(windowmenu
->getX(), frame
.y
+ frame
.title_h
);
858 windowmenu
->reconfigure();
863 void OpenboxWindow::positionWindows(void) {
864 XResizeWindow(display
, frame
.window
, frame
.width
,
865 ((flags
.shaded
) ? frame
.title_h
: frame
.height
));
866 XSetWindowBorderWidth(display
, frame
.window
, frame
.border_w
);
867 XSetWindowBorderWidth(display
, frame
.plate
, frame
.mwm_border_w
);
868 XMoveResizeWindow(display
, frame
.plate
, 0, frame
.y_border
,
869 client
.width
, client
.height
);
870 XMoveResizeWindow(display
, client
.window
, 0, 0, client
.width
, client
.height
);
872 if (decorations
.titlebar
) {
873 XSetWindowBorderWidth(display
, frame
.title
, frame
.border_w
);
874 XMoveResizeWindow(display
, frame
.title
, -frame
.border_w
,
875 -frame
.border_w
, frame
.width
, frame
.title_h
);
878 } else if (frame
.title
) {
879 XUnmapWindow(display
, frame
.title
);
881 if (decorations
.handle
) {
882 XSetWindowBorderWidth(display
, frame
.handle
, frame
.border_w
);
883 XSetWindowBorderWidth(display
, frame
.left_grip
, frame
.border_w
);
884 XSetWindowBorderWidth(display
, frame
.right_grip
, frame
.border_w
);
886 XMoveResizeWindow(display
, frame
.handle
, -frame
.border_w
,
887 frame
.y_handle
- frame
.border_w
,
888 frame
.width
, frame
.handle_h
);
889 XMoveResizeWindow(display
, frame
.left_grip
, -frame
.border_w
,
890 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
891 XMoveResizeWindow(display
, frame
.right_grip
,
892 frame
.width
- frame
.grip_w
- frame
.border_w
,
893 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
894 XMapSubwindows(display
, frame
.handle
);
895 } else if (frame
.handle
) {
896 XUnmapWindow(display
, frame
.handle
);
901 void OpenboxWindow::getWMName(void) {
903 delete [] client
.title
;
904 client
.title
= (char *) 0;
907 XTextProperty text_prop
;
911 if (XGetWMName(display
, client
.window
, &text_prop
)) {
912 if (text_prop
.value
&& text_prop
.nitems
> 0) {
913 if (text_prop
.encoding
!= XA_STRING
) {
914 text_prop
.nitems
= strlen((char *) text_prop
.value
);
916 if ((XmbTextPropertyToTextList(display
, &text_prop
,
917 &list
, &num
) == Success
) &&
918 (num
> 0) && *list
) {
919 client
.title
= bstrdup(*list
);
920 XFreeStringList(list
);
922 client
.title
= bstrdup((char *) text_prop
.value
);
925 client
.title
= bstrdup((char *) text_prop
.value
);
927 XFree((char *) text_prop
.value
);
929 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
933 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
936 client
.title_len
= strlen(client
.title
);
938 if (i18n
->multibyte()) {
939 XRectangle ink
, logical
;
940 XmbTextExtents(screen
->getWindowStyle()->fontset
,
941 client
.title
, client
.title_len
, &ink
, &logical
);
942 client
.title_text_w
= logical
.width
;
944 client
.title_len
= strlen(client
.title
);
945 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
946 client
.title
, client
.title_len
);
949 client
.title_text_w
+= (frame
.bevel_w
* 4);
953 void OpenboxWindow::getWMIconName(void) {
954 if (client
.icon_title
) {
955 delete [] client
.icon_title
;
956 client
.icon_title
= (char *) 0;
959 XTextProperty text_prop
;
963 if (XGetWMIconName(display
, client
.window
, &text_prop
)) {
964 if (text_prop
.value
&& text_prop
.nitems
> 0) {
965 if (text_prop
.encoding
!= XA_STRING
) {
966 text_prop
.nitems
= strlen((char *) text_prop
.value
);
968 if ((XmbTextPropertyToTextList(display
, &text_prop
,
969 &list
, &num
) == Success
) &&
970 (num
> 0) && *list
) {
971 client
.icon_title
= bstrdup(*list
);
972 XFreeStringList(list
);
974 client
.icon_title
= bstrdup((char *) text_prop
.value
);
977 client
.icon_title
= bstrdup((char *) text_prop
.value
);
979 XFree((char *) text_prop
.value
);
981 client
.icon_title
= bstrdup(client
.title
);
984 client
.icon_title
= bstrdup(client
.title
);
990 * Retrieve which WM Protocols are supported by the client window.
991 * If the WM_DELETE_WINDOW protocol is supported, add the close button to the
992 * window's decorations and allow the close behavior.
993 * If the WM_TAKE_FOCUS protocol is supported, save a value that indicates
996 void OpenboxWindow::getWMProtocols(void) {
1000 if (XGetWMProtocols(display
, client
.window
, &proto
, &num_return
)) {
1001 for (int i
= 0; i
< num_return
; ++i
) {
1002 if (proto
[i
] == openbox
.getWMDeleteAtom())
1003 functions
.close
= decorations
.close
= True
;
1004 else if (proto
[i
] == openbox
.getWMTakeFocusAtom())
1005 flags
.send_focus_message
= True
;
1006 else if (proto
[i
] == openbox
.getOpenboxStructureMessagesAtom())
1007 screen
->addNetizen(new Netizen(*screen
, client
.window
));
1016 * Gets the value of the WM_HINTS property.
1017 * If the property is not set, then use a set of default values.
1019 void OpenboxWindow::getWMHints(void) {
1020 XWMHints
*wmhint
= XGetWMHints(display
, client
.window
);
1022 flags
.visible
= True
;
1023 flags
.iconic
= False
;
1024 focus_mode
= F_Passive
;
1025 client
.window_group
= None
;
1026 client
.initial_state
= NormalState
;
1029 client
.wm_hint_flags
= wmhint
->flags
;
1030 if (wmhint
->flags
& InputHint
) {
1031 if (wmhint
->input
== True
) {
1032 if (flags
.send_focus_message
)
1033 focus_mode
= F_LocallyActive
;
1035 focus_mode
= F_Passive
;
1037 if (flags
.send_focus_message
)
1038 focus_mode
= F_GloballyActive
;
1040 focus_mode
= F_NoInput
;
1043 focus_mode
= F_Passive
;
1046 if (wmhint
->flags
& StateHint
)
1047 client
.initial_state
= wmhint
->initial_state
;
1049 client
.initial_state
= NormalState
;
1051 if (wmhint
->flags
& WindowGroupHint
) {
1052 if (! client
.window_group
) {
1053 client
.window_group
= wmhint
->window_group
;
1054 openbox
.saveGroupSearch(client
.window_group
, this);
1057 client
.window_group
= None
;
1064 * Gets the value of the WM_NORMAL_HINTS property.
1065 * If the property is not set, then use a set of default values.
1067 void OpenboxWindow::getWMNormalHints(void) {
1069 XSizeHints sizehint
;
1071 client
.min_width
= client
.min_height
=
1072 client
.base_width
= client
.base_height
=
1073 client
.width_inc
= client
.height_inc
= 1;
1074 client
.max_width
= screen
->size().w();
1075 client
.max_height
= screen
->size().h();
1076 client
.min_aspect_x
= client
.min_aspect_y
=
1077 client
.max_aspect_x
= client
.max_aspect_y
= 1;
1078 client
.win_gravity
= NorthWestGravity
;
1080 if (! XGetWMNormalHints(display
, client
.window
, &sizehint
, &icccm_mask
))
1083 client
.normal_hint_flags
= sizehint
.flags
;
1085 if (sizehint
.flags
& PMinSize
) {
1086 client
.min_width
= sizehint
.min_width
;
1087 client
.min_height
= sizehint
.min_height
;
1090 if (sizehint
.flags
& PMaxSize
) {
1091 client
.max_width
= sizehint
.max_width
;
1092 client
.max_height
= sizehint
.max_height
;
1095 if (sizehint
.flags
& PResizeInc
) {
1096 client
.width_inc
= sizehint
.width_inc
;
1097 client
.height_inc
= sizehint
.height_inc
;
1100 if (sizehint
.flags
& PAspect
) {
1101 client
.min_aspect_x
= sizehint
.min_aspect
.x
;
1102 client
.min_aspect_y
= sizehint
.min_aspect
.y
;
1103 client
.max_aspect_x
= sizehint
.max_aspect
.x
;
1104 client
.max_aspect_y
= sizehint
.max_aspect
.y
;
1107 if (sizehint
.flags
& PBaseSize
) {
1108 client
.base_width
= sizehint
.base_width
;
1109 client
.base_height
= sizehint
.base_height
;
1112 if (sizehint
.flags
& PWinGravity
)
1113 client
.win_gravity
= sizehint
.win_gravity
;
1118 * Gets the MWM hints for the class' contained window.
1119 * This is used while initializing the window to its first state, and not
1121 * Returns: true if the MWM hints are successfully retreived and applied; false
1124 void OpenboxWindow::getMWMHints(void) {
1127 unsigned long num
, len
;
1129 int ret
= XGetWindowProperty(display
, client
.window
,
1130 openbox
.getMotifWMHintsAtom(), 0,
1131 PropMwmHintsElements
, False
,
1132 openbox
.getMotifWMHintsAtom(), &atom_return
,
1133 &format
, &num
, &len
,
1134 (unsigned char **) &client
.mwm_hint
);
1136 if (ret
!= Success
|| !client
.mwm_hint
|| num
!= PropMwmHintsElements
)
1139 if (client
.mwm_hint
->flags
& MwmHintsDecorations
) {
1140 if (client
.mwm_hint
->decorations
& MwmDecorAll
) {
1141 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1142 decorations
.iconify
= decorations
.maximize
=
1143 decorations
.close
= decorations
.menu
= True
;
1145 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1146 decorations
.iconify
= decorations
.maximize
=
1147 decorations
.close
= decorations
.menu
= False
;
1149 if (client
.mwm_hint
->decorations
& MwmDecorBorder
)
1150 decorations
.border
= True
;
1151 if (client
.mwm_hint
->decorations
& MwmDecorHandle
)
1152 decorations
.handle
= True
;
1153 if (client
.mwm_hint
->decorations
& MwmDecorTitle
)
1154 decorations
.titlebar
= True
;
1155 if (client
.mwm_hint
->decorations
& MwmDecorMenu
)
1156 decorations
.menu
= True
;
1157 if (client
.mwm_hint
->decorations
& MwmDecorIconify
)
1158 decorations
.iconify
= True
;
1159 if (client
.mwm_hint
->decorations
& MwmDecorMaximize
)
1160 decorations
.maximize
= True
;
1164 if (client
.mwm_hint
->flags
& MwmHintsFunctions
) {
1165 if (client
.mwm_hint
->functions
& MwmFuncAll
) {
1166 functions
.resize
= functions
.move
= functions
.iconify
=
1167 functions
.maximize
= functions
.close
= True
;
1169 functions
.resize
= functions
.move
= functions
.iconify
=
1170 functions
.maximize
= functions
.close
= False
;
1172 if (client
.mwm_hint
->functions
& MwmFuncResize
)
1173 functions
.resize
= True
;
1174 if (client
.mwm_hint
->functions
& MwmFuncMove
)
1175 functions
.move
= True
;
1176 if (client
.mwm_hint
->functions
& MwmFuncIconify
)
1177 functions
.iconify
= True
;
1178 if (client
.mwm_hint
->functions
& MwmFuncMaximize
)
1179 functions
.maximize
= True
;
1180 if (client
.mwm_hint
->functions
& MwmFuncClose
)
1181 functions
.close
= True
;
1188 * Gets the openbox hints from the class' contained window.
1189 * This is used while initializing the window to its first state, and not
1191 * Returns: true if the hints are successfully retreived and applied; false if
1194 void OpenboxWindow::getOpenboxHints(void) {
1197 unsigned long num
, len
;
1199 int ret
= XGetWindowProperty(display
, client
.window
,
1200 openbox
.getOpenboxHintsAtom(), 0,
1201 PropOpenboxHintsElements
, False
,
1202 openbox
.getOpenboxHintsAtom(), &atom_return
,
1203 &format
, &num
, &len
,
1204 (unsigned char **) &client
.openbox_hint
);
1205 if (ret
!= Success
|| !client
.openbox_hint
||
1206 num
!= PropOpenboxHintsElements
)
1209 if (client
.openbox_hint
->flags
& AttribShaded
)
1210 flags
.shaded
= (client
.openbox_hint
->attrib
& AttribShaded
);
1212 if ((client
.openbox_hint
->flags
& AttribMaxHoriz
) &&
1213 (client
.openbox_hint
->flags
& AttribMaxVert
))
1214 flags
.maximized
= (client
.openbox_hint
->attrib
&
1215 (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1216 else if (client
.openbox_hint
->flags
& AttribMaxVert
)
1217 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxVert
) ? 2 : 0;
1218 else if (client
.openbox_hint
->flags
& AttribMaxHoriz
)
1219 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxHoriz
) ? 3 : 0;
1221 if (client
.openbox_hint
->flags
& AttribOmnipresent
)
1222 flags
.stuck
= (client
.openbox_hint
->attrib
& AttribOmnipresent
);
1224 if (client
.openbox_hint
->flags
& AttribWorkspace
)
1225 workspace_number
= client
.openbox_hint
->workspace
;
1227 // if (client.openbox_hint->flags & AttribStack)
1228 // don't yet have always on top/bottom for openbox yet... working
1231 if (client
.openbox_hint
->flags
& AttribDecoration
) {
1232 switch (client
.openbox_hint
->decoration
) {
1234 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1235 decorations
.iconify
= decorations
.maximize
=
1236 decorations
.menu
= False
;
1237 functions
.resize
= functions
.move
= functions
.iconify
=
1238 functions
.maximize
= False
;
1243 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
=
1244 functions
.move
= functions
.iconify
= True
;
1245 decorations
.border
= decorations
.handle
= decorations
.maximize
=
1246 functions
.resize
= functions
.maximize
= False
;
1251 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
1252 decorations
.iconify
= decorations
.border
= decorations
.handle
=
1253 decorations
.maximize
= functions
.resize
= functions
.maximize
=
1254 functions
.iconify
= False
;
1260 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1261 decorations
.iconify
= decorations
.maximize
=
1262 decorations
.menu
= True
;
1263 functions
.resize
= functions
.move
= functions
.iconify
=
1264 functions
.maximize
= True
;
1274 void OpenboxWindow::configure(int dx
, int dy
,
1275 unsigned int dw
, unsigned int dh
) {
1276 Bool send_event
= (frame
.x
!= dx
|| frame
.y
!= dy
);
1278 if ((dw
!= frame
.width
) || (dh
!= frame
.height
)) {
1279 if ((((signed) frame
.width
) + dx
) < 0) dx
= 0;
1280 if ((((signed) frame
.height
) + dy
) < 0) dy
= 0;
1290 if (openbox
.hasShapeExtensions() && flags
.shaped
) {
1291 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
1292 frame
.mwm_border_w
, frame
.y_border
+
1293 frame
.mwm_border_w
, client
.window
,
1294 ShapeBounding
, ShapeSet
);
1297 XRectangle xrect
[2];
1298 xrect
[0].x
= xrect
[0].y
= 0;
1299 xrect
[0].width
= frame
.width
;
1300 xrect
[0].height
= frame
.y_border
;
1302 if (decorations
.handle
) {
1304 xrect
[1].y
= frame
.y_handle
;
1305 xrect
[1].width
= frame
.width
;
1306 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
1310 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
1311 xrect
, num
, ShapeUnion
, Unsorted
);
1315 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1319 setFocusFlag(flags
.focused
);
1325 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1327 if (! flags
.moving
) send_event
= True
;
1330 if (send_event
&& ! flags
.moving
) {
1331 client
.x
= dx
+ frame
.mwm_border_w
+ frame
.border_w
;
1332 client
.y
= dy
+ frame
.y_border
+ frame
.mwm_border_w
+
1336 event
.type
= ConfigureNotify
;
1338 event
.xconfigure
.display
= display
;
1339 event
.xconfigure
.event
= client
.window
;
1340 event
.xconfigure
.window
= client
.window
;
1341 event
.xconfigure
.x
= client
.x
;
1342 event
.xconfigure
.y
= client
.y
;
1343 event
.xconfigure
.width
= client
.width
;
1344 event
.xconfigure
.height
= client
.height
;
1345 event
.xconfigure
.border_width
= client
.old_bw
;
1346 event
.xconfigure
.above
= frame
.window
;
1347 event
.xconfigure
.override_redirect
= False
;
1349 XSendEvent(display
, client
.window
, True
, NoEventMask
, &event
);
1351 screen
->updateNetizenConfigNotify(&event
);
1356 Bool
OpenboxWindow::setInputFocus(void) {
1357 if (((signed) (frame
.x
+ frame
.width
)) < 0) {
1358 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1359 configure(frame
.border_w
, frame
.border_w
, frame
.width
, frame
.height
);
1360 else if (frame
.y
> (signed) screen
->size().h())
1361 configure(frame
.border_w
, screen
->size().h() - frame
.height
,
1362 frame
.width
, frame
.height
);
1364 configure(frame
.border_w
, frame
.y
+ frame
.border_w
,
1365 frame
.width
, frame
.height
);
1366 } else if (frame
.x
> (signed) screen
->size().w()) {
1367 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1368 configure(screen
->size().w() - frame
.width
, frame
.border_w
,
1369 frame
.width
, frame
.height
);
1370 else if (frame
.y
> (signed) screen
->size().h())
1371 configure(screen
->size().w() - frame
.width
,
1372 screen
->size().h() - frame
.height
, frame
.width
, frame
.height
);
1374 configure(screen
->size().w() - frame
.width
,
1375 frame
.y
+ frame
.border_w
, frame
.width
, frame
.height
);
1379 if (! validateClient()) return False
;
1383 if (client
.transient
&& flags
.modal
) {
1384 ret
= client
.transient
->setInputFocus();
1385 } else if (! flags
.focused
) {
1386 if (focus_mode
== F_LocallyActive
|| focus_mode
== F_Passive
)
1387 XSetInputFocus(display
, client
.window
,
1388 RevertToPointerRoot
, CurrentTime
);
1390 XSetInputFocus(display
, screen
->getRootWindow(),
1391 RevertToNone
, CurrentTime
);
1393 openbox
.setFocusedWindow(this);
1395 if (flags
.send_focus_message
) {
1397 ce
.xclient
.type
= ClientMessage
;
1398 ce
.xclient
.message_type
= openbox
.getWMProtocolsAtom();
1399 ce
.xclient
.display
= display
;
1400 ce
.xclient
.window
= client
.window
;
1401 ce
.xclient
.format
= 32;
1402 ce
.xclient
.data
.l
[0] = openbox
.getWMTakeFocusAtom();
1403 ce
.xclient
.data
.l
[1] = openbox
.getLastTime();
1404 ce
.xclient
.data
.l
[2] = 0l;
1405 ce
.xclient
.data
.l
[3] = 0l;
1406 ce
.xclient
.data
.l
[4] = 0l;
1407 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1410 if (screen
->sloppyFocus() && screen
->autoRaise())
1422 void OpenboxWindow::iconify(void) {
1423 if (flags
.iconic
) return;
1425 if (windowmenu
) windowmenu
->hide();
1427 setState(IconicState
);
1429 XSelectInput(display
, client
.window
, NoEventMask
);
1430 XUnmapWindow(display
, client
.window
);
1431 XSelectInput(display
, client
.window
,
1432 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1434 XUnmapWindow(display
, frame
.window
);
1435 flags
.visible
= False
;
1436 flags
.iconic
= True
;
1438 screen
->getWorkspace(workspace_number
)->removeWindow(this);
1440 if (flags
.transient
&& client
.transient_for
&&
1441 !client
.transient_for
->flags
.iconic
) {
1442 client
.transient_for
->iconify();
1444 screen
->addIcon(this);
1446 if (client
.transient
&& !client
.transient
->flags
.iconic
) {
1447 client
.transient
->iconify();
1452 void OpenboxWindow::deiconify(Bool reassoc
, Bool raise
) {
1453 if (flags
.iconic
|| reassoc
)
1454 screen
->reassociateWindow(this, -1, False
);
1455 else if (workspace_number
!= screen
->getCurrentWorkspace()->getWorkspaceID())
1458 setState(NormalState
);
1460 XSelectInput(display
, client
.window
, NoEventMask
);
1461 XMapWindow(display
, client
.window
);
1462 XSelectInput(display
, client
.window
,
1463 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1465 XMapSubwindows(display
, frame
.window
);
1466 XMapWindow(display
, frame
.window
);
1468 if (flags
.iconic
&& screen
->focusNew()) setInputFocus();
1470 flags
.visible
= True
;
1471 flags
.iconic
= False
;
1473 if (reassoc
&& client
.transient
) client
.transient
->deiconify(True
, False
);
1476 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1480 void OpenboxWindow::close(void) {
1482 ce
.xclient
.type
= ClientMessage
;
1483 ce
.xclient
.message_type
= openbox
.getWMProtocolsAtom();
1484 ce
.xclient
.display
= display
;
1485 ce
.xclient
.window
= client
.window
;
1486 ce
.xclient
.format
= 32;
1487 ce
.xclient
.data
.l
[0] = openbox
.getWMDeleteAtom();
1488 ce
.xclient
.data
.l
[1] = CurrentTime
;
1489 ce
.xclient
.data
.l
[2] = 0l;
1490 ce
.xclient
.data
.l
[3] = 0l;
1491 ce
.xclient
.data
.l
[4] = 0l;
1492 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1496 void OpenboxWindow::withdraw(void) {
1497 flags
.visible
= False
;
1498 flags
.iconic
= False
;
1500 XUnmapWindow(display
, frame
.window
);
1502 XSelectInput(display
, client
.window
, NoEventMask
);
1503 XUnmapWindow(display
, client
.window
);
1504 XSelectInput(display
, client
.window
,
1505 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1507 if (windowmenu
) windowmenu
->hide();
1511 void OpenboxWindow::maximize(unsigned int button
) {
1512 // handle case where menu is open then the max button is used instead
1513 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
1515 if (flags
.maximized
) {
1516 flags
.maximized
= 0;
1518 openbox_attrib
.flags
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1519 openbox_attrib
.attrib
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1521 // when a resize is begun, maximize(0) is called to clear any maximization
1522 // flags currently set. Otherwise it still thinks it is maximized.
1523 // so we do not need to call configure() because resizing will handle it
1524 if (!flags
.resizing
)
1525 configure(openbox_attrib
.premax_x
, openbox_attrib
.premax_y
,
1526 openbox_attrib
.premax_w
, openbox_attrib
.premax_h
);
1528 openbox_attrib
.premax_x
= openbox_attrib
.premax_y
= 0;
1529 openbox_attrib
.premax_w
= openbox_attrib
.premax_h
= 0;
1532 setState(current_state
);
1536 // the following code is temporary and will be taken care of by Screen in the
1537 // future (with the NETWM 'strut')
1538 Rect
space(0, 0, screen
->size().w(), screen
->size().h());
1539 if (! screen
->fullMax()) {
1541 Slit
*slit
= screen
->getSlit();
1542 int slit_x
= slit
->autoHide() ? slit
->hiddenOrigin().x() : slit
->area().x(),
1543 slit_y
= slit
->autoHide() ? slit
->hiddenOrigin().y() : slit
->area().y();
1544 Toolbar
*toolbar
= screen
->getToolbar();
1545 int tbarh
= screen
->hideToolbar() ? 0 :
1546 toolbar
->getExposedHeight() + screen
->getBorderWidth() * 2;
1548 switch (toolbar
->placement()) {
1549 case Toolbar::TopLeft
:
1550 case Toolbar::TopCenter
:
1551 case Toolbar::TopRight
:
1554 case Toolbar::BottomLeft
:
1555 case Toolbar::BottomCenter
:
1556 case Toolbar::BottomRight
:
1560 ASSERT(false); // unhandled placement
1562 if ((slit
->direction() == Slit::Horizontal
&&
1563 (slit
->placement() == Slit::TopLeft
||
1564 slit
->placement() == Slit::TopRight
)) ||
1565 slit
->placement() == Slit::TopCenter
) {
1567 if (tbartop
&& slit_y
+ slit
->area().h() < tbarh
) {
1568 space
.setY(space
.y() + tbarh
);
1569 space
.setH(space
.h() - tbarh
);
1571 space
.setY(space
.y() + (slit_y
+ slit
->area().h() +
1572 screen
->getBorderWidth() * 2));
1573 space
.setH(space
.h() - (slit_y
+ slit
->area().h() +
1574 screen
->getBorderWidth() * 2));
1576 space
.setH(space
.h() - tbarh
);
1578 } else if ((slit
->direction() == Slit::Vertical
&&
1579 (slit
->placement() == Slit::TopRight
||
1580 slit
->placement() == Slit::BottomRight
)) ||
1581 slit
->placement() == Slit::CenterRight
) {
1583 space
.setW(space
.w() - (screen
->size().w() - slit_x
));
1585 space
.setY(space
.y() + tbarh
);
1586 space
.setH(space
.h() - tbarh
);
1587 } else if ((slit
->direction() == Slit::Horizontal
&&
1588 (slit
->placement() == Slit::BottomLeft
||
1589 slit
->placement() == Slit::BottomRight
)) ||
1590 slit
->placement() == Slit::BottomCenter
) {
1592 if (!tbartop
&& (screen
->size().h() - slit_y
) < tbarh
) {
1593 space
.setH(space
.h() - tbarh
);
1595 space
.setH(space
.h() - (screen
->size().h() - slit_y
));
1597 space
.setY(space
.y() + tbarh
);
1598 space
.setH(space
.h() - tbarh
);
1601 } else {// if ((slit->direction() == Slit::Vertical &&
1602 // (slit->placement() == Slit::TopLeft ||
1603 // slit->placement() == Slit::BottomLeft)) ||
1604 // slit->placement() == Slit::CenterLeft)
1606 space
.setX(slit_x
+ slit
->area().w() +
1607 screen
->getBorderWidth() * 2);
1608 space
.setW(space
.w() - (slit_x
+ slit
->area().w() +
1609 screen
->getBorderWidth() * 2));
1611 space
.setY(space
.y() + tbarh
);
1612 space
.setH(space
.h() - tbarh
);
1615 Toolbar
*toolbar
= screen
->getToolbar();
1616 int tbarh
= screen
->hideToolbar() ? 0 :
1617 toolbar
->getExposedHeight() + screen
->getBorderWidth() * 2;
1618 switch (toolbar
->placement()) {
1619 case Toolbar::TopLeft
:
1620 case Toolbar::TopCenter
:
1621 case Toolbar::TopRight
:
1622 space
.setY(toolbar
->getExposedHeight());
1623 space
.setH(space
.h() - toolbar
->getExposedHeight());
1625 case Toolbar::BottomLeft
:
1626 case Toolbar::BottomCenter
:
1627 case Toolbar::BottomRight
:
1628 space
.setH(space
.h() - tbarh
);
1631 ASSERT(false); // unhandled placement
1636 openbox_attrib
.premax_x
= frame
.x
;
1637 openbox_attrib
.premax_y
= frame
.y
;
1638 openbox_attrib
.premax_w
= frame
.width
;
1639 openbox_attrib
.premax_h
= frame
.height
;
1641 unsigned int dw
= space
.w(),
1643 dw
-= frame
.border_w
* 2;
1644 dw
-= frame
.mwm_border_w
* 2;
1645 dw
-= client
.base_width
;
1647 dh
-= frame
.border_w
* 2;
1648 dh
-= frame
.mwm_border_w
* 2;
1649 dh
-= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1650 dh
-= client
.base_height
;
1651 dh
-= frame
.y_border
;
1653 if (dw
< client
.min_width
) dw
= client
.min_width
;
1654 if (dh
< client
.min_height
) dh
= client
.min_height
;
1655 if (dw
> client
.max_width
) dw
= client
.max_width
;
1656 if (dh
> client
.max_height
) dh
= client
.max_height
;
1658 dw
-= (dw
% client
.width_inc
);
1659 dw
+= client
.base_width
;
1660 dw
+= frame
.mwm_border_w
* 2;
1662 dh
-= (dh
% client
.height_inc
);
1663 dh
+= client
.base_height
;
1664 dh
+= frame
.y_border
;
1665 dh
+= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1666 dh
+= frame
.mwm_border_w
* 2;
1668 int dx
= space
.x() + ((space
.w() - dw
) / 2) - frame
.border_w
,
1669 dy
= space
.y() + ((space
.h() - dh
) / 2) - frame
.border_w
;
1673 openbox_attrib
.flags
|= AttribMaxHoriz
| AttribMaxVert
;
1674 openbox_attrib
.attrib
|= AttribMaxHoriz
| AttribMaxVert
;
1678 openbox_attrib
.flags
|= AttribMaxVert
;
1679 openbox_attrib
.attrib
|= AttribMaxVert
;
1686 openbox_attrib
.flags
|= AttribMaxHoriz
;
1687 openbox_attrib
.attrib
|= AttribMaxHoriz
;
1695 openbox_attrib
.flags
^= AttribShaded
;
1696 openbox_attrib
.attrib
^= AttribShaded
;
1697 flags
.shaded
= False
;
1700 flags
.maximized
= button
;
1702 configure(dx
, dy
, dw
, dh
);
1703 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1705 setState(current_state
);
1709 void OpenboxWindow::setWorkspace(int n
) {
1710 workspace_number
= n
;
1712 openbox_attrib
.flags
|= AttribWorkspace
;
1713 openbox_attrib
.workspace
= workspace_number
;
1717 void OpenboxWindow::shade(void) {
1718 if (!decorations
.titlebar
)
1722 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.height
);
1723 flags
.shaded
= False
;
1724 openbox_attrib
.flags
^= AttribShaded
;
1725 openbox_attrib
.attrib
^= AttribShaded
;
1727 setState(NormalState
);
1729 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.title_h
);
1730 flags
.shaded
= True
;
1731 openbox_attrib
.flags
|= AttribShaded
;
1732 openbox_attrib
.attrib
|= AttribShaded
;
1734 setState(IconicState
);
1739 void OpenboxWindow::stick(void) {
1741 openbox_attrib
.flags
^= AttribOmnipresent
;
1742 openbox_attrib
.attrib
^= AttribOmnipresent
;
1744 flags
.stuck
= False
;
1747 screen
->reassociateWindow(this, -1, True
);
1749 setState(current_state
);
1753 openbox_attrib
.flags
|= AttribOmnipresent
;
1754 openbox_attrib
.attrib
|= AttribOmnipresent
;
1756 setState(current_state
);
1761 void OpenboxWindow::setFocusFlag(Bool focus
) {
1762 flags
.focused
= focus
;
1764 if (decorations
.titlebar
) {
1765 if (flags
.focused
) {
1767 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.ftitle
);
1769 XSetWindowBackground(display
, frame
.title
, frame
.ftitle_pixel
);
1772 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.utitle
);
1774 XSetWindowBackground(display
, frame
.title
, frame
.utitle_pixel
);
1776 XClearWindow(display
, frame
.title
);
1782 if (decorations
.handle
) {
1783 if (flags
.focused
) {
1785 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.fhandle
);
1787 XSetWindowBackground(display
, frame
.handle
, frame
.fhandle_pixel
);
1790 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.fgrip
);
1791 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.fgrip
);
1793 XSetWindowBackground(display
, frame
.right_grip
, frame
.fgrip_pixel
);
1794 XSetWindowBackground(display
, frame
.left_grip
, frame
.fgrip_pixel
);
1798 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.uhandle
);
1800 XSetWindowBackground(display
, frame
.handle
, frame
.uhandle_pixel
);
1803 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.ugrip
);
1804 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.ugrip
);
1806 XSetWindowBackground(display
, frame
.right_grip
, frame
.ugrip_pixel
);
1807 XSetWindowBackground(display
, frame
.left_grip
, frame
.ugrip_pixel
);
1810 XClearWindow(display
, frame
.handle
);
1811 XClearWindow(display
, frame
.right_grip
);
1812 XClearWindow(display
, frame
.left_grip
);
1815 if (decorations
.border
) {
1817 XSetWindowBorder(display
, frame
.plate
, frame
.fborder_pixel
);
1819 XSetWindowBorder(display
, frame
.plate
, frame
.uborder_pixel
);
1822 if (screen
->sloppyFocus() && screen
->autoRaise() && timer
->isTiming())
1827 void OpenboxWindow::installColormap(Bool install
) {
1829 if (! validateClient()) return;
1831 int i
= 0, ncmap
= 0;
1832 Colormap
*cmaps
= XListInstalledColormaps(display
, client
.window
, &ncmap
);
1833 XWindowAttributes wattrib
;
1835 if (XGetWindowAttributes(display
, client
.window
, &wattrib
)) {
1837 // install the window's colormap
1838 for (i
= 0; i
< ncmap
; i
++) {
1839 if (*(cmaps
+ i
) == wattrib
.colormap
)
1840 // this window is using an installed color map... do not install
1843 // otherwise, install the window's colormap
1845 XInstallColormap(display
, wattrib
.colormap
);
1847 // uninstall the window's colormap
1848 for (i
= 0; i
< ncmap
; i
++) {
1849 if (*(cmaps
+ i
) == wattrib
.colormap
)
1850 // we found the colormap to uninstall
1851 XUninstallColormap(display
, wattrib
.colormap
);
1863 void OpenboxWindow::setState(unsigned long new_state
) {
1864 current_state
= new_state
;
1866 unsigned long state
[2];
1867 state
[0] = (unsigned long) current_state
;
1868 state
[1] = (unsigned long) None
;
1869 XChangeProperty(display
, client
.window
, openbox
.getWMStateAtom(),
1870 openbox
.getWMStateAtom(), 32, PropModeReplace
,
1871 (unsigned char *) state
, 2);
1873 XChangeProperty(display
, client
.window
,
1874 openbox
.getOpenboxAttributesAtom(),
1875 openbox
.getOpenboxAttributesAtom(), 32, PropModeReplace
,
1876 (unsigned char *) &openbox_attrib
,
1877 PropOpenboxAttributesElements
);
1881 Bool
OpenboxWindow::getState(void) {
1887 unsigned long *state
, ulfoo
, nitems
;
1889 if ((XGetWindowProperty(display
, client
.window
, openbox
.getWMStateAtom(),
1890 0l, 2l, False
, openbox
.getWMStateAtom(),
1891 &atom_return
, &foo
, &nitems
, &ulfoo
,
1892 (unsigned char **) &state
) != Success
) ||
1899 current_state
= (unsigned long) state
[0];
1904 XFree((void *) state
);
1910 void OpenboxWindow::setGravityOffsets(void) {
1911 // x coordinates for each gravity type
1912 const int x_west
= client
.x
;
1913 const int x_east
= client
.x
+ client
.width
- frame
.width
;
1914 const int x_center
= client
.x
+ client
.width
- frame
.width
/2;
1915 // y coordinates for each gravity type
1916 const int y_north
= client
.y
;
1917 const int y_south
= client
.y
+ client
.height
- frame
.height
;
1918 const int y_center
= client
.y
+ client
.height
- frame
.height
/2;
1920 switch (client
.win_gravity
) {
1921 case NorthWestGravity
:
1930 case NorthEastGravity
:
1934 case SouthWestGravity
:
1942 case SouthEastGravity
:
1960 frame
.x
= client
.x
- frame
.mwm_border_w
+ frame
.border_w
;
1961 frame
.y
= client
.y
- frame
.y_border
- frame
.mwm_border_w
- frame
.border_w
;
1967 void OpenboxWindow::restoreAttributes(void) {
1968 if (! getState()) current_state
= NormalState
;
1972 unsigned long ulfoo
, nitems
;
1974 OpenboxAttributes
*net
;
1975 int ret
= XGetWindowProperty(display
, client
.window
,
1976 openbox
.getOpenboxAttributesAtom(), 0l,
1977 PropOpenboxAttributesElements
, False
,
1978 openbox
.getOpenboxAttributesAtom(),
1979 &atom_return
, &foo
, &nitems
, &ulfoo
,
1980 (unsigned char **) &net
);
1981 if (ret
!= Success
|| !net
|| nitems
!= PropOpenboxAttributesElements
)
1984 openbox_attrib
.flags
= net
->flags
;
1985 openbox_attrib
.attrib
= net
->attrib
;
1986 openbox_attrib
.decoration
= net
->decoration
;
1987 openbox_attrib
.workspace
= net
->workspace
;
1988 openbox_attrib
.stack
= net
->stack
;
1989 openbox_attrib
.premax_x
= net
->premax_x
;
1990 openbox_attrib
.premax_y
= net
->premax_y
;
1991 openbox_attrib
.premax_w
= net
->premax_w
;
1992 openbox_attrib
.premax_h
= net
->premax_h
;
1994 XFree((void *) net
);
1996 if (openbox_attrib
.flags
& AttribShaded
&&
1997 openbox_attrib
.attrib
& AttribShaded
) {
1999 ((current_state
== IconicState
) ? NormalState
: current_state
);
2001 flags
.shaded
= False
;
2004 current_state
= save_state
;
2007 if (((int) openbox_attrib
.workspace
!= screen
->getCurrentWorkspaceID()) &&
2008 ((int) openbox_attrib
.workspace
< screen
->getWorkspaceCount())) {
2009 screen
->reassociateWindow(this, openbox_attrib
.workspace
, True
);
2011 if (current_state
== NormalState
) current_state
= WithdrawnState
;
2012 } else if (current_state
== WithdrawnState
) {
2013 current_state
= NormalState
;
2016 if (openbox_attrib
.flags
& AttribOmnipresent
&&
2017 openbox_attrib
.attrib
& AttribOmnipresent
) {
2018 flags
.stuck
= False
;
2021 current_state
= NormalState
;
2024 if ((openbox_attrib
.flags
& AttribMaxHoriz
) ||
2025 (openbox_attrib
.flags
& AttribMaxVert
)) {
2026 int x
= openbox_attrib
.premax_x
, y
= openbox_attrib
.premax_y
;
2027 unsigned int w
= openbox_attrib
.premax_w
, h
= openbox_attrib
.premax_h
;
2028 flags
.maximized
= 0;
2030 unsigned int m
= False
;
2031 if ((openbox_attrib
.flags
& AttribMaxHoriz
) &&
2032 (openbox_attrib
.flags
& AttribMaxVert
))
2033 m
= (openbox_attrib
.attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
2034 else if (openbox_attrib
.flags
& AttribMaxVert
)
2035 m
= (openbox_attrib
.attrib
& AttribMaxVert
) ? 2 : 0;
2036 else if (openbox_attrib
.flags
& AttribMaxHoriz
)
2037 m
= (openbox_attrib
.attrib
& AttribMaxHoriz
) ? 3 : 0;
2041 openbox_attrib
.premax_x
= x
;
2042 openbox_attrib
.premax_y
= y
;
2043 openbox_attrib
.premax_w
= w
;
2044 openbox_attrib
.premax_h
= h
;
2047 setState(current_state
);
2052 * The reverse of the setGravityOffsets function. Uses the frame window's
2053 * position to find the window's reference point.
2055 void OpenboxWindow::restoreGravity(void) {
2056 // x coordinates for each gravity type
2057 const int x_west
= frame
.x
;
2058 const int x_east
= frame
.x
+ frame
.width
- client
.width
;
2059 const int x_center
= frame
.x
+ (frame
.width
/2) - client
.width
;
2060 // y coordinates for each gravity type
2061 const int y_north
= frame
.y
;
2062 const int y_south
= frame
.y
+ frame
.height
- client
.height
;
2063 const int y_center
= frame
.y
+ (frame
.height
/2) - client
.height
;
2065 switch(client
.win_gravity
) {
2067 case NorthWestGravity
:
2072 client
.x
= x_center
;
2075 case NorthEastGravity
:
2079 case SouthWestGravity
:
2084 client
.x
= x_center
;
2087 case SouthEastGravity
:
2093 client
.y
= y_center
;
2097 client
.y
= y_center
;
2100 client
.x
= x_center
;
2101 client
.y
= y_center
;
2105 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
2106 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
2113 void OpenboxWindow::redrawLabel(void) {
2114 int dx
= frame
.bevel_w
* 2, dlen
= client
.title_len
;
2115 unsigned int l
= client
.title_text_w
;
2117 if (flags
.focused
) {
2119 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.flabel
);
2121 XSetWindowBackground(display
, frame
.label
, frame
.flabel_pixel
);
2124 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.ulabel
);
2126 XSetWindowBackground(display
, frame
.label
, frame
.ulabel_pixel
);
2128 XClearWindow(display
, frame
.label
);
2130 if (client
.title_text_w
> frame
.label_w
) {
2131 for (; dlen
>= 0; dlen
--) {
2132 if (i18n
->multibyte()) {
2133 XRectangle ink
, logical
;
2134 XmbTextExtents(screen
->getWindowStyle()->fontset
, client
.title
, dlen
,
2138 l
= XTextWidth(screen
->getWindowStyle()->font
, client
.title
, dlen
);
2140 l
+= (frame
.bevel_w
* 4);
2142 if (l
< frame
.label_w
)
2147 switch (screen
->getWindowStyle()->justify
) {
2148 case BScreen::RightJustify
:
2149 dx
+= frame
.label_w
- l
;
2152 case BScreen::CenterJustify
:
2153 dx
+= (frame
.label_w
- l
) / 2;
2157 WindowStyle
*style
= screen
->getWindowStyle();
2158 GC text_gc
= (flags
.focused
) ? style
->l_text_focus_gc
:
2159 style
->l_text_unfocus_gc
;
2160 if (i18n
->multibyte())
2161 XmbDrawString(display
, frame
.label
, style
->fontset
, text_gc
, dx
,
2162 (1 - style
->fontset_extents
->max_ink_extent
.y
),
2163 client
.title
, dlen
);
2165 XDrawString(display
, frame
.label
, text_gc
, dx
,
2166 (style
->font
->ascent
+ 1), client
.title
, dlen
);
2170 void OpenboxWindow::redrawAllButtons(void) {
2171 if (frame
.iconify_button
) redrawIconifyButton(False
);
2172 if (frame
.maximize_button
) redrawMaximizeButton(flags
.maximized
);
2173 if (frame
.close_button
) redrawCloseButton(False
);
2177 void OpenboxWindow::redrawIconifyButton(Bool pressed
) {
2179 if (flags
.focused
) {
2181 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2184 XSetWindowBackground(display
, frame
.iconify_button
,
2185 frame
.fbutton_pixel
);
2188 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2191 XSetWindowBackground(display
, frame
.iconify_button
,
2192 frame
.ubutton_pixel
);
2196 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.pbutton
);
2198 XSetWindowBackground(display
, frame
.iconify_button
, frame
.pbutton_pixel
);
2200 XClearWindow(display
, frame
.iconify_button
);
2202 XDrawRectangle(display
, frame
.iconify_button
,
2203 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2204 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2205 2, (frame
.button_h
- 5), (frame
.button_w
- 5), 2);
2209 void OpenboxWindow::redrawMaximizeButton(Bool pressed
) {
2211 if (flags
.focused
) {
2213 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2216 XSetWindowBackground(display
, frame
.maximize_button
,
2217 frame
.fbutton_pixel
);
2220 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2223 XSetWindowBackground(display
, frame
.maximize_button
,
2224 frame
.ubutton_pixel
);
2228 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2231 XSetWindowBackground(display
, frame
.maximize_button
,
2232 frame
.pbutton_pixel
);
2234 XClearWindow(display
, frame
.maximize_button
);
2236 XDrawRectangle(display
, frame
.maximize_button
,
2237 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2238 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2239 2, 2, (frame
.button_w
- 5), (frame
.button_h
- 5));
2240 XDrawLine(display
, frame
.maximize_button
,
2241 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2242 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2243 2, 3, (frame
.button_w
- 3), 3);
2247 void OpenboxWindow::redrawCloseButton(Bool pressed
) {
2249 if (flags
.focused
) {
2251 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2254 XSetWindowBackground(display
, frame
.close_button
,
2255 frame
.fbutton_pixel
);
2258 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2261 XSetWindowBackground(display
, frame
.close_button
,
2262 frame
.ubutton_pixel
);
2266 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.pbutton
);
2268 XSetWindowBackground(display
, frame
.close_button
, frame
.pbutton_pixel
);
2270 XClearWindow(display
, frame
.close_button
);
2272 XDrawLine(display
, frame
.close_button
,
2273 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2274 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2, 2,
2275 (frame
.button_w
- 3), (frame
.button_h
- 3));
2276 XDrawLine(display
, frame
.close_button
,
2277 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2278 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2,
2279 (frame
.button_h
- 3),
2280 (frame
.button_w
- 3), 2);
2284 void OpenboxWindow::mapRequestEvent(XMapRequestEvent
*re
) {
2285 if (re
->window
== client
.window
) {
2287 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowMapRequest
,
2288 "OpenboxWindow::mapRequestEvent() for 0x%lx\n"),
2293 if (! validateClient()) return;
2295 Bool get_state_ret
= getState();
2296 if (! (get_state_ret
&& openbox
.isStartup())) {
2297 if ((client
.wm_hint_flags
& StateHint
) &&
2298 (! (current_state
== NormalState
|| current_state
== IconicState
)))
2299 current_state
= client
.initial_state
;
2301 current_state
= NormalState
;
2302 } else if (flags
.iconic
) {
2303 current_state
= NormalState
;
2306 switch (current_state
) {
2311 case WithdrawnState
:
2328 void OpenboxWindow::mapNotifyEvent(XMapEvent
*ne
) {
2329 if ((ne
->window
== client
.window
) && (! ne
->override_redirect
)
2330 && (flags
.visible
)) {
2332 if (! validateClient()) return;
2334 if (decorations
.titlebar
) positionButtons();
2336 setState(NormalState
);
2340 if (flags
.transient
|| screen
->focusNew())
2343 setFocusFlag(False
);
2345 flags
.visible
= True
;
2346 flags
.iconic
= False
;
2353 void OpenboxWindow::unmapNotifyEvent(XUnmapEvent
*ue
) {
2354 if (ue
->window
== client
.window
) {
2356 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotify
,
2357 "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"),
2362 if (! validateClient()) return;
2364 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
2365 XSelectInput(display
, client
.window
, NoEventMask
);
2367 XDeleteProperty(display
, client
.window
, openbox
.getWMStateAtom());
2368 XDeleteProperty(display
, client
.window
,
2369 openbox
.getOpenboxAttributesAtom());
2371 XUnmapWindow(display
, frame
.window
);
2372 XUnmapWindow(display
, client
.window
);
2375 if (! XCheckTypedWindowEvent(display
, client
.window
, ReparentNotify
,
2378 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotifyReparent
,
2379 "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to "
2380 "root.\n"), client
.window
);
2384 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
2385 client
.x
, client
.y
);
2397 void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent
*de
) {
2398 if (de
->window
== client
.window
) {
2399 XUnmapWindow(display
, frame
.window
);
2406 void OpenboxWindow::propertyNotifyEvent(Atom atom
) {
2408 if (! validateClient()) return;
2412 case XA_WM_CLIENT_MACHINE
:
2416 case XA_WM_TRANSIENT_FOR
:
2417 // determine if this is a transient window
2419 if (XGetTransientForHint(display
, client
.window
, &win
)) {
2420 if (win
&& (win
!= client
.window
)) {
2421 if ((client
.transient_for
= openbox
.searchWindow(win
))) {
2422 client
.transient_for
->client
.transient
= this;
2423 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2424 flags
.transient
= True
;
2425 } else if (win
== client
.window_group
) {
2426 //jr This doesn't look quite right...
2427 if ((client
.transient_for
= openbox
.searchGroup(win
, this))) {
2428 client
.transient_for
->client
.transient
= this;
2429 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2430 flags
.transient
= True
;
2435 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
2438 // adjust the window decorations based on transience
2439 if (flags
.transient
)
2440 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
2450 case XA_WM_ICON_NAME
:
2452 if (flags
.iconic
) screen
->iconUpdate();
2458 if (decorations
.titlebar
)
2462 screen
->getWorkspace(workspace_number
)->update();
2466 case XA_WM_NORMAL_HINTS
: {
2469 if ((client
.normal_hint_flags
& PMinSize
) &&
2470 (client
.normal_hint_flags
& PMaxSize
)) {
2471 if (client
.max_width
<= client
.min_width
&&
2472 client
.max_height
<= client
.min_height
)
2473 decorations
.maximize
= decorations
.handle
=
2474 functions
.resize
= functions
.maximize
= False
;
2476 decorations
.maximize
= decorations
.handle
=
2477 functions
.resize
= functions
.maximize
= True
;
2480 int x
= frame
.x
, y
= frame
.y
;
2481 unsigned int w
= frame
.width
, h
= frame
.height
;
2485 if ((x
!= frame
.x
) || (y
!= frame
.y
) ||
2486 (w
!= frame
.width
) || (h
!= frame
.height
))
2493 if (atom
== openbox
.getWMProtocolsAtom()) {
2496 if (decorations
.close
&& (! frame
.close_button
)) {
2497 createCloseButton();
2498 if (decorations
.titlebar
) positionButtons(True
);
2499 if (windowmenu
) windowmenu
->reconfigure();
2510 void OpenboxWindow::exposeEvent(XExposeEvent
*ee
) {
2511 if (frame
.label
== ee
->window
&& decorations
.titlebar
)
2513 else if (frame
.close_button
== ee
->window
)
2514 redrawCloseButton(False
);
2515 else if (frame
.maximize_button
== ee
->window
)
2516 redrawMaximizeButton(flags
.maximized
);
2517 else if (frame
.iconify_button
== ee
->window
)
2518 redrawIconifyButton(False
);
2522 void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent
*cr
) {
2523 if (cr
->window
== client
.window
) {
2525 if (! validateClient()) return;
2527 int cx
= frame
.x
, cy
= frame
.y
;
2528 unsigned int cw
= frame
.width
, ch
= frame
.height
;
2530 if (cr
->value_mask
& CWBorderWidth
)
2531 client
.old_bw
= cr
->border_width
;
2533 if (cr
->value_mask
& CWX
)
2534 cx
= cr
->x
- frame
.mwm_border_w
- frame
.border_w
;
2536 if (cr
->value_mask
& CWY
)
2537 cy
= cr
->y
- frame
.y_border
- frame
.mwm_border_w
-
2540 if (cr
->value_mask
& CWWidth
)
2541 cw
= cr
->width
+ (frame
.mwm_border_w
* 2);
2543 if (cr
->value_mask
& CWHeight
)
2544 ch
= cr
->height
+ frame
.y_border
+ (frame
.mwm_border_w
* 2) +
2545 (frame
.border_w
* decorations
.handle
) + frame
.handle_h
;
2547 if (frame
.x
!= cx
|| frame
.y
!= cy
||
2548 frame
.width
!= cw
|| frame
.height
!= ch
)
2549 configure(cx
, cy
, cw
, ch
);
2551 if (cr
->value_mask
& CWStackMode
) {
2552 switch (cr
->detail
) {
2556 if (flags
.iconic
) deiconify();
2557 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2562 if (flags
.iconic
) deiconify();
2563 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2573 void OpenboxWindow::buttonPressEvent(XButtonEvent
*be
) {
2575 if (! validateClient())
2578 int stack_change
= 1; // < 0 means to lower the window
2579 // > 0 means to raise the window
2580 // 0 means to leave it where it is
2582 // alt + left/right click begins interactively moving/resizing the window
2583 // when the mouse is moved
2584 if (be
->state
== Mod1Mask
&& (be
->button
== 1 || be
->button
== 3)) {
2585 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2586 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2587 if (be
->button
== 3) {
2588 if (screen
->getWindowZones() == 4 &&
2589 be
->y
< (signed) frame
.height
/ 2) {
2590 resize_zone
= ZoneTop
;
2592 resize_zone
= ZoneBottom
;
2594 if (screen
->getWindowZones() >= 2 &&
2595 be
->x
< (signed) frame
.width
/ 2) {
2596 resize_zone
|= ZoneLeft
;
2598 resize_zone
|= ZoneRight
;
2601 // control + left click on the titlebar shades the window
2602 } else if (be
->state
== ControlMask
&& be
->button
== 1) {
2603 if (be
->window
== frame
.title
||
2604 be
->window
== frame
.label
)
2607 } else if (be
->state
== 0 && be
->button
== 1) {
2608 if (windowmenu
&& windowmenu
->isVisible())
2611 if (be
->window
== frame
.maximize_button
) {
2612 redrawMaximizeButton(True
);
2613 } else if (be
->window
== frame
.iconify_button
) {
2614 redrawIconifyButton(True
);
2615 } else if (be
->window
== frame
.close_button
) {
2616 redrawCloseButton(True
);
2617 } else if (be
->window
== frame
.plate
) {
2618 XAllowEvents(display
, ReplayPointer
, be
->time
);
2619 } else if (be
->window
== frame
.title
||
2620 be
->window
== frame
.label
) {
2621 // shade the window when the titlebar is double clicked
2622 if ( (be
->time
- lastButtonPressTime
) <=
2623 openbox
.getDoubleClickInterval()) {
2624 lastButtonPressTime
= 0;
2627 lastButtonPressTime
= be
->time
;
2629 // clicking and dragging on the titlebar moves the window, so on a click
2630 // we need to save the coords of the click in case the user drags
2631 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2632 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2633 } else if (be
->window
== frame
.handle
||
2634 be
->window
== frame
.left_grip
||
2635 be
->window
== frame
.right_grip
||
2636 be
->window
== frame
.window
) {
2637 // clicking and dragging on the window's frame moves the window, so on a
2638 // click we need to save the coords of the click in case the user drags
2639 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2640 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2641 if (be
->window
== frame
.left_grip
)
2642 resize_zone
= ZoneBottom
| ZoneLeft
;
2643 else if (be
->window
== frame
.right_grip
)
2644 resize_zone
= ZoneBottom
| ZoneRight
;
2647 } else if (be
->state
== 0 && be
->button
== 2) {
2648 if (be
->window
== frame
.maximize_button
) {
2649 redrawMaximizeButton(True
);
2650 // a middle click anywhere on the window's frame except for on the buttons
2651 // will lower the window
2652 } else if (! (be
->window
== frame
.iconify_button
||
2653 be
->window
== frame
.close_button
) ) {
2657 } else if (be
->state
== 0 && be
->button
== 3) {
2658 if (be
->window
== frame
.maximize_button
) {
2659 redrawMaximizeButton(True
);
2660 // a right click on the window's frame will show or hide the window's
2662 } else if (be
->window
== frame
.title
||
2663 be
->window
== frame
.label
||
2664 be
->window
== frame
.handle
||
2665 be
->window
== frame
.window
) {
2668 if (windowmenu
->isVisible()) {
2671 // get the coords for the menu
2672 mx
= be
->x_root
- windowmenu
->getWidth() / 2;
2673 if (be
->window
== frame
.title
|| be
->window
== frame
.label
) {
2674 my
= frame
.y
+ frame
.title_h
;
2675 } else if (be
->window
= frame
.handle
) {
2676 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2677 } else { // (be->window == frame.window)
2678 if (be
->y
<= (signed) frame
.bevel_w
) {
2679 my
= frame
.y
+ frame
.y_border
;
2681 my
= be
->y_root
- (windowmenu
->getHeight() / 2);
2685 if (mx
> (signed) (frame
.x
+ frame
.width
-
2686 windowmenu
->getWidth())) {
2687 mx
= frame
.x
+ frame
.width
- windowmenu
->getWidth();
2688 } else if (mx
< frame
.x
) {
2692 if (my
> (signed) (frame
.y
+ frame
.y_handle
-
2693 windowmenu
->getHeight())) {
2694 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2695 } else if (my
< (signed) (frame
.y
+
2696 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
))) {
2698 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
);
2701 windowmenu
->move(mx
, my
);
2703 XRaiseWindow(display
, windowmenu
->getWindowID());
2704 XRaiseWindow(display
, windowmenu
->getSendToMenu()->getWindowID());
2705 stack_change
= 0; // dont raise the window overtop of the menu
2710 } else if (be
->state
== 0 && be
->button
== 4) {
2711 if ((be
->window
== frame
.label
||
2712 be
->window
== frame
.title
) &&
2716 } else if (be
->state
== 0 && be
->button
== 5) {
2717 if ((be
->window
== frame
.label
||
2718 be
->window
== frame
.title
) &&
2723 if (! (flags
.focused
|| screen
->sloppyFocus()) ) {
2724 setInputFocus(); // any click focus' the window in 'click to focus'
2726 if (stack_change
< 0) {
2727 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2728 } else if (stack_change
> 0) {
2729 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2736 void OpenboxWindow::buttonReleaseEvent(XButtonEvent
*re
) {
2738 if (! validateClient())
2741 // alt + middle button released
2742 if (re
->state
== (Mod1Mask
& Button2Mask
) && re
->button
== 2) {
2743 if (re
->window
== frame
.window
) {
2744 XUngrabPointer(display
, CurrentTime
); // why? i dont know
2746 // left button released
2747 } else if (re
->button
== 1) {
2748 if (re
->window
== frame
.maximize_button
) {
2749 if (re
->state
== Button1Mask
&& // only the left button was depressed
2750 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2751 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2752 maximize(re
->button
);
2754 redrawMaximizeButton(False
);
2756 } else if (re
->window
== frame
.iconify_button
) {
2757 if (re
->state
== Button1Mask
&& // only the left button was depressed
2758 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2759 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2762 redrawIconifyButton(False
);
2764 } else if (re
->window
== frame
.close_button
) {
2765 if (re
->state
== Button1Mask
&& // only the left button was depressed
2766 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2767 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2770 //we should always redraw the close button. some applications
2771 //eg. acroread don't honour the close.
2772 redrawCloseButton(False
);
2774 // middle button released
2775 } else if (re
->button
== 2) {
2776 if (re
->window
== frame
.maximize_button
) {
2777 if (re
->state
== Button2Mask
&& // only the middle button was depressed
2778 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2779 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2780 maximize(re
->button
);
2782 redrawMaximizeButton(False
);
2785 // right button released
2786 } else if (re
->button
== 3) {
2787 if (re
->window
== frame
.maximize_button
) {
2788 if (re
->state
== Button3Mask
&& // only the right button was depressed
2789 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2790 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2791 maximize(re
->button
);
2793 redrawMaximizeButton(False
);
2798 // when the window is being interactively moved, a button release stops the
2801 flags
.moving
= False
;
2803 openbox
.maskWindowEvents(0, (OpenboxWindow
*) 0);
2804 if (!screen
->opaqueMove()) {
2805 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2806 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2807 frame
.resize_h
- 1);
2809 configure(frame
.move_x
, frame
.move_y
, frame
.width
, frame
.height
);
2812 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
2814 screen
->hideGeometry();
2815 XUngrabPointer(display
, CurrentTime
);
2816 // when the window is being interactively resized, a button release stops the
2818 } else if (flags
.resizing
) {
2819 flags
.resizing
= False
;
2820 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2821 frame
.resize_x
, frame
.resize_y
,
2822 frame
.resize_w
- 1, frame
.resize_h
- 1);
2823 screen
->hideGeometry();
2824 if (resize_zone
& ZoneLeft
) {
2826 } else { // when resizing with "Alt+Button3", the resize is the same as if
2827 // done with the right grip (the right side of the window is what
2831 // unset maximized state when resized after fully maximized
2832 if (flags
.maximized
== 1) {
2835 configure(frame
.resize_x
, frame
.resize_y
,
2836 frame
.resize_w
- (frame
.border_w
* 2),
2837 frame
.resize_h
- (frame
.border_w
* 2));
2839 XUngrabPointer(display
, CurrentTime
);
2847 void OpenboxWindow::motionNotifyEvent(XMotionEvent
*me
) {
2848 if (!flags
.resizing
&& (me
->state
& Button1Mask
) && functions
.move
&&
2849 (frame
.title
== me
->window
|| frame
.label
== me
->window
||
2850 frame
.handle
== me
->window
|| frame
.window
== me
->window
)) {
2851 if (! flags
.moving
) {
2852 XGrabPointer(display
, me
->window
, False
, Button1MotionMask
|
2853 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
,
2854 None
, openbox
.getMoveCursor(), CurrentTime
);
2856 if (windowmenu
&& windowmenu
->isVisible())
2859 flags
.moving
= True
;
2861 openbox
.maskWindowEvents(client
.window
, this);
2863 if (! screen
->opaqueMove()) {
2866 frame
.move_x
= frame
.x
;
2867 frame
.move_y
= frame
.y
;
2868 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2869 frame
.resize_h
= ((flags
.shaded
) ? frame
.title_h
: frame
.height
) +
2870 (frame
.border_w
* 2);
2872 screen
->showPosition(frame
.x
, frame
.y
);
2874 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2875 frame
.move_x
, frame
.move_y
,
2876 frame
.resize_w
- 1, frame
.resize_h
- 1);
2879 int dx
= me
->x_root
- frame
.grab_x
, dy
= me
->y_root
- frame
.grab_y
;
2881 dx
-= frame
.border_w
;
2882 dy
-= frame
.border_w
;
2884 int snap_distance
= screen
->edgeSnapThreshold();
2885 // width/height of the snapping window
2886 unsigned int snap_w
= frame
.width
+ (frame
.border_w
* 2);
2887 unsigned int snap_h
= area().h() + (frame
.border_w
* 2);
2888 if (snap_distance
) {
2889 int drx
= screen
->size().w() - (dx
+ snap_w
);
2891 if (dx
< drx
&& (dx
> 0 && dx
< snap_distance
) ||
2892 (dx
< 0 && dx
> -snap_distance
) )
2894 else if ( (drx
> 0 && drx
< snap_distance
) ||
2895 (drx
< 0 && drx
> -snap_distance
) )
2896 dx
= screen
->size().w() - snap_w
;
2898 int dtty
, dbby
, dty
, dby
;
2899 switch (screen
->getToolbar()->placement()) {
2900 case Toolbar::TopLeft
:
2901 case Toolbar::TopCenter
:
2902 case Toolbar::TopRight
:
2903 dtty
= screen
->getToolbar()->getExposedHeight() +
2905 dbby
= screen
->size().h();
2910 dbby
= screen
->getToolbar()->area().y();
2915 dby
= dbby
- (dy
+ snap_h
);
2917 if ( (dy
> 0 && dty
< snap_distance
) ||
2918 (dy
< 0 && dty
> -snap_distance
) )
2920 else if ( (dby
> 0 && dby
< snap_distance
) ||
2921 (dby
< 0 && dby
> -snap_distance
) )
2925 if (screen
->opaqueMove()) {
2926 configure(dx
, dy
, frame
.width
, frame
.height
);
2928 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2929 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2930 frame
.resize_h
- 1);
2935 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2936 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2937 frame
.resize_h
- 1);
2940 screen
->showPosition(dx
, dy
);
2942 } else if (functions
.resize
&&
2943 (((me
->state
& Button1Mask
) && (me
->window
== frame
.right_grip
||
2944 me
->window
== frame
.left_grip
)) ||
2945 (me
->state
& (Mod1Mask
| Button3Mask
) &&
2946 me
->window
== frame
.window
))) {
2947 Bool left
= resize_zone
& ZoneLeft
;
2949 if (! flags
.resizing
) {
2951 if (resize_zone
& ZoneTop
)
2952 cursor
= (resize_zone
& ZoneLeft
) ?
2953 openbox
.getUpperLeftAngleCursor() :
2954 openbox
.getUpperRightAngleCursor();
2956 cursor
= (resize_zone
& ZoneLeft
) ?
2957 openbox
.getLowerLeftAngleCursor() :
2958 openbox
.getLowerRightAngleCursor();
2959 XGrabPointer(display
, me
->window
, False
, ButtonMotionMask
|
2960 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
,
2961 cursor
, CurrentTime
);
2963 flags
.resizing
= True
;
2968 if (resize_zone
& ZoneRight
)
2969 frame
.grab_x
= me
->x
- screen
->getBorderWidth();
2971 frame
.grab_x
= me
->x
+ screen
->getBorderWidth();
2972 if (resize_zone
& ZoneTop
)
2973 frame
.grab_y
= me
->y
+ screen
->getBorderWidth() * 2;
2975 frame
.grab_y
= me
->y
- screen
->getBorderWidth() * 2;
2976 frame
.resize_x
= frame
.x
;
2977 frame
.resize_y
= frame
.y
;
2978 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2979 frame
.resize_h
= frame
.height
+ (frame
.border_w
* 2);
2982 left_fixsize(&gx
, &gy
);
2984 right_fixsize(&gx
, &gy
);
2986 screen
->showGeometry(gx
, gy
);
2988 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2989 frame
.resize_x
, frame
.resize_y
,
2990 frame
.resize_w
- 1, frame
.resize_h
- 1);
2992 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2993 frame
.resize_x
, frame
.resize_y
,
2994 frame
.resize_w
- 1, frame
.resize_h
- 1);
2998 if (resize_zone
& ZoneTop
)
2999 frame
.resize_h
= frame
.height
- (me
->y
- frame
.grab_y
);
3001 frame
.resize_h
= frame
.height
+ (me
->y
- frame
.grab_y
);
3002 if (frame
.resize_h
< 1) frame
.resize_h
= 1;
3005 frame
.resize_x
= me
->x_root
- frame
.grab_x
;
3006 if (frame
.resize_x
> (signed) (frame
.x
+ frame
.width
))
3007 frame
.resize_x
= frame
.resize_x
+ frame
.width
- 1;
3009 left_fixsize(&gx
, &gy
);
3011 frame
.resize_w
= frame
.width
+ (me
->x
- frame
.grab_x
);
3012 if (frame
.resize_w
< 1) frame
.resize_w
= 1;
3014 right_fixsize(&gx
, &gy
);
3017 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
3018 frame
.resize_x
, frame
.resize_y
,
3019 frame
.resize_w
- 1, frame
.resize_h
- 1);
3021 screen
->showGeometry(gx
, gy
);
3028 void OpenboxWindow::shapeEvent(XShapeEvent
*) {
3029 if (openbox
.hasShapeExtensions()) {
3032 if (! validateClient()) return;
3033 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
3034 frame
.mwm_border_w
, frame
.y_border
+
3035 frame
.mwm_border_w
, client
.window
,
3036 ShapeBounding
, ShapeSet
);
3039 XRectangle xrect
[2];
3040 xrect
[0].x
= xrect
[0].y
= 0;
3041 xrect
[0].width
= frame
.width
;
3042 xrect
[0].height
= frame
.y_border
;
3044 if (decorations
.handle
) {
3046 xrect
[1].y
= frame
.y_handle
;
3047 xrect
[1].width
= frame
.width
;
3048 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
3052 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
3053 xrect
, num
, ShapeUnion
, Unsorted
);
3061 Bool
OpenboxWindow::validateClient(void) {
3062 XSync(display
, False
);
3065 if (XCheckTypedWindowEvent(display
, client
.window
, DestroyNotify
, &e
) ||
3066 XCheckTypedWindowEvent(display
, client
.window
, UnmapNotify
, &e
)) {
3067 XPutBackEvent(display
, &e
);
3077 void OpenboxWindow::restore(void) {
3078 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
3079 XSelectInput(display
, client
.window
, NoEventMask
);
3083 XUnmapWindow(display
, frame
.window
);
3084 XUnmapWindow(display
, client
.window
);
3086 XSetWindowBorderWidth(display
, client
.window
, client
.old_bw
);
3087 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
3088 client
.x
, client
.y
);
3089 XMapWindow(display
, client
.window
);
3095 void OpenboxWindow::timeout(void) {
3096 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
3100 void OpenboxWindow::changeOpenboxHints(OpenboxHints
*net
) {
3101 if ((net
->flags
& AttribShaded
) &&
3102 ((openbox_attrib
.attrib
& AttribShaded
) !=
3103 (net
->attrib
& AttribShaded
)))
3106 if (flags
.visible
&& // watch out for requests when we can not be seen
3107 (net
->flags
& (AttribMaxVert
| AttribMaxHoriz
)) &&
3108 ((openbox_attrib
.attrib
& (AttribMaxVert
| AttribMaxHoriz
)) !=
3109 (net
->attrib
& (AttribMaxVert
| AttribMaxHoriz
)))) {
3110 if (flags
.maximized
) {
3115 if ((net
->flags
& AttribMaxHoriz
) && (net
->flags
& AttribMaxVert
))
3116 button
= ((net
->attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0);
3117 else if (net
->flags
& AttribMaxVert
)
3118 button
= ((net
->attrib
& AttribMaxVert
) ? 2 : 0);
3119 else if (net
->flags
& AttribMaxHoriz
)
3120 button
= ((net
->attrib
& AttribMaxHoriz
) ? 3 : 0);
3126 if ((net
->flags
& AttribOmnipresent
) &&
3127 ((openbox_attrib
.attrib
& AttribOmnipresent
) !=
3128 (net
->attrib
& AttribOmnipresent
)))
3131 if ((net
->flags
& AttribWorkspace
) &&
3132 (workspace_number
!= (signed) net
->workspace
)) {
3133 screen
->reassociateWindow(this, net
->workspace
, True
);
3135 if (screen
->getCurrentWorkspaceID() != (signed) net
->workspace
) withdraw();
3139 if (net
->flags
& AttribDecoration
) {
3140 switch (net
->decoration
) {
3142 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3143 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= False
;
3149 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3150 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= True
;
3155 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
= True
;
3156 decorations
.border
= decorations
.handle
= decorations
.maximize
= False
;
3161 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
3162 decorations
.iconify
= decorations
.border
= decorations
.handle
=
3163 decorations
.maximize
= False
;
3168 XMapSubwindows(display
, frame
.window
);
3169 XMapWindow(display
, frame
.window
);
3173 setState(current_state
);
3179 * Set the sizes of all components of the window frame
3180 * (the window decorations).
3181 * These values are based upon the current style settings and the client
3182 * window's dimentions.
3184 void OpenboxWindow::upsize(void) {
3185 frame
.bevel_w
= screen
->getBevelWidth();
3187 if (decorations
.border
) {
3188 frame
.border_w
= screen
->getBorderWidth();
3189 if (!flags
.transient
)
3190 frame
.mwm_border_w
= screen
->getFrameWidth();
3192 frame
.mwm_border_w
= 0;
3194 frame
.mwm_border_w
= frame
.border_w
= 0;
3197 if (decorations
.titlebar
) {
3198 // the height of the titlebar is based upon the height of the font being
3199 // used to display the window's title
3200 WindowStyle
*style
= screen
->getWindowStyle();
3201 if (i18n
->multibyte())
3202 frame
.title_h
= (style
->fontset_extents
->max_ink_extent
.height
+
3203 (frame
.bevel_w
* 2) + 2);
3205 frame
.title_h
= (style
->font
->ascent
+ style
->font
->descent
+
3206 (frame
.bevel_w
* 2) + 2);
3208 frame
.label_h
= frame
.title_h
- (frame
.bevel_w
* 2);
3209 frame
.button_w
= frame
.button_h
= (frame
.label_h
- 2);
3210 frame
.y_border
= frame
.title_h
+ frame
.border_w
;
3214 frame
.button_w
= frame
.button_h
= 0;
3218 frame
.border_h
= client
.height
+ frame
.mwm_border_w
* 2;
3220 if (decorations
.handle
) {
3221 frame
.y_handle
= frame
.y_border
+ frame
.border_h
+ frame
.border_w
;
3222 frame
.grip_w
= frame
.button_w
* 2;
3223 frame
.grip_h
= frame
.handle_h
= screen
->getHandleWidth();
3225 frame
.y_handle
= frame
.y_border
+ frame
.border_h
;
3227 frame
.grip_w
= frame
.grip_h
= 0;
3230 frame
.width
= client
.width
+ (frame
.mwm_border_w
* 2);
3231 frame
.height
= frame
.y_handle
+ frame
.handle_h
;
3236 * Set the size and position of the client window.
3237 * These values are based upon the current style settings and the frame
3238 * window's dimensions.
3240 void OpenboxWindow::downsize(void) {
3241 frame
.y_handle
= frame
.height
- frame
.handle_h
;
3242 frame
.border_h
= frame
.y_handle
- frame
.y_border
-
3243 (decorations
.handle
? frame
.border_w
: 0);
3245 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
3246 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+ frame
.border_w
;
3248 client
.width
= frame
.width
- (frame
.mwm_border_w
* 2);
3249 client
.height
= frame
.height
- frame
.y_border
- (frame
.mwm_border_w
* 2)
3250 - frame
.handle_h
- (decorations
.handle
? frame
.border_w
: 0);
3252 frame
.y_handle
= frame
.border_h
+ frame
.y_border
+ frame
.border_w
;
3256 void OpenboxWindow::right_fixsize(int *gx
, int *gy
) {
3257 // calculate the size of the client window and conform it to the
3258 // size specified by the size hints of the client window...
3259 int dx
= frame
.resize_w
- client
.base_width
- (frame
.mwm_border_w
* 2) -
3260 (frame
.border_w
* 2) + (client
.width_inc
/ 2);
3261 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3262 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3263 + (client
.height_inc
/ 2);
3265 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3266 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3267 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3268 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3270 dx
/= client
.width_inc
;
3271 dy
/= client
.height_inc
;
3276 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3277 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3279 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3280 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3281 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3282 if (resize_zone
& ZoneTop
)
3283 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3284 screen
->getBorderWidth() * 2;
3288 void OpenboxWindow::left_fixsize(int *gx
, int *gy
) {
3289 // calculate the size of the client window and conform it to the
3290 // size specified by the size hints of the client window...
3291 int dx
= frame
.x
+ frame
.width
- frame
.resize_x
- client
.base_width
-
3292 (frame
.mwm_border_w
* 2) + (client
.width_inc
/ 2);
3293 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3294 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3295 + (client
.height_inc
/ 2);
3297 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3298 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3299 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3300 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3302 dx
/= client
.width_inc
;
3303 dy
/= client
.height_inc
;
3308 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3309 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3311 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3312 frame
.resize_x
= frame
.x
+ frame
.width
- frame
.resize_w
+
3313 (frame
.border_w
* 2);
3314 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3315 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3316 if (resize_zone
& ZoneTop
)
3317 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3318 screen
->getBorderWidth() * 2;