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
);
149 if(wwin
->flags
.shaded
) {
150 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
151 wwin
->frame
->top_width
- 1);
153 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
154 + wwin
->frame
->top_width
;
155 wWindowSynthConfigureNotify(wwin
);
158 if (flags
& WTextureSettings
) {
159 wwin
->frame
->flags
.need_texture_remake
= 1;
161 if (flags
& (WTextureSettings
| WColorSettings
)) {
162 if (wwin
->frame
->titlebar
)
163 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
165 wFrameWindowPaint(wwin
->frame
);
169 /************************************/
172 wWindowFor(Window window
)
174 WObjDescriptor
*desc
;
179 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
182 if (desc
->parent_type
==WCLASS_WINDOW
)
184 else if (desc
->parent_type
==WCLASS_FRAME
) {
185 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
186 if (frame
->flags
.is_client_window_frame
)
199 wwin
= wmalloc(sizeof(WWindow
));
202 memset(wwin
, 0, sizeof(WWindow
));
204 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
205 wwin
->client_descriptor
.parent
= wwin
;
206 wwin
->client_descriptor
.self
= wwin
;
207 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
214 wWindowDestroy(WWindow
*wwin
)
218 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
219 wwin
->screen_ptr
->cmap_window
= NULL
;
222 WMRemoveNotificationObserver(wwin
);
224 wwin
->flags
.destroyed
= 1;
226 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
227 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
230 WMRemoveFromBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
232 if (!WMGetBagItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
233 WMFreeBag(wwin
->screen_ptr
->shortcutWindows
[i
]);
234 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
238 if (wwin
->normal_hints
)
239 XFree(wwin
->normal_hints
);
242 XFree(wwin
->wm_hints
);
244 if (wwin
->wm_instance
)
245 XFree(wwin
->wm_instance
);
248 XFree(wwin
->wm_class
);
250 if (wwin
->wm_gnustep_attr
)
251 wfree(wwin
->wm_gnustep_attr
);
253 if (wwin
->cmap_windows
)
254 XFree(wwin
->cmap_windows
);
256 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
259 wFrameWindowDestroy(wwin
->frame
);
262 RemoveFromStackList(wwin
->icon
->core
);
263 wIconDestroy(wwin
->icon
);
264 if (wPreferences
.auto_arrange_icons
)
265 wArrangeIcons(wwin
->screen_ptr
, True
);
274 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
276 if (gs_hints
->flags
& GSWindowStyleAttr
) {
277 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
278 wwin
->client_flags
.no_border
= 1;
279 wwin
->client_flags
.no_titlebar
= 1;
280 wwin
->client_flags
.no_closable
= 1;
281 wwin
->client_flags
.no_miniaturizable
= 1;
282 wwin
->client_flags
.no_resizable
= 1;
283 wwin
->client_flags
.no_close_button
= 1;
284 wwin
->client_flags
.no_miniaturize_button
= 1;
285 wwin
->client_flags
.no_resizebar
= 1;
287 wwin
->client_flags
.no_close_button
=
288 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
290 wwin
->client_flags
.no_closable
=
291 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
293 wwin
->client_flags
.no_miniaturize_button
=
294 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
296 wwin
->client_flags
.no_miniaturizable
=
297 wwin
->client_flags
.no_miniaturize_button
;
299 wwin
->client_flags
.no_resizebar
=
300 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
302 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
304 /* these attributes supposedly imply in the existence
306 if (gs_hints
->window_style
& (WMResizableWindowMask
|
307 WMClosableWindowMask
|
308 WMMiniaturizableWindowMask
)) {
309 wwin
->client_flags
.no_titlebar
= 0;
311 wwin
->client_flags
.no_titlebar
=
312 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
317 /* setup the defaults */
318 wwin
->client_flags
.no_border
= 0;
319 wwin
->client_flags
.no_titlebar
= 0;
320 wwin
->client_flags
.no_closable
= 0;
321 wwin
->client_flags
.no_miniaturizable
= 0;
322 wwin
->client_flags
.no_resizable
= 0;
323 wwin
->client_flags
.no_close_button
= 0;
324 wwin
->client_flags
.no_miniaturize_button
= 0;
325 wwin
->client_flags
.no_resizebar
= 0;
327 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
328 wwin
->client_flags
.no_appicon
= 1;
334 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
335 WWindowAttributes
*mask
)
337 if (wflags
->no_appicon
&& mask
->no_appicon
)
338 wflags
->emulate_appicon
= 0;
340 if (wwin
->main_window
!=None
) {
341 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
342 if (wapp
&& !wapp
->flags
.emulated
)
343 wflags
->emulate_appicon
= 0;
346 if (wwin
->transient_for
!=None
347 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
348 wflags
->emulate_appicon
= 0;
350 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
357 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
359 WScreen
*scr
= wwin
->screen_ptr
;
361 /* sets global default stuff */
362 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
363 &wwin
->client_flags
, NULL
, True
);
365 * Decoration setting is done in this precedence (lower to higher)
366 * - use global default in the resource database
367 * - guess some settings
368 * - use GNUstep/external window attributes
369 * - set hints specified for the app in the resource DB
372 WSETUFLAG(wwin
, broken_close
, 0);
374 if (wwin
->protocols
.DELETE_WINDOW
)
375 WSETUFLAG(wwin
, kill_close
, 0);
377 WSETUFLAG(wwin
, kill_close
, 1);
379 /* transients can't be iconified or maximized */
380 if (wwin
->transient_for
) {
381 WSETUFLAG(wwin
, no_miniaturizable
, 1);
382 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
385 /* if the window can't be resized, remove the resizebar */
386 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
387 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
388 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
389 WSETUFLAG(wwin
, no_resizable
, 1);
390 WSETUFLAG(wwin
, no_resizebar
, 1);
393 /* set GNUstep window attributes */
394 if (wwin
->wm_gnustep_attr
) {
395 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
397 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
399 *level
= wwin
->wm_gnustep_attr
->window_level
;
401 * INT_MIN is the only illegal window level.
403 if (*level
== INT_MIN
)
404 *level
= INT_MIN
+ 1;
407 *level
= WMNormalLevel
;
410 int tmp_workspace
= -1;
417 wMWMCheckClientHints(wwin
);
418 #endif /* MWM_HINTS */
421 check
= wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
422 #endif /* GNOME_STUFF */
426 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
427 #endif /* KWM_HINTS */
430 wOLWMCheckClientHints(wwin
);
431 #endif /* OLWM_HINTS */
434 if (WFLAGP(wwin
, floating
))
435 *level
= WMFloatingLevel
;
436 else if (WFLAGP(wwin
, sunken
))
437 *level
= WMSunkenLevel
;
439 *level
= WMNormalLevel
;
444 if (tmp_workspace
>= 0) {
445 *workspace
= tmp_workspace
% scr
->workspace_count
;
450 * Set attributes specified only for that window/class.
451 * This might do duplicate work with the 1st wDefaultFillAttributes().
453 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
454 &wwin
->user_flags
, &wwin
->defined_user_flags
,
457 * Sanity checks for attributes that depend on other attributes
459 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
460 wwin
->user_flags
.emulate_appicon
= 0;
462 if (wwin
->main_window
!=None
) {
463 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
464 if (wapp
&& !wapp
->flags
.emulated
)
465 wwin
->user_flags
.emulate_appicon
= 0;
468 if (wwin
->transient_for
!=None
469 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
470 wwin
->user_flags
.emulate_appicon
= 0;
472 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
473 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
474 wwin
->user_flags
.sunken
= 0;
476 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
483 wWindowCanReceiveFocus(WWindow
*wwin
)
485 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
487 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
489 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
497 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
501 w1
= wwin
->frame
->core
->width
;
502 h1
= wwin
->frame
->core
->height
;
503 w2
= obscured
->frame
->core
->width
;
504 h2
= obscured
->frame
->core
->height
;
506 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
507 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
510 if (wwin
->frame_x
+ w1
< obscured
->frame_x
511 || wwin
->frame_y
+ h1
< obscured
->frame_y
512 || wwin
->frame_x
> obscured
->frame_x
+ w2
513 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
523 *----------------------------------------------------------------
525 * reparents the window and allocates a descriptor for it.
526 * Window manager hints and other hints are fetched to configure
527 * the window decoration attributes and others. User preferences
528 * for the window are used if available, to configure window
529 * decorations and some behaviour.
530 * If in startup, windows that are override redirect,
531 * unmapped and never were managed and are Withdrawn are not
535 * the new window descriptor
538 * The window is reparented and appropriate notification
539 * is done to the client. Input mask for the window is setup.
540 * The window descriptor is also associated with various window
541 * contexts and inserted in the head of the window list.
542 * Event handler contexts are associated for some objects
543 * (buttons, titlebar and resizebar)
545 *----------------------------------------------------------------
548 wManageWindow(WScreen
*scr
, Window window
)
552 unsigned width
, height
;
553 XWindowAttributes wattribs
;
554 XSetWindowAttributes attribs
;
555 WWindowState
*win_state
;
556 WWindow
*transientOwner
= NULL
;
562 Bool withdraw
= False
;
565 /* XGrabServer(dpy); */
567 /* make sure the window is still there */
568 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
573 /* if it's an override-redirect, ignore it */
574 if (wattribs
.override_redirect
) {
579 wm_state
= PropGetWindowState(window
);
581 /* if it's startup and the window is unmapped, don't manage it */
582 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
587 if (!wFetchName(dpy
, window
, &title
)) {
592 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
597 #endif /* KWM_HINTS */
600 wwin
= wWindowCreate();
602 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
605 printf("managing window %x\n", (unsigned)window
);
609 if (wShapeSupported
) {
614 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
615 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
616 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
617 wwin
->flags
.shaped
= b_shaped
;
622 *--------------------------------------------------
624 * Get hints and other information in properties
626 *--------------------------------------------------
628 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
630 /* setup descriptor */
631 wwin
->client_win
= window
;
632 wwin
->screen_ptr
= scr
;
634 wwin
->old_border_width
= wattribs
.border_width
;
636 wwin
->event_mask
= CLIENT_EVENTS
;
637 attribs
.event_mask
= CLIENT_EVENTS
;
638 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
639 attribs
.save_under
= False
;
640 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
641 |CWSaveUnder
, &attribs
);
642 XSetWindowBorderWidth(dpy
, window
, 0);
644 /* get hints from GNUstep app */
645 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
646 wwin
->flags
.is_gnustep
= 1;
648 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
649 wwin
->wm_gnustep_attr
= NULL
;
652 wwin
->client_leader
= PropGetClientLeader(window
);
653 if (wwin
->client_leader
!=None
)
654 wwin
->main_window
= wwin
->client_leader
;
656 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
658 if (wwin
->wm_hints
) {
659 if (wwin
->wm_hints
->flags
& StateHint
) {
661 if (wwin
->wm_hints
->initial_state
== IconicState
) {
663 wwin
->flags
.miniaturized
= 1;
665 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
671 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
672 wwin
->group_id
= wwin
->wm_hints
->window_group
;
673 /* window_group has priority over CLIENT_LEADER */
674 wwin
->main_window
= wwin
->group_id
;
676 wwin
->group_id
= None
;
679 if (wwin
->wm_hints
->flags
& UrgencyHint
)
680 wwin
->flags
.urgent
= 1;
682 wwin
->group_id
= None
;
685 PropGetProtocols(window
, &wwin
->protocols
);
687 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
688 wwin
->transient_for
= None
;
690 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
691 wwin
->transient_for
= scr
->root_win
;
693 transientOwner
= wWindowFor(wwin
->transient_for
);
694 if (transientOwner
&& transientOwner
->main_window
!=None
) {
695 wwin
->main_window
= transientOwner
->main_window
;
697 wwin->main_window = None;
702 /* guess the focus mode */
703 wwin
->focus_mode
= getFocusMode(wwin
);
705 /* get geometry stuff */
706 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
708 /* get colormap windows */
709 GetColormapWindows(wwin
);
712 *--------------------------------------------------
714 * Setup the decoration/window attributes and
717 *--------------------------------------------------
720 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
723 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
724 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
726 transientOwner
= wWindowFor(wwin
->group_id
);
728 if (transientOwner
) {
729 wwin
->transient_for
= wwin
->group_id
;
731 /* transients can't be iconified or maximized */
732 if (wwin
->transient_for
) {
733 WSETUFLAG(wwin
, no_miniaturizable
, 1);
734 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
738 #endif /* OLWM_HINTS */
741 * Make broken apps behave as a nice app.
743 if (WFLAGP(wwin
, emulate_appicon
)) {
744 wwin
->main_window
= wwin
->client_win
;
748 *------------------------------------------------------------
750 * Setup the initial state of the window
752 *------------------------------------------------------------
755 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
756 wwin
->flags
.miniaturized
= 1;
759 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
760 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
768 bla
= wGNOMECheckInitialClientState(wwin
);
772 wKWMCheckClientInitialState(wwin
);
776 /* apply previous state if it exists and we're in startup */
777 if (scr
->flags
.startup
&& wm_state
>= 0) {
779 if (wm_state
== IconicState
) {
781 wwin
->flags
.miniaturized
= 1;
783 } else if (wm_state
== WithdrawnState
) {
789 /* if there is a saved state (from file), restore it */
791 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
792 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
794 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
796 if (win_state
&& !withdraw
) {
798 if (win_state
->state
->hidden
>0)
799 wwin
->flags
.hidden
= win_state
->state
->hidden
;
801 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
802 wwin
->flags
.shaded
= win_state
->state
->shaded
;
804 if (win_state
->state
->miniaturized
>0 &&
805 !WFLAGP(wwin
, no_miniaturizable
)) {
806 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
809 if (!IS_OMNIPRESENT(wwin
)) {
810 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
812 if (w
< 0 || w
>= scr
->workspace_count
) {
813 workspace
= win_state
->state
->workspace
;
814 if (workspace
>= scr
->workspace_count
)
815 workspace
= scr
->current_workspace
;
820 workspace
= scr
->current_workspace
;
824 /* if we're restarting, restore saved state (from hints).
825 * This will overwrite previous */
829 if (getSavedState(window
, &wstate
)) {
830 wwin
->flags
.shaded
= wstate
->shaded
;
831 wwin
->flags
.hidden
= wstate
->hidden
;
832 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
833 wwin
->flags
.maximized
= wstate
->maximized
;
834 if (wwin
->flags
.maximized
) {
835 wwin
->old_geometry
.x
= wstate
->x
;
836 wwin
->old_geometry
.y
= wstate
->y
;
837 wwin
->old_geometry
.width
= wstate
->w
;
838 wwin
->old_geometry
.height
= wstate
->h
;
841 workspace
= wstate
->workspace
;
846 /* restore window shortcut */
847 if (wstate
!= NULL
|| win_state
!= NULL
) {
850 if (win_state
!= NULL
)
851 mask
= win_state
->state
->window_shortcuts
;
853 if (wstate
!= NULL
&& mask
== 0)
854 mask
= wstate
->window_shortcuts
;
859 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
861 if (!scr
->shortcutWindows
[i
])
862 scr
->shortcutWindows
[i
] = WMCreateBag(4);
864 WMPutInBag(scr
->shortcutWindows
[i
], wwin
);
869 if (wstate
!= NULL
) {
874 /* don't let transients start miniaturized if their owners are not */
875 if (transientOwner
&& !transientOwner
->flags
.miniaturized
876 && wwin
->flags
.miniaturized
&& !withdraw
) {
877 wwin
->flags
.miniaturized
= 0;
879 wwin
->wm_hints
->initial_state
= NormalState
;
882 /* set workspace on which the window starts */
883 if (workspace
>= 0) {
884 if (workspace
> scr
->workspace_count
-1) {
885 workspace
= workspace
% scr
->workspace_count
;
890 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
892 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
897 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
899 workspace
= transientOwner
->frame
->workspace
;
903 workspace
= scr
->current_workspace
;
908 /* setup window geometry */
909 if (win_state
&& win_state
->state
->w
> 0) {
910 width
= win_state
->state
->w
;
911 height
= win_state
->state
->h
;
913 wWindowConstrainSize(wwin
, &width
, &height
);
915 /* do not ask for window placement if the window is
916 * transient, during startup, if the initial workspace is another one
917 * or if the window wants to start iconic.
918 * If geometry was saved, restore it. */
920 Bool dontBring
= False
;
922 if (win_state
&& win_state
->state
->w
> 0) {
923 x
= win_state
->state
->x
;
924 y
= win_state
->state
->y
;
925 } else if ((wwin
->transient_for
==None
926 || wPreferences
.window_placement
!=WPM_MANUAL
)
927 && !scr
->flags
.startup
928 && workspace
== scr
->current_workspace
929 && !wwin
->flags
.miniaturized
930 && !wwin
->flags
.maximized
931 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
933 if (transientOwner
&& transientOwner
->flags
.mapped
) {
934 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
936 x
= transientOwner
->frame_x
+
937 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
938 y
= transientOwner
->frame_y
+
939 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
943 else if (x
+ width
> scr
->scr_width
)
944 x
= scr
->scr_width
- width
;
948 else if (y
+ height
> scr
->scr_height
)
949 y
= scr
->scr_height
- height
;
951 PlaceWindow(wwin
, &x
, &y
, width
, height
);
953 if (wPreferences
.window_placement
== WPM_MANUAL
)
957 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
958 wScreenBringInside(scr
, &x
, &y
, width
, height
);
961 if (wwin
->flags
.urgent
) {
962 if (!IS_OMNIPRESENT(wwin
))
963 wwin
->flags
.omnipresent
^= 1;
967 *--------------------------------------------------
969 * Create frame, borders and do reparenting
971 *--------------------------------------------------
973 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
974 #ifdef XKB_BUTTON_HINT
975 if (wPreferences
.modelock
)
976 foo
|= WFF_LANGUAGE_BUTTON
;
978 if (!WFLAGP(wwin
, no_titlebar
))
980 if (!WFLAGP(wwin
, no_resizebar
))
981 foo
|= WFF_RESIZEBAR
;
982 if (!WFLAGP(wwin
, no_border
))
985 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
987 &wPreferences
.window_title_clearance
, foo
,
988 scr
->window_title_texture
,
989 scr
->resizebar_texture
,
990 scr
->window_title_pixel
,
991 &scr
->window_title_gc
,
994 wwin
->frame
->flags
.is_client_window_frame
= 1;
995 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
997 /* setup button images */
998 wWindowUpdateButtonImages(wwin
);
1000 /* hide unused buttons */
1002 if (WFLAGP(wwin
, no_close_button
))
1003 foo
|= WFF_RIGHT_BUTTON
;
1004 if (WFLAGP(wwin
, no_miniaturize_button
))
1005 foo
|= WFF_LEFT_BUTTON
;
1006 #ifdef XKB_BUTTON_HINT
1007 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1008 foo
|= WFF_LANGUAGE_BUTTON
;
1011 wFrameWindowHideButton(wwin
->frame
, foo
);
1013 wwin
->frame
->child
= wwin
;
1016 /* emulate olwm push pin. Make the button look as pushed-in for
1017 * the pinned-out state. When the button is clicked, it will
1018 * revert to the normal position, which means the pin is pinned-in.
1020 if (wwin
->flags
.olwm_push_pin_out
)
1021 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1022 #endif /* OLWM_HINTS */
1025 wwin
->frame
->workspace
= workspace
;
1027 wwin
->frame
->on_click_left
= windowIconifyClick
;
1028 #ifdef XKB_BUTTON_HINT
1029 if (wPreferences
.modelock
)
1030 wwin
->frame
->on_click_language
= windowLanguageClick
;
1033 wwin
->frame
->on_click_right
= windowCloseClick
;
1034 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1036 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1037 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1039 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1042 XSelectInput(dpy
, wwin
->client_win
,
1043 wwin
->event_mask
& ~StructureNotifyMask
);
1045 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1046 0, wwin
->frame
->top_width
);
1048 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1054 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1056 /* if gravity is to the south, account for the border sizes */
1058 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1062 * wWindowConfigure() will init the client window's size
1063 * (wwin->client.{width,height}) and all other geometry
1064 * related variables (frame_x,frame_y)
1066 wWindowConfigure(wwin
, x
, y
, width
, height
);
1068 /* to make sure the window receives it's new position after reparenting */
1069 wWindowSynthConfigureNotify(wwin
);
1072 *--------------------------------------------------
1074 * Setup descriptors and save window to internal
1077 *--------------------------------------------------
1080 if (wwin
->main_window
!=None
) {
1084 /* Leader windows do not necessary set themselves as leaders.
1085 * If this is the case, point the leader of this window to
1087 leader
= wWindowFor(wwin
->main_window
);
1088 if (leader
&& leader
->main_window
==None
) {
1089 leader
->main_window
= leader
->client_win
;
1091 app
= wApplicationCreate(scr
, wwin
->main_window
);
1093 app
->last_workspace
= workspace
;
1096 * Do application specific stuff, like setting application
1100 if (wwin
->flags
.hidden
) {
1101 /* if the window was set to hidden because it was hidden
1102 * in a previous incarnation and that state was restored */
1103 app
->flags
.hidden
= 1;
1106 if (app
->flags
.hidden
) {
1107 wwin
->flags
.hidden
= 1;
1112 /* setup the frame descriptor */
1113 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1114 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1115 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1117 /* don't let windows go away if we die */
1118 XAddToSaveSet(dpy
, window
);
1120 XLowerWindow(dpy
, window
);
1122 /* if window is in this workspace and should be mapped, then map it */
1123 if (!wwin
->flags
.miniaturized
1124 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1125 && !wwin
->flags
.hidden
&& !withdraw
) {
1127 /* The following "if" is to avoid crashing of clients that expect
1128 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1129 * after the return from this function.
1131 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1132 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1134 wClientSetState(wwin
, NormalState
, None
);
1138 /* if not auto focus, then map the window under the currently
1140 #define _WIDTH(w) (w)->frame->core->width
1141 #define _HEIGHT(w) (w)->frame->core->height
1142 if (!wPreferences
.auto_focus
&& scr
->focused_window
1143 && !scr
->flags
.startup
&& !transientOwner
1144 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1145 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1146 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1147 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1148 || wwin
->flags
.maximized
)) {
1149 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1157 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1158 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1160 * The brain damaged idiotic non-click to focus modes will
1161 * have trouble with this because:
1163 * 1. window is created and mapped by the client
1164 * 2. window is mapped by wmaker in small size
1165 * 3. window is animated to grow to normal size
1166 * 4. this function returns to normal event loop
1167 * 5. eventually, the EnterNotify event that would trigger
1168 * the window focusing (if the mouse is over that window)
1169 * will be processed by wmaker.
1170 * But since this event will be rather delayed
1171 * (step 3 has a large delay) the time when the event ocurred
1172 * and when it is processed, the client that owns that window
1173 * will reject the XSetInputFocus() for it.
1175 && (wPreferences
.focus_mode
==WKF_CLICK
1176 || wPreferences
.auto_focus
)) {
1177 DoWindowBirth(wwin
);
1183 /* setup stacking descriptor */
1184 if (transientOwner
) {
1185 /* && wPreferences.on_top_transients */
1186 if (transientOwner
) {
1187 wwin
->frame
->core
->stacking
->child_of
=
1188 transientOwner
->frame
->core
;
1191 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1195 if (!scr
->focused_window
) {
1196 /* first window on the list */
1199 scr
->focused_window
= wwin
;
1203 /* add window at beginning of focus window list */
1204 tmp
= scr
->focused_window
;
1212 /* Update name must come after WApplication stuff is done */
1213 wWindowUpdateName(wwin
, title
);
1219 wGNOMEUpdateClientStateHint(wwin
, True
);
1222 wKWMUpdateClientWorkspace(wwin
);
1223 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1229 *--------------------------------------------------
1231 * Final preparations before window is ready to go
1233 *--------------------------------------------------
1236 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1239 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1240 && !wwin
->flags
.hidden
) {
1241 if (((transientOwner
&& transientOwner
->flags
.focused
)
1242 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1243 wSetFocusTo(scr
, wwin
);
1245 wWindowResetMouseGrabs(wwin
);
1247 if (!WFLAGP(wwin
, no_bind_keys
)) {
1248 wWindowSetKeyGrabs(wwin
);
1251 wGNOMEUpdateClientListHint(scr
);
1254 wwin
->flags
.kwm_managed
= 1;
1256 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1259 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1261 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1264 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1265 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1267 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1268 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1274 *------------------------------------------------------------
1275 * Setup Notification Observers
1276 *------------------------------------------------------------
1278 WMAddNotificationObserver(appearanceObserver
, wwin
,
1279 WNWindowAppearanceSettingsChanged
, wwin
);
1283 *--------------------------------------------------
1285 * Cleanup temporary stuff
1287 *--------------------------------------------------
1291 wWindowDeleteSavedState(win_state
);
1293 /* If the window must be withdrawed, then do it now.
1294 * Must do some optimization, 'though */
1296 wwin
->flags
.mapped
= 0;
1297 wClientSetState(wwin
, WithdrawnState
, None
);
1298 wUnmanageWindow(wwin
, True
, False
);
1310 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1311 char *title
, int x
, int y
, int width
, int height
)
1316 wwin
= wWindowCreate();
1318 WMAddNotificationObserver(appearanceObserver
, wwin
,
1319 WNWindowAppearanceSettingsChanged
, wwin
);
1321 wwin
->flags
.internal_window
= 1;
1323 WSETUFLAG(wwin
, omnipresent
, 1);
1324 WSETUFLAG(wwin
, no_shadeable
, 1);
1325 WSETUFLAG(wwin
, no_resizable
, 1);
1326 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1328 wwin
->focus_mode
= WFM_PASSIVE
;
1330 wwin
->client_win
= window
;
1331 wwin
->screen_ptr
= scr
;
1333 wwin
->transient_for
= owner
;
1337 wwin
->client
.width
= width
;
1338 wwin
->client
.height
= height
;
1340 wwin
->frame_x
= wwin
->client
.x
;
1341 wwin
->frame_y
= wwin
->client
.y
;
1344 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1345 foo
|= WFF_TITLEBAR
;
1346 #ifdef XKB_BUTTON_HINT
1347 foo
|= WFF_LANGUAGE_BUTTON
;
1350 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1351 wwin
->frame_x
, wwin
->frame_y
,
1353 &wPreferences
.window_title_clearance
, foo
,
1354 scr
->window_title_texture
,
1355 scr
->resizebar_texture
,
1356 scr
->window_title_pixel
,
1357 &scr
->window_title_gc
,
1360 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1362 wwin
->frame
->flags
.is_client_window_frame
= 1;
1363 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1365 wFrameWindowChangeTitle(wwin
->frame
, title
);
1367 /* setup button images */
1368 wWindowUpdateButtonImages(wwin
);
1371 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1373 wwin
->frame
->child
= wwin
;
1375 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1377 #ifdef XKB_BUTTON_HINT
1378 if (wPreferences
.modelock
)
1379 wwin
->frame
->on_click_language
= windowLanguageClick
;
1382 wwin
->frame
->on_click_right
= windowCloseClick
;
1384 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1385 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1387 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1389 wwin
->client
.y
+= wwin
->frame
->top_width
;
1390 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1391 0, wwin
->frame
->top_width
);
1393 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1394 wwin
->client
.width
, wwin
->client
.height
);
1396 /* setup the frame descriptor */
1397 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1398 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1399 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1402 XLowerWindow(dpy
, window
);
1403 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1405 /* setup stacking descriptor */
1408 wPreferences
.on_top_transients
&&
1410 wwin
->transient_for
!=None
1411 && wwin
->transient_for
!=scr
->root_win
) {
1413 tmp
= wWindowFor(wwin
->transient_for
);
1415 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1417 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1421 if (!scr
->focused_window
) {
1422 /* first window on the list */
1425 scr
->focused_window
= wwin
;
1429 /* add window at beginning of focus window list */
1430 tmp
= scr
->focused_window
;
1438 if (wwin
->flags
.is_gnustep
== 0)
1439 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1441 /* if (wPreferences.auto_focus)*/
1442 wSetFocusTo(scr
, wwin
);
1444 wWindowResetMouseGrabs(wwin
);
1446 wWindowSetKeyGrabs(wwin
);
1448 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
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
;
1478 wwin
->frame
->workspace
= -1;
1480 wKWMUpdateClientWorkspace(wwin
);
1483 /* First close attribute editor window if open */
1484 if (wwin
->flags
.inspector_open
) {
1485 wCloseInspectorForWindow(wwin
);
1488 /* Close window menu if it's open for this window */
1489 if (wwin
->flags
.menu_open_for_me
) {
1490 CloseWindowMenu(scr
);
1494 if (!wwin
->flags
.internal_window
)
1495 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1497 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1499 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1500 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1503 XUnmapWindow(dpy
, frame
->window
);
1505 XUnmapWindow(dpy
, wwin
->client_win
);
1507 /* deselect window */
1508 wSelectWindow(wwin
, False
);
1510 /* remove all pending events on window */
1511 /* I think this only matters for autoraise */
1512 if (wPreferences
.raise_delay
)
1513 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1517 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1519 /* reparent the window back to the root */
1521 wClientRestore(wwin
);
1523 if (wwin
->transient_for
!=scr
->root_win
) {
1524 owner
= wWindowFor(wwin
->transient_for
);
1526 if (!owner
->flags
.semi_focused
) {
1529 owner
->flags
.semi_focused
= 0;
1534 wasFocused
= wwin
->flags
.focused
;
1536 /* remove from window focus list */
1537 if (!wwin
->prev
&& !wwin
->next
) {
1538 /* was the only window */
1539 scr
->focused_window
= NULL
;
1540 newFocusedWindow
= NULL
;
1545 wwin
->prev
->next
= wwin
->next
;
1547 wwin
->next
->prev
= wwin
->prev
;
1549 scr
->focused_window
= wwin
->prev
;
1550 scr
->focused_window
->next
= NULL
;
1553 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1555 /* if in click to focus mode and the window
1556 * was a transient, focus the owner window
1559 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1560 tmp
= wWindowFor(wwin
->transient_for
);
1561 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1565 /* otherwise, focus the next one in the focus list */
1567 tmp
= scr
->focused_window
;
1568 while (tmp
) { /* look for one in the window list first */
1569 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1570 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1574 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1575 tmp
= scr
->focused_window
;
1577 if (!WFLAGP(tmp
, no_focusable
)
1578 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1585 newFocusedWindow
= tmp
;
1587 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1588 || wPreferences
.focus_mode
==WKF_POINTER
) {
1593 /* This is to let the root window get the keyboard input
1594 * if Sloppy focus mode and no other window get focus.
1595 * This way keybindings will not freeze.
1598 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1599 &foo
, &foo
, &foo
, &foo
, &mask
))
1600 tmp
= wWindowFor(win
);
1603 newFocusedWindow
= tmp
;
1605 newFocusedWindow
= NULL
;
1609 if (!wwin
->flags
.internal_window
) {
1611 wGNOMERemoveClient(wwin
);
1614 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1619 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1620 (unsigned)frame
->window
);
1624 if (newFocusedWindow
!= owner
&& owner
) {
1625 if (wwin
->flags
.is_gnustep
== 0)
1626 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1628 wSetFocusTo(scr
, newFocusedWindow
);
1630 wWindowDestroy(wwin
);
1636 wWindowMap(WWindow
*wwin
)
1638 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1639 if (!wwin
->flags
.shaded
) {
1640 /* window will be remapped when getting MapNotify */
1641 XSelectInput(dpy
, wwin
->client_win
,
1642 wwin
->event_mask
& ~StructureNotifyMask
);
1643 XMapWindow(dpy
, wwin
->client_win
);
1644 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1646 wwin
->flags
.mapped
= 1;
1652 wWindowUnmap(WWindow
*wwin
)
1654 wwin
->flags
.mapped
= 0;
1656 /* prevent window withdrawal when getting UnmapNotify */
1657 XSelectInput(dpy
, wwin
->client_win
,
1658 wwin
->event_mask
& ~StructureNotifyMask
);
1659 XUnmapWindow(dpy
, wwin
->client_win
);
1660 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1662 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1668 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1673 #ifdef KEEP_XKB_LOCK_STATUS
1674 if (wPreferences
.modelock
) {
1675 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1677 #endif /* KEEP_XKB_LOCK_STATUS */
1679 wwin
->flags
.semi_focused
= 0;
1681 if (wwin
->flags
.is_gnustep
== 0)
1682 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1684 wwin
->flags
.focused
= 1;
1686 wWindowResetMouseGrabs(wwin
);
1688 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1690 if (owin
== wwin
|| !owin
)
1693 nowner
= wWindowFor(wwin
->transient_for
);
1695 /* new window is a transient for the old window */
1696 if (nowner
== owin
) {
1697 owin
->flags
.semi_focused
= 1;
1698 wWindowUnfocus(nowner
);
1702 oowner
= wWindowFor(owin
->transient_for
);
1704 /* new window is owner of old window */
1705 if (wwin
== oowner
) {
1706 wWindowUnfocus(owin
);
1711 wWindowUnfocus(owin
);
1715 /* new window has same owner of old window */
1716 if (oowner
== nowner
) {
1717 /* prevent unfocusing of owner */
1718 oowner
->flags
.semi_focused
= 0;
1719 wWindowUnfocus(owin
);
1720 oowner
->flags
.semi_focused
= 1;
1725 /* nowner != NULL && oowner != nowner */
1726 nowner
->flags
.semi_focused
= 1;
1727 wWindowUnfocus(nowner
);
1728 wWindowUnfocus(owin
);
1733 wWindowUnfocus(WWindow
*wwin
)
1735 CloseWindowMenu(wwin
->screen_ptr
);
1737 if (wwin
->flags
.is_gnustep
== 0)
1738 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1739 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1741 if (wwin
->transient_for
!=None
1742 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1744 owner
= wWindowFor(wwin
->transient_for
);
1745 if (owner
&& owner
->flags
.semi_focused
) {
1746 owner
->flags
.semi_focused
= 0;
1747 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1748 wWindowUnfocus(owner
);
1749 wFrameWindowPaint(owner
->frame
);
1753 wwin
->flags
.focused
= 0;
1755 wWindowResetMouseGrabs(wwin
);
1757 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1763 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1765 WApplication
*app
= wApplicationOf(wwin
->main_window
);
1768 char prefix
[32] = "";
1775 instIndex
= wApplicationIndexOfInstance(app
);
1778 wwin
->flags
.wm_name_changed
= 1;
1781 /* the hint was removed */
1782 title
= DEF_WINDOW_TITLE
;
1785 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1791 if (instIndex
> 0) {
1792 sprintf(prefix
, " [%i]", instIndex
);
1794 title
= wstrconcat(title
, prefix
);
1797 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1798 /* only update the menu if the title has actually changed */
1799 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE
);
1801 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1811 *----------------------------------------------------------------------
1813 * wWindowConstrainSize--
1814 * Constrains size for the client window, taking the maximal size,
1815 * window resize increments and other size hints into account.
1818 * The closest size to what was given that the client window can
1821 *----------------------------------------------------------------------
1824 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1826 int width
= *nwidth
;
1827 int height
= *nheight
;
1830 int minW
= 1, minH
= 1;
1831 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1832 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1833 int minAX
= -1, minAY
= -1;
1834 int maxAX
= -1, maxAY
= -1;
1838 if (wwin
->normal_hints
) {
1839 winc
= wwin
->normal_hints
->width_inc
;
1840 hinc
= wwin
->normal_hints
->height_inc
;
1841 minW
= wwin
->normal_hints
->min_width
;
1842 minH
= wwin
->normal_hints
->min_height
;
1843 maxW
= wwin
->normal_hints
->max_width
;
1844 maxH
= wwin
->normal_hints
->max_height
;
1845 if (wwin
->normal_hints
->flags
& PAspect
) {
1846 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1847 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1848 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1849 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1863 /* aspect ratio code borrowed from olwm */
1865 /* adjust max aspect ratio */
1866 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1867 if (maxAX
> maxAY
) {
1868 height
= (width
* maxAY
) / maxAX
;
1869 if (height
> maxH
) {
1871 width
= (height
* maxAX
) / maxAY
;
1874 width
= (height
* maxAX
) / maxAY
;
1877 height
= (width
* maxAY
) / maxAX
;
1882 /* adjust min aspect ratio */
1883 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1884 if (minAX
> minAY
) {
1885 height
= (width
* minAY
) / minAX
;
1886 if (height
< minH
) {
1888 width
= (height
* minAX
) / minAY
;
1891 width
= (height
* minAX
) / minAY
;
1894 height
= (width
* minAY
) / minAX
;
1901 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1903 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1907 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1909 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1912 /* broken stupid apps may cause preposterous values for these.. */
1921 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1923 WScreen
*scr
= wwin
->screen_ptr
;
1927 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1928 || workspace
== wwin
->frame
->workspace
)
1931 if (workspace
!= scr
->current_workspace
) {
1932 /* Sent to other workspace. Unmap window */
1933 if ((wwin
->flags
.mapped
1934 || wwin
->flags
.shaded
1935 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1936 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1938 wapp
= wApplicationOf(wwin
->main_window
);
1940 wapp
->last_workspace
= workspace
;
1942 if (wwin
->flags
.miniaturized
) {
1944 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1945 wwin
->icon
->mapped
= 0;
1949 wSetFocusTo(scr
, NULL
);
1953 /* brought to current workspace. Map window */
1954 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1956 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1957 wwin
->icon
->mapped
= 1;
1959 } else if (!wwin
->flags
.mapped
&&
1960 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1964 if (!IS_OMNIPRESENT(wwin
)) {
1965 wwin
->frame
->workspace
= workspace
;
1966 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1969 wGNOMEUpdateClientStateHint(wwin
, True
);
1972 wKWMUpdateClientWorkspace(wwin
);
1973 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1982 wWindowSynthConfigureNotify(WWindow
*wwin
)
1986 sevent
.type
= ConfigureNotify
;
1987 sevent
.xconfigure
.display
= dpy
;
1988 sevent
.xconfigure
.event
= wwin
->client_win
;
1989 sevent
.xconfigure
.window
= wwin
->client_win
;
1991 sevent
.xconfigure
.x
= wwin
->client
.x
;
1992 sevent
.xconfigure
.y
= wwin
->client
.y
;
1993 sevent
.xconfigure
.width
= wwin
->client
.width
;
1994 sevent
.xconfigure
.height
= wwin
->client
.height
;
1996 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1997 if (WFLAGP(wwin
, no_titlebar
))
1998 sevent
.xconfigure
.above
= None
;
2000 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2002 sevent
.xconfigure
.override_redirect
= False
;
2003 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2005 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2012 *----------------------------------------------------------------------
2013 * wWindowConfigure--
2014 * Configures the frame, decorations and client window to the
2015 * specified geometry. The geometry is not checked for validity,
2016 * wWindowConstrainSize() must be used for that.
2017 * The size parameters are for the client window, but the position is
2019 * The client window receives a ConfigureNotify event, according
2020 * to what ICCCM says.
2026 * Window size and position are changed and client window receives
2027 * a ConfigureNotify event.
2028 *----------------------------------------------------------------------
2031 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2033 int req_x
, req_y
; /* new position of the frame */
2034 int req_width
, req_height
; /* new size of the client */
2036 int synth_notify
= False
;
2039 resize
= (req_width
!=wwin
->client
.width
2040 || req_height
!=wwin
->client
.height
);
2042 * if the window is being moved but not resized then
2043 * send a synthetic ConfigureNotify
2045 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2046 synth_notify
= True
;
2049 if (WFLAGP(wwin
, dont_move_off
))
2050 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2051 req_width
, req_height
);
2053 if (req_width
< MIN_WINDOW_SIZE
)
2054 req_width
= MIN_WINDOW_SIZE
;
2055 if (req_height
< MIN_WINDOW_SIZE
)
2056 req_height
= MIN_WINDOW_SIZE
;
2058 /* If growing, resize inner part before frame,
2059 * if shrinking, resize frame before.
2060 * This will prevent the frame (that can have a different color)
2061 * to be exposed, causing flicker */
2062 if (req_height
> wwin
->frame
->core
->height
2063 || req_width
> wwin
->frame
->core
->width
)
2064 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2066 if (wwin
->flags
.shaded
) {
2067 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2068 req_width
, wwin
->frame
->core
->height
);
2069 wwin
->old_geometry
.height
= req_height
;
2073 h
= req_height
+ wwin
->frame
->top_width
2074 + wwin
->frame
->bottom_width
;
2076 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2079 if (!(req_height
> wwin
->frame
->core
->height
2080 || req_width
> wwin
->frame
->core
->width
))
2081 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2083 wwin
->client
.x
= req_x
;
2084 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2085 wwin
->client
.width
= req_width
;
2086 wwin
->client
.height
= req_height
;
2088 wwin
->client
.x
= req_x
;
2089 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2091 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2093 wwin
->frame_x
= req_x
;
2094 wwin
->frame_y
= req_y
;
2095 if (!WFLAGP(wwin
, no_border
)) {
2096 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2097 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2101 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2102 wWindowSetShape(wwin
);
2107 wWindowSynthConfigureNotify(wwin
);
2113 wWindowMove(wwin
, req_x
, req_y
)
2115 int req_x
, req_y
; /* new position of the frame */
2117 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2118 int synth_notify
= False
;
2120 /* Send a synthetic ConfigureNotify event for every window movement. */
2121 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2122 synth_notify
= True
;
2125 /* A single synthetic ConfigureNotify event is sent at the end of
2126 * a completed (opaque) movement in moveres.c */
2129 if (WFLAGP(wwin
, dont_move_off
))
2130 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2131 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2133 wwin
->client
.x
= req_x
;
2134 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2135 if (!WFLAGP(wwin
, no_border
)) {
2136 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2137 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2140 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2142 wwin
->frame_x
= req_x
;
2143 wwin
->frame_y
= req_y
;
2145 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2147 wWindowSynthConfigureNotify(wwin
);
2153 wWindowUpdateButtonImages(WWindow
*wwin
)
2155 WScreen
*scr
= wwin
->screen_ptr
;
2156 Pixmap pixmap
, mask
;
2157 WFrameWindow
*fwin
= wwin
->frame
;
2159 if (WFLAGP(wwin
, no_titlebar
))
2162 /* miniaturize button */
2164 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2165 if (wwin
->wm_gnustep_attr
2166 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2167 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2169 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2170 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2175 if (fwin
->lbutton_image
2176 && (fwin
->lbutton_image
->image
!= pixmap
2177 || fwin
->lbutton_image
->mask
!= mask
)) {
2178 wPixmapDestroy(fwin
->lbutton_image
);
2179 fwin
->lbutton_image
= NULL
;
2182 if (!fwin
->lbutton_image
) {
2183 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2184 fwin
->lbutton_image
->client_owned
= 1;
2185 fwin
->lbutton_image
->client_owned_mask
= 1;
2188 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2189 wPixmapDestroy(fwin
->lbutton_image
);
2191 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2195 #ifdef XKB_BUTTON_HINT
2196 if (!WFLAGP(wwin
, no_language_button
)) {
2197 if (fwin
->languagebutton_image
&&
2198 !fwin
->languagebutton_image
->shared
) {
2199 wPixmapDestroy(fwin
->languagebutton_image
);
2201 fwin
->languagebutton_image
=
2202 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2208 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2209 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2211 if (!WFLAGP(wwin
, no_close_button
)) {
2212 if (wwin
->wm_gnustep_attr
2213 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2214 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2216 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2217 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2221 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2222 || fwin
->rbutton_image
->mask
!= mask
)) {
2223 wPixmapDestroy(fwin
->rbutton_image
);
2224 fwin
->rbutton_image
= NULL
;
2227 if (!fwin
->rbutton_image
) {
2228 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2229 fwin
->rbutton_image
->client_owned
= 1;
2230 fwin
->rbutton_image
->client_owned_mask
= 1;
2233 } else if (WFLAGP(wwin
, kill_close
)) {
2235 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2236 wPixmapDestroy(fwin
->rbutton_image
);
2238 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2240 } else if (MGFLAGP(wwin
, broken_close
)) {
2242 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2243 wPixmapDestroy(fwin
->rbutton_image
);
2245 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2249 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2250 wPixmapDestroy(fwin
->rbutton_image
);
2252 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2256 /* force buttons to be redrawn */
2257 fwin
->flags
.need_texture_change
= 1;
2258 wFrameWindowPaint(fwin
);
2263 *---------------------------------------------------------------------------
2264 * wWindowConfigureBorders--
2265 * Update window border configuration according to attribute flags.
2267 *---------------------------------------------------------------------------
2270 wWindowConfigureBorders(WWindow
*wwin
)
2276 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2277 #ifdef XKB_BUTTON_HINT
2278 flags
|= WFF_LANGUAGE_BUTTON
;
2280 if (!WFLAGP(wwin
, no_titlebar
))
2281 flags
|= WFF_TITLEBAR
;
2282 if (!WFLAGP(wwin
, no_resizebar
))
2283 flags
|= WFF_RESIZEBAR
;
2284 if (!WFLAGP(wwin
, no_border
))
2285 flags
|= WFF_BORDER
;
2286 if (wwin
->flags
.shaded
)
2287 flags
|= WFF_IS_SHADED
;
2289 oldh
= wwin
->frame
->top_width
;
2290 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2291 if (oldh
!= wwin
->frame
->top_width
) {
2292 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2294 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2295 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2296 wwin
->client
.width
, wwin
->client
.height
);
2300 if (!WFLAGP(wwin
, no_miniaturize_button
)
2301 && wwin
->frame
->flags
.hide_left_button
)
2302 flags
|= WFF_LEFT_BUTTON
;
2304 #ifdef XKB_BUTTON_HINT
2305 if (!WFLAGP(wwin
, no_language_button
)
2306 && wwin
->frame
->flags
.hide_language_button
)
2307 flags
|= WFF_LANGUAGE_BUTTON
;
2310 if (!WFLAGP(wwin
, no_close_button
)
2311 && wwin
->frame
->flags
.hide_right_button
)
2312 flags
|= WFF_RIGHT_BUTTON
;
2315 wWindowUpdateButtonImages(wwin
);
2316 wFrameWindowShowButton(wwin
->frame
, flags
);
2320 if (WFLAGP(wwin
, no_miniaturize_button
)
2321 && !wwin
->frame
->flags
.hide_left_button
)
2322 flags
|= WFF_LEFT_BUTTON
;
2324 #ifdef XKB_BUTTON_HINT
2325 if (WFLAGP(wwin
, no_language_button
)
2326 && !wwin
->frame
->flags
.hide_language_button
)
2327 flags
|= WFF_LANGUAGE_BUTTON
;
2330 if (WFLAGP(wwin
, no_close_button
)
2331 && !wwin
->frame
->flags
.hide_right_button
)
2332 flags
|= WFF_RIGHT_BUTTON
;
2335 wFrameWindowHideButton(wwin
->frame
, flags
);
2338 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2339 wWindowSetShape(wwin
);
2347 wWindowSaveState(WWindow
*wwin
)
2352 memset(data
, 0, sizeof(CARD32
)*10);
2353 data
[0] = wwin
->frame
->workspace
;
2354 data
[1] = wwin
->flags
.miniaturized
;
2355 data
[2] = wwin
->flags
.shaded
;
2356 data
[3] = wwin
->flags
.hidden
;
2357 data
[4] = wwin
->flags
.maximized
;
2358 if (wwin
->flags
.maximized
== 0) {
2359 data
[5] = wwin
->frame_x
;
2360 data
[6] = wwin
->frame_y
;
2361 data
[7] = wwin
->frame
->core
->width
;
2362 data
[8] = wwin
->frame
->core
->height
;
2364 data
[5] = wwin
->old_geometry
.x
;
2365 data
[6] = wwin
->old_geometry
.y
;
2366 data
[7] = wwin
->old_geometry
.width
;
2367 data
[8] = wwin
->old_geometry
.height
;
2370 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2371 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2372 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2375 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2376 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2377 (unsigned char *)data
, 10);
2382 getSavedState(Window window
, WSavedState
**state
)
2386 unsigned long nitems_ret
;
2387 unsigned long bytes_after_ret
;
2390 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2391 True
, _XA_WINDOWMAKER_STATE
,
2392 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2393 (unsigned char **)&data
)!=Success
|| !data
)
2396 *state
= malloc(sizeof(WSavedState
));
2399 (*state
)->workspace
= data
[0];
2400 (*state
)->miniaturized
= data
[1];
2401 (*state
)->shaded
= data
[2];
2402 (*state
)->hidden
= data
[3];
2403 (*state
)->maximized
= data
[4];
2404 (*state
)->x
= data
[5];
2405 (*state
)->y
= data
[6];
2406 (*state
)->w
= data
[7];
2407 (*state
)->h
= data
[8];
2408 (*state
)->window_shortcuts
= data
[9];
2412 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2421 wWindowClearShape(WWindow
*wwin
)
2423 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2424 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2429 wWindowSetShape(WWindow
*wwin
)
2433 #ifdef OPTIMIZE_SHAPE
2438 /* only shape is the client's */
2439 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2443 /* Get array of rectangles describing the shape mask */
2444 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2450 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2456 /* insert our decoration rectangles in the rect list */
2457 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2460 if (!WFLAGP(wwin
, no_titlebar
)) {
2462 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2463 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2464 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2467 if (!WFLAGP(wwin
, no_resizebar
)) {
2469 urec
[count
].y
= wwin
->frame
->core
->height
2470 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2471 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2472 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2476 /* shape our frame window */
2477 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2478 0, wwin
->frame
->top_width
, urec
, count
,
2479 ShapeSet
, Unsorted
);
2485 #endif /* OPTIMIZE_SHAPE */
2487 if (!WFLAGP(wwin
, no_titlebar
)) {
2490 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2491 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2494 if (!WFLAGP(wwin
, no_resizebar
)) {
2496 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2497 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2498 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2502 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2503 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2505 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2506 0, wwin
->frame
->top_width
, wwin
->client_win
,
2507 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2512 /* ====================================================================== */
2515 getFocusMode(WWindow
*wwin
)
2519 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2520 if (wwin
->wm_hints
->input
== True
) {
2521 if (wwin
->protocols
.TAKE_FOCUS
)
2522 mode
= WFM_LOCALLY_ACTIVE
;
2526 if (wwin
->protocols
.TAKE_FOCUS
)
2527 mode
= WFM_GLOBALLY_ACTIVE
;
2529 mode
= WFM_NO_INPUT
;
2539 wWindowSetKeyGrabs(WWindow
*wwin
)
2544 for (i
=0; i
<WKBD_LAST
; i
++) {
2545 key
= &wKeyBindings
[i
];
2547 if (key
->keycode
==0)
2549 if (key
->modifier
!=AnyModifier
) {
2550 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2551 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2553 /* Also grab all modifier combinations possible that include,
2554 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2555 * work even if the NumLock/ScrollLock key is on.
2557 wHackedGrabKey(key
->keycode
, key
->modifier
,
2558 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2562 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2563 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2567 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2574 wWindowResetMouseGrabs(WWindow
*wwin
)
2576 /* Mouse grabs can't be done on the client window because of
2577 * ICCCM and because clients that try to do the same will crash.
2579 * But there is a problem wich makes tbar buttons of unfocused
2580 * windows not usable as the click goes to the frame window instead
2581 * of the button itself. Must figure a way to fix that.
2584 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2586 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2587 /* grabs for Meta+drag */
2588 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2589 True
, ButtonPressMask
, GrabModeSync
,
2590 GrabModeAsync
, None
, None
);
2593 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2594 && !wwin
->flags
.is_gnustep
) {
2595 /* the passive grabs to focus the window */
2596 /* if (wPreferences.focus_mode == WKF_CLICK) */
2597 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2598 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2606 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2608 if (attr
->flags
& GSExtraFlagsAttr
) {
2609 if (MGFLAGP(wwin
, broken_close
) !=
2610 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2611 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2612 wWindowUpdateButtonImages(wwin
);
2619 wWindowAddSavedState(char *instance
, char *class, char *command
,
2620 pid_t pid
, WSavedState
*state
)
2622 WWindowState
*wstate
;
2624 wstate
= malloc(sizeof(WWindowState
));
2628 memset(wstate
, 0, sizeof(WWindowState
));
2631 wstate
->instance
= wstrdup(instance
);
2633 wstate
->class = wstrdup(class);
2635 wstate
->command
= wstrdup(command
);
2636 wstate
->state
= state
;
2638 wstate
->next
= windowState
;
2639 windowState
= wstate
;
2642 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2650 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2654 wWindowGetSavedState(Window win
)
2656 char *instance
, *class, *command
=NULL
;
2657 WWindowState
*wstate
= windowState
;
2664 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2666 command
= wtokenjoin(argv
, argc
);
2667 XFreeStringList(argv
);
2672 if (PropGetWMClass(win
, &class, &instance
)) {
2674 if (SAME(instance
, wstate
->instance
) &&
2675 SAME(class, wstate
->class) &&
2676 SAME(command
, wstate
->command
)) {
2679 wstate
= wstate
->next
;
2686 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2690 if (command
) wfree(command
);
2691 if (instance
) XFree(instance
);
2692 if (class) XFree(class);
2699 wWindowDeleteSavedState(WMagicNumber id
)
2701 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2703 if (!wstate
|| !windowState
)
2708 windowState
= wstate
->next
;
2710 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2711 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2713 if (wstate
->instance
) wfree(wstate
->instance
);
2714 if (wstate
->class) wfree(wstate
->class);
2715 if (wstate
->command
) wfree(wstate
->command
);
2716 wfree(wstate
->state
);
2720 if (tmp
->next
==wstate
) {
2721 tmp
->next
=wstate
->next
;
2723 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2724 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2726 if (wstate
->instance
) wfree(wstate
->instance
);
2727 if (wstate
->class) wfree(wstate
->class);
2728 if (wstate
->command
) wfree(wstate
->command
);
2729 wfree(wstate
->state
);
2740 wWindowDeleteSavedStatesForPID(pid_t pid
)
2742 WWindowState
*tmp
, *wstate
;
2748 if (tmp
->pid
== pid
) {
2749 wstate
= windowState
;
2750 windowState
= tmp
->next
;
2752 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2753 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2755 if (wstate
->instance
) wfree(wstate
->instance
);
2756 if (wstate
->class) wfree(wstate
->class);
2757 if (wstate
->command
) wfree(wstate
->command
);
2758 wfree(wstate
->state
);
2762 if (tmp
->next
->pid
==pid
) {
2764 tmp
->next
= wstate
->next
;
2766 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2767 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2769 if (wstate
->instance
) wfree(wstate
->instance
);
2770 if (wstate
->class) wfree(wstate
->class);
2771 if (wstate
->command
) wfree(wstate
->command
);
2772 wfree(wstate
->state
);
2782 /* ====================================================================== */
2785 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2787 WWindow
*wwin
= data
;
2789 #ifndef NUMLOCK_HACK
2790 if ((event
->xbutton
.state
& ValidModMask
)
2791 != (event
->xbutton
.state
& ~LockMask
)) {
2792 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2793 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2797 event
->xbutton
.state
&= ValidModMask
;
2799 CloseWindowMenu(wwin
->screen_ptr
);
2801 if (wPreferences
.focus_mode
==WKF_CLICK
2802 && !(event
->xbutton
.state
&ControlMask
)
2803 && !WFLAGP(wwin
, no_focusable
)) {
2804 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2807 if (event
->xbutton
.button
== Button1
)
2808 wRaiseFrame(wwin
->frame
->core
);
2810 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2811 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2812 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2813 GrabModeAsync
, GrabModeAsync
, None
,
2814 None
, CurrentTime
)!=GrabSuccess
) {
2816 wwarning("pointer grab failed for window move");
2822 if (event
->xbutton
.state
& MOD_MASK
) {
2823 /* move the window */
2824 wMouseMoveWindow(wwin
, event
);
2825 XUngrabPointer(dpy
, CurrentTime
);
2827 wMouseResizeWindow(wwin
, event
);
2828 XUngrabPointer(dpy
, CurrentTime
);
2835 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2837 WWindow
*wwin
= data
;
2839 event
->xbutton
.state
&= ValidModMask
;
2841 if (event
->xbutton
.button
==Button1
) {
2842 if (event
->xbutton
.state
== 0) {
2843 if (!WFLAGP(wwin
, no_shadeable
)) {
2845 if (wwin
->flags
.shaded
)
2846 wUnshadeWindow(wwin
);
2853 if (event
->xbutton
.state
& ControlMask
)
2854 dir
|= MAX_VERTICAL
;
2856 if (event
->xbutton
.state
& ShiftMask
) {
2857 dir
|= MAX_HORIZONTAL
;
2858 if (!(event
->xbutton
.state
& ControlMask
))
2859 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2862 /* maximize window */
2863 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2864 int ndir
= dir
^ wwin
->flags
.maximized
;
2865 if (wwin
->flags
.maximized
!= 0)
2866 wUnmaximizeWindow(wwin
);
2868 wMaximizeWindow(wwin
, ndir
);
2871 } else if (event
->xbutton
.button
==Button3
) {
2872 if (event
->xbutton
.state
& MOD_MASK
) {
2873 wHideOtherApplications(wwin
);
2875 } else if (event
->xbutton
.button
==Button2
) {
2876 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2882 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2884 WWindow
*wwin
= desc
->parent
;
2886 event
->xbutton
.state
&= ValidModMask
;
2888 CloseWindowMenu(wwin
->screen_ptr
);
2890 if (/*wPreferences.focus_mode==WKF_CLICK
2891 &&*/ !(event
->xbutton
.state
&ControlMask
)
2892 && !WFLAGP(wwin
, no_focusable
)) {
2893 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2895 if (event
->xbutton
.button
== Button1
) {
2896 wRaiseFrame(wwin
->frame
->core
);
2899 if (event
->xbutton
.state
& MOD_MASK
) {
2900 /* move the window */
2901 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2902 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2903 GrabModeAsync
, GrabModeAsync
, None
,
2904 None
, CurrentTime
)!=GrabSuccess
) {
2906 wwarning("pointer grab failed for window move");
2910 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2911 wMouseResizeWindow(wwin
, event
);
2913 wMouseMoveWindow(wwin
, event
);
2914 XUngrabPointer(dpy
, CurrentTime
);
2920 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2922 WWindow
*wwin
= (WWindow
*)data
;
2924 #ifndef NUMLOCK_HACK
2925 if ((event
->xbutton
.state
& ValidModMask
)
2926 != (event
->xbutton
.state
& ~LockMask
)) {
2927 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2928 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2931 event
->xbutton
.state
&= ValidModMask
;
2933 CloseWindowMenu(wwin
->screen_ptr
);
2935 if (wPreferences
.focus_mode
==WKF_CLICK
2936 && !(event
->xbutton
.state
&ControlMask
)
2937 && !WFLAGP(wwin
, no_focusable
)) {
2938 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2941 if (event
->xbutton
.button
== Button1
2942 || event
->xbutton
.button
== Button2
) {
2944 if (event
->xbutton
.button
== Button1
) {
2945 if (event
->xbutton
.state
& MOD_MASK
) {
2946 wLowerFrame(wwin
->frame
->core
);
2948 wRaiseFrame(wwin
->frame
->core
);
2951 if ((event
->xbutton
.state
& ShiftMask
)
2952 && !(event
->xbutton
.state
& ControlMask
)) {
2953 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2956 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2957 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2958 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2959 GrabModeAsync
, GrabModeAsync
, None
,
2960 None
, CurrentTime
)!=GrabSuccess
) {
2962 wwarning("pointer grab failed for window move");
2967 /* move the window */
2968 wMouseMoveWindow(wwin
, event
);
2970 XUngrabPointer(dpy
, CurrentTime
);
2971 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2972 && !wwin
->flags
.internal_window
2973 && !WCHECK_STATE(WSTATE_MODAL
)) {
2974 WObjDescriptor
*desc
;
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 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2988 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2990 /* allow drag select */
2991 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2992 event
->xany
.send_event
= True
;
2993 (*desc
->handle_mousedown
)(desc
, event
);
2995 XUngrabPointer(dpy
, CurrentTime
);
3002 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3004 WWindow
*wwin
= data
;
3006 event
->xbutton
.state
&= ValidModMask
;
3008 CloseWindowMenu(wwin
->screen_ptr
);
3010 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3013 /* if control-click, kill the client */
3014 if (event
->xbutton
.state
& ControlMask
) {
3018 if (wwin
->flags
.olwm_push_pin_out
) {
3020 wwin
->flags
.olwm_push_pin_out
= 0;
3022 wOLWMChangePushpinState(wwin
, True
);
3024 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3029 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3030 /* send delete message */
3031 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3038 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3040 WWindow
*wwin
= data
;
3042 CloseWindowMenu(wwin
->screen_ptr
);
3044 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3047 /* send delete message */
3048 if (wwin
->protocols
.DELETE_WINDOW
) {
3049 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3056 #ifdef XKB_BUTTON_HINT
3058 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3060 WWindow
*wwin
= data
;
3061 WFrameWindow
*fwin
= wwin
->frame
;
3062 WScreen
*scr
= fwin
->screen_ptr
;
3063 XkbStateRec staterec
;
3066 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3068 tl
= wwin
->frame
->languagemode
;
3069 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3070 wwin
->frame
->last_languagemode
= tl
;
3071 wSetFocusTo(scr
, wwin
);
3072 wwin
->frame
->languagebutton_image
=
3073 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3074 wwin
->frame
->languagemode
];
3075 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3076 if (event
->xbutton
.button
== Button3
)
3078 wRaiseFrame(fwin
->core
);
3084 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3086 WWindow
*wwin
= data
;
3088 event
->xbutton
.state
&= ValidModMask
;
3090 CloseWindowMenu(wwin
->screen_ptr
);
3092 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3095 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3096 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3100 if ((event
->xbutton
.state
& ControlMask
) ||
3101 (event
->xbutton
.button
== Button3
)) {
3103 wapp
= wApplicationOf(wwin
->main_window
);
3104 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3105 wHideApplication(wapp
);
3106 } else if (event
->xbutton
.state
==0) {
3107 wIconifyWindow(wwin
);