1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
38 #include "WindowMaker.h"
44 #include "winspector.h"
46 #include "properties.h"
53 #include "workspace.h"
65 # include "openlook.h"
68 /****** Global Variables ******/
70 extern WShortKey wKeyBindings
[WKBD_LAST
];
73 extern Bool wShapeSupported
;
77 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
83 extern Atom _XA_WM_DELETE_WINDOW
;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
86 extern Atom _XA_WINDOWMAKER_STATE
;
88 extern WPreferences wPreferences
;
90 #define MOD_MASK wPreferences.modifier_mask
92 extern Time LastTimestamp
;
95 extern void DoWindowBirth(WWindow
*);
98 /***** Local Stuff *****/
101 static WWindowState
*windowState
=NULL
;
105 /* local functions */
106 static FocusMode
getFocusMode(WWindow
*wwin
);
108 static int getSavedState(Window window
, WSavedState
**state
);
110 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
115 /* frame window (during window grabs) */
116 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
119 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
120 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
123 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
126 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
127 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
129 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
132 /****** Notification Observers ******/
135 appearanceObserver(void *self
, WMNotification
*notif
)
137 WWindow
*wwin
= (WWindow
*)self
;
138 int flags
= (int)WMGetNotificationClientData(notif
);
140 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
143 if (flags
& WFontSettings
) {
144 wWindowConfigureBorders(wwin
);
146 if (flags
& WTextureSettings
) {
147 wwin
->frame
->flags
.need_texture1_remake
= 1;
148 wwin
->frame
->flags
.need_texture2_remake
= 1;
149 wwin
->frame
->flags
.need_texture3_remake
= 1;
151 if (flags
& (WTextureSettings
| WColorSettings
)) {
152 if (wwin
->frame
->titlebar
)
153 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
155 wFrameWindowPaint(wwin
->frame
);
159 /************************************/
162 wWindowFor(Window window
)
164 WObjDescriptor
*desc
;
169 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
172 if (desc
->parent_type
==WCLASS_WINDOW
)
174 else if (desc
->parent_type
==WCLASS_FRAME
) {
175 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
176 if (frame
->flags
.is_client_window_frame
)
189 wwin
= wmalloc(sizeof(WWindow
));
192 memset(wwin
, 0, sizeof(WWindow
));
194 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
195 wwin
->client_descriptor
.parent
= wwin
;
196 wwin
->client_descriptor
.self
= wwin
;
197 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
204 wWindowDestroy(WWindow
*wwin
)
208 WMRemoveNotificationObserver(wwin
);
210 wwin
->flags
.destroyed
= 1;
212 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
213 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
) {
214 wwin
->screen_ptr
->shortcutWindow
[i
] = NULL
;
218 if (wwin
->normal_hints
)
219 free(wwin
->normal_hints
);
222 XFree(wwin
->wm_hints
);
224 if (wwin
->wm_instance
)
225 XFree(wwin
->wm_instance
);
228 XFree(wwin
->wm_class
);
230 if (wwin
->wm_gnustep_attr
)
231 free(wwin
->wm_gnustep_attr
);
233 if (wwin
->cmap_windows
)
234 XFree(wwin
->cmap_windows
);
236 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
239 wFrameWindowDestroy(wwin
->frame
);
242 RemoveFromStackList(wwin
->icon
->core
);
243 wIconDestroy(wwin
->icon
);
244 if (wPreferences
.auto_arrange_icons
)
245 wArrangeIcons(wwin
->screen_ptr
, True
);
254 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
256 if (gs_hints
->flags
& GSWindowStyleAttr
) {
257 wwin
->client_flags
.no_titlebar
=
258 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
260 wwin
->client_flags
.no_close_button
=
261 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
263 wwin
->client_flags
.no_closable
=
264 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
266 wwin
->client_flags
.no_miniaturize_button
=
267 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
269 wwin
->client_flags
.no_miniaturizable
=
270 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
272 wwin
->client_flags
.no_resizebar
=
273 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
275 wwin
->client_flags
.no_resizable
=
276 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
278 /* setup the defaults */
279 wwin
->client_flags
.no_titlebar
= 0;
280 wwin
->client_flags
.no_closable
= 0;
281 wwin
->client_flags
.no_miniaturizable
= 0;
282 wwin
->client_flags
.no_resizable
= 0;
283 wwin
->client_flags
.no_close_button
= 0;
284 wwin
->client_flags
.no_miniaturize_button
= 0;
285 wwin
->client_flags
.no_resizebar
= 0;
287 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
288 wwin
->client_flags
.no_appicon
= 1;
294 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
295 WWindowAttributes
*mask
)
297 if (wflags
->no_appicon
&& mask
->no_appicon
)
298 wflags
->emulate_appicon
= 0;
300 if (wwin
->main_window
!=None
) {
301 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
302 if (wapp
&& !wapp
->flags
.emulated
)
303 wflags
->emulate_appicon
= 0;
306 if (wwin
->transient_for
!=None
307 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
308 wflags
->emulate_appicon
= 0;
310 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
317 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
319 WScreen
*scr
= wwin
->screen_ptr
;
321 /* sets global default stuff */
322 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
323 &wwin
->client_flags
, NULL
, True
);
325 * Decoration setting is done in this precedence (lower to higher)
326 * - use global default in the resource database
327 * - guess some settings
328 * - use GNUstep/external window attributes
329 * - set hints specified for the app in the resource DB
332 WSETUFLAG(wwin
, broken_close
, 0);
334 if (wwin
->protocols
.DELETE_WINDOW
)
335 WSETUFLAG(wwin
, kill_close
, 0);
337 WSETUFLAG(wwin
, kill_close
, 1);
339 /* transients can't be iconified or maximized */
340 if (wwin
->transient_for
) {
341 WSETUFLAG(wwin
, no_miniaturizable
, 1);
342 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
345 /* if the window can't be resized, remove the resizebar */
346 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
347 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
348 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
349 WSETUFLAG(wwin
, no_resizable
, 1);
350 WSETUFLAG(wwin
, no_resizebar
, 1);
353 /* set GNUstep window attributes */
354 if (wwin
->wm_gnustep_attr
) {
355 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
357 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
359 switch (wwin
->wm_gnustep_attr
->window_level
) {
360 case WMNormalWindowLevel
:
361 *level
= WMNormalLevel
;
363 case WMFloatingWindowLevel
:
364 *level
= WMFloatingLevel
;
366 case WMDockWindowLevel
:
367 *level
= WMDockLevel
;
369 case WMSubmenuWindowLevel
:
370 *level
= WMSubmenuLevel
;
372 case WMMainMenuWindowLevel
:
373 *level
= WMMainMenuLevel
;
376 *level
= WMNormalLevel
;
381 *level
= WMNormalLevel
;
384 int tmp_workspace
= -1;
388 wMWMCheckClientHints(wwin
);
389 #endif /* MWM_HINTS */
392 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
393 #endif /* KWM_HINTS */
396 wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
397 #endif /* GNOME_STUFF */
400 wOLWMCheckClientHints(wwin
);
401 #endif /* OLWM_HINTS */
404 if (WFLAGP(wwin
, floating
))
405 *level
= WMFloatingLevel
;
406 else if (WFLAGP(wwin
, sunken
))
407 *level
= WMSunkenLevel
;
409 *level
= WMNormalLevel
;
414 if (tmp_workspace
>= 0) {
415 *workspace
= tmp_workspace
% scr
->workspace_count
;
420 * Set attributes specified only for that window/class.
421 * This might do duplicate work with the 1st wDefaultFillAttributes().
423 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
424 &wwin
->user_flags
, &wwin
->defined_user_flags
,
427 * Sanity checks for attributes that depend on other attributes
429 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
430 wwin
->user_flags
.emulate_appicon
= 0;
432 if (wwin
->main_window
!=None
) {
433 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
434 if (wapp
&& !wapp
->flags
.emulated
)
435 wwin
->user_flags
.emulate_appicon
= 0;
438 if (wwin
->transient_for
!=None
439 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
440 wwin
->user_flags
.emulate_appicon
= 0;
442 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
443 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
444 wwin
->user_flags
.sunken
= 0;
446 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
453 wWindowCanReceiveFocus(WWindow
*wwin
)
455 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
457 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
459 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
467 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
471 w1
= wwin
->frame
->core
->width
;
472 h1
= wwin
->frame
->core
->height
;
473 w2
= obscured
->frame
->core
->width
;
474 h2
= obscured
->frame
->core
->height
;
476 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
477 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
480 if (wwin
->frame_x
+ w1
< obscured
->frame_x
481 || wwin
->frame_y
+ h1
< obscured
->frame_y
482 || wwin
->frame_x
> obscured
->frame_x
+ w2
483 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
492 *----------------------------------------------------------------
494 * reparents the window and allocates a descriptor for it.
495 * Window manager hints and other hints are fetched to configure
496 * the window decoration attributes and others. User preferences
497 * for the window are used if available, to configure window
498 * decorations and some behaviour.
499 * If in startup, windows that are override redirect,
500 * unmapped and never were managed and are Withdrawn are not
504 * the new window descriptor
507 * The window is reparented and appropriate notification
508 * is done to the client. Input mask for the window is setup.
509 * The window descriptor is also associated with various window
510 * contexts and inserted in the head of the window list.
511 * Event handler contexts are associated for some objects
512 * (buttons, titlebar and resizebar)
514 *----------------------------------------------------------------
517 wManageWindow(WScreen
*scr
, Window window
)
521 unsigned width
, height
;
522 XWindowAttributes wattribs
;
523 XSetWindowAttributes attribs
;
524 WWindowState
*win_state
;
525 WWindow
*transientOwner
= NULL
;
531 Bool withdraw
= False
;
534 /* XGrabServer(dpy); */
536 /* make sure the window is still there */
537 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
542 /* if it's an override-redirect, ignore it */
543 if (wattribs
.override_redirect
) {
548 wm_state
= PropGetWindowState(window
);
550 /* if it's startup and the window is unmapped, don't manage it */
551 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
556 if (!wFetchName(dpy
, window
, &title
)) {
561 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
566 #endif /* KWM_HINTS */
569 wwin
= wWindowCreate();
571 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
574 printf("managing window %x\n", (unsigned)window
);
578 if (wShapeSupported
) {
583 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
584 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
585 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
586 wwin
->flags
.shaped
= b_shaped
;
591 *--------------------------------------------------
593 * Get hints and other information in properties
595 *--------------------------------------------------
597 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
599 /* setup descriptor */
600 wwin
->client_win
= window
;
601 wwin
->screen_ptr
= scr
;
603 wwin
->old_border_width
= wattribs
.border_width
;
605 wwin
->event_mask
= CLIENT_EVENTS
;
606 attribs
.event_mask
= CLIENT_EVENTS
;
607 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
608 attribs
.save_under
= False
;
609 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
610 |CWSaveUnder
, &attribs
);
611 XSetWindowBorderWidth(dpy
, window
, 0);
613 /* get hints from GNUstep app */
614 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
615 wwin
->wm_gnustep_attr
= NULL
;
618 wwin
->client_leader
= PropGetClientLeader(window
);
619 if (wwin
->client_leader
!=None
)
620 wwin
->main_window
= wwin
->client_leader
;
622 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
624 if (wwin
->wm_hints
) {
625 if (wwin
->wm_hints
->flags
& StateHint
) {
627 if (wwin
->wm_hints
->initial_state
== IconicState
) {
629 wwin
->flags
.miniaturized
= 1;
631 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
637 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
638 wwin
->group_id
= wwin
->wm_hints
->window_group
;
639 /* window_group has priority over CLIENT_LEADER */
640 wwin
->main_window
= wwin
->group_id
;
642 wwin
->group_id
= None
;
645 if (wwin
->wm_hints
->flags
& UrgencyHint
)
646 wwin
->flags
.urgent
= 1;
648 wwin
->group_id
= None
;
651 PropGetProtocols(window
, &wwin
->protocols
);
653 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
654 wwin
->transient_for
= None
;
656 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
657 wwin
->transient_for
= scr
->root_win
;
659 transientOwner
= wWindowFor(wwin
->transient_for
);
660 if (transientOwner
&& transientOwner
->main_window
!=None
) {
661 wwin
->main_window
= transientOwner
->main_window
;
663 wwin->main_window = None;
668 /* guess the focus mode */
669 wwin
->focus_mode
= getFocusMode(wwin
);
671 /* get geometry stuff */
672 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
674 /* get colormap windows */
675 GetColormapWindows(wwin
);
678 *--------------------------------------------------
680 * Setup the decoration/window attributes and
683 *--------------------------------------------------
686 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
689 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
690 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
692 transientOwner
= wWindowFor(wwin
->group_id
);
694 if (transientOwner
) {
695 wwin
->transient_for
= wwin
->group_id
;
697 /* transients can't be iconified or maximized */
698 if (wwin
->transient_for
) {
699 WSETUFLAG(wwin
, no_miniaturizable
, 1);
700 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
704 #endif /* OLWM_HINTS */
707 * Make broken apps behave as a nice app.
709 if (WFLAGP(wwin
, emulate_appicon
)) {
710 wwin
->main_window
= wwin
->client_win
;
714 *------------------------------------------------------------
716 * Setup the initial state of the window
718 *------------------------------------------------------------
721 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
722 wwin
->flags
.miniaturized
= 1;
725 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
726 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
730 wGNOMECheckInitialClientState(wwin
);
733 wKWMCheckClientInitialState(wwin
);
736 /* apply previous state if it exists and we're in startup */
737 if (scr
->flags
.startup
&& wm_state
>= 0) {
739 if (wm_state
== IconicState
) {
741 wwin
->flags
.miniaturized
= 1;
743 } else if (wm_state
== WithdrawnState
) {
749 /* if there is a saved state (from file), restore it */
751 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
752 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
754 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
756 if (win_state
&& !withdraw
) {
758 if (win_state
->state
->hidden
>0)
759 wwin
->flags
.hidden
= win_state
->state
->hidden
;
761 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
762 wwin
->flags
.shaded
= win_state
->state
->shaded
;
764 if (win_state
->state
->miniaturized
>0 &&
765 !WFLAGP(wwin
, no_miniaturizable
)) {
766 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
768 if (!IS_OMNIPRESENT(wwin
)) {
769 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
771 if (w
< 0 || w
>= scr
->workspace_count
) {
772 workspace
= win_state
->state
->workspace
;
773 if (workspace
>= scr
->workspace_count
)
774 workspace
= scr
->current_workspace
;
779 workspace
= scr
->current_workspace
;
783 /* if we're restarting, restore saved state (from hints).
784 * This will overwrite previous */
788 if (getSavedState(window
, &wstate
)) {
789 wwin
->flags
.shaded
= wstate
->shaded
;
790 wwin
->flags
.hidden
= wstate
->hidden
;
791 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
792 workspace
= wstate
->workspace
;
794 if (scr
->flags
.startup
&& wstate
->window_shortcuts
>= 0) {
797 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
798 if (wstate
->window_shortcuts
& (1<<i
))
799 scr
->shortcutWindow
[i
] = wwin
;
806 /* don't let transients start miniaturized if their owners are not */
807 if (transientOwner
&& !transientOwner
->flags
.miniaturized
808 && wwin
->flags
.miniaturized
&& !withdraw
) {
809 wwin
->flags
.miniaturized
= 0;
811 wwin
->wm_hints
->initial_state
= NormalState
;
814 /* set workspace on which the window starts */
815 if (workspace
>= 0) {
816 if (workspace
> scr
->workspace_count
-1) {
817 workspace
= workspace
% scr
->workspace_count
;
822 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
824 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
829 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
831 workspace
= transientOwner
->frame
->workspace
;
835 workspace
= scr
->current_workspace
;
840 /* setup window geometry */
841 if (win_state
&& win_state
->state
->use_geometry
) {
842 width
= win_state
->state
->w
;
843 height
= win_state
->state
->h
;
845 wWindowConstrainSize(wwin
, &width
, &height
);
847 /* do not ask for window placement if the window is
848 * transient, during startup, if the initial workspace is another one
849 * or if the window wants to start iconic.
850 * If geometry was saved, restore it. */
852 Bool dontBring
= False
;
854 if (win_state
&& win_state
->state
->use_geometry
) {
855 x
= win_state
->state
->x
;
856 y
= win_state
->state
->y
;
857 } else if ((wwin
->transient_for
==None
858 || wPreferences
.window_placement
!=WPM_MANUAL
)
859 && !scr
->flags
.startup
860 && workspace
== scr
->current_workspace
861 && !wwin
->flags
.miniaturized
862 && !wwin
->flags
.maximized
863 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
864 PlaceWindow(wwin
, &x
, &y
, width
, height
);
865 if (wPreferences
.window_placement
== WPM_MANUAL
)
869 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
870 wScreenBringInside(scr
, &x
, &y
, width
, height
);
873 if (wwin
->flags
.urgent
) {
874 if (!IS_OMNIPRESENT(wwin
))
875 wwin
->flags
.omnipresent
^= 1;
879 *--------------------------------------------------
881 * Create frame, borders and do reparenting
883 *--------------------------------------------------
885 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
886 if (!WFLAGP(wwin
, no_titlebar
))
888 if (!WFLAGP(wwin
, no_resizebar
))
889 foo
|= WFF_RESIZEBAR
;
891 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
892 x
, y
, width
, height
, foo
,
893 scr
->window_title_texture
,
894 scr
->resizebar_texture
,
895 scr
->window_title_pixel
,
896 &scr
->window_title_gc
,
899 wwin
->frame
->flags
.is_client_window_frame
= 1;
900 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
902 /* setup button images */
903 wWindowUpdateButtonImages(wwin
);
905 /* hide unused buttons */
907 if (WFLAGP(wwin
, no_close_button
))
908 foo
|= WFF_RIGHT_BUTTON
;
909 if (WFLAGP(wwin
, no_miniaturize_button
))
910 foo
|= WFF_LEFT_BUTTON
;
912 wFrameWindowHideButton(wwin
->frame
, foo
);
914 wwin
->frame
->child
= wwin
;
917 /* emulate olwm push pin. Make the button look as pushed-in for
918 * the pinned-out state. When the button is clicked, it will
919 * revert to the normal position, which means the pin is pinned-in.
921 if (wwin
->flags
.olwm_push_pin_out
)
922 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
923 #endif /* OLWM_HINTS */
925 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
929 wwin
->frame
->workspace
= workspace
;
931 wwin
->frame
->on_click_left
= windowIconifyClick
;
933 wwin
->frame
->on_click_right
= windowCloseClick
;
934 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
936 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
937 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
939 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
942 XSelectInput(dpy
, wwin
->client_win
,
943 wwin
->event_mask
& ~StructureNotifyMask
);
945 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
946 0, wwin
->frame
->top_width
);
948 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
954 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
956 /* if gravity is to the south, account for the border sizes */
958 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
962 * wWindowConfigure() will init the client window's size
963 * (wwin->client.{width,height}) and all other geometry
964 * related variables (frame_x,frame_y)
966 wWindowConfigure(wwin
, x
, y
, width
, height
);
968 /* to make sure the window receives it's new position after reparenting */
969 wWindowSynthConfigureNotify(wwin
);
972 *--------------------------------------------------
974 * Setup descriptors and save window to internal
977 *--------------------------------------------------
980 if (wwin
->main_window
!=None
) {
984 /* Leader windows do not necessary set themselves as leaders.
985 * If this is the case, point the leader of this window to
987 leader
= wWindowFor(wwin
->main_window
);
988 if (leader
&& leader
->main_window
==None
) {
989 leader
->main_window
= leader
->client_win
;
991 app
= wApplicationCreate(scr
, wwin
->main_window
);
993 app
->last_workspace
= workspace
;
996 * Do application specific stuff, like setting application
1000 if (wwin
->flags
.hidden
) {
1001 /* if the window was set to hidden because it was hidden
1002 * in a previous incarnation and that state was restored */
1003 app
->flags
.hidden
= 1;
1006 if (app
->flags
.hidden
) {
1007 wwin
->flags
.hidden
= 1;
1012 /* setup the frame descriptor */
1013 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1014 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1015 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1017 /* don't let windows go away if we die */
1018 XAddToSaveSet(dpy
, window
);
1020 XLowerWindow(dpy
, window
);
1022 /* if window is in this workspace and should be mapped, then map it */
1023 if (!wwin
->flags
.miniaturized
1024 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1025 && !wwin
->flags
.hidden
&& !withdraw
) {
1027 /* The following "if" is to avoid crashing of clients that expect
1028 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1029 * after the return from this function.
1031 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1032 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1034 wClientSetState(wwin
, NormalState
, None
);
1038 /* if not auto focus, then map the window under the currently
1040 #define _WIDTH(w) (w)->frame->core->width
1041 #define _HEIGHT(w) (w)->frame->core->height
1042 if (!wPreferences
.auto_focus
&& scr
->focused_window
1043 && !scr
->flags
.startup
&& !transientOwner
1044 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1045 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1046 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1047 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1048 || wwin
->flags
.maximized
)) {
1049 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1057 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1058 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1060 * The brain damaged idiotic non-click to focus modes will
1061 * have trouble with this because:
1063 * 1. window is created and mapped by the client
1064 * 2. window is mapped by wmaker in small size
1065 * 3. window is animated to grow to normal size
1066 * 4. this function returns to normal event loop
1067 * 5. eventually, the EnterNotify event that would trigger
1068 * the window focusing (if the mouse is over that window)
1069 * will be processed by wmaker.
1070 * But since this event will be rather delayed
1071 * (step 3 has a large delay) the time when the event ocurred
1072 * and when it is processed, the client that owns that window
1073 * will reject the XSetInputFocus() for it.
1075 && (wPreferences
.focus_mode
==WKF_CLICK
1076 || wPreferences
.auto_focus
)) {
1077 DoWindowBirth(wwin
);
1083 /* setup stacking descriptor */
1084 if (transientOwner
) {
1085 /* && wPreferences.on_top_transients */
1086 if (transientOwner
) {
1087 wwin
->frame
->core
->stacking
->child_of
=
1088 transientOwner
->frame
->core
;
1091 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1095 if (!scr
->focused_window
) {
1096 /* first window on the list */
1099 scr
->focused_window
= wwin
;
1103 /* add window at beginning of focus window list */
1104 tmp
= scr
->focused_window
;
1113 wGNOMEUpdateClientStateHint(wwin
, True
);
1116 wKWMUpdateClientWorkspace(wwin
);
1117 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1123 *--------------------------------------------------
1125 * Final preparations before window is ready to go
1127 *--------------------------------------------------
1130 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1133 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1134 && !wwin
->flags
.hidden
) {
1135 if ((transientOwner
&& transientOwner
->flags
.focused
)
1136 || wPreferences
.auto_focus
)
1137 wSetFocusTo(scr
, wwin
);
1139 wWindowResetMouseGrabs(wwin
);
1141 if (!WFLAGP(wwin
, no_bind_keys
)) {
1142 wWindowSetKeyGrabs(wwin
);
1145 wGNOMEUpdateClientListHint(scr
);
1148 wwin
->flags
.kwm_managed
= 1;
1150 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1153 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1155 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1158 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1159 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1161 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1162 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1168 *------------------------------------------------------------
1169 * Setup Notification Observers
1170 *------------------------------------------------------------
1172 WMAddNotificationObserver(appearanceObserver
, wwin
,
1173 WNWindowAppearanceSettingsChanged
, wwin
);
1177 *--------------------------------------------------
1179 * Cleanup temporary stuff
1181 *--------------------------------------------------
1185 wWindowDeleteSavedState(win_state
);
1187 /* If the window must be withdrawed, then do it now.
1188 * Must do some optimization, 'though */
1190 wwin
->flags
.mapped
= 0;
1191 wClientSetState(wwin
, WithdrawnState
, None
);
1192 wUnmanageWindow(wwin
, True
, False
);
1204 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1205 char *title
, int x
, int y
, int width
, int height
)
1210 wwin
= wWindowCreate();
1212 WMAddNotificationObserver(appearanceObserver
, wwin
,
1213 WNWindowAppearanceSettingsChanged
, wwin
);
1215 wwin
->flags
.internal_window
= 1;
1217 WSETUFLAG(wwin
, omnipresent
, 1);
1218 WSETUFLAG(wwin
, no_shadeable
, 1);
1219 WSETUFLAG(wwin
, no_resizable
, 1);
1220 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1222 wwin
->focus_mode
= WFM_PASSIVE
;
1224 wwin
->client_win
= window
;
1225 wwin
->screen_ptr
= scr
;
1227 wwin
->transient_for
= owner
;
1231 wwin
->client
.width
= width
;
1232 wwin
->client
.height
= height
;
1234 wwin
->frame_x
= wwin
->client
.x
;
1235 wwin
->frame_y
= wwin
->client
.y
;
1238 foo
= WFF_RIGHT_BUTTON
;
1239 foo
|= WFF_TITLEBAR
;
1241 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1242 wwin
->frame_x
, wwin
->frame_y
,
1244 scr
->window_title_texture
,
1245 scr
->resizebar_texture
,
1246 scr
->window_title_pixel
,
1247 &scr
->window_title_gc
,
1250 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1252 wwin
->frame
->flags
.is_client_window_frame
= 1;
1253 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1255 wFrameWindowChangeTitle(wwin
->frame
, title
);
1257 /* setup button images */
1258 wWindowUpdateButtonImages(wwin
);
1261 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1263 wwin
->frame
->child
= wwin
;
1265 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1267 wwin
->frame
->on_click_right
= windowCloseClick
;
1269 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1270 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1272 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1274 wwin
->client
.y
+= wwin
->frame
->top_width
;
1275 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1276 0, wwin
->frame
->top_width
);
1278 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1279 wwin
->client
.width
, wwin
->client
.height
);
1281 /* setup the frame descriptor */
1282 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1283 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1284 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1287 XLowerWindow(dpy
, window
);
1288 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1290 /* setup stacking descriptor */
1293 wPreferences
.on_top_transients
&&
1295 wwin
->transient_for
!=None
1296 && wwin
->transient_for
!=scr
->root_win
) {
1298 tmp
= wWindowFor(wwin
->transient_for
);
1300 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1302 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1306 if (!scr
->focused_window
) {
1307 /* first window on the list */
1310 scr
->focused_window
= wwin
;
1314 /* add window at beginning of focus window list */
1315 tmp
= scr
->focused_window
;
1323 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1325 /* if (wPreferences.auto_focus)*/
1326 wSetFocusTo(scr
, wwin
);
1328 wWindowResetMouseGrabs(wwin
);
1330 wWindowSetKeyGrabs(wwin
);
1332 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1339 *----------------------------------------------------------------------
1341 * Removes the frame window from a window and destroys all data
1342 * related to it. The window will be reparented back to the root window
1343 * if restore is True.
1346 * Everything related to the window is destroyed and the window
1347 * is removed from the window lists. Focus is set to the previous on the
1349 *----------------------------------------------------------------------
1352 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1354 WCoreWindow
*frame
= wwin
->frame
->core
;
1355 WWindow
*owner
= NULL
;
1356 WWindow
*newFocusedWindow
= NULL
;
1358 WScreen
*scr
= wwin
->screen_ptr
;
1362 wwin
->frame
->workspace
= -1;
1364 wKWMUpdateClientWorkspace(wwin
);
1367 /* First close attribute editor window if open */
1368 if (wwin
->flags
.inspector_open
) {
1369 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1370 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1373 /* Close window menu if it's open for this window */
1374 if (wwin
->flags
.menu_open_for_me
) {
1375 CloseWindowMenu(scr
);
1379 if (!wwin
->flags
.internal_window
)
1380 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1382 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1384 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1385 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1388 XUnmapWindow(dpy
, frame
->window
);
1390 XUnmapWindow(dpy
, wwin
->client_win
);
1392 /* deselect window */
1393 wSelectWindow(wwin
, False
);
1395 /* remove all pending events on window */
1396 /* I think this only matters for autoraise */
1397 if (wPreferences
.raise_delay
)
1398 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1402 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1404 /* reparent the window back to the root */
1406 wClientRestore(wwin
);
1408 if (wwin
->transient_for
!=scr
->root_win
) {
1409 owner
= wWindowFor(wwin
->transient_for
);
1411 if (!owner
->flags
.semi_focused
) {
1414 owner
->flags
.semi_focused
= 0;
1419 wasFocused
= wwin
->flags
.focused
;
1421 /* remove from window focus list */
1422 if (!wwin
->prev
&& !wwin
->next
) {
1423 /* was the only window */
1424 scr
->focused_window
= NULL
;
1425 newFocusedWindow
= NULL
;
1430 wwin
->prev
->next
= wwin
->next
;
1432 wwin
->next
->prev
= wwin
->prev
;
1434 scr
->focused_window
= wwin
->prev
;
1435 scr
->focused_window
->next
= NULL
;
1438 /* if in click to focus mode and the window
1439 * was a transient, focus the owner window
1442 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1443 tmp
= wWindowFor(wwin
->transient_for
);
1444 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1448 /* otherwise, focus the next one in the focus list */
1450 tmp
= scr
->focused_window
;
1452 if (!WFLAGP(tmp
, no_focusable
)
1453 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1458 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1459 newFocusedWindow
= tmp
;
1460 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1461 || wPreferences
.focus_mode
==WKF_POINTER
) {
1466 /* This is to let the root window get the keyboard input
1467 * if Sloppy focus mode and no other window get focus.
1468 * This way keybindings will not freeze.
1471 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1472 &foo
, &foo
, &foo
, &foo
, &mask
))
1473 tmp
= wWindowFor(win
);
1476 newFocusedWindow
= tmp
;
1478 newFocusedWindow
= NULL
;
1482 if (!wwin
->flags
.internal_window
) {
1484 wGNOMERemoveClient(wwin
);
1487 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1492 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1493 (unsigned)frame
->window
);
1497 if (newFocusedWindow
!= owner
&& owner
) {
1498 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1500 wSetFocusTo(scr
, newFocusedWindow
);
1502 wWindowDestroy(wwin
);
1508 wWindowMap(WWindow
*wwin
)
1510 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1511 if (!wwin
->flags
.shaded
) {
1512 /* window will be remapped when getting MapNotify */
1513 XSelectInput(dpy
, wwin
->client_win
,
1514 wwin
->event_mask
& ~StructureNotifyMask
);
1515 XMapWindow(dpy
, wwin
->client_win
);
1516 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1518 wwin
->flags
.mapped
= 1;
1524 wWindowUnmap(WWindow
*wwin
)
1526 wwin
->flags
.mapped
= 0;
1528 /* prevent window withdrawal when getting UnmapNotify */
1529 XSelectInput(dpy
, wwin
->client_win
,
1530 wwin
->event_mask
& ~StructureNotifyMask
);
1531 XUnmapWindow(dpy
, wwin
->client_win
);
1532 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1534 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1540 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1545 #ifdef KEEP_XKB_LOCK_STATUS
1546 if (wPreferences
.modelock
) {
1547 if (!wwin
->flags
.focused
) {
1548 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1551 #endif /* KEEP_XKB_LOCK_STATUS */
1553 wwin
->flags
.semi_focused
= 0;
1555 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1557 wwin
->flags
.focused
= 1;
1559 wWindowResetMouseGrabs(wwin
);
1561 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1563 if (owin
== wwin
|| !owin
)
1566 nowner
= wWindowFor(wwin
->transient_for
);
1568 /* new window is a transient for the old window */
1569 if (nowner
== owin
) {
1570 owin
->flags
.semi_focused
= 1;
1571 wWindowUnfocus(nowner
);
1575 oowner
= wWindowFor(owin
->transient_for
);
1577 /* new window is owner of old window */
1578 if (wwin
== oowner
) {
1579 wWindowUnfocus(owin
);
1584 wWindowUnfocus(owin
);
1588 /* new window has same owner of old window */
1589 if (oowner
== nowner
) {
1590 /* prevent unfocusing of owner */
1591 oowner
->flags
.semi_focused
= 0;
1592 wWindowUnfocus(owin
);
1593 oowner
->flags
.semi_focused
= 1;
1598 /* nowner != NULL && oowner != nowner */
1599 nowner
->flags
.semi_focused
= 1;
1600 wWindowUnfocus(nowner
);
1601 wWindowUnfocus(owin
);
1606 wWindowUnfocus(WWindow
*wwin
)
1608 CloseWindowMenu(wwin
->screen_ptr
);
1610 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1611 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1613 if (wwin
->transient_for
!=None
1614 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1616 owner
= wWindowFor(wwin
->transient_for
);
1617 if (owner
&& owner
->flags
.semi_focused
) {
1618 owner
->flags
.semi_focused
= 0;
1619 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1620 wWindowUnfocus(owner
);
1621 wFrameWindowPaint(owner
->frame
);
1625 wwin
->flags
.focused
= 0;
1627 wWindowResetMouseGrabs(wwin
);
1629 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1636 *----------------------------------------------------------------------
1638 * wWindowConstrainSize--
1639 * Constrains size for the client window, taking the maximal size,
1640 * window resize increments and other size hints into account.
1643 * The closest size to what was given that the client window can
1646 *----------------------------------------------------------------------
1649 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1651 XSizeHints
*sizeh
= wwin
->normal_hints
;
1652 int width
= *nwidth
;
1653 int height
= *nheight
;
1654 int winc
= sizeh
->width_inc
;
1655 int hinc
= sizeh
->height_inc
;
1657 if (width
< sizeh
->min_width
)
1658 width
= sizeh
->min_width
;
1659 if (height
< sizeh
->min_height
)
1660 height
= sizeh
->min_height
;
1662 if (width
> sizeh
->max_width
)
1663 width
= sizeh
->max_width
;
1664 if (height
> sizeh
->max_height
)
1665 height
= sizeh
->max_height
;
1667 /* aspect ratio code borrowed from olwm */
1668 if (sizeh
->flags
& PAspect
) {
1669 /* adjust max aspect ratio */
1670 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1671 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1672 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1673 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1674 if (height
> sizeh
->max_height
) {
1675 height
= sizeh
->max_height
;
1676 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1679 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1680 if (width
> sizeh
->max_width
) {
1681 width
= sizeh
->max_width
;
1682 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1687 /* adjust min aspect ratio */
1688 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1689 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1690 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1691 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1692 if (height
< sizeh
->min_height
) {
1693 height
= sizeh
->min_height
;
1694 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1697 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1698 if (width
< sizeh
->min_width
) {
1699 width
= sizeh
->min_width
;
1700 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1706 if (sizeh
->base_width
!= 0) {
1707 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1708 + sizeh
->base_width
;
1710 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1714 if (sizeh
->base_width
!= 0) {
1715 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1716 + sizeh
->base_height
;
1718 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1719 + sizeh
->min_height
;
1728 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1730 WScreen
*scr
= wwin
->screen_ptr
;
1734 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1735 || workspace
== wwin
->frame
->workspace
)
1738 if (workspace
!= scr
->current_workspace
) {
1739 /* Sent to other workspace. Unmap window */
1740 if ((wwin
->flags
.mapped
1741 || wwin
->flags
.shaded
1742 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1743 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1745 wapp
= wApplicationOf(wwin
->main_window
);
1747 wapp
->last_workspace
= workspace
;
1749 if (wwin
->flags
.miniaturized
) {
1750 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1751 wwin
->icon
->mapped
= 0;
1754 wSetFocusTo(scr
, NULL
);
1758 /* brought to current workspace. Map window */
1759 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1760 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1761 wwin
->icon
->mapped
= 1;
1762 } else if (!wwin
->flags
.mapped
&&
1763 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1767 if (!IS_OMNIPRESENT(wwin
)) {
1768 wwin
->frame
->workspace
= workspace
;
1769 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1772 wGNOMEUpdateClientStateHint(wwin
, True
);
1775 wKWMUpdateClientWorkspace(wwin
);
1776 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1785 wWindowSynthConfigureNotify(WWindow
*wwin
)
1789 sevent
.type
= ConfigureNotify
;
1790 sevent
.xconfigure
.display
= dpy
;
1791 sevent
.xconfigure
.event
= wwin
->client_win
;
1792 sevent
.xconfigure
.window
= wwin
->client_win
;
1794 sevent
.xconfigure
.x
= wwin
->client
.x
;
1795 sevent
.xconfigure
.y
= wwin
->client
.y
;
1796 sevent
.xconfigure
.width
= wwin
->client
.width
;
1797 sevent
.xconfigure
.height
= wwin
->client
.height
;
1799 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1800 if (WFLAGP(wwin
, no_titlebar
))
1801 sevent
.xconfigure
.above
= None
;
1803 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1805 sevent
.xconfigure
.override_redirect
= False
;
1806 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1808 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1815 *----------------------------------------------------------------------
1816 * wWindowConfigure--
1817 * Configures the frame, decorations and client window to the
1818 * specified geometry. The geometry is not checked for validity,
1819 * wWindowConstrainSize() must be used for that.
1820 * The size parameters are for the client window, but the position is
1822 * The client window receives a ConfigureNotify event, according
1823 * to what ICCCM says.
1829 * Window size and position are changed and client window receives
1830 * a ConfigureNotify event.
1831 *----------------------------------------------------------------------
1834 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1836 int req_x
, req_y
; /* new position of the frame */
1837 int req_width
, req_height
; /* new size of the client */
1839 int synth_notify
= False
;
1842 resize
= (req_width
!=wwin
->client
.width
1843 || req_height
!=wwin
->client
.height
);
1845 * if the window is being moved but not resized then
1846 * send a synthetic ConfigureNotify
1848 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1849 synth_notify
= True
;
1852 if (WFLAGP(wwin
, dont_move_off
))
1853 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1854 req_width
, req_height
);
1856 if (req_width
< MIN_WINDOW_SIZE
)
1857 req_width
= MIN_WINDOW_SIZE
;
1858 if (req_height
< MIN_WINDOW_SIZE
)
1859 req_height
= MIN_WINDOW_SIZE
;
1861 /* If growing, resize inner part before frame,
1862 * if shrinking, resize frame before.
1863 * This will prevent the frame (that can have a different color)
1864 * to be exposed, causing flicker */
1865 if (req_height
> wwin
->frame
->core
->height
1866 || req_width
> wwin
->frame
->core
->width
)
1867 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1869 if (wwin
->flags
.shaded
) {
1870 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1871 req_width
, wwin
->frame
->core
->height
);
1872 wwin
->old_geometry
.height
= req_height
;
1876 h
= req_height
+ wwin
->frame
->top_width
1877 + wwin
->frame
->bottom_width
;
1879 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1882 if (!(req_height
> wwin
->frame
->core
->height
1883 || req_width
> wwin
->frame
->core
->width
))
1884 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1886 wwin
->client
.x
= req_x
;
1887 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1888 wwin
->client
.width
= req_width
;
1889 wwin
->client
.height
= req_height
;
1891 wwin
->client
.x
= req_x
;
1892 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1894 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1896 wwin
->frame_x
= req_x
;
1897 wwin
->frame_y
= req_y
;
1900 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1901 wWindowSetShape(wwin
);
1906 wWindowSynthConfigureNotify(wwin
);
1912 wWindowMove(wwin
, req_x
, req_y
)
1914 int req_x
, req_y
; /* new position of the frame */
1916 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1917 int synth_notify
= False
;
1919 /* Send a synthetic ConfigureNotify event for every window movement. */
1920 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1921 synth_notify
= True
;
1924 /* A single synthetic ConfigureNotify event is sent at the end of
1925 * a completed (opaque) movement in moveres.c */
1928 if (WFLAGP(wwin
, dont_move_off
))
1929 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1930 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1932 wwin
->client
.x
= req_x
;
1933 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1935 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1937 wwin
->frame_x
= req_x
;
1938 wwin
->frame_y
= req_y
;
1940 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1942 wWindowSynthConfigureNotify(wwin
);
1948 wWindowUpdateButtonImages(WWindow
*wwin
)
1950 WScreen
*scr
= wwin
->screen_ptr
;
1951 Pixmap pixmap
, mask
;
1952 WFrameWindow
*fwin
= wwin
->frame
;
1954 if (WFLAGP(wwin
, no_titlebar
))
1957 /* miniaturize button */
1959 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
1960 if (wwin
->wm_gnustep_attr
1961 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1962 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1964 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1965 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1970 if (fwin
->lbutton_image
1971 && (fwin
->lbutton_image
->image
!= pixmap
1972 || fwin
->lbutton_image
->mask
!= mask
)) {
1973 wPixmapDestroy(fwin
->lbutton_image
);
1974 fwin
->lbutton_image
= NULL
;
1977 if (!fwin
->lbutton_image
) {
1978 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1979 fwin
->lbutton_image
->client_owned
= 1;
1980 fwin
->lbutton_image
->client_owned_mask
= 1;
1983 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
1984 wPixmapDestroy(fwin
->lbutton_image
);
1986 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
1992 if (!WFLAGP(wwin
, no_close_button
)) {
1993 if (wwin
->wm_gnustep_attr
1994 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
1995 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
1997 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
1998 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2003 if (fwin
->rbutton_image
2004 && (fwin
->rbutton_image
->image
!= pixmap
2005 || fwin
->rbutton_image
->mask
!= mask
)) {
2006 wPixmapDestroy(fwin
->rbutton_image
);
2007 fwin
->rbutton_image
= NULL
;
2010 if (!fwin
->rbutton_image
) {
2011 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2012 fwin
->rbutton_image
->client_owned
= 1;
2013 fwin
->rbutton_image
->client_owned_mask
= 1;
2015 } else if (WFLAGP(wwin
, kill_close
)) {
2016 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2017 wPixmapDestroy(fwin
->rbutton_image
);
2019 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2020 } else if (WFLAGP(wwin
, broken_close
)) {
2021 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2022 wPixmapDestroy(fwin
->rbutton_image
);
2024 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2026 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2027 wPixmapDestroy(fwin
->rbutton_image
);
2029 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2033 /* force buttons to be redrawn */
2034 fwin
->flags
.need_texture_change
= 1;
2035 wFrameWindowPaint(fwin
);
2040 *---------------------------------------------------------------------------
2041 * wWindowConfigureBorders--
2042 * Update window border configuration according to attribute flags.
2044 *---------------------------------------------------------------------------
2047 wWindowConfigureBorders(WWindow
*wwin
)
2053 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2054 if (!WFLAGP(wwin
, no_titlebar
))
2055 flags
|= WFF_TITLEBAR
;
2056 if (!WFLAGP(wwin
, no_resizebar
))
2057 flags
|= WFF_RESIZEBAR
;
2058 if (wwin
->flags
.shaded
)
2059 flags
|= WFF_IS_SHADED
;
2061 oldh
= wwin
->frame
->top_width
;
2062 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2063 if (oldh
!= wwin
->frame
->top_width
) {
2064 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2066 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2067 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2068 wwin
->client
.width
, wwin
->client
.height
);
2072 if (!WFLAGP(wwin
, no_miniaturize_button
)
2073 && wwin
->frame
->flags
.hide_left_button
)
2074 flags
|= WFF_LEFT_BUTTON
;
2076 if (!WFLAGP(wwin
, no_close_button
)
2077 && wwin
->frame
->flags
.hide_right_button
)
2078 flags
|= WFF_RIGHT_BUTTON
;
2081 wWindowUpdateButtonImages(wwin
);
2082 wFrameWindowShowButton(wwin
->frame
, flags
);
2086 if (WFLAGP(wwin
, no_miniaturize_button
)
2087 && !wwin
->frame
->flags
.hide_left_button
)
2088 flags
|= WFF_LEFT_BUTTON
;
2090 if (WFLAGP(wwin
, no_close_button
)
2091 && !wwin
->frame
->flags
.hide_right_button
)
2092 flags
|= WFF_RIGHT_BUTTON
;
2095 wFrameWindowHideButton(wwin
->frame
, flags
);
2098 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2099 wWindowSetShape(wwin
);
2107 wWindowSaveState(WWindow
*wwin
)
2112 memset(data
, 0, sizeof(CARD32
)*10);
2113 data
[0] = wwin
->frame
->workspace
;
2114 data
[1] = wwin
->flags
.miniaturized
;
2115 data
[2] = wwin
->flags
.shaded
;
2116 data
[3] = wwin
->flags
.hidden
;
2118 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2119 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
)
2122 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2123 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2124 (unsigned char *)data
, 10);
2129 getSavedState(Window window
, WSavedState
**state
)
2133 unsigned long nitems_ret
;
2134 unsigned long bytes_after_ret
;
2137 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2138 True
, _XA_WINDOWMAKER_STATE
,
2139 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2140 (unsigned char **)&data
)!=Success
|| !data
)
2143 *state
= malloc(sizeof(WSavedState
));
2146 (*state
)->workspace
= data
[0];
2147 (*state
)->miniaturized
= data
[1];
2148 (*state
)->shaded
= data
[2];
2149 (*state
)->hidden
= data
[3];
2150 (*state
)->use_geometry
= data
[4];
2151 (*state
)->x
= data
[5];
2152 (*state
)->y
= data
[6];
2153 (*state
)->w
= data
[7];
2154 (*state
)->h
= data
[8];
2155 (*state
)->window_shortcuts
= data
[9];
2159 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2168 wWindowClearShape(WWindow
*wwin
)
2170 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2171 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2176 wWindowSetShape(WWindow
*wwin
)
2180 #ifdef OPTIMIZE_SHAPE
2185 /* only shape is the client's */
2186 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2190 /* Get array of rectangles describing the shape mask */
2191 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2197 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2203 /* insert our decoration rectangles in the rect list */
2204 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2207 if (!WFLAGP(wwin
, no_titlebar
)) {
2209 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2210 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2211 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2214 if (!WFLAGP(wwin
, no_resizebar
)) {
2216 urec
[count
].y
= wwin
->frame
->core
->height
2217 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2218 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2219 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2223 /* shape our frame window */
2224 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2225 0, wwin
->frame
->top_width
, urec
, count
,
2226 ShapeSet
, Unsorted
);
2232 #endif /* OPTIMIZE_SHAPE */
2234 if (!WFLAGP(wwin
, no_titlebar
)) {
2237 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2238 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2241 if (!WFLAGP(wwin
, no_resizebar
)) {
2243 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2244 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2245 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2249 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2250 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2252 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2253 0, wwin
->frame
->top_width
, wwin
->client_win
,
2254 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2259 /* ====================================================================== */
2262 getFocusMode(WWindow
*wwin
)
2266 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2267 if (wwin
->wm_hints
->input
== True
) {
2268 if (wwin
->protocols
.TAKE_FOCUS
)
2269 mode
= WFM_LOCALLY_ACTIVE
;
2273 if (wwin
->protocols
.TAKE_FOCUS
)
2274 mode
= WFM_GLOBALLY_ACTIVE
;
2276 mode
= WFM_NO_INPUT
;
2286 wWindowSetKeyGrabs(WWindow
*wwin
)
2291 for (i
=0; i
<WKBD_LAST
; i
++) {
2292 key
= &wKeyBindings
[i
];
2294 if (key
->keycode
==0)
2296 if (key
->modifier
!=AnyModifier
) {
2297 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2298 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2300 /* Also grab all modifier combinations possible that include,
2301 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2302 * work even if the NumLock/ScrollLock key is on.
2304 wHackedGrabKey(key
->keycode
, key
->modifier
,
2305 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2309 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2310 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2314 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2321 wWindowResetMouseGrabs(WWindow
*wwin
)
2323 /* Mouse grabs can't be done on the client window because of
2324 * ICCCM and because clients that try to do the same will crash.
2326 * But there is a problem wich makes tbar buttons of unfocused
2327 * windows not usable as the click goes to the frame window instead
2328 * of the button itself. Must figure a way to fix that.
2331 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2333 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2334 /* grabs for Meta+drag */
2335 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2336 True
, ButtonPressMask
, GrabModeSync
,
2337 GrabModeAsync
, None
, None
);
2340 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)) {
2341 /* the passive grabs to focus the window */
2342 if (wPreferences
.focus_mode
== WKF_CLICK
)
2343 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2344 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2352 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2355 if (attr
->flags
& GSExtraFlagsAttr
) {
2356 if (WFLAGP(wwin
, broken_close
) !=
2357 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2359 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2361 wWindowUpdateButtonImages(wwin
);
2369 wWindowAddSavedState(char *instance
, char *class, char *command
,
2370 pid_t pid
, WSavedState
*state
)
2372 WWindowState
*wstate
;
2374 wstate
= malloc(sizeof(WWindowState
));
2378 memset(wstate
, 0, sizeof(WWindowState
));
2381 wstate
->instance
= wstrdup(instance
);
2383 wstate
->class = wstrdup(class);
2385 wstate
->command
= wstrdup(command
);
2386 wstate
->state
= state
;
2388 wstate
->next
= windowState
;
2389 windowState
= wstate
;
2392 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2400 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2404 wWindowGetSavedState(Window win
)
2406 char *instance
, *class, *command
=NULL
;
2407 WWindowState
*wstate
= windowState
;
2414 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2416 command
= FlattenStringList(argv
, argc
);
2417 XFreeStringList(argv
);
2422 if (PropGetWMClass(win
, &class, &instance
)) {
2424 if (SAME(instance
, wstate
->instance
) &&
2425 SAME(class, wstate
->class) &&
2426 SAME(command
, wstate
->command
)) {
2429 wstate
= wstate
->next
;
2436 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2440 if (command
) free(command
);
2441 if (instance
) XFree(instance
);
2442 if (class) XFree(class);
2449 wWindowDeleteSavedState(WMagicNumber id
)
2451 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2453 if (!wstate
|| !windowState
)
2458 windowState
= wstate
->next
;
2460 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2461 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2463 if (wstate
->instance
) free(wstate
->instance
);
2464 if (wstate
->class) free(wstate
->class);
2465 if (wstate
->command
) free(wstate
->command
);
2466 free(wstate
->state
);
2470 if (tmp
->next
==wstate
) {
2471 tmp
->next
=wstate
->next
;
2473 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2474 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2476 if (wstate
->instance
) free(wstate
->instance
);
2477 if (wstate
->class) free(wstate
->class);
2478 if (wstate
->command
) free(wstate
->command
);
2479 free(wstate
->state
);
2490 wWindowDeleteSavedStatesForPID(pid_t pid
)
2492 WWindowState
*tmp
, *wstate
;
2498 if (tmp
->pid
== pid
) {
2499 wstate
= windowState
;
2500 windowState
= tmp
->next
;
2502 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2503 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2505 if (wstate
->instance
) free(wstate
->instance
);
2506 if (wstate
->class) free(wstate
->class);
2507 if (wstate
->command
) free(wstate
->command
);
2508 free(wstate
->state
);
2512 if (tmp
->next
->pid
==pid
) {
2514 tmp
->next
= wstate
->next
;
2516 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2517 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2519 if (wstate
->instance
) free(wstate
->instance
);
2520 if (wstate
->class) free(wstate
->class);
2521 if (wstate
->command
) free(wstate
->command
);
2522 free(wstate
->state
);
2532 /* ====================================================================== */
2535 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2537 WWindow
*wwin
= data
;
2539 #ifndef NUMLOCK_HACK
2540 if ((event
->xbutton
.state
& ValidModMask
)
2541 != (event
->xbutton
.state
& ~LockMask
)) {
2542 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2543 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2547 event
->xbutton
.state
&= ValidModMask
;
2549 CloseWindowMenu(wwin
->screen_ptr
);
2551 if (wPreferences
.focus_mode
==WKF_CLICK
2552 && !(event
->xbutton
.state
&ControlMask
)
2553 && !WFLAGP(wwin
, no_focusable
)) {
2554 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2557 if (event
->xbutton
.button
== Button1
)
2558 wRaiseFrame(wwin
->frame
->core
);
2560 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2561 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2562 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2563 GrabModeAsync
, GrabModeAsync
, None
,
2564 None
, CurrentTime
)!=GrabSuccess
) {
2566 wwarning("pointer grab failed for window move");
2572 if (event
->xbutton
.state
& MOD_MASK
) {
2573 /* move the window */
2574 wMouseMoveWindow(wwin
, event
);
2575 XUngrabPointer(dpy
, CurrentTime
);
2577 wMouseResizeWindow(wwin
, event
);
2578 XUngrabPointer(dpy
, CurrentTime
);
2585 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2587 WWindow
*wwin
= data
;
2589 event
->xbutton
.state
&= ValidModMask
;
2591 if (event
->xbutton
.button
==Button1
) {
2592 if (event
->xbutton
.state
== 0) {
2593 if (!WFLAGP(wwin
, no_shadeable
)) {
2595 if (wwin
->flags
.shaded
)
2596 wUnshadeWindow(wwin
);
2603 if (event
->xbutton
.state
& ControlMask
)
2604 dir
|= MAX_VERTICAL
;
2606 if (event
->xbutton
.state
& ShiftMask
) {
2607 dir
|= MAX_HORIZONTAL
;
2608 if (!(event
->xbutton
.state
& ControlMask
))
2609 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2612 /* maximize window */
2613 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2614 if (wwin
->flags
.maximized
)
2615 wUnmaximizeWindow(wwin
);
2617 wMaximizeWindow(wwin
, dir
);
2620 } else if (event
->xbutton
.button
==Button3
) {
2621 if (event
->xbutton
.state
& MOD_MASK
) {
2622 wHideOtherApplications(wwin
);
2624 } else if (event
->xbutton
.button
==Button2
) {
2625 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2631 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2633 WWindow
*wwin
= desc
->parent
;
2635 event
->xbutton
.state
&= ValidModMask
;
2637 CloseWindowMenu(wwin
->screen_ptr
);
2639 if (wPreferences
.focus_mode
==WKF_CLICK
2640 && !(event
->xbutton
.state
&ControlMask
)
2641 && !WFLAGP(wwin
, no_focusable
)) {
2642 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2644 if (event
->xbutton
.button
== Button1
) {
2645 wRaiseFrame(wwin
->frame
->core
);
2648 if (event
->xbutton
.state
& MOD_MASK
) {
2649 /* move the window */
2650 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2651 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2652 GrabModeAsync
, GrabModeAsync
, None
,
2653 None
, CurrentTime
)!=GrabSuccess
) {
2655 wwarning("pointer grab failed for window move");
2659 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2660 wMouseResizeWindow(wwin
, event
);
2662 wMouseMoveWindow(wwin
, event
);
2663 XUngrabPointer(dpy
, CurrentTime
);
2669 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2671 WWindow
*wwin
= (WWindow
*)data
;
2673 #ifndef NUMLOCK_HACK
2674 if ((event
->xbutton
.state
& ValidModMask
)
2675 != (event
->xbutton
.state
& ~LockMask
)) {
2676 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2677 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2680 event
->xbutton
.state
&= ValidModMask
;
2682 CloseWindowMenu(wwin
->screen_ptr
);
2684 if (wPreferences
.focus_mode
==WKF_CLICK
2685 && !(event
->xbutton
.state
&ControlMask
)
2686 && !WFLAGP(wwin
, no_focusable
)) {
2687 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2690 if (event
->xbutton
.button
== Button1
2691 || event
->xbutton
.button
== Button2
) {
2693 if (event
->xbutton
.button
== Button1
) {
2694 if (event
->xbutton
.state
& MOD_MASK
) {
2695 wLowerFrame(wwin
->frame
->core
);
2697 wRaiseFrame(wwin
->frame
->core
);
2700 if ((event
->xbutton
.state
& ShiftMask
)
2701 && !(event
->xbutton
.state
& ControlMask
)) {
2702 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2705 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2706 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2707 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2708 GrabModeAsync
, GrabModeAsync
, None
,
2709 None
, CurrentTime
)!=GrabSuccess
) {
2711 wwarning("pointer grab failed for window move");
2716 /* move the window */
2717 wMouseMoveWindow(wwin
, event
);
2719 XUngrabPointer(dpy
, CurrentTime
);
2720 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2721 && !wwin
->flags
.internal_window
2722 && !WCHECK_STATE(WSTATE_MODAL
)) {
2723 WObjDescriptor
*desc
;
2725 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2726 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2727 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2728 GrabModeAsync
, GrabModeAsync
, None
,
2729 None
, CurrentTime
)!=GrabSuccess
) {
2731 wwarning("pointer grab failed for window move");
2736 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2737 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2739 /* allow drag select */
2740 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2741 event
->xany
.send_event
= True
;
2742 (*desc
->handle_mousedown
)(desc
, event
);
2744 XUngrabPointer(dpy
, CurrentTime
);
2751 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2753 WWindow
*wwin
= data
;
2755 event
->xbutton
.state
&= ValidModMask
;
2757 CloseWindowMenu(wwin
->screen_ptr
);
2759 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2762 /* if control-click, kill the client */
2763 if (event
->xbutton
.state
& ControlMask
) {
2767 if (wwin
->flags
.olwm_push_pin_out
) {
2769 wwin
->flags
.olwm_push_pin_out
= 0;
2771 wOLWMChangePushpinState(wwin
, True
);
2773 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2778 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2779 /* send delete message */
2780 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2787 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2789 WWindow
*wwin
= data
;
2791 CloseWindowMenu(wwin
->screen_ptr
);
2793 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2796 /* send delete message */
2797 if (wwin
->protocols
.DELETE_WINDOW
) {
2798 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2806 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2808 WWindow
*wwin
= data
;
2810 event
->xbutton
.state
&= ValidModMask
;
2812 CloseWindowMenu(wwin
->screen_ptr
);
2814 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2817 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2818 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2822 if ((event
->xbutton
.state
& ControlMask
) ||
2823 (event
->xbutton
.button
== Button3
)) {
2825 wapp
= wApplicationOf(wwin
->main_window
);
2826 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2827 wHideApplication(wapp
);
2828 } else if (event
->xbutton
.state
==0) {
2829 wIconifyWindow(wwin
);