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 */
37 /* For getting mouse wheel mappings from WINGs */
38 #include <WINGs/WINGsP.h>
40 #include "WindowMaker.h"
46 #include "winspector.h"
48 #include "properties.h"
55 #include "workspace.h"
68 # include "openlook.h"
71 /****** Global Variables ******/
73 extern WShortKey wKeyBindings
[WKBD_LAST
];
76 extern Bool wShapeSupported
;
80 extern XContext wWinContext
;
83 extern Cursor wCursor
[WCUR_LAST
];
86 extern Atom _XA_WM_DELETE_WINDOW
;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
89 extern Atom _XA_WINDOWMAKER_STATE
;
91 extern WPreferences wPreferences
;
93 #define MOD_MASK wPreferences.modifier_mask
95 extern Time LastTimestamp
;
98 extern void DoWindowBirth(WWindow
*);
102 /***** Local Stuff *****/
105 static WWindowState
*windowState
=NULL
;
109 /* local functions */
110 static FocusMode
getFocusMode(WWindow
*wwin
);
112 static int getSavedState(Window window
, WSavedState
**state
);
114 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
119 /* frame window (during window grabs) */
120 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
123 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
127 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
129 #ifdef XKB_BUTTON_HINT
130 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
133 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
134 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
136 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
139 /****** Notification Observers ******/
142 appearanceObserver(void *self
, WMNotification
*notif
)
144 WWindow
*wwin
= (WWindow
*)self
;
145 int flags
= (int)WMGetNotificationClientData(notif
);
147 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
150 if (flags
& WFontSettings
) {
151 wWindowConfigureBorders(wwin
);
152 if(wwin
->flags
.shaded
) {
153 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
154 wwin
->frame
->top_width
- 1);
156 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
157 + wwin
->frame
->top_width
;
158 wWindowSynthConfigureNotify(wwin
);
161 if (flags
& WTextureSettings
) {
162 wwin
->frame
->flags
.need_texture_remake
= 1;
164 if (flags
& (WTextureSettings
| WColorSettings
)) {
165 if (wwin
->frame
->titlebar
)
166 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
168 wFrameWindowPaint(wwin
->frame
);
172 /************************************/
175 wWindowFor(Window window
)
177 WObjDescriptor
*desc
;
182 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
185 if (desc
->parent_type
==WCLASS_WINDOW
)
187 else if (desc
->parent_type
==WCLASS_FRAME
) {
188 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
189 if (frame
->flags
.is_client_window_frame
)
202 wwin
= wmalloc(sizeof(WWindow
));
205 memset(wwin
, 0, sizeof(WWindow
));
207 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
208 wwin
->client_descriptor
.parent
= wwin
;
209 wwin
->client_descriptor
.self
= wwin
;
210 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
217 wWindowDestroy(WWindow
*wwin
)
221 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
222 wwin
->screen_ptr
->cmap_window
= NULL
;
225 WMRemoveNotificationObserver(wwin
);
227 wwin
->flags
.destroyed
= 1;
229 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
230 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
233 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
235 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
236 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
237 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
241 if (wwin
->normal_hints
)
242 XFree(wwin
->normal_hints
);
245 XFree(wwin
->wm_hints
);
247 if (wwin
->wm_instance
)
248 XFree(wwin
->wm_instance
);
251 XFree(wwin
->wm_class
);
253 if (wwin
->wm_gnustep_attr
)
254 wfree(wwin
->wm_gnustep_attr
);
256 if (wwin
->cmap_windows
)
257 XFree(wwin
->cmap_windows
);
259 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
262 wFrameWindowDestroy(wwin
->frame
);
265 RemoveFromStackList(wwin
->icon
->core
);
266 wIconDestroy(wwin
->icon
);
267 if (wPreferences
.auto_arrange_icons
)
268 wArrangeIcons(wwin
->screen_ptr
, True
);
277 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
279 if (gs_hints
->flags
& GSWindowStyleAttr
) {
280 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
281 wwin
->client_flags
.no_border
= 1;
282 wwin
->client_flags
.no_titlebar
= 1;
283 wwin
->client_flags
.no_closable
= 1;
284 wwin
->client_flags
.no_miniaturizable
= 1;
285 wwin
->client_flags
.no_resizable
= 1;
286 wwin
->client_flags
.no_close_button
= 1;
287 wwin
->client_flags
.no_miniaturize_button
= 1;
288 wwin
->client_flags
.no_resizebar
= 1;
290 wwin
->client_flags
.no_close_button
=
291 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
293 wwin
->client_flags
.no_closable
=
294 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
296 wwin
->client_flags
.no_miniaturize_button
=
297 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
299 wwin
->client_flags
.no_miniaturizable
=
300 wwin
->client_flags
.no_miniaturize_button
;
302 wwin
->client_flags
.no_resizebar
=
303 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
305 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
307 /* these attributes supposedly imply in the existence
309 if (gs_hints
->window_style
& (WMResizableWindowMask
|
310 WMClosableWindowMask
|
311 WMMiniaturizableWindowMask
)) {
312 wwin
->client_flags
.no_titlebar
= 0;
314 wwin
->client_flags
.no_titlebar
=
315 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
320 /* setup the defaults */
321 wwin
->client_flags
.no_border
= 0;
322 wwin
->client_flags
.no_titlebar
= 0;
323 wwin
->client_flags
.no_closable
= 0;
324 wwin
->client_flags
.no_miniaturizable
= 0;
325 wwin
->client_flags
.no_resizable
= 0;
326 wwin
->client_flags
.no_close_button
= 0;
327 wwin
->client_flags
.no_miniaturize_button
= 0;
328 wwin
->client_flags
.no_resizebar
= 0;
330 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
331 wwin
->client_flags
.no_appicon
= 1;
337 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
338 WWindowAttributes
*mask
)
340 if (wflags
->no_appicon
&& mask
->no_appicon
)
341 wflags
->emulate_appicon
= 0;
343 if (wwin
->main_window
!=None
) {
344 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
345 if (wapp
&& !wapp
->flags
.emulated
)
346 wflags
->emulate_appicon
= 0;
349 if (wwin
->transient_for
!=None
350 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
351 wflags
->emulate_appicon
= 0;
353 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
360 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
362 WScreen
*scr
= wwin
->screen_ptr
;
364 /* sets global default stuff */
365 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
366 &wwin
->client_flags
, NULL
, True
);
368 * Decoration setting is done in this precedence (lower to higher)
369 * - use global default in the resource database
370 * - guess some settings
371 * - use GNUstep/external window attributes
372 * - set hints specified for the app in the resource DB
375 WSETUFLAG(wwin
, broken_close
, 0);
377 if (wwin
->protocols
.DELETE_WINDOW
)
378 WSETUFLAG(wwin
, kill_close
, 0);
380 WSETUFLAG(wwin
, kill_close
, 1);
382 /* transients can't be iconified or maximized */
383 if (wwin
->transient_for
) {
384 WSETUFLAG(wwin
, no_miniaturizable
, 1);
385 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
388 /* if the window can't be resized, remove the resizebar */
389 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
390 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
391 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
392 WSETUFLAG(wwin
, no_resizable
, 1);
393 WSETUFLAG(wwin
, no_resizebar
, 1);
396 /* set GNUstep window attributes */
397 if (wwin
->wm_gnustep_attr
) {
398 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
400 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
402 *level
= wwin
->wm_gnustep_attr
->window_level
;
404 * INT_MIN is the only illegal window level.
406 if (*level
== INT_MIN
)
407 *level
= INT_MIN
+ 1;
410 *level
= WMNormalLevel
;
413 int tmp_workspace
= -1;
414 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
420 wMWMCheckClientHints(wwin
);
421 #endif /* MWM_HINTS */
424 check
= wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
425 #endif /* GNOME_STUFF */
429 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
430 #endif /* KWM_HINTS */
433 wOLWMCheckClientHints(wwin
);
434 #endif /* OLWM_HINTS */
436 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
437 * have INT_MIN that means that no window level was requested. -Dan
439 if (tmp_level
== INT_MIN
) {
440 if (WFLAGP(wwin
, floating
))
441 *level
= WMFloatingLevel
;
442 else if (WFLAGP(wwin
, sunken
))
443 *level
= WMSunkenLevel
;
445 *level
= WMNormalLevel
;
450 if (tmp_workspace
>= 0) {
451 *workspace
= tmp_workspace
% scr
->workspace_count
;
456 * Set attributes specified only for that window/class.
457 * This might do duplicate work with the 1st wDefaultFillAttributes().
459 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
460 &wwin
->user_flags
, &wwin
->defined_user_flags
,
463 * Sanity checks for attributes that depend on other attributes
465 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
466 wwin
->user_flags
.emulate_appicon
= 0;
468 if (wwin
->main_window
!=None
) {
469 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
470 if (wapp
&& !wapp
->flags
.emulated
)
471 wwin
->user_flags
.emulate_appicon
= 0;
474 if (wwin
->transient_for
!=None
475 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
476 wwin
->user_flags
.emulate_appicon
= 0;
478 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
479 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
480 wwin
->user_flags
.sunken
= 0;
482 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
489 wWindowCanReceiveFocus(WWindow
*wwin
)
491 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
493 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
495 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
503 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
507 w1
= wwin
->frame
->core
->width
;
508 h1
= wwin
->frame
->core
->height
;
509 w2
= obscured
->frame
->core
->width
;
510 h2
= obscured
->frame
->core
->height
;
512 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
513 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
516 if (wwin
->frame_x
+ w1
< obscured
->frame_x
517 || wwin
->frame_y
+ h1
< obscured
->frame_y
518 || wwin
->frame_x
> obscured
->frame_x
+ w2
519 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
529 *----------------------------------------------------------------
531 * reparents the window and allocates a descriptor for it.
532 * Window manager hints and other hints are fetched to configure
533 * the window decoration attributes and others. User preferences
534 * for the window are used if available, to configure window
535 * decorations and some behaviour.
536 * If in startup, windows that are override redirect,
537 * unmapped and never were managed and are Withdrawn are not
541 * the new window descriptor
544 * The window is reparented and appropriate notification
545 * is done to the client. Input mask for the window is setup.
546 * The window descriptor is also associated with various window
547 * contexts and inserted in the head of the window list.
548 * Event handler contexts are associated for some objects
549 * (buttons, titlebar and resizebar)
551 *----------------------------------------------------------------
554 wManageWindow(WScreen
*scr
, Window window
)
558 unsigned width
, height
;
559 XWindowAttributes wattribs
;
560 XSetWindowAttributes attribs
;
561 WWindowState
*win_state
;
562 WWindow
*transientOwner
= NULL
;
568 Bool withdraw
= False
;
572 /* XGrabServer(dpy); */
574 /* make sure the window is still there */
575 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
580 /* if it's an override-redirect, ignore it */
581 if (wattribs
.override_redirect
) {
586 wm_state
= PropGetWindowState(window
);
588 /* if it's startup and the window is unmapped, don't manage it */
589 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
594 if (!wFetchName(dpy
, window
, &title
)) {
599 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
604 #endif /* KWM_HINTS */
607 wwin
= wWindowCreate();
609 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
612 printf("managing window %x\n", (unsigned)window
);
616 if (wShapeSupported
) {
621 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
622 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
623 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
624 wwin
->flags
.shaped
= b_shaped
;
629 *--------------------------------------------------
631 * Get hints and other information in properties
633 *--------------------------------------------------
635 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
637 /* setup descriptor */
638 wwin
->client_win
= window
;
639 wwin
->screen_ptr
= scr
;
641 wwin
->old_border_width
= wattribs
.border_width
;
643 wwin
->event_mask
= CLIENT_EVENTS
;
644 attribs
.event_mask
= CLIENT_EVENTS
;
645 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
646 attribs
.save_under
= False
;
647 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
648 |CWSaveUnder
, &attribs
);
649 XSetWindowBorderWidth(dpy
, window
, 0);
651 /* get hints from GNUstep app */
652 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
653 wwin
->flags
.is_gnustep
= 1;
655 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
656 wwin
->wm_gnustep_attr
= NULL
;
659 wwin
->client_leader
= PropGetClientLeader(window
);
660 if (wwin
->client_leader
!=None
)
661 wwin
->main_window
= wwin
->client_leader
;
663 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
665 if (wwin
->wm_hints
) {
666 if (wwin
->wm_hints
->flags
& StateHint
) {
668 if (wwin
->wm_hints
->initial_state
== IconicState
) {
670 wwin
->flags
.miniaturized
= 1;
672 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
678 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
679 wwin
->group_id
= wwin
->wm_hints
->window_group
;
680 /* window_group has priority over CLIENT_LEADER */
681 wwin
->main_window
= wwin
->group_id
;
683 wwin
->group_id
= None
;
686 if (wwin
->wm_hints
->flags
& UrgencyHint
)
687 wwin
->flags
.urgent
= 1;
689 wwin
->group_id
= None
;
692 PropGetProtocols(window
, &wwin
->protocols
);
694 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
695 wwin
->transient_for
= None
;
697 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
698 wwin
->transient_for
= scr
->root_win
;
700 transientOwner
= wWindowFor(wwin
->transient_for
);
701 if (transientOwner
&& transientOwner
->main_window
!=None
) {
702 wwin
->main_window
= transientOwner
->main_window
;
704 wwin->main_window = None;
709 /* guess the focus mode */
710 wwin
->focus_mode
= getFocusMode(wwin
);
712 /* get geometry stuff */
713 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
715 /* get colormap windows */
716 GetColormapWindows(wwin
);
719 *--------------------------------------------------
721 * Setup the decoration/window attributes and
724 *--------------------------------------------------
727 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
730 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
731 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
733 transientOwner
= wWindowFor(wwin
->group_id
);
735 if (transientOwner
) {
736 wwin
->transient_for
= wwin
->group_id
;
738 /* transients can't be iconified or maximized */
739 if (wwin
->transient_for
) {
740 WSETUFLAG(wwin
, no_miniaturizable
, 1);
741 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
745 #endif /* OLWM_HINTS */
748 * Make broken apps behave as a nice app.
750 if (WFLAGP(wwin
, emulate_appicon
)) {
751 wwin
->main_window
= wwin
->client_win
;
755 *------------------------------------------------------------
757 * Setup the initial state of the window
759 *------------------------------------------------------------
762 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
763 wwin
->flags
.miniaturized
= 1;
766 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
767 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
775 bla
= wGNOMECheckInitialClientState(wwin
);
779 wKWMCheckClientInitialState(wwin
);
783 /* apply previous state if it exists and we're in startup */
784 if (scr
->flags
.startup
&& wm_state
>= 0) {
786 if (wm_state
== IconicState
) {
788 wwin
->flags
.miniaturized
= 1;
790 } else if (wm_state
== WithdrawnState
) {
796 /* if there is a saved state (from file), restore it */
798 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
799 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
801 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
803 if (win_state
&& !withdraw
) {
805 if (win_state
->state
->hidden
>0)
806 wwin
->flags
.hidden
= win_state
->state
->hidden
;
808 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
809 wwin
->flags
.shaded
= win_state
->state
->shaded
;
811 if (win_state
->state
->miniaturized
>0 &&
812 !WFLAGP(wwin
, no_miniaturizable
)) {
813 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
816 if (!IS_OMNIPRESENT(wwin
)) {
817 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
819 if (w
< 0 || w
>= scr
->workspace_count
) {
820 workspace
= win_state
->state
->workspace
;
821 if (workspace
>= scr
->workspace_count
)
822 workspace
= scr
->current_workspace
;
827 workspace
= scr
->current_workspace
;
831 /* if we're restarting, restore saved state (from hints).
832 * This will overwrite previous */
836 if (getSavedState(window
, &wstate
)) {
837 wwin
->flags
.shaded
= wstate
->shaded
;
838 wwin
->flags
.hidden
= wstate
->hidden
;
839 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
840 wwin
->flags
.maximized
= wstate
->maximized
;
841 if (wwin
->flags
.maximized
) {
842 wwin
->old_geometry
.x
= wstate
->x
;
843 wwin
->old_geometry
.y
= wstate
->y
;
844 wwin
->old_geometry
.width
= wstate
->w
;
845 wwin
->old_geometry
.height
= wstate
->h
;
848 workspace
= wstate
->workspace
;
853 /* restore window shortcut */
854 if (wstate
!= NULL
|| win_state
!= NULL
) {
857 if (win_state
!= NULL
)
858 mask
= win_state
->state
->window_shortcuts
;
860 if (wstate
!= NULL
&& mask
== 0)
861 mask
= wstate
->window_shortcuts
;
866 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
868 if (!scr
->shortcutWindows
[i
])
869 scr
->shortcutWindows
[i
] = WMCreateArray(4);
871 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
876 if (wstate
!= NULL
) {
881 /* don't let transients start miniaturized if their owners are not */
882 if (transientOwner
&& !transientOwner
->flags
.miniaturized
883 && wwin
->flags
.miniaturized
&& !withdraw
) {
884 wwin
->flags
.miniaturized
= 0;
886 wwin
->wm_hints
->initial_state
= NormalState
;
889 /* set workspace on which the window starts */
890 if (workspace
>= 0) {
891 if (workspace
> scr
->workspace_count
-1) {
892 workspace
= workspace
% scr
->workspace_count
;
897 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
899 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
904 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
906 workspace
= transientOwner
->frame
->workspace
;
910 workspace
= scr
->current_workspace
;
915 /* setup window geometry */
916 if (win_state
&& win_state
->state
->w
> 0) {
917 width
= win_state
->state
->w
;
918 height
= win_state
->state
->h
;
920 wWindowConstrainSize(wwin
, &width
, &height
);
922 /* do not ask for window placement if the window is
923 * transient, during startup, if the initial workspace is another one
924 * or if the window wants to start iconic.
925 * If geometry was saved, restore it. */
927 Bool dontBring
= False
;
929 if (win_state
&& win_state
->state
->w
> 0) {
930 x
= win_state
->state
->x
;
931 y
= win_state
->state
->y
;
932 } else if ((wwin
->transient_for
==None
933 || wPreferences
.window_placement
!=WPM_MANUAL
)
934 && !scr
->flags
.startup
935 && workspace
== scr
->current_workspace
936 && !wwin
->flags
.miniaturized
937 && !wwin
->flags
.maximized
938 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
940 if (transientOwner
&& transientOwner
->flags
.mapped
) {
941 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
943 x
= transientOwner
->frame_x
+
944 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
945 y
= transientOwner
->frame_y
+
946 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
950 else if (x
+ width
> scr
->scr_width
)
951 x
= scr
->scr_width
- width
;
955 else if (y
+ height
> scr
->scr_height
)
956 y
= scr
->scr_height
- height
;
958 PlaceWindow(wwin
, &x
, &y
, width
, height
);
960 if (wPreferences
.window_placement
== WPM_MANUAL
)
964 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
965 wScreenBringInside(scr
, &x
, &y
, width
, height
);
968 if (wwin
->flags
.urgent
) {
969 if (!IS_OMNIPRESENT(wwin
))
970 wwin
->flags
.omnipresent
^= 1;
974 *--------------------------------------------------
976 * Create frame, borders and do reparenting
978 *--------------------------------------------------
980 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
981 #ifdef XKB_BUTTON_HINT
982 if (wPreferences
.modelock
)
983 foo
|= WFF_LANGUAGE_BUTTON
;
985 if (!WFLAGP(wwin
, no_titlebar
))
987 if (!WFLAGP(wwin
, no_resizebar
))
988 foo
|= WFF_RESIZEBAR
;
989 if (!WFLAGP(wwin
, no_border
))
992 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
994 &wPreferences
.window_title_clearance
, foo
,
995 scr
->window_title_texture
,
996 scr
->resizebar_texture
,
997 scr
->window_title_pixel
,
998 &scr
->window_title_gc
,
1001 wwin
->frame
->flags
.is_client_window_frame
= 1;
1002 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1004 /* setup button images */
1005 wWindowUpdateButtonImages(wwin
);
1007 /* hide unused buttons */
1009 if (WFLAGP(wwin
, no_close_button
))
1010 foo
|= WFF_RIGHT_BUTTON
;
1011 if (WFLAGP(wwin
, no_miniaturize_button
))
1012 foo
|= WFF_LEFT_BUTTON
;
1013 #ifdef XKB_BUTTON_HINT
1014 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1015 foo
|= WFF_LANGUAGE_BUTTON
;
1018 wFrameWindowHideButton(wwin
->frame
, foo
);
1020 wwin
->frame
->child
= wwin
;
1023 /* emulate olwm push pin. Make the button look as pushed-in for
1024 * the pinned-out state. When the button is clicked, it will
1025 * revert to the normal position, which means the pin is pinned-in.
1027 if (wwin
->flags
.olwm_push_pin_out
)
1028 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1029 #endif /* OLWM_HINTS */
1032 wwin
->frame
->workspace
= workspace
;
1034 wwin
->frame
->on_click_left
= windowIconifyClick
;
1035 #ifdef XKB_BUTTON_HINT
1036 if (wPreferences
.modelock
)
1037 wwin
->frame
->on_click_language
= windowLanguageClick
;
1040 wwin
->frame
->on_click_right
= windowCloseClick
;
1041 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1043 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1044 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1046 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1049 XSelectInput(dpy
, wwin
->client_win
,
1050 wwin
->event_mask
& ~StructureNotifyMask
);
1052 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1053 0, wwin
->frame
->top_width
);
1055 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1061 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1063 /* if gravity is to the south, account for the border sizes */
1065 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1069 * wWindowConfigure() will init the client window's size
1070 * (wwin->client.{width,height}) and all other geometry
1071 * related variables (frame_x,frame_y)
1073 wWindowConfigure(wwin
, x
, y
, width
, height
);
1075 /* to make sure the window receives it's new position after reparenting */
1076 wWindowSynthConfigureNotify(wwin
);
1079 *--------------------------------------------------
1081 * Setup descriptors and save window to internal
1084 *--------------------------------------------------
1087 if (wwin
->main_window
!=None
) {
1091 /* Leader windows do not necessary set themselves as leaders.
1092 * If this is the case, point the leader of this window to
1094 leader
= wWindowFor(wwin
->main_window
);
1095 if (leader
&& leader
->main_window
==None
) {
1096 leader
->main_window
= leader
->client_win
;
1098 app
= wApplicationCreate(scr
, wwin
->main_window
);
1100 app
->last_workspace
= workspace
;
1103 * Do application specific stuff, like setting application
1107 if (wwin
->flags
.hidden
) {
1108 /* if the window was set to hidden because it was hidden
1109 * in a previous incarnation and that state was restored */
1110 app
->flags
.hidden
= 1;
1111 } else if (app
->flags
.hidden
) {
1112 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1113 wwin
->flags
.hidden
= 1;
1115 wUnhideApplication(app
, False
, False
);
1122 /* setup the frame descriptor */
1123 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1124 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1125 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1127 /* don't let windows go away if we die */
1128 XAddToSaveSet(dpy
, window
);
1130 XLowerWindow(dpy
, window
);
1132 /* if window is in this workspace and should be mapped, then map it */
1133 if (!wwin
->flags
.miniaturized
1134 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1135 && !wwin
->flags
.hidden
&& !withdraw
) {
1137 /* The following "if" is to avoid crashing of clients that expect
1138 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1139 * after the return from this function.
1141 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1142 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1144 wClientSetState(wwin
, NormalState
, None
);
1148 /* if not auto focus, then map the window under the currently
1150 #define _WIDTH(w) (w)->frame->core->width
1151 #define _HEIGHT(w) (w)->frame->core->height
1152 if (!wPreferences
.auto_focus
&& scr
->focused_window
1153 && !scr
->flags
.startup
&& !transientOwner
1154 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1155 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1156 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1157 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1158 || wwin
->flags
.maximized
)) {
1159 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1167 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1168 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1170 * The brain damaged idiotic non-click to focus modes will
1171 * have trouble with this because:
1173 * 1. window is created and mapped by the client
1174 * 2. window is mapped by wmaker in small size
1175 * 3. window is animated to grow to normal size
1176 * 4. this function returns to normal event loop
1177 * 5. eventually, the EnterNotify event that would trigger
1178 * the window focusing (if the mouse is over that window)
1179 * will be processed by wmaker.
1180 * But since this event will be rather delayed
1181 * (step 3 has a large delay) the time when the event ocurred
1182 * and when it is processed, the client that owns that window
1183 * will reject the XSetInputFocus() for it.
1185 && (wPreferences
.focus_mode
==WKF_CLICK
1186 || wPreferences
.auto_focus
)) {
1187 DoWindowBirth(wwin
);
1193 /* setup stacking descriptor */
1194 if (transientOwner
) {
1195 /* && wPreferences.on_top_transients */
1196 if (transientOwner
) {
1197 wwin
->frame
->core
->stacking
->child_of
=
1198 transientOwner
->frame
->core
;
1201 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1205 if (!scr
->focused_window
) {
1206 /* first window on the list */
1209 scr
->focused_window
= wwin
;
1213 /* add window at beginning of focus window list */
1214 tmp
= scr
->focused_window
;
1222 /* raise is set to true if we un-hid the app when this window was born.
1223 * we raise, else old windows of this app will be above this new one. */
1225 wRaiseFrame(wwin
->frame
->core
);
1228 /* Update name must come after WApplication stuff is done */
1229 wWindowUpdateName(wwin
, title
);
1236 *--------------------------------------------------
1238 * Final preparations before window is ready to go
1240 *--------------------------------------------------
1243 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1246 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1247 && !wwin
->flags
.hidden
) {
1248 if (((transientOwner
&& transientOwner
->flags
.focused
)
1249 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1250 wSetFocusTo(scr
, wwin
);
1252 wWindowResetMouseGrabs(wwin
);
1254 if (!WFLAGP(wwin
, no_bind_keys
)) {
1255 wWindowSetKeyGrabs(wwin
);
1259 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1262 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1266 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1267 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1269 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1270 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1276 *------------------------------------------------------------
1277 * Setup Notification Observers
1278 *------------------------------------------------------------
1280 WMAddNotificationObserver(appearanceObserver
, wwin
,
1281 WNWindowAppearanceSettingsChanged
, wwin
);
1285 *--------------------------------------------------
1287 * Cleanup temporary stuff
1289 *--------------------------------------------------
1293 wWindowDeleteSavedState(win_state
);
1295 /* If the window must be withdrawed, then do it now.
1296 * Must do some optimization, 'though */
1298 wwin
->flags
.mapped
= 0;
1299 wClientSetState(wwin
, WithdrawnState
, None
);
1300 wUnmanageWindow(wwin
, True
, False
);
1312 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1313 char *title
, int x
, int y
, int width
, int height
)
1318 wwin
= wWindowCreate();
1320 WMAddNotificationObserver(appearanceObserver
, wwin
,
1321 WNWindowAppearanceSettingsChanged
, wwin
);
1323 wwin
->flags
.internal_window
= 1;
1325 WSETUFLAG(wwin
, omnipresent
, 1);
1326 WSETUFLAG(wwin
, no_shadeable
, 1);
1327 WSETUFLAG(wwin
, no_resizable
, 1);
1328 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1330 wwin
->focus_mode
= WFM_PASSIVE
;
1332 wwin
->client_win
= window
;
1333 wwin
->screen_ptr
= scr
;
1335 wwin
->transient_for
= owner
;
1339 wwin
->client
.width
= width
;
1340 wwin
->client
.height
= height
;
1342 wwin
->frame_x
= wwin
->client
.x
;
1343 wwin
->frame_y
= wwin
->client
.y
;
1346 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1347 foo
|= WFF_TITLEBAR
;
1348 #ifdef XKB_BUTTON_HINT
1349 foo
|= WFF_LANGUAGE_BUTTON
;
1352 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1353 wwin
->frame_x
, wwin
->frame_y
,
1355 &wPreferences
.window_title_clearance
, foo
,
1356 scr
->window_title_texture
,
1357 scr
->resizebar_texture
,
1358 scr
->window_title_pixel
,
1359 &scr
->window_title_gc
,
1362 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1364 wwin
->frame
->flags
.is_client_window_frame
= 1;
1365 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1367 wFrameWindowChangeTitle(wwin
->frame
, title
);
1369 /* setup button images */
1370 wWindowUpdateButtonImages(wwin
);
1373 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1375 wwin
->frame
->child
= wwin
;
1377 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1379 #ifdef XKB_BUTTON_HINT
1380 if (wPreferences
.modelock
)
1381 wwin
->frame
->on_click_language
= windowLanguageClick
;
1384 wwin
->frame
->on_click_right
= windowCloseClick
;
1386 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1387 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1389 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1391 wwin
->client
.y
+= wwin
->frame
->top_width
;
1392 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1393 0, wwin
->frame
->top_width
);
1395 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1396 wwin
->client
.width
, wwin
->client
.height
);
1398 /* setup the frame descriptor */
1399 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1400 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1401 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1404 XLowerWindow(dpy
, window
);
1405 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1407 /* setup stacking descriptor */
1410 wPreferences
.on_top_transients
&&
1412 wwin
->transient_for
!=None
1413 && wwin
->transient_for
!=scr
->root_win
) {
1415 tmp
= wWindowFor(wwin
->transient_for
);
1417 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1419 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1423 if (!scr
->focused_window
) {
1424 /* first window on the list */
1427 scr
->focused_window
= wwin
;
1431 /* add window at beginning of focus window list */
1432 tmp
= scr
->focused_window
;
1440 if (wwin
->flags
.is_gnustep
== 0)
1441 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1443 /* if (wPreferences.auto_focus)*/
1444 wSetFocusTo(scr
, wwin
);
1446 wWindowResetMouseGrabs(wwin
);
1448 wWindowSetKeyGrabs(wwin
);
1455 *----------------------------------------------------------------------
1457 * Removes the frame window from a window and destroys all data
1458 * related to it. The window will be reparented back to the root window
1459 * if restore is True.
1462 * Everything related to the window is destroyed and the window
1463 * is removed from the window lists. Focus is set to the previous on the
1465 *----------------------------------------------------------------------
1468 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1470 WCoreWindow
*frame
= wwin
->frame
->core
;
1471 WWindow
*owner
= NULL
;
1472 WWindow
*newFocusedWindow
= NULL
;
1474 WScreen
*scr
= wwin
->screen_ptr
;
1477 /* First close attribute editor window if open */
1478 if (wwin
->flags
.inspector_open
) {
1479 wCloseInspectorForWindow(wwin
);
1482 /* Close window menu if it's open for this window */
1483 if (wwin
->flags
.menu_open_for_me
) {
1484 CloseWindowMenu(scr
);
1488 if (!wwin
->flags
.internal_window
)
1489 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1491 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1493 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1494 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1497 XUnmapWindow(dpy
, frame
->window
);
1499 XUnmapWindow(dpy
, wwin
->client_win
);
1501 /* deselect window */
1502 wSelectWindow(wwin
, False
);
1504 /* remove all pending events on window */
1505 /* I think this only matters for autoraise */
1506 if (wPreferences
.raise_delay
)
1507 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1511 /* reparent the window back to the root */
1513 wClientRestore(wwin
);
1515 if (wwin
->transient_for
!=scr
->root_win
) {
1516 owner
= wWindowFor(wwin
->transient_for
);
1518 if (!owner
->flags
.semi_focused
) {
1521 owner
->flags
.semi_focused
= 0;
1526 wasFocused
= wwin
->flags
.focused
;
1528 /* remove from window focus list */
1529 if (!wwin
->prev
&& !wwin
->next
) {
1530 /* was the only window */
1531 scr
->focused_window
= NULL
;
1532 newFocusedWindow
= NULL
;
1537 wwin
->prev
->next
= wwin
->next
;
1539 wwin
->next
->prev
= wwin
->prev
;
1541 scr
->focused_window
= wwin
->prev
;
1542 scr
->focused_window
->next
= NULL
;
1545 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1547 /* if in click to focus mode and the window
1548 * was a transient, focus the owner window
1551 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1552 tmp
= wWindowFor(wwin
->transient_for
);
1553 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1557 /* otherwise, focus the next one in the focus list */
1559 tmp
= scr
->focused_window
;
1560 while (tmp
) { /* look for one in the window list first */
1561 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1562 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1566 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1567 tmp
= scr
->focused_window
;
1569 if (!WFLAGP(tmp
, no_focusable
)
1570 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1577 newFocusedWindow
= tmp
;
1579 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1584 /* This is to let the root window get the keyboard input
1585 * if Sloppy focus mode and no other window get focus.
1586 * This way keybindings will not freeze.
1589 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1590 &foo
, &foo
, &foo
, &foo
, &mask
))
1591 tmp
= wWindowFor(win
);
1594 newFocusedWindow
= tmp
;
1596 newFocusedWindow
= NULL
;
1600 if (!wwin
->flags
.internal_window
) {
1601 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1605 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1606 (unsigned)frame
->window
);
1610 if (newFocusedWindow
!= owner
&& owner
) {
1611 if (wwin
->flags
.is_gnustep
== 0)
1612 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1614 wSetFocusTo(scr
, newFocusedWindow
);
1616 wWindowDestroy(wwin
);
1622 wWindowMap(WWindow
*wwin
)
1624 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1625 if (!wwin
->flags
.shaded
) {
1626 /* window will be remapped when getting MapNotify */
1627 XSelectInput(dpy
, wwin
->client_win
,
1628 wwin
->event_mask
& ~StructureNotifyMask
);
1629 XMapWindow(dpy
, wwin
->client_win
);
1630 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1632 wwin
->flags
.mapped
= 1;
1638 wWindowUnmap(WWindow
*wwin
)
1640 wwin
->flags
.mapped
= 0;
1642 /* prevent window withdrawal when getting UnmapNotify */
1643 XSelectInput(dpy
, wwin
->client_win
,
1644 wwin
->event_mask
& ~StructureNotifyMask
);
1645 XUnmapWindow(dpy
, wwin
->client_win
);
1646 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1648 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1654 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1659 #ifdef KEEP_XKB_LOCK_STATUS
1660 if (wPreferences
.modelock
) {
1661 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1663 #endif /* KEEP_XKB_LOCK_STATUS */
1665 wwin
->flags
.semi_focused
= 0;
1667 if (wwin
->flags
.is_gnustep
== 0)
1668 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1670 wwin
->flags
.focused
= 1;
1672 wWindowResetMouseGrabs(wwin
);
1674 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)True
);
1676 if (owin
== wwin
|| !owin
)
1679 nowner
= wWindowFor(wwin
->transient_for
);
1681 /* new window is a transient for the old window */
1682 if (nowner
== owin
) {
1683 owin
->flags
.semi_focused
= 1;
1684 wWindowUnfocus(nowner
);
1688 oowner
= wWindowFor(owin
->transient_for
);
1690 /* new window is owner of old window */
1691 if (wwin
== oowner
) {
1692 wWindowUnfocus(owin
);
1697 wWindowUnfocus(owin
);
1701 /* new window has same owner of old window */
1702 if (oowner
== nowner
) {
1703 /* prevent unfocusing of owner */
1704 oowner
->flags
.semi_focused
= 0;
1705 wWindowUnfocus(owin
);
1706 oowner
->flags
.semi_focused
= 1;
1711 /* nowner != NULL && oowner != nowner */
1712 nowner
->flags
.semi_focused
= 1;
1713 wWindowUnfocus(nowner
);
1714 wWindowUnfocus(owin
);
1719 wWindowUnfocus(WWindow
*wwin
)
1721 CloseWindowMenu(wwin
->screen_ptr
);
1723 if (wwin
->flags
.is_gnustep
== 0)
1724 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1725 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1727 if (wwin
->transient_for
!=None
1728 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1730 owner
= wWindowFor(wwin
->transient_for
);
1731 if (owner
&& owner
->flags
.semi_focused
) {
1732 owner
->flags
.semi_focused
= 0;
1733 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1734 wWindowUnfocus(owner
);
1735 wFrameWindowPaint(owner
->frame
);
1739 wwin
->flags
.focused
= 0;
1741 wWindowResetMouseGrabs(wwin
);
1743 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)False
);
1748 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1750 WApplication
*app
= wApplicationOf(wwin
->main_window
);
1752 char prefix
[32] = "";
1759 instIndex
= wApplicationIndexOfGroup(app
);
1762 wwin
->flags
.wm_name_changed
= 1;
1765 /* the hint was removed */
1766 title
= DEF_WINDOW_TITLE
;
1768 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1773 #ifndef NO_WINDOW_ENUMERATOR
1774 if (instIndex
> 0) {
1775 snprintf(prefix
, sizeof(prefix
), " [%i]", instIndex
);
1777 title
= wstrconcat(title
, prefix
);
1781 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1783 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1786 #ifndef NO_WINDOW_ENUMERATOR
1796 *----------------------------------------------------------------------
1798 * wWindowConstrainSize--
1799 * Constrains size for the client window, taking the maximal size,
1800 * window resize increments and other size hints into account.
1803 * The closest size to what was given that the client window can
1806 *----------------------------------------------------------------------
1809 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1811 int width
= *nwidth
;
1812 int height
= *nheight
;
1815 int minW
= 1, minH
= 1;
1816 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1817 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1818 int minAX
= -1, minAY
= -1;
1819 int maxAX
= -1, maxAY
= -1;
1823 if (wwin
->normal_hints
) {
1824 winc
= wwin
->normal_hints
->width_inc
;
1825 hinc
= wwin
->normal_hints
->height_inc
;
1826 minW
= wwin
->normal_hints
->min_width
;
1827 minH
= wwin
->normal_hints
->min_height
;
1828 maxW
= wwin
->normal_hints
->max_width
;
1829 maxH
= wwin
->normal_hints
->max_height
;
1830 if (wwin
->normal_hints
->flags
& PAspect
) {
1831 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1832 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1833 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1834 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1837 baseW
= wwin
->normal_hints
->base_width
;
1838 baseH
= wwin
->normal_hints
->base_height
;
1851 /* aspect ratio code borrowed from olwm */
1853 /* adjust max aspect ratio */
1854 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1855 if (maxAX
> maxAY
) {
1856 height
= (width
* maxAY
) / maxAX
;
1857 if (height
> maxH
) {
1859 width
= (height
* maxAX
) / maxAY
;
1862 width
= (height
* maxAX
) / maxAY
;
1865 height
= (width
* maxAY
) / maxAX
;
1870 /* adjust min aspect ratio */
1871 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1872 if (minAX
> minAY
) {
1873 height
= (width
* minAY
) / minAX
;
1874 if (height
< minH
) {
1876 width
= (height
* minAX
) / minAY
;
1879 width
= (height
* minAX
) / minAY
;
1882 height
= (width
* minAY
) / minAX
;
1889 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1891 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1895 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1897 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1900 /* broken stupid apps may cause preposterous values for these.. */
1909 wWindowCropSize(WWindow
*wwin
, int maxW
, int maxH
,
1910 int *width
, int *height
)
1912 int baseW
= 0, baseH
= 0;
1913 int winc
= 1, hinc
= 1;
1915 if (wwin
->normal_hints
) {
1916 baseW
= wwin
->normal_hints
->base_width
;
1917 baseH
= wwin
->normal_hints
->base_height
;
1919 winc
= wwin
->normal_hints
->width_inc
;
1920 hinc
= wwin
->normal_hints
->height_inc
;
1924 *width
= maxW
- (maxW
- baseW
) % winc
;
1927 *height
= maxH
- (maxH
- baseH
) % hinc
;
1932 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1934 WScreen
*scr
= wwin
->screen_ptr
;
1938 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1939 || workspace
== wwin
->frame
->workspace
)
1942 if (workspace
!= scr
->current_workspace
) {
1943 /* Sent to other workspace. Unmap window */
1944 if ((wwin
->flags
.mapped
1945 || wwin
->flags
.shaded
1946 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1947 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1949 wapp
= wApplicationOf(wwin
->main_window
);
1951 wapp
->last_workspace
= workspace
;
1953 if (wwin
->flags
.miniaturized
) {
1955 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1956 wwin
->icon
->mapped
= 0;
1960 wSetFocusTo(scr
, NULL
);
1964 /* brought to current workspace. Map window */
1965 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1967 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1968 wwin
->icon
->mapped
= 1;
1970 } else if (!wwin
->flags
.mapped
&&
1971 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1975 if (!IS_OMNIPRESENT(wwin
)) {
1976 int oldWorkspace
= wwin
->frame
->workspace
;
1978 wwin
->frame
->workspace
= workspace
;
1980 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void*)oldWorkspace
);
1990 wWindowSynthConfigureNotify(WWindow
*wwin
)
1994 sevent
.type
= ConfigureNotify
;
1995 sevent
.xconfigure
.display
= dpy
;
1996 sevent
.xconfigure
.event
= wwin
->client_win
;
1997 sevent
.xconfigure
.window
= wwin
->client_win
;
1999 sevent
.xconfigure
.x
= wwin
->client
.x
;
2000 sevent
.xconfigure
.y
= wwin
->client
.y
;
2001 sevent
.xconfigure
.width
= wwin
->client
.width
;
2002 sevent
.xconfigure
.height
= wwin
->client
.height
;
2004 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2005 if (WFLAGP(wwin
, no_titlebar
))
2006 sevent
.xconfigure
.above
= None
;
2008 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2010 sevent
.xconfigure
.override_redirect
= False
;
2011 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2013 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2020 *----------------------------------------------------------------------
2021 * wWindowConfigure--
2022 * Configures the frame, decorations and client window to the
2023 * specified geometry. The geometry is not checked for validity,
2024 * wWindowConstrainSize() must be used for that.
2025 * The size parameters are for the client window, but the position is
2027 * The client window receives a ConfigureNotify event, according
2028 * to what ICCCM says.
2034 * Window size and position are changed and client window receives
2035 * a ConfigureNotify event.
2036 *----------------------------------------------------------------------
2039 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2041 int req_x
, req_y
; /* new position of the frame */
2042 int req_width
, req_height
; /* new size of the client */
2044 int synth_notify
= False
;
2047 resize
= (req_width
!=wwin
->client
.width
2048 || req_height
!=wwin
->client
.height
);
2050 * if the window is being moved but not resized then
2051 * send a synthetic ConfigureNotify
2053 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2054 synth_notify
= True
;
2057 if (WFLAGP(wwin
, dont_move_off
))
2058 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2059 req_width
, req_height
);
2061 if (req_width
< MIN_WINDOW_SIZE
)
2062 req_width
= MIN_WINDOW_SIZE
;
2063 if (req_height
< MIN_WINDOW_SIZE
)
2064 req_height
= MIN_WINDOW_SIZE
;
2066 /* If growing, resize inner part before frame,
2067 * if shrinking, resize frame before.
2068 * This will prevent the frame (that can have a different color)
2069 * to be exposed, causing flicker */
2070 if (req_height
> wwin
->frame
->core
->height
2071 || req_width
> wwin
->frame
->core
->width
)
2072 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2074 if (wwin
->flags
.shaded
) {
2075 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2076 req_width
, wwin
->frame
->core
->height
);
2077 wwin
->old_geometry
.height
= req_height
;
2081 h
= req_height
+ wwin
->frame
->top_width
2082 + wwin
->frame
->bottom_width
;
2084 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2087 if (!(req_height
> wwin
->frame
->core
->height
2088 || req_width
> wwin
->frame
->core
->width
))
2089 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2091 wwin
->client
.x
= req_x
;
2092 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2093 wwin
->client
.width
= req_width
;
2094 wwin
->client
.height
= req_height
;
2096 wwin
->client
.x
= req_x
;
2097 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2099 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2101 wwin
->frame_x
= req_x
;
2102 wwin
->frame_y
= req_y
;
2103 if (!WFLAGP(wwin
, no_border
)) {
2104 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2105 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2109 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2110 wWindowSetShape(wwin
);
2115 wWindowSynthConfigureNotify(wwin
);
2121 wWindowMove(wwin
, req_x
, req_y
)
2123 int req_x
, req_y
; /* new position of the frame */
2125 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2126 int synth_notify
= False
;
2128 /* Send a synthetic ConfigureNotify event for every window movement. */
2129 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2130 synth_notify
= True
;
2133 /* A single synthetic ConfigureNotify event is sent at the end of
2134 * a completed (opaque) movement in moveres.c */
2137 if (WFLAGP(wwin
, dont_move_off
))
2138 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2139 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2141 wwin
->client
.x
= req_x
;
2142 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2143 if (!WFLAGP(wwin
, no_border
)) {
2144 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2145 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2148 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2150 wwin
->frame_x
= req_x
;
2151 wwin
->frame_y
= req_y
;
2153 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2155 wWindowSynthConfigureNotify(wwin
);
2161 wWindowUpdateButtonImages(WWindow
*wwin
)
2163 WScreen
*scr
= wwin
->screen_ptr
;
2164 Pixmap pixmap
, mask
;
2165 WFrameWindow
*fwin
= wwin
->frame
;
2167 if (WFLAGP(wwin
, no_titlebar
))
2170 /* miniaturize button */
2172 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2173 if (wwin
->wm_gnustep_attr
2174 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2175 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2177 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2178 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2183 if (fwin
->lbutton_image
2184 && (fwin
->lbutton_image
->image
!= pixmap
2185 || fwin
->lbutton_image
->mask
!= mask
)) {
2186 wPixmapDestroy(fwin
->lbutton_image
);
2187 fwin
->lbutton_image
= NULL
;
2190 if (!fwin
->lbutton_image
) {
2191 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2192 fwin
->lbutton_image
->client_owned
= 1;
2193 fwin
->lbutton_image
->client_owned_mask
= 1;
2196 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2197 wPixmapDestroy(fwin
->lbutton_image
);
2199 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2203 #ifdef XKB_BUTTON_HINT
2204 if (!WFLAGP(wwin
, no_language_button
)) {
2205 if (fwin
->languagebutton_image
&&
2206 !fwin
->languagebutton_image
->shared
) {
2207 wPixmapDestroy(fwin
->languagebutton_image
);
2209 fwin
->languagebutton_image
=
2210 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2216 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2217 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2219 if (!WFLAGP(wwin
, no_close_button
)) {
2220 if (wwin
->wm_gnustep_attr
2221 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2222 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2224 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2225 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2229 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2230 || fwin
->rbutton_image
->mask
!= mask
)) {
2231 wPixmapDestroy(fwin
->rbutton_image
);
2232 fwin
->rbutton_image
= NULL
;
2235 if (!fwin
->rbutton_image
) {
2236 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2237 fwin
->rbutton_image
->client_owned
= 1;
2238 fwin
->rbutton_image
->client_owned_mask
= 1;
2241 } else if (WFLAGP(wwin
, kill_close
)) {
2243 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2244 wPixmapDestroy(fwin
->rbutton_image
);
2246 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2248 } else if (MGFLAGP(wwin
, broken_close
)) {
2250 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2251 wPixmapDestroy(fwin
->rbutton_image
);
2253 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2257 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2258 wPixmapDestroy(fwin
->rbutton_image
);
2260 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2264 /* force buttons to be redrawn */
2265 fwin
->flags
.need_texture_change
= 1;
2266 wFrameWindowPaint(fwin
);
2271 *---------------------------------------------------------------------------
2272 * wWindowConfigureBorders--
2273 * Update window border configuration according to attribute flags.
2275 *---------------------------------------------------------------------------
2278 wWindowConfigureBorders(WWindow
*wwin
)
2284 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2285 #ifdef XKB_BUTTON_HINT
2286 flags
|= WFF_LANGUAGE_BUTTON
;
2288 if (!WFLAGP(wwin
, no_titlebar
))
2289 flags
|= WFF_TITLEBAR
;
2290 if (!WFLAGP(wwin
, no_resizebar
))
2291 flags
|= WFF_RESIZEBAR
;
2292 if (!WFLAGP(wwin
, no_border
))
2293 flags
|= WFF_BORDER
;
2294 if (wwin
->flags
.shaded
)
2295 flags
|= WFF_IS_SHADED
;
2297 oldh
= wwin
->frame
->top_width
;
2298 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2299 if (oldh
!= wwin
->frame
->top_width
) {
2300 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2302 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2303 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2304 wwin
->client
.width
, wwin
->client
.height
);
2308 if (!WFLAGP(wwin
, no_miniaturize_button
)
2309 && wwin
->frame
->flags
.hide_left_button
)
2310 flags
|= WFF_LEFT_BUTTON
;
2312 #ifdef XKB_BUTTON_HINT
2313 if (!WFLAGP(wwin
, no_language_button
)
2314 && wwin
->frame
->flags
.hide_language_button
)
2315 flags
|= WFF_LANGUAGE_BUTTON
;
2318 if (!WFLAGP(wwin
, no_close_button
)
2319 && wwin
->frame
->flags
.hide_right_button
)
2320 flags
|= WFF_RIGHT_BUTTON
;
2323 wWindowUpdateButtonImages(wwin
);
2324 wFrameWindowShowButton(wwin
->frame
, flags
);
2328 if (WFLAGP(wwin
, no_miniaturize_button
)
2329 && !wwin
->frame
->flags
.hide_left_button
)
2330 flags
|= WFF_LEFT_BUTTON
;
2332 #ifdef XKB_BUTTON_HINT
2333 if (WFLAGP(wwin
, no_language_button
)
2334 && !wwin
->frame
->flags
.hide_language_button
)
2335 flags
|= WFF_LANGUAGE_BUTTON
;
2338 if (WFLAGP(wwin
, no_close_button
)
2339 && !wwin
->frame
->flags
.hide_right_button
)
2340 flags
|= WFF_RIGHT_BUTTON
;
2343 wFrameWindowHideButton(wwin
->frame
, flags
);
2346 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2347 wWindowSetShape(wwin
);
2355 wWindowSaveState(WWindow
*wwin
)
2360 memset(data
, 0, sizeof(CARD32
)*10);
2361 data
[0] = wwin
->frame
->workspace
;
2362 data
[1] = wwin
->flags
.miniaturized
;
2363 data
[2] = wwin
->flags
.shaded
;
2364 data
[3] = wwin
->flags
.hidden
;
2365 data
[4] = wwin
->flags
.maximized
;
2366 if (wwin
->flags
.maximized
== 0) {
2367 data
[5] = wwin
->frame_x
;
2368 data
[6] = wwin
->frame_y
;
2369 data
[7] = wwin
->frame
->core
->width
;
2370 data
[8] = wwin
->frame
->core
->height
;
2372 data
[5] = wwin
->old_geometry
.x
;
2373 data
[6] = wwin
->old_geometry
.y
;
2374 data
[7] = wwin
->old_geometry
.width
;
2375 data
[8] = wwin
->old_geometry
.height
;
2378 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2379 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2380 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2383 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2384 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2385 (unsigned char *)data
, 10);
2390 getSavedState(Window window
, WSavedState
**state
)
2394 unsigned long nitems_ret
;
2395 unsigned long bytes_after_ret
;
2398 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2399 True
, _XA_WINDOWMAKER_STATE
,
2400 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2401 (unsigned char **)&data
)!=Success
|| !data
)
2404 *state
= wmalloc(sizeof(WSavedState
));
2406 (*state
)->workspace
= data
[0];
2407 (*state
)->miniaturized
= data
[1];
2408 (*state
)->shaded
= data
[2];
2409 (*state
)->hidden
= data
[3];
2410 (*state
)->maximized
= data
[4];
2411 (*state
)->x
= data
[5];
2412 (*state
)->y
= data
[6];
2413 (*state
)->w
= data
[7];
2414 (*state
)->h
= data
[8];
2415 (*state
)->window_shortcuts
= data
[9];
2419 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2428 wWindowClearShape(WWindow
*wwin
)
2430 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2431 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2436 wWindowSetShape(WWindow
*wwin
)
2440 #ifdef OPTIMIZE_SHAPE
2445 /* only shape is the client's */
2446 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2450 /* Get array of rectangles describing the shape mask */
2451 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2457 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2463 /* insert our decoration rectangles in the rect list */
2464 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2467 if (!WFLAGP(wwin
, no_titlebar
)) {
2469 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2470 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2471 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2474 if (!WFLAGP(wwin
, no_resizebar
)) {
2476 urec
[count
].y
= wwin
->frame
->core
->height
2477 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2478 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2479 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2483 /* shape our frame window */
2484 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2485 0, wwin
->frame
->top_width
, urec
, count
,
2486 ShapeSet
, Unsorted
);
2492 #endif /* OPTIMIZE_SHAPE */
2494 if (!WFLAGP(wwin
, no_titlebar
)) {
2497 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2498 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2501 if (!WFLAGP(wwin
, no_resizebar
)) {
2503 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2504 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2505 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2509 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2510 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2512 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2513 0, wwin
->frame
->top_width
, wwin
->client_win
,
2514 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2519 /* ====================================================================== */
2522 getFocusMode(WWindow
*wwin
)
2526 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2527 if (wwin
->wm_hints
->input
== True
) {
2528 if (wwin
->protocols
.TAKE_FOCUS
)
2529 mode
= WFM_LOCALLY_ACTIVE
;
2533 if (wwin
->protocols
.TAKE_FOCUS
)
2534 mode
= WFM_GLOBALLY_ACTIVE
;
2536 mode
= WFM_NO_INPUT
;
2546 wWindowSetKeyGrabs(WWindow
*wwin
)
2551 for (i
=0; i
<WKBD_LAST
; i
++) {
2552 key
= &wKeyBindings
[i
];
2554 if (key
->keycode
==0)
2556 if (key
->modifier
!=AnyModifier
) {
2557 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2558 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2560 /* Also grab all modifier combinations possible that include,
2561 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2562 * work even if the NumLock/ScrollLock key is on.
2564 wHackedGrabKey(key
->keycode
, key
->modifier
,
2565 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2569 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2570 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2574 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2581 wWindowResetMouseGrabs(WWindow
*wwin
)
2583 /* Mouse grabs can't be done on the client window because of
2584 * ICCCM and because clients that try to do the same will crash.
2586 * But there is a problem wich makes tbar buttons of unfocused
2587 * windows not usable as the click goes to the frame window instead
2588 * of the button itself. Must figure a way to fix that.
2591 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2593 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2594 /* grabs for Meta+drag */
2595 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2596 True
, ButtonPressMask
, GrabModeSync
,
2597 GrabModeAsync
, None
, None
);
2600 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2601 && !wwin
->flags
.is_gnustep
) {
2602 /* the passive grabs to focus the window */
2603 /* if (wPreferences.focus_mode == WKF_CLICK) */
2604 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2605 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2613 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2615 if (attr
->flags
& GSExtraFlagsAttr
) {
2616 if (MGFLAGP(wwin
, broken_close
) !=
2617 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2618 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2619 wWindowUpdateButtonImages(wwin
);
2626 wWindowAddSavedState(char *instance
, char *class, char *command
,
2627 pid_t pid
, WSavedState
*state
)
2629 WWindowState
*wstate
;
2631 wstate
= malloc(sizeof(WWindowState
));
2635 memset(wstate
, 0, sizeof(WWindowState
));
2638 wstate
->instance
= wstrdup(instance
);
2640 wstate
->class = wstrdup(class);
2642 wstate
->command
= wstrdup(command
);
2643 wstate
->state
= state
;
2645 wstate
->next
= windowState
;
2646 windowState
= wstate
;
2649 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2657 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2661 wWindowGetSavedState(Window win
)
2663 char *instance
, *class, *command
=NULL
;
2664 WWindowState
*wstate
= windowState
;
2671 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2673 command
= wtokenjoin(argv
, argc
);
2674 XFreeStringList(argv
);
2679 if (PropGetWMClass(win
, &class, &instance
)) {
2681 if (SAME(instance
, wstate
->instance
) &&
2682 SAME(class, wstate
->class) &&
2683 SAME(command
, wstate
->command
)) {
2686 wstate
= wstate
->next
;
2693 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2697 if (command
) wfree(command
);
2698 if (instance
) XFree(instance
);
2699 if (class) XFree(class);
2706 wWindowDeleteSavedState(WMagicNumber id
)
2708 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2710 if (!wstate
|| !windowState
)
2715 windowState
= wstate
->next
;
2717 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2718 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2720 if (wstate
->instance
) wfree(wstate
->instance
);
2721 if (wstate
->class) wfree(wstate
->class);
2722 if (wstate
->command
) wfree(wstate
->command
);
2723 wfree(wstate
->state
);
2727 if (tmp
->next
==wstate
) {
2728 tmp
->next
=wstate
->next
;
2730 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2731 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2733 if (wstate
->instance
) wfree(wstate
->instance
);
2734 if (wstate
->class) wfree(wstate
->class);
2735 if (wstate
->command
) wfree(wstate
->command
);
2736 wfree(wstate
->state
);
2747 wWindowDeleteSavedStatesForPID(pid_t pid
)
2749 WWindowState
*tmp
, *wstate
;
2755 if (tmp
->pid
== pid
) {
2756 wstate
= windowState
;
2757 windowState
= tmp
->next
;
2759 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2760 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2762 if (wstate
->instance
) wfree(wstate
->instance
);
2763 if (wstate
->class) wfree(wstate
->class);
2764 if (wstate
->command
) wfree(wstate
->command
);
2765 wfree(wstate
->state
);
2769 if (tmp
->next
->pid
==pid
) {
2771 tmp
->next
= wstate
->next
;
2773 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2774 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2776 if (wstate
->instance
) wfree(wstate
->instance
);
2777 if (wstate
->class) wfree(wstate
->class);
2778 if (wstate
->command
) wfree(wstate
->command
);
2779 wfree(wstate
->state
);
2790 wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2792 wwin
->flags
.omnipresent
= flag
;
2794 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2798 /* ====================================================================== */
2801 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2803 WWindow
*wwin
= data
;
2805 #ifndef NUMLOCK_HACK
2806 if ((event
->xbutton
.state
& ValidModMask
)
2807 != (event
->xbutton
.state
& ~LockMask
)) {
2808 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2809 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2813 event
->xbutton
.state
&= ValidModMask
;
2815 CloseWindowMenu(wwin
->screen_ptr
);
2817 if (wPreferences
.focus_mode
==WKF_CLICK
2818 && !(event
->xbutton
.state
&ControlMask
)
2819 && !WFLAGP(wwin
, no_focusable
)) {
2820 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2823 if (event
->xbutton
.button
== Button1
)
2824 wRaiseFrame(wwin
->frame
->core
);
2826 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2827 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2828 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2829 GrabModeAsync
, GrabModeAsync
, None
,
2830 None
, CurrentTime
)!=GrabSuccess
) {
2832 wwarning("pointer grab failed for window move");
2838 if (event
->xbutton
.state
& MOD_MASK
) {
2839 /* move the window */
2840 wMouseMoveWindow(wwin
, event
);
2841 XUngrabPointer(dpy
, CurrentTime
);
2843 wMouseResizeWindow(wwin
, event
);
2844 XUngrabPointer(dpy
, CurrentTime
);
2851 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2853 WWindow
*wwin
= data
;
2855 event
->xbutton
.state
&= ValidModMask
;
2857 if (event
->xbutton
.button
==Button1
) {
2858 if (event
->xbutton
.state
== 0) {
2859 if (!WFLAGP(wwin
, no_shadeable
)) {
2861 if (wwin
->flags
.shaded
)
2862 wUnshadeWindow(wwin
);
2869 if (event
->xbutton
.state
& ControlMask
)
2870 dir
|= MAX_VERTICAL
;
2872 if (event
->xbutton
.state
& ShiftMask
) {
2873 dir
|= MAX_HORIZONTAL
;
2874 if (!(event
->xbutton
.state
& ControlMask
))
2875 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2878 /* maximize window */
2879 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2880 int ndir
= dir
^ wwin
->flags
.maximized
;
2881 if (wwin
->flags
.maximized
!= 0)
2882 wUnmaximizeWindow(wwin
);
2884 wMaximizeWindow(wwin
, ndir
);
2887 } else if (event
->xbutton
.button
==Button3
) {
2888 if (event
->xbutton
.state
& MOD_MASK
) {
2889 wHideOtherApplications(wwin
);
2891 } else if (event
->xbutton
.button
==Button2
) {
2892 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2893 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2895 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2896 wUnshadeWindow(wwin
);
2902 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2904 WWindow
*wwin
= desc
->parent
;
2906 event
->xbutton
.state
&= ValidModMask
;
2908 CloseWindowMenu(wwin
->screen_ptr
);
2910 if (/*wPreferences.focus_mode==WKF_CLICK
2911 &&*/ !(event
->xbutton
.state
&ControlMask
)
2912 && !WFLAGP(wwin
, no_focusable
)) {
2913 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2915 if (event
->xbutton
.button
== Button1
) {
2916 wRaiseFrame(wwin
->frame
->core
);
2919 if (event
->xbutton
.state
& MOD_MASK
) {
2920 /* move the window */
2921 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2922 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2923 GrabModeAsync
, GrabModeAsync
, None
,
2924 None
, CurrentTime
)!=GrabSuccess
) {
2926 wwarning("pointer grab failed for window move");
2930 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2931 wMouseResizeWindow(wwin
, event
);
2933 wMouseMoveWindow(wwin
, event
);
2934 XUngrabPointer(dpy
, CurrentTime
);
2940 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2942 WWindow
*wwin
= (WWindow
*)data
;
2944 #ifndef NUMLOCK_HACK
2945 if ((event
->xbutton
.state
& ValidModMask
)
2946 != (event
->xbutton
.state
& ~LockMask
)) {
2947 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2948 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2951 event
->xbutton
.state
&= ValidModMask
;
2953 CloseWindowMenu(wwin
->screen_ptr
);
2955 if (wPreferences
.focus_mode
==WKF_CLICK
2956 && !(event
->xbutton
.state
&ControlMask
)
2957 && !WFLAGP(wwin
, no_focusable
)) {
2958 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2961 if (event
->xbutton
.button
== Button1
2962 || event
->xbutton
.button
== Button2
) {
2964 if (event
->xbutton
.button
== Button1
) {
2965 if (event
->xbutton
.state
& MOD_MASK
) {
2966 wLowerFrame(wwin
->frame
->core
);
2968 wRaiseFrame(wwin
->frame
->core
);
2971 if ((event
->xbutton
.state
& ShiftMask
)
2972 && !(event
->xbutton
.state
& ControlMask
)) {
2973 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2976 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2977 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2978 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2979 GrabModeAsync
, GrabModeAsync
, None
,
2980 None
, CurrentTime
)!=GrabSuccess
) {
2982 wwarning("pointer grab failed for window move");
2987 /* move the window */
2988 wMouseMoveWindow(wwin
, event
);
2990 XUngrabPointer(dpy
, CurrentTime
);
2991 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2992 && !wwin
->flags
.internal_window
2993 && !WCHECK_STATE(WSTATE_MODAL
)) {
2994 WObjDescriptor
*desc
;
2996 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2997 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2998 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2999 GrabModeAsync
, GrabModeAsync
, None
,
3000 None
, CurrentTime
)!=GrabSuccess
) {
3002 wwarning("pointer grab failed for window move");
3007 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
3008 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3010 /* allow drag select */
3011 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3012 event
->xany
.send_event
= True
;
3013 (*desc
->handle_mousedown
)(desc
, event
);
3015 XUngrabPointer(dpy
, CurrentTime
);
3022 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3024 WWindow
*wwin
= data
;
3026 event
->xbutton
.state
&= ValidModMask
;
3028 CloseWindowMenu(wwin
->screen_ptr
);
3030 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3033 /* if control-click, kill the client */
3034 if (event
->xbutton
.state
& ControlMask
) {
3038 if (wwin
->flags
.olwm_push_pin_out
) {
3040 wwin
->flags
.olwm_push_pin_out
= 0;
3042 wOLWMChangePushpinState(wwin
, True
);
3044 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3049 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3050 /* send delete message */
3051 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3058 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3060 WWindow
*wwin
= data
;
3062 CloseWindowMenu(wwin
->screen_ptr
);
3064 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3067 /* send delete message */
3068 if (wwin
->protocols
.DELETE_WINDOW
) {
3069 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3076 #ifdef XKB_BUTTON_HINT
3078 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3080 WWindow
*wwin
= data
;
3081 WFrameWindow
*fwin
= wwin
->frame
;
3082 WScreen
*scr
= fwin
->screen_ptr
;
3083 XkbStateRec staterec
;
3086 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3088 tl
= wwin
->frame
->languagemode
;
3089 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3090 wwin
->frame
->last_languagemode
= tl
;
3091 wSetFocusTo(scr
, wwin
);
3092 wwin
->frame
->languagebutton_image
=
3093 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3094 wwin
->frame
->languagemode
];
3095 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3096 if (event
->xbutton
.button
== Button3
)
3098 wRaiseFrame(fwin
->core
);
3104 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3106 WWindow
*wwin
= data
;
3108 event
->xbutton
.state
&= ValidModMask
;
3110 CloseWindowMenu(wwin
->screen_ptr
);
3112 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3115 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3116 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3120 if ((event
->xbutton
.state
& ControlMask
) ||
3121 (event
->xbutton
.button
== Button3
)) {
3123 wapp
= wApplicationOf(wwin
->main_window
);
3124 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3125 wHideApplication(wapp
);
3126 } else if (event
->xbutton
.state
==0) {
3127 wIconifyWindow(wwin
);