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 // STDC_HEADERS
43 # endif // HAVE_STDIO_H
52 #include "Windowmenu.h"
53 #include "Workspace.h"
59 * Initializes the class with default values/the window's set initial values.
61 OpenboxWindow::OpenboxWindow(Openbox
*b
, Window w
, BScreen
*s
) {
63 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowCreating
,
64 "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
);
179 flags
.managed
= True
;
180 openbox
->saveWindowSearch(client
.window
, this);
182 // determine if this is a transient window
184 if (XGetTransientForHint(display
, client
.window
, &win
)) {
185 if (win
&& (win
!= client
.window
)) {
187 if ((tr
= openbox
->searchWindow(win
))) {
188 while (tr
->client
.transient
) tr
= tr
->client
.transient
;
189 client
.transient_for
= tr
;
190 tr
->client
.transient
= this;
191 flags
.stuck
= client
.transient_for
->flags
.stuck
;
192 flags
.transient
= True
;
193 } else if (win
== client
.window_group
) {
194 if ((tr
= openbox
->searchGroup(win
, this))) {
195 while (tr
->client
.transient
) tr
= tr
->client
.transient
;
196 client
.transient_for
= tr
;
197 tr
->client
.transient
= this;
198 flags
.stuck
= client
.transient_for
->flags
.stuck
;
199 flags
.transient
= True
;
204 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
207 // adjust the window decorations based on transience and window sizes
209 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
211 if ((client
.normal_hint_flags
& PMinSize
) &&
212 (client
.normal_hint_flags
& PMaxSize
) &&
213 client
.max_width
<= client
.min_width
&&
214 client
.max_height
<= client
.min_height
) {
215 decorations
.maximize
= decorations
.handle
=
216 functions
.resize
= functions
.maximize
= False
;
220 Bool place_window
= True
;
221 if (openbox
->isStartup() || flags
.transient
||
222 client
.normal_hint_flags
& (PPosition
|USPosition
)) {
225 if ((openbox
->isStartup()) ||
227 (signed) (frame
.y
+ frame
.y_border
) >= 0 &&
228 frame
.x
<= (signed) screen
->getWidth() &&
229 frame
.y
<= (signed) screen
->getHeight()))
230 place_window
= False
;
233 frame
.window
= createToplevelWindow(frame
.x
, frame
.y
, frame
.width
,
236 openbox
->saveWindowSearch(frame
.window
, this);
238 frame
.plate
= createChildWindow(frame
.window
);
239 openbox
->saveWindowSearch(frame
.plate
, this);
241 if (decorations
.titlebar
) {
242 frame
.title
= createChildWindow(frame
.window
);
243 frame
.label
= createChildWindow(frame
.title
);
244 openbox
->saveWindowSearch(frame
.title
, this);
245 openbox
->saveWindowSearch(frame
.label
, this);
248 if (decorations
.handle
) {
249 frame
.handle
= createChildWindow(frame
.window
);
250 openbox
->saveWindowSearch(frame
.handle
, this);
253 createChildWindow(frame
.handle
, openbox
->getLowerLeftAngleCursor());
254 openbox
->saveWindowSearch(frame
.left_grip
, this);
257 createChildWindow(frame
.handle
, openbox
->getLowerRightAngleCursor());
258 openbox
->saveWindowSearch(frame
.right_grip
, this);
261 associateClientWindow();
263 if (! screen
->isSloppyFocus())
264 openbox
->grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
265 GrabModeSync
, GrabModeSync
, None
, None
);
267 openbox
->grabButton(Button1
, Mod1Mask
, frame
.window
, True
,
268 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
269 GrabModeAsync
, None
, openbox
->getMoveCursor());
270 openbox
->grabButton(Button2
, Mod1Mask
, frame
.window
, True
,
271 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
, None
);
272 openbox
->grabButton(Button3
, Mod1Mask
, frame
.window
, True
,
273 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
274 GrabModeAsync
, None
, None
);
277 XRaiseWindow(display
, frame
.plate
);
278 XMapSubwindows(display
, frame
.plate
);
279 if (decorations
.titlebar
) XMapSubwindows(display
, frame
.title
);
280 XMapSubwindows(display
, frame
.window
);
282 if (decorations
.menu
)
283 windowmenu
= new Windowmenu(this);
287 if (workspace_number
< 0 || workspace_number
>= screen
->getWorkspaceCount())
288 screen
->getCurrentWorkspace()->addWindow(this, place_window
);
290 screen
->getWorkspace(workspace_number
)->addWindow(this, place_window
);
292 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
295 flags
.shaded
= False
;
299 if (flags
.maximized
&& functions
.maximize
) {
300 unsigned int button
= flags
.maximized
;
311 OpenboxWindow::~OpenboxWindow(void) {
312 if (flags
.moving
|| flags
.resizing
) {
313 screen
->hideGeometry();
314 XUngrabPointer(display
, CurrentTime
);
317 if (workspace_number
!= -1 && window_number
!= -1)
318 screen
->getWorkspace(workspace_number
)->removeWindow(this);
319 else if (flags
.iconic
)
320 screen
->removeIcon(this);
323 if (timer
->isTiming()) timer
->stop();
327 if (windowmenu
) delete windowmenu
;
330 delete [] client
.title
;
332 if (client
.icon_title
)
333 delete [] client
.icon_title
;
336 XFree(client
.mwm_hint
);
338 if (client
.openbox_hint
)
339 XFree(client
.openbox_hint
);
341 if (client
.window_group
)
342 openbox
->removeGroupSearch(client
.window_group
);
344 if (flags
.transient
&& client
.transient_for
)
345 client
.transient_for
->client
.transient
= client
.transient
;
346 if (client
.transient
)
347 client
.transient
->client
.transient_for
= client
.transient_for
;
349 if (frame
.close_button
) {
350 openbox
->removeWindowSearch(frame
.close_button
);
351 XDestroyWindow(display
, frame
.close_button
);
354 if (frame
.iconify_button
) {
355 openbox
->removeWindowSearch(frame
.iconify_button
);
356 XDestroyWindow(display
, frame
.iconify_button
);
359 if (frame
.maximize_button
) {
360 openbox
->removeWindowSearch(frame
.maximize_button
);
361 XDestroyWindow(display
, frame
.maximize_button
);
366 image_ctrl
->removeImage(frame
.ftitle
);
369 image_ctrl
->removeImage(frame
.utitle
);
372 image_ctrl
->removeImage(frame
.flabel
);
375 image_ctrl
->removeImage(frame
.ulabel
);
377 openbox
->removeWindowSearch(frame
.label
);
378 openbox
->removeWindowSearch(frame
.title
);
379 XDestroyWindow(display
, frame
.label
);
380 XDestroyWindow(display
, frame
.title
);
385 image_ctrl
->removeImage(frame
.fhandle
);
388 image_ctrl
->removeImage(frame
.uhandle
);
391 image_ctrl
->removeImage(frame
.fgrip
);
394 image_ctrl
->removeImage(frame
.ugrip
);
396 openbox
->removeWindowSearch(frame
.handle
);
397 openbox
->removeWindowSearch(frame
.right_grip
);
398 openbox
->removeWindowSearch(frame
.left_grip
);
399 XDestroyWindow(display
, frame
.right_grip
);
400 XDestroyWindow(display
, frame
.left_grip
);
401 XDestroyWindow(display
, frame
.handle
);
405 image_ctrl
->removeImage(frame
.fbutton
);
408 image_ctrl
->removeImage(frame
.ubutton
);
411 image_ctrl
->removeImage(frame
.pbutton
);
414 openbox
->removeWindowSearch(frame
.plate
);
415 XDestroyWindow(display
, frame
.plate
);
419 openbox
->removeWindowSearch(frame
.window
);
420 XDestroyWindow(display
, frame
.window
);
424 openbox
->removeWindowSearch(client
.window
);
425 screen
->removeNetizen(client
.window
);
431 * Creates a new top level window, with a given location, size, and border
433 * Returns: the newly created window
435 Window
OpenboxWindow::createToplevelWindow(int x
, int y
, unsigned int width
,
437 unsigned int borderwidth
)
439 XSetWindowAttributes attrib_create
;
440 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
| CWColormap
|
441 CWOverrideRedirect
| CWEventMask
;
443 attrib_create
.background_pixmap
= None
;
444 attrib_create
.colormap
= screen
->getColormap();
445 attrib_create
.override_redirect
= True
;
446 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
447 ButtonMotionMask
| EnterWindowMask
;
449 return XCreateWindow(display
, screen
->getRootWindow(), x
, y
, width
, height
,
450 borderwidth
, screen
->getDepth(), InputOutput
,
451 screen
->getVisual(), create_mask
,
457 * Creates a child window, and optionally associates a given cursor with
460 Window
OpenboxWindow::createChildWindow(Window parent
, Cursor cursor
) {
461 XSetWindowAttributes attrib_create
;
462 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
|
465 attrib_create
.background_pixmap
= None
;
466 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
467 ButtonMotionMask
| ExposureMask
|
468 EnterWindowMask
| LeaveWindowMask
;
471 create_mask
|= CWCursor
;
472 attrib_create
.cursor
= cursor
;
475 return XCreateWindow(display
, parent
, 0, 0, 1, 1, 0, screen
->getDepth(),
476 InputOutput
, screen
->getVisual(), create_mask
,
481 void OpenboxWindow::associateClientWindow(void) {
482 XSetWindowBorderWidth(display
, client
.window
, 0);
486 XChangeSaveSet(display
, client
.window
, SetModeInsert
);
487 XSetWindowAttributes attrib_set
;
489 XSelectInput(display
, frame
.plate
, NoEventMask
);
490 XReparentWindow(display
, client
.window
, frame
.plate
, 0, 0);
491 XSelectInput(display
, frame
.plate
, SubstructureRedirectMask
);
495 attrib_set
.event_mask
= PropertyChangeMask
| StructureNotifyMask
|
497 attrib_set
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
500 XChangeWindowAttributes(display
, client
.window
, CWEventMask
|CWDontPropagate
,
504 if (openbox
->hasShapeExtensions()) {
505 XShapeSelectInput(display
, client
.window
, ShapeNotifyMask
);
510 XShapeQueryExtents(display
, client
.window
, &flags
.shaped
, &foo
, &foo
,
511 &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
, &ufoo
);
514 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
515 frame
.mwm_border_w
, frame
.y_border
+
516 frame
.mwm_border_w
, client
.window
,
517 ShapeBounding
, ShapeSet
);
521 xrect
[0].x
= xrect
[0].y
= 0;
522 xrect
[0].width
= frame
.width
;
523 xrect
[0].height
= frame
.y_border
;
525 if (decorations
.handle
) {
527 xrect
[1].y
= frame
.y_handle
;
528 xrect
[1].width
= frame
.width
;
529 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
533 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
534 xrect
, num
, ShapeUnion
, Unsorted
);
539 if (decorations
.iconify
) createIconifyButton();
540 if (decorations
.maximize
) createMaximizeButton();
541 if (decorations
.close
) createCloseButton();
544 if (frame
.close_button
)
545 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.ubutton
);
546 if (frame
.maximize_button
)
547 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
549 if (frame
.iconify_button
)
550 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.ubutton
);
552 if (frame
.close_button
)
553 XSetWindowBackground(display
, frame
.close_button
, frame
.ubutton_pixel
);
554 if (frame
.maximize_button
)
555 XSetWindowBackground(display
, frame
.maximize_button
,
556 frame
.ubutton_pixel
);
557 if (frame
.iconify_button
)
558 XSetWindowBackground(display
, frame
.iconify_button
, frame
.ubutton_pixel
);
563 void OpenboxWindow::decorate(void) {
564 Pixmap tmp
= frame
.fbutton
;
565 BTexture
*texture
= &(screen
->getWindowStyle()->b_focus
);
566 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
567 frame
.fbutton
= None
;
568 frame
.fbutton_pixel
= texture
->getColor()->getPixel();
571 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
573 if (tmp
) image_ctrl
->removeImage(tmp
);
576 texture
= &(screen
->getWindowStyle()->b_unfocus
);
577 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
578 frame
.ubutton
= None
;
579 frame
.ubutton_pixel
= texture
->getColor()->getPixel();
582 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
584 if (tmp
) image_ctrl
->removeImage(tmp
);
587 texture
= &(screen
->getWindowStyle()->b_pressed
);
588 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
589 frame
.pbutton
= None
;
590 frame
.pbutton_pixel
= texture
->getColor()->getPixel();
593 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
595 if (tmp
) image_ctrl
->removeImage(tmp
);
597 if (decorations
.titlebar
) {
599 texture
= &(screen
->getWindowStyle()->t_focus
);
600 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
602 frame
.ftitle_pixel
= texture
->getColor()->getPixel();
605 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
607 if (tmp
) image_ctrl
->removeImage(tmp
);
610 texture
= &(screen
->getWindowStyle()->t_unfocus
);
611 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
613 frame
.utitle_pixel
= texture
->getColor()->getPixel();
616 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
618 if (tmp
) image_ctrl
->removeImage(tmp
);
620 XSetWindowBorder(display
, frame
.title
,
621 screen
->getBorderColor()->getPixel());
626 if (decorations
.border
) {
627 frame
.fborder_pixel
= screen
->getWindowStyle()->f_focus
.getPixel();
628 frame
.uborder_pixel
= screen
->getWindowStyle()->f_unfocus
.getPixel();
629 openbox_attrib
.flags
|= AttribDecoration
;
630 openbox_attrib
.decoration
= DecorNormal
;
632 openbox_attrib
.flags
|= AttribDecoration
;
633 openbox_attrib
.decoration
= DecorNone
;
636 if (decorations
.handle
) {
638 texture
= &(screen
->getWindowStyle()->h_focus
);
639 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
640 frame
.fhandle
= None
;
641 frame
.fhandle_pixel
= texture
->getColor()->getPixel();
644 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
646 if (tmp
) image_ctrl
->removeImage(tmp
);
649 texture
= &(screen
->getWindowStyle()->h_unfocus
);
650 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
651 frame
.uhandle
= None
;
652 frame
.uhandle_pixel
= texture
->getColor()->getPixel();
655 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
657 if (tmp
) image_ctrl
->removeImage(tmp
);
660 texture
= &(screen
->getWindowStyle()->g_focus
);
661 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
663 frame
.fgrip_pixel
= texture
->getColor()->getPixel();
666 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
668 if (tmp
) image_ctrl
->removeImage(tmp
);
671 texture
= &(screen
->getWindowStyle()->g_unfocus
);
672 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
674 frame
.ugrip_pixel
= texture
->getColor()->getPixel();
677 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
679 if (tmp
) image_ctrl
->removeImage(tmp
);
681 XSetWindowBorder(display
, frame
.handle
,
682 screen
->getBorderColor()->getPixel());
683 XSetWindowBorder(display
, frame
.left_grip
,
684 screen
->getBorderColor()->getPixel());
685 XSetWindowBorder(display
, frame
.right_grip
,
686 screen
->getBorderColor()->getPixel());
689 XSetWindowBorder(display
, frame
.window
,
690 screen
->getBorderColor()->getPixel());
694 void OpenboxWindow::decorateLabel(void) {
695 Pixmap tmp
= frame
.flabel
;
696 BTexture
*texture
= &(screen
->getWindowStyle()->l_focus
);
697 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
699 frame
.flabel_pixel
= texture
->getColor()->getPixel();
702 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
704 if (tmp
) image_ctrl
->removeImage(tmp
);
707 texture
= &(screen
->getWindowStyle()->l_unfocus
);
708 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
710 frame
.ulabel_pixel
= texture
->getColor()->getPixel();
713 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
715 if (tmp
) image_ctrl
->removeImage(tmp
);
719 void OpenboxWindow::createCloseButton(void) {
720 if (decorations
.close
&& frame
.title
!= None
) {
721 frame
.close_button
= createChildWindow(frame
.title
);
722 openbox
->saveWindowSearch(frame
.close_button
, this);
727 void OpenboxWindow::createIconifyButton(void) {
728 if (decorations
.iconify
&& frame
.title
!= None
) {
729 frame
.iconify_button
= createChildWindow(frame
.title
);
730 openbox
->saveWindowSearch(frame
.iconify_button
, this);
735 void OpenboxWindow::createMaximizeButton(void) {
736 if (decorations
.maximize
&& frame
.title
!= None
) {
737 frame
.maximize_button
= createChildWindow(frame
.title
);
738 openbox
->saveWindowSearch(frame
.maximize_button
, this);
743 void OpenboxWindow::positionButtons(Bool redecorate_label
) {
744 const char *format
= openbox
->getTitleBarLayout();
745 const unsigned int bw
= frame
.bevel_w
+ 1;
746 const unsigned int by
= frame
.bevel_w
+ 1;
747 unsigned int bx
= frame
.bevel_w
+ 1;
748 unsigned int bcount
= strlen(format
) - 1;
750 if (!decorations
.close
)
752 if (!decorations
.maximize
)
754 if (!decorations
.iconify
)
756 frame
.label_w
= frame
.width
- bx
* 2 - (frame
.button_w
+ bw
) * bcount
;
758 bool hasclose
, hasiconify
, hasmaximize
;
759 hasclose
= hasiconify
= hasmaximize
= false;
761 for (int i
= 0; format
[i
] != '\0' && i
< 4; i
++) {
764 if (decorations
.close
&& frame
.close_button
!= None
) {
765 XMoveResizeWindow(display
, frame
.close_button
, bx
, by
,
766 frame
.button_w
, frame
.button_h
);
767 XMapWindow(display
, frame
.close_button
);
768 XClearWindow(display
, frame
.close_button
);
769 bx
+= frame
.button_w
+ bw
;
771 } else if (frame
.close_button
)
772 XUnmapWindow(display
, frame
.close_button
);
775 if (decorations
.iconify
&& frame
.iconify_button
!= None
) {
776 XMoveResizeWindow(display
, frame
.iconify_button
, bx
, by
,
777 frame
.button_w
, frame
.button_h
);
778 XMapWindow(display
, frame
.iconify_button
);
779 XClearWindow(display
, frame
.iconify_button
);
780 bx
+= frame
.button_w
+ bw
;
782 } else if (frame
.close_button
)
783 XUnmapWindow(display
, frame
.close_button
);
786 if (decorations
.maximize
&& frame
.maximize_button
!= None
) {
787 XMoveResizeWindow(display
, frame
.maximize_button
, bx
, by
,
788 frame
.button_w
, frame
.button_h
);
789 XMapWindow(display
, frame
.maximize_button
);
790 XClearWindow(display
, frame
.maximize_button
);
791 bx
+= frame
.button_w
+ bw
;
793 } else if (frame
.close_button
)
794 XUnmapWindow(display
, frame
.close_button
);
797 XMoveResizeWindow(display
, frame
.label
, bx
, by
- 1,
798 frame
.label_w
, frame
.label_h
);
799 bx
+= frame
.label_w
+ bw
;
805 openbox
->removeWindowSearch(frame
.close_button
);
806 XDestroyWindow(display
, frame
.close_button
);
809 openbox
->removeWindowSearch(frame
.iconify_button
);
810 XDestroyWindow(display
, frame
.iconify_button
);
813 openbox
->removeWindowSearch(frame
.maximize_button
);
814 XDestroyWindow(display
, frame
.maximize_button
);
816 if (redecorate_label
)
823 void OpenboxWindow::reconfigure(void) {
826 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
827 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
831 if (i18n
->multibyte()) {
832 XRectangle ink
, logical
;
833 XmbTextExtents(screen
->getWindowStyle()->fontset
,
834 client
.title
, client
.title_len
, &ink
, &logical
);
835 client
.title_text_w
= logical
.width
;
837 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
838 client
.title
, client
.title_len
);
840 client
.title_text_w
+= (frame
.bevel_w
* 4);
846 XClearWindow(display
, frame
.window
);
847 setFocusFlag(flags
.focused
);
849 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
851 if (! screen
->isSloppyFocus())
852 openbox
->grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
853 GrabModeSync
, GrabModeSync
, None
, None
);
855 openbox
->ungrabButton(Button1
, 0, frame
.plate
);
858 windowmenu
->move(windowmenu
->getX(), frame
.y
+ frame
.title_h
);
859 windowmenu
->reconfigure();
864 void OpenboxWindow::positionWindows(void) {
865 XResizeWindow(display
, frame
.window
, frame
.width
,
866 ((flags
.shaded
) ? frame
.title_h
: frame
.height
));
867 XSetWindowBorderWidth(display
, frame
.window
, frame
.border_w
);
868 XSetWindowBorderWidth(display
, frame
.plate
, frame
.mwm_border_w
);
869 XMoveResizeWindow(display
, frame
.plate
, 0, frame
.y_border
,
870 client
.width
, client
.height
);
871 XMoveResizeWindow(display
, client
.window
, 0, 0, client
.width
, client
.height
);
873 if (decorations
.titlebar
) {
874 XSetWindowBorderWidth(display
, frame
.title
, frame
.border_w
);
875 XMoveResizeWindow(display
, frame
.title
, -frame
.border_w
,
876 -frame
.border_w
, frame
.width
, frame
.title_h
);
879 } else if (frame
.title
) {
880 XUnmapWindow(display
, frame
.title
);
882 if (decorations
.handle
) {
883 XSetWindowBorderWidth(display
, frame
.handle
, frame
.border_w
);
884 XSetWindowBorderWidth(display
, frame
.left_grip
, frame
.border_w
);
885 XSetWindowBorderWidth(display
, frame
.right_grip
, frame
.border_w
);
887 XMoveResizeWindow(display
, frame
.handle
, -frame
.border_w
,
888 frame
.y_handle
- frame
.border_w
,
889 frame
.width
, frame
.handle_h
);
890 XMoveResizeWindow(display
, frame
.left_grip
, -frame
.border_w
,
891 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
892 XMoveResizeWindow(display
, frame
.right_grip
,
893 frame
.width
- frame
.grip_w
- frame
.border_w
,
894 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
895 XMapSubwindows(display
, frame
.handle
);
896 } else if (frame
.handle
) {
897 XUnmapWindow(display
, frame
.handle
);
902 void OpenboxWindow::getWMName(void) {
904 delete [] client
.title
;
905 client
.title
= (char *) 0;
908 XTextProperty text_prop
;
912 if (XGetWMName(display
, client
.window
, &text_prop
)) {
913 if (text_prop
.value
&& text_prop
.nitems
> 0) {
914 if (text_prop
.encoding
!= XA_STRING
) {
915 text_prop
.nitems
= strlen((char *) text_prop
.value
);
917 if ((XmbTextPropertyToTextList(display
, &text_prop
,
918 &list
, &num
) == Success
) &&
919 (num
> 0) && *list
) {
920 client
.title
= bstrdup(*list
);
921 XFreeStringList(list
);
923 client
.title
= bstrdup((char *) text_prop
.value
);
926 client
.title
= bstrdup((char *) text_prop
.value
);
928 XFree((char *) text_prop
.value
);
930 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
934 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
937 client
.title_len
= strlen(client
.title
);
939 if (i18n
->multibyte()) {
940 XRectangle ink
, logical
;
941 XmbTextExtents(screen
->getWindowStyle()->fontset
,
942 client
.title
, client
.title_len
, &ink
, &logical
);
943 client
.title_text_w
= logical
.width
;
945 client
.title_len
= strlen(client
.title
);
946 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
947 client
.title
, client
.title_len
);
950 client
.title_text_w
+= (frame
.bevel_w
* 4);
954 void OpenboxWindow::getWMIconName(void) {
955 if (client
.icon_title
) {
956 delete [] client
.icon_title
;
957 client
.icon_title
= (char *) 0;
960 XTextProperty text_prop
;
964 if (XGetWMIconName(display
, client
.window
, &text_prop
)) {
965 if (text_prop
.value
&& text_prop
.nitems
> 0) {
966 if (text_prop
.encoding
!= XA_STRING
) {
967 text_prop
.nitems
= strlen((char *) text_prop
.value
);
969 if ((XmbTextPropertyToTextList(display
, &text_prop
,
970 &list
, &num
) == Success
) &&
971 (num
> 0) && *list
) {
972 client
.icon_title
= bstrdup(*list
);
973 XFreeStringList(list
);
975 client
.icon_title
= bstrdup((char *) text_prop
.value
);
978 client
.icon_title
= bstrdup((char *) text_prop
.value
);
980 XFree((char *) text_prop
.value
);
982 client
.icon_title
= bstrdup(client
.title
);
985 client
.icon_title
= bstrdup(client
.title
);
991 * Retrieve which WM Protocols are supported by the client window.
992 * If the WM_DELETE_WINDOW protocol is supported, add the close button to the
993 * window's decorations and allow the close behavior.
994 * If the WM_TAKE_FOCUS protocol is supported, save a value that indicates
997 void OpenboxWindow::getWMProtocols(void) {
1001 if (XGetWMProtocols(display
, client
.window
, &proto
, &num_return
)) {
1002 for (int i
= 0; i
< num_return
; ++i
) {
1003 if (proto
[i
] == openbox
->getWMDeleteAtom())
1004 functions
.close
= decorations
.close
= True
;
1005 else if (proto
[i
] == openbox
->getWMTakeFocusAtom())
1006 flags
.send_focus_message
= True
;
1007 else if (proto
[i
] == openbox
->getOpenboxStructureMessagesAtom())
1008 screen
->addNetizen(new Netizen(screen
, client
.window
));
1017 * Gets the value of the WM_HINTS property.
1018 * If the property is not set, then use a set of default values.
1020 void OpenboxWindow::getWMHints(void) {
1021 XWMHints
*wmhint
= XGetWMHints(display
, client
.window
);
1023 flags
.visible
= True
;
1024 flags
.iconic
= False
;
1025 focus_mode
= F_Passive
;
1026 client
.window_group
= None
;
1027 client
.initial_state
= NormalState
;
1030 client
.wm_hint_flags
= wmhint
->flags
;
1031 if (wmhint
->flags
& InputHint
) {
1032 if (wmhint
->input
== True
) {
1033 if (flags
.send_focus_message
)
1034 focus_mode
= F_LocallyActive
;
1036 focus_mode
= F_Passive
;
1038 if (flags
.send_focus_message
)
1039 focus_mode
= F_GloballyActive
;
1041 focus_mode
= F_NoInput
;
1044 focus_mode
= F_Passive
;
1047 if (wmhint
->flags
& StateHint
)
1048 client
.initial_state
= wmhint
->initial_state
;
1050 client
.initial_state
= NormalState
;
1052 if (wmhint
->flags
& WindowGroupHint
) {
1053 if (! client
.window_group
) {
1054 client
.window_group
= wmhint
->window_group
;
1055 openbox
->saveGroupSearch(client
.window_group
, this);
1058 client
.window_group
= None
;
1065 * Gets the value of the WM_NORMAL_HINTS property.
1066 * If the property is not set, then use a set of default values.
1068 void OpenboxWindow::getWMNormalHints(void) {
1070 XSizeHints sizehint
;
1072 client
.min_width
= client
.min_height
=
1073 client
.base_width
= client
.base_height
=
1074 client
.width_inc
= client
.height_inc
= 1;
1075 client
.max_width
= screen
->getWidth();
1076 client
.max_height
= screen
->getHeight();
1077 client
.min_aspect_x
= client
.min_aspect_y
=
1078 client
.max_aspect_x
= client
.max_aspect_y
= 1;
1079 client
.win_gravity
= NorthWestGravity
;
1081 if (! XGetWMNormalHints(display
, client
.window
, &sizehint
, &icccm_mask
))
1084 client
.normal_hint_flags
= sizehint
.flags
;
1086 if (sizehint
.flags
& PMinSize
) {
1087 client
.min_width
= sizehint
.min_width
;
1088 client
.min_height
= sizehint
.min_height
;
1091 if (sizehint
.flags
& PMaxSize
) {
1092 client
.max_width
= sizehint
.max_width
;
1093 client
.max_height
= sizehint
.max_height
;
1096 if (sizehint
.flags
& PResizeInc
) {
1097 client
.width_inc
= sizehint
.width_inc
;
1098 client
.height_inc
= sizehint
.height_inc
;
1101 if (sizehint
.flags
& PAspect
) {
1102 client
.min_aspect_x
= sizehint
.min_aspect
.x
;
1103 client
.min_aspect_y
= sizehint
.min_aspect
.y
;
1104 client
.max_aspect_x
= sizehint
.max_aspect
.x
;
1105 client
.max_aspect_y
= sizehint
.max_aspect
.y
;
1108 if (sizehint
.flags
& PBaseSize
) {
1109 client
.base_width
= sizehint
.base_width
;
1110 client
.base_height
= sizehint
.base_height
;
1113 if (sizehint
.flags
& PWinGravity
)
1114 client
.win_gravity
= sizehint
.win_gravity
;
1119 * Gets the MWM hints for the class' contained window.
1120 * This is used while initializing the window to its first state, and not
1122 * Returns: true if the MWM hints are successfully retreived and applied; false
1125 void OpenboxWindow::getMWMHints(void) {
1128 unsigned long num
, len
;
1130 int ret
= XGetWindowProperty(display
, client
.window
,
1131 openbox
->getMotifWMHintsAtom(), 0,
1132 PropMwmHintsElements
, False
,
1133 openbox
->getMotifWMHintsAtom(), &atom_return
,
1134 &format
, &num
, &len
,
1135 (unsigned char **) &client
.mwm_hint
);
1137 if (ret
!= Success
|| !client
.mwm_hint
|| num
!= PropMwmHintsElements
)
1140 if (client
.mwm_hint
->flags
& MwmHintsDecorations
) {
1141 if (client
.mwm_hint
->decorations
& MwmDecorAll
) {
1142 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1143 decorations
.iconify
= decorations
.maximize
=
1144 decorations
.close
= decorations
.menu
= True
;
1146 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1147 decorations
.iconify
= decorations
.maximize
=
1148 decorations
.close
= decorations
.menu
= False
;
1150 if (client
.mwm_hint
->decorations
& MwmDecorBorder
)
1151 decorations
.border
= True
;
1152 if (client
.mwm_hint
->decorations
& MwmDecorHandle
)
1153 decorations
.handle
= True
;
1154 if (client
.mwm_hint
->decorations
& MwmDecorTitle
)
1155 decorations
.titlebar
= True
;
1156 if (client
.mwm_hint
->decorations
& MwmDecorMenu
)
1157 decorations
.menu
= True
;
1158 if (client
.mwm_hint
->decorations
& MwmDecorIconify
)
1159 decorations
.iconify
= True
;
1160 if (client
.mwm_hint
->decorations
& MwmDecorMaximize
)
1161 decorations
.maximize
= True
;
1165 if (client
.mwm_hint
->flags
& MwmHintsFunctions
) {
1166 if (client
.mwm_hint
->functions
& MwmFuncAll
) {
1167 functions
.resize
= functions
.move
= functions
.iconify
=
1168 functions
.maximize
= functions
.close
= True
;
1170 functions
.resize
= functions
.move
= functions
.iconify
=
1171 functions
.maximize
= functions
.close
= False
;
1173 if (client
.mwm_hint
->functions
& MwmFuncResize
)
1174 functions
.resize
= True
;
1175 if (client
.mwm_hint
->functions
& MwmFuncMove
)
1176 functions
.move
= True
;
1177 if (client
.mwm_hint
->functions
& MwmFuncIconify
)
1178 functions
.iconify
= True
;
1179 if (client
.mwm_hint
->functions
& MwmFuncMaximize
)
1180 functions
.maximize
= True
;
1181 if (client
.mwm_hint
->functions
& MwmFuncClose
)
1182 functions
.close
= True
;
1189 * Gets the openbox hints from the class' contained window.
1190 * This is used while initializing the window to its first state, and not
1192 * Returns: true if the hints are successfully retreived and applied; false if
1195 void OpenboxWindow::getOpenboxHints(void) {
1198 unsigned long num
, len
;
1200 int ret
= XGetWindowProperty(display
, client
.window
,
1201 openbox
->getOpenboxHintsAtom(), 0,
1202 PropOpenboxHintsElements
, False
,
1203 openbox
->getOpenboxHintsAtom(), &atom_return
,
1204 &format
, &num
, &len
,
1205 (unsigned char **) &client
.openbox_hint
);
1206 if (ret
!= Success
|| !client
.openbox_hint
||
1207 num
!= PropOpenboxHintsElements
)
1210 if (client
.openbox_hint
->flags
& AttribShaded
)
1211 flags
.shaded
= (client
.openbox_hint
->attrib
& AttribShaded
);
1213 if ((client
.openbox_hint
->flags
& AttribMaxHoriz
) &&
1214 (client
.openbox_hint
->flags
& AttribMaxVert
))
1215 flags
.maximized
= (client
.openbox_hint
->attrib
&
1216 (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1217 else if (client
.openbox_hint
->flags
& AttribMaxVert
)
1218 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxVert
) ? 2 : 0;
1219 else if (client
.openbox_hint
->flags
& AttribMaxHoriz
)
1220 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxHoriz
) ? 3 : 0;
1222 if (client
.openbox_hint
->flags
& AttribOmnipresent
)
1223 flags
.stuck
= (client
.openbox_hint
->attrib
& AttribOmnipresent
);
1225 if (client
.openbox_hint
->flags
& AttribWorkspace
)
1226 workspace_number
= client
.openbox_hint
->workspace
;
1228 // if (client.openbox_hint->flags & AttribStack)
1229 // don't yet have always on top/bottom for openbox yet... working
1232 if (client
.openbox_hint
->flags
& AttribDecoration
) {
1233 switch (client
.openbox_hint
->decoration
) {
1235 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1236 decorations
.iconify
= decorations
.maximize
=
1237 decorations
.menu
= False
;
1238 functions
.resize
= functions
.move
= functions
.iconify
=
1239 functions
.maximize
= False
;
1244 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
=
1245 functions
.move
= functions
.iconify
= True
;
1246 decorations
.border
= decorations
.handle
= decorations
.maximize
=
1247 functions
.resize
= functions
.maximize
= False
;
1252 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
1253 decorations
.iconify
= decorations
.border
= decorations
.handle
=
1254 decorations
.maximize
= functions
.resize
= functions
.maximize
=
1255 functions
.iconify
= False
;
1261 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1262 decorations
.iconify
= decorations
.maximize
=
1263 decorations
.menu
= True
;
1264 functions
.resize
= functions
.move
= functions
.iconify
=
1265 functions
.maximize
= True
;
1275 void OpenboxWindow::configure(int dx
, int dy
,
1276 unsigned int dw
, unsigned int dh
) {
1277 Bool send_event
= (frame
.x
!= dx
|| frame
.y
!= dy
);
1279 if ((dw
!= frame
.width
) || (dh
!= frame
.height
)) {
1280 if ((((signed) frame
.width
) + dx
) < 0) dx
= 0;
1281 if ((((signed) frame
.height
) + dy
) < 0) dy
= 0;
1291 if (openbox
->hasShapeExtensions() && flags
.shaped
) {
1292 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
1293 frame
.mwm_border_w
, frame
.y_border
+
1294 frame
.mwm_border_w
, client
.window
,
1295 ShapeBounding
, ShapeSet
);
1298 XRectangle xrect
[2];
1299 xrect
[0].x
= xrect
[0].y
= 0;
1300 xrect
[0].width
= frame
.width
;
1301 xrect
[0].height
= frame
.y_border
;
1303 if (decorations
.handle
) {
1305 xrect
[1].y
= frame
.y_handle
;
1306 xrect
[1].width
= frame
.width
;
1307 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
1311 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
1312 xrect
, num
, ShapeUnion
, Unsorted
);
1316 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1320 setFocusFlag(flags
.focused
);
1326 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1328 if (! flags
.moving
) send_event
= True
;
1331 if (send_event
&& ! flags
.moving
) {
1332 client
.x
= dx
+ frame
.mwm_border_w
+ frame
.border_w
;
1333 client
.y
= dy
+ frame
.y_border
+ frame
.mwm_border_w
+
1337 event
.type
= ConfigureNotify
;
1339 event
.xconfigure
.display
= display
;
1340 event
.xconfigure
.event
= client
.window
;
1341 event
.xconfigure
.window
= client
.window
;
1342 event
.xconfigure
.x
= client
.x
;
1343 event
.xconfigure
.y
= client
.y
;
1344 event
.xconfigure
.width
= client
.width
;
1345 event
.xconfigure
.height
= client
.height
;
1346 event
.xconfigure
.border_width
= client
.old_bw
;
1347 event
.xconfigure
.above
= frame
.window
;
1348 event
.xconfigure
.override_redirect
= False
;
1350 XSendEvent(display
, client
.window
, True
, NoEventMask
, &event
);
1352 screen
->updateNetizenConfigNotify(&event
);
1357 Bool
OpenboxWindow::setInputFocus(void) {
1358 if (((signed) (frame
.x
+ frame
.width
)) < 0) {
1359 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1360 configure(frame
.border_w
, frame
.border_w
, frame
.width
, frame
.height
);
1361 else if (frame
.y
> (signed) screen
->getHeight())
1362 configure(frame
.border_w
, screen
->getHeight() - frame
.height
,
1363 frame
.width
, frame
.height
);
1365 configure(frame
.border_w
, frame
.y
+ frame
.border_w
,
1366 frame
.width
, frame
.height
);
1367 } else if (frame
.x
> (signed) screen
->getWidth()) {
1368 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1369 configure(screen
->getWidth() - frame
.width
, frame
.border_w
,
1370 frame
.width
, frame
.height
);
1371 else if (frame
.y
> (signed) screen
->getHeight())
1372 configure(screen
->getWidth() - frame
.width
,
1373 screen
->getHeight() - frame
.height
, frame
.width
, frame
.height
);
1375 configure(screen
->getWidth() - frame
.width
,
1376 frame
.y
+ frame
.border_w
, frame
.width
, frame
.height
);
1380 if (! validateClient()) return False
;
1384 if (client
.transient
&& flags
.modal
) {
1385 ret
= client
.transient
->setInputFocus();
1386 } else if (! flags
.focused
) {
1387 if (focus_mode
== F_LocallyActive
|| focus_mode
== F_Passive
)
1388 XSetInputFocus(display
, client
.window
,
1389 RevertToPointerRoot
, CurrentTime
);
1391 XSetInputFocus(display
, screen
->getRootWindow(),
1392 RevertToNone
, CurrentTime
);
1394 openbox
->setFocusedWindow(this);
1396 if (flags
.send_focus_message
) {
1398 ce
.xclient
.type
= ClientMessage
;
1399 ce
.xclient
.message_type
= openbox
->getWMProtocolsAtom();
1400 ce
.xclient
.display
= display
;
1401 ce
.xclient
.window
= client
.window
;
1402 ce
.xclient
.format
= 32;
1403 ce
.xclient
.data
.l
[0] = openbox
->getWMTakeFocusAtom();
1404 ce
.xclient
.data
.l
[1] = openbox
->getLastTime();
1405 ce
.xclient
.data
.l
[2] = 0l;
1406 ce
.xclient
.data
.l
[3] = 0l;
1407 ce
.xclient
.data
.l
[4] = 0l;
1408 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1411 if (screen
->isSloppyFocus() && screen
->doAutoRaise())
1423 void OpenboxWindow::iconify(void) {
1424 if (flags
.iconic
) return;
1426 if (windowmenu
) windowmenu
->hide();
1428 setState(IconicState
);
1430 XSelectInput(display
, client
.window
, NoEventMask
);
1431 XUnmapWindow(display
, client
.window
);
1432 XSelectInput(display
, client
.window
,
1433 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1435 XUnmapWindow(display
, frame
.window
);
1436 flags
.visible
= False
;
1437 flags
.iconic
= True
;
1439 screen
->getWorkspace(workspace_number
)->removeWindow(this);
1441 if (flags
.transient
&& client
.transient_for
&&
1442 !client
.transient_for
->flags
.iconic
) {
1443 client
.transient_for
->iconify();
1445 screen
->addIcon(this);
1447 if (client
.transient
&& !client
.transient
->flags
.iconic
) {
1448 client
.transient
->iconify();
1453 void OpenboxWindow::deiconify(Bool reassoc
, Bool raise
) {
1454 if (flags
.iconic
|| reassoc
)
1455 screen
->reassociateWindow(this, -1, False
);
1456 else if (workspace_number
!= screen
->getCurrentWorkspace()->getWorkspaceID())
1459 setState(NormalState
);
1461 XSelectInput(display
, client
.window
, NoEventMask
);
1462 XMapWindow(display
, client
.window
);
1463 XSelectInput(display
, client
.window
,
1464 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1466 XMapSubwindows(display
, frame
.window
);
1467 XMapWindow(display
, frame
.window
);
1469 if (flags
.iconic
&& screen
->doFocusNew()) setInputFocus();
1471 flags
.visible
= True
;
1472 flags
.iconic
= False
;
1474 if (reassoc
&& client
.transient
) client
.transient
->deiconify(True
, False
);
1477 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1481 void OpenboxWindow::close(void) {
1483 ce
.xclient
.type
= ClientMessage
;
1484 ce
.xclient
.message_type
= openbox
->getWMProtocolsAtom();
1485 ce
.xclient
.display
= display
;
1486 ce
.xclient
.window
= client
.window
;
1487 ce
.xclient
.format
= 32;
1488 ce
.xclient
.data
.l
[0] = openbox
->getWMDeleteAtom();
1489 ce
.xclient
.data
.l
[1] = CurrentTime
;
1490 ce
.xclient
.data
.l
[2] = 0l;
1491 ce
.xclient
.data
.l
[3] = 0l;
1492 ce
.xclient
.data
.l
[4] = 0l;
1493 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1497 void OpenboxWindow::withdraw(void) {
1498 flags
.visible
= False
;
1499 flags
.iconic
= False
;
1501 XUnmapWindow(display
, frame
.window
);
1503 XSelectInput(display
, client
.window
, NoEventMask
);
1504 XUnmapWindow(display
, client
.window
);
1505 XSelectInput(display
, client
.window
,
1506 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1508 if (windowmenu
) windowmenu
->hide();
1512 void OpenboxWindow::maximize(unsigned int button
) {
1513 // handle case where menu is open then the max button is used instead
1514 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
1516 if (flags
.maximized
) {
1517 flags
.maximized
= 0;
1519 openbox_attrib
.flags
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1520 openbox_attrib
.attrib
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1522 // when a resize is begun, maximize(0) is called to clear any maximization
1523 // flags currently set. Otherwise it still thinks it is maximized.
1524 // so we do not need to call configure() because resizing will handle it
1525 if (!flags
.resizing
)
1526 configure(openbox_attrib
.premax_x
, openbox_attrib
.premax_y
,
1527 openbox_attrib
.premax_w
, openbox_attrib
.premax_h
);
1529 openbox_attrib
.premax_x
= openbox_attrib
.premax_y
= 0;
1530 openbox_attrib
.premax_w
= openbox_attrib
.premax_h
= 0;
1533 setState(current_state
);
1538 unsigned int dw
, dh
;
1540 openbox_attrib
.premax_x
= frame
.x
;
1541 openbox_attrib
.premax_y
= frame
.y
;
1542 openbox_attrib
.premax_w
= frame
.width
;
1543 openbox_attrib
.premax_h
= frame
.height
;
1545 dw
= screen
->getWidth();
1546 dw
-= frame
.border_w
* 2;
1547 dw
-= frame
.mwm_border_w
* 2;
1548 dw
-= client
.base_width
;
1550 dh
= screen
->getHeight();
1551 dh
-= frame
.border_w
* 2;
1552 dh
-= frame
.mwm_border_w
* 2;
1553 dh
-= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1554 dh
-= client
.base_height
;
1555 dh
-= frame
.y_border
;
1557 if (! screen
->doFullMax())
1558 dh
-= screen
->getToolbar()->getExposedHeight() + frame
.border_w
;
1560 if (dw
< client
.min_width
) dw
= client
.min_width
;
1561 if (dh
< client
.min_height
) dh
= client
.min_height
;
1562 if (dw
> client
.max_width
) dw
= client
.max_width
;
1563 if (dh
> client
.max_height
) dh
= client
.max_height
;
1565 dw
-= (dw
% client
.width_inc
);
1566 dw
+= client
.base_width
;
1567 dw
+= frame
.mwm_border_w
* 2;
1569 dh
-= (dh
% client
.height_inc
);
1570 dh
+= client
.base_height
;
1571 dh
+= frame
.y_border
;
1572 dh
+= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1573 dh
+= frame
.mwm_border_w
* 2;
1575 dx
+= ((screen
->getWidth() - dw
) / 2) - frame
.border_w
;
1577 if (screen
->doFullMax()) {
1578 dy
+= ((screen
->getHeight() - dh
) / 2) - frame
.border_w
;
1580 dy
+= (((screen
->getHeight() - screen
->getToolbar()->getExposedHeight())
1581 - dh
) / 2) - frame
.border_w
;
1583 switch (screen
->getToolbarPlacement()) {
1584 case Toolbar::TopLeft
:
1585 case Toolbar::TopCenter
:
1586 case Toolbar::TopRight
:
1587 dy
+= screen
->getToolbar()->getExposedHeight() +
1595 openbox_attrib
.flags
|= AttribMaxHoriz
| AttribMaxVert
;
1596 openbox_attrib
.attrib
|= AttribMaxHoriz
| AttribMaxVert
;
1600 openbox_attrib
.flags
|= AttribMaxVert
;
1601 openbox_attrib
.attrib
|= AttribMaxVert
;
1608 openbox_attrib
.flags
|= AttribMaxHoriz
;
1609 openbox_attrib
.attrib
|= AttribMaxHoriz
;
1617 openbox_attrib
.flags
^= AttribShaded
;
1618 openbox_attrib
.attrib
^= AttribShaded
;
1619 flags
.shaded
= False
;
1622 flags
.maximized
= button
;
1624 configure(dx
, dy
, dw
, dh
);
1625 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1627 setState(current_state
);
1631 void OpenboxWindow::setWorkspace(int n
) {
1632 workspace_number
= n
;
1634 openbox_attrib
.flags
|= AttribWorkspace
;
1635 openbox_attrib
.workspace
= workspace_number
;
1639 void OpenboxWindow::shade(void) {
1640 if (!decorations
.titlebar
)
1644 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.height
);
1645 flags
.shaded
= False
;
1646 openbox_attrib
.flags
^= AttribShaded
;
1647 openbox_attrib
.attrib
^= AttribShaded
;
1649 setState(NormalState
);
1651 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.title_h
);
1652 flags
.shaded
= True
;
1653 openbox_attrib
.flags
|= AttribShaded
;
1654 openbox_attrib
.attrib
|= AttribShaded
;
1656 setState(IconicState
);
1661 void OpenboxWindow::stick(void) {
1663 openbox_attrib
.flags
^= AttribOmnipresent
;
1664 openbox_attrib
.attrib
^= AttribOmnipresent
;
1666 flags
.stuck
= False
;
1669 screen
->reassociateWindow(this, -1, True
);
1671 setState(current_state
);
1675 openbox_attrib
.flags
|= AttribOmnipresent
;
1676 openbox_attrib
.attrib
|= AttribOmnipresent
;
1678 setState(current_state
);
1683 void OpenboxWindow::setFocusFlag(Bool focus
) {
1684 flags
.focused
= focus
;
1686 if (decorations
.titlebar
) {
1687 if (flags
.focused
) {
1689 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.ftitle
);
1691 XSetWindowBackground(display
, frame
.title
, frame
.ftitle_pixel
);
1694 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.utitle
);
1696 XSetWindowBackground(display
, frame
.title
, frame
.utitle_pixel
);
1698 XClearWindow(display
, frame
.title
);
1704 if (decorations
.handle
) {
1705 if (flags
.focused
) {
1707 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.fhandle
);
1709 XSetWindowBackground(display
, frame
.handle
, frame
.fhandle_pixel
);
1712 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.fgrip
);
1713 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.fgrip
);
1715 XSetWindowBackground(display
, frame
.right_grip
, frame
.fgrip_pixel
);
1716 XSetWindowBackground(display
, frame
.left_grip
, frame
.fgrip_pixel
);
1720 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.uhandle
);
1722 XSetWindowBackground(display
, frame
.handle
, frame
.uhandle_pixel
);
1725 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.ugrip
);
1726 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.ugrip
);
1728 XSetWindowBackground(display
, frame
.right_grip
, frame
.ugrip_pixel
);
1729 XSetWindowBackground(display
, frame
.left_grip
, frame
.ugrip_pixel
);
1732 XClearWindow(display
, frame
.handle
);
1733 XClearWindow(display
, frame
.right_grip
);
1734 XClearWindow(display
, frame
.left_grip
);
1737 if (decorations
.border
) {
1739 XSetWindowBorder(display
, frame
.plate
, frame
.fborder_pixel
);
1741 XSetWindowBorder(display
, frame
.plate
, frame
.uborder_pixel
);
1744 if (screen
->isSloppyFocus() && screen
->doAutoRaise() && timer
->isTiming())
1749 void OpenboxWindow::installColormap(Bool install
) {
1751 if (! validateClient()) return;
1753 int i
= 0, ncmap
= 0;
1754 Colormap
*cmaps
= XListInstalledColormaps(display
, client
.window
, &ncmap
);
1755 XWindowAttributes wattrib
;
1757 if (XGetWindowAttributes(display
, client
.window
, &wattrib
)) {
1759 // install the window's colormap
1760 for (i
= 0; i
< ncmap
; i
++) {
1761 if (*(cmaps
+ i
) == wattrib
.colormap
)
1762 // this window is using an installed color map... do not install
1765 // otherwise, install the window's colormap
1767 XInstallColormap(display
, wattrib
.colormap
);
1769 // uninstall the window's colormap
1770 for (i
= 0; i
< ncmap
; i
++) {
1771 if (*(cmaps
+ i
) == wattrib
.colormap
)
1772 // we found the colormap to uninstall
1773 XUninstallColormap(display
, wattrib
.colormap
);
1785 void OpenboxWindow::setState(unsigned long new_state
) {
1786 current_state
= new_state
;
1788 unsigned long state
[2];
1789 state
[0] = (unsigned long) current_state
;
1790 state
[1] = (unsigned long) None
;
1791 XChangeProperty(display
, client
.window
, openbox
->getWMStateAtom(),
1792 openbox
->getWMStateAtom(), 32, PropModeReplace
,
1793 (unsigned char *) state
, 2);
1795 XChangeProperty(display
, client
.window
,
1796 openbox
->getOpenboxAttributesAtom(),
1797 openbox
->getOpenboxAttributesAtom(), 32, PropModeReplace
,
1798 (unsigned char *) &openbox_attrib
,
1799 PropOpenboxAttributesElements
);
1803 Bool
OpenboxWindow::getState(void) {
1809 unsigned long *state
, ulfoo
, nitems
;
1811 if ((XGetWindowProperty(display
, client
.window
, openbox
->getWMStateAtom(),
1812 0l, 2l, False
, openbox
->getWMStateAtom(),
1813 &atom_return
, &foo
, &nitems
, &ulfoo
,
1814 (unsigned char **) &state
) != Success
) ||
1821 current_state
= (unsigned long) state
[0];
1826 XFree((void *) state
);
1832 void OpenboxWindow::setGravityOffsets(void) {
1833 // x coordinates for each gravity type
1834 const int x_west
= client
.x
;
1835 const int x_east
= client
.x
+ client
.width
- frame
.width
;
1836 const int x_center
= client
.x
+ client
.width
- frame
.width
/2;
1837 // y coordinates for each gravity type
1838 const int y_north
= client
.y
;
1839 const int y_south
= client
.y
+ client
.height
- frame
.height
;
1840 const int y_center
= client
.y
+ client
.height
- frame
.height
/2;
1842 switch (client
.win_gravity
) {
1843 case NorthWestGravity
:
1852 case NorthEastGravity
:
1856 case SouthWestGravity
:
1864 case SouthEastGravity
:
1882 frame
.x
= client
.x
- frame
.mwm_border_w
+ frame
.border_w
;
1883 frame
.y
= client
.y
- frame
.y_border
- frame
.mwm_border_w
- frame
.border_w
;
1889 void OpenboxWindow::restoreAttributes(void) {
1890 if (! getState()) current_state
= NormalState
;
1894 unsigned long ulfoo
, nitems
;
1896 OpenboxAttributes
*net
;
1897 int ret
= XGetWindowProperty(display
, client
.window
,
1898 openbox
->getOpenboxAttributesAtom(), 0l,
1899 PropOpenboxAttributesElements
, False
,
1900 openbox
->getOpenboxAttributesAtom(),
1901 &atom_return
, &foo
, &nitems
, &ulfoo
,
1902 (unsigned char **) &net
);
1903 if (ret
!= Success
|| !net
|| nitems
!= PropOpenboxAttributesElements
)
1906 openbox_attrib
.flags
= net
->flags
;
1907 openbox_attrib
.attrib
= net
->attrib
;
1908 openbox_attrib
.decoration
= net
->decoration
;
1909 openbox_attrib
.workspace
= net
->workspace
;
1910 openbox_attrib
.stack
= net
->stack
;
1911 openbox_attrib
.premax_x
= net
->premax_x
;
1912 openbox_attrib
.premax_y
= net
->premax_y
;
1913 openbox_attrib
.premax_w
= net
->premax_w
;
1914 openbox_attrib
.premax_h
= net
->premax_h
;
1916 XFree((void *) net
);
1918 if (openbox_attrib
.flags
& AttribShaded
&&
1919 openbox_attrib
.attrib
& AttribShaded
) {
1921 ((current_state
== IconicState
) ? NormalState
: current_state
);
1923 flags
.shaded
= False
;
1926 current_state
= save_state
;
1929 if (((int) openbox_attrib
.workspace
!= screen
->getCurrentWorkspaceID()) &&
1930 ((int) openbox_attrib
.workspace
< screen
->getWorkspaceCount())) {
1931 screen
->reassociateWindow(this, openbox_attrib
.workspace
, True
);
1933 if (current_state
== NormalState
) current_state
= WithdrawnState
;
1934 } else if (current_state
== WithdrawnState
) {
1935 current_state
= NormalState
;
1938 if (openbox_attrib
.flags
& AttribOmnipresent
&&
1939 openbox_attrib
.attrib
& AttribOmnipresent
) {
1940 flags
.stuck
= False
;
1943 current_state
= NormalState
;
1946 if ((openbox_attrib
.flags
& AttribMaxHoriz
) ||
1947 (openbox_attrib
.flags
& AttribMaxVert
)) {
1948 int x
= openbox_attrib
.premax_x
, y
= openbox_attrib
.premax_y
;
1949 unsigned int w
= openbox_attrib
.premax_w
, h
= openbox_attrib
.premax_h
;
1950 flags
.maximized
= 0;
1952 unsigned int m
= False
;
1953 if ((openbox_attrib
.flags
& AttribMaxHoriz
) &&
1954 (openbox_attrib
.flags
& AttribMaxVert
))
1955 m
= (openbox_attrib
.attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1956 else if (openbox_attrib
.flags
& AttribMaxVert
)
1957 m
= (openbox_attrib
.attrib
& AttribMaxVert
) ? 2 : 0;
1958 else if (openbox_attrib
.flags
& AttribMaxHoriz
)
1959 m
= (openbox_attrib
.attrib
& AttribMaxHoriz
) ? 3 : 0;
1963 openbox_attrib
.premax_x
= x
;
1964 openbox_attrib
.premax_y
= y
;
1965 openbox_attrib
.premax_w
= w
;
1966 openbox_attrib
.premax_h
= h
;
1969 setState(current_state
);
1974 * The reverse of the setGravityOffsets function. Uses the frame window's
1975 * position to find the window's reference point.
1977 void OpenboxWindow::restoreGravity(void) {
1978 // x coordinates for each gravity type
1979 const int x_west
= frame
.x
;
1980 const int x_east
= frame
.x
+ frame
.width
- client
.width
;
1981 const int x_center
= frame
.x
+ (frame
.width
/2) - client
.width
;
1982 // y coordinates for each gravity type
1983 const int y_north
= frame
.y
;
1984 const int y_south
= frame
.y
+ frame
.height
- client
.height
;
1985 const int y_center
= frame
.y
+ (frame
.height
/2) - client
.height
;
1987 switch(client
.win_gravity
) {
1989 case NorthWestGravity
:
1994 client
.x
= x_center
;
1997 case NorthEastGravity
:
2001 case SouthWestGravity
:
2006 client
.x
= x_center
;
2009 case SouthEastGravity
:
2015 client
.y
= y_center
;
2019 client
.y
= y_center
;
2022 client
.x
= x_center
;
2023 client
.y
= y_center
;
2027 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
2028 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
2035 void OpenboxWindow::redrawLabel(void) {
2036 int dx
= frame
.bevel_w
* 2, dlen
= client
.title_len
;
2037 unsigned int l
= client
.title_text_w
;
2039 if (flags
.focused
) {
2041 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.flabel
);
2043 XSetWindowBackground(display
, frame
.label
, frame
.flabel_pixel
);
2046 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.ulabel
);
2048 XSetWindowBackground(display
, frame
.label
, frame
.ulabel_pixel
);
2050 XClearWindow(display
, frame
.label
);
2052 if (client
.title_text_w
> frame
.label_w
) {
2053 for (; dlen
>= 0; dlen
--) {
2054 if (i18n
->multibyte()) {
2055 XRectangle ink
, logical
;
2056 XmbTextExtents(screen
->getWindowStyle()->fontset
, client
.title
, dlen
,
2060 l
= XTextWidth(screen
->getWindowStyle()->font
, client
.title
, dlen
);
2062 l
+= (frame
.bevel_w
* 4);
2064 if (l
< frame
.label_w
)
2069 switch (screen
->getWindowStyle()->justify
) {
2070 case BScreen::RightJustify
:
2071 dx
+= frame
.label_w
- l
;
2074 case BScreen::CenterJustify
:
2075 dx
+= (frame
.label_w
- l
) / 2;
2079 WindowStyle
*style
= screen
->getWindowStyle();
2080 GC text_gc
= (flags
.focused
) ? style
->l_text_focus_gc
:
2081 style
->l_text_unfocus_gc
;
2082 if (i18n
->multibyte())
2083 XmbDrawString(display
, frame
.label
, style
->fontset
, text_gc
, dx
,
2084 (1 - style
->fontset_extents
->max_ink_extent
.y
),
2085 client
.title
, dlen
);
2087 XDrawString(display
, frame
.label
, text_gc
, dx
,
2088 (style
->font
->ascent
+ 1), client
.title
, dlen
);
2092 void OpenboxWindow::redrawAllButtons(void) {
2093 if (frame
.iconify_button
) redrawIconifyButton(False
);
2094 if (frame
.maximize_button
) redrawMaximizeButton(flags
.maximized
);
2095 if (frame
.close_button
) redrawCloseButton(False
);
2099 void OpenboxWindow::redrawIconifyButton(Bool pressed
) {
2101 if (flags
.focused
) {
2103 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2106 XSetWindowBackground(display
, frame
.iconify_button
,
2107 frame
.fbutton_pixel
);
2110 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2113 XSetWindowBackground(display
, frame
.iconify_button
,
2114 frame
.ubutton_pixel
);
2118 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.pbutton
);
2120 XSetWindowBackground(display
, frame
.iconify_button
, frame
.pbutton_pixel
);
2122 XClearWindow(display
, frame
.iconify_button
);
2124 XDrawRectangle(display
, frame
.iconify_button
,
2125 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2126 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2127 2, (frame
.button_h
- 5), (frame
.button_w
- 5), 2);
2131 void OpenboxWindow::redrawMaximizeButton(Bool pressed
) {
2133 if (flags
.focused
) {
2135 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2138 XSetWindowBackground(display
, frame
.maximize_button
,
2139 frame
.fbutton_pixel
);
2142 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2145 XSetWindowBackground(display
, frame
.maximize_button
,
2146 frame
.ubutton_pixel
);
2150 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2153 XSetWindowBackground(display
, frame
.maximize_button
,
2154 frame
.pbutton_pixel
);
2156 XClearWindow(display
, frame
.maximize_button
);
2158 XDrawRectangle(display
, frame
.maximize_button
,
2159 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2160 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2161 2, 2, (frame
.button_w
- 5), (frame
.button_h
- 5));
2162 XDrawLine(display
, frame
.maximize_button
,
2163 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2164 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2165 2, 3, (frame
.button_w
- 3), 3);
2169 void OpenboxWindow::redrawCloseButton(Bool pressed
) {
2171 if (flags
.focused
) {
2173 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2176 XSetWindowBackground(display
, frame
.close_button
,
2177 frame
.fbutton_pixel
);
2180 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2183 XSetWindowBackground(display
, frame
.close_button
,
2184 frame
.ubutton_pixel
);
2188 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.pbutton
);
2190 XSetWindowBackground(display
, frame
.close_button
, frame
.pbutton_pixel
);
2192 XClearWindow(display
, frame
.close_button
);
2194 XDrawLine(display
, frame
.close_button
,
2195 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2196 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2, 2,
2197 (frame
.button_w
- 3), (frame
.button_h
- 3));
2198 XDrawLine(display
, frame
.close_button
,
2199 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2200 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2,
2201 (frame
.button_h
- 3),
2202 (frame
.button_w
- 3), 2);
2206 void OpenboxWindow::mapRequestEvent(XMapRequestEvent
*re
) {
2207 if (re
->window
== client
.window
) {
2209 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowMapRequest
,
2210 "OpenboxWindow::mapRequestEvent() for 0x%lx\n"),
2215 if (! validateClient()) return;
2217 Bool get_state_ret
= getState();
2218 if (! (get_state_ret
&& openbox
->isStartup())) {
2219 if ((client
.wm_hint_flags
& StateHint
) &&
2220 (! (current_state
== NormalState
|| current_state
== IconicState
)))
2221 current_state
= client
.initial_state
;
2223 current_state
= NormalState
;
2224 } else if (flags
.iconic
) {
2225 current_state
= NormalState
;
2228 switch (current_state
) {
2233 case WithdrawnState
:
2250 void OpenboxWindow::mapNotifyEvent(XMapEvent
*ne
) {
2251 if ((ne
->window
== client
.window
) && (! ne
->override_redirect
)
2252 && (flags
.visible
)) {
2254 if (! validateClient()) return;
2256 if (decorations
.titlebar
) positionButtons();
2258 setState(NormalState
);
2262 if (flags
.transient
|| screen
->doFocusNew())
2265 setFocusFlag(False
);
2267 flags
.visible
= True
;
2268 flags
.iconic
= False
;
2275 void OpenboxWindow::unmapNotifyEvent(XUnmapEvent
*ue
) {
2276 if (ue
->window
== client
.window
) {
2278 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotify
,
2279 "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"),
2284 if (! validateClient()) return;
2286 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
2287 XSelectInput(display
, client
.window
, NoEventMask
);
2289 XDeleteProperty(display
, client
.window
, openbox
->getWMStateAtom());
2290 XDeleteProperty(display
, client
.window
,
2291 openbox
->getOpenboxAttributesAtom());
2293 XUnmapWindow(display
, frame
.window
);
2294 XUnmapWindow(display
, client
.window
);
2297 if (! XCheckTypedWindowEvent(display
, client
.window
, ReparentNotify
,
2300 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotifyReparent
,
2301 "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to "
2302 "root.\n"), client
.window
);
2306 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
2307 client
.x
, client
.y
);
2319 void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent
*de
) {
2320 if (de
->window
== client
.window
) {
2321 XUnmapWindow(display
, frame
.window
);
2328 void OpenboxWindow::propertyNotifyEvent(Atom atom
) {
2330 if (! validateClient()) return;
2334 case XA_WM_CLIENT_MACHINE
:
2338 case XA_WM_TRANSIENT_FOR
:
2339 // determine if this is a transient window
2341 if (XGetTransientForHint(display
, client
.window
, &win
)) {
2342 if (win
&& (win
!= client
.window
)) {
2343 if ((client
.transient_for
= openbox
->searchWindow(win
))) {
2344 client
.transient_for
->client
.transient
= this;
2345 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2346 flags
.transient
= True
;
2347 } else if (win
== client
.window_group
) {
2348 //jr This doesn't look quite right...
2349 if ((client
.transient_for
= openbox
->searchGroup(win
, this))) {
2350 client
.transient_for
->client
.transient
= this;
2351 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2352 flags
.transient
= True
;
2357 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
2360 // adjust the window decorations based on transience
2361 if (flags
.transient
)
2362 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
2372 case XA_WM_ICON_NAME
:
2374 if (flags
.iconic
) screen
->iconUpdate();
2380 if (decorations
.titlebar
)
2384 screen
->getWorkspace(workspace_number
)->update();
2388 case XA_WM_NORMAL_HINTS
: {
2391 if ((client
.normal_hint_flags
& PMinSize
) &&
2392 (client
.normal_hint_flags
& PMaxSize
)) {
2393 if (client
.max_width
<= client
.min_width
&&
2394 client
.max_height
<= client
.min_height
)
2395 decorations
.maximize
= decorations
.handle
=
2396 functions
.resize
= functions
.maximize
= False
;
2398 decorations
.maximize
= decorations
.handle
=
2399 functions
.resize
= functions
.maximize
= True
;
2402 int x
= frame
.x
, y
= frame
.y
;
2403 unsigned int w
= frame
.width
, h
= frame
.height
;
2407 if ((x
!= frame
.x
) || (y
!= frame
.y
) ||
2408 (w
!= frame
.width
) || (h
!= frame
.height
))
2415 if (atom
== openbox
->getWMProtocolsAtom()) {
2418 if (decorations
.close
&& (! frame
.close_button
)) {
2419 createCloseButton();
2420 if (decorations
.titlebar
) positionButtons(True
);
2421 if (windowmenu
) windowmenu
->reconfigure();
2432 void OpenboxWindow::exposeEvent(XExposeEvent
*ee
) {
2433 if (frame
.label
== ee
->window
&& decorations
.titlebar
)
2435 else if (frame
.close_button
== ee
->window
)
2436 redrawCloseButton(False
);
2437 else if (frame
.maximize_button
== ee
->window
)
2438 redrawMaximizeButton(flags
.maximized
);
2439 else if (frame
.iconify_button
== ee
->window
)
2440 redrawIconifyButton(False
);
2444 void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent
*cr
) {
2445 if (cr
->window
== client
.window
) {
2447 if (! validateClient()) return;
2449 int cx
= frame
.x
, cy
= frame
.y
;
2450 unsigned int cw
= frame
.width
, ch
= frame
.height
;
2452 if (cr
->value_mask
& CWBorderWidth
)
2453 client
.old_bw
= cr
->border_width
;
2455 if (cr
->value_mask
& CWX
)
2456 cx
= cr
->x
- frame
.mwm_border_w
- frame
.border_w
;
2458 if (cr
->value_mask
& CWY
)
2459 cy
= cr
->y
- frame
.y_border
- frame
.mwm_border_w
-
2462 if (cr
->value_mask
& CWWidth
)
2463 cw
= cr
->width
+ (frame
.mwm_border_w
* 2);
2465 if (cr
->value_mask
& CWHeight
)
2466 ch
= cr
->height
+ frame
.y_border
+ (frame
.mwm_border_w
* 2) +
2467 (frame
.border_w
* decorations
.handle
) + frame
.handle_h
;
2469 if (frame
.x
!= cx
|| frame
.y
!= cy
||
2470 frame
.width
!= cw
|| frame
.height
!= ch
)
2471 configure(cx
, cy
, cw
, ch
);
2473 if (cr
->value_mask
& CWStackMode
) {
2474 switch (cr
->detail
) {
2478 if (flags
.iconic
) deiconify();
2479 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2484 if (flags
.iconic
) deiconify();
2485 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2495 void OpenboxWindow::buttonPressEvent(XButtonEvent
*be
) {
2497 if (! validateClient())
2500 int stack_change
= 1; // < 0 means to lower the window
2501 // > 0 means to raise the window
2502 // 0 means to leave it where it is
2504 // alt + left/right click begins interactively moving/resizing the window
2505 // when the mouse is moved
2506 if (be
->state
== Mod1Mask
&& (be
->button
== 1 || be
->button
== 3)) {
2507 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2508 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2509 if (be
->button
== 3) {
2510 if (screen
->getWindowZones() == 4 &&
2511 be
->y
< (signed) frame
.height
/ 2) {
2512 resize_zone
= ZoneTop
;
2514 resize_zone
= ZoneBottom
;
2516 if (screen
->getWindowZones() >= 2 &&
2517 be
->x
< (signed) frame
.width
/ 2) {
2518 resize_zone
|= ZoneLeft
;
2520 resize_zone
|= ZoneRight
;
2523 // control + left click on the titlebar shades the window
2524 } else if (be
->state
== ControlMask
&& be
->button
== 1) {
2525 if (be
->window
== frame
.title
||
2526 be
->window
== frame
.label
)
2529 } else if (be
->state
== 0 && be
->button
== 1) {
2530 if (windowmenu
&& windowmenu
->isVisible())
2533 if (be
->window
== frame
.maximize_button
) {
2534 redrawMaximizeButton(True
);
2535 } else if (be
->window
== frame
.iconify_button
) {
2536 redrawIconifyButton(True
);
2537 } else if (be
->window
== frame
.close_button
) {
2538 redrawCloseButton(True
);
2539 } else if (be
->window
== frame
.plate
) {
2540 XAllowEvents(display
, ReplayPointer
, be
->time
);
2541 } else if (be
->window
== frame
.title
||
2542 be
->window
== frame
.label
) {
2543 // shade the window when the titlebar is double clicked
2544 if ( (be
->time
- lastButtonPressTime
) <=
2545 openbox
->getDoubleClickInterval()) {
2546 lastButtonPressTime
= 0;
2549 lastButtonPressTime
= be
->time
;
2551 // clicking and dragging on the titlebar moves the window, so on a click
2552 // we need to save the coords of the click in case the user drags
2553 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2554 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2555 } else if (be
->window
== frame
.handle
||
2556 be
->window
== frame
.left_grip
||
2557 be
->window
== frame
.right_grip
||
2558 be
->window
== frame
.window
) {
2559 // clicking and dragging on the window's frame moves the window, so on a
2560 // click we need to save the coords of the click in case the user drags
2561 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2562 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2563 if (be
->window
== frame
.left_grip
)
2564 resize_zone
= ZoneBottom
| ZoneLeft
;
2565 else if (be
->window
== frame
.right_grip
)
2566 resize_zone
= ZoneBottom
| ZoneRight
;
2569 } else if (be
->state
== 0 && be
->button
== 2) {
2570 if (be
->window
== frame
.maximize_button
) {
2571 redrawMaximizeButton(True
);
2572 // a middle click anywhere on the window's frame except for on the buttons
2573 // will lower the window
2574 } else if (! (be
->window
== frame
.iconify_button
||
2575 be
->window
== frame
.close_button
) ) {
2579 } else if (be
->state
== 0 && be
->button
== 3) {
2580 if (be
->window
== frame
.maximize_button
) {
2581 redrawMaximizeButton(True
);
2582 // a right click on the window's frame will show or hide the window's
2584 } else if (be
->window
== frame
.title
||
2585 be
->window
== frame
.label
||
2586 be
->window
== frame
.handle
||
2587 be
->window
== frame
.window
) {
2590 if (windowmenu
->isVisible()) {
2593 // get the coords for the menu
2594 mx
= be
->x_root
- windowmenu
->getWidth() / 2;
2595 if (be
->window
== frame
.title
|| be
->window
== frame
.label
) {
2596 my
= frame
.y
+ frame
.title_h
;
2597 } else if (be
->window
= frame
.handle
) {
2598 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2599 } else { // (be->window == frame.window)
2600 if (be
->y
<= (signed) frame
.bevel_w
) {
2601 my
= frame
.y
+ frame
.y_border
;
2603 my
= be
->y_root
- (windowmenu
->getHeight() / 2);
2607 if (mx
> (signed) (frame
.x
+ frame
.width
-
2608 windowmenu
->getWidth())) {
2609 mx
= frame
.x
+ frame
.width
- windowmenu
->getWidth();
2610 } else if (mx
< frame
.x
) {
2614 if (my
> (signed) (frame
.y
+ frame
.y_handle
-
2615 windowmenu
->getHeight())) {
2616 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2617 } else if (my
< (signed) (frame
.y
+
2618 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
))) {
2620 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
);
2623 windowmenu
->move(mx
, my
);
2625 XRaiseWindow(display
, windowmenu
->getWindowID());
2626 XRaiseWindow(display
, windowmenu
->getSendToMenu()->getWindowID());
2627 stack_change
= 0; // dont raise the window overtop of the menu
2632 } else if (be
->state
== 0 && be
->button
== 4) {
2633 if ((be
->window
== frame
.label
||
2634 be
->window
== frame
.title
) &&
2638 } else if (be
->state
== 0 && be
->button
== 5) {
2639 if ((be
->window
== frame
.label
||
2640 be
->window
== frame
.title
) &&
2645 if (! (flags
.focused
|| screen
->isSloppyFocus()) ) {
2646 setInputFocus(); // any click focus' the window in 'click to focus'
2648 if (stack_change
< 0) {
2649 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2650 } else if (stack_change
> 0) {
2651 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2658 void OpenboxWindow::buttonReleaseEvent(XButtonEvent
*re
) {
2660 if (! validateClient())
2663 // alt + middle button released
2664 if (re
->state
== (Mod1Mask
& Button2Mask
) && re
->button
== 2) {
2665 if (re
->window
== frame
.window
) {
2666 XUngrabPointer(display
, CurrentTime
); // why? i dont know
2668 // left button released
2669 } else if (re
->button
== 1) {
2670 if (re
->window
== frame
.maximize_button
) {
2671 if (re
->state
== Button1Mask
&& // only the left button was depressed
2672 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2673 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2674 maximize(re
->button
);
2676 redrawMaximizeButton(False
);
2678 } else if (re
->window
== frame
.iconify_button
) {
2679 if (re
->state
== Button1Mask
&& // only the left button was depressed
2680 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2681 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2684 redrawIconifyButton(False
);
2686 } else if (re
->window
== frame
.close_button
) {
2687 if (re
->state
== Button1Mask
&& // only the left button was depressed
2688 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2689 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2692 //we should always redraw the close button. some applications
2693 //eg. acroread don't honour the close.
2694 redrawCloseButton(False
);
2696 // middle button released
2697 } else if (re
->button
== 2) {
2698 if (re
->window
== frame
.maximize_button
) {
2699 if (re
->state
== Button2Mask
&& // only the middle button was depressed
2700 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2701 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2702 maximize(re
->button
);
2704 redrawMaximizeButton(False
);
2707 // right button released
2708 } else if (re
->button
== 3) {
2709 if (re
->window
== frame
.maximize_button
) {
2710 if (re
->state
== Button3Mask
&& // only the right button was depressed
2711 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2712 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2713 maximize(re
->button
);
2715 redrawMaximizeButton(False
);
2720 // when the window is being interactively moved, a button release stops the
2723 flags
.moving
= False
;
2725 openbox
->maskWindowEvents(0, (OpenboxWindow
*) 0);
2726 if (!screen
->doOpaqueMove()) {
2727 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2728 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2729 frame
.resize_h
- 1);
2731 configure(frame
.move_x
, frame
.move_y
, frame
.width
, frame
.height
);
2734 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
2736 screen
->hideGeometry();
2737 XUngrabPointer(display
, CurrentTime
);
2738 // when the window is being interactively resized, a button release stops the
2740 } else if (flags
.resizing
) {
2741 flags
.resizing
= False
;
2742 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2743 frame
.resize_x
, frame
.resize_y
,
2744 frame
.resize_w
- 1, frame
.resize_h
- 1);
2745 screen
->hideGeometry();
2746 if (resize_zone
& ZoneLeft
) {
2748 } else { // when resizing with "Alt+Button3", the resize is the same as if
2749 // done with the right grip (the right side of the window is what
2753 // unset maximized state when resized after fully maximized
2754 if (flags
.maximized
== 1) {
2757 configure(frame
.resize_x
, frame
.resize_y
,
2758 frame
.resize_w
- (frame
.border_w
* 2),
2759 frame
.resize_h
- (frame
.border_w
* 2));
2761 XUngrabPointer(display
, CurrentTime
);
2769 void OpenboxWindow::motionNotifyEvent(XMotionEvent
*me
) {
2770 if (!flags
.resizing
&& (me
->state
& Button1Mask
) && functions
.move
&&
2771 (frame
.title
== me
->window
|| frame
.label
== me
->window
||
2772 frame
.handle
== me
->window
|| frame
.window
== me
->window
)) {
2773 if (! flags
.moving
) {
2774 XGrabPointer(display
, me
->window
, False
, Button1MotionMask
|
2775 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
,
2776 None
, openbox
->getMoveCursor(), CurrentTime
);
2778 if (windowmenu
&& windowmenu
->isVisible())
2781 flags
.moving
= True
;
2783 openbox
->maskWindowEvents(client
.window
, this);
2785 if (! screen
->doOpaqueMove()) {
2788 frame
.move_x
= frame
.x
;
2789 frame
.move_y
= frame
.y
;
2790 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2791 frame
.resize_h
= ((flags
.shaded
) ? frame
.title_h
: frame
.height
) +
2792 (frame
.border_w
* 2);
2794 screen
->showPosition(frame
.x
, frame
.y
);
2796 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2797 frame
.move_x
, frame
.move_y
,
2798 frame
.resize_w
- 1, frame
.resize_h
- 1);
2801 int dx
= me
->x_root
- frame
.grab_x
, dy
= me
->y_root
- frame
.grab_y
;
2803 dx
-= frame
.border_w
;
2804 dy
-= frame
.border_w
;
2806 int snap_distance
= screen
->getEdgeSnapThreshold();
2807 if (snap_distance
) {
2808 int drx
= screen
->getWidth() - (dx
+ frame
.snap_w
);
2810 if (dx
< drx
&& (dx
> 0 && dx
< snap_distance
) ||
2811 (dx
< 0 && dx
> -snap_distance
) )
2813 else if ( (drx
> 0 && drx
< snap_distance
) ||
2814 (drx
< 0 && drx
> -snap_distance
) )
2815 dx
= screen
->getWidth() - frame
.snap_w
;
2817 int dtty
, dbby
, dty
, dby
;
2818 switch (screen
->getToolbarPlacement()) {
2819 case Toolbar::TopLeft
:
2820 case Toolbar::TopCenter
:
2821 case Toolbar::TopRight
:
2822 dtty
= screen
->getToolbar()->getExposedHeight() +
2824 dbby
= screen
->getHeight();
2829 dbby
= screen
->getToolbar()->getY();
2834 dby
= dbby
- (dy
+ frame
.snap_h
);
2836 if ( (dy
> 0 && dty
< snap_distance
) ||
2837 (dy
< 0 && dty
> -snap_distance
) )
2839 else if ( (dby
> 0 && dby
< snap_distance
) ||
2840 (dby
< 0 && dby
> -snap_distance
) )
2841 dy
= dbby
- frame
.snap_h
;
2844 if (screen
->doOpaqueMove()) {
2845 configure(dx
, dy
, frame
.width
, frame
.height
);
2847 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2848 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2849 frame
.resize_h
- 1);
2854 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2855 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2856 frame
.resize_h
- 1);
2859 screen
->showPosition(dx
, dy
);
2861 } else if (functions
.resize
&&
2862 (((me
->state
& Button1Mask
) && (me
->window
== frame
.right_grip
||
2863 me
->window
== frame
.left_grip
)) ||
2864 (me
->state
& (Mod1Mask
| Button3Mask
) &&
2865 me
->window
== frame
.window
))) {
2866 Bool left
= resize_zone
& ZoneLeft
;
2868 if (! flags
.resizing
) {
2870 if (resize_zone
& ZoneTop
)
2871 cursor
= (resize_zone
& ZoneLeft
) ?
2872 openbox
->getUpperLeftAngleCursor() :
2873 openbox
->getUpperRightAngleCursor();
2875 cursor
= (resize_zone
& ZoneLeft
) ?
2876 openbox
->getLowerLeftAngleCursor() :
2877 openbox
->getLowerRightAngleCursor();
2878 XGrabPointer(display
, me
->window
, False
, ButtonMotionMask
|
2879 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
,
2880 cursor
, CurrentTime
);
2882 flags
.resizing
= True
;
2887 if (resize_zone
& ZoneRight
)
2888 frame
.grab_x
= me
->x
- screen
->getBorderWidth();
2890 frame
.grab_x
= me
->x
+ screen
->getBorderWidth();
2891 if (resize_zone
& ZoneTop
)
2892 frame
.grab_y
= me
->y
+ screen
->getBorderWidth() * 2;
2894 frame
.grab_y
= me
->y
- screen
->getBorderWidth() * 2;
2895 frame
.resize_x
= frame
.x
;
2896 frame
.resize_y
= frame
.y
;
2897 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2898 frame
.resize_h
= frame
.height
+ (frame
.border_w
* 2);
2901 left_fixsize(&gx
, &gy
);
2903 right_fixsize(&gx
, &gy
);
2905 screen
->showGeometry(gx
, gy
);
2907 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2908 frame
.resize_x
, frame
.resize_y
,
2909 frame
.resize_w
- 1, frame
.resize_h
- 1);
2911 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2912 frame
.resize_x
, frame
.resize_y
,
2913 frame
.resize_w
- 1, frame
.resize_h
- 1);
2917 if (resize_zone
& ZoneTop
)
2918 frame
.resize_h
= frame
.height
- (me
->y
- frame
.grab_y
);
2920 frame
.resize_h
= frame
.height
+ (me
->y
- frame
.grab_y
);
2921 if (frame
.resize_h
< 1) frame
.resize_h
= 1;
2924 frame
.resize_x
= me
->x_root
- frame
.grab_x
;
2925 if (frame
.resize_x
> (signed) (frame
.x
+ frame
.width
))
2926 frame
.resize_x
= frame
.resize_x
+ frame
.width
- 1;
2928 left_fixsize(&gx
, &gy
);
2930 frame
.resize_w
= frame
.width
+ (me
->x
- frame
.grab_x
);
2931 if (frame
.resize_w
< 1) frame
.resize_w
= 1;
2933 right_fixsize(&gx
, &gy
);
2936 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2937 frame
.resize_x
, frame
.resize_y
,
2938 frame
.resize_w
- 1, frame
.resize_h
- 1);
2940 screen
->showGeometry(gx
, gy
);
2947 void OpenboxWindow::shapeEvent(XShapeEvent
*) {
2948 if (openbox
->hasShapeExtensions()) {
2951 if (! validateClient()) return;
2952 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
2953 frame
.mwm_border_w
, frame
.y_border
+
2954 frame
.mwm_border_w
, client
.window
,
2955 ShapeBounding
, ShapeSet
);
2958 XRectangle xrect
[2];
2959 xrect
[0].x
= xrect
[0].y
= 0;
2960 xrect
[0].width
= frame
.width
;
2961 xrect
[0].height
= frame
.y_border
;
2963 if (decorations
.handle
) {
2965 xrect
[1].y
= frame
.y_handle
;
2966 xrect
[1].width
= frame
.width
;
2967 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
2971 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
2972 xrect
, num
, ShapeUnion
, Unsorted
);
2980 Bool
OpenboxWindow::validateClient(void) {
2981 XSync(display
, False
);
2984 if (XCheckTypedWindowEvent(display
, client
.window
, DestroyNotify
, &e
) ||
2985 XCheckTypedWindowEvent(display
, client
.window
, UnmapNotify
, &e
)) {
2986 XPutBackEvent(display
, &e
);
2996 void OpenboxWindow::restore(void) {
2997 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
2998 XSelectInput(display
, client
.window
, NoEventMask
);
3002 XUnmapWindow(display
, frame
.window
);
3003 XUnmapWindow(display
, client
.window
);
3005 XSetWindowBorderWidth(display
, client
.window
, client
.old_bw
);
3006 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
3007 client
.x
, client
.y
);
3008 XMapWindow(display
, client
.window
);
3014 void OpenboxWindow::timeout(void) {
3015 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
3019 void OpenboxWindow::changeOpenboxHints(OpenboxHints
*net
) {
3020 if ((net
->flags
& AttribShaded
) &&
3021 ((openbox_attrib
.attrib
& AttribShaded
) !=
3022 (net
->attrib
& AttribShaded
)))
3025 if (flags
.visible
&& // watch out for requests when we can not be seen
3026 (net
->flags
& (AttribMaxVert
| AttribMaxHoriz
)) &&
3027 ((openbox_attrib
.attrib
& (AttribMaxVert
| AttribMaxHoriz
)) !=
3028 (net
->attrib
& (AttribMaxVert
| AttribMaxHoriz
)))) {
3029 if (flags
.maximized
) {
3034 if ((net
->flags
& AttribMaxHoriz
) && (net
->flags
& AttribMaxVert
))
3035 button
= ((net
->attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0);
3036 else if (net
->flags
& AttribMaxVert
)
3037 button
= ((net
->attrib
& AttribMaxVert
) ? 2 : 0);
3038 else if (net
->flags
& AttribMaxHoriz
)
3039 button
= ((net
->attrib
& AttribMaxHoriz
) ? 3 : 0);
3045 if ((net
->flags
& AttribOmnipresent
) &&
3046 ((openbox_attrib
.attrib
& AttribOmnipresent
) !=
3047 (net
->attrib
& AttribOmnipresent
)))
3050 if ((net
->flags
& AttribWorkspace
) &&
3051 (workspace_number
!= (signed) net
->workspace
)) {
3052 screen
->reassociateWindow(this, net
->workspace
, True
);
3054 if (screen
->getCurrentWorkspaceID() != (signed) net
->workspace
) withdraw();
3058 if (net
->flags
& AttribDecoration
) {
3059 switch (net
->decoration
) {
3061 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3062 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= False
;
3068 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3069 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= True
;
3074 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
= True
;
3075 decorations
.border
= decorations
.handle
= decorations
.maximize
= False
;
3080 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
3081 decorations
.iconify
= decorations
.border
= decorations
.handle
=
3082 decorations
.maximize
= False
;
3087 XMapSubwindows(display
, frame
.window
);
3088 XMapWindow(display
, frame
.window
);
3092 setState(current_state
);
3098 * Set the sizes of all components of the window frame
3099 * (the window decorations).
3100 * These values are based upon the current style settings and the client
3101 * window's dimentions.
3103 void OpenboxWindow::upsize(void) {
3104 frame
.bevel_w
= screen
->getBevelWidth();
3106 if (decorations
.border
) {
3107 frame
.border_w
= screen
->getBorderWidth();
3108 if (!flags
.transient
)
3109 frame
.mwm_border_w
= screen
->getFrameWidth();
3111 frame
.mwm_border_w
= 0;
3113 frame
.mwm_border_w
= frame
.border_w
= 0;
3116 if (decorations
.titlebar
) {
3117 // the height of the titlebar is based upon the height of the font being
3118 // used to display the window's title
3119 WindowStyle
*style
= screen
->getWindowStyle();
3120 if (i18n
->multibyte())
3121 frame
.title_h
= (style
->fontset_extents
->max_ink_extent
.height
+
3122 (frame
.bevel_w
* 2) + 2);
3124 frame
.title_h
= (style
->font
->ascent
+ style
->font
->descent
+
3125 (frame
.bevel_w
* 2) + 2);
3127 frame
.label_h
= frame
.title_h
- (frame
.bevel_w
* 2);
3128 frame
.button_w
= frame
.button_h
= (frame
.label_h
- 2);
3129 frame
.y_border
= frame
.title_h
+ frame
.border_w
;
3133 frame
.button_w
= frame
.button_h
= 0;
3137 frame
.border_h
= client
.height
+ frame
.mwm_border_w
* 2;
3139 if (decorations
.handle
) {
3140 frame
.y_handle
= frame
.y_border
+ frame
.border_h
+ frame
.border_w
;
3141 frame
.grip_w
= frame
.button_w
* 2;
3142 frame
.grip_h
= frame
.handle_h
= screen
->getHandleWidth();
3144 frame
.y_handle
= frame
.y_border
+ frame
.border_h
;
3146 frame
.grip_w
= frame
.grip_h
= 0;
3149 frame
.width
= client
.width
+ (frame
.mwm_border_w
* 2);
3150 frame
.height
= frame
.y_handle
+ frame
.handle_h
;
3152 frame
.snap_w
= frame
.width
+ (frame
.border_w
* 2);
3153 frame
.snap_h
= frame
.height
+ (frame
.border_w
* 2);
3158 * Set the size and position of the client window.
3159 * These values are based upon the current style settings and the frame
3160 * window's dimensions.
3162 void OpenboxWindow::downsize(void) {
3163 frame
.y_handle
= frame
.height
- frame
.handle_h
;
3164 frame
.border_h
= frame
.y_handle
- frame
.y_border
-
3165 (decorations
.handle
? frame
.border_w
: 0);
3167 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
3168 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+ frame
.border_w
;
3170 client
.width
= frame
.width
- (frame
.mwm_border_w
* 2);
3171 client
.height
= frame
.height
- frame
.y_border
- (frame
.mwm_border_w
* 2)
3172 - frame
.handle_h
- (decorations
.handle
? frame
.border_w
: 0);
3174 frame
.y_handle
= frame
.border_h
+ frame
.y_border
+ frame
.border_w
;
3176 frame
.snap_w
= frame
.width
+ (frame
.border_w
* 2);
3177 frame
.snap_h
= frame
.height
+ (frame
.border_w
* 2);
3181 void OpenboxWindow::right_fixsize(int *gx
, int *gy
) {
3182 // calculate the size of the client window and conform it to the
3183 // size specified by the size hints of the client window...
3184 int dx
= frame
.resize_w
- client
.base_width
- (frame
.mwm_border_w
* 2) -
3185 (frame
.border_w
* 2) + (client
.width_inc
/ 2);
3186 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3187 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3188 + (client
.height_inc
/ 2);
3190 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3191 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3192 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3193 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3195 dx
/= client
.width_inc
;
3196 dy
/= client
.height_inc
;
3201 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3202 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3204 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3205 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3206 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3207 if (resize_zone
& ZoneTop
)
3208 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3209 screen
->getBorderWidth() * 2;
3213 void OpenboxWindow::left_fixsize(int *gx
, int *gy
) {
3214 // calculate the size of the client window and conform it to the
3215 // size specified by the size hints of the client window...
3216 int dx
= frame
.x
+ frame
.width
- frame
.resize_x
- client
.base_width
-
3217 (frame
.mwm_border_w
* 2) + (client
.width_inc
/ 2);
3218 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3219 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3220 + (client
.height_inc
/ 2);
3222 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3223 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3224 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3225 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3227 dx
/= client
.width_inc
;
3228 dy
/= client
.height_inc
;
3233 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3234 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3236 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3237 frame
.resize_x
= frame
.x
+ frame
.width
- frame
.resize_w
+
3238 (frame
.border_w
* 2);
3239 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3240 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3241 if (resize_zone
& ZoneTop
)
3242 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3243 screen
->getBorderWidth() * 2;