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
;
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();
544 void OpenboxWindow::decorate(void) {
545 Pixmap tmp
= frame
.fbutton
;
546 BTexture
*texture
= &(screen
->getWindowStyle()->b_focus
);
547 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
548 frame
.fbutton
= None
;
549 frame
.fbutton_pixel
= texture
->getColor()->getPixel();
552 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
554 if (tmp
) image_ctrl
->removeImage(tmp
);
557 texture
= &(screen
->getWindowStyle()->b_unfocus
);
558 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
559 frame
.ubutton
= None
;
560 frame
.ubutton_pixel
= texture
->getColor()->getPixel();
563 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
565 if (tmp
) image_ctrl
->removeImage(tmp
);
568 texture
= &(screen
->getWindowStyle()->b_pressed
);
569 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
570 frame
.pbutton
= None
;
571 frame
.pbutton_pixel
= texture
->getColor()->getPixel();
574 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
576 if (tmp
) image_ctrl
->removeImage(tmp
);
578 if (decorations
.titlebar
) {
580 texture
= &(screen
->getWindowStyle()->t_focus
);
581 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
583 frame
.ftitle_pixel
= texture
->getColor()->getPixel();
586 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
588 if (tmp
) image_ctrl
->removeImage(tmp
);
591 texture
= &(screen
->getWindowStyle()->t_unfocus
);
592 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
594 frame
.utitle_pixel
= texture
->getColor()->getPixel();
597 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
599 if (tmp
) image_ctrl
->removeImage(tmp
);
601 XSetWindowBorder(display
, frame
.title
,
602 screen
->getBorderColor()->getPixel());
607 if (decorations
.border
) {
608 frame
.fborder_pixel
= screen
->getWindowStyle()->f_focus
.getPixel();
609 frame
.uborder_pixel
= screen
->getWindowStyle()->f_unfocus
.getPixel();
610 openbox_attrib
.flags
|= AttribDecoration
;
611 openbox_attrib
.decoration
= DecorNormal
;
613 openbox_attrib
.flags
|= AttribDecoration
;
614 openbox_attrib
.decoration
= DecorNone
;
617 if (decorations
.handle
) {
619 texture
= &(screen
->getWindowStyle()->h_focus
);
620 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
621 frame
.fhandle
= None
;
622 frame
.fhandle_pixel
= texture
->getColor()->getPixel();
625 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
627 if (tmp
) image_ctrl
->removeImage(tmp
);
630 texture
= &(screen
->getWindowStyle()->h_unfocus
);
631 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
632 frame
.uhandle
= None
;
633 frame
.uhandle_pixel
= texture
->getColor()->getPixel();
636 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
638 if (tmp
) image_ctrl
->removeImage(tmp
);
641 texture
= &(screen
->getWindowStyle()->g_focus
);
642 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
644 frame
.fgrip_pixel
= texture
->getColor()->getPixel();
647 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
649 if (tmp
) image_ctrl
->removeImage(tmp
);
652 texture
= &(screen
->getWindowStyle()->g_unfocus
);
653 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
655 frame
.ugrip_pixel
= texture
->getColor()->getPixel();
658 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
660 if (tmp
) image_ctrl
->removeImage(tmp
);
662 XSetWindowBorder(display
, frame
.handle
,
663 screen
->getBorderColor()->getPixel());
664 XSetWindowBorder(display
, frame
.left_grip
,
665 screen
->getBorderColor()->getPixel());
666 XSetWindowBorder(display
, frame
.right_grip
,
667 screen
->getBorderColor()->getPixel());
670 XSetWindowBorder(display
, frame
.window
,
671 screen
->getBorderColor()->getPixel());
675 void OpenboxWindow::decorateLabel(void) {
676 Pixmap tmp
= frame
.flabel
;
677 BTexture
*texture
= &(screen
->getWindowStyle()->l_focus
);
678 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
680 frame
.flabel_pixel
= texture
->getColor()->getPixel();
683 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
685 if (tmp
) image_ctrl
->removeImage(tmp
);
688 texture
= &(screen
->getWindowStyle()->l_unfocus
);
689 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
691 frame
.ulabel_pixel
= texture
->getColor()->getPixel();
694 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
696 if (tmp
) image_ctrl
->removeImage(tmp
);
700 void OpenboxWindow::createCloseButton(void) {
701 if (decorations
.close
&& frame
.title
!= None
) {
702 frame
.close_button
= createChildWindow(frame
.title
);
703 openbox
.saveWindowSearch(frame
.close_button
, this);
708 void OpenboxWindow::createIconifyButton(void) {
709 if (decorations
.iconify
&& frame
.title
!= None
) {
710 frame
.iconify_button
= createChildWindow(frame
.title
);
711 openbox
.saveWindowSearch(frame
.iconify_button
, this);
716 void OpenboxWindow::createMaximizeButton(void) {
717 if (decorations
.maximize
&& frame
.title
!= None
) {
718 frame
.maximize_button
= createChildWindow(frame
.title
);
719 openbox
.saveWindowSearch(frame
.maximize_button
, this);
724 void OpenboxWindow::positionButtons(Bool redecorate_label
) {
725 const char *format
= openbox
.getTitleBarLayout();
726 const unsigned int bw
= frame
.bevel_w
+ 1;
727 const unsigned int by
= frame
.bevel_w
+ 1;
728 unsigned int bx
= frame
.bevel_w
+ 1;
729 unsigned int bcount
= strlen(format
) - 1;
731 if (!decorations
.close
)
733 if (!decorations
.maximize
)
735 if (!decorations
.iconify
)
737 frame
.label_w
= frame
.width
- bx
* 2 - (frame
.button_w
+ bw
) * bcount
;
739 bool hasclose
, hasiconify
, hasmaximize
;
740 hasclose
= hasiconify
= hasmaximize
= false;
742 for (int i
= 0; format
[i
] != '\0' && i
< 4; i
++) {
745 if (decorations
.close
) {
746 if (frame
.close_button
== None
)
748 XMoveResizeWindow(display
, frame
.close_button
, bx
, by
,
749 frame
.button_w
, frame
.button_h
);
750 XMapWindow(display
, frame
.close_button
);
751 XClearWindow(display
, frame
.close_button
);
752 bx
+= frame
.button_w
+ bw
;
757 if (decorations
.iconify
) {
758 if (frame
.iconify_button
== None
)
759 createIconifyButton();
760 XMoveResizeWindow(display
, frame
.iconify_button
, bx
, by
,
761 frame
.button_w
, frame
.button_h
);
762 XMapWindow(display
, frame
.iconify_button
);
763 XClearWindow(display
, frame
.iconify_button
);
764 bx
+= frame
.button_w
+ bw
;
769 if (decorations
.maximize
) {
770 if (frame
.maximize_button
== None
)
771 createMaximizeButton();
772 XMoveResizeWindow(display
, frame
.maximize_button
, bx
, by
,
773 frame
.button_w
, frame
.button_h
);
774 XMapWindow(display
, frame
.maximize_button
);
775 XClearWindow(display
, frame
.maximize_button
);
776 bx
+= frame
.button_w
+ bw
;
781 XMoveResizeWindow(display
, frame
.label
, bx
, by
- 1,
782 frame
.label_w
, frame
.label_h
);
783 bx
+= frame
.label_w
+ bw
;
789 openbox
.removeWindowSearch(frame
.close_button
);
790 XDestroyWindow(display
, frame
.close_button
);
791 frame
.close_button
= None
;
794 openbox
.removeWindowSearch(frame
.iconify_button
);
795 XDestroyWindow(display
, frame
.iconify_button
);
796 frame
.iconify_button
= None
;
799 openbox
.removeWindowSearch(frame
.maximize_button
);
800 XDestroyWindow(display
, frame
.maximize_button
);
801 frame
.maximize_button
= None
;
803 if (redecorate_label
)
810 void OpenboxWindow::reconfigure(void) {
813 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
814 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
818 if (i18n
->multibyte()) {
819 XRectangle ink
, logical
;
820 XmbTextExtents(screen
->getWindowStyle()->fontset
,
821 client
.title
, client
.title_len
, &ink
, &logical
);
822 client
.title_text_w
= logical
.width
;
824 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
825 client
.title
, client
.title_len
);
827 client
.title_text_w
+= (frame
.bevel_w
* 4);
833 XClearWindow(display
, frame
.window
);
834 setFocusFlag(flags
.focused
);
836 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
838 if (! screen
->sloppyFocus())
839 openbox
.grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
840 GrabModeSync
, GrabModeSync
, None
, None
);
842 openbox
.ungrabButton(Button1
, 0, frame
.plate
);
845 windowmenu
->move(windowmenu
->getX(), frame
.y
+ frame
.title_h
);
846 windowmenu
->reconfigure();
851 void OpenboxWindow::positionWindows(void) {
852 XResizeWindow(display
, frame
.window
, frame
.width
,
853 ((flags
.shaded
) ? frame
.title_h
: frame
.height
));
854 XSetWindowBorderWidth(display
, frame
.window
, frame
.border_w
);
855 XSetWindowBorderWidth(display
, frame
.plate
, frame
.mwm_border_w
);
856 XMoveResizeWindow(display
, frame
.plate
, 0, frame
.y_border
,
857 client
.width
, client
.height
);
858 XMoveResizeWindow(display
, client
.window
, 0, 0, client
.width
, client
.height
);
860 if (decorations
.titlebar
) {
861 XSetWindowBorderWidth(display
, frame
.title
, frame
.border_w
);
862 XMoveResizeWindow(display
, frame
.title
, -frame
.border_w
,
863 -frame
.border_w
, frame
.width
, frame
.title_h
);
866 } else if (frame
.title
) {
867 XUnmapWindow(display
, frame
.title
);
869 if (decorations
.handle
) {
870 XSetWindowBorderWidth(display
, frame
.handle
, frame
.border_w
);
871 XSetWindowBorderWidth(display
, frame
.left_grip
, frame
.border_w
);
872 XSetWindowBorderWidth(display
, frame
.right_grip
, frame
.border_w
);
874 XMoveResizeWindow(display
, frame
.handle
, -frame
.border_w
,
875 frame
.y_handle
- frame
.border_w
,
876 frame
.width
, frame
.handle_h
);
877 XMoveResizeWindow(display
, frame
.left_grip
, -frame
.border_w
,
878 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
879 XMoveResizeWindow(display
, frame
.right_grip
,
880 frame
.width
- frame
.grip_w
- frame
.border_w
,
881 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
882 XMapSubwindows(display
, frame
.handle
);
883 } else if (frame
.handle
) {
884 XUnmapWindow(display
, frame
.handle
);
889 void OpenboxWindow::getWMName(void) {
891 delete [] client
.title
;
892 client
.title
= (char *) 0;
895 XTextProperty text_prop
;
899 if (XGetWMName(display
, client
.window
, &text_prop
)) {
900 if (text_prop
.value
&& text_prop
.nitems
> 0) {
901 if (text_prop
.encoding
!= XA_STRING
) {
902 text_prop
.nitems
= strlen((char *) text_prop
.value
);
904 if ((XmbTextPropertyToTextList(display
, &text_prop
,
905 &list
, &num
) == Success
) &&
906 (num
> 0) && *list
) {
907 client
.title
= bstrdup(*list
);
908 XFreeStringList(list
);
910 client
.title
= bstrdup((char *) text_prop
.value
);
913 client
.title
= bstrdup((char *) text_prop
.value
);
915 XFree((char *) text_prop
.value
);
917 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
921 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
924 client
.title_len
= strlen(client
.title
);
926 if (i18n
->multibyte()) {
927 XRectangle ink
, logical
;
928 XmbTextExtents(screen
->getWindowStyle()->fontset
,
929 client
.title
, client
.title_len
, &ink
, &logical
);
930 client
.title_text_w
= logical
.width
;
932 client
.title_len
= strlen(client
.title
);
933 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
934 client
.title
, client
.title_len
);
937 client
.title_text_w
+= (frame
.bevel_w
* 4);
941 void OpenboxWindow::getWMIconName(void) {
942 if (client
.icon_title
) {
943 delete [] client
.icon_title
;
944 client
.icon_title
= (char *) 0;
947 XTextProperty text_prop
;
951 if (XGetWMIconName(display
, client
.window
, &text_prop
)) {
952 if (text_prop
.value
&& text_prop
.nitems
> 0) {
953 if (text_prop
.encoding
!= XA_STRING
) {
954 text_prop
.nitems
= strlen((char *) text_prop
.value
);
956 if ((XmbTextPropertyToTextList(display
, &text_prop
,
957 &list
, &num
) == Success
) &&
958 (num
> 0) && *list
) {
959 client
.icon_title
= bstrdup(*list
);
960 XFreeStringList(list
);
962 client
.icon_title
= bstrdup((char *) text_prop
.value
);
965 client
.icon_title
= bstrdup((char *) text_prop
.value
);
967 XFree((char *) text_prop
.value
);
969 client
.icon_title
= bstrdup(client
.title
);
972 client
.icon_title
= bstrdup(client
.title
);
978 * Retrieve which WM Protocols are supported by the client window.
979 * If the WM_DELETE_WINDOW protocol is supported, add the close button to the
980 * window's decorations and allow the close behavior.
981 * If the WM_TAKE_FOCUS protocol is supported, save a value that indicates
984 void OpenboxWindow::getWMProtocols(void) {
988 if (XGetWMProtocols(display
, client
.window
, &proto
, &num_return
)) {
989 for (int i
= 0; i
< num_return
; ++i
) {
990 if (proto
[i
] == openbox
.getWMDeleteAtom())
991 functions
.close
= decorations
.close
= True
;
992 else if (proto
[i
] == openbox
.getWMTakeFocusAtom())
993 flags
.send_focus_message
= True
;
994 else if (proto
[i
] == openbox
.getOpenboxStructureMessagesAtom())
995 screen
->addNetizen(new Netizen(*screen
, client
.window
));
1004 * Gets the value of the WM_HINTS property.
1005 * If the property is not set, then use a set of default values.
1007 void OpenboxWindow::getWMHints(void) {
1008 XWMHints
*wmhint
= XGetWMHints(display
, client
.window
);
1010 flags
.visible
= True
;
1011 flags
.iconic
= False
;
1012 focus_mode
= F_Passive
;
1013 client
.window_group
= None
;
1014 client
.initial_state
= NormalState
;
1017 client
.wm_hint_flags
= wmhint
->flags
;
1018 if (wmhint
->flags
& InputHint
) {
1019 if (wmhint
->input
== True
) {
1020 if (flags
.send_focus_message
)
1021 focus_mode
= F_LocallyActive
;
1023 focus_mode
= F_Passive
;
1025 if (flags
.send_focus_message
)
1026 focus_mode
= F_GloballyActive
;
1028 focus_mode
= F_NoInput
;
1031 focus_mode
= F_Passive
;
1034 if (wmhint
->flags
& StateHint
)
1035 client
.initial_state
= wmhint
->initial_state
;
1037 client
.initial_state
= NormalState
;
1039 if (wmhint
->flags
& WindowGroupHint
) {
1040 if (! client
.window_group
) {
1041 client
.window_group
= wmhint
->window_group
;
1042 openbox
.saveGroupSearch(client
.window_group
, this);
1045 client
.window_group
= None
;
1052 * Gets the value of the WM_NORMAL_HINTS property.
1053 * If the property is not set, then use a set of default values.
1055 void OpenboxWindow::getWMNormalHints(void) {
1057 XSizeHints sizehint
;
1059 client
.min_width
= client
.min_height
=
1060 client
.base_width
= client
.base_height
=
1061 client
.width_inc
= client
.height_inc
= 1;
1062 client
.max_width
= screen
->size().w();
1063 client
.max_height
= screen
->size().h();
1064 client
.min_aspect_x
= client
.min_aspect_y
=
1065 client
.max_aspect_x
= client
.max_aspect_y
= 1;
1066 client
.win_gravity
= NorthWestGravity
;
1068 if (! XGetWMNormalHints(display
, client
.window
, &sizehint
, &icccm_mask
))
1071 client
.normal_hint_flags
= sizehint
.flags
;
1073 if (sizehint
.flags
& PMinSize
) {
1074 client
.min_width
= sizehint
.min_width
;
1075 client
.min_height
= sizehint
.min_height
;
1078 if (sizehint
.flags
& PMaxSize
) {
1079 client
.max_width
= sizehint
.max_width
;
1080 client
.max_height
= sizehint
.max_height
;
1083 if (sizehint
.flags
& PResizeInc
) {
1084 client
.width_inc
= sizehint
.width_inc
;
1085 client
.height_inc
= sizehint
.height_inc
;
1088 if (sizehint
.flags
& PAspect
) {
1089 client
.min_aspect_x
= sizehint
.min_aspect
.x
;
1090 client
.min_aspect_y
= sizehint
.min_aspect
.y
;
1091 client
.max_aspect_x
= sizehint
.max_aspect
.x
;
1092 client
.max_aspect_y
= sizehint
.max_aspect
.y
;
1095 if (sizehint
.flags
& PBaseSize
) {
1096 client
.base_width
= sizehint
.base_width
;
1097 client
.base_height
= sizehint
.base_height
;
1100 if (sizehint
.flags
& PWinGravity
)
1101 client
.win_gravity
= sizehint
.win_gravity
;
1106 * Gets the MWM hints for the class' contained window.
1107 * This is used while initializing the window to its first state, and not
1109 * Returns: true if the MWM hints are successfully retreived and applied; false
1112 void OpenboxWindow::getMWMHints(void) {
1115 unsigned long num
, len
;
1117 int ret
= XGetWindowProperty(display
, client
.window
,
1118 openbox
.getMotifWMHintsAtom(), 0,
1119 PropMwmHintsElements
, False
,
1120 openbox
.getMotifWMHintsAtom(), &atom_return
,
1121 &format
, &num
, &len
,
1122 (unsigned char **) &client
.mwm_hint
);
1124 if (ret
!= Success
|| !client
.mwm_hint
|| num
!= PropMwmHintsElements
)
1127 if (client
.mwm_hint
->flags
& MwmHintsDecorations
) {
1128 if (client
.mwm_hint
->decorations
& MwmDecorAll
) {
1129 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1130 decorations
.iconify
= decorations
.maximize
=
1131 decorations
.close
= decorations
.menu
= True
;
1133 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1134 decorations
.iconify
= decorations
.maximize
=
1135 decorations
.close
= decorations
.menu
= False
;
1137 if (client
.mwm_hint
->decorations
& MwmDecorBorder
)
1138 decorations
.border
= True
;
1139 if (client
.mwm_hint
->decorations
& MwmDecorHandle
)
1140 decorations
.handle
= True
;
1141 if (client
.mwm_hint
->decorations
& MwmDecorTitle
)
1142 decorations
.titlebar
= True
;
1143 if (client
.mwm_hint
->decorations
& MwmDecorMenu
)
1144 decorations
.menu
= True
;
1145 if (client
.mwm_hint
->decorations
& MwmDecorIconify
)
1146 decorations
.iconify
= True
;
1147 if (client
.mwm_hint
->decorations
& MwmDecorMaximize
)
1148 decorations
.maximize
= True
;
1152 if (client
.mwm_hint
->flags
& MwmHintsFunctions
) {
1153 if (client
.mwm_hint
->functions
& MwmFuncAll
) {
1154 functions
.resize
= functions
.move
= functions
.iconify
=
1155 functions
.maximize
= functions
.close
= True
;
1157 functions
.resize
= functions
.move
= functions
.iconify
=
1158 functions
.maximize
= functions
.close
= False
;
1160 if (client
.mwm_hint
->functions
& MwmFuncResize
)
1161 functions
.resize
= True
;
1162 if (client
.mwm_hint
->functions
& MwmFuncMove
)
1163 functions
.move
= True
;
1164 if (client
.mwm_hint
->functions
& MwmFuncIconify
)
1165 functions
.iconify
= True
;
1166 if (client
.mwm_hint
->functions
& MwmFuncMaximize
)
1167 functions
.maximize
= True
;
1168 if (client
.mwm_hint
->functions
& MwmFuncClose
)
1169 functions
.close
= True
;
1176 * Gets the openbox hints from the class' contained window.
1177 * This is used while initializing the window to its first state, and not
1179 * Returns: true if the hints are successfully retreived and applied; false if
1182 void OpenboxWindow::getOpenboxHints(void) {
1185 unsigned long num
, len
;
1187 int ret
= XGetWindowProperty(display
, client
.window
,
1188 openbox
.getOpenboxHintsAtom(), 0,
1189 PropOpenboxHintsElements
, False
,
1190 openbox
.getOpenboxHintsAtom(), &atom_return
,
1191 &format
, &num
, &len
,
1192 (unsigned char **) &client
.openbox_hint
);
1193 if (ret
!= Success
|| !client
.openbox_hint
||
1194 num
!= PropOpenboxHintsElements
)
1197 if (client
.openbox_hint
->flags
& AttribShaded
)
1198 flags
.shaded
= (client
.openbox_hint
->attrib
& AttribShaded
);
1200 if ((client
.openbox_hint
->flags
& AttribMaxHoriz
) &&
1201 (client
.openbox_hint
->flags
& AttribMaxVert
))
1202 flags
.maximized
= (client
.openbox_hint
->attrib
&
1203 (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1204 else if (client
.openbox_hint
->flags
& AttribMaxVert
)
1205 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxVert
) ? 2 : 0;
1206 else if (client
.openbox_hint
->flags
& AttribMaxHoriz
)
1207 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxHoriz
) ? 3 : 0;
1209 if (client
.openbox_hint
->flags
& AttribOmnipresent
)
1210 flags
.stuck
= (client
.openbox_hint
->attrib
& AttribOmnipresent
);
1212 if (client
.openbox_hint
->flags
& AttribWorkspace
)
1213 workspace_number
= client
.openbox_hint
->workspace
;
1215 // if (client.openbox_hint->flags & AttribStack)
1216 // don't yet have always on top/bottom for openbox yet... working
1219 if (client
.openbox_hint
->flags
& AttribDecoration
) {
1220 switch (client
.openbox_hint
->decoration
) {
1222 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1223 decorations
.iconify
= decorations
.maximize
=
1224 decorations
.menu
= False
;
1225 functions
.resize
= functions
.move
= functions
.iconify
=
1226 functions
.maximize
= False
;
1231 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
=
1232 functions
.move
= functions
.iconify
= True
;
1233 decorations
.border
= decorations
.handle
= decorations
.maximize
=
1234 functions
.resize
= functions
.maximize
= False
;
1239 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
1240 decorations
.iconify
= decorations
.border
= decorations
.handle
=
1241 decorations
.maximize
= functions
.resize
= functions
.maximize
=
1242 functions
.iconify
= False
;
1248 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1249 decorations
.iconify
= decorations
.maximize
=
1250 decorations
.menu
= True
;
1251 functions
.resize
= functions
.move
= functions
.iconify
=
1252 functions
.maximize
= True
;
1262 void OpenboxWindow::configure(int dx
, int dy
,
1263 unsigned int dw
, unsigned int dh
) {
1264 Bool send_event
= (frame
.x
!= dx
|| frame
.y
!= dy
);
1266 if ((dw
!= frame
.width
) || (dh
!= frame
.height
)) {
1267 if ((((signed) frame
.width
) + dx
) < 0) dx
= 0;
1268 if ((((signed) frame
.height
) + dy
) < 0) dy
= 0;
1278 if (openbox
.hasShapeExtensions() && flags
.shaped
) {
1279 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
1280 frame
.mwm_border_w
, frame
.y_border
+
1281 frame
.mwm_border_w
, client
.window
,
1282 ShapeBounding
, ShapeSet
);
1285 XRectangle xrect
[2];
1286 xrect
[0].x
= xrect
[0].y
= 0;
1287 xrect
[0].width
= frame
.width
;
1288 xrect
[0].height
= frame
.y_border
;
1290 if (decorations
.handle
) {
1292 xrect
[1].y
= frame
.y_handle
;
1293 xrect
[1].width
= frame
.width
;
1294 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
1298 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
1299 xrect
, num
, ShapeUnion
, Unsorted
);
1303 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1307 setFocusFlag(flags
.focused
);
1313 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1315 if (! flags
.moving
) send_event
= True
;
1318 if (send_event
&& ! flags
.moving
) {
1319 client
.x
= dx
+ frame
.mwm_border_w
+ frame
.border_w
;
1320 client
.y
= dy
+ frame
.y_border
+ frame
.mwm_border_w
+
1324 event
.type
= ConfigureNotify
;
1326 event
.xconfigure
.display
= display
;
1327 event
.xconfigure
.event
= client
.window
;
1328 event
.xconfigure
.window
= client
.window
;
1329 event
.xconfigure
.x
= client
.x
;
1330 event
.xconfigure
.y
= client
.y
;
1331 event
.xconfigure
.width
= client
.width
;
1332 event
.xconfigure
.height
= client
.height
;
1333 event
.xconfigure
.border_width
= client
.old_bw
;
1334 event
.xconfigure
.above
= frame
.window
;
1335 event
.xconfigure
.override_redirect
= False
;
1337 XSendEvent(display
, client
.window
, True
, NoEventMask
, &event
);
1339 screen
->updateNetizenConfigNotify(&event
);
1344 bool OpenboxWindow::setInputFocus(void) {
1345 if (((signed) (frame
.x
+ frame
.width
)) < 0) {
1346 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1347 configure(frame
.border_w
, frame
.border_w
, frame
.width
, frame
.height
);
1348 else if (frame
.y
> (signed) screen
->size().h())
1349 configure(frame
.border_w
, screen
->size().h() - frame
.height
,
1350 frame
.width
, frame
.height
);
1352 configure(frame
.border_w
, frame
.y
+ frame
.border_w
,
1353 frame
.width
, frame
.height
);
1354 } else if (frame
.x
> (signed) screen
->size().w()) {
1355 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1356 configure(screen
->size().w() - frame
.width
, frame
.border_w
,
1357 frame
.width
, frame
.height
);
1358 else if (frame
.y
> (signed) screen
->size().h())
1359 configure(screen
->size().w() - frame
.width
,
1360 screen
->size().h() - frame
.height
, frame
.width
, frame
.height
);
1362 configure(screen
->size().w() - frame
.width
,
1363 frame
.y
+ frame
.border_w
, frame
.width
, frame
.height
);
1367 if (! validateClient()) return False
;
1371 if (client
.transient
&& flags
.modal
) {
1372 ret
= client
.transient
->setInputFocus();
1373 } else if (! flags
.focused
) {
1374 if (focus_mode
== F_LocallyActive
|| focus_mode
== F_Passive
) {
1375 XSetInputFocus(display
, client
.window
,
1376 RevertToPointerRoot
, CurrentTime
);
1377 openbox
.focusWindow(this);
1379 if (flags
.send_focus_message
) {
1381 ce
.xclient
.type
= ClientMessage
;
1382 ce
.xclient
.message_type
= openbox
.getWMProtocolsAtom();
1383 ce
.xclient
.display
= display
;
1384 ce
.xclient
.window
= client
.window
;
1385 ce
.xclient
.format
= 32;
1386 ce
.xclient
.data
.l
[0] = openbox
.getWMTakeFocusAtom();
1387 ce
.xclient
.data
.l
[1] = openbox
.getLastTime();
1388 ce
.xclient
.data
.l
[2] = 0l;
1389 ce
.xclient
.data
.l
[3] = 0l;
1390 ce
.xclient
.data
.l
[4] = 0l;
1391 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1394 if (screen
->sloppyFocus() && screen
->autoRaise())
1407 void OpenboxWindow::iconify(void) {
1408 if (flags
.iconic
) return;
1413 if (windowmenu
) windowmenu
->hide();
1415 setState(IconicState
);
1417 XSelectInput(display
, client
.window
, NoEventMask
);
1418 XUnmapWindow(display
, client
.window
);
1419 XSelectInput(display
, client
.window
,
1420 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1422 XUnmapWindow(display
, frame
.window
);
1423 flags
.visible
= False
;
1424 flags
.iconic
= True
;
1426 screen
->getWorkspace(workspace_number
)->removeWindow(this);
1428 if (flags
.transient
&& client
.transient_for
&&
1429 !client
.transient_for
->flags
.iconic
) {
1430 client
.transient_for
->iconify();
1432 screen
->addIcon(this);
1434 if (client
.transient
&& !client
.transient
->flags
.iconic
) {
1435 client
.transient
->iconify();
1440 void OpenboxWindow::deiconify(bool reassoc
, bool raise
, bool initial
) {
1441 if (flags
.iconic
|| reassoc
)
1442 screen
->reassociateWindow(this, -1, False
);
1443 else if (workspace_number
!= screen
->getCurrentWorkspace()->getWorkspaceID())
1446 setState(NormalState
);
1448 XSelectInput(display
, client
.window
, NoEventMask
);
1449 XMapWindow(display
, client
.window
);
1450 XSelectInput(display
, client
.window
,
1451 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1453 XMapSubwindows(display
, frame
.window
);
1454 XMapWindow(display
, frame
.window
);
1456 // if we're using the click to place placement type, then immediately
1457 // after the window is mapped, we need to start interactively moving it
1458 if (initial
&& place_window
&&
1459 screen
->placementPolicy() == BScreen::ClickMousePlacement
) {
1463 XQueryPointer(openbox
.getXDisplay(), screen
->getRootWindow(),
1464 &r
, &c
, &rx
, &ry
, &x
, &y
, &m
);
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) {
1500 flags
.visible
= False
;
1501 flags
.iconic
= False
;
1503 XUnmapWindow(display
, frame
.window
);
1505 XSelectInput(display
, client
.window
, NoEventMask
);
1506 XUnmapWindow(display
, client
.window
);
1507 XSelectInput(display
, client
.window
,
1508 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1510 if (windowmenu
) windowmenu
->hide();
1514 void OpenboxWindow::maximize(unsigned int button
) {
1518 // handle case where menu is open then the max button is used instead
1519 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
1521 if (flags
.maximized
) {
1522 flags
.maximized
= 0;
1524 openbox_attrib
.flags
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1525 openbox_attrib
.attrib
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1527 // when a resize is begun, maximize(0) is called to clear any maximization
1528 // flags currently set. Otherwise it still thinks it is maximized.
1529 // so we do not need to call configure() because resizing will handle it
1530 if (!flags
.resizing
)
1531 configure(openbox_attrib
.premax_x
, openbox_attrib
.premax_y
,
1532 openbox_attrib
.premax_w
, openbox_attrib
.premax_h
);
1534 openbox_attrib
.premax_x
= openbox_attrib
.premax_y
= 0;
1535 openbox_attrib
.premax_w
= openbox_attrib
.premax_h
= 0;
1538 setState(current_state
);
1542 openbox_attrib
.premax_x
= frame
.x
;
1543 openbox_attrib
.premax_y
= frame
.y
;
1544 openbox_attrib
.premax_w
= frame
.width
;
1545 openbox_attrib
.premax_h
= frame
.height
;
1547 Rect space
= screen
->availableArea();
1548 unsigned int dw
= space
.w(),
1550 dw
-= frame
.border_w
* 2;
1551 dw
-= frame
.mwm_border_w
* 2;
1552 dw
-= client
.base_width
;
1554 dh
-= frame
.border_w
* 2;
1555 dh
-= frame
.mwm_border_w
* 2;
1556 dh
-= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1557 dh
-= client
.base_height
;
1558 dh
-= frame
.y_border
;
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 int dx
= space
.x() + ((space
.w() - dw
) / 2) - frame
.border_w
,
1576 dy
= space
.y() + ((space
.h() - dh
) / 2) - frame
.border_w
;
1580 openbox_attrib
.flags
|= AttribMaxHoriz
| AttribMaxVert
;
1581 openbox_attrib
.attrib
|= AttribMaxHoriz
| AttribMaxVert
;
1585 openbox_attrib
.flags
|= AttribMaxVert
;
1586 openbox_attrib
.attrib
|= AttribMaxVert
;
1593 openbox_attrib
.flags
|= AttribMaxHoriz
;
1594 openbox_attrib
.attrib
|= AttribMaxHoriz
;
1602 openbox_attrib
.flags
^= AttribShaded
;
1603 openbox_attrib
.attrib
^= AttribShaded
;
1604 flags
.shaded
= False
;
1607 flags
.maximized
= button
;
1609 configure(dx
, dy
, dw
, dh
);
1610 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1612 setState(current_state
);
1616 void OpenboxWindow::setWorkspace(int n
) {
1617 ASSERT(n
< screen
->getWorkspaceCount());
1618 workspace_number
= n
;
1620 openbox_attrib
.flags
|= AttribWorkspace
;
1621 openbox_attrib
.workspace
= workspace_number
;
1625 void OpenboxWindow::shade(void) {
1626 if (!decorations
.titlebar
)
1630 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.height
);
1631 flags
.shaded
= False
;
1632 openbox_attrib
.flags
^= AttribShaded
;
1633 openbox_attrib
.attrib
^= AttribShaded
;
1635 setState(NormalState
);
1637 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.title_h
);
1638 flags
.shaded
= True
;
1639 openbox_attrib
.flags
|= AttribShaded
;
1640 openbox_attrib
.attrib
|= AttribShaded
;
1642 setState(IconicState
);
1647 void OpenboxWindow::stick(void) {
1649 openbox_attrib
.flags
^= AttribOmnipresent
;
1650 openbox_attrib
.attrib
^= AttribOmnipresent
;
1652 flags
.stuck
= False
;
1655 screen
->reassociateWindow(this, -1, True
);
1657 setState(current_state
);
1661 openbox_attrib
.flags
|= AttribOmnipresent
;
1662 openbox_attrib
.attrib
|= AttribOmnipresent
;
1664 setState(current_state
);
1669 void OpenboxWindow::setFocusFlag(Bool focus
) {
1670 flags
.focused
= focus
;
1672 if (decorations
.titlebar
) {
1673 if (flags
.focused
) {
1675 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.ftitle
);
1677 XSetWindowBackground(display
, frame
.title
, frame
.ftitle_pixel
);
1680 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.utitle
);
1682 XSetWindowBackground(display
, frame
.title
, frame
.utitle_pixel
);
1684 XClearWindow(display
, frame
.title
);
1690 if (decorations
.handle
) {
1691 if (flags
.focused
) {
1693 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.fhandle
);
1695 XSetWindowBackground(display
, frame
.handle
, frame
.fhandle_pixel
);
1698 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.fgrip
);
1699 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.fgrip
);
1701 XSetWindowBackground(display
, frame
.right_grip
, frame
.fgrip_pixel
);
1702 XSetWindowBackground(display
, frame
.left_grip
, frame
.fgrip_pixel
);
1706 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.uhandle
);
1708 XSetWindowBackground(display
, frame
.handle
, frame
.uhandle_pixel
);
1711 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.ugrip
);
1712 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.ugrip
);
1714 XSetWindowBackground(display
, frame
.right_grip
, frame
.ugrip_pixel
);
1715 XSetWindowBackground(display
, frame
.left_grip
, frame
.ugrip_pixel
);
1718 XClearWindow(display
, frame
.handle
);
1719 XClearWindow(display
, frame
.right_grip
);
1720 XClearWindow(display
, frame
.left_grip
);
1723 if (decorations
.border
) {
1725 XSetWindowBorder(display
, frame
.plate
, frame
.fborder_pixel
);
1727 XSetWindowBorder(display
, frame
.plate
, frame
.uborder_pixel
);
1730 if (screen
->sloppyFocus() && screen
->autoRaise() && timer
->isTiming())
1736 void OpenboxWindow::installColormap(Bool install
) {
1738 if (! validateClient()) return;
1740 int i
= 0, ncmap
= 0;
1741 Colormap
*cmaps
= XListInstalledColormaps(display
, client
.window
, &ncmap
);
1742 XWindowAttributes wattrib
;
1744 if (XGetWindowAttributes(display
, client
.window
, &wattrib
)) {
1746 // install the window's colormap
1747 for (i
= 0; i
< ncmap
; i
++) {
1748 if (*(cmaps
+ i
) == wattrib
.colormap
)
1749 // this window is using an installed color map... do not install
1752 // otherwise, install the window's colormap
1754 XInstallColormap(display
, wattrib
.colormap
);
1756 // uninstall the window's colormap
1757 for (i
= 0; i
< ncmap
; i
++) {
1758 if (*(cmaps
+ i
) == wattrib
.colormap
)
1759 // we found the colormap to uninstall
1760 XUninstallColormap(display
, wattrib
.colormap
);
1772 void OpenboxWindow::setState(unsigned long new_state
) {
1773 current_state
= new_state
;
1775 unsigned long state
[2];
1776 state
[0] = (unsigned long) current_state
;
1777 state
[1] = (unsigned long) None
;
1778 XChangeProperty(display
, client
.window
, openbox
.getWMStateAtom(),
1779 openbox
.getWMStateAtom(), 32, PropModeReplace
,
1780 (unsigned char *) state
, 2);
1782 XChangeProperty(display
, client
.window
,
1783 openbox
.getOpenboxAttributesAtom(),
1784 openbox
.getOpenboxAttributesAtom(), 32, PropModeReplace
,
1785 (unsigned char *) &openbox_attrib
,
1786 PropOpenboxAttributesElements
);
1790 Bool
OpenboxWindow::getState(void) {
1796 unsigned long *state
, ulfoo
, nitems
;
1798 if ((XGetWindowProperty(display
, client
.window
, openbox
.getWMStateAtom(),
1799 0l, 2l, False
, openbox
.getWMStateAtom(),
1800 &atom_return
, &foo
, &nitems
, &ulfoo
,
1801 (unsigned char **) &state
) != Success
) ||
1808 current_state
= (unsigned long) state
[0];
1813 XFree((void *) state
);
1819 void OpenboxWindow::setGravityOffsets(void) {
1820 // x coordinates for each gravity type
1821 const int x_west
= client
.x
;
1822 const int x_east
= client
.x
+ client
.width
- frame
.width
;
1823 const int x_center
= client
.x
+ client
.width
- frame
.width
/2;
1824 // y coordinates for each gravity type
1825 const int y_north
= client
.y
;
1826 const int y_south
= client
.y
+ client
.height
- frame
.height
;
1827 const int y_center
= client
.y
+ client
.height
- frame
.height
/2;
1829 switch (client
.win_gravity
) {
1830 case NorthWestGravity
:
1839 case NorthEastGravity
:
1843 case SouthWestGravity
:
1851 case SouthEastGravity
:
1869 frame
.x
= client
.x
- frame
.mwm_border_w
+ frame
.border_w
;
1870 frame
.y
= client
.y
- frame
.y_border
- frame
.mwm_border_w
- frame
.border_w
;
1876 void OpenboxWindow::restoreAttributes(void) {
1877 if (! getState()) current_state
= NormalState
;
1881 unsigned long ulfoo
, nitems
;
1883 OpenboxAttributes
*net
;
1884 int ret
= XGetWindowProperty(display
, client
.window
,
1885 openbox
.getOpenboxAttributesAtom(), 0l,
1886 PropOpenboxAttributesElements
, False
,
1887 openbox
.getOpenboxAttributesAtom(),
1888 &atom_return
, &foo
, &nitems
, &ulfoo
,
1889 (unsigned char **) &net
);
1890 if (ret
!= Success
|| !net
|| nitems
!= PropOpenboxAttributesElements
)
1893 openbox_attrib
.flags
= net
->flags
;
1894 openbox_attrib
.attrib
= net
->attrib
;
1895 openbox_attrib
.decoration
= net
->decoration
;
1896 openbox_attrib
.workspace
= net
->workspace
;
1897 openbox_attrib
.stack
= net
->stack
;
1898 openbox_attrib
.premax_x
= net
->premax_x
;
1899 openbox_attrib
.premax_y
= net
->premax_y
;
1900 openbox_attrib
.premax_w
= net
->premax_w
;
1901 openbox_attrib
.premax_h
= net
->premax_h
;
1903 XFree((void *) net
);
1905 if (openbox_attrib
.flags
& AttribShaded
&&
1906 openbox_attrib
.attrib
& AttribShaded
) {
1908 ((current_state
== IconicState
) ? NormalState
: current_state
);
1910 flags
.shaded
= False
;
1913 current_state
= save_state
;
1916 if (((int) openbox_attrib
.workspace
!= screen
->getCurrentWorkspaceID()) &&
1917 ((int) openbox_attrib
.workspace
< screen
->getWorkspaceCount())) {
1918 screen
->reassociateWindow(this, openbox_attrib
.workspace
, True
);
1920 if (current_state
== NormalState
) current_state
= WithdrawnState
;
1921 } else if (current_state
== WithdrawnState
) {
1922 current_state
= NormalState
;
1925 if (openbox_attrib
.flags
& AttribOmnipresent
&&
1926 openbox_attrib
.attrib
& AttribOmnipresent
) {
1927 flags
.stuck
= False
;
1930 current_state
= NormalState
;
1933 if ((openbox_attrib
.flags
& AttribMaxHoriz
) ||
1934 (openbox_attrib
.flags
& AttribMaxVert
)) {
1935 int x
= openbox_attrib
.premax_x
, y
= openbox_attrib
.premax_y
;
1936 unsigned int w
= openbox_attrib
.premax_w
, h
= openbox_attrib
.premax_h
;
1937 flags
.maximized
= 0;
1939 unsigned int m
= False
;
1940 if ((openbox_attrib
.flags
& AttribMaxHoriz
) &&
1941 (openbox_attrib
.flags
& AttribMaxVert
))
1942 m
= (openbox_attrib
.attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1943 else if (openbox_attrib
.flags
& AttribMaxVert
)
1944 m
= (openbox_attrib
.attrib
& AttribMaxVert
) ? 2 : 0;
1945 else if (openbox_attrib
.flags
& AttribMaxHoriz
)
1946 m
= (openbox_attrib
.attrib
& AttribMaxHoriz
) ? 3 : 0;
1950 openbox_attrib
.premax_x
= x
;
1951 openbox_attrib
.premax_y
= y
;
1952 openbox_attrib
.premax_w
= w
;
1953 openbox_attrib
.premax_h
= h
;
1956 setState(current_state
);
1961 * The reverse of the setGravityOffsets function. Uses the frame window's
1962 * position to find the window's reference point.
1964 void OpenboxWindow::restoreGravity(void) {
1965 // x coordinates for each gravity type
1966 const int x_west
= frame
.x
;
1967 const int x_east
= frame
.x
+ frame
.width
- client
.width
;
1968 const int x_center
= frame
.x
+ (frame
.width
/2) - client
.width
;
1969 // y coordinates for each gravity type
1970 const int y_north
= frame
.y
;
1971 const int y_south
= frame
.y
+ frame
.height
- client
.height
;
1972 const int y_center
= frame
.y
+ (frame
.height
/2) - client
.height
;
1974 switch(client
.win_gravity
) {
1976 case NorthWestGravity
:
1981 client
.x
= x_center
;
1984 case NorthEastGravity
:
1988 case SouthWestGravity
:
1993 client
.x
= x_center
;
1996 case SouthEastGravity
:
2002 client
.y
= y_center
;
2006 client
.y
= y_center
;
2009 client
.x
= x_center
;
2010 client
.y
= y_center
;
2014 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
2015 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
2022 void OpenboxWindow::redrawLabel(void) {
2023 int dx
= frame
.bevel_w
* 2, dlen
= client
.title_len
;
2024 unsigned int l
= client
.title_text_w
;
2026 if (flags
.focused
) {
2028 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.flabel
);
2030 XSetWindowBackground(display
, frame
.label
, frame
.flabel_pixel
);
2033 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.ulabel
);
2035 XSetWindowBackground(display
, frame
.label
, frame
.ulabel_pixel
);
2037 XClearWindow(display
, frame
.label
);
2039 if (client
.title_text_w
> frame
.label_w
) {
2040 for (; dlen
>= 0; dlen
--) {
2041 if (i18n
->multibyte()) {
2042 XRectangle ink
, logical
;
2043 XmbTextExtents(screen
->getWindowStyle()->fontset
, client
.title
, dlen
,
2047 l
= XTextWidth(screen
->getWindowStyle()->font
, client
.title
, dlen
);
2049 l
+= (frame
.bevel_w
* 4);
2051 if (l
< frame
.label_w
)
2056 switch (screen
->getWindowStyle()->justify
) {
2057 case BScreen::RightJustify
:
2058 dx
+= frame
.label_w
- l
;
2061 case BScreen::CenterJustify
:
2062 dx
+= (frame
.label_w
- l
) / 2;
2066 WindowStyle
*style
= screen
->getWindowStyle();
2067 GC text_gc
= (flags
.focused
) ? style
->l_text_focus_gc
:
2068 style
->l_text_unfocus_gc
;
2069 if (i18n
->multibyte())
2070 XmbDrawString(display
, frame
.label
, style
->fontset
, text_gc
, dx
,
2071 (1 - style
->fontset_extents
->max_ink_extent
.y
),
2072 client
.title
, dlen
);
2074 XDrawString(display
, frame
.label
, text_gc
, dx
,
2075 (style
->font
->ascent
+ 1), client
.title
, dlen
);
2079 void OpenboxWindow::redrawAllButtons(void) {
2080 if (frame
.iconify_button
) redrawIconifyButton(False
);
2081 if (frame
.maximize_button
) redrawMaximizeButton(flags
.maximized
);
2082 if (frame
.close_button
) redrawCloseButton(False
);
2086 void OpenboxWindow::redrawIconifyButton(Bool pressed
) {
2088 if (flags
.focused
) {
2090 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2093 XSetWindowBackground(display
, frame
.iconify_button
,
2094 frame
.fbutton_pixel
);
2097 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2100 XSetWindowBackground(display
, frame
.iconify_button
,
2101 frame
.ubutton_pixel
);
2105 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.pbutton
);
2107 XSetWindowBackground(display
, frame
.iconify_button
, frame
.pbutton_pixel
);
2109 XClearWindow(display
, frame
.iconify_button
);
2111 XDrawRectangle(display
, frame
.iconify_button
,
2112 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2113 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2114 2, (frame
.button_h
- 5), (frame
.button_w
- 5), 2);
2118 void OpenboxWindow::redrawMaximizeButton(Bool pressed
) {
2120 if (flags
.focused
) {
2122 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2125 XSetWindowBackground(display
, frame
.maximize_button
,
2126 frame
.fbutton_pixel
);
2129 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2132 XSetWindowBackground(display
, frame
.maximize_button
,
2133 frame
.ubutton_pixel
);
2137 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2140 XSetWindowBackground(display
, frame
.maximize_button
,
2141 frame
.pbutton_pixel
);
2143 XClearWindow(display
, frame
.maximize_button
);
2145 XDrawRectangle(display
, frame
.maximize_button
,
2146 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2147 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2148 2, 2, (frame
.button_w
- 5), (frame
.button_h
- 5));
2149 XDrawLine(display
, frame
.maximize_button
,
2150 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2151 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2152 2, 3, (frame
.button_w
- 3), 3);
2156 void OpenboxWindow::redrawCloseButton(Bool pressed
) {
2158 if (flags
.focused
) {
2160 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2163 XSetWindowBackground(display
, frame
.close_button
,
2164 frame
.fbutton_pixel
);
2167 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2170 XSetWindowBackground(display
, frame
.close_button
,
2171 frame
.ubutton_pixel
);
2175 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.pbutton
);
2177 XSetWindowBackground(display
, frame
.close_button
, frame
.pbutton_pixel
);
2179 XClearWindow(display
, frame
.close_button
);
2181 XDrawLine(display
, frame
.close_button
,
2182 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2183 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2, 2,
2184 (frame
.button_w
- 3), (frame
.button_h
- 3));
2185 XDrawLine(display
, frame
.close_button
,
2186 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2187 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2,
2188 (frame
.button_h
- 3),
2189 (frame
.button_w
- 3), 2);
2193 void OpenboxWindow::mapRequestEvent(XMapRequestEvent
*re
) {
2194 if (re
->window
== client
.window
) {
2196 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowMapRequest
,
2197 "OpenboxWindow::mapRequestEvent() for 0x%lx\n"),
2202 if (! validateClient()) return;
2204 Bool get_state_ret
= getState();
2205 if (! (get_state_ret
&& openbox
.isStartup())) {
2206 if ((client
.wm_hint_flags
& StateHint
) &&
2207 (! (current_state
== NormalState
|| current_state
== IconicState
)))
2208 current_state
= client
.initial_state
;
2210 current_state
= NormalState
;
2211 } else if (flags
.iconic
) {
2212 current_state
= NormalState
;
2215 switch (current_state
) {
2220 case WithdrawnState
:
2228 deiconify(False
, True
, True
); // specify that we're initializing the
2238 void OpenboxWindow::mapNotifyEvent(XMapEvent
*ne
) {
2239 if ((ne
->window
== client
.window
) && (! ne
->override_redirect
)
2240 && (flags
.visible
)) {
2242 if (! validateClient()) return;
2244 if (decorations
.titlebar
) positionButtons();
2246 setState(NormalState
);
2250 if (flags
.transient
|| screen
->focusNew())
2253 setFocusFlag(False
);
2255 flags
.visible
= True
;
2256 flags
.iconic
= False
;
2263 void OpenboxWindow::unmapNotifyEvent(XUnmapEvent
*ue
) {
2264 if (ue
->window
== client
.window
) {
2266 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotify
,
2267 "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"),
2272 if (! validateClient()) return;
2277 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
2278 XSelectInput(display
, client
.window
, NoEventMask
);
2280 XDeleteProperty(display
, client
.window
, openbox
.getWMStateAtom());
2281 XDeleteProperty(display
, client
.window
,
2282 openbox
.getOpenboxAttributesAtom());
2284 XUnmapWindow(display
, frame
.window
);
2285 XUnmapWindow(display
, client
.window
);
2288 if (! XCheckTypedWindowEvent(display
, client
.window
, ReparentNotify
,
2291 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotifyReparent
,
2292 "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to "
2293 "root.\n"), client
.window
);
2297 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
2298 client
.x
, client
.y
);
2310 void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent
*de
) {
2311 if (de
->window
== client
.window
) {
2314 XUnmapWindow(display
, frame
.window
);
2321 void OpenboxWindow::propertyNotifyEvent(Atom atom
) {
2323 if (! validateClient()) return;
2327 case XA_WM_CLIENT_MACHINE
:
2331 case XA_WM_TRANSIENT_FOR
:
2332 // determine if this is a transient window
2334 if (XGetTransientForHint(display
, client
.window
, &win
)) {
2335 if (win
&& (win
!= client
.window
)) {
2336 if ((client
.transient_for
= openbox
.searchWindow(win
))) {
2337 client
.transient_for
->client
.transient
= this;
2338 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2339 flags
.transient
= True
;
2340 } else if (win
== client
.window_group
) {
2341 //jr This doesn't look quite right...
2342 if ((client
.transient_for
= openbox
.searchGroup(win
, this))) {
2343 client
.transient_for
->client
.transient
= this;
2344 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2345 flags
.transient
= True
;
2350 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
2353 // adjust the window decorations based on transience
2354 if (flags
.transient
)
2355 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
2365 case XA_WM_ICON_NAME
:
2367 if (flags
.iconic
) screen
->iconUpdate();
2373 if (decorations
.titlebar
)
2377 screen
->getWorkspace(workspace_number
)->update();
2381 case XA_WM_NORMAL_HINTS
: {
2384 if ((client
.normal_hint_flags
& PMinSize
) &&
2385 (client
.normal_hint_flags
& PMaxSize
)) {
2386 if (client
.max_width
<= client
.min_width
&&
2387 client
.max_height
<= client
.min_height
)
2388 decorations
.maximize
= decorations
.handle
=
2389 functions
.resize
= functions
.maximize
= False
;
2391 decorations
.maximize
= decorations
.handle
=
2392 functions
.resize
= functions
.maximize
= True
;
2395 int x
= frame
.x
, y
= frame
.y
;
2396 unsigned int w
= frame
.width
, h
= frame
.height
;
2400 if ((x
!= frame
.x
) || (y
!= frame
.y
) ||
2401 (w
!= frame
.width
) || (h
!= frame
.height
))
2408 if (atom
== openbox
.getWMProtocolsAtom()) {
2411 if (decorations
.close
&& (! frame
.close_button
)) {
2412 createCloseButton();
2413 if (decorations
.titlebar
) positionButtons(True
);
2414 if (windowmenu
) windowmenu
->reconfigure();
2425 void OpenboxWindow::exposeEvent(XExposeEvent
*ee
) {
2426 if (frame
.label
== ee
->window
&& decorations
.titlebar
)
2428 else if (frame
.close_button
== ee
->window
)
2429 redrawCloseButton(False
);
2430 else if (frame
.maximize_button
== ee
->window
)
2431 redrawMaximizeButton(flags
.maximized
);
2432 else if (frame
.iconify_button
== ee
->window
)
2433 redrawIconifyButton(False
);
2437 void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent
*cr
) {
2438 if (cr
->window
== client
.window
) {
2440 if (! validateClient()) return;
2442 int cx
= frame
.x
, cy
= frame
.y
;
2443 unsigned int cw
= frame
.width
, ch
= frame
.height
;
2445 if (cr
->value_mask
& CWBorderWidth
)
2446 client
.old_bw
= cr
->border_width
;
2448 if (cr
->value_mask
& CWX
)
2449 cx
= cr
->x
- frame
.mwm_border_w
- frame
.border_w
;
2451 if (cr
->value_mask
& CWY
)
2452 cy
= cr
->y
- frame
.y_border
- frame
.mwm_border_w
-
2455 if (cr
->value_mask
& CWWidth
)
2456 cw
= cr
->width
+ (frame
.mwm_border_w
* 2);
2458 if (cr
->value_mask
& CWHeight
)
2459 ch
= cr
->height
+ frame
.y_border
+ (frame
.mwm_border_w
* 2) +
2460 (frame
.border_w
* decorations
.handle
) + frame
.handle_h
;
2462 if (frame
.x
!= cx
|| frame
.y
!= cy
||
2463 frame
.width
!= cw
|| frame
.height
!= ch
)
2464 configure(cx
, cy
, cw
, ch
);
2466 if (cr
->value_mask
& CWStackMode
) {
2467 switch (cr
->detail
) {
2471 if (flags
.iconic
) deiconify();
2472 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2477 if (flags
.iconic
) deiconify();
2478 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2488 void OpenboxWindow::buttonPressEvent(XButtonEvent
*be
) {
2490 if (! validateClient())
2493 int stack_change
= 1; // < 0 means to lower the window
2494 // > 0 means to raise the window
2495 // 0 means to leave it where it is
2497 // alt + left/right click begins interactively moving/resizing the window
2498 // when the mouse is moved
2499 if (be
->state
== Mod1Mask
&& (be
->button
== 1 || be
->button
== 3)) {
2500 if (be
->button
== 3) {
2501 if (screen
->getWindowZones() == 4 &&
2502 be
->y
< (signed) frame
.height
/ 2) {
2503 resize_zone
= ZoneTop
;
2505 resize_zone
= ZoneBottom
;
2507 if (screen
->getWindowZones() >= 2 &&
2508 be
->x
< (signed) frame
.width
/ 2) {
2509 resize_zone
|= ZoneLeft
;
2511 resize_zone
|= ZoneRight
;
2514 // control + left click on the titlebar shades the window
2515 } else if (be
->state
== ControlMask
&& be
->button
== 1) {
2516 if (be
->window
== frame
.title
||
2517 be
->window
== frame
.label
)
2520 } else if (be
->state
== 0 && be
->button
== 1) {
2521 if (windowmenu
&& windowmenu
->isVisible())
2524 if (be
->window
== frame
.maximize_button
) {
2525 redrawMaximizeButton(True
);
2526 } else if (be
->window
== frame
.iconify_button
) {
2527 redrawIconifyButton(True
);
2528 } else if (be
->window
== frame
.close_button
) {
2529 redrawCloseButton(True
);
2530 } else if (be
->window
== frame
.plate
) {
2531 XAllowEvents(display
, ReplayPointer
, be
->time
);
2532 } else if (be
->window
== frame
.title
||
2533 be
->window
== frame
.label
) {
2534 // shade the window when the titlebar is double clicked
2535 if ( (be
->time
- lastButtonPressTime
) <=
2536 openbox
.getDoubleClickInterval()) {
2537 lastButtonPressTime
= 0;
2540 lastButtonPressTime
= be
->time
;
2542 // clicking and dragging on the titlebar moves the window, so on a click
2543 // we need to save the coords of the click in case the user drags
2544 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2545 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2546 } else if (be
->window
== frame
.handle
||
2547 be
->window
== frame
.left_grip
||
2548 be
->window
== frame
.right_grip
||
2549 be
->window
== frame
.window
) {
2550 // clicking and dragging on the window's frame moves the window, so on a
2551 // click we need to save the coords of the click in case the user drags
2552 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2553 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2554 if (be
->window
== frame
.left_grip
)
2555 resize_zone
= ZoneBottom
| ZoneLeft
;
2556 else if (be
->window
== frame
.right_grip
)
2557 resize_zone
= ZoneBottom
| ZoneRight
;
2560 } else if (be
->state
== 0 && be
->button
== 2) {
2561 if (be
->window
== frame
.maximize_button
) {
2562 redrawMaximizeButton(True
);
2563 // a middle click anywhere on the window's frame except for on the buttons
2564 // will lower the window
2565 } else if (! (be
->window
== frame
.iconify_button
||
2566 be
->window
== frame
.close_button
) ) {
2570 } else if (be
->state
== 0 && be
->button
== 3) {
2571 if (be
->window
== frame
.maximize_button
) {
2572 redrawMaximizeButton(True
);
2573 // a right click on the window's frame will show or hide the window's
2575 } else if (be
->window
== frame
.title
||
2576 be
->window
== frame
.label
||
2577 be
->window
== frame
.handle
||
2578 be
->window
== frame
.window
) {
2581 if (windowmenu
->isVisible()) {
2584 // get the coords for the menu
2585 mx
= be
->x_root
- windowmenu
->getWidth() / 2;
2586 if (be
->window
== frame
.title
|| be
->window
== frame
.label
) {
2587 my
= frame
.y
+ frame
.title_h
;
2588 } else if (be
->window
== frame
.handle
) {
2589 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2590 } else { // (be->window == frame.window)
2591 if (be
->y
<= (signed) frame
.bevel_w
) {
2592 my
= frame
.y
+ frame
.y_border
;
2594 my
= be
->y_root
- (windowmenu
->getHeight() / 2);
2598 if (mx
> (signed) (frame
.x
+ frame
.width
-
2599 windowmenu
->getWidth())) {
2600 mx
= frame
.x
+ frame
.width
- windowmenu
->getWidth();
2601 } else if (mx
< frame
.x
) {
2605 if (my
> (signed) (frame
.y
+ frame
.y_handle
-
2606 windowmenu
->getHeight())) {
2607 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2608 } else if (my
< (signed) (frame
.y
+
2609 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
))) {
2611 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
);
2614 windowmenu
->move(mx
, my
);
2616 XRaiseWindow(display
, windowmenu
->getWindowID());
2617 XRaiseWindow(display
, windowmenu
->getSendToMenu()->getWindowID());
2618 stack_change
= 0; // dont raise the window overtop of the menu
2623 } else if (be
->state
== 0 && be
->button
== 4) {
2624 if ((be
->window
== frame
.label
||
2625 be
->window
== frame
.title
) &&
2629 } else if (be
->state
== 0 && be
->button
== 5) {
2630 if ((be
->window
== frame
.label
||
2631 be
->window
== frame
.title
) &&
2636 if (! (flags
.focused
|| screen
->sloppyFocus()) ) {
2637 setInputFocus(); // any click focus' the window in 'click to focus'
2639 if (stack_change
< 0) {
2640 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2641 } else if (stack_change
> 0) {
2642 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2649 void OpenboxWindow::buttonReleaseEvent(XButtonEvent
*re
) {
2651 if (! validateClient())
2654 // alt + middle button released
2655 if (re
->state
== (Mod1Mask
& Button2Mask
) && re
->button
== 2) {
2656 if (re
->window
== frame
.window
) {
2657 XUngrabPointer(display
, CurrentTime
); // why? i dont know
2659 // left button released
2660 } else if (re
->button
== 1) {
2661 if (re
->window
== frame
.maximize_button
) {
2662 if (re
->state
== Button1Mask
&& // only the left button was depressed
2663 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2664 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2665 maximize(re
->button
);
2667 redrawMaximizeButton(False
);
2669 } else if (re
->window
== frame
.iconify_button
) {
2670 if (re
->state
== Button1Mask
&& // only the left button was depressed
2671 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2672 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2675 redrawIconifyButton(False
);
2677 } else if (re
->window
== frame
.close_button
) {
2678 if (re
->state
== Button1Mask
&& // only the left button was depressed
2679 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2680 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2683 //we should always redraw the close button. some applications
2684 //eg. acroread don't honour the close.
2685 redrawCloseButton(False
);
2687 // middle button released
2688 } else if (re
->button
== 2) {
2689 if (re
->window
== frame
.maximize_button
) {
2690 if (re
->state
== Button2Mask
&& // only the middle button was depressed
2691 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2692 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2693 maximize(re
->button
);
2695 redrawMaximizeButton(False
);
2698 // right button released
2699 } else if (re
->button
== 3) {
2700 if (re
->window
== frame
.maximize_button
) {
2701 if (re
->state
== Button3Mask
&& // only the right button was depressed
2702 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2703 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2704 maximize(re
->button
);
2706 redrawMaximizeButton(False
);
2711 // when the window is being interactively moved, a button release stops the
2715 // when the window is being interactively resized, a button release stops the
2717 } else if (flags
.resizing
) {
2718 flags
.resizing
= False
;
2719 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2720 frame
.resize_x
, frame
.resize_y
,
2721 frame
.resize_w
- 1, frame
.resize_h
- 1);
2722 screen
->hideGeometry();
2723 if (resize_zone
& ZoneLeft
) {
2725 } else { // when resizing with "Alt+Button3", the resize is the same as if
2726 // done with the right grip (the right side of the window is what
2730 // unset maximized state when resized after fully maximized
2731 if (flags
.maximized
== 1) {
2734 configure(frame
.resize_x
, frame
.resize_y
,
2735 frame
.resize_w
- (frame
.border_w
* 2),
2736 frame
.resize_h
- (frame
.border_w
* 2));
2738 XUngrabPointer(display
, CurrentTime
);
2746 void OpenboxWindow::startMove(int x
, int y
) {
2747 ASSERT(!flags
.moving
);
2749 // make sure only one window is moving at a time
2750 OpenboxWindow
*w
= openbox
.getMaskedWindow();
2751 if (w
!= (OpenboxWindow
*) 0 && w
->flags
.moving
)
2754 XGrabPointer(display
, frame
.window
, False
, PointerMotionMask
|
2755 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
,
2756 None
, openbox
.getMoveCursor(), CurrentTime
);
2758 if (windowmenu
&& windowmenu
->isVisible())
2761 flags
.moving
= True
;
2763 openbox
.maskWindowEvents(client
.window
, this);
2765 if (! screen
->opaqueMove()) {
2768 frame
.move_x
= frame
.x
;
2769 frame
.move_y
= frame
.y
;
2770 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2771 frame
.resize_h
= ((flags
.shaded
) ? frame
.title_h
: frame
.height
) +
2772 (frame
.border_w
* 2);
2774 screen
->showPosition(frame
.x
, frame
.y
);
2776 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2777 frame
.move_x
, frame
.move_y
,
2778 frame
.resize_w
- 1, frame
.resize_h
- 1);
2780 frame
.grab_x
= x
- frame
.x
- frame
.border_w
;
2781 frame
.grab_y
= y
- frame
.y
- frame
.border_w
;
2785 void OpenboxWindow::doMove(int x
, int y
) {
2786 ASSERT(flags
.moving
);
2788 int dx
= x
- frame
.grab_x
, dy
= y
- frame
.grab_y
;
2790 dx
-= frame
.border_w
;
2791 dy
-= frame
.border_w
;
2793 int snap_distance
= screen
->edgeSnapThreshold();
2794 // width/height of the snapping window
2795 unsigned int snap_w
= frame
.width
+ (frame
.border_w
* 2);
2796 unsigned int snap_h
= area().h() + (frame
.border_w
* 2);
2797 if (snap_distance
) {
2798 int drx
= screen
->size().w() - (dx
+ snap_w
);
2800 if (dx
< drx
&& (dx
> 0 && dx
< snap_distance
) ||
2801 (dx
< 0 && dx
> -snap_distance
) )
2803 else if ( (drx
> 0 && drx
< snap_distance
) ||
2804 (drx
< 0 && drx
> -snap_distance
) )
2805 dx
= screen
->size().w() - snap_w
;
2807 int dtty
, dbby
, dty
, dby
;
2808 switch (screen
->getToolbar()->placement()) {
2809 case Toolbar::TopLeft
:
2810 case Toolbar::TopCenter
:
2811 case Toolbar::TopRight
:
2812 dtty
= screen
->getToolbar()->getExposedHeight() +
2814 dbby
= screen
->size().h();
2819 dbby
= screen
->getToolbar()->area().y();
2824 dby
= dbby
- (dy
+ snap_h
);
2826 if ( (dy
> 0 && dty
< snap_distance
) ||
2827 (dy
< 0 && dty
> -snap_distance
) )
2829 else if ( (dby
> 0 && dby
< snap_distance
) ||
2830 (dby
< 0 && dby
> -snap_distance
) )
2834 if (screen
->opaqueMove()) {
2835 configure(dx
, dy
, frame
.width
, frame
.height
);
2837 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2838 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2839 frame
.resize_h
- 1);
2844 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2845 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2846 frame
.resize_h
- 1);
2849 screen
->showPosition(dx
, dy
);
2853 void OpenboxWindow::endMove() {
2854 ASSERT(flags
.moving
);
2856 flags
.moving
= False
;
2858 openbox
.maskWindowEvents(0, (OpenboxWindow
*) 0);
2859 if (!screen
->opaqueMove()) {
2860 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2861 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2862 frame
.resize_h
- 1);
2864 configure(frame
.move_x
, frame
.move_y
, frame
.width
, frame
.height
);
2867 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
2869 screen
->hideGeometry();
2870 XUngrabPointer(display
, CurrentTime
);
2871 // if there are any left over motions from the move, drop them now cuz they
2874 while (XCheckTypedWindowEvent(display
, frame
.window
, MotionNotify
, &e
));
2878 void OpenboxWindow::motionNotifyEvent(XMotionEvent
*me
) {
2880 doMove(me
->x_root
, me
->y_root
);
2881 else if (!flags
.resizing
&& (me
->state
& Button1Mask
) && functions
.move
&&
2882 (frame
.title
== me
->window
|| frame
.label
== me
->window
||
2883 frame
.handle
== me
->window
|| frame
.window
== me
->window
))
2884 startMove(me
->x_root
, me
->y_root
);
2885 else if (functions
.resize
&&
2886 (((me
->state
& Button1Mask
) && (me
->window
== frame
.right_grip
||
2887 me
->window
== frame
.left_grip
)) ||
2888 (me
->state
== (Mod1Mask
| Button3Mask
) &&
2889 me
->window
== frame
.window
))) {
2890 Bool left
= resize_zone
& ZoneLeft
;
2892 if (! flags
.resizing
) {
2894 if (resize_zone
& ZoneTop
)
2895 cursor
= (resize_zone
& ZoneLeft
) ?
2896 openbox
.getUpperLeftAngleCursor() :
2897 openbox
.getUpperRightAngleCursor();
2899 cursor
= (resize_zone
& ZoneLeft
) ?
2900 openbox
.getLowerLeftAngleCursor() :
2901 openbox
.getLowerRightAngleCursor();
2902 XGrabPointer(display
, me
->window
, False
, ButtonMotionMask
|
2903 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
,
2904 cursor
, CurrentTime
);
2906 flags
.resizing
= True
;
2911 if (resize_zone
& ZoneRight
)
2912 frame
.grab_x
= me
->x
- screen
->getBorderWidth();
2914 frame
.grab_x
= me
->x
+ screen
->getBorderWidth();
2915 if (resize_zone
& ZoneTop
)
2916 frame
.grab_y
= me
->y
+ screen
->getBorderWidth() * 2;
2918 frame
.grab_y
= me
->y
- screen
->getBorderWidth() * 2;
2919 frame
.resize_x
= frame
.x
;
2920 frame
.resize_y
= frame
.y
;
2921 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2922 frame
.resize_h
= frame
.height
+ (frame
.border_w
* 2);
2925 left_fixsize(&gx
, &gy
);
2927 right_fixsize(&gx
, &gy
);
2929 screen
->showGeometry(gx
, gy
);
2931 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2932 frame
.resize_x
, frame
.resize_y
,
2933 frame
.resize_w
- 1, frame
.resize_h
- 1);
2935 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2936 frame
.resize_x
, frame
.resize_y
,
2937 frame
.resize_w
- 1, frame
.resize_h
- 1);
2941 if (resize_zone
& ZoneTop
)
2942 frame
.resize_h
= frame
.height
- (me
->y
- frame
.grab_y
);
2944 frame
.resize_h
= frame
.height
+ (me
->y
- frame
.grab_y
);
2945 if (frame
.resize_h
< 1) frame
.resize_h
= 1;
2948 frame
.resize_x
= me
->x_root
- frame
.grab_x
;
2949 if (frame
.resize_x
> (signed) (frame
.x
+ frame
.width
))
2950 frame
.resize_x
= frame
.resize_x
+ frame
.width
- 1;
2952 left_fixsize(&gx
, &gy
);
2954 frame
.resize_w
= frame
.width
+ (me
->x
- frame
.grab_x
);
2955 if (frame
.resize_w
< 1) frame
.resize_w
= 1;
2957 right_fixsize(&gx
, &gy
);
2960 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2961 frame
.resize_x
, frame
.resize_y
,
2962 frame
.resize_w
- 1, frame
.resize_h
- 1);
2964 screen
->showGeometry(gx
, gy
);
2971 void OpenboxWindow::shapeEvent(XShapeEvent
*) {
2972 if (openbox
.hasShapeExtensions()) {
2975 if (! validateClient()) return;
2976 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
2977 frame
.mwm_border_w
, frame
.y_border
+
2978 frame
.mwm_border_w
, client
.window
,
2979 ShapeBounding
, ShapeSet
);
2982 XRectangle xrect
[2];
2983 xrect
[0].x
= xrect
[0].y
= 0;
2984 xrect
[0].width
= frame
.width
;
2985 xrect
[0].height
= frame
.y_border
;
2987 if (decorations
.handle
) {
2989 xrect
[1].y
= frame
.y_handle
;
2990 xrect
[1].width
= frame
.width
;
2991 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
2995 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
2996 xrect
, num
, ShapeUnion
, Unsorted
);
3004 bool OpenboxWindow::validateClient(void) {
3005 XSync(display
, False
);
3008 if (XCheckTypedWindowEvent(display
, client
.window
, DestroyNotify
, &e
) ||
3009 XCheckTypedWindowEvent(display
, client
.window
, UnmapNotify
, &e
)) {
3010 XPutBackEvent(display
, &e
);
3020 void OpenboxWindow::restore(void) {
3021 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
3022 XSelectInput(display
, client
.window
, NoEventMask
);
3026 XUnmapWindow(display
, frame
.window
);
3027 XUnmapWindow(display
, client
.window
);
3029 XSetWindowBorderWidth(display
, client
.window
, client
.old_bw
);
3030 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
3031 client
.x
, client
.y
);
3032 XMapWindow(display
, client
.window
);
3040 void OpenboxWindow::timeout(void) {
3041 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
3045 void OpenboxWindow::changeOpenboxHints(OpenboxHints
*net
) {
3046 if ((net
->flags
& AttribShaded
) &&
3047 ((openbox_attrib
.attrib
& AttribShaded
) !=
3048 (net
->attrib
& AttribShaded
)))
3051 if (flags
.visible
&& // watch out for requests when we can not be seen
3052 (net
->flags
& (AttribMaxVert
| AttribMaxHoriz
)) &&
3053 ((openbox_attrib
.attrib
& (AttribMaxVert
| AttribMaxHoriz
)) !=
3054 (net
->attrib
& (AttribMaxVert
| AttribMaxHoriz
)))) {
3055 if (flags
.maximized
) {
3060 if ((net
->flags
& AttribMaxHoriz
) && (net
->flags
& AttribMaxVert
))
3061 button
= ((net
->attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0);
3062 else if (net
->flags
& AttribMaxVert
)
3063 button
= ((net
->attrib
& AttribMaxVert
) ? 2 : 0);
3064 else if (net
->flags
& AttribMaxHoriz
)
3065 button
= ((net
->attrib
& AttribMaxHoriz
) ? 3 : 0);
3071 if ((net
->flags
& AttribOmnipresent
) &&
3072 ((openbox_attrib
.attrib
& AttribOmnipresent
) !=
3073 (net
->attrib
& AttribOmnipresent
)))
3076 if ((net
->flags
& AttribWorkspace
) &&
3077 (workspace_number
!= (signed) net
->workspace
)) {
3078 screen
->reassociateWindow(this, net
->workspace
, True
);
3080 if (screen
->getCurrentWorkspaceID() != (signed) net
->workspace
) withdraw();
3084 if (net
->flags
& AttribDecoration
) {
3085 switch (net
->decoration
) {
3087 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3088 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= False
;
3094 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
=
3095 decorations
.border
= True
;
3096 decorations
.handle
= (functions
.resize
&& !flags
.transient
);
3097 decorations
.maximize
= functions
.maximize
;
3102 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
= True
;
3103 decorations
.border
= decorations
.border
= decorations
.handle
= False
;
3104 decorations
.maximize
= functions
.maximize
;
3109 decorations
.titlebar
= decorations
.menu
= True
;
3110 decorations
.iconify
= decorations
.border
= False
;
3111 decorations
.handle
= (functions
.resize
&& !flags
.transient
);
3112 decorations
.maximize
= functions
.maximize
;
3117 XMapSubwindows(display
, frame
.window
);
3118 XMapWindow(display
, frame
.window
);
3122 setState(current_state
);
3128 * Set the sizes of all components of the window frame
3129 * (the window decorations).
3130 * These values are based upon the current style settings and the client
3131 * window's dimentions.
3133 void OpenboxWindow::upsize(void) {
3134 frame
.bevel_w
= screen
->getBevelWidth();
3136 if (decorations
.border
) {
3137 frame
.border_w
= screen
->getBorderWidth();
3138 if (!flags
.transient
)
3139 frame
.mwm_border_w
= screen
->getFrameWidth();
3141 frame
.mwm_border_w
= 0;
3143 frame
.mwm_border_w
= frame
.border_w
= 0;
3146 if (decorations
.titlebar
) {
3147 // the height of the titlebar is based upon the height of the font being
3148 // used to display the window's title
3149 WindowStyle
*style
= screen
->getWindowStyle();
3150 if (i18n
->multibyte())
3151 frame
.title_h
= (style
->fontset_extents
->max_ink_extent
.height
+
3152 (frame
.bevel_w
* 2) + 2);
3154 frame
.title_h
= (style
->font
->ascent
+ style
->font
->descent
+
3155 (frame
.bevel_w
* 2) + 2);
3157 frame
.label_h
= frame
.title_h
- (frame
.bevel_w
* 2);
3158 frame
.button_w
= frame
.button_h
= (frame
.label_h
- 2);
3159 frame
.y_border
= frame
.title_h
+ frame
.border_w
;
3163 frame
.button_w
= frame
.button_h
= 0;
3167 frame
.border_h
= client
.height
+ frame
.mwm_border_w
* 2;
3169 if (decorations
.handle
) {
3170 frame
.y_handle
= frame
.y_border
+ frame
.border_h
+ frame
.border_w
;
3171 frame
.grip_w
= frame
.button_w
* 2;
3172 frame
.grip_h
= frame
.handle_h
= screen
->getHandleWidth();
3174 frame
.y_handle
= frame
.y_border
+ frame
.border_h
;
3176 frame
.grip_w
= frame
.grip_h
= 0;
3179 frame
.width
= client
.width
+ (frame
.mwm_border_w
* 2);
3180 frame
.height
= frame
.y_handle
+ frame
.handle_h
;
3185 * Set the size and position of the client window.
3186 * These values are based upon the current style settings and the frame
3187 * window's dimensions.
3189 void OpenboxWindow::downsize(void) {
3190 frame
.y_handle
= frame
.height
- frame
.handle_h
;
3191 frame
.border_h
= frame
.y_handle
- frame
.y_border
-
3192 (decorations
.handle
? frame
.border_w
: 0);
3194 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
3195 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+ frame
.border_w
;
3197 client
.width
= frame
.width
- (frame
.mwm_border_w
* 2);
3198 client
.height
= frame
.height
- frame
.y_border
- (frame
.mwm_border_w
* 2)
3199 - frame
.handle_h
- (decorations
.handle
? frame
.border_w
: 0);
3201 frame
.y_handle
= frame
.border_h
+ frame
.y_border
+ frame
.border_w
;
3205 void OpenboxWindow::right_fixsize(int *gx
, int *gy
) {
3206 // calculate the size of the client window and conform it to the
3207 // size specified by the size hints of the client window...
3208 int dx
= frame
.resize_w
- client
.base_width
- (frame
.mwm_border_w
* 2) -
3209 (frame
.border_w
* 2) + (client
.width_inc
/ 2);
3210 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3211 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3212 + (client
.height_inc
/ 2);
3214 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3215 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3216 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3217 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3219 dx
/= client
.width_inc
;
3220 dy
/= client
.height_inc
;
3225 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3226 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3228 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3229 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3230 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3231 if (resize_zone
& ZoneTop
)
3232 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3233 screen
->getBorderWidth() * 2;
3237 void OpenboxWindow::left_fixsize(int *gx
, int *gy
) {
3238 // calculate the size of the client window and conform it to the
3239 // size specified by the size hints of the client window...
3240 int dx
= frame
.x
+ frame
.width
- frame
.resize_x
- client
.base_width
-
3241 (frame
.mwm_border_w
* 2) + (client
.width_inc
/ 2);
3242 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3243 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3244 + (client
.height_inc
/ 2);
3246 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3247 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3248 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3249 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3251 dx
/= client
.width_inc
;
3252 dy
/= client
.height_inc
;
3257 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3258 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3260 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3261 frame
.resize_x
= frame
.x
+ frame
.width
- frame
.resize_w
+
3262 (frame
.border_w
* 2);
3263 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3264 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3265 if (resize_zone
& ZoneTop
)
3266 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3267 screen
->getBorderWidth() * 2;