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"
66 # include "openlook.h"
69 /****** Global Variables ******/
71 extern WShortKey wKeyBindings
[WKBD_LAST
];
74 extern Bool wShapeSupported
;
78 extern XContext wWinContext
;
81 extern Cursor wCursor
[WCUR_LAST
];
84 extern Atom _XA_WM_DELETE_WINDOW
;
85 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
87 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern WPreferences wPreferences
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern Time LastTimestamp
;
96 extern void DoWindowBirth(WWindow
*);
99 /***** Local Stuff *****/
102 static WWindowState
*windowState
=NULL
;
106 /* local functions */
107 static FocusMode
getFocusMode(WWindow
*wwin
);
109 static int getSavedState(Window window
, WSavedState
**state
);
111 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
116 /* frame window (during window grabs) */
117 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
120 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
121 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
126 #ifdef XKB_BUTTON_HINT
127 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
130 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
131 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
133 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
136 /****** Notification Observers ******/
139 appearanceObserver(void *self
, WMNotification
*notif
)
141 WWindow
*wwin
= (WWindow
*)self
;
142 int flags
= (int)WMGetNotificationClientData(notif
);
144 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
147 if (flags
& WFontSettings
) {
148 wWindowConfigureBorders(wwin
);
150 if (flags
& WTextureSettings
) {
151 wwin
->frame
->flags
.need_texture_remake
= 1;
153 if (flags
& (WTextureSettings
| WColorSettings
)) {
154 if (wwin
->frame
->titlebar
)
155 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
157 wFrameWindowPaint(wwin
->frame
);
161 /************************************/
164 wWindowFor(Window window
)
166 WObjDescriptor
*desc
;
171 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
174 if (desc
->parent_type
==WCLASS_WINDOW
)
176 else if (desc
->parent_type
==WCLASS_FRAME
) {
177 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
178 if (frame
->flags
.is_client_window_frame
)
191 wwin
= wmalloc(sizeof(WWindow
));
194 memset(wwin
, 0, sizeof(WWindow
));
196 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
197 wwin
->client_descriptor
.parent
= wwin
;
198 wwin
->client_descriptor
.self
= wwin
;
199 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
206 wWindowDestroy(WWindow
*wwin
)
210 WMRemoveNotificationObserver(wwin
);
212 wwin
->flags
.destroyed
= 1;
214 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
215 if (wwin
->screen_ptr
->shortcutSelectedWindows
[i
]) {
216 WMRemoveFromBag(wwin
->screen_ptr
->shortcutSelectedWindows
[i
], wwin
);
218 if (!WMGetBagItemCount(wwin
->screen_ptr
->shortcutSelectedWindows
[i
])) {
219 WMFreeBag(wwin
->screen_ptr
->shortcutSelectedWindows
[i
]);
220 wwin
->screen_ptr
->shortcutSelectedWindows
[i
] = NULL
;
225 if (wwin
->normal_hints
)
226 free(wwin
->normal_hints
);
229 XFree(wwin
->wm_hints
);
231 if (wwin
->wm_instance
)
232 XFree(wwin
->wm_instance
);
235 XFree(wwin
->wm_class
);
237 if (wwin
->wm_gnustep_attr
)
238 free(wwin
->wm_gnustep_attr
);
240 if (wwin
->cmap_windows
)
241 XFree(wwin
->cmap_windows
);
243 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
246 wFrameWindowDestroy(wwin
->frame
);
249 RemoveFromStackList(wwin
->icon
->core
);
250 wIconDestroy(wwin
->icon
);
251 if (wPreferences
.auto_arrange_icons
)
252 wArrangeIcons(wwin
->screen_ptr
, True
);
261 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
263 if (gs_hints
->flags
& GSWindowStyleAttr
) {
264 wwin
->client_flags
.no_titlebar
=
265 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
267 wwin
->client_flags
.no_close_button
=
268 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
270 wwin
->client_flags
.no_closable
=
271 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
273 wwin
->client_flags
.no_miniaturize_button
=
274 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
276 wwin
->client_flags
.no_miniaturizable
=
277 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
279 wwin
->client_flags
.no_resizebar
=
280 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
282 wwin
->client_flags
.no_resizable
=
283 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
285 /* setup the defaults */
286 wwin
->client_flags
.no_titlebar
= 0;
287 wwin
->client_flags
.no_closable
= 0;
288 wwin
->client_flags
.no_miniaturizable
= 0;
289 wwin
->client_flags
.no_resizable
= 0;
290 wwin
->client_flags
.no_close_button
= 0;
291 wwin
->client_flags
.no_miniaturize_button
= 0;
292 wwin
->client_flags
.no_resizebar
= 0;
294 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
295 wwin
->client_flags
.no_appicon
= 1;
301 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
302 WWindowAttributes
*mask
)
304 if (wflags
->no_appicon
&& mask
->no_appicon
)
305 wflags
->emulate_appicon
= 0;
307 if (wwin
->main_window
!=None
) {
308 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
309 if (wapp
&& !wapp
->flags
.emulated
)
310 wflags
->emulate_appicon
= 0;
313 if (wwin
->transient_for
!=None
314 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
315 wflags
->emulate_appicon
= 0;
317 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
324 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
326 WScreen
*scr
= wwin
->screen_ptr
;
328 /* sets global default stuff */
329 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
330 &wwin
->client_flags
, NULL
, True
);
332 * Decoration setting is done in this precedence (lower to higher)
333 * - use global default in the resource database
334 * - guess some settings
335 * - use GNUstep/external window attributes
336 * - set hints specified for the app in the resource DB
339 WSETUFLAG(wwin
, broken_close
, 0);
341 if (wwin
->protocols
.DELETE_WINDOW
)
342 WSETUFLAG(wwin
, kill_close
, 0);
344 WSETUFLAG(wwin
, kill_close
, 1);
346 /* transients can't be iconified or maximized */
347 if (wwin
->transient_for
) {
348 WSETUFLAG(wwin
, no_miniaturizable
, 1);
349 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
352 /* if the window can't be resized, remove the resizebar */
353 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
354 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
355 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
356 WSETUFLAG(wwin
, no_resizable
, 1);
357 WSETUFLAG(wwin
, no_resizebar
, 1);
360 /* set GNUstep window attributes */
361 if (wwin
->wm_gnustep_attr
) {
362 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
364 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
366 switch (wwin
->wm_gnustep_attr
->window_level
) {
367 case WMNormalWindowLevel
:
368 *level
= WMNormalLevel
;
370 case WMFloatingWindowLevel
:
371 *level
= WMFloatingLevel
;
373 case WMDockWindowLevel
:
374 *level
= WMDockLevel
;
376 case WMSubmenuWindowLevel
:
377 *level
= WMSubmenuLevel
;
379 case WMMainMenuWindowLevel
:
380 *level
= WMMainMenuLevel
;
383 *level
= WMNormalLevel
;
388 *level
= WMNormalLevel
;
391 int tmp_workspace
= -1;
395 wMWMCheckClientHints(wwin
);
396 #endif /* MWM_HINTS */
399 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
400 #endif /* KWM_HINTS */
403 wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
404 #endif /* GNOME_STUFF */
407 wOLWMCheckClientHints(wwin
);
408 #endif /* OLWM_HINTS */
411 if (WFLAGP(wwin
, floating
))
412 *level
= WMFloatingLevel
;
413 else if (WFLAGP(wwin
, sunken
))
414 *level
= WMSunkenLevel
;
416 *level
= WMNormalLevel
;
421 if (tmp_workspace
>= 0) {
422 *workspace
= tmp_workspace
% scr
->workspace_count
;
427 * Set attributes specified only for that window/class.
428 * This might do duplicate work with the 1st wDefaultFillAttributes().
430 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
431 &wwin
->user_flags
, &wwin
->defined_user_flags
,
434 * Sanity checks for attributes that depend on other attributes
436 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
437 wwin
->user_flags
.emulate_appicon
= 0;
439 if (wwin
->main_window
!=None
) {
440 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
441 if (wapp
&& !wapp
->flags
.emulated
)
442 wwin
->user_flags
.emulate_appicon
= 0;
445 if (wwin
->transient_for
!=None
446 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
447 wwin
->user_flags
.emulate_appicon
= 0;
449 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
450 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
451 wwin
->user_flags
.sunken
= 0;
453 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
460 wWindowCanReceiveFocus(WWindow
*wwin
)
462 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
464 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
466 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
474 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
478 w1
= wwin
->frame
->core
->width
;
479 h1
= wwin
->frame
->core
->height
;
480 w2
= obscured
->frame
->core
->width
;
481 h2
= obscured
->frame
->core
->height
;
483 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
484 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
487 if (wwin
->frame_x
+ w1
< obscured
->frame_x
488 || wwin
->frame_y
+ h1
< obscured
->frame_y
489 || wwin
->frame_x
> obscured
->frame_x
+ w2
490 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
499 *----------------------------------------------------------------
501 * reparents the window and allocates a descriptor for it.
502 * Window manager hints and other hints are fetched to configure
503 * the window decoration attributes and others. User preferences
504 * for the window are used if available, to configure window
505 * decorations and some behaviour.
506 * If in startup, windows that are override redirect,
507 * unmapped and never were managed and are Withdrawn are not
511 * the new window descriptor
514 * The window is reparented and appropriate notification
515 * is done to the client. Input mask for the window is setup.
516 * The window descriptor is also associated with various window
517 * contexts and inserted in the head of the window list.
518 * Event handler contexts are associated for some objects
519 * (buttons, titlebar and resizebar)
521 *----------------------------------------------------------------
524 wManageWindow(WScreen
*scr
, Window window
)
528 unsigned width
, height
;
529 XWindowAttributes wattribs
;
530 XSetWindowAttributes attribs
;
531 WWindowState
*win_state
;
532 WWindow
*transientOwner
= NULL
;
538 Bool withdraw
= False
;
541 /* XGrabServer(dpy); */
543 /* make sure the window is still there */
544 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
549 /* if it's an override-redirect, ignore it */
550 if (wattribs
.override_redirect
) {
555 wm_state
= PropGetWindowState(window
);
557 /* if it's startup and the window is unmapped, don't manage it */
558 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
563 if (!wFetchName(dpy
, window
, &title
)) {
568 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
573 #endif /* KWM_HINTS */
576 wwin
= wWindowCreate();
578 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
581 printf("managing window %x\n", (unsigned)window
);
585 if (wShapeSupported
) {
590 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
591 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
592 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
593 wwin
->flags
.shaped
= b_shaped
;
598 *--------------------------------------------------
600 * Get hints and other information in properties
602 *--------------------------------------------------
604 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
606 /* setup descriptor */
607 wwin
->client_win
= window
;
608 wwin
->screen_ptr
= scr
;
610 wwin
->old_border_width
= wattribs
.border_width
;
612 wwin
->event_mask
= CLIENT_EVENTS
;
613 attribs
.event_mask
= CLIENT_EVENTS
;
614 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
615 attribs
.save_under
= False
;
616 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
617 |CWSaveUnder
, &attribs
);
618 XSetWindowBorderWidth(dpy
, window
, 0);
620 /* get hints from GNUstep app */
621 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
622 wwin
->wm_gnustep_attr
= NULL
;
625 wwin
->client_leader
= PropGetClientLeader(window
);
626 if (wwin
->client_leader
!=None
)
627 wwin
->main_window
= wwin
->client_leader
;
629 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
631 if (wwin
->wm_hints
) {
632 if (wwin
->wm_hints
->flags
& StateHint
) {
634 if (wwin
->wm_hints
->initial_state
== IconicState
) {
636 wwin
->flags
.miniaturized
= 1;
638 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
644 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
645 wwin
->group_id
= wwin
->wm_hints
->window_group
;
646 /* window_group has priority over CLIENT_LEADER */
647 wwin
->main_window
= wwin
->group_id
;
649 wwin
->group_id
= None
;
652 if (wwin
->wm_hints
->flags
& UrgencyHint
)
653 wwin
->flags
.urgent
= 1;
655 wwin
->group_id
= None
;
658 PropGetProtocols(window
, &wwin
->protocols
);
660 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
661 wwin
->transient_for
= None
;
663 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
664 wwin
->transient_for
= scr
->root_win
;
666 transientOwner
= wWindowFor(wwin
->transient_for
);
667 if (transientOwner
&& transientOwner
->main_window
!=None
) {
668 wwin
->main_window
= transientOwner
->main_window
;
670 wwin->main_window = None;
675 /* guess the focus mode */
676 wwin
->focus_mode
= getFocusMode(wwin
);
678 /* get geometry stuff */
679 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
681 /* get colormap windows */
682 GetColormapWindows(wwin
);
685 *--------------------------------------------------
687 * Setup the decoration/window attributes and
690 *--------------------------------------------------
693 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
696 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
697 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
699 transientOwner
= wWindowFor(wwin
->group_id
);
701 if (transientOwner
) {
702 wwin
->transient_for
= wwin
->group_id
;
704 /* transients can't be iconified or maximized */
705 if (wwin
->transient_for
) {
706 WSETUFLAG(wwin
, no_miniaturizable
, 1);
707 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
711 #endif /* OLWM_HINTS */
714 * Make broken apps behave as a nice app.
716 if (WFLAGP(wwin
, emulate_appicon
)) {
717 wwin
->main_window
= wwin
->client_win
;
721 *------------------------------------------------------------
723 * Setup the initial state of the window
725 *------------------------------------------------------------
728 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
729 wwin
->flags
.miniaturized
= 1;
732 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
733 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
737 wGNOMECheckInitialClientState(wwin
);
740 wKWMCheckClientInitialState(wwin
);
743 /* apply previous state if it exists and we're in startup */
744 if (scr
->flags
.startup
&& wm_state
>= 0) {
746 if (wm_state
== IconicState
) {
748 wwin
->flags
.miniaturized
= 1;
750 } else if (wm_state
== WithdrawnState
) {
756 /* if there is a saved state (from file), restore it */
758 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
759 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
761 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
763 if (win_state
&& !withdraw
) {
765 if (win_state
->state
->hidden
>0)
766 wwin
->flags
.hidden
= win_state
->state
->hidden
;
768 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
769 wwin
->flags
.shaded
= win_state
->state
->shaded
;
771 if (win_state
->state
->miniaturized
>0 &&
772 !WFLAGP(wwin
, no_miniaturizable
)) {
773 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
775 if (!IS_OMNIPRESENT(wwin
)) {
776 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
778 if (w
< 0 || w
>= scr
->workspace_count
) {
779 workspace
= win_state
->state
->workspace
;
780 if (workspace
>= scr
->workspace_count
)
781 workspace
= scr
->current_workspace
;
786 workspace
= scr
->current_workspace
;
790 /* if we're restarting, restore saved state (from hints).
791 * This will overwrite previous */
795 if (getSavedState(window
, &wstate
)) {
796 wwin
->flags
.shaded
= wstate
->shaded
;
797 wwin
->flags
.hidden
= wstate
->hidden
;
798 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
799 workspace
= wstate
->workspace
;
801 if (scr
->flags
.startup
&& wstate
->window_shortcuts
>= 0) {
804 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
805 if (wstate
->window_shortcuts
& (1<<i
))
806 scr
->shortcutWindow
[i
] = wwin
;
813 /* don't let transients start miniaturized if their owners are not */
814 if (transientOwner
&& !transientOwner
->flags
.miniaturized
815 && wwin
->flags
.miniaturized
&& !withdraw
) {
816 wwin
->flags
.miniaturized
= 0;
818 wwin
->wm_hints
->initial_state
= NormalState
;
821 /* set workspace on which the window starts */
822 if (workspace
>= 0) {
823 if (workspace
> scr
->workspace_count
-1) {
824 workspace
= workspace
% scr
->workspace_count
;
829 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
831 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
836 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
838 workspace
= transientOwner
->frame
->workspace
;
842 workspace
= scr
->current_workspace
;
847 /* setup window geometry */
848 if (win_state
&& win_state
->state
->use_geometry
) {
849 width
= win_state
->state
->w
;
850 height
= win_state
->state
->h
;
852 wWindowConstrainSize(wwin
, &width
, &height
);
854 /* do not ask for window placement if the window is
855 * transient, during startup, if the initial workspace is another one
856 * or if the window wants to start iconic.
857 * If geometry was saved, restore it. */
859 Bool dontBring
= False
;
861 if (win_state
&& win_state
->state
->use_geometry
) {
862 x
= win_state
->state
->x
;
863 y
= win_state
->state
->y
;
864 } else if ((wwin
->transient_for
==None
865 || wPreferences
.window_placement
!=WPM_MANUAL
)
866 && !scr
->flags
.startup
867 && workspace
== scr
->current_workspace
868 && !wwin
->flags
.miniaturized
869 && !wwin
->flags
.maximized
870 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
871 PlaceWindow(wwin
, &x
, &y
, width
, height
);
872 if (wPreferences
.window_placement
== WPM_MANUAL
)
876 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
877 wScreenBringInside(scr
, &x
, &y
, width
, height
);
880 if (wwin
->flags
.urgent
) {
881 if (!IS_OMNIPRESENT(wwin
))
882 wwin
->flags
.omnipresent
^= 1;
886 *--------------------------------------------------
888 * Create frame, borders and do reparenting
890 *--------------------------------------------------
892 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
893 #ifdef XKB_BUTTON_HINT
894 if (wPreferences
.modelock
)
895 foo
|= WFF_LANGUAGE_BUTTON
;
897 if (!WFLAGP(wwin
, no_titlebar
))
899 if (!WFLAGP(wwin
, no_resizebar
))
900 foo
|= WFF_RESIZEBAR
;
902 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
903 x
, y
, width
, height
, foo
,
904 scr
->window_title_texture
,
905 scr
->resizebar_texture
,
906 scr
->window_title_pixel
,
907 #ifdef DRAWSTRING_PLUGIN
910 &scr
->window_title_gc
,
913 wwin
->frame
->flags
.is_client_window_frame
= 1;
914 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
916 /* setup button images */
917 wWindowUpdateButtonImages(wwin
);
919 /* hide unused buttons */
921 if (WFLAGP(wwin
, no_close_button
))
922 foo
|= WFF_RIGHT_BUTTON
;
923 if (WFLAGP(wwin
, no_miniaturize_button
))
924 foo
|= WFF_LEFT_BUTTON
;
925 #ifdef XKB_BUTTON_HINT
926 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
927 foo
|= WFF_LANGUAGE_BUTTON
;
930 wFrameWindowHideButton(wwin
->frame
, foo
);
932 wwin
->frame
->child
= wwin
;
935 /* emulate olwm push pin. Make the button look as pushed-in for
936 * the pinned-out state. When the button is clicked, it will
937 * revert to the normal position, which means the pin is pinned-in.
939 if (wwin
->flags
.olwm_push_pin_out
)
940 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
941 #endif /* OLWM_HINTS */
943 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
947 wwin
->frame
->workspace
= workspace
;
949 wwin
->frame
->on_click_left
= windowIconifyClick
;
950 #ifdef XKB_BUTTON_HINT
951 if (wPreferences
.modelock
)
952 wwin
->frame
->on_click_language
= windowLanguageClick
;
955 wwin
->frame
->on_click_right
= windowCloseClick
;
956 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
958 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
959 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
961 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
964 XSelectInput(dpy
, wwin
->client_win
,
965 wwin
->event_mask
& ~StructureNotifyMask
);
967 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
968 0, wwin
->frame
->top_width
);
970 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
976 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
978 /* if gravity is to the south, account for the border sizes */
980 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
984 * wWindowConfigure() will init the client window's size
985 * (wwin->client.{width,height}) and all other geometry
986 * related variables (frame_x,frame_y)
988 wWindowConfigure(wwin
, x
, y
, width
, height
);
990 /* to make sure the window receives it's new position after reparenting */
991 wWindowSynthConfigureNotify(wwin
);
994 *--------------------------------------------------
996 * Setup descriptors and save window to internal
999 *--------------------------------------------------
1002 if (wwin
->main_window
!=None
) {
1006 /* Leader windows do not necessary set themselves as leaders.
1007 * If this is the case, point the leader of this window to
1009 leader
= wWindowFor(wwin
->main_window
);
1010 if (leader
&& leader
->main_window
==None
) {
1011 leader
->main_window
= leader
->client_win
;
1013 app
= wApplicationCreate(scr
, wwin
->main_window
);
1015 app
->last_workspace
= workspace
;
1018 * Do application specific stuff, like setting application
1022 if (wwin
->flags
.hidden
) {
1023 /* if the window was set to hidden because it was hidden
1024 * in a previous incarnation and that state was restored */
1025 app
->flags
.hidden
= 1;
1028 if (app
->flags
.hidden
) {
1029 wwin
->flags
.hidden
= 1;
1034 /* setup the frame descriptor */
1035 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1036 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1037 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1039 /* don't let windows go away if we die */
1040 XAddToSaveSet(dpy
, window
);
1042 XLowerWindow(dpy
, window
);
1044 /* if window is in this workspace and should be mapped, then map it */
1045 if (!wwin
->flags
.miniaturized
1046 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1047 && !wwin
->flags
.hidden
&& !withdraw
) {
1049 /* The following "if" is to avoid crashing of clients that expect
1050 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1051 * after the return from this function.
1053 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1054 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1056 wClientSetState(wwin
, NormalState
, None
);
1060 /* if not auto focus, then map the window under the currently
1062 #define _WIDTH(w) (w)->frame->core->width
1063 #define _HEIGHT(w) (w)->frame->core->height
1064 if (!wPreferences
.auto_focus
&& scr
->focused_window
1065 && !scr
->flags
.startup
&& !transientOwner
1066 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1067 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1068 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1069 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1070 || wwin
->flags
.maximized
)) {
1071 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1079 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1080 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1082 * The brain damaged idiotic non-click to focus modes will
1083 * have trouble with this because:
1085 * 1. window is created and mapped by the client
1086 * 2. window is mapped by wmaker in small size
1087 * 3. window is animated to grow to normal size
1088 * 4. this function returns to normal event loop
1089 * 5. eventually, the EnterNotify event that would trigger
1090 * the window focusing (if the mouse is over that window)
1091 * will be processed by wmaker.
1092 * But since this event will be rather delayed
1093 * (step 3 has a large delay) the time when the event ocurred
1094 * and when it is processed, the client that owns that window
1095 * will reject the XSetInputFocus() for it.
1097 && (wPreferences
.focus_mode
==WKF_CLICK
1098 || wPreferences
.auto_focus
)) {
1099 DoWindowBirth(wwin
);
1105 /* setup stacking descriptor */
1106 if (transientOwner
) {
1107 /* && wPreferences.on_top_transients */
1108 if (transientOwner
) {
1109 wwin
->frame
->core
->stacking
->child_of
=
1110 transientOwner
->frame
->core
;
1113 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1117 if (!scr
->focused_window
) {
1118 /* first window on the list */
1121 scr
->focused_window
= wwin
;
1125 /* add window at beginning of focus window list */
1126 tmp
= scr
->focused_window
;
1135 wGNOMEUpdateClientStateHint(wwin
, True
);
1138 wKWMUpdateClientWorkspace(wwin
);
1139 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1145 *--------------------------------------------------
1147 * Final preparations before window is ready to go
1149 *--------------------------------------------------
1152 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1155 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1156 && !wwin
->flags
.hidden
) {
1157 if (((transientOwner
&& transientOwner
->flags
.focused
)
1158 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1159 wSetFocusTo(scr
, wwin
);
1161 wWindowResetMouseGrabs(wwin
);
1163 if (!WFLAGP(wwin
, no_bind_keys
)) {
1164 wWindowSetKeyGrabs(wwin
);
1167 wGNOMEUpdateClientListHint(scr
);
1170 wwin
->flags
.kwm_managed
= 1;
1172 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1175 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1177 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1180 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1181 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1183 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1184 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1190 *------------------------------------------------------------
1191 * Setup Notification Observers
1192 *------------------------------------------------------------
1194 WMAddNotificationObserver(appearanceObserver
, wwin
,
1195 WNWindowAppearanceSettingsChanged
, wwin
);
1199 *--------------------------------------------------
1201 * Cleanup temporary stuff
1203 *--------------------------------------------------
1207 wWindowDeleteSavedState(win_state
);
1209 /* If the window must be withdrawed, then do it now.
1210 * Must do some optimization, 'though */
1212 wwin
->flags
.mapped
= 0;
1213 wClientSetState(wwin
, WithdrawnState
, None
);
1214 wUnmanageWindow(wwin
, True
, False
);
1226 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1227 char *title
, int x
, int y
, int width
, int height
)
1232 wwin
= wWindowCreate();
1234 WMAddNotificationObserver(appearanceObserver
, wwin
,
1235 WNWindowAppearanceSettingsChanged
, wwin
);
1237 wwin
->flags
.internal_window
= 1;
1239 WSETUFLAG(wwin
, omnipresent
, 1);
1240 WSETUFLAG(wwin
, no_shadeable
, 1);
1241 WSETUFLAG(wwin
, no_resizable
, 1);
1242 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1244 wwin
->focus_mode
= WFM_PASSIVE
;
1246 wwin
->client_win
= window
;
1247 wwin
->screen_ptr
= scr
;
1249 wwin
->transient_for
= owner
;
1253 wwin
->client
.width
= width
;
1254 wwin
->client
.height
= height
;
1256 wwin
->frame_x
= wwin
->client
.x
;
1257 wwin
->frame_y
= wwin
->client
.y
;
1260 foo
= WFF_RIGHT_BUTTON
;
1261 foo
|= WFF_TITLEBAR
;
1262 #ifdef XKB_BUTTON_HINT
1263 foo
|= WFF_LANGUAGE_BUTTON
;
1266 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1267 wwin
->frame_x
, wwin
->frame_y
,
1269 scr
->window_title_texture
,
1270 scr
->resizebar_texture
,
1271 scr
->window_title_pixel
,
1272 #ifdef DRAWSTRING_PLUGIN
1275 &scr
->window_title_gc
,
1278 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1280 wwin
->frame
->flags
.is_client_window_frame
= 1;
1281 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1283 wFrameWindowChangeTitle(wwin
->frame
, title
);
1285 /* setup button images */
1286 wWindowUpdateButtonImages(wwin
);
1289 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1291 wwin
->frame
->child
= wwin
;
1293 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1295 #ifdef XKB_BUTTON_HINT
1296 if (wPreferences
.modelock
)
1297 wwin
->frame
->on_click_language
= windowLanguageClick
;
1300 wwin
->frame
->on_click_right
= windowCloseClick
;
1302 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1303 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1305 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1307 wwin
->client
.y
+= wwin
->frame
->top_width
;
1308 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1309 0, wwin
->frame
->top_width
);
1311 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1312 wwin
->client
.width
, wwin
->client
.height
);
1314 /* setup the frame descriptor */
1315 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1316 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1317 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1320 XLowerWindow(dpy
, window
);
1321 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1323 /* setup stacking descriptor */
1326 wPreferences
.on_top_transients
&&
1328 wwin
->transient_for
!=None
1329 && wwin
->transient_for
!=scr
->root_win
) {
1331 tmp
= wWindowFor(wwin
->transient_for
);
1333 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1335 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1339 if (!scr
->focused_window
) {
1340 /* first window on the list */
1343 scr
->focused_window
= wwin
;
1347 /* add window at beginning of focus window list */
1348 tmp
= scr
->focused_window
;
1356 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1358 /* if (wPreferences.auto_focus)*/
1359 wSetFocusTo(scr
, wwin
);
1361 wWindowResetMouseGrabs(wwin
);
1363 wWindowSetKeyGrabs(wwin
);
1365 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1372 *----------------------------------------------------------------------
1374 * Removes the frame window from a window and destroys all data
1375 * related to it. The window will be reparented back to the root window
1376 * if restore is True.
1379 * Everything related to the window is destroyed and the window
1380 * is removed from the window lists. Focus is set to the previous on the
1382 *----------------------------------------------------------------------
1385 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1387 WCoreWindow
*frame
= wwin
->frame
->core
;
1388 WWindow
*owner
= NULL
;
1389 WWindow
*newFocusedWindow
= NULL
;
1391 WScreen
*scr
= wwin
->screen_ptr
;
1395 wwin
->frame
->workspace
= -1;
1397 wKWMUpdateClientWorkspace(wwin
);
1400 /* First close attribute editor window if open */
1401 if (wwin
->flags
.inspector_open
) {
1402 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1403 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1406 /* Close window menu if it's open for this window */
1407 if (wwin
->flags
.menu_open_for_me
) {
1408 CloseWindowMenu(scr
);
1412 if (!wwin
->flags
.internal_window
)
1413 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1415 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1417 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1418 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1421 XUnmapWindow(dpy
, frame
->window
);
1423 XUnmapWindow(dpy
, wwin
->client_win
);
1425 /* deselect window */
1426 wSelectWindow(wwin
, False
);
1428 /* remove all pending events on window */
1429 /* I think this only matters for autoraise */
1430 if (wPreferences
.raise_delay
)
1431 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1435 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1437 /* reparent the window back to the root */
1439 wClientRestore(wwin
);
1441 if (wwin
->transient_for
!=scr
->root_win
) {
1442 owner
= wWindowFor(wwin
->transient_for
);
1444 if (!owner
->flags
.semi_focused
) {
1447 owner
->flags
.semi_focused
= 0;
1452 wasFocused
= wwin
->flags
.focused
;
1454 /* remove from window focus list */
1455 if (!wwin
->prev
&& !wwin
->next
) {
1456 /* was the only window */
1457 scr
->focused_window
= NULL
;
1458 newFocusedWindow
= NULL
;
1463 wwin
->prev
->next
= wwin
->next
;
1465 wwin
->next
->prev
= wwin
->prev
;
1467 scr
->focused_window
= wwin
->prev
;
1468 scr
->focused_window
->next
= NULL
;
1471 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1473 /* if in click to focus mode and the window
1474 * was a transient, focus the owner window
1477 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1478 tmp
= wWindowFor(wwin
->transient_for
);
1479 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1483 /* otherwise, focus the next one in the focus list */
1485 tmp
= scr
->focused_window
;
1486 while (tmp
) { /* look for one in the window list first */
1487 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1488 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1492 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1493 tmp
= scr
->focused_window
;
1495 if (!WFLAGP(tmp
, no_focusable
)
1496 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1503 newFocusedWindow
= tmp
;
1505 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1506 || wPreferences
.focus_mode
==WKF_POINTER
) {
1511 /* This is to let the root window get the keyboard input
1512 * if Sloppy focus mode and no other window get focus.
1513 * This way keybindings will not freeze.
1516 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1517 &foo
, &foo
, &foo
, &foo
, &mask
))
1518 tmp
= wWindowFor(win
);
1521 newFocusedWindow
= tmp
;
1523 newFocusedWindow
= NULL
;
1527 if (!wwin
->flags
.internal_window
) {
1529 wGNOMERemoveClient(wwin
);
1532 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1537 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1538 (unsigned)frame
->window
);
1542 if (newFocusedWindow
!= owner
&& owner
) {
1543 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1545 wSetFocusTo(scr
, newFocusedWindow
);
1547 wWindowDestroy(wwin
);
1553 wWindowMap(WWindow
*wwin
)
1555 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1556 if (!wwin
->flags
.shaded
) {
1557 /* window will be remapped when getting MapNotify */
1558 XSelectInput(dpy
, wwin
->client_win
,
1559 wwin
->event_mask
& ~StructureNotifyMask
);
1560 XMapWindow(dpy
, wwin
->client_win
);
1561 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1563 wwin
->flags
.mapped
= 1;
1569 wWindowUnmap(WWindow
*wwin
)
1571 wwin
->flags
.mapped
= 0;
1573 /* prevent window withdrawal when getting UnmapNotify */
1574 XSelectInput(dpy
, wwin
->client_win
,
1575 wwin
->event_mask
& ~StructureNotifyMask
);
1576 XUnmapWindow(dpy
, wwin
->client_win
);
1577 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1579 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1585 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1590 #ifdef KEEP_XKB_LOCK_STATUS
1591 if (wPreferences
.modelock
) {
1592 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1594 #endif /* KEEP_XKB_LOCK_STATUS */
1596 wwin
->flags
.semi_focused
= 0;
1598 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1600 wwin
->flags
.focused
= 1;
1602 wWindowResetMouseGrabs(wwin
);
1604 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1606 if (owin
== wwin
|| !owin
)
1609 nowner
= wWindowFor(wwin
->transient_for
);
1611 /* new window is a transient for the old window */
1612 if (nowner
== owin
) {
1613 owin
->flags
.semi_focused
= 1;
1614 wWindowUnfocus(nowner
);
1618 oowner
= wWindowFor(owin
->transient_for
);
1620 /* new window is owner of old window */
1621 if (wwin
== oowner
) {
1622 wWindowUnfocus(owin
);
1627 wWindowUnfocus(owin
);
1631 /* new window has same owner of old window */
1632 if (oowner
== nowner
) {
1633 /* prevent unfocusing of owner */
1634 oowner
->flags
.semi_focused
= 0;
1635 wWindowUnfocus(owin
);
1636 oowner
->flags
.semi_focused
= 1;
1641 /* nowner != NULL && oowner != nowner */
1642 nowner
->flags
.semi_focused
= 1;
1643 wWindowUnfocus(nowner
);
1644 wWindowUnfocus(owin
);
1649 wWindowUnfocus(WWindow
*wwin
)
1651 CloseWindowMenu(wwin
->screen_ptr
);
1653 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1654 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1656 if (wwin
->transient_for
!=None
1657 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1659 owner
= wWindowFor(wwin
->transient_for
);
1660 if (owner
&& owner
->flags
.semi_focused
) {
1661 owner
->flags
.semi_focused
= 0;
1662 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1663 wWindowUnfocus(owner
);
1664 wFrameWindowPaint(owner
->frame
);
1668 wwin
->flags
.focused
= 0;
1670 wWindowResetMouseGrabs(wwin
);
1672 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1679 *----------------------------------------------------------------------
1681 * wWindowConstrainSize--
1682 * Constrains size for the client window, taking the maximal size,
1683 * window resize increments and other size hints into account.
1686 * The closest size to what was given that the client window can
1689 *----------------------------------------------------------------------
1692 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1694 int width
= *nwidth
;
1695 int height
= *nheight
;
1698 int minW
= 1, minH
= 1;
1699 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1700 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1701 int minAX
= -1, minAY
= -1;
1702 int maxAX
= -1, maxAY
= -1;
1706 if (wwin
->normal_hints
) {
1707 winc
= wwin
->normal_hints
->width_inc
;
1708 hinc
= wwin
->normal_hints
->height_inc
;
1709 minW
= wwin
->normal_hints
->min_width
;
1710 minH
= wwin
->normal_hints
->min_height
;
1711 maxW
= wwin
->normal_hints
->max_width
;
1712 maxH
= wwin
->normal_hints
->max_height
;
1713 if (wwin
->normal_hints
->flags
& PAspect
) {
1714 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1715 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1716 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1717 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1731 /* aspect ratio code borrowed from olwm */
1733 /* adjust max aspect ratio */
1734 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1735 if (maxAX
> maxAY
) {
1736 height
= (width
* maxAY
) / maxAX
;
1737 if (height
> maxH
) {
1739 width
= (height
* maxAX
) / maxAY
;
1742 width
= (height
* maxAX
) / maxAY
;
1745 height
= (width
* maxAY
) / maxAX
;
1750 /* adjust min aspect ratio */
1751 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1752 if (minAX
> minAY
) {
1753 height
= (width
* minAY
) / minAX
;
1754 if (height
< minH
) {
1756 width
= (height
* minAX
) / minAY
;
1759 width
= (height
* minAX
) / minAY
;
1762 height
= (width
* minAY
) / minAX
;
1769 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1771 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1775 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1777 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1786 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1788 WScreen
*scr
= wwin
->screen_ptr
;
1792 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1793 || workspace
== wwin
->frame
->workspace
)
1796 if (workspace
!= scr
->current_workspace
) {
1797 /* Sent to other workspace. Unmap window */
1798 if ((wwin
->flags
.mapped
1799 || wwin
->flags
.shaded
1800 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1801 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1803 wapp
= wApplicationOf(wwin
->main_window
);
1805 wapp
->last_workspace
= workspace
;
1807 if (wwin
->flags
.miniaturized
) {
1809 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1810 wwin
->icon
->mapped
= 0;
1814 wSetFocusTo(scr
, NULL
);
1818 /* brought to current workspace. Map window */
1819 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1821 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1822 wwin
->icon
->mapped
= 1;
1824 } else if (!wwin
->flags
.mapped
&&
1825 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1829 if (!IS_OMNIPRESENT(wwin
)) {
1830 wwin
->frame
->workspace
= workspace
;
1831 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1834 wGNOMEUpdateClientStateHint(wwin
, True
);
1837 wKWMUpdateClientWorkspace(wwin
);
1838 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1847 wWindowSynthConfigureNotify(WWindow
*wwin
)
1851 sevent
.type
= ConfigureNotify
;
1852 sevent
.xconfigure
.display
= dpy
;
1853 sevent
.xconfigure
.event
= wwin
->client_win
;
1854 sevent
.xconfigure
.window
= wwin
->client_win
;
1856 sevent
.xconfigure
.x
= wwin
->client
.x
;
1857 sevent
.xconfigure
.y
= wwin
->client
.y
;
1858 sevent
.xconfigure
.width
= wwin
->client
.width
;
1859 sevent
.xconfigure
.height
= wwin
->client
.height
;
1861 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1862 if (WFLAGP(wwin
, no_titlebar
))
1863 sevent
.xconfigure
.above
= None
;
1865 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1867 sevent
.xconfigure
.override_redirect
= False
;
1868 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1870 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1877 *----------------------------------------------------------------------
1878 * wWindowConfigure--
1879 * Configures the frame, decorations and client window to the
1880 * specified geometry. The geometry is not checked for validity,
1881 * wWindowConstrainSize() must be used for that.
1882 * The size parameters are for the client window, but the position is
1884 * The client window receives a ConfigureNotify event, according
1885 * to what ICCCM says.
1891 * Window size and position are changed and client window receives
1892 * a ConfigureNotify event.
1893 *----------------------------------------------------------------------
1896 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1898 int req_x
, req_y
; /* new position of the frame */
1899 int req_width
, req_height
; /* new size of the client */
1901 int synth_notify
= False
;
1904 resize
= (req_width
!=wwin
->client
.width
1905 || req_height
!=wwin
->client
.height
);
1907 * if the window is being moved but not resized then
1908 * send a synthetic ConfigureNotify
1910 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1911 synth_notify
= True
;
1914 if (WFLAGP(wwin
, dont_move_off
))
1915 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1916 req_width
, req_height
);
1918 if (req_width
< MIN_WINDOW_SIZE
)
1919 req_width
= MIN_WINDOW_SIZE
;
1920 if (req_height
< MIN_WINDOW_SIZE
)
1921 req_height
= MIN_WINDOW_SIZE
;
1923 /* If growing, resize inner part before frame,
1924 * if shrinking, resize frame before.
1925 * This will prevent the frame (that can have a different color)
1926 * to be exposed, causing flicker */
1927 if (req_height
> wwin
->frame
->core
->height
1928 || req_width
> wwin
->frame
->core
->width
)
1929 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1931 if (wwin
->flags
.shaded
) {
1932 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1933 req_width
, wwin
->frame
->core
->height
);
1934 wwin
->old_geometry
.height
= req_height
;
1938 h
= req_height
+ wwin
->frame
->top_width
1939 + wwin
->frame
->bottom_width
;
1941 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1944 if (!(req_height
> wwin
->frame
->core
->height
1945 || req_width
> wwin
->frame
->core
->width
))
1946 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1948 wwin
->client
.x
= req_x
;
1949 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1950 wwin
->client
.width
= req_width
;
1951 wwin
->client
.height
= req_height
;
1953 wwin
->client
.x
= req_x
;
1954 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1956 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1958 wwin
->frame_x
= req_x
;
1959 wwin
->frame_y
= req_y
;
1962 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1963 wWindowSetShape(wwin
);
1968 wWindowSynthConfigureNotify(wwin
);
1974 wWindowMove(wwin
, req_x
, req_y
)
1976 int req_x
, req_y
; /* new position of the frame */
1978 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1979 int synth_notify
= False
;
1981 /* Send a synthetic ConfigureNotify event for every window movement. */
1982 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1983 synth_notify
= True
;
1986 /* A single synthetic ConfigureNotify event is sent at the end of
1987 * a completed (opaque) movement in moveres.c */
1990 if (WFLAGP(wwin
, dont_move_off
))
1991 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1992 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1994 wwin
->client
.x
= req_x
;
1995 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1997 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1999 wwin
->frame_x
= req_x
;
2000 wwin
->frame_y
= req_y
;
2002 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2004 wWindowSynthConfigureNotify(wwin
);
2009 wWindowUpdateButtonImages(WWindow
*wwin
)
2011 WScreen
*scr
= wwin
->screen_ptr
;
2012 Pixmap pixmap
, mask
;
2013 WFrameWindow
*fwin
= wwin
->frame
;
2015 if (WFLAGP(wwin
, no_titlebar
))
2018 /* miniaturize button */
2020 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2021 if (wwin
->wm_gnustep_attr
2022 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2023 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2025 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2026 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2031 if (fwin
->lbutton_image
2032 && (fwin
->lbutton_image
->image
!= pixmap
2033 || fwin
->lbutton_image
->mask
!= mask
)) {
2034 wPixmapDestroy(fwin
->lbutton_image
);
2035 fwin
->lbutton_image
= NULL
;
2038 if (!fwin
->lbutton_image
) {
2039 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2040 fwin
->lbutton_image
->client_owned
= 1;
2041 fwin
->lbutton_image
->client_owned_mask
= 1;
2044 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2045 wPixmapDestroy(fwin
->lbutton_image
);
2047 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2051 #ifdef XKB_BUTTON_HINT
2052 if (!WFLAGP(wwin
, no_language_button
)) {
2053 if (fwin
->languagebutton_image
&&
2054 !fwin
->languagebutton_image
->shared
) {
2055 wPixmapDestroy(fwin
->languagebutton_image
);
2057 fwin
->languagebutton_image
=
2058 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2064 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2065 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2067 if (!WFLAGP(wwin
, no_close_button
)) {
2068 if (wwin
->wm_gnustep_attr
2069 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2070 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2072 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2073 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2077 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2078 || fwin
->rbutton_image
->mask
!= mask
)) {
2079 wPixmapDestroy(fwin
->rbutton_image
);
2080 fwin
->rbutton_image
= NULL
;
2083 if (!fwin
->rbutton_image
) {
2084 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2085 fwin
->rbutton_image
->client_owned
= 1;
2086 fwin
->rbutton_image
->client_owned_mask
= 1;
2089 } else if (WFLAGP(wwin
, kill_close
)) {
2091 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2092 wPixmapDestroy(fwin
->rbutton_image
);
2094 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2096 } else if (MGFLAGP(wwin
, broken_close
)) {
2098 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2099 wPixmapDestroy(fwin
->rbutton_image
);
2101 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2105 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2106 wPixmapDestroy(fwin
->rbutton_image
);
2108 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2112 /* force buttons to be redrawn */
2113 fwin
->flags
.need_texture_change
= 1;
2114 wFrameWindowPaint(fwin
);
2119 *---------------------------------------------------------------------------
2120 * wWindowConfigureBorders--
2121 * Update window border configuration according to attribute flags.
2123 *---------------------------------------------------------------------------
2126 wWindowConfigureBorders(WWindow
*wwin
)
2132 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2133 #ifdef XKB_BUTTON_HINT
2134 flags
|= WFF_LANGUAGE_BUTTON
;
2136 if (!WFLAGP(wwin
, no_titlebar
))
2137 flags
|= WFF_TITLEBAR
;
2138 if (!WFLAGP(wwin
, no_resizebar
))
2139 flags
|= WFF_RESIZEBAR
;
2140 if (wwin
->flags
.shaded
)
2141 flags
|= WFF_IS_SHADED
;
2143 oldh
= wwin
->frame
->top_width
;
2144 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2145 if (oldh
!= wwin
->frame
->top_width
) {
2146 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2148 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2149 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2150 wwin
->client
.width
, wwin
->client
.height
);
2154 if (!WFLAGP(wwin
, no_miniaturize_button
)
2155 && wwin
->frame
->flags
.hide_left_button
)
2156 flags
|= WFF_LEFT_BUTTON
;
2158 #ifdef XKB_BUTTON_HINT
2159 if (!WFLAGP(wwin
, no_language_button
)
2160 && wwin
->frame
->flags
.hide_language_button
)
2161 flags
|= WFF_LANGUAGE_BUTTON
;
2164 if (!WFLAGP(wwin
, no_close_button
)
2165 && wwin
->frame
->flags
.hide_right_button
)
2166 flags
|= WFF_RIGHT_BUTTON
;
2169 wWindowUpdateButtonImages(wwin
);
2170 wFrameWindowShowButton(wwin
->frame
, flags
);
2174 if (WFLAGP(wwin
, no_miniaturize_button
)
2175 && !wwin
->frame
->flags
.hide_left_button
)
2176 flags
|= WFF_LEFT_BUTTON
;
2178 #ifdef XKB_BUTTON_HINT
2179 if (WFLAGP(wwin
, no_language_button
)
2180 && !wwin
->frame
->flags
.hide_language_button
)
2181 flags
|= WFF_LANGUAGE_BUTTON
;
2184 if (WFLAGP(wwin
, no_close_button
)
2185 && !wwin
->frame
->flags
.hide_right_button
)
2186 flags
|= WFF_RIGHT_BUTTON
;
2189 wFrameWindowHideButton(wwin
->frame
, flags
);
2192 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2193 wWindowSetShape(wwin
);
2201 wWindowSaveState(WWindow
*wwin
)
2206 memset(data
, 0, sizeof(CARD32
)*10);
2207 data
[0] = wwin
->frame
->workspace
;
2208 data
[1] = wwin
->flags
.miniaturized
;
2209 data
[2] = wwin
->flags
.shaded
;
2210 data
[3] = wwin
->flags
.hidden
;
2212 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2213 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
)
2216 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2217 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2218 (unsigned char *)data
, 10);
2223 getSavedState(Window window
, WSavedState
**state
)
2227 unsigned long nitems_ret
;
2228 unsigned long bytes_after_ret
;
2231 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2232 True
, _XA_WINDOWMAKER_STATE
,
2233 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2234 (unsigned char **)&data
)!=Success
|| !data
)
2237 *state
= malloc(sizeof(WSavedState
));
2240 (*state
)->workspace
= data
[0];
2241 (*state
)->miniaturized
= data
[1];
2242 (*state
)->shaded
= data
[2];
2243 (*state
)->hidden
= data
[3];
2244 (*state
)->use_geometry
= data
[4];
2245 (*state
)->x
= data
[5];
2246 (*state
)->y
= data
[6];
2247 (*state
)->w
= data
[7];
2248 (*state
)->h
= data
[8];
2249 (*state
)->window_shortcuts
= data
[9];
2253 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2262 wWindowClearShape(WWindow
*wwin
)
2264 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2265 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2270 wWindowSetShape(WWindow
*wwin
)
2274 #ifdef OPTIMIZE_SHAPE
2279 /* only shape is the client's */
2280 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2284 /* Get array of rectangles describing the shape mask */
2285 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2291 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2297 /* insert our decoration rectangles in the rect list */
2298 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2301 if (!WFLAGP(wwin
, no_titlebar
)) {
2303 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2304 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2305 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2308 if (!WFLAGP(wwin
, no_resizebar
)) {
2310 urec
[count
].y
= wwin
->frame
->core
->height
2311 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2312 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2313 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2317 /* shape our frame window */
2318 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2319 0, wwin
->frame
->top_width
, urec
, count
,
2320 ShapeSet
, Unsorted
);
2326 #endif /* OPTIMIZE_SHAPE */
2328 if (!WFLAGP(wwin
, no_titlebar
)) {
2331 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2332 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2335 if (!WFLAGP(wwin
, no_resizebar
)) {
2337 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2338 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2339 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2343 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2344 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2346 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2347 0, wwin
->frame
->top_width
, wwin
->client_win
,
2348 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2353 /* ====================================================================== */
2356 getFocusMode(WWindow
*wwin
)
2360 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2361 if (wwin
->wm_hints
->input
== True
) {
2362 if (wwin
->protocols
.TAKE_FOCUS
)
2363 mode
= WFM_LOCALLY_ACTIVE
;
2367 if (wwin
->protocols
.TAKE_FOCUS
)
2368 mode
= WFM_GLOBALLY_ACTIVE
;
2370 mode
= WFM_NO_INPUT
;
2380 wWindowSetKeyGrabs(WWindow
*wwin
)
2385 for (i
=0; i
<WKBD_LAST
; i
++) {
2386 key
= &wKeyBindings
[i
];
2388 if (key
->keycode
==0)
2390 if (key
->modifier
!=AnyModifier
) {
2391 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2392 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2394 /* Also grab all modifier combinations possible that include,
2395 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2396 * work even if the NumLock/ScrollLock key is on.
2398 wHackedGrabKey(key
->keycode
, key
->modifier
,
2399 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2403 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2404 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2408 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2415 wWindowResetMouseGrabs(WWindow
*wwin
)
2417 /* Mouse grabs can't be done on the client window because of
2418 * ICCCM and because clients that try to do the same will crash.
2420 * But there is a problem wich makes tbar buttons of unfocused
2421 * windows not usable as the click goes to the frame window instead
2422 * of the button itself. Must figure a way to fix that.
2425 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2427 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2428 /* grabs for Meta+drag */
2429 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2430 True
, ButtonPressMask
, GrabModeSync
,
2431 GrabModeAsync
, None
, None
);
2434 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)) {
2435 /* the passive grabs to focus the window */
2436 if (wPreferences
.focus_mode
== WKF_CLICK
)
2437 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2438 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2446 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2448 if (attr
->flags
& GSExtraFlagsAttr
) {
2449 if (MGFLAGP(wwin
, broken_close
) !=
2450 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2451 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2452 wWindowUpdateButtonImages(wwin
);
2459 wWindowAddSavedState(char *instance
, char *class, char *command
,
2460 pid_t pid
, WSavedState
*state
)
2462 WWindowState
*wstate
;
2464 wstate
= malloc(sizeof(WWindowState
));
2468 memset(wstate
, 0, sizeof(WWindowState
));
2471 wstate
->instance
= wstrdup(instance
);
2473 wstate
->class = wstrdup(class);
2475 wstate
->command
= wstrdup(command
);
2476 wstate
->state
= state
;
2478 wstate
->next
= windowState
;
2479 windowState
= wstate
;
2482 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2490 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2494 wWindowGetSavedState(Window win
)
2496 char *instance
, *class, *command
=NULL
;
2497 WWindowState
*wstate
= windowState
;
2504 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2506 command
= FlattenStringList(argv
, argc
);
2507 XFreeStringList(argv
);
2512 if (PropGetWMClass(win
, &class, &instance
)) {
2514 if (SAME(instance
, wstate
->instance
) &&
2515 SAME(class, wstate
->class) &&
2516 SAME(command
, wstate
->command
)) {
2519 wstate
= wstate
->next
;
2526 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2530 if (command
) free(command
);
2531 if (instance
) XFree(instance
);
2532 if (class) XFree(class);
2539 wWindowDeleteSavedState(WMagicNumber id
)
2541 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2543 if (!wstate
|| !windowState
)
2548 windowState
= wstate
->next
;
2550 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2551 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2553 if (wstate
->instance
) free(wstate
->instance
);
2554 if (wstate
->class) free(wstate
->class);
2555 if (wstate
->command
) free(wstate
->command
);
2556 free(wstate
->state
);
2560 if (tmp
->next
==wstate
) {
2561 tmp
->next
=wstate
->next
;
2563 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2564 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2566 if (wstate
->instance
) free(wstate
->instance
);
2567 if (wstate
->class) free(wstate
->class);
2568 if (wstate
->command
) free(wstate
->command
);
2569 free(wstate
->state
);
2580 wWindowDeleteSavedStatesForPID(pid_t pid
)
2582 WWindowState
*tmp
, *wstate
;
2588 if (tmp
->pid
== pid
) {
2589 wstate
= windowState
;
2590 windowState
= tmp
->next
;
2592 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2593 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2595 if (wstate
->instance
) free(wstate
->instance
);
2596 if (wstate
->class) free(wstate
->class);
2597 if (wstate
->command
) free(wstate
->command
);
2598 free(wstate
->state
);
2602 if (tmp
->next
->pid
==pid
) {
2604 tmp
->next
= wstate
->next
;
2606 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2607 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2609 if (wstate
->instance
) free(wstate
->instance
);
2610 if (wstate
->class) free(wstate
->class);
2611 if (wstate
->command
) free(wstate
->command
);
2612 free(wstate
->state
);
2622 /* ====================================================================== */
2625 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2627 WWindow
*wwin
= data
;
2629 #ifndef NUMLOCK_HACK
2630 if ((event
->xbutton
.state
& ValidModMask
)
2631 != (event
->xbutton
.state
& ~LockMask
)) {
2632 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2633 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2637 event
->xbutton
.state
&= ValidModMask
;
2639 CloseWindowMenu(wwin
->screen_ptr
);
2641 if (wPreferences
.focus_mode
==WKF_CLICK
2642 && !(event
->xbutton
.state
&ControlMask
)
2643 && !WFLAGP(wwin
, no_focusable
)) {
2644 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2647 if (event
->xbutton
.button
== Button1
)
2648 wRaiseFrame(wwin
->frame
->core
);
2650 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2651 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2652 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2653 GrabModeAsync
, GrabModeAsync
, None
,
2654 None
, CurrentTime
)!=GrabSuccess
) {
2656 wwarning("pointer grab failed for window move");
2662 if (event
->xbutton
.state
& MOD_MASK
) {
2663 /* move the window */
2664 wMouseMoveWindow(wwin
, event
);
2665 XUngrabPointer(dpy
, CurrentTime
);
2667 wMouseResizeWindow(wwin
, event
);
2668 XUngrabPointer(dpy
, CurrentTime
);
2675 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2677 WWindow
*wwin
= data
;
2679 event
->xbutton
.state
&= ValidModMask
;
2681 if (event
->xbutton
.button
==Button1
) {
2682 if (event
->xbutton
.state
== 0) {
2683 if (!WFLAGP(wwin
, no_shadeable
)) {
2685 if (wwin
->flags
.shaded
)
2686 wUnshadeWindow(wwin
);
2693 if (event
->xbutton
.state
& ControlMask
)
2694 dir
|= MAX_VERTICAL
;
2696 if (event
->xbutton
.state
& ShiftMask
) {
2697 dir
|= MAX_HORIZONTAL
;
2698 if (!(event
->xbutton
.state
& ControlMask
))
2699 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2702 /* maximize window */
2703 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2704 if (wwin
->flags
.maximized
)
2705 wUnmaximizeWindow(wwin
);
2707 wMaximizeWindow(wwin
, dir
);
2710 } else if (event
->xbutton
.button
==Button3
) {
2711 if (event
->xbutton
.state
& MOD_MASK
) {
2712 wHideOtherApplications(wwin
);
2714 } else if (event
->xbutton
.button
==Button2
) {
2715 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2721 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2723 WWindow
*wwin
= desc
->parent
;
2725 event
->xbutton
.state
&= ValidModMask
;
2727 CloseWindowMenu(wwin
->screen_ptr
);
2729 if (wPreferences
.focus_mode
==WKF_CLICK
2730 && !(event
->xbutton
.state
&ControlMask
)
2731 && !WFLAGP(wwin
, no_focusable
)) {
2732 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2734 if (event
->xbutton
.button
== Button1
) {
2735 wRaiseFrame(wwin
->frame
->core
);
2738 if (event
->xbutton
.state
& MOD_MASK
) {
2739 /* move the window */
2740 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2741 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2742 GrabModeAsync
, GrabModeAsync
, None
,
2743 None
, CurrentTime
)!=GrabSuccess
) {
2745 wwarning("pointer grab failed for window move");
2749 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2750 wMouseResizeWindow(wwin
, event
);
2752 wMouseMoveWindow(wwin
, event
);
2753 XUngrabPointer(dpy
, CurrentTime
);
2759 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2761 WWindow
*wwin
= (WWindow
*)data
;
2763 #ifndef NUMLOCK_HACK
2764 if ((event
->xbutton
.state
& ValidModMask
)
2765 != (event
->xbutton
.state
& ~LockMask
)) {
2766 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2767 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2770 event
->xbutton
.state
&= ValidModMask
;
2772 CloseWindowMenu(wwin
->screen_ptr
);
2774 if (wPreferences
.focus_mode
==WKF_CLICK
2775 && !(event
->xbutton
.state
&ControlMask
)
2776 && !WFLAGP(wwin
, no_focusable
)) {
2777 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2780 if (event
->xbutton
.button
== Button1
2781 || event
->xbutton
.button
== Button2
) {
2783 if (event
->xbutton
.button
== Button1
) {
2784 if (event
->xbutton
.state
& MOD_MASK
) {
2785 wLowerFrame(wwin
->frame
->core
);
2787 wRaiseFrame(wwin
->frame
->core
);
2790 if ((event
->xbutton
.state
& ShiftMask
)
2791 && !(event
->xbutton
.state
& ControlMask
)) {
2792 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2795 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2796 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2797 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2798 GrabModeAsync
, GrabModeAsync
, None
,
2799 None
, CurrentTime
)!=GrabSuccess
) {
2801 wwarning("pointer grab failed for window move");
2806 /* move the window */
2807 wMouseMoveWindow(wwin
, event
);
2809 XUngrabPointer(dpy
, CurrentTime
);
2810 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2811 && !wwin
->flags
.internal_window
2812 && !WCHECK_STATE(WSTATE_MODAL
)) {
2813 WObjDescriptor
*desc
;
2815 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2816 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2817 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2818 GrabModeAsync
, GrabModeAsync
, None
,
2819 None
, CurrentTime
)!=GrabSuccess
) {
2821 wwarning("pointer grab failed for window move");
2826 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2827 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2829 /* allow drag select */
2830 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2831 event
->xany
.send_event
= True
;
2832 (*desc
->handle_mousedown
)(desc
, event
);
2834 XUngrabPointer(dpy
, CurrentTime
);
2841 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2843 WWindow
*wwin
= data
;
2845 event
->xbutton
.state
&= ValidModMask
;
2847 CloseWindowMenu(wwin
->screen_ptr
);
2849 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2852 /* if control-click, kill the client */
2853 if (event
->xbutton
.state
& ControlMask
) {
2857 if (wwin
->flags
.olwm_push_pin_out
) {
2859 wwin
->flags
.olwm_push_pin_out
= 0;
2861 wOLWMChangePushpinState(wwin
, True
);
2863 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2868 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2869 /* send delete message */
2870 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2877 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2879 WWindow
*wwin
= data
;
2881 CloseWindowMenu(wwin
->screen_ptr
);
2883 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2886 /* send delete message */
2887 if (wwin
->protocols
.DELETE_WINDOW
) {
2888 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2895 #ifdef XKB_BUTTON_HINT
2897 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2899 WWindow
*wwin
= data
;
2900 WFrameWindow
*fwin
= wwin
->frame
;
2901 WScreen
*scr
= fwin
->screen_ptr
;
2902 XkbStateRec staterec
;
2905 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2907 tl
= wwin
->frame
->languagemode
;
2908 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2909 wwin
->frame
->last_languagemode
= tl
;
2910 wSetFocusTo(scr
, wwin
);
2911 wwin
->frame
->languagebutton_image
=
2912 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
2913 wwin
->frame
->languagemode
];
2914 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2915 if (event
->xbutton
.button
== Button3
)
2917 wRaiseFrame(fwin
->core
);
2923 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2925 WWindow
*wwin
= data
;
2927 event
->xbutton
.state
&= ValidModMask
;
2929 CloseWindowMenu(wwin
->screen_ptr
);
2931 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2934 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2935 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2939 if ((event
->xbutton
.state
& ControlMask
) ||
2940 (event
->xbutton
.button
== Button3
)) {
2942 wapp
= wApplicationOf(wwin
->main_window
);
2943 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2944 wHideApplication(wapp
);
2945 } else if (event
->xbutton
.state
==0) {
2946 wIconifyWindow(wwin
);