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"
59 * Initializes the class with default values/the window's set initial values.
61 OpenboxWindow::OpenboxWindow(Openbox
&o
, Window w
, BScreen
*s
) : openbox(o
) {
63 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowCreating
,
64 "OpenboxWindow::OpenboxWindow(): creating 0x%lx\n"),
69 display
= openbox
.getXDisplay();
72 if (! validateClient()) return;
74 // fetch client size and placement
75 XWindowAttributes wattrib
;
76 if ((! XGetWindowAttributes(display
, client
.window
, &wattrib
)) ||
77 (! wattrib
.screen
) || wattrib
.override_redirect
) {
80 i18n
->getMessage(WindowSet
, WindowXGetWindowAttributesFail
,
81 "OpenboxWindow::OpenboxWindow(): XGetWindowAttributes "
92 screen
= openbox
.searchScreen(RootWindowOfScreen(wattrib
.screen
));
95 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowCannotFindScreen
,
96 "OpenboxWindow::OpenboxWindow(): can't find screen\n"
97 "\tfor root window 0x%lx\n"),
98 RootWindowOfScreen(wattrib
.screen
));
106 flags
.moving
= flags
.resizing
= flags
.shaded
= flags
.visible
=
107 flags
.iconic
= flags
.transient
= flags
.focused
=
108 flags
.stuck
= flags
.modal
= flags
.send_focus_message
=
109 flags
.shaped
= flags
.managed
= False
;
112 openbox_attrib
.workspace
= workspace_number
= window_number
= -1;
114 openbox_attrib
.flags
= openbox_attrib
.attrib
= openbox_attrib
.stack
115 = openbox_attrib
.decoration
= 0l;
116 openbox_attrib
.premax_x
= openbox_attrib
.premax_y
= 0;
117 openbox_attrib
.premax_w
= openbox_attrib
.premax_h
= 0;
119 frame
.window
= frame
.plate
= frame
.title
= frame
.handle
= None
;
120 frame
.close_button
= frame
.iconify_button
= frame
.maximize_button
= None
;
121 frame
.right_grip
= frame
.left_grip
= None
;
123 frame
.utitle
= frame
.ftitle
= frame
.uhandle
= frame
.fhandle
= None
;
124 frame
.ulabel
= frame
.flabel
= frame
.ubutton
= frame
.fbutton
= None
;
125 frame
.pbutton
= frame
.ugrip
= frame
.fgrip
= None
;
127 decorations
.titlebar
= decorations
.border
= decorations
.handle
= True
;
128 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= True
;
129 functions
.resize
= functions
.move
= functions
.iconify
=
130 functions
.maximize
= True
;
131 functions
.close
= decorations
.close
= False
;
133 client
.wm_hint_flags
= client
.normal_hint_flags
= 0;
134 client
.transient_for
= client
.transient
= 0;
136 client
.title_len
= 0;
137 client
.icon_title
= 0;
138 client
.mwm_hint
= (MwmHints
*) 0;
139 client
.openbox_hint
= (OpenboxHints
*) 0;
141 // get the initial size and location of client window (relative to the
142 // _root window_). This position is the reference point used with the
143 // window's gravity to find the window's initial position.
144 client
.x
= wattrib
.x
;
145 client
.y
= wattrib
.y
;
146 client
.width
= wattrib
.width
;
147 client
.height
= wattrib
.height
;
148 client
.old_bw
= wattrib
.border_width
;
151 lastButtonPressTime
= 0;
152 image_ctrl
= screen
->getImageControl();
154 timer
= new BTimer(openbox
, *this);
155 timer
->setTimeout(openbox
.getAutoRaiseDelay());
156 timer
->fireOnce(True
);
159 if (! client
.openbox_hint
)
162 // get size, aspect, minimum/maximum size and other hints set by the
169 if (client
.initial_state
== WithdrawnState
) {
170 screen
->getSlit()->addClient(client
.window
);
177 flags
.managed
= True
;
178 openbox
.saveWindowSearch(client
.window
, this);
180 // determine if this is a transient window
182 if (XGetTransientForHint(display
, client
.window
, &win
)) {
183 if (win
&& (win
!= client
.window
)) {
185 if ((tr
= openbox
.searchWindow(win
))) {
186 while (tr
->client
.transient
) tr
= tr
->client
.transient
;
187 client
.transient_for
= tr
;
188 tr
->client
.transient
= this;
189 flags
.stuck
= client
.transient_for
->flags
.stuck
;
190 flags
.transient
= True
;
191 } else if (win
== client
.window_group
) {
192 if ((tr
= openbox
.searchGroup(win
, this))) {
193 while (tr
->client
.transient
) tr
= tr
->client
.transient
;
194 client
.transient_for
= tr
;
195 tr
->client
.transient
= this;
196 flags
.stuck
= client
.transient_for
->flags
.stuck
;
197 flags
.transient
= True
;
202 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
205 // adjust the window decorations based on transience and window sizes
207 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
209 if ((client
.normal_hint_flags
& PMinSize
) &&
210 (client
.normal_hint_flags
& PMaxSize
) &&
211 client
.max_width
<= client
.min_width
&&
212 client
.max_height
<= client
.min_height
) {
213 decorations
.maximize
= decorations
.handle
=
214 functions
.resize
= functions
.maximize
= False
;
218 Bool place_window
= True
;
219 if (openbox
.isStartup() || flags
.transient
||
220 client
.normal_hint_flags
& (PPosition
|USPosition
)) {
223 if ((openbox
.isStartup()) ||
225 (signed) (frame
.y
+ frame
.y_border
) >= 0 &&
226 frame
.x
<= (signed) screen
->size().w() &&
227 frame
.y
<= (signed) screen
->size().h()))
228 place_window
= False
;
231 frame
.window
= createToplevelWindow(frame
.x
, frame
.y
, frame
.width
,
234 openbox
.saveWindowSearch(frame
.window
, this);
236 frame
.plate
= createChildWindow(frame
.window
);
237 openbox
.saveWindowSearch(frame
.plate
, this);
239 if (decorations
.titlebar
) {
240 frame
.title
= createChildWindow(frame
.window
);
241 frame
.label
= createChildWindow(frame
.title
);
242 openbox
.saveWindowSearch(frame
.title
, this);
243 openbox
.saveWindowSearch(frame
.label
, this);
246 if (decorations
.handle
) {
247 frame
.handle
= createChildWindow(frame
.window
);
248 openbox
.saveWindowSearch(frame
.handle
, this);
251 createChildWindow(frame
.handle
, openbox
.getLowerLeftAngleCursor());
252 openbox
.saveWindowSearch(frame
.left_grip
, this);
255 createChildWindow(frame
.handle
, openbox
.getLowerRightAngleCursor());
256 openbox
.saveWindowSearch(frame
.right_grip
, this);
259 associateClientWindow();
261 if (! screen
->sloppyFocus())
262 openbox
.grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
263 GrabModeSync
, GrabModeSync
, None
, None
);
265 openbox
.grabButton(Button1
, Mod1Mask
, frame
.window
, True
,
266 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
267 GrabModeAsync
, None
, openbox
.getMoveCursor());
268 openbox
.grabButton(Button2
, Mod1Mask
, frame
.window
, True
,
269 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
, None
);
270 openbox
.grabButton(Button3
, Mod1Mask
, frame
.window
, True
,
271 ButtonReleaseMask
| ButtonMotionMask
, GrabModeAsync
,
272 GrabModeAsync
, None
, None
);
275 XRaiseWindow(display
, frame
.plate
);
276 XMapSubwindows(display
, frame
.plate
);
277 if (decorations
.titlebar
) XMapSubwindows(display
, frame
.title
);
278 XMapSubwindows(display
, frame
.window
);
280 if (decorations
.menu
)
281 windowmenu
= new Windowmenu(*this);
285 if (workspace_number
< 0 || workspace_number
>= screen
->getWorkspaceCount())
286 screen
->getCurrentWorkspace()->addWindow(this, place_window
);
288 screen
->getWorkspace(workspace_number
)->addWindow(this, place_window
);
290 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
293 flags
.shaded
= False
;
297 if (flags
.maximized
&& functions
.maximize
) {
298 unsigned int button
= flags
.maximized
;
309 OpenboxWindow::~OpenboxWindow(void) {
310 if (flags
.moving
|| flags
.resizing
) {
311 screen
->hideGeometry();
312 XUngrabPointer(display
, CurrentTime
);
315 if (workspace_number
!= -1 && window_number
!= -1)
316 screen
->getWorkspace(workspace_number
)->removeWindow(this);
317 else if (flags
.iconic
)
318 screen
->removeIcon(this);
321 if (timer
->isTiming()) timer
->stop();
325 if (windowmenu
) delete windowmenu
;
328 delete [] client
.title
;
330 if (client
.icon_title
)
331 delete [] client
.icon_title
;
334 XFree(client
.mwm_hint
);
336 if (client
.openbox_hint
)
337 XFree(client
.openbox_hint
);
339 if (client
.window_group
)
340 openbox
.removeGroupSearch(client
.window_group
);
342 if (flags
.transient
&& client
.transient_for
)
343 client
.transient_for
->client
.transient
= client
.transient
;
344 if (client
.transient
)
345 client
.transient
->client
.transient_for
= client
.transient_for
;
347 if (frame
.close_button
) {
348 openbox
.removeWindowSearch(frame
.close_button
);
349 XDestroyWindow(display
, frame
.close_button
);
352 if (frame
.iconify_button
) {
353 openbox
.removeWindowSearch(frame
.iconify_button
);
354 XDestroyWindow(display
, frame
.iconify_button
);
357 if (frame
.maximize_button
) {
358 openbox
.removeWindowSearch(frame
.maximize_button
);
359 XDestroyWindow(display
, frame
.maximize_button
);
364 image_ctrl
->removeImage(frame
.ftitle
);
367 image_ctrl
->removeImage(frame
.utitle
);
370 image_ctrl
->removeImage(frame
.flabel
);
373 image_ctrl
->removeImage(frame
.ulabel
);
375 openbox
.removeWindowSearch(frame
.label
);
376 openbox
.removeWindowSearch(frame
.title
);
377 XDestroyWindow(display
, frame
.label
);
378 XDestroyWindow(display
, frame
.title
);
383 image_ctrl
->removeImage(frame
.fhandle
);
386 image_ctrl
->removeImage(frame
.uhandle
);
389 image_ctrl
->removeImage(frame
.fgrip
);
392 image_ctrl
->removeImage(frame
.ugrip
);
394 openbox
.removeWindowSearch(frame
.handle
);
395 openbox
.removeWindowSearch(frame
.right_grip
);
396 openbox
.removeWindowSearch(frame
.left_grip
);
397 XDestroyWindow(display
, frame
.right_grip
);
398 XDestroyWindow(display
, frame
.left_grip
);
399 XDestroyWindow(display
, frame
.handle
);
403 image_ctrl
->removeImage(frame
.fbutton
);
406 image_ctrl
->removeImage(frame
.ubutton
);
409 image_ctrl
->removeImage(frame
.pbutton
);
412 openbox
.removeWindowSearch(frame
.plate
);
413 XDestroyWindow(display
, frame
.plate
);
417 openbox
.removeWindowSearch(frame
.window
);
418 XDestroyWindow(display
, frame
.window
);
422 openbox
.removeWindowSearch(client
.window
);
423 screen
->removeNetizen(client
.window
);
429 * Creates a new top level window, with a given location, size, and border
431 * Returns: the newly created window
433 Window
OpenboxWindow::createToplevelWindow(int x
, int y
, unsigned int width
,
435 unsigned int borderwidth
)
437 XSetWindowAttributes attrib_create
;
438 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
| CWColormap
|
439 CWOverrideRedirect
| CWEventMask
;
441 attrib_create
.background_pixmap
= None
;
442 attrib_create
.colormap
= screen
->getColormap();
443 attrib_create
.override_redirect
= True
;
444 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
445 ButtonMotionMask
| EnterWindowMask
;
447 return XCreateWindow(display
, screen
->getRootWindow(), x
, y
, width
, height
,
448 borderwidth
, screen
->getDepth(), InputOutput
,
449 screen
->getVisual(), create_mask
,
455 * Creates a child window, and optionally associates a given cursor with
458 Window
OpenboxWindow::createChildWindow(Window parent
, Cursor cursor
) {
459 XSetWindowAttributes attrib_create
;
460 unsigned long create_mask
= CWBackPixmap
| CWBorderPixel
|
463 attrib_create
.background_pixmap
= None
;
464 attrib_create
.event_mask
= ButtonPressMask
| ButtonReleaseMask
|
465 ButtonMotionMask
| ExposureMask
|
466 EnterWindowMask
| LeaveWindowMask
;
469 create_mask
|= CWCursor
;
470 attrib_create
.cursor
= cursor
;
473 return XCreateWindow(display
, parent
, 0, 0, 1, 1, 0, screen
->getDepth(),
474 InputOutput
, screen
->getVisual(), create_mask
,
479 void OpenboxWindow::associateClientWindow(void) {
480 XSetWindowBorderWidth(display
, client
.window
, 0);
484 XChangeSaveSet(display
, client
.window
, SetModeInsert
);
485 XSetWindowAttributes attrib_set
;
487 XSelectInput(display
, frame
.plate
, NoEventMask
);
488 XReparentWindow(display
, client
.window
, frame
.plate
, 0, 0);
489 XSelectInput(display
, frame
.plate
, SubstructureRedirectMask
);
493 attrib_set
.event_mask
= PropertyChangeMask
| StructureNotifyMask
|
495 attrib_set
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
498 XChangeWindowAttributes(display
, client
.window
, CWEventMask
|CWDontPropagate
,
502 if (openbox
.hasShapeExtensions()) {
503 XShapeSelectInput(display
, client
.window
, ShapeNotifyMask
);
508 XShapeQueryExtents(display
, client
.window
, &flags
.shaped
, &foo
, &foo
,
509 &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
, &ufoo
);
512 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
513 frame
.mwm_border_w
, frame
.y_border
+
514 frame
.mwm_border_w
, client
.window
,
515 ShapeBounding
, ShapeSet
);
519 xrect
[0].x
= xrect
[0].y
= 0;
520 xrect
[0].width
= frame
.width
;
521 xrect
[0].height
= frame
.y_border
;
523 if (decorations
.handle
) {
525 xrect
[1].y
= frame
.y_handle
;
526 xrect
[1].width
= frame
.width
;
527 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
531 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
532 xrect
, num
, ShapeUnion
, Unsorted
);
537 if (decorations
.iconify
) createIconifyButton();
538 if (decorations
.maximize
) createMaximizeButton();
539 if (decorations
.close
) createCloseButton();
542 if (frame
.close_button
)
543 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.ubutton
);
544 if (frame
.maximize_button
)
545 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
547 if (frame
.iconify_button
)
548 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.ubutton
);
550 if (frame
.close_button
)
551 XSetWindowBackground(display
, frame
.close_button
, frame
.ubutton_pixel
);
552 if (frame
.maximize_button
)
553 XSetWindowBackground(display
, frame
.maximize_button
,
554 frame
.ubutton_pixel
);
555 if (frame
.iconify_button
)
556 XSetWindowBackground(display
, frame
.iconify_button
, frame
.ubutton_pixel
);
561 void OpenboxWindow::decorate(void) {
562 Pixmap tmp
= frame
.fbutton
;
563 BTexture
*texture
= &(screen
->getWindowStyle()->b_focus
);
564 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
565 frame
.fbutton
= None
;
566 frame
.fbutton_pixel
= texture
->getColor()->getPixel();
569 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
571 if (tmp
) image_ctrl
->removeImage(tmp
);
574 texture
= &(screen
->getWindowStyle()->b_unfocus
);
575 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
576 frame
.ubutton
= None
;
577 frame
.ubutton_pixel
= texture
->getColor()->getPixel();
580 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
582 if (tmp
) image_ctrl
->removeImage(tmp
);
585 texture
= &(screen
->getWindowStyle()->b_pressed
);
586 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
587 frame
.pbutton
= None
;
588 frame
.pbutton_pixel
= texture
->getColor()->getPixel();
591 image_ctrl
->renderImage(frame
.button_w
, frame
.button_h
, texture
);
593 if (tmp
) image_ctrl
->removeImage(tmp
);
595 if (decorations
.titlebar
) {
597 texture
= &(screen
->getWindowStyle()->t_focus
);
598 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
600 frame
.ftitle_pixel
= texture
->getColor()->getPixel();
603 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
605 if (tmp
) image_ctrl
->removeImage(tmp
);
608 texture
= &(screen
->getWindowStyle()->t_unfocus
);
609 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
611 frame
.utitle_pixel
= texture
->getColor()->getPixel();
614 image_ctrl
->renderImage(frame
.width
, frame
.title_h
, texture
);
616 if (tmp
) image_ctrl
->removeImage(tmp
);
618 XSetWindowBorder(display
, frame
.title
,
619 screen
->getBorderColor()->getPixel());
624 if (decorations
.border
) {
625 frame
.fborder_pixel
= screen
->getWindowStyle()->f_focus
.getPixel();
626 frame
.uborder_pixel
= screen
->getWindowStyle()->f_unfocus
.getPixel();
627 openbox_attrib
.flags
|= AttribDecoration
;
628 openbox_attrib
.decoration
= DecorNormal
;
630 openbox_attrib
.flags
|= AttribDecoration
;
631 openbox_attrib
.decoration
= DecorNone
;
634 if (decorations
.handle
) {
636 texture
= &(screen
->getWindowStyle()->h_focus
);
637 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
638 frame
.fhandle
= None
;
639 frame
.fhandle_pixel
= texture
->getColor()->getPixel();
642 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
644 if (tmp
) image_ctrl
->removeImage(tmp
);
647 texture
= &(screen
->getWindowStyle()->h_unfocus
);
648 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
649 frame
.uhandle
= None
;
650 frame
.uhandle_pixel
= texture
->getColor()->getPixel();
653 image_ctrl
->renderImage(frame
.width
, frame
.handle_h
, texture
);
655 if (tmp
) image_ctrl
->removeImage(tmp
);
658 texture
= &(screen
->getWindowStyle()->g_focus
);
659 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
661 frame
.fgrip_pixel
= texture
->getColor()->getPixel();
664 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
666 if (tmp
) image_ctrl
->removeImage(tmp
);
669 texture
= &(screen
->getWindowStyle()->g_unfocus
);
670 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
672 frame
.ugrip_pixel
= texture
->getColor()->getPixel();
675 image_ctrl
->renderImage(frame
.grip_w
, frame
.grip_h
, texture
);
677 if (tmp
) image_ctrl
->removeImage(tmp
);
679 XSetWindowBorder(display
, frame
.handle
,
680 screen
->getBorderColor()->getPixel());
681 XSetWindowBorder(display
, frame
.left_grip
,
682 screen
->getBorderColor()->getPixel());
683 XSetWindowBorder(display
, frame
.right_grip
,
684 screen
->getBorderColor()->getPixel());
687 XSetWindowBorder(display
, frame
.window
,
688 screen
->getBorderColor()->getPixel());
692 void OpenboxWindow::decorateLabel(void) {
693 Pixmap tmp
= frame
.flabel
;
694 BTexture
*texture
= &(screen
->getWindowStyle()->l_focus
);
695 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
697 frame
.flabel_pixel
= texture
->getColor()->getPixel();
700 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
702 if (tmp
) image_ctrl
->removeImage(tmp
);
705 texture
= &(screen
->getWindowStyle()->l_unfocus
);
706 if (texture
->getTexture() == (BImage_Flat
| BImage_Solid
)) {
708 frame
.ulabel_pixel
= texture
->getColor()->getPixel();
711 image_ctrl
->renderImage(frame
.label_w
, frame
.label_h
, texture
);
713 if (tmp
) image_ctrl
->removeImage(tmp
);
717 void OpenboxWindow::createCloseButton(void) {
718 if (decorations
.close
&& frame
.title
!= None
) {
719 frame
.close_button
= createChildWindow(frame
.title
);
720 openbox
.saveWindowSearch(frame
.close_button
, this);
725 void OpenboxWindow::createIconifyButton(void) {
726 if (decorations
.iconify
&& frame
.title
!= None
) {
727 frame
.iconify_button
= createChildWindow(frame
.title
);
728 openbox
.saveWindowSearch(frame
.iconify_button
, this);
733 void OpenboxWindow::createMaximizeButton(void) {
734 if (decorations
.maximize
&& frame
.title
!= None
) {
735 frame
.maximize_button
= createChildWindow(frame
.title
);
736 openbox
.saveWindowSearch(frame
.maximize_button
, this);
741 void OpenboxWindow::positionButtons(Bool redecorate_label
) {
742 const char *format
= openbox
.getTitleBarLayout();
743 const unsigned int bw
= frame
.bevel_w
+ 1;
744 const unsigned int by
= frame
.bevel_w
+ 1;
745 unsigned int bx
= frame
.bevel_w
+ 1;
746 unsigned int bcount
= strlen(format
) - 1;
748 if (!decorations
.close
)
750 if (!decorations
.maximize
)
752 if (!decorations
.iconify
)
754 frame
.label_w
= frame
.width
- bx
* 2 - (frame
.button_w
+ bw
) * bcount
;
756 bool hasclose
, hasiconify
, hasmaximize
;
757 hasclose
= hasiconify
= hasmaximize
= false;
759 for (int i
= 0; format
[i
] != '\0' && i
< 4; i
++) {
762 if (decorations
.close
&& frame
.close_button
!= None
) {
763 XMoveResizeWindow(display
, frame
.close_button
, bx
, by
,
764 frame
.button_w
, frame
.button_h
);
765 XMapWindow(display
, frame
.close_button
);
766 XClearWindow(display
, frame
.close_button
);
767 bx
+= frame
.button_w
+ bw
;
769 } else if (frame
.close_button
)
770 XUnmapWindow(display
, frame
.close_button
);
773 if (decorations
.iconify
&& frame
.iconify_button
!= None
) {
774 XMoveResizeWindow(display
, frame
.iconify_button
, bx
, by
,
775 frame
.button_w
, frame
.button_h
);
776 XMapWindow(display
, frame
.iconify_button
);
777 XClearWindow(display
, frame
.iconify_button
);
778 bx
+= frame
.button_w
+ bw
;
780 } else if (frame
.close_button
)
781 XUnmapWindow(display
, frame
.close_button
);
784 if (decorations
.maximize
&& frame
.maximize_button
!= None
) {
785 XMoveResizeWindow(display
, frame
.maximize_button
, bx
, by
,
786 frame
.button_w
, frame
.button_h
);
787 XMapWindow(display
, frame
.maximize_button
);
788 XClearWindow(display
, frame
.maximize_button
);
789 bx
+= frame
.button_w
+ bw
;
791 } else if (frame
.close_button
)
792 XUnmapWindow(display
, frame
.close_button
);
795 XMoveResizeWindow(display
, frame
.label
, bx
, by
- 1,
796 frame
.label_w
, frame
.label_h
);
797 bx
+= frame
.label_w
+ bw
;
803 openbox
.removeWindowSearch(frame
.close_button
);
804 XDestroyWindow(display
, frame
.close_button
);
807 openbox
.removeWindowSearch(frame
.iconify_button
);
808 XDestroyWindow(display
, frame
.iconify_button
);
811 openbox
.removeWindowSearch(frame
.maximize_button
);
812 XDestroyWindow(display
, frame
.maximize_button
);
814 if (redecorate_label
)
821 void OpenboxWindow::reconfigure(void) {
824 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
825 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
829 if (i18n
->multibyte()) {
830 XRectangle ink
, logical
;
831 XmbTextExtents(screen
->getWindowStyle()->fontset
,
832 client
.title
, client
.title_len
, &ink
, &logical
);
833 client
.title_text_w
= logical
.width
;
835 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
836 client
.title
, client
.title_len
);
838 client
.title_text_w
+= (frame
.bevel_w
* 4);
844 XClearWindow(display
, frame
.window
);
845 setFocusFlag(flags
.focused
);
847 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
849 if (! screen
->sloppyFocus())
850 openbox
.grabButton(Button1
, 0, frame
.plate
, True
, ButtonPressMask
,
851 GrabModeSync
, GrabModeSync
, None
, None
);
853 openbox
.ungrabButton(Button1
, 0, frame
.plate
);
856 windowmenu
->move(windowmenu
->getX(), frame
.y
+ frame
.title_h
);
857 windowmenu
->reconfigure();
862 void OpenboxWindow::positionWindows(void) {
863 XResizeWindow(display
, frame
.window
, frame
.width
,
864 ((flags
.shaded
) ? frame
.title_h
: frame
.height
));
865 XSetWindowBorderWidth(display
, frame
.window
, frame
.border_w
);
866 XSetWindowBorderWidth(display
, frame
.plate
, frame
.mwm_border_w
);
867 XMoveResizeWindow(display
, frame
.plate
, 0, frame
.y_border
,
868 client
.width
, client
.height
);
869 XMoveResizeWindow(display
, client
.window
, 0, 0, client
.width
, client
.height
);
871 if (decorations
.titlebar
) {
872 XSetWindowBorderWidth(display
, frame
.title
, frame
.border_w
);
873 XMoveResizeWindow(display
, frame
.title
, -frame
.border_w
,
874 -frame
.border_w
, frame
.width
, frame
.title_h
);
877 } else if (frame
.title
) {
878 XUnmapWindow(display
, frame
.title
);
880 if (decorations
.handle
) {
881 XSetWindowBorderWidth(display
, frame
.handle
, frame
.border_w
);
882 XSetWindowBorderWidth(display
, frame
.left_grip
, frame
.border_w
);
883 XSetWindowBorderWidth(display
, frame
.right_grip
, frame
.border_w
);
885 XMoveResizeWindow(display
, frame
.handle
, -frame
.border_w
,
886 frame
.y_handle
- frame
.border_w
,
887 frame
.width
, frame
.handle_h
);
888 XMoveResizeWindow(display
, frame
.left_grip
, -frame
.border_w
,
889 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
890 XMoveResizeWindow(display
, frame
.right_grip
,
891 frame
.width
- frame
.grip_w
- frame
.border_w
,
892 -frame
.border_w
, frame
.grip_w
, frame
.grip_h
);
893 XMapSubwindows(display
, frame
.handle
);
894 } else if (frame
.handle
) {
895 XUnmapWindow(display
, frame
.handle
);
900 void OpenboxWindow::getWMName(void) {
902 delete [] client
.title
;
903 client
.title
= (char *) 0;
906 XTextProperty text_prop
;
910 if (XGetWMName(display
, client
.window
, &text_prop
)) {
911 if (text_prop
.value
&& text_prop
.nitems
> 0) {
912 if (text_prop
.encoding
!= XA_STRING
) {
913 text_prop
.nitems
= strlen((char *) text_prop
.value
);
915 if ((XmbTextPropertyToTextList(display
, &text_prop
,
916 &list
, &num
) == Success
) &&
917 (num
> 0) && *list
) {
918 client
.title
= bstrdup(*list
);
919 XFreeStringList(list
);
921 client
.title
= bstrdup((char *) text_prop
.value
);
924 client
.title
= bstrdup((char *) text_prop
.value
);
926 XFree((char *) text_prop
.value
);
928 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
932 client
.title
= bstrdup(i18n
->getMessage(WindowSet
, WindowUnnamed
,
935 client
.title_len
= strlen(client
.title
);
937 if (i18n
->multibyte()) {
938 XRectangle ink
, logical
;
939 XmbTextExtents(screen
->getWindowStyle()->fontset
,
940 client
.title
, client
.title_len
, &ink
, &logical
);
941 client
.title_text_w
= logical
.width
;
943 client
.title_len
= strlen(client
.title
);
944 client
.title_text_w
= XTextWidth(screen
->getWindowStyle()->font
,
945 client
.title
, client
.title_len
);
948 client
.title_text_w
+= (frame
.bevel_w
* 4);
952 void OpenboxWindow::getWMIconName(void) {
953 if (client
.icon_title
) {
954 delete [] client
.icon_title
;
955 client
.icon_title
= (char *) 0;
958 XTextProperty text_prop
;
962 if (XGetWMIconName(display
, client
.window
, &text_prop
)) {
963 if (text_prop
.value
&& text_prop
.nitems
> 0) {
964 if (text_prop
.encoding
!= XA_STRING
) {
965 text_prop
.nitems
= strlen((char *) text_prop
.value
);
967 if ((XmbTextPropertyToTextList(display
, &text_prop
,
968 &list
, &num
) == Success
) &&
969 (num
> 0) && *list
) {
970 client
.icon_title
= bstrdup(*list
);
971 XFreeStringList(list
);
973 client
.icon_title
= bstrdup((char *) text_prop
.value
);
976 client
.icon_title
= bstrdup((char *) text_prop
.value
);
978 XFree((char *) text_prop
.value
);
980 client
.icon_title
= bstrdup(client
.title
);
983 client
.icon_title
= bstrdup(client
.title
);
989 * Retrieve which WM Protocols are supported by the client window.
990 * If the WM_DELETE_WINDOW protocol is supported, add the close button to the
991 * window's decorations and allow the close behavior.
992 * If the WM_TAKE_FOCUS protocol is supported, save a value that indicates
995 void OpenboxWindow::getWMProtocols(void) {
999 if (XGetWMProtocols(display
, client
.window
, &proto
, &num_return
)) {
1000 for (int i
= 0; i
< num_return
; ++i
) {
1001 if (proto
[i
] == openbox
.getWMDeleteAtom())
1002 functions
.close
= decorations
.close
= True
;
1003 else if (proto
[i
] == openbox
.getWMTakeFocusAtom())
1004 flags
.send_focus_message
= True
;
1005 else if (proto
[i
] == openbox
.getOpenboxStructureMessagesAtom())
1006 screen
->addNetizen(new Netizen(*screen
, client
.window
));
1015 * Gets the value of the WM_HINTS property.
1016 * If the property is not set, then use a set of default values.
1018 void OpenboxWindow::getWMHints(void) {
1019 XWMHints
*wmhint
= XGetWMHints(display
, client
.window
);
1021 flags
.visible
= True
;
1022 flags
.iconic
= False
;
1023 focus_mode
= F_Passive
;
1024 client
.window_group
= None
;
1025 client
.initial_state
= NormalState
;
1028 client
.wm_hint_flags
= wmhint
->flags
;
1029 if (wmhint
->flags
& InputHint
) {
1030 if (wmhint
->input
== True
) {
1031 if (flags
.send_focus_message
)
1032 focus_mode
= F_LocallyActive
;
1034 focus_mode
= F_Passive
;
1036 if (flags
.send_focus_message
)
1037 focus_mode
= F_GloballyActive
;
1039 focus_mode
= F_NoInput
;
1042 focus_mode
= F_Passive
;
1045 if (wmhint
->flags
& StateHint
)
1046 client
.initial_state
= wmhint
->initial_state
;
1048 client
.initial_state
= NormalState
;
1050 if (wmhint
->flags
& WindowGroupHint
) {
1051 if (! client
.window_group
) {
1052 client
.window_group
= wmhint
->window_group
;
1053 openbox
.saveGroupSearch(client
.window_group
, this);
1056 client
.window_group
= None
;
1063 * Gets the value of the WM_NORMAL_HINTS property.
1064 * If the property is not set, then use a set of default values.
1066 void OpenboxWindow::getWMNormalHints(void) {
1068 XSizeHints sizehint
;
1070 client
.min_width
= client
.min_height
=
1071 client
.base_width
= client
.base_height
=
1072 client
.width_inc
= client
.height_inc
= 1;
1073 client
.max_width
= screen
->size().w();
1074 client
.max_height
= screen
->size().h();
1075 client
.min_aspect_x
= client
.min_aspect_y
=
1076 client
.max_aspect_x
= client
.max_aspect_y
= 1;
1077 client
.win_gravity
= NorthWestGravity
;
1079 if (! XGetWMNormalHints(display
, client
.window
, &sizehint
, &icccm_mask
))
1082 client
.normal_hint_flags
= sizehint
.flags
;
1084 if (sizehint
.flags
& PMinSize
) {
1085 client
.min_width
= sizehint
.min_width
;
1086 client
.min_height
= sizehint
.min_height
;
1089 if (sizehint
.flags
& PMaxSize
) {
1090 client
.max_width
= sizehint
.max_width
;
1091 client
.max_height
= sizehint
.max_height
;
1094 if (sizehint
.flags
& PResizeInc
) {
1095 client
.width_inc
= sizehint
.width_inc
;
1096 client
.height_inc
= sizehint
.height_inc
;
1099 if (sizehint
.flags
& PAspect
) {
1100 client
.min_aspect_x
= sizehint
.min_aspect
.x
;
1101 client
.min_aspect_y
= sizehint
.min_aspect
.y
;
1102 client
.max_aspect_x
= sizehint
.max_aspect
.x
;
1103 client
.max_aspect_y
= sizehint
.max_aspect
.y
;
1106 if (sizehint
.flags
& PBaseSize
) {
1107 client
.base_width
= sizehint
.base_width
;
1108 client
.base_height
= sizehint
.base_height
;
1111 if (sizehint
.flags
& PWinGravity
)
1112 client
.win_gravity
= sizehint
.win_gravity
;
1117 * Gets the MWM hints for the class' contained window.
1118 * This is used while initializing the window to its first state, and not
1120 * Returns: true if the MWM hints are successfully retreived and applied; false
1123 void OpenboxWindow::getMWMHints(void) {
1126 unsigned long num
, len
;
1128 int ret
= XGetWindowProperty(display
, client
.window
,
1129 openbox
.getMotifWMHintsAtom(), 0,
1130 PropMwmHintsElements
, False
,
1131 openbox
.getMotifWMHintsAtom(), &atom_return
,
1132 &format
, &num
, &len
,
1133 (unsigned char **) &client
.mwm_hint
);
1135 if (ret
!= Success
|| !client
.mwm_hint
|| num
!= PropMwmHintsElements
)
1138 if (client
.mwm_hint
->flags
& MwmHintsDecorations
) {
1139 if (client
.mwm_hint
->decorations
& MwmDecorAll
) {
1140 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1141 decorations
.iconify
= decorations
.maximize
=
1142 decorations
.close
= decorations
.menu
= True
;
1144 decorations
.titlebar
= decorations
.handle
= decorations
.border
=
1145 decorations
.iconify
= decorations
.maximize
=
1146 decorations
.close
= decorations
.menu
= False
;
1148 if (client
.mwm_hint
->decorations
& MwmDecorBorder
)
1149 decorations
.border
= True
;
1150 if (client
.mwm_hint
->decorations
& MwmDecorHandle
)
1151 decorations
.handle
= True
;
1152 if (client
.mwm_hint
->decorations
& MwmDecorTitle
)
1153 decorations
.titlebar
= True
;
1154 if (client
.mwm_hint
->decorations
& MwmDecorMenu
)
1155 decorations
.menu
= True
;
1156 if (client
.mwm_hint
->decorations
& MwmDecorIconify
)
1157 decorations
.iconify
= True
;
1158 if (client
.mwm_hint
->decorations
& MwmDecorMaximize
)
1159 decorations
.maximize
= True
;
1163 if (client
.mwm_hint
->flags
& MwmHintsFunctions
) {
1164 if (client
.mwm_hint
->functions
& MwmFuncAll
) {
1165 functions
.resize
= functions
.move
= functions
.iconify
=
1166 functions
.maximize
= functions
.close
= True
;
1168 functions
.resize
= functions
.move
= functions
.iconify
=
1169 functions
.maximize
= functions
.close
= False
;
1171 if (client
.mwm_hint
->functions
& MwmFuncResize
)
1172 functions
.resize
= True
;
1173 if (client
.mwm_hint
->functions
& MwmFuncMove
)
1174 functions
.move
= True
;
1175 if (client
.mwm_hint
->functions
& MwmFuncIconify
)
1176 functions
.iconify
= True
;
1177 if (client
.mwm_hint
->functions
& MwmFuncMaximize
)
1178 functions
.maximize
= True
;
1179 if (client
.mwm_hint
->functions
& MwmFuncClose
)
1180 functions
.close
= True
;
1187 * Gets the openbox hints from the class' contained window.
1188 * This is used while initializing the window to its first state, and not
1190 * Returns: true if the hints are successfully retreived and applied; false if
1193 void OpenboxWindow::getOpenboxHints(void) {
1196 unsigned long num
, len
;
1198 int ret
= XGetWindowProperty(display
, client
.window
,
1199 openbox
.getOpenboxHintsAtom(), 0,
1200 PropOpenboxHintsElements
, False
,
1201 openbox
.getOpenboxHintsAtom(), &atom_return
,
1202 &format
, &num
, &len
,
1203 (unsigned char **) &client
.openbox_hint
);
1204 if (ret
!= Success
|| !client
.openbox_hint
||
1205 num
!= PropOpenboxHintsElements
)
1208 if (client
.openbox_hint
->flags
& AttribShaded
)
1209 flags
.shaded
= (client
.openbox_hint
->attrib
& AttribShaded
);
1211 if ((client
.openbox_hint
->flags
& AttribMaxHoriz
) &&
1212 (client
.openbox_hint
->flags
& AttribMaxVert
))
1213 flags
.maximized
= (client
.openbox_hint
->attrib
&
1214 (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1215 else if (client
.openbox_hint
->flags
& AttribMaxVert
)
1216 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxVert
) ? 2 : 0;
1217 else if (client
.openbox_hint
->flags
& AttribMaxHoriz
)
1218 flags
.maximized
= (client
.openbox_hint
->attrib
& AttribMaxHoriz
) ? 3 : 0;
1220 if (client
.openbox_hint
->flags
& AttribOmnipresent
)
1221 flags
.stuck
= (client
.openbox_hint
->attrib
& AttribOmnipresent
);
1223 if (client
.openbox_hint
->flags
& AttribWorkspace
)
1224 workspace_number
= client
.openbox_hint
->workspace
;
1226 // if (client.openbox_hint->flags & AttribStack)
1227 // don't yet have always on top/bottom for openbox yet... working
1230 if (client
.openbox_hint
->flags
& AttribDecoration
) {
1231 switch (client
.openbox_hint
->decoration
) {
1233 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1234 decorations
.iconify
= decorations
.maximize
=
1235 decorations
.menu
= False
;
1236 functions
.resize
= functions
.move
= functions
.iconify
=
1237 functions
.maximize
= False
;
1242 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
=
1243 functions
.move
= functions
.iconify
= True
;
1244 decorations
.border
= decorations
.handle
= decorations
.maximize
=
1245 functions
.resize
= functions
.maximize
= False
;
1250 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
1251 decorations
.iconify
= decorations
.border
= decorations
.handle
=
1252 decorations
.maximize
= functions
.resize
= functions
.maximize
=
1253 functions
.iconify
= False
;
1259 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
1260 decorations
.iconify
= decorations
.maximize
=
1261 decorations
.menu
= True
;
1262 functions
.resize
= functions
.move
= functions
.iconify
=
1263 functions
.maximize
= True
;
1273 void OpenboxWindow::configure(int dx
, int dy
,
1274 unsigned int dw
, unsigned int dh
) {
1275 Bool send_event
= (frame
.x
!= dx
|| frame
.y
!= dy
);
1277 if ((dw
!= frame
.width
) || (dh
!= frame
.height
)) {
1278 if ((((signed) frame
.width
) + dx
) < 0) dx
= 0;
1279 if ((((signed) frame
.height
) + dy
) < 0) dy
= 0;
1289 if (openbox
.hasShapeExtensions() && flags
.shaped
) {
1290 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
1291 frame
.mwm_border_w
, frame
.y_border
+
1292 frame
.mwm_border_w
, client
.window
,
1293 ShapeBounding
, ShapeSet
);
1296 XRectangle xrect
[2];
1297 xrect
[0].x
= xrect
[0].y
= 0;
1298 xrect
[0].width
= frame
.width
;
1299 xrect
[0].height
= frame
.y_border
;
1301 if (decorations
.handle
) {
1303 xrect
[1].y
= frame
.y_handle
;
1304 xrect
[1].width
= frame
.width
;
1305 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
1309 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
1310 xrect
, num
, ShapeUnion
, Unsorted
);
1314 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1318 setFocusFlag(flags
.focused
);
1324 XMoveWindow(display
, frame
.window
, frame
.x
, frame
.y
);
1326 if (! flags
.moving
) send_event
= True
;
1329 if (send_event
&& ! flags
.moving
) {
1330 client
.x
= dx
+ frame
.mwm_border_w
+ frame
.border_w
;
1331 client
.y
= dy
+ frame
.y_border
+ frame
.mwm_border_w
+
1335 event
.type
= ConfigureNotify
;
1337 event
.xconfigure
.display
= display
;
1338 event
.xconfigure
.event
= client
.window
;
1339 event
.xconfigure
.window
= client
.window
;
1340 event
.xconfigure
.x
= client
.x
;
1341 event
.xconfigure
.y
= client
.y
;
1342 event
.xconfigure
.width
= client
.width
;
1343 event
.xconfigure
.height
= client
.height
;
1344 event
.xconfigure
.border_width
= client
.old_bw
;
1345 event
.xconfigure
.above
= frame
.window
;
1346 event
.xconfigure
.override_redirect
= False
;
1348 XSendEvent(display
, client
.window
, True
, NoEventMask
, &event
);
1350 screen
->updateNetizenConfigNotify(&event
);
1355 Bool
OpenboxWindow::setInputFocus(void) {
1356 if (((signed) (frame
.x
+ frame
.width
)) < 0) {
1357 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1358 configure(frame
.border_w
, frame
.border_w
, frame
.width
, frame
.height
);
1359 else if (frame
.y
> (signed) screen
->size().h())
1360 configure(frame
.border_w
, screen
->size().h() - frame
.height
,
1361 frame
.width
, frame
.height
);
1363 configure(frame
.border_w
, frame
.y
+ frame
.border_w
,
1364 frame
.width
, frame
.height
);
1365 } else if (frame
.x
> (signed) screen
->size().w()) {
1366 if (((signed) (frame
.y
+ frame
.y_border
)) < 0)
1367 configure(screen
->size().w() - frame
.width
, frame
.border_w
,
1368 frame
.width
, frame
.height
);
1369 else if (frame
.y
> (signed) screen
->size().h())
1370 configure(screen
->size().w() - frame
.width
,
1371 screen
->size().h() - frame
.height
, frame
.width
, frame
.height
);
1373 configure(screen
->size().w() - frame
.width
,
1374 frame
.y
+ frame
.border_w
, frame
.width
, frame
.height
);
1378 if (! validateClient()) return False
;
1382 if (client
.transient
&& flags
.modal
) {
1383 ret
= client
.transient
->setInputFocus();
1384 } else if (! flags
.focused
) {
1385 if (focus_mode
== F_LocallyActive
|| focus_mode
== F_Passive
)
1386 XSetInputFocus(display
, client
.window
,
1387 RevertToPointerRoot
, CurrentTime
);
1389 XSetInputFocus(display
, screen
->getRootWindow(),
1390 RevertToNone
, CurrentTime
);
1392 openbox
.setFocusedWindow(this);
1394 if (flags
.send_focus_message
) {
1396 ce
.xclient
.type
= ClientMessage
;
1397 ce
.xclient
.message_type
= openbox
.getWMProtocolsAtom();
1398 ce
.xclient
.display
= display
;
1399 ce
.xclient
.window
= client
.window
;
1400 ce
.xclient
.format
= 32;
1401 ce
.xclient
.data
.l
[0] = openbox
.getWMTakeFocusAtom();
1402 ce
.xclient
.data
.l
[1] = openbox
.getLastTime();
1403 ce
.xclient
.data
.l
[2] = 0l;
1404 ce
.xclient
.data
.l
[3] = 0l;
1405 ce
.xclient
.data
.l
[4] = 0l;
1406 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1409 if (screen
->sloppyFocus() && screen
->autoRaise())
1421 void OpenboxWindow::iconify(void) {
1422 if (flags
.iconic
) return;
1424 if (windowmenu
) windowmenu
->hide();
1426 setState(IconicState
);
1428 XSelectInput(display
, client
.window
, NoEventMask
);
1429 XUnmapWindow(display
, client
.window
);
1430 XSelectInput(display
, client
.window
,
1431 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1433 XUnmapWindow(display
, frame
.window
);
1434 flags
.visible
= False
;
1435 flags
.iconic
= True
;
1437 screen
->getWorkspace(workspace_number
)->removeWindow(this);
1439 if (flags
.transient
&& client
.transient_for
&&
1440 !client
.transient_for
->flags
.iconic
) {
1441 client
.transient_for
->iconify();
1443 screen
->addIcon(this);
1445 if (client
.transient
&& !client
.transient
->flags
.iconic
) {
1446 client
.transient
->iconify();
1451 void OpenboxWindow::deiconify(Bool reassoc
, Bool raise
) {
1452 if (flags
.iconic
|| reassoc
)
1453 screen
->reassociateWindow(this, -1, False
);
1454 else if (workspace_number
!= screen
->getCurrentWorkspace()->getWorkspaceID())
1457 setState(NormalState
);
1459 XSelectInput(display
, client
.window
, NoEventMask
);
1460 XMapWindow(display
, client
.window
);
1461 XSelectInput(display
, client
.window
,
1462 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1464 XMapSubwindows(display
, frame
.window
);
1465 XMapWindow(display
, frame
.window
);
1467 if (flags
.iconic
&& screen
->focusNew()) setInputFocus();
1469 flags
.visible
= True
;
1470 flags
.iconic
= False
;
1472 if (reassoc
&& client
.transient
) client
.transient
->deiconify(True
, False
);
1475 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1479 void OpenboxWindow::close(void) {
1481 ce
.xclient
.type
= ClientMessage
;
1482 ce
.xclient
.message_type
= openbox
.getWMProtocolsAtom();
1483 ce
.xclient
.display
= display
;
1484 ce
.xclient
.window
= client
.window
;
1485 ce
.xclient
.format
= 32;
1486 ce
.xclient
.data
.l
[0] = openbox
.getWMDeleteAtom();
1487 ce
.xclient
.data
.l
[1] = CurrentTime
;
1488 ce
.xclient
.data
.l
[2] = 0l;
1489 ce
.xclient
.data
.l
[3] = 0l;
1490 ce
.xclient
.data
.l
[4] = 0l;
1491 XSendEvent(display
, client
.window
, False
, NoEventMask
, &ce
);
1495 void OpenboxWindow::withdraw(void) {
1496 flags
.visible
= False
;
1497 flags
.iconic
= False
;
1499 XUnmapWindow(display
, frame
.window
);
1501 XSelectInput(display
, client
.window
, NoEventMask
);
1502 XUnmapWindow(display
, client
.window
);
1503 XSelectInput(display
, client
.window
,
1504 PropertyChangeMask
| StructureNotifyMask
| FocusChangeMask
);
1506 if (windowmenu
) windowmenu
->hide();
1510 void OpenboxWindow::maximize(unsigned int button
) {
1511 // handle case where menu is open then the max button is used instead
1512 if (windowmenu
&& windowmenu
->isVisible()) windowmenu
->hide();
1514 if (flags
.maximized
) {
1515 flags
.maximized
= 0;
1517 openbox_attrib
.flags
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1518 openbox_attrib
.attrib
&= ! (AttribMaxHoriz
| AttribMaxVert
);
1520 // when a resize is begun, maximize(0) is called to clear any maximization
1521 // flags currently set. Otherwise it still thinks it is maximized.
1522 // so we do not need to call configure() because resizing will handle it
1523 if (!flags
.resizing
)
1524 configure(openbox_attrib
.premax_x
, openbox_attrib
.premax_y
,
1525 openbox_attrib
.premax_w
, openbox_attrib
.premax_h
);
1527 openbox_attrib
.premax_x
= openbox_attrib
.premax_y
= 0;
1528 openbox_attrib
.premax_w
= openbox_attrib
.premax_h
= 0;
1531 setState(current_state
);
1536 unsigned int dw
, dh
;
1538 openbox_attrib
.premax_x
= frame
.x
;
1539 openbox_attrib
.premax_y
= frame
.y
;
1540 openbox_attrib
.premax_w
= frame
.width
;
1541 openbox_attrib
.premax_h
= frame
.height
;
1543 dw
= screen
->size().w();
1544 dw
-= frame
.border_w
* 2;
1545 dw
-= frame
.mwm_border_w
* 2;
1546 dw
-= client
.base_width
;
1548 dh
= screen
->size().h();
1549 dh
-= frame
.border_w
* 2;
1550 dh
-= frame
.mwm_border_w
* 2;
1551 dh
-= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1552 dh
-= client
.base_height
;
1553 dh
-= frame
.y_border
;
1555 if (! screen
->fullMax())
1556 dh
-= screen
->getToolbar()->getExposedHeight() + frame
.border_w
;
1558 if (dw
< client
.min_width
) dw
= client
.min_width
;
1559 if (dh
< client
.min_height
) dh
= client
.min_height
;
1560 if (dw
> client
.max_width
) dw
= client
.max_width
;
1561 if (dh
> client
.max_height
) dh
= client
.max_height
;
1563 dw
-= (dw
% client
.width_inc
);
1564 dw
+= client
.base_width
;
1565 dw
+= frame
.mwm_border_w
* 2;
1567 dh
-= (dh
% client
.height_inc
);
1568 dh
+= client
.base_height
;
1569 dh
+= frame
.y_border
;
1570 dh
+= ((frame
.handle_h
+ frame
.border_w
) * decorations
.handle
);
1571 dh
+= frame
.mwm_border_w
* 2;
1573 dx
+= ((screen
->size().w() - dw
) / 2) - frame
.border_w
;
1575 if (screen
->fullMax()) {
1576 dy
+= ((screen
->size().h() - dh
) / 2) - frame
.border_w
;
1578 dy
+= (((screen
->size().h() - screen
->getToolbar()->getExposedHeight())
1579 - dh
) / 2) - frame
.border_w
;
1581 switch (screen
->getToolbar()->placement()) {
1582 case Toolbar::TopLeft
:
1583 case Toolbar::TopCenter
:
1584 case Toolbar::TopRight
:
1585 dy
+= screen
->getToolbar()->getExposedHeight() +
1593 openbox_attrib
.flags
|= AttribMaxHoriz
| AttribMaxVert
;
1594 openbox_attrib
.attrib
|= AttribMaxHoriz
| AttribMaxVert
;
1598 openbox_attrib
.flags
|= AttribMaxVert
;
1599 openbox_attrib
.attrib
|= AttribMaxVert
;
1606 openbox_attrib
.flags
|= AttribMaxHoriz
;
1607 openbox_attrib
.attrib
|= AttribMaxHoriz
;
1615 openbox_attrib
.flags
^= AttribShaded
;
1616 openbox_attrib
.attrib
^= AttribShaded
;
1617 flags
.shaded
= False
;
1620 flags
.maximized
= button
;
1622 configure(dx
, dy
, dw
, dh
);
1623 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
1625 setState(current_state
);
1629 void OpenboxWindow::setWorkspace(int n
) {
1630 workspace_number
= n
;
1632 openbox_attrib
.flags
|= AttribWorkspace
;
1633 openbox_attrib
.workspace
= workspace_number
;
1637 void OpenboxWindow::shade(void) {
1638 if (!decorations
.titlebar
)
1642 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.height
);
1643 flags
.shaded
= False
;
1644 openbox_attrib
.flags
^= AttribShaded
;
1645 openbox_attrib
.attrib
^= AttribShaded
;
1647 setState(NormalState
);
1649 XResizeWindow(display
, frame
.window
, frame
.width
, frame
.title_h
);
1650 flags
.shaded
= True
;
1651 openbox_attrib
.flags
|= AttribShaded
;
1652 openbox_attrib
.attrib
|= AttribShaded
;
1654 setState(IconicState
);
1659 void OpenboxWindow::stick(void) {
1661 openbox_attrib
.flags
^= AttribOmnipresent
;
1662 openbox_attrib
.attrib
^= AttribOmnipresent
;
1664 flags
.stuck
= False
;
1667 screen
->reassociateWindow(this, -1, True
);
1669 setState(current_state
);
1673 openbox_attrib
.flags
|= AttribOmnipresent
;
1674 openbox_attrib
.attrib
|= AttribOmnipresent
;
1676 setState(current_state
);
1681 void OpenboxWindow::setFocusFlag(Bool focus
) {
1682 flags
.focused
= focus
;
1684 if (decorations
.titlebar
) {
1685 if (flags
.focused
) {
1687 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.ftitle
);
1689 XSetWindowBackground(display
, frame
.title
, frame
.ftitle_pixel
);
1692 XSetWindowBackgroundPixmap(display
, frame
.title
, frame
.utitle
);
1694 XSetWindowBackground(display
, frame
.title
, frame
.utitle_pixel
);
1696 XClearWindow(display
, frame
.title
);
1702 if (decorations
.handle
) {
1703 if (flags
.focused
) {
1705 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.fhandle
);
1707 XSetWindowBackground(display
, frame
.handle
, frame
.fhandle_pixel
);
1710 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.fgrip
);
1711 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.fgrip
);
1713 XSetWindowBackground(display
, frame
.right_grip
, frame
.fgrip_pixel
);
1714 XSetWindowBackground(display
, frame
.left_grip
, frame
.fgrip_pixel
);
1718 XSetWindowBackgroundPixmap(display
, frame
.handle
, frame
.uhandle
);
1720 XSetWindowBackground(display
, frame
.handle
, frame
.uhandle_pixel
);
1723 XSetWindowBackgroundPixmap(display
, frame
.right_grip
, frame
.ugrip
);
1724 XSetWindowBackgroundPixmap(display
, frame
.left_grip
, frame
.ugrip
);
1726 XSetWindowBackground(display
, frame
.right_grip
, frame
.ugrip_pixel
);
1727 XSetWindowBackground(display
, frame
.left_grip
, frame
.ugrip_pixel
);
1730 XClearWindow(display
, frame
.handle
);
1731 XClearWindow(display
, frame
.right_grip
);
1732 XClearWindow(display
, frame
.left_grip
);
1735 if (decorations
.border
) {
1737 XSetWindowBorder(display
, frame
.plate
, frame
.fborder_pixel
);
1739 XSetWindowBorder(display
, frame
.plate
, frame
.uborder_pixel
);
1742 if (screen
->sloppyFocus() && screen
->autoRaise() && timer
->isTiming())
1747 void OpenboxWindow::installColormap(Bool install
) {
1749 if (! validateClient()) return;
1751 int i
= 0, ncmap
= 0;
1752 Colormap
*cmaps
= XListInstalledColormaps(display
, client
.window
, &ncmap
);
1753 XWindowAttributes wattrib
;
1755 if (XGetWindowAttributes(display
, client
.window
, &wattrib
)) {
1757 // install the window's colormap
1758 for (i
= 0; i
< ncmap
; i
++) {
1759 if (*(cmaps
+ i
) == wattrib
.colormap
)
1760 // this window is using an installed color map... do not install
1763 // otherwise, install the window's colormap
1765 XInstallColormap(display
, wattrib
.colormap
);
1767 // uninstall the window's colormap
1768 for (i
= 0; i
< ncmap
; i
++) {
1769 if (*(cmaps
+ i
) == wattrib
.colormap
)
1770 // we found the colormap to uninstall
1771 XUninstallColormap(display
, wattrib
.colormap
);
1783 void OpenboxWindow::setState(unsigned long new_state
) {
1784 current_state
= new_state
;
1786 unsigned long state
[2];
1787 state
[0] = (unsigned long) current_state
;
1788 state
[1] = (unsigned long) None
;
1789 XChangeProperty(display
, client
.window
, openbox
.getWMStateAtom(),
1790 openbox
.getWMStateAtom(), 32, PropModeReplace
,
1791 (unsigned char *) state
, 2);
1793 XChangeProperty(display
, client
.window
,
1794 openbox
.getOpenboxAttributesAtom(),
1795 openbox
.getOpenboxAttributesAtom(), 32, PropModeReplace
,
1796 (unsigned char *) &openbox_attrib
,
1797 PropOpenboxAttributesElements
);
1801 Bool
OpenboxWindow::getState(void) {
1807 unsigned long *state
, ulfoo
, nitems
;
1809 if ((XGetWindowProperty(display
, client
.window
, openbox
.getWMStateAtom(),
1810 0l, 2l, False
, openbox
.getWMStateAtom(),
1811 &atom_return
, &foo
, &nitems
, &ulfoo
,
1812 (unsigned char **) &state
) != Success
) ||
1819 current_state
= (unsigned long) state
[0];
1824 XFree((void *) state
);
1830 void OpenboxWindow::setGravityOffsets(void) {
1831 // x coordinates for each gravity type
1832 const int x_west
= client
.x
;
1833 const int x_east
= client
.x
+ client
.width
- frame
.width
;
1834 const int x_center
= client
.x
+ client
.width
- frame
.width
/2;
1835 // y coordinates for each gravity type
1836 const int y_north
= client
.y
;
1837 const int y_south
= client
.y
+ client
.height
- frame
.height
;
1838 const int y_center
= client
.y
+ client
.height
- frame
.height
/2;
1840 switch (client
.win_gravity
) {
1841 case NorthWestGravity
:
1850 case NorthEastGravity
:
1854 case SouthWestGravity
:
1862 case SouthEastGravity
:
1880 frame
.x
= client
.x
- frame
.mwm_border_w
+ frame
.border_w
;
1881 frame
.y
= client
.y
- frame
.y_border
- frame
.mwm_border_w
- frame
.border_w
;
1887 void OpenboxWindow::restoreAttributes(void) {
1888 if (! getState()) current_state
= NormalState
;
1892 unsigned long ulfoo
, nitems
;
1894 OpenboxAttributes
*net
;
1895 int ret
= XGetWindowProperty(display
, client
.window
,
1896 openbox
.getOpenboxAttributesAtom(), 0l,
1897 PropOpenboxAttributesElements
, False
,
1898 openbox
.getOpenboxAttributesAtom(),
1899 &atom_return
, &foo
, &nitems
, &ulfoo
,
1900 (unsigned char **) &net
);
1901 if (ret
!= Success
|| !net
|| nitems
!= PropOpenboxAttributesElements
)
1904 openbox_attrib
.flags
= net
->flags
;
1905 openbox_attrib
.attrib
= net
->attrib
;
1906 openbox_attrib
.decoration
= net
->decoration
;
1907 openbox_attrib
.workspace
= net
->workspace
;
1908 openbox_attrib
.stack
= net
->stack
;
1909 openbox_attrib
.premax_x
= net
->premax_x
;
1910 openbox_attrib
.premax_y
= net
->premax_y
;
1911 openbox_attrib
.premax_w
= net
->premax_w
;
1912 openbox_attrib
.premax_h
= net
->premax_h
;
1914 XFree((void *) net
);
1916 if (openbox_attrib
.flags
& AttribShaded
&&
1917 openbox_attrib
.attrib
& AttribShaded
) {
1919 ((current_state
== IconicState
) ? NormalState
: current_state
);
1921 flags
.shaded
= False
;
1924 current_state
= save_state
;
1927 if (((int) openbox_attrib
.workspace
!= screen
->getCurrentWorkspaceID()) &&
1928 ((int) openbox_attrib
.workspace
< screen
->getWorkspaceCount())) {
1929 screen
->reassociateWindow(this, openbox_attrib
.workspace
, True
);
1931 if (current_state
== NormalState
) current_state
= WithdrawnState
;
1932 } else if (current_state
== WithdrawnState
) {
1933 current_state
= NormalState
;
1936 if (openbox_attrib
.flags
& AttribOmnipresent
&&
1937 openbox_attrib
.attrib
& AttribOmnipresent
) {
1938 flags
.stuck
= False
;
1941 current_state
= NormalState
;
1944 if ((openbox_attrib
.flags
& AttribMaxHoriz
) ||
1945 (openbox_attrib
.flags
& AttribMaxVert
)) {
1946 int x
= openbox_attrib
.premax_x
, y
= openbox_attrib
.premax_y
;
1947 unsigned int w
= openbox_attrib
.premax_w
, h
= openbox_attrib
.premax_h
;
1948 flags
.maximized
= 0;
1950 unsigned int m
= False
;
1951 if ((openbox_attrib
.flags
& AttribMaxHoriz
) &&
1952 (openbox_attrib
.flags
& AttribMaxVert
))
1953 m
= (openbox_attrib
.attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0;
1954 else if (openbox_attrib
.flags
& AttribMaxVert
)
1955 m
= (openbox_attrib
.attrib
& AttribMaxVert
) ? 2 : 0;
1956 else if (openbox_attrib
.flags
& AttribMaxHoriz
)
1957 m
= (openbox_attrib
.attrib
& AttribMaxHoriz
) ? 3 : 0;
1961 openbox_attrib
.premax_x
= x
;
1962 openbox_attrib
.premax_y
= y
;
1963 openbox_attrib
.premax_w
= w
;
1964 openbox_attrib
.premax_h
= h
;
1967 setState(current_state
);
1972 * The reverse of the setGravityOffsets function. Uses the frame window's
1973 * position to find the window's reference point.
1975 void OpenboxWindow::restoreGravity(void) {
1976 // x coordinates for each gravity type
1977 const int x_west
= frame
.x
;
1978 const int x_east
= frame
.x
+ frame
.width
- client
.width
;
1979 const int x_center
= frame
.x
+ (frame
.width
/2) - client
.width
;
1980 // y coordinates for each gravity type
1981 const int y_north
= frame
.y
;
1982 const int y_south
= frame
.y
+ frame
.height
- client
.height
;
1983 const int y_center
= frame
.y
+ (frame
.height
/2) - client
.height
;
1985 switch(client
.win_gravity
) {
1987 case NorthWestGravity
:
1992 client
.x
= x_center
;
1995 case NorthEastGravity
:
1999 case SouthWestGravity
:
2004 client
.x
= x_center
;
2007 case SouthEastGravity
:
2013 client
.y
= y_center
;
2017 client
.y
= y_center
;
2020 client
.x
= x_center
;
2021 client
.y
= y_center
;
2025 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
2026 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+
2033 void OpenboxWindow::redrawLabel(void) {
2034 int dx
= frame
.bevel_w
* 2, dlen
= client
.title_len
;
2035 unsigned int l
= client
.title_text_w
;
2037 if (flags
.focused
) {
2039 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.flabel
);
2041 XSetWindowBackground(display
, frame
.label
, frame
.flabel_pixel
);
2044 XSetWindowBackgroundPixmap(display
, frame
.label
, frame
.ulabel
);
2046 XSetWindowBackground(display
, frame
.label
, frame
.ulabel_pixel
);
2048 XClearWindow(display
, frame
.label
);
2050 if (client
.title_text_w
> frame
.label_w
) {
2051 for (; dlen
>= 0; dlen
--) {
2052 if (i18n
->multibyte()) {
2053 XRectangle ink
, logical
;
2054 XmbTextExtents(screen
->getWindowStyle()->fontset
, client
.title
, dlen
,
2058 l
= XTextWidth(screen
->getWindowStyle()->font
, client
.title
, dlen
);
2060 l
+= (frame
.bevel_w
* 4);
2062 if (l
< frame
.label_w
)
2067 switch (screen
->getWindowStyle()->justify
) {
2068 case BScreen::RightJustify
:
2069 dx
+= frame
.label_w
- l
;
2072 case BScreen::CenterJustify
:
2073 dx
+= (frame
.label_w
- l
) / 2;
2077 WindowStyle
*style
= screen
->getWindowStyle();
2078 GC text_gc
= (flags
.focused
) ? style
->l_text_focus_gc
:
2079 style
->l_text_unfocus_gc
;
2080 if (i18n
->multibyte())
2081 XmbDrawString(display
, frame
.label
, style
->fontset
, text_gc
, dx
,
2082 (1 - style
->fontset_extents
->max_ink_extent
.y
),
2083 client
.title
, dlen
);
2085 XDrawString(display
, frame
.label
, text_gc
, dx
,
2086 (style
->font
->ascent
+ 1), client
.title
, dlen
);
2090 void OpenboxWindow::redrawAllButtons(void) {
2091 if (frame
.iconify_button
) redrawIconifyButton(False
);
2092 if (frame
.maximize_button
) redrawMaximizeButton(flags
.maximized
);
2093 if (frame
.close_button
) redrawCloseButton(False
);
2097 void OpenboxWindow::redrawIconifyButton(Bool pressed
) {
2099 if (flags
.focused
) {
2101 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2104 XSetWindowBackground(display
, frame
.iconify_button
,
2105 frame
.fbutton_pixel
);
2108 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
,
2111 XSetWindowBackground(display
, frame
.iconify_button
,
2112 frame
.ubutton_pixel
);
2116 XSetWindowBackgroundPixmap(display
, frame
.iconify_button
, frame
.pbutton
);
2118 XSetWindowBackground(display
, frame
.iconify_button
, frame
.pbutton_pixel
);
2120 XClearWindow(display
, frame
.iconify_button
);
2122 XDrawRectangle(display
, frame
.iconify_button
,
2123 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2124 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2125 2, (frame
.button_h
- 5), (frame
.button_w
- 5), 2);
2129 void OpenboxWindow::redrawMaximizeButton(Bool pressed
) {
2131 if (flags
.focused
) {
2133 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2136 XSetWindowBackground(display
, frame
.maximize_button
,
2137 frame
.fbutton_pixel
);
2140 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2143 XSetWindowBackground(display
, frame
.maximize_button
,
2144 frame
.ubutton_pixel
);
2148 XSetWindowBackgroundPixmap(display
, frame
.maximize_button
,
2151 XSetWindowBackground(display
, frame
.maximize_button
,
2152 frame
.pbutton_pixel
);
2154 XClearWindow(display
, frame
.maximize_button
);
2156 XDrawRectangle(display
, frame
.maximize_button
,
2157 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2158 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2159 2, 2, (frame
.button_w
- 5), (frame
.button_h
- 5));
2160 XDrawLine(display
, frame
.maximize_button
,
2161 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2162 screen
->getWindowStyle()->b_pic_unfocus_gc
),
2163 2, 3, (frame
.button_w
- 3), 3);
2167 void OpenboxWindow::redrawCloseButton(Bool pressed
) {
2169 if (flags
.focused
) {
2171 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2174 XSetWindowBackground(display
, frame
.close_button
,
2175 frame
.fbutton_pixel
);
2178 XSetWindowBackgroundPixmap(display
, frame
.close_button
,
2181 XSetWindowBackground(display
, frame
.close_button
,
2182 frame
.ubutton_pixel
);
2186 XSetWindowBackgroundPixmap(display
, frame
.close_button
, frame
.pbutton
);
2188 XSetWindowBackground(display
, frame
.close_button
, frame
.pbutton_pixel
);
2190 XClearWindow(display
, frame
.close_button
);
2192 XDrawLine(display
, frame
.close_button
,
2193 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2194 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2, 2,
2195 (frame
.button_w
- 3), (frame
.button_h
- 3));
2196 XDrawLine(display
, frame
.close_button
,
2197 ((flags
.focused
) ? screen
->getWindowStyle()->b_pic_focus_gc
:
2198 screen
->getWindowStyle()->b_pic_unfocus_gc
), 2,
2199 (frame
.button_h
- 3),
2200 (frame
.button_w
- 3), 2);
2204 void OpenboxWindow::mapRequestEvent(XMapRequestEvent
*re
) {
2205 if (re
->window
== client
.window
) {
2207 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowMapRequest
,
2208 "OpenboxWindow::mapRequestEvent() for 0x%lx\n"),
2213 if (! validateClient()) return;
2215 Bool get_state_ret
= getState();
2216 if (! (get_state_ret
&& openbox
.isStartup())) {
2217 if ((client
.wm_hint_flags
& StateHint
) &&
2218 (! (current_state
== NormalState
|| current_state
== IconicState
)))
2219 current_state
= client
.initial_state
;
2221 current_state
= NormalState
;
2222 } else if (flags
.iconic
) {
2223 current_state
= NormalState
;
2226 switch (current_state
) {
2231 case WithdrawnState
:
2248 void OpenboxWindow::mapNotifyEvent(XMapEvent
*ne
) {
2249 if ((ne
->window
== client
.window
) && (! ne
->override_redirect
)
2250 && (flags
.visible
)) {
2252 if (! validateClient()) return;
2254 if (decorations
.titlebar
) positionButtons();
2256 setState(NormalState
);
2260 if (flags
.transient
|| screen
->focusNew())
2263 setFocusFlag(False
);
2265 flags
.visible
= True
;
2266 flags
.iconic
= False
;
2273 void OpenboxWindow::unmapNotifyEvent(XUnmapEvent
*ue
) {
2274 if (ue
->window
== client
.window
) {
2276 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotify
,
2277 "OpenboxWindow::unmapNotifyEvent() for 0x%lx\n"),
2282 if (! validateClient()) return;
2284 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
2285 XSelectInput(display
, client
.window
, NoEventMask
);
2287 XDeleteProperty(display
, client
.window
, openbox
.getWMStateAtom());
2288 XDeleteProperty(display
, client
.window
,
2289 openbox
.getOpenboxAttributesAtom());
2291 XUnmapWindow(display
, frame
.window
);
2292 XUnmapWindow(display
, client
.window
);
2295 if (! XCheckTypedWindowEvent(display
, client
.window
, ReparentNotify
,
2298 fprintf(stderr
, i18n
->getMessage(WindowSet
, WindowUnmapNotifyReparent
,
2299 "OpenboxWindow::unmapNotifyEvent(): reparent 0x%lx to "
2300 "root.\n"), client
.window
);
2304 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
2305 client
.x
, client
.y
);
2317 void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent
*de
) {
2318 if (de
->window
== client
.window
) {
2319 XUnmapWindow(display
, frame
.window
);
2326 void OpenboxWindow::propertyNotifyEvent(Atom atom
) {
2328 if (! validateClient()) return;
2332 case XA_WM_CLIENT_MACHINE
:
2336 case XA_WM_TRANSIENT_FOR
:
2337 // determine if this is a transient window
2339 if (XGetTransientForHint(display
, client
.window
, &win
)) {
2340 if (win
&& (win
!= client
.window
)) {
2341 if ((client
.transient_for
= openbox
.searchWindow(win
))) {
2342 client
.transient_for
->client
.transient
= this;
2343 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2344 flags
.transient
= True
;
2345 } else if (win
== client
.window_group
) {
2346 //jr This doesn't look quite right...
2347 if ((client
.transient_for
= openbox
.searchGroup(win
, this))) {
2348 client
.transient_for
->client
.transient
= this;
2349 flags
.stuck
= client
.transient_for
->flags
.stuck
;
2350 flags
.transient
= True
;
2355 if (win
== screen
->getRootWindow()) flags
.modal
= True
;
2358 // adjust the window decorations based on transience
2359 if (flags
.transient
)
2360 decorations
.maximize
= decorations
.handle
= functions
.maximize
= False
;
2370 case XA_WM_ICON_NAME
:
2372 if (flags
.iconic
) screen
->iconUpdate();
2378 if (decorations
.titlebar
)
2382 screen
->getWorkspace(workspace_number
)->update();
2386 case XA_WM_NORMAL_HINTS
: {
2389 if ((client
.normal_hint_flags
& PMinSize
) &&
2390 (client
.normal_hint_flags
& PMaxSize
)) {
2391 if (client
.max_width
<= client
.min_width
&&
2392 client
.max_height
<= client
.min_height
)
2393 decorations
.maximize
= decorations
.handle
=
2394 functions
.resize
= functions
.maximize
= False
;
2396 decorations
.maximize
= decorations
.handle
=
2397 functions
.resize
= functions
.maximize
= True
;
2400 int x
= frame
.x
, y
= frame
.y
;
2401 unsigned int w
= frame
.width
, h
= frame
.height
;
2405 if ((x
!= frame
.x
) || (y
!= frame
.y
) ||
2406 (w
!= frame
.width
) || (h
!= frame
.height
))
2413 if (atom
== openbox
.getWMProtocolsAtom()) {
2416 if (decorations
.close
&& (! frame
.close_button
)) {
2417 createCloseButton();
2418 if (decorations
.titlebar
) positionButtons(True
);
2419 if (windowmenu
) windowmenu
->reconfigure();
2430 void OpenboxWindow::exposeEvent(XExposeEvent
*ee
) {
2431 if (frame
.label
== ee
->window
&& decorations
.titlebar
)
2433 else if (frame
.close_button
== ee
->window
)
2434 redrawCloseButton(False
);
2435 else if (frame
.maximize_button
== ee
->window
)
2436 redrawMaximizeButton(flags
.maximized
);
2437 else if (frame
.iconify_button
== ee
->window
)
2438 redrawIconifyButton(False
);
2442 void OpenboxWindow::configureRequestEvent(XConfigureRequestEvent
*cr
) {
2443 if (cr
->window
== client
.window
) {
2445 if (! validateClient()) return;
2447 int cx
= frame
.x
, cy
= frame
.y
;
2448 unsigned int cw
= frame
.width
, ch
= frame
.height
;
2450 if (cr
->value_mask
& CWBorderWidth
)
2451 client
.old_bw
= cr
->border_width
;
2453 if (cr
->value_mask
& CWX
)
2454 cx
= cr
->x
- frame
.mwm_border_w
- frame
.border_w
;
2456 if (cr
->value_mask
& CWY
)
2457 cy
= cr
->y
- frame
.y_border
- frame
.mwm_border_w
-
2460 if (cr
->value_mask
& CWWidth
)
2461 cw
= cr
->width
+ (frame
.mwm_border_w
* 2);
2463 if (cr
->value_mask
& CWHeight
)
2464 ch
= cr
->height
+ frame
.y_border
+ (frame
.mwm_border_w
* 2) +
2465 (frame
.border_w
* decorations
.handle
) + frame
.handle_h
;
2467 if (frame
.x
!= cx
|| frame
.y
!= cy
||
2468 frame
.width
!= cw
|| frame
.height
!= ch
)
2469 configure(cx
, cy
, cw
, ch
);
2471 if (cr
->value_mask
& CWStackMode
) {
2472 switch (cr
->detail
) {
2476 if (flags
.iconic
) deiconify();
2477 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2482 if (flags
.iconic
) deiconify();
2483 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2493 void OpenboxWindow::buttonPressEvent(XButtonEvent
*be
) {
2495 if (! validateClient())
2498 int stack_change
= 1; // < 0 means to lower the window
2499 // > 0 means to raise the window
2500 // 0 means to leave it where it is
2502 // alt + left/right click begins interactively moving/resizing the window
2503 // when the mouse is moved
2504 if (be
->state
== Mod1Mask
&& (be
->button
== 1 || be
->button
== 3)) {
2505 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2506 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2507 if (be
->button
== 3) {
2508 if (screen
->getWindowZones() == 4 &&
2509 be
->y
< (signed) frame
.height
/ 2) {
2510 resize_zone
= ZoneTop
;
2512 resize_zone
= ZoneBottom
;
2514 if (screen
->getWindowZones() >= 2 &&
2515 be
->x
< (signed) frame
.width
/ 2) {
2516 resize_zone
|= ZoneLeft
;
2518 resize_zone
|= ZoneRight
;
2521 // control + left click on the titlebar shades the window
2522 } else if (be
->state
== ControlMask
&& be
->button
== 1) {
2523 if (be
->window
== frame
.title
||
2524 be
->window
== frame
.label
)
2527 } else if (be
->state
== 0 && be
->button
== 1) {
2528 if (windowmenu
&& windowmenu
->isVisible())
2531 if (be
->window
== frame
.maximize_button
) {
2532 redrawMaximizeButton(True
);
2533 } else if (be
->window
== frame
.iconify_button
) {
2534 redrawIconifyButton(True
);
2535 } else if (be
->window
== frame
.close_button
) {
2536 redrawCloseButton(True
);
2537 } else if (be
->window
== frame
.plate
) {
2538 XAllowEvents(display
, ReplayPointer
, be
->time
);
2539 } else if (be
->window
== frame
.title
||
2540 be
->window
== frame
.label
) {
2541 // shade the window when the titlebar is double clicked
2542 if ( (be
->time
- lastButtonPressTime
) <=
2543 openbox
.getDoubleClickInterval()) {
2544 lastButtonPressTime
= 0;
2547 lastButtonPressTime
= be
->time
;
2549 // clicking and dragging on the titlebar moves the window, so on a click
2550 // we need to save the coords of the click in case the user drags
2551 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2552 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2553 } else if (be
->window
== frame
.handle
||
2554 be
->window
== frame
.left_grip
||
2555 be
->window
== frame
.right_grip
||
2556 be
->window
== frame
.window
) {
2557 // clicking and dragging on the window's frame moves the window, so on a
2558 // click we need to save the coords of the click in case the user drags
2559 frame
.grab_x
= be
->x_root
- frame
.x
- frame
.border_w
;
2560 frame
.grab_y
= be
->y_root
- frame
.y
- frame
.border_w
;
2561 if (be
->window
== frame
.left_grip
)
2562 resize_zone
= ZoneBottom
| ZoneLeft
;
2563 else if (be
->window
== frame
.right_grip
)
2564 resize_zone
= ZoneBottom
| ZoneRight
;
2567 } else if (be
->state
== 0 && be
->button
== 2) {
2568 if (be
->window
== frame
.maximize_button
) {
2569 redrawMaximizeButton(True
);
2570 // a middle click anywhere on the window's frame except for on the buttons
2571 // will lower the window
2572 } else if (! (be
->window
== frame
.iconify_button
||
2573 be
->window
== frame
.close_button
) ) {
2577 } else if (be
->state
== 0 && be
->button
== 3) {
2578 if (be
->window
== frame
.maximize_button
) {
2579 redrawMaximizeButton(True
);
2580 // a right click on the window's frame will show or hide the window's
2582 } else if (be
->window
== frame
.title
||
2583 be
->window
== frame
.label
||
2584 be
->window
== frame
.handle
||
2585 be
->window
== frame
.window
) {
2588 if (windowmenu
->isVisible()) {
2591 // get the coords for the menu
2592 mx
= be
->x_root
- windowmenu
->getWidth() / 2;
2593 if (be
->window
== frame
.title
|| be
->window
== frame
.label
) {
2594 my
= frame
.y
+ frame
.title_h
;
2595 } else if (be
->window
= frame
.handle
) {
2596 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2597 } else { // (be->window == frame.window)
2598 if (be
->y
<= (signed) frame
.bevel_w
) {
2599 my
= frame
.y
+ frame
.y_border
;
2601 my
= be
->y_root
- (windowmenu
->getHeight() / 2);
2605 if (mx
> (signed) (frame
.x
+ frame
.width
-
2606 windowmenu
->getWidth())) {
2607 mx
= frame
.x
+ frame
.width
- windowmenu
->getWidth();
2608 } else if (mx
< frame
.x
) {
2612 if (my
> (signed) (frame
.y
+ frame
.y_handle
-
2613 windowmenu
->getHeight())) {
2614 my
= frame
.y
+ frame
.y_handle
- windowmenu
->getHeight();
2615 } else if (my
< (signed) (frame
.y
+
2616 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
))) {
2618 ((decorations
.titlebar
) ? frame
.title_h
: frame
.y_border
);
2621 windowmenu
->move(mx
, my
);
2623 XRaiseWindow(display
, windowmenu
->getWindowID());
2624 XRaiseWindow(display
, windowmenu
->getSendToMenu()->getWindowID());
2625 stack_change
= 0; // dont raise the window overtop of the menu
2630 } else if (be
->state
== 0 && be
->button
== 4) {
2631 if ((be
->window
== frame
.label
||
2632 be
->window
== frame
.title
) &&
2636 } else if (be
->state
== 0 && be
->button
== 5) {
2637 if ((be
->window
== frame
.label
||
2638 be
->window
== frame
.title
) &&
2643 if (! (flags
.focused
|| screen
->sloppyFocus()) ) {
2644 setInputFocus(); // any click focus' the window in 'click to focus'
2646 if (stack_change
< 0) {
2647 screen
->getWorkspace(workspace_number
)->lowerWindow(this);
2648 } else if (stack_change
> 0) {
2649 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
2656 void OpenboxWindow::buttonReleaseEvent(XButtonEvent
*re
) {
2658 if (! validateClient())
2661 // alt + middle button released
2662 if (re
->state
== (Mod1Mask
& Button2Mask
) && re
->button
== 2) {
2663 if (re
->window
== frame
.window
) {
2664 XUngrabPointer(display
, CurrentTime
); // why? i dont know
2666 // left button released
2667 } else if (re
->button
== 1) {
2668 if (re
->window
== frame
.maximize_button
) {
2669 if (re
->state
== Button1Mask
&& // only the left button was depressed
2670 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2671 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2672 maximize(re
->button
);
2674 redrawMaximizeButton(False
);
2676 } else if (re
->window
== frame
.iconify_button
) {
2677 if (re
->state
== Button1Mask
&& // only the left button was depressed
2678 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2679 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2682 redrawIconifyButton(False
);
2684 } else if (re
->window
== frame
.close_button
) {
2685 if (re
->state
== Button1Mask
&& // only the left button was depressed
2686 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2687 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2690 //we should always redraw the close button. some applications
2691 //eg. acroread don't honour the close.
2692 redrawCloseButton(False
);
2694 // middle button released
2695 } else if (re
->button
== 2) {
2696 if (re
->window
== frame
.maximize_button
) {
2697 if (re
->state
== Button2Mask
&& // only the middle button was depressed
2698 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2699 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2700 maximize(re
->button
);
2702 redrawMaximizeButton(False
);
2705 // right button released
2706 } else if (re
->button
== 3) {
2707 if (re
->window
== frame
.maximize_button
) {
2708 if (re
->state
== Button3Mask
&& // only the right button was depressed
2709 (re
->x
>= 0) && ((unsigned) re
->x
<= frame
.button_w
) &&
2710 (re
->y
>= 0) && ((unsigned) re
->y
<= frame
.button_h
)) {
2711 maximize(re
->button
);
2713 redrawMaximizeButton(False
);
2718 // when the window is being interactively moved, a button release stops the
2721 flags
.moving
= False
;
2723 openbox
.maskWindowEvents(0, (OpenboxWindow
*) 0);
2724 if (!screen
->opaqueMove()) {
2725 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2726 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2727 frame
.resize_h
- 1);
2729 configure(frame
.move_x
, frame
.move_y
, frame
.width
, frame
.height
);
2732 configure(frame
.x
, frame
.y
, frame
.width
, frame
.height
);
2734 screen
->hideGeometry();
2735 XUngrabPointer(display
, CurrentTime
);
2736 // when the window is being interactively resized, a button release stops the
2738 } else if (flags
.resizing
) {
2739 flags
.resizing
= False
;
2740 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2741 frame
.resize_x
, frame
.resize_y
,
2742 frame
.resize_w
- 1, frame
.resize_h
- 1);
2743 screen
->hideGeometry();
2744 if (resize_zone
& ZoneLeft
) {
2746 } else { // when resizing with "Alt+Button3", the resize is the same as if
2747 // done with the right grip (the right side of the window is what
2751 // unset maximized state when resized after fully maximized
2752 if (flags
.maximized
== 1) {
2755 configure(frame
.resize_x
, frame
.resize_y
,
2756 frame
.resize_w
- (frame
.border_w
* 2),
2757 frame
.resize_h
- (frame
.border_w
* 2));
2759 XUngrabPointer(display
, CurrentTime
);
2767 void OpenboxWindow::motionNotifyEvent(XMotionEvent
*me
) {
2768 if (!flags
.resizing
&& (me
->state
& Button1Mask
) && functions
.move
&&
2769 (frame
.title
== me
->window
|| frame
.label
== me
->window
||
2770 frame
.handle
== me
->window
|| frame
.window
== me
->window
)) {
2771 if (! flags
.moving
) {
2772 XGrabPointer(display
, me
->window
, False
, Button1MotionMask
|
2773 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
,
2774 None
, openbox
.getMoveCursor(), CurrentTime
);
2776 if (windowmenu
&& windowmenu
->isVisible())
2779 flags
.moving
= True
;
2781 openbox
.maskWindowEvents(client
.window
, this);
2783 if (! screen
->opaqueMove()) {
2786 frame
.move_x
= frame
.x
;
2787 frame
.move_y
= frame
.y
;
2788 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2789 frame
.resize_h
= ((flags
.shaded
) ? frame
.title_h
: frame
.height
) +
2790 (frame
.border_w
* 2);
2792 screen
->showPosition(frame
.x
, frame
.y
);
2794 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2795 frame
.move_x
, frame
.move_y
,
2796 frame
.resize_w
- 1, frame
.resize_h
- 1);
2799 int dx
= me
->x_root
- frame
.grab_x
, dy
= me
->y_root
- frame
.grab_y
;
2801 dx
-= frame
.border_w
;
2802 dy
-= frame
.border_w
;
2804 int snap_distance
= screen
->edgeSnapThreshold();
2805 // width/height of the snapping window
2806 unsigned int snap_w
= frame
.width
+ (frame
.border_w
* 2);
2807 unsigned int snap_h
= size().h() + (frame
.border_w
* 2);
2808 if (snap_distance
) {
2809 int drx
= screen
->size().w() - (dx
+ snap_w
);
2811 if (dx
< drx
&& (dx
> 0 && dx
< snap_distance
) ||
2812 (dx
< 0 && dx
> -snap_distance
) )
2814 else if ( (drx
> 0 && drx
< snap_distance
) ||
2815 (drx
< 0 && drx
> -snap_distance
) )
2816 dx
= screen
->size().w() - snap_w
;
2818 int dtty
, dbby
, dty
, dby
;
2819 switch (screen
->getToolbar()->placement()) {
2820 case Toolbar::TopLeft
:
2821 case Toolbar::TopCenter
:
2822 case Toolbar::TopRight
:
2823 dtty
= screen
->getToolbar()->getExposedHeight() +
2825 dbby
= screen
->size().h();
2830 dbby
= screen
->getToolbar()->getY();
2835 dby
= dbby
- (dy
+ snap_h
);
2837 if ( (dy
> 0 && dty
< snap_distance
) ||
2838 (dy
< 0 && dty
> -snap_distance
) )
2840 else if ( (dby
> 0 && dby
< snap_distance
) ||
2841 (dby
< 0 && dby
> -snap_distance
) )
2845 if (screen
->opaqueMove()) {
2846 configure(dx
, dy
, frame
.width
, frame
.height
);
2848 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2849 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2850 frame
.resize_h
- 1);
2855 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2856 frame
.move_x
, frame
.move_y
, frame
.resize_w
- 1,
2857 frame
.resize_h
- 1);
2860 screen
->showPosition(dx
, dy
);
2862 } else if (functions
.resize
&&
2863 (((me
->state
& Button1Mask
) && (me
->window
== frame
.right_grip
||
2864 me
->window
== frame
.left_grip
)) ||
2865 (me
->state
& (Mod1Mask
| Button3Mask
) &&
2866 me
->window
== frame
.window
))) {
2867 Bool left
= resize_zone
& ZoneLeft
;
2869 if (! flags
.resizing
) {
2871 if (resize_zone
& ZoneTop
)
2872 cursor
= (resize_zone
& ZoneLeft
) ?
2873 openbox
.getUpperLeftAngleCursor() :
2874 openbox
.getUpperRightAngleCursor();
2876 cursor
= (resize_zone
& ZoneLeft
) ?
2877 openbox
.getLowerLeftAngleCursor() :
2878 openbox
.getLowerRightAngleCursor();
2879 XGrabPointer(display
, me
->window
, False
, ButtonMotionMask
|
2880 ButtonReleaseMask
, GrabModeAsync
, GrabModeAsync
, None
,
2881 cursor
, CurrentTime
);
2883 flags
.resizing
= True
;
2888 if (resize_zone
& ZoneRight
)
2889 frame
.grab_x
= me
->x
- screen
->getBorderWidth();
2891 frame
.grab_x
= me
->x
+ screen
->getBorderWidth();
2892 if (resize_zone
& ZoneTop
)
2893 frame
.grab_y
= me
->y
+ screen
->getBorderWidth() * 2;
2895 frame
.grab_y
= me
->y
- screen
->getBorderWidth() * 2;
2896 frame
.resize_x
= frame
.x
;
2897 frame
.resize_y
= frame
.y
;
2898 frame
.resize_w
= frame
.width
+ (frame
.border_w
* 2);
2899 frame
.resize_h
= frame
.height
+ (frame
.border_w
* 2);
2902 left_fixsize(&gx
, &gy
);
2904 right_fixsize(&gx
, &gy
);
2906 screen
->showGeometry(gx
, gy
);
2908 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2909 frame
.resize_x
, frame
.resize_y
,
2910 frame
.resize_w
- 1, frame
.resize_h
- 1);
2912 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2913 frame
.resize_x
, frame
.resize_y
,
2914 frame
.resize_w
- 1, frame
.resize_h
- 1);
2918 if (resize_zone
& ZoneTop
)
2919 frame
.resize_h
= frame
.height
- (me
->y
- frame
.grab_y
);
2921 frame
.resize_h
= frame
.height
+ (me
->y
- frame
.grab_y
);
2922 if (frame
.resize_h
< 1) frame
.resize_h
= 1;
2925 frame
.resize_x
= me
->x_root
- frame
.grab_x
;
2926 if (frame
.resize_x
> (signed) (frame
.x
+ frame
.width
))
2927 frame
.resize_x
= frame
.resize_x
+ frame
.width
- 1;
2929 left_fixsize(&gx
, &gy
);
2931 frame
.resize_w
= frame
.width
+ (me
->x
- frame
.grab_x
);
2932 if (frame
.resize_w
< 1) frame
.resize_w
= 1;
2934 right_fixsize(&gx
, &gy
);
2937 XDrawRectangle(display
, screen
->getRootWindow(), screen
->getOpGC(),
2938 frame
.resize_x
, frame
.resize_y
,
2939 frame
.resize_w
- 1, frame
.resize_h
- 1);
2941 screen
->showGeometry(gx
, gy
);
2948 void OpenboxWindow::shapeEvent(XShapeEvent
*) {
2949 if (openbox
.hasShapeExtensions()) {
2952 if (! validateClient()) return;
2953 XShapeCombineShape(display
, frame
.window
, ShapeBounding
,
2954 frame
.mwm_border_w
, frame
.y_border
+
2955 frame
.mwm_border_w
, client
.window
,
2956 ShapeBounding
, ShapeSet
);
2959 XRectangle xrect
[2];
2960 xrect
[0].x
= xrect
[0].y
= 0;
2961 xrect
[0].width
= frame
.width
;
2962 xrect
[0].height
= frame
.y_border
;
2964 if (decorations
.handle
) {
2966 xrect
[1].y
= frame
.y_handle
;
2967 xrect
[1].width
= frame
.width
;
2968 xrect
[1].height
= frame
.handle_h
+ frame
.border_w
;
2972 XShapeCombineRectangles(display
, frame
.window
, ShapeBounding
, 0, 0,
2973 xrect
, num
, ShapeUnion
, Unsorted
);
2981 Bool
OpenboxWindow::validateClient(void) {
2982 XSync(display
, False
);
2985 if (XCheckTypedWindowEvent(display
, client
.window
, DestroyNotify
, &e
) ||
2986 XCheckTypedWindowEvent(display
, client
.window
, UnmapNotify
, &e
)) {
2987 XPutBackEvent(display
, &e
);
2997 void OpenboxWindow::restore(void) {
2998 XChangeSaveSet(display
, client
.window
, SetModeDelete
);
2999 XSelectInput(display
, client
.window
, NoEventMask
);
3003 XUnmapWindow(display
, frame
.window
);
3004 XUnmapWindow(display
, client
.window
);
3006 XSetWindowBorderWidth(display
, client
.window
, client
.old_bw
);
3007 XReparentWindow(display
, client
.window
, screen
->getRootWindow(),
3008 client
.x
, client
.y
);
3009 XMapWindow(display
, client
.window
);
3015 void OpenboxWindow::timeout(void) {
3016 screen
->getWorkspace(workspace_number
)->raiseWindow(this);
3020 void OpenboxWindow::changeOpenboxHints(OpenboxHints
*net
) {
3021 if ((net
->flags
& AttribShaded
) &&
3022 ((openbox_attrib
.attrib
& AttribShaded
) !=
3023 (net
->attrib
& AttribShaded
)))
3026 if (flags
.visible
&& // watch out for requests when we can not be seen
3027 (net
->flags
& (AttribMaxVert
| AttribMaxHoriz
)) &&
3028 ((openbox_attrib
.attrib
& (AttribMaxVert
| AttribMaxHoriz
)) !=
3029 (net
->attrib
& (AttribMaxVert
| AttribMaxHoriz
)))) {
3030 if (flags
.maximized
) {
3035 if ((net
->flags
& AttribMaxHoriz
) && (net
->flags
& AttribMaxVert
))
3036 button
= ((net
->attrib
& (AttribMaxHoriz
| AttribMaxVert
)) ? 1 : 0);
3037 else if (net
->flags
& AttribMaxVert
)
3038 button
= ((net
->attrib
& AttribMaxVert
) ? 2 : 0);
3039 else if (net
->flags
& AttribMaxHoriz
)
3040 button
= ((net
->attrib
& AttribMaxHoriz
) ? 3 : 0);
3046 if ((net
->flags
& AttribOmnipresent
) &&
3047 ((openbox_attrib
.attrib
& AttribOmnipresent
) !=
3048 (net
->attrib
& AttribOmnipresent
)))
3051 if ((net
->flags
& AttribWorkspace
) &&
3052 (workspace_number
!= (signed) net
->workspace
)) {
3053 screen
->reassociateWindow(this, net
->workspace
, True
);
3055 if (screen
->getCurrentWorkspaceID() != (signed) net
->workspace
) withdraw();
3059 if (net
->flags
& AttribDecoration
) {
3060 switch (net
->decoration
) {
3062 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3063 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= False
;
3069 decorations
.titlebar
= decorations
.border
= decorations
.handle
=
3070 decorations
.iconify
= decorations
.maximize
= decorations
.menu
= True
;
3075 decorations
.titlebar
= decorations
.iconify
= decorations
.menu
= True
;
3076 decorations
.border
= decorations
.handle
= decorations
.maximize
= False
;
3081 decorations
.titlebar
= decorations
.menu
= functions
.move
= True
;
3082 decorations
.iconify
= decorations
.border
= decorations
.handle
=
3083 decorations
.maximize
= False
;
3088 XMapSubwindows(display
, frame
.window
);
3089 XMapWindow(display
, frame
.window
);
3093 setState(current_state
);
3099 * Set the sizes of all components of the window frame
3100 * (the window decorations).
3101 * These values are based upon the current style settings and the client
3102 * window's dimentions.
3104 void OpenboxWindow::upsize(void) {
3105 frame
.bevel_w
= screen
->getBevelWidth();
3107 if (decorations
.border
) {
3108 frame
.border_w
= screen
->getBorderWidth();
3109 if (!flags
.transient
)
3110 frame
.mwm_border_w
= screen
->getFrameWidth();
3112 frame
.mwm_border_w
= 0;
3114 frame
.mwm_border_w
= frame
.border_w
= 0;
3117 if (decorations
.titlebar
) {
3118 // the height of the titlebar is based upon the height of the font being
3119 // used to display the window's title
3120 WindowStyle
*style
= screen
->getWindowStyle();
3121 if (i18n
->multibyte())
3122 frame
.title_h
= (style
->fontset_extents
->max_ink_extent
.height
+
3123 (frame
.bevel_w
* 2) + 2);
3125 frame
.title_h
= (style
->font
->ascent
+ style
->font
->descent
+
3126 (frame
.bevel_w
* 2) + 2);
3128 frame
.label_h
= frame
.title_h
- (frame
.bevel_w
* 2);
3129 frame
.button_w
= frame
.button_h
= (frame
.label_h
- 2);
3130 frame
.y_border
= frame
.title_h
+ frame
.border_w
;
3134 frame
.button_w
= frame
.button_h
= 0;
3138 frame
.border_h
= client
.height
+ frame
.mwm_border_w
* 2;
3140 if (decorations
.handle
) {
3141 frame
.y_handle
= frame
.y_border
+ frame
.border_h
+ frame
.border_w
;
3142 frame
.grip_w
= frame
.button_w
* 2;
3143 frame
.grip_h
= frame
.handle_h
= screen
->getHandleWidth();
3145 frame
.y_handle
= frame
.y_border
+ frame
.border_h
;
3147 frame
.grip_w
= frame
.grip_h
= 0;
3150 frame
.width
= client
.width
+ (frame
.mwm_border_w
* 2);
3151 frame
.height
= frame
.y_handle
+ frame
.handle_h
;
3156 * Set the size and position of the client window.
3157 * These values are based upon the current style settings and the frame
3158 * window's dimensions.
3160 void OpenboxWindow::downsize(void) {
3161 frame
.y_handle
= frame
.height
- frame
.handle_h
;
3162 frame
.border_h
= frame
.y_handle
- frame
.y_border
-
3163 (decorations
.handle
? frame
.border_w
: 0);
3165 client
.x
= frame
.x
+ frame
.mwm_border_w
+ frame
.border_w
;
3166 client
.y
= frame
.y
+ frame
.y_border
+ frame
.mwm_border_w
+ frame
.border_w
;
3168 client
.width
= frame
.width
- (frame
.mwm_border_w
* 2);
3169 client
.height
= frame
.height
- frame
.y_border
- (frame
.mwm_border_w
* 2)
3170 - frame
.handle_h
- (decorations
.handle
? frame
.border_w
: 0);
3172 frame
.y_handle
= frame
.border_h
+ frame
.y_border
+ frame
.border_w
;
3176 void OpenboxWindow::right_fixsize(int *gx
, int *gy
) {
3177 // calculate the size of the client window and conform it to the
3178 // size specified by the size hints of the client window...
3179 int dx
= frame
.resize_w
- client
.base_width
- (frame
.mwm_border_w
* 2) -
3180 (frame
.border_w
* 2) + (client
.width_inc
/ 2);
3181 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3182 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3183 + (client
.height_inc
/ 2);
3185 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3186 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3187 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3188 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3190 dx
/= client
.width_inc
;
3191 dy
/= client
.height_inc
;
3196 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3197 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3199 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3200 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3201 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3202 if (resize_zone
& ZoneTop
)
3203 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3204 screen
->getBorderWidth() * 2;
3208 void OpenboxWindow::left_fixsize(int *gx
, int *gy
) {
3209 // calculate the size of the client window and conform it to the
3210 // size specified by the size hints of the client window...
3211 int dx
= frame
.x
+ frame
.width
- frame
.resize_x
- client
.base_width
-
3212 (frame
.mwm_border_w
* 2) + (client
.width_inc
/ 2);
3213 int dy
= frame
.resize_h
- frame
.y_border
- client
.base_height
-
3214 frame
.handle_h
- (frame
.border_w
* 3) - (frame
.mwm_border_w
* 2)
3215 + (client
.height_inc
/ 2);
3217 if (dx
< (signed) client
.min_width
) dx
= client
.min_width
;
3218 if (dy
< (signed) client
.min_height
) dy
= client
.min_height
;
3219 if ((unsigned) dx
> client
.max_width
) dx
= client
.max_width
;
3220 if ((unsigned) dy
> client
.max_height
) dy
= client
.max_height
;
3222 dx
/= client
.width_inc
;
3223 dy
/= client
.height_inc
;
3228 dx
= (dx
* client
.width_inc
) + client
.base_width
;
3229 dy
= (dy
* client
.height_inc
) + client
.base_height
;
3231 frame
.resize_w
= dx
+ (frame
.mwm_border_w
* 2) + (frame
.border_w
* 2);
3232 frame
.resize_x
= frame
.x
+ frame
.width
- frame
.resize_w
+
3233 (frame
.border_w
* 2);
3234 frame
.resize_h
= dy
+ frame
.y_border
+ frame
.handle_h
+
3235 (frame
.mwm_border_w
* 2) + (frame
.border_w
* 3);
3236 if (resize_zone
& ZoneTop
)
3237 frame
.resize_y
= frame
.y
+ frame
.height
- frame
.resize_h
+
3238 screen
->getBorderWidth() * 2;