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 free(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 switch (wwin
->wm_gnustep_attr
->window_level
) {
400 case WMNormalWindowLevel
:
401 *level
= WMNormalLevel
;
403 case WMFloatingWindowLevel
:
404 *level
= WMFloatingLevel
;
406 case WMDockWindowLevel
:
407 *level
= WMDockLevel
;
409 case WMSubmenuWindowLevel
:
410 *level
= WMSubmenuLevel
;
412 case WMMainMenuWindowLevel
:
413 *level
= WMMainMenuLevel
;
416 *level
= WMNormalLevel
;
421 *level
= WMNormalLevel
;
424 int tmp_workspace
= -1;
431 wMWMCheckClientHints(wwin
);
432 #endif /* MWM_HINTS */
435 check
= wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
436 #endif /* GNOME_STUFF */
440 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
441 #endif /* KWM_HINTS */
444 wOLWMCheckClientHints(wwin
);
445 #endif /* OLWM_HINTS */
448 if (WFLAGP(wwin
, floating
))
449 *level
= WMFloatingLevel
;
450 else if (WFLAGP(wwin
, sunken
))
451 *level
= WMSunkenLevel
;
453 *level
= WMNormalLevel
;
458 if (tmp_workspace
>= 0) {
459 *workspace
= tmp_workspace
% scr
->workspace_count
;
464 * Set attributes specified only for that window/class.
465 * This might do duplicate work with the 1st wDefaultFillAttributes().
467 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
468 &wwin
->user_flags
, &wwin
->defined_user_flags
,
471 * Sanity checks for attributes that depend on other attributes
473 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
474 wwin
->user_flags
.emulate_appicon
= 0;
476 if (wwin
->main_window
!=None
) {
477 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
478 if (wapp
&& !wapp
->flags
.emulated
)
479 wwin
->user_flags
.emulate_appicon
= 0;
482 if (wwin
->transient_for
!=None
483 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
484 wwin
->user_flags
.emulate_appicon
= 0;
486 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
487 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
488 wwin
->user_flags
.sunken
= 0;
490 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
497 wWindowCanReceiveFocus(WWindow
*wwin
)
499 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
501 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
503 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
511 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
515 w1
= wwin
->frame
->core
->width
;
516 h1
= wwin
->frame
->core
->height
;
517 w2
= obscured
->frame
->core
->width
;
518 h2
= obscured
->frame
->core
->height
;
520 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
521 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
524 if (wwin
->frame_x
+ w1
< obscured
->frame_x
525 || wwin
->frame_y
+ h1
< obscured
->frame_y
526 || wwin
->frame_x
> obscured
->frame_x
+ w2
527 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
536 *----------------------------------------------------------------
538 * reparents the window and allocates a descriptor for it.
539 * Window manager hints and other hints are fetched to configure
540 * the window decoration attributes and others. User preferences
541 * for the window are used if available, to configure window
542 * decorations and some behaviour.
543 * If in startup, windows that are override redirect,
544 * unmapped and never were managed and are Withdrawn are not
548 * the new window descriptor
551 * The window is reparented and appropriate notification
552 * is done to the client. Input mask for the window is setup.
553 * The window descriptor is also associated with various window
554 * contexts and inserted in the head of the window list.
555 * Event handler contexts are associated for some objects
556 * (buttons, titlebar and resizebar)
558 *----------------------------------------------------------------
561 wManageWindow(WScreen
*scr
, Window window
)
565 unsigned width
, height
;
566 XWindowAttributes wattribs
;
567 XSetWindowAttributes attribs
;
568 WWindowState
*win_state
;
569 WWindow
*transientOwner
= NULL
;
575 Bool withdraw
= False
;
578 /* XGrabServer(dpy); */
580 /* make sure the window is still there */
581 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
586 /* if it's an override-redirect, ignore it */
587 if (wattribs
.override_redirect
) {
592 wm_state
= PropGetWindowState(window
);
594 /* if it's startup and the window is unmapped, don't manage it */
595 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
600 if (!wFetchName(dpy
, window
, &title
)) {
605 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
610 #endif /* KWM_HINTS */
613 wwin
= wWindowCreate();
615 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
618 printf("managing window %x\n", (unsigned)window
);
622 if (wShapeSupported
) {
627 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
628 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
629 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
630 wwin
->flags
.shaped
= b_shaped
;
635 *--------------------------------------------------
637 * Get hints and other information in properties
639 *--------------------------------------------------
641 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
643 /* setup descriptor */
644 wwin
->client_win
= window
;
645 wwin
->screen_ptr
= scr
;
647 wwin
->old_border_width
= wattribs
.border_width
;
649 wwin
->event_mask
= CLIENT_EVENTS
;
650 attribs
.event_mask
= CLIENT_EVENTS
;
651 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
652 attribs
.save_under
= False
;
653 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
654 |CWSaveUnder
, &attribs
);
655 XSetWindowBorderWidth(dpy
, window
, 0);
657 /* get hints from GNUstep app */
658 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
659 wwin
->flags
.is_gnustep
= 1;
661 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
662 wwin
->wm_gnustep_attr
= NULL
;
665 wwin
->client_leader
= PropGetClientLeader(window
);
666 if (wwin
->client_leader
!=None
)
667 wwin
->main_window
= wwin
->client_leader
;
669 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
671 if (wwin
->wm_hints
) {
672 if (wwin
->wm_hints
->flags
& StateHint
) {
674 if (wwin
->wm_hints
->initial_state
== IconicState
) {
676 wwin
->flags
.miniaturized
= 1;
678 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
684 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
685 wwin
->group_id
= wwin
->wm_hints
->window_group
;
686 /* window_group has priority over CLIENT_LEADER */
687 wwin
->main_window
= wwin
->group_id
;
689 wwin
->group_id
= None
;
692 if (wwin
->wm_hints
->flags
& UrgencyHint
)
693 wwin
->flags
.urgent
= 1;
695 wwin
->group_id
= None
;
698 PropGetProtocols(window
, &wwin
->protocols
);
700 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
701 wwin
->transient_for
= None
;
703 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
704 wwin
->transient_for
= scr
->root_win
;
706 transientOwner
= wWindowFor(wwin
->transient_for
);
707 if (transientOwner
&& transientOwner
->main_window
!=None
) {
708 wwin
->main_window
= transientOwner
->main_window
;
710 wwin->main_window = None;
715 /* guess the focus mode */
716 wwin
->focus_mode
= getFocusMode(wwin
);
718 /* get geometry stuff */
719 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
721 /* get colormap windows */
722 GetColormapWindows(wwin
);
725 *--------------------------------------------------
727 * Setup the decoration/window attributes and
730 *--------------------------------------------------
733 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
736 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
737 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
739 transientOwner
= wWindowFor(wwin
->group_id
);
741 if (transientOwner
) {
742 wwin
->transient_for
= wwin
->group_id
;
744 /* transients can't be iconified or maximized */
745 if (wwin
->transient_for
) {
746 WSETUFLAG(wwin
, no_miniaturizable
, 1);
747 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
751 #endif /* OLWM_HINTS */
754 * Make broken apps behave as a nice app.
756 if (WFLAGP(wwin
, emulate_appicon
)) {
757 wwin
->main_window
= wwin
->client_win
;
761 *------------------------------------------------------------
763 * Setup the initial state of the window
765 *------------------------------------------------------------
768 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
769 wwin
->flags
.miniaturized
= 1;
772 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
773 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
781 bla
= wGNOMECheckInitialClientState(wwin
);
785 wKWMCheckClientInitialState(wwin
);
789 /* apply previous state if it exists and we're in startup */
790 if (scr
->flags
.startup
&& wm_state
>= 0) {
792 if (wm_state
== IconicState
) {
794 wwin
->flags
.miniaturized
= 1;
796 } else if (wm_state
== WithdrawnState
) {
802 /* if there is a saved state (from file), restore it */
804 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
805 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
807 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
809 if (win_state
&& !withdraw
) {
811 if (win_state
->state
->hidden
>0)
812 wwin
->flags
.hidden
= win_state
->state
->hidden
;
814 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
815 wwin
->flags
.shaded
= win_state
->state
->shaded
;
817 if (win_state
->state
->miniaturized
>0 &&
818 !WFLAGP(wwin
, no_miniaturizable
)) {
819 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
821 if (!IS_OMNIPRESENT(wwin
)) {
822 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
824 if (w
< 0 || w
>= scr
->workspace_count
) {
825 workspace
= win_state
->state
->workspace
;
826 if (workspace
>= scr
->workspace_count
)
827 workspace
= scr
->current_workspace
;
832 workspace
= scr
->current_workspace
;
836 /* if we're restarting, restore saved state (from hints).
837 * This will overwrite previous */
841 if (getSavedState(window
, &wstate
)) {
842 wwin
->flags
.shaded
= wstate
->shaded
;
843 wwin
->flags
.hidden
= wstate
->hidden
;
844 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
845 workspace
= wstate
->workspace
;
847 if (scr
->flags
.startup
&& wstate
->window_shortcuts
> 0) {
850 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
851 if (wstate
->window_shortcuts
& (1<<i
)) {
852 if (!scr
->shortcutWindows
[i
])
853 scr
->shortcutWindows
[i
] = WMCreateBag(4);
855 WMPutInBag(scr
->shortcutWindows
[i
], wwin
);
863 /* don't let transients start miniaturized if their owners are not */
864 if (transientOwner
&& !transientOwner
->flags
.miniaturized
865 && wwin
->flags
.miniaturized
&& !withdraw
) {
866 wwin
->flags
.miniaturized
= 0;
868 wwin
->wm_hints
->initial_state
= NormalState
;
871 /* set workspace on which the window starts */
872 if (workspace
>= 0) {
873 if (workspace
> scr
->workspace_count
-1) {
874 workspace
= workspace
% scr
->workspace_count
;
879 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
881 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
886 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
888 workspace
= transientOwner
->frame
->workspace
;
892 workspace
= scr
->current_workspace
;
897 /* setup window geometry */
898 if (win_state
&& win_state
->state
->use_geometry
) {
899 width
= win_state
->state
->w
;
900 height
= win_state
->state
->h
;
902 wWindowConstrainSize(wwin
, &width
, &height
);
904 /* do not ask for window placement if the window is
905 * transient, during startup, if the initial workspace is another one
906 * or if the window wants to start iconic.
907 * If geometry was saved, restore it. */
909 Bool dontBring
= False
;
911 if (win_state
&& win_state
->state
->use_geometry
) {
912 x
= win_state
->state
->x
;
913 y
= win_state
->state
->y
;
914 } else if ((wwin
->transient_for
==None
915 || wPreferences
.window_placement
!=WPM_MANUAL
)
916 && !scr
->flags
.startup
917 && workspace
== scr
->current_workspace
918 && !wwin
->flags
.miniaturized
919 && !wwin
->flags
.maximized
920 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
922 if (transientOwner
&& transientOwner
->flags
.mapped
) {
923 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
925 x
= transientOwner
->frame_x
+
926 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
927 y
= transientOwner
->frame_y
+
928 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
932 else if (x
+ width
> scr
->scr_width
)
933 x
= scr
->scr_width
- width
;
937 else if (y
+ height
> scr
->scr_height
)
938 y
= scr
->scr_height
- height
;
940 PlaceWindow(wwin
, &x
, &y
, width
, height
);
942 if (wPreferences
.window_placement
== WPM_MANUAL
)
946 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
947 wScreenBringInside(scr
, &x
, &y
, width
, height
);
950 if (wwin
->flags
.urgent
) {
951 if (!IS_OMNIPRESENT(wwin
))
952 wwin
->flags
.omnipresent
^= 1;
956 *--------------------------------------------------
958 * Create frame, borders and do reparenting
960 *--------------------------------------------------
962 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
963 #ifdef XKB_BUTTON_HINT
964 if (wPreferences
.modelock
)
965 foo
|= WFF_LANGUAGE_BUTTON
;
967 if (!WFLAGP(wwin
, no_titlebar
))
969 if (!WFLAGP(wwin
, no_resizebar
))
970 foo
|= WFF_RESIZEBAR
;
971 if (!WFLAGP(wwin
, no_border
))
974 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
976 &wPreferences
.window_title_clearance
, foo
,
977 scr
->window_title_texture
,
978 scr
->resizebar_texture
,
979 scr
->window_title_pixel
,
980 #ifdef DRAWSTRING_PLUGIN
983 &scr
->window_title_gc
,
986 wwin
->frame
->flags
.is_client_window_frame
= 1;
987 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
989 /* setup button images */
990 wWindowUpdateButtonImages(wwin
);
992 /* hide unused buttons */
994 if (WFLAGP(wwin
, no_close_button
))
995 foo
|= WFF_RIGHT_BUTTON
;
996 if (WFLAGP(wwin
, no_miniaturize_button
))
997 foo
|= WFF_LEFT_BUTTON
;
998 #ifdef XKB_BUTTON_HINT
999 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1000 foo
|= WFF_LANGUAGE_BUTTON
;
1003 wFrameWindowHideButton(wwin
->frame
, foo
);
1005 wwin
->frame
->child
= wwin
;
1008 /* emulate olwm push pin. Make the button look as pushed-in for
1009 * the pinned-out state. When the button is clicked, it will
1010 * revert to the normal position, which means the pin is pinned-in.
1012 if (wwin
->flags
.olwm_push_pin_out
)
1013 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1014 #endif /* OLWM_HINTS */
1016 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
1020 wwin
->frame
->workspace
= workspace
;
1022 wwin
->frame
->on_click_left
= windowIconifyClick
;
1023 #ifdef XKB_BUTTON_HINT
1024 if (wPreferences
.modelock
)
1025 wwin
->frame
->on_click_language
= windowLanguageClick
;
1028 wwin
->frame
->on_click_right
= windowCloseClick
;
1029 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1031 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1032 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1034 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1037 XSelectInput(dpy
, wwin
->client_win
,
1038 wwin
->event_mask
& ~StructureNotifyMask
);
1040 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1041 0, wwin
->frame
->top_width
);
1043 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1049 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1051 /* if gravity is to the south, account for the border sizes */
1053 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1057 * wWindowConfigure() will init the client window's size
1058 * (wwin->client.{width,height}) and all other geometry
1059 * related variables (frame_x,frame_y)
1061 wWindowConfigure(wwin
, x
, y
, width
, height
);
1063 /* to make sure the window receives it's new position after reparenting */
1064 wWindowSynthConfigureNotify(wwin
);
1067 *--------------------------------------------------
1069 * Setup descriptors and save window to internal
1072 *--------------------------------------------------
1075 if (wwin
->main_window
!=None
) {
1079 /* Leader windows do not necessary set themselves as leaders.
1080 * If this is the case, point the leader of this window to
1082 leader
= wWindowFor(wwin
->main_window
);
1083 if (leader
&& leader
->main_window
==None
) {
1084 leader
->main_window
= leader
->client_win
;
1086 app
= wApplicationCreate(scr
, wwin
->main_window
);
1088 app
->last_workspace
= workspace
;
1091 * Do application specific stuff, like setting application
1095 if (wwin
->flags
.hidden
) {
1096 /* if the window was set to hidden because it was hidden
1097 * in a previous incarnation and that state was restored */
1098 app
->flags
.hidden
= 1;
1101 if (app
->flags
.hidden
) {
1102 wwin
->flags
.hidden
= 1;
1107 /* setup the frame descriptor */
1108 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1109 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1110 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1112 /* don't let windows go away if we die */
1113 XAddToSaveSet(dpy
, window
);
1115 XLowerWindow(dpy
, window
);
1117 /* if window is in this workspace and should be mapped, then map it */
1118 if (!wwin
->flags
.miniaturized
1119 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1120 && !wwin
->flags
.hidden
&& !withdraw
) {
1122 /* The following "if" is to avoid crashing of clients that expect
1123 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1124 * after the return from this function.
1126 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1127 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1129 wClientSetState(wwin
, NormalState
, None
);
1133 /* if not auto focus, then map the window under the currently
1135 #define _WIDTH(w) (w)->frame->core->width
1136 #define _HEIGHT(w) (w)->frame->core->height
1137 if (!wPreferences
.auto_focus
&& scr
->focused_window
1138 && !scr
->flags
.startup
&& !transientOwner
1139 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1140 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1141 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1142 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1143 || wwin
->flags
.maximized
)) {
1144 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1152 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1153 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1155 * The brain damaged idiotic non-click to focus modes will
1156 * have trouble with this because:
1158 * 1. window is created and mapped by the client
1159 * 2. window is mapped by wmaker in small size
1160 * 3. window is animated to grow to normal size
1161 * 4. this function returns to normal event loop
1162 * 5. eventually, the EnterNotify event that would trigger
1163 * the window focusing (if the mouse is over that window)
1164 * will be processed by wmaker.
1165 * But since this event will be rather delayed
1166 * (step 3 has a large delay) the time when the event ocurred
1167 * and when it is processed, the client that owns that window
1168 * will reject the XSetInputFocus() for it.
1170 && (wPreferences
.focus_mode
==WKF_CLICK
1171 || wPreferences
.auto_focus
)) {
1172 DoWindowBirth(wwin
);
1178 /* setup stacking descriptor */
1179 if (transientOwner
) {
1180 /* && wPreferences.on_top_transients */
1181 if (transientOwner
) {
1182 wwin
->frame
->core
->stacking
->child_of
=
1183 transientOwner
->frame
->core
;
1186 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1190 if (!scr
->focused_window
) {
1191 /* first window on the list */
1194 scr
->focused_window
= wwin
;
1198 /* add window at beginning of focus window list */
1199 tmp
= scr
->focused_window
;
1208 wGNOMEUpdateClientStateHint(wwin
, True
);
1211 wKWMUpdateClientWorkspace(wwin
);
1212 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1218 *--------------------------------------------------
1220 * Final preparations before window is ready to go
1222 *--------------------------------------------------
1225 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1228 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1229 && !wwin
->flags
.hidden
) {
1230 if (((transientOwner
&& transientOwner
->flags
.focused
)
1231 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1232 wSetFocusTo(scr
, wwin
);
1234 wWindowResetMouseGrabs(wwin
);
1236 if (!WFLAGP(wwin
, no_bind_keys
)) {
1237 wWindowSetKeyGrabs(wwin
);
1240 wGNOMEUpdateClientListHint(scr
);
1243 wwin
->flags
.kwm_managed
= 1;
1245 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1248 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1250 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1253 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1254 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1256 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1257 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1263 *------------------------------------------------------------
1264 * Setup Notification Observers
1265 *------------------------------------------------------------
1267 WMAddNotificationObserver(appearanceObserver
, wwin
,
1268 WNWindowAppearanceSettingsChanged
, wwin
);
1272 *--------------------------------------------------
1274 * Cleanup temporary stuff
1276 *--------------------------------------------------
1280 wWindowDeleteSavedState(win_state
);
1282 /* If the window must be withdrawed, then do it now.
1283 * Must do some optimization, 'though */
1285 wwin
->flags
.mapped
= 0;
1286 wClientSetState(wwin
, WithdrawnState
, None
);
1287 wUnmanageWindow(wwin
, True
, False
);
1299 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1300 char *title
, int x
, int y
, int width
, int height
)
1305 wwin
= wWindowCreate();
1307 WMAddNotificationObserver(appearanceObserver
, wwin
,
1308 WNWindowAppearanceSettingsChanged
, wwin
);
1310 wwin
->flags
.internal_window
= 1;
1312 WSETUFLAG(wwin
, omnipresent
, 1);
1313 WSETUFLAG(wwin
, no_shadeable
, 1);
1314 WSETUFLAG(wwin
, no_resizable
, 1);
1315 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1317 wwin
->focus_mode
= WFM_PASSIVE
;
1319 wwin
->client_win
= window
;
1320 wwin
->screen_ptr
= scr
;
1322 wwin
->transient_for
= owner
;
1326 wwin
->client
.width
= width
;
1327 wwin
->client
.height
= height
;
1329 wwin
->frame_x
= wwin
->client
.x
;
1330 wwin
->frame_y
= wwin
->client
.y
;
1333 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1334 foo
|= WFF_TITLEBAR
;
1335 #ifdef XKB_BUTTON_HINT
1336 foo
|= WFF_LANGUAGE_BUTTON
;
1339 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1340 wwin
->frame_x
, wwin
->frame_y
,
1342 &wPreferences
.window_title_clearance
, foo
,
1343 scr
->window_title_texture
,
1344 scr
->resizebar_texture
,
1345 scr
->window_title_pixel
,
1346 #ifdef DRAWSTRING_PLUGIN
1349 &scr
->window_title_gc
,
1352 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1354 wwin
->frame
->flags
.is_client_window_frame
= 1;
1355 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1357 wFrameWindowChangeTitle(wwin
->frame
, title
);
1359 /* setup button images */
1360 wWindowUpdateButtonImages(wwin
);
1363 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1365 wwin
->frame
->child
= wwin
;
1367 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1369 #ifdef XKB_BUTTON_HINT
1370 if (wPreferences
.modelock
)
1371 wwin
->frame
->on_click_language
= windowLanguageClick
;
1374 wwin
->frame
->on_click_right
= windowCloseClick
;
1376 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1377 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1379 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1381 wwin
->client
.y
+= wwin
->frame
->top_width
;
1382 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1383 0, wwin
->frame
->top_width
);
1385 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1386 wwin
->client
.width
, wwin
->client
.height
);
1388 /* setup the frame descriptor */
1389 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1390 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1391 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1394 XLowerWindow(dpy
, window
);
1395 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1397 /* setup stacking descriptor */
1400 wPreferences
.on_top_transients
&&
1402 wwin
->transient_for
!=None
1403 && wwin
->transient_for
!=scr
->root_win
) {
1405 tmp
= wWindowFor(wwin
->transient_for
);
1407 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1409 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1413 if (!scr
->focused_window
) {
1414 /* first window on the list */
1417 scr
->focused_window
= wwin
;
1421 /* add window at beginning of focus window list */
1422 tmp
= scr
->focused_window
;
1430 if (wwin
->flags
.is_gnustep
== 0)
1431 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1433 /* if (wPreferences.auto_focus)*/
1434 wSetFocusTo(scr
, wwin
);
1436 wWindowResetMouseGrabs(wwin
);
1438 wWindowSetKeyGrabs(wwin
);
1440 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1447 *----------------------------------------------------------------------
1449 * Removes the frame window from a window and destroys all data
1450 * related to it. The window will be reparented back to the root window
1451 * if restore is True.
1454 * Everything related to the window is destroyed and the window
1455 * is removed from the window lists. Focus is set to the previous on the
1457 *----------------------------------------------------------------------
1460 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1462 WCoreWindow
*frame
= wwin
->frame
->core
;
1463 WWindow
*owner
= NULL
;
1464 WWindow
*newFocusedWindow
= NULL
;
1466 WScreen
*scr
= wwin
->screen_ptr
;
1470 wwin
->frame
->workspace
= -1;
1472 wKWMUpdateClientWorkspace(wwin
);
1475 /* First close attribute editor window if open */
1476 if (wwin
->flags
.inspector_open
) {
1477 wCloseInspectorForWindow(wwin
);
1480 /* Close window menu if it's open for this window */
1481 if (wwin
->flags
.menu_open_for_me
) {
1482 CloseWindowMenu(scr
);
1486 if (!wwin
->flags
.internal_window
)
1487 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1489 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1491 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1492 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1495 XUnmapWindow(dpy
, frame
->window
);
1497 XUnmapWindow(dpy
, wwin
->client_win
);
1499 /* deselect window */
1500 wSelectWindow(wwin
, False
);
1502 /* remove all pending events on window */
1503 /* I think this only matters for autoraise */
1504 if (wPreferences
.raise_delay
)
1505 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1509 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
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
1580 || wPreferences
.focus_mode
==WKF_POINTER
) {
1585 /* This is to let the root window get the keyboard input
1586 * if Sloppy focus mode and no other window get focus.
1587 * This way keybindings will not freeze.
1590 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1591 &foo
, &foo
, &foo
, &foo
, &mask
))
1592 tmp
= wWindowFor(win
);
1595 newFocusedWindow
= tmp
;
1597 newFocusedWindow
= NULL
;
1601 if (!wwin
->flags
.internal_window
) {
1603 wGNOMERemoveClient(wwin
);
1606 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1611 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1612 (unsigned)frame
->window
);
1616 if (newFocusedWindow
!= owner
&& owner
) {
1617 if (wwin
->flags
.is_gnustep
== 0)
1618 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1620 wSetFocusTo(scr
, newFocusedWindow
);
1622 wWindowDestroy(wwin
);
1628 wWindowMap(WWindow
*wwin
)
1630 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1631 if (!wwin
->flags
.shaded
) {
1632 /* window will be remapped when getting MapNotify */
1633 XSelectInput(dpy
, wwin
->client_win
,
1634 wwin
->event_mask
& ~StructureNotifyMask
);
1635 XMapWindow(dpy
, wwin
->client_win
);
1636 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1638 wwin
->flags
.mapped
= 1;
1644 wWindowUnmap(WWindow
*wwin
)
1646 wwin
->flags
.mapped
= 0;
1648 /* prevent window withdrawal when getting UnmapNotify */
1649 XSelectInput(dpy
, wwin
->client_win
,
1650 wwin
->event_mask
& ~StructureNotifyMask
);
1651 XUnmapWindow(dpy
, wwin
->client_win
);
1652 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1654 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1660 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1665 #ifdef KEEP_XKB_LOCK_STATUS
1666 if (wPreferences
.modelock
) {
1667 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1669 #endif /* KEEP_XKB_LOCK_STATUS */
1671 wwin
->flags
.semi_focused
= 0;
1673 if (wwin
->flags
.is_gnustep
== 0)
1674 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1676 wwin
->flags
.focused
= 1;
1678 wWindowResetMouseGrabs(wwin
);
1680 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1682 if (owin
== wwin
|| !owin
)
1685 nowner
= wWindowFor(wwin
->transient_for
);
1687 /* new window is a transient for the old window */
1688 if (nowner
== owin
) {
1689 owin
->flags
.semi_focused
= 1;
1690 wWindowUnfocus(nowner
);
1694 oowner
= wWindowFor(owin
->transient_for
);
1696 /* new window is owner of old window */
1697 if (wwin
== oowner
) {
1698 wWindowUnfocus(owin
);
1703 wWindowUnfocus(owin
);
1707 /* new window has same owner of old window */
1708 if (oowner
== nowner
) {
1709 /* prevent unfocusing of owner */
1710 oowner
->flags
.semi_focused
= 0;
1711 wWindowUnfocus(owin
);
1712 oowner
->flags
.semi_focused
= 1;
1717 /* nowner != NULL && oowner != nowner */
1718 nowner
->flags
.semi_focused
= 1;
1719 wWindowUnfocus(nowner
);
1720 wWindowUnfocus(owin
);
1725 wWindowUnfocus(WWindow
*wwin
)
1727 CloseWindowMenu(wwin
->screen_ptr
);
1729 if (wwin
->flags
.is_gnustep
== 0)
1730 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1731 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1733 if (wwin
->transient_for
!=None
1734 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1736 owner
= wWindowFor(wwin
->transient_for
);
1737 if (owner
&& owner
->flags
.semi_focused
) {
1738 owner
->flags
.semi_focused
= 0;
1739 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1740 wWindowUnfocus(owner
);
1741 wFrameWindowPaint(owner
->frame
);
1745 wwin
->flags
.focused
= 0;
1747 wWindowResetMouseGrabs(wwin
);
1749 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1756 *----------------------------------------------------------------------
1758 * wWindowConstrainSize--
1759 * Constrains size for the client window, taking the maximal size,
1760 * window resize increments and other size hints into account.
1763 * The closest size to what was given that the client window can
1766 *----------------------------------------------------------------------
1769 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1771 int width
= *nwidth
;
1772 int height
= *nheight
;
1775 int minW
= 1, minH
= 1;
1776 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1777 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1778 int minAX
= -1, minAY
= -1;
1779 int maxAX
= -1, maxAY
= -1;
1783 if (wwin
->normal_hints
) {
1784 winc
= wwin
->normal_hints
->width_inc
;
1785 hinc
= wwin
->normal_hints
->height_inc
;
1786 minW
= wwin
->normal_hints
->min_width
;
1787 minH
= wwin
->normal_hints
->min_height
;
1788 maxW
= wwin
->normal_hints
->max_width
;
1789 maxH
= wwin
->normal_hints
->max_height
;
1790 if (wwin
->normal_hints
->flags
& PAspect
) {
1791 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1792 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1793 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1794 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1808 /* aspect ratio code borrowed from olwm */
1810 /* adjust max aspect ratio */
1811 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1812 if (maxAX
> maxAY
) {
1813 height
= (width
* maxAY
) / maxAX
;
1814 if (height
> maxH
) {
1816 width
= (height
* maxAX
) / maxAY
;
1819 width
= (height
* maxAX
) / maxAY
;
1822 height
= (width
* maxAY
) / maxAX
;
1827 /* adjust min aspect ratio */
1828 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1829 if (minAX
> minAY
) {
1830 height
= (width
* minAY
) / minAX
;
1831 if (height
< minH
) {
1833 width
= (height
* minAX
) / minAY
;
1836 width
= (height
* minAX
) / minAY
;
1839 height
= (width
* minAY
) / minAX
;
1846 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1848 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1852 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1854 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1857 /* broken stupid apps may cause preposterous values for these.. */
1866 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1868 WScreen
*scr
= wwin
->screen_ptr
;
1872 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1873 || workspace
== wwin
->frame
->workspace
)
1876 if (workspace
!= scr
->current_workspace
) {
1877 /* Sent to other workspace. Unmap window */
1878 if ((wwin
->flags
.mapped
1879 || wwin
->flags
.shaded
1880 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1881 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1883 wapp
= wApplicationOf(wwin
->main_window
);
1885 wapp
->last_workspace
= workspace
;
1887 if (wwin
->flags
.miniaturized
) {
1889 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1890 wwin
->icon
->mapped
= 0;
1894 wSetFocusTo(scr
, NULL
);
1898 /* brought to current workspace. Map window */
1899 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1901 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1902 wwin
->icon
->mapped
= 1;
1904 } else if (!wwin
->flags
.mapped
&&
1905 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1909 if (!IS_OMNIPRESENT(wwin
)) {
1910 wwin
->frame
->workspace
= workspace
;
1911 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1914 wGNOMEUpdateClientStateHint(wwin
, True
);
1917 wKWMUpdateClientWorkspace(wwin
);
1918 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1927 wWindowSynthConfigureNotify(WWindow
*wwin
)
1931 sevent
.type
= ConfigureNotify
;
1932 sevent
.xconfigure
.display
= dpy
;
1933 sevent
.xconfigure
.event
= wwin
->client_win
;
1934 sevent
.xconfigure
.window
= wwin
->client_win
;
1936 sevent
.xconfigure
.x
= wwin
->client
.x
;
1937 sevent
.xconfigure
.y
= wwin
->client
.y
;
1938 sevent
.xconfigure
.width
= wwin
->client
.width
;
1939 sevent
.xconfigure
.height
= wwin
->client
.height
;
1941 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1942 if (WFLAGP(wwin
, no_titlebar
))
1943 sevent
.xconfigure
.above
= None
;
1945 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1947 sevent
.xconfigure
.override_redirect
= False
;
1948 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1950 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1957 *----------------------------------------------------------------------
1958 * wWindowConfigure--
1959 * Configures the frame, decorations and client window to the
1960 * specified geometry. The geometry is not checked for validity,
1961 * wWindowConstrainSize() must be used for that.
1962 * The size parameters are for the client window, but the position is
1964 * The client window receives a ConfigureNotify event, according
1965 * to what ICCCM says.
1971 * Window size and position are changed and client window receives
1972 * a ConfigureNotify event.
1973 *----------------------------------------------------------------------
1976 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1978 int req_x
, req_y
; /* new position of the frame */
1979 int req_width
, req_height
; /* new size of the client */
1981 int synth_notify
= False
;
1984 resize
= (req_width
!=wwin
->client
.width
1985 || req_height
!=wwin
->client
.height
);
1987 * if the window is being moved but not resized then
1988 * send a synthetic ConfigureNotify
1990 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1991 synth_notify
= True
;
1994 if (WFLAGP(wwin
, dont_move_off
))
1995 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1996 req_width
, req_height
);
1998 if (req_width
< MIN_WINDOW_SIZE
)
1999 req_width
= MIN_WINDOW_SIZE
;
2000 if (req_height
< MIN_WINDOW_SIZE
)
2001 req_height
= MIN_WINDOW_SIZE
;
2003 /* If growing, resize inner part before frame,
2004 * if shrinking, resize frame before.
2005 * This will prevent the frame (that can have a different color)
2006 * to be exposed, causing flicker */
2007 if (req_height
> wwin
->frame
->core
->height
2008 || req_width
> wwin
->frame
->core
->width
)
2009 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2011 if (wwin
->flags
.shaded
) {
2012 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2013 req_width
, wwin
->frame
->core
->height
);
2014 wwin
->old_geometry
.height
= req_height
;
2018 h
= req_height
+ wwin
->frame
->top_width
2019 + wwin
->frame
->bottom_width
;
2021 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2024 if (!(req_height
> wwin
->frame
->core
->height
2025 || req_width
> wwin
->frame
->core
->width
))
2026 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2028 wwin
->client
.x
= req_x
;
2029 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2030 wwin
->client
.width
= req_width
;
2031 wwin
->client
.height
= req_height
;
2033 wwin
->client
.x
= req_x
;
2034 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2036 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2038 wwin
->frame_x
= req_x
;
2039 wwin
->frame_y
= req_y
;
2040 if (!WFLAGP(wwin
, no_border
)) {
2041 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2042 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2046 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2047 wWindowSetShape(wwin
);
2052 wWindowSynthConfigureNotify(wwin
);
2058 wWindowMove(wwin
, req_x
, req_y
)
2060 int req_x
, req_y
; /* new position of the frame */
2062 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2063 int synth_notify
= False
;
2065 /* Send a synthetic ConfigureNotify event for every window movement. */
2066 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2067 synth_notify
= True
;
2070 /* A single synthetic ConfigureNotify event is sent at the end of
2071 * a completed (opaque) movement in moveres.c */
2074 if (WFLAGP(wwin
, dont_move_off
))
2075 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2076 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2078 wwin
->client
.x
= req_x
;
2079 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2080 if (!WFLAGP(wwin
, no_border
)) {
2081 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2082 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2085 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2087 wwin
->frame_x
= req_x
;
2088 wwin
->frame_y
= req_y
;
2090 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2092 wWindowSynthConfigureNotify(wwin
);
2098 wWindowUpdateButtonImages(WWindow
*wwin
)
2100 WScreen
*scr
= wwin
->screen_ptr
;
2101 Pixmap pixmap
, mask
;
2102 WFrameWindow
*fwin
= wwin
->frame
;
2104 if (WFLAGP(wwin
, no_titlebar
))
2107 /* miniaturize button */
2109 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2110 if (wwin
->wm_gnustep_attr
2111 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2112 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2114 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2115 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2120 if (fwin
->lbutton_image
2121 && (fwin
->lbutton_image
->image
!= pixmap
2122 || fwin
->lbutton_image
->mask
!= mask
)) {
2123 wPixmapDestroy(fwin
->lbutton_image
);
2124 fwin
->lbutton_image
= NULL
;
2127 if (!fwin
->lbutton_image
) {
2128 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2129 fwin
->lbutton_image
->client_owned
= 1;
2130 fwin
->lbutton_image
->client_owned_mask
= 1;
2133 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2134 wPixmapDestroy(fwin
->lbutton_image
);
2136 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2140 #ifdef XKB_BUTTON_HINT
2141 if (!WFLAGP(wwin
, no_language_button
)) {
2142 if (fwin
->languagebutton_image
&&
2143 !fwin
->languagebutton_image
->shared
) {
2144 wPixmapDestroy(fwin
->languagebutton_image
);
2146 fwin
->languagebutton_image
=
2147 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2153 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2154 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2156 if (!WFLAGP(wwin
, no_close_button
)) {
2157 if (wwin
->wm_gnustep_attr
2158 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2159 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2161 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2162 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2166 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2167 || fwin
->rbutton_image
->mask
!= mask
)) {
2168 wPixmapDestroy(fwin
->rbutton_image
);
2169 fwin
->rbutton_image
= NULL
;
2172 if (!fwin
->rbutton_image
) {
2173 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2174 fwin
->rbutton_image
->client_owned
= 1;
2175 fwin
->rbutton_image
->client_owned_mask
= 1;
2178 } else if (WFLAGP(wwin
, kill_close
)) {
2180 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2181 wPixmapDestroy(fwin
->rbutton_image
);
2183 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2185 } else if (MGFLAGP(wwin
, broken_close
)) {
2187 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2188 wPixmapDestroy(fwin
->rbutton_image
);
2190 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2194 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2195 wPixmapDestroy(fwin
->rbutton_image
);
2197 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2201 /* force buttons to be redrawn */
2202 fwin
->flags
.need_texture_change
= 1;
2203 wFrameWindowPaint(fwin
);
2208 *---------------------------------------------------------------------------
2209 * wWindowConfigureBorders--
2210 * Update window border configuration according to attribute flags.
2212 *---------------------------------------------------------------------------
2215 wWindowConfigureBorders(WWindow
*wwin
)
2221 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2222 #ifdef XKB_BUTTON_HINT
2223 flags
|= WFF_LANGUAGE_BUTTON
;
2225 if (!WFLAGP(wwin
, no_titlebar
))
2226 flags
|= WFF_TITLEBAR
;
2227 if (!WFLAGP(wwin
, no_resizebar
))
2228 flags
|= WFF_RESIZEBAR
;
2229 if (!WFLAGP(wwin
, no_border
))
2230 flags
|= WFF_BORDER
;
2231 if (wwin
->flags
.shaded
)
2232 flags
|= WFF_IS_SHADED
;
2234 oldh
= wwin
->frame
->top_width
;
2235 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2236 if (oldh
!= wwin
->frame
->top_width
) {
2237 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2239 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2240 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2241 wwin
->client
.width
, wwin
->client
.height
);
2245 if (!WFLAGP(wwin
, no_miniaturize_button
)
2246 && wwin
->frame
->flags
.hide_left_button
)
2247 flags
|= WFF_LEFT_BUTTON
;
2249 #ifdef XKB_BUTTON_HINT
2250 if (!WFLAGP(wwin
, no_language_button
)
2251 && wwin
->frame
->flags
.hide_language_button
)
2252 flags
|= WFF_LANGUAGE_BUTTON
;
2255 if (!WFLAGP(wwin
, no_close_button
)
2256 && wwin
->frame
->flags
.hide_right_button
)
2257 flags
|= WFF_RIGHT_BUTTON
;
2260 wWindowUpdateButtonImages(wwin
);
2261 wFrameWindowShowButton(wwin
->frame
, flags
);
2265 if (WFLAGP(wwin
, no_miniaturize_button
)
2266 && !wwin
->frame
->flags
.hide_left_button
)
2267 flags
|= WFF_LEFT_BUTTON
;
2269 #ifdef XKB_BUTTON_HINT
2270 if (WFLAGP(wwin
, no_language_button
)
2271 && !wwin
->frame
->flags
.hide_language_button
)
2272 flags
|= WFF_LANGUAGE_BUTTON
;
2275 if (WFLAGP(wwin
, no_close_button
)
2276 && !wwin
->frame
->flags
.hide_right_button
)
2277 flags
|= WFF_RIGHT_BUTTON
;
2280 wFrameWindowHideButton(wwin
->frame
, flags
);
2283 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2284 wWindowSetShape(wwin
);
2292 wWindowSaveState(WWindow
*wwin
)
2297 memset(data
, 0, sizeof(CARD32
)*10);
2298 data
[0] = wwin
->frame
->workspace
;
2299 data
[1] = wwin
->flags
.miniaturized
;
2300 data
[2] = wwin
->flags
.shaded
;
2301 data
[3] = wwin
->flags
.hidden
;
2303 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2304 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2305 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2308 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2309 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2310 (unsigned char *)data
, 10);
2315 getSavedState(Window window
, WSavedState
**state
)
2319 unsigned long nitems_ret
;
2320 unsigned long bytes_after_ret
;
2323 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2324 True
, _XA_WINDOWMAKER_STATE
,
2325 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2326 (unsigned char **)&data
)!=Success
|| !data
)
2329 *state
= malloc(sizeof(WSavedState
));
2332 (*state
)->workspace
= data
[0];
2333 (*state
)->miniaturized
= data
[1];
2334 (*state
)->shaded
= data
[2];
2335 (*state
)->hidden
= data
[3];
2336 (*state
)->use_geometry
= data
[4];
2337 (*state
)->x
= data
[5];
2338 (*state
)->y
= data
[6];
2339 (*state
)->w
= data
[7];
2340 (*state
)->h
= data
[8];
2341 (*state
)->window_shortcuts
= data
[9];
2345 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2354 wWindowClearShape(WWindow
*wwin
)
2356 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2357 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2362 wWindowSetShape(WWindow
*wwin
)
2366 #ifdef OPTIMIZE_SHAPE
2371 /* only shape is the client's */
2372 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2376 /* Get array of rectangles describing the shape mask */
2377 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2383 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2389 /* insert our decoration rectangles in the rect list */
2390 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2393 if (!WFLAGP(wwin
, no_titlebar
)) {
2395 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2396 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2397 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2400 if (!WFLAGP(wwin
, no_resizebar
)) {
2402 urec
[count
].y
= wwin
->frame
->core
->height
2403 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2404 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2405 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2409 /* shape our frame window */
2410 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2411 0, wwin
->frame
->top_width
, urec
, count
,
2412 ShapeSet
, Unsorted
);
2418 #endif /* OPTIMIZE_SHAPE */
2420 if (!WFLAGP(wwin
, no_titlebar
)) {
2423 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2424 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2427 if (!WFLAGP(wwin
, no_resizebar
)) {
2429 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2430 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2431 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2435 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2436 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2438 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2439 0, wwin
->frame
->top_width
, wwin
->client_win
,
2440 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2445 /* ====================================================================== */
2448 getFocusMode(WWindow
*wwin
)
2452 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2453 if (wwin
->wm_hints
->input
== True
) {
2454 if (wwin
->protocols
.TAKE_FOCUS
)
2455 mode
= WFM_LOCALLY_ACTIVE
;
2459 if (wwin
->protocols
.TAKE_FOCUS
)
2460 mode
= WFM_GLOBALLY_ACTIVE
;
2462 mode
= WFM_NO_INPUT
;
2472 wWindowSetKeyGrabs(WWindow
*wwin
)
2477 for (i
=0; i
<WKBD_LAST
; i
++) {
2478 key
= &wKeyBindings
[i
];
2480 if (key
->keycode
==0)
2482 if (key
->modifier
!=AnyModifier
) {
2483 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2484 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2486 /* Also grab all modifier combinations possible that include,
2487 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2488 * work even if the NumLock/ScrollLock key is on.
2490 wHackedGrabKey(key
->keycode
, key
->modifier
,
2491 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2495 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2496 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2500 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2507 wWindowResetMouseGrabs(WWindow
*wwin
)
2509 /* Mouse grabs can't be done on the client window because of
2510 * ICCCM and because clients that try to do the same will crash.
2512 * But there is a problem wich makes tbar buttons of unfocused
2513 * windows not usable as the click goes to the frame window instead
2514 * of the button itself. Must figure a way to fix that.
2517 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2519 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2520 /* grabs for Meta+drag */
2521 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2522 True
, ButtonPressMask
, GrabModeSync
,
2523 GrabModeAsync
, None
, None
);
2526 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2527 && !wwin
->flags
.is_gnustep
) {
2528 /* the passive grabs to focus the window */
2529 if (wPreferences
.focus_mode
== WKF_CLICK
)
2530 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2531 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2539 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2541 if (attr
->flags
& GSExtraFlagsAttr
) {
2542 if (MGFLAGP(wwin
, broken_close
) !=
2543 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2544 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2545 wWindowUpdateButtonImages(wwin
);
2552 wWindowAddSavedState(char *instance
, char *class, char *command
,
2553 pid_t pid
, WSavedState
*state
)
2555 WWindowState
*wstate
;
2557 wstate
= malloc(sizeof(WWindowState
));
2561 memset(wstate
, 0, sizeof(WWindowState
));
2564 wstate
->instance
= wstrdup(instance
);
2566 wstate
->class = wstrdup(class);
2568 wstate
->command
= wstrdup(command
);
2569 wstate
->state
= state
;
2571 wstate
->next
= windowState
;
2572 windowState
= wstate
;
2575 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2583 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2587 wWindowGetSavedState(Window win
)
2589 char *instance
, *class, *command
=NULL
;
2590 WWindowState
*wstate
= windowState
;
2597 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2599 command
= FlattenStringList(argv
, argc
);
2600 XFreeStringList(argv
);
2605 if (PropGetWMClass(win
, &class, &instance
)) {
2607 if (SAME(instance
, wstate
->instance
) &&
2608 SAME(class, wstate
->class) &&
2609 SAME(command
, wstate
->command
)) {
2612 wstate
= wstate
->next
;
2619 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2623 if (command
) free(command
);
2624 if (instance
) XFree(instance
);
2625 if (class) XFree(class);
2632 wWindowDeleteSavedState(WMagicNumber id
)
2634 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2636 if (!wstate
|| !windowState
)
2641 windowState
= wstate
->next
;
2643 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2644 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2646 if (wstate
->instance
) free(wstate
->instance
);
2647 if (wstate
->class) free(wstate
->class);
2648 if (wstate
->command
) free(wstate
->command
);
2649 free(wstate
->state
);
2653 if (tmp
->next
==wstate
) {
2654 tmp
->next
=wstate
->next
;
2656 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2657 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2659 if (wstate
->instance
) free(wstate
->instance
);
2660 if (wstate
->class) free(wstate
->class);
2661 if (wstate
->command
) free(wstate
->command
);
2662 free(wstate
->state
);
2673 wWindowDeleteSavedStatesForPID(pid_t pid
)
2675 WWindowState
*tmp
, *wstate
;
2681 if (tmp
->pid
== pid
) {
2682 wstate
= windowState
;
2683 windowState
= tmp
->next
;
2685 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2686 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2688 if (wstate
->instance
) free(wstate
->instance
);
2689 if (wstate
->class) free(wstate
->class);
2690 if (wstate
->command
) free(wstate
->command
);
2691 free(wstate
->state
);
2695 if (tmp
->next
->pid
==pid
) {
2697 tmp
->next
= wstate
->next
;
2699 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2700 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2702 if (wstate
->instance
) free(wstate
->instance
);
2703 if (wstate
->class) free(wstate
->class);
2704 if (wstate
->command
) free(wstate
->command
);
2705 free(wstate
->state
);
2715 /* ====================================================================== */
2718 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2720 WWindow
*wwin
= data
;
2722 #ifndef NUMLOCK_HACK
2723 if ((event
->xbutton
.state
& ValidModMask
)
2724 != (event
->xbutton
.state
& ~LockMask
)) {
2725 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2726 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2730 event
->xbutton
.state
&= ValidModMask
;
2732 CloseWindowMenu(wwin
->screen_ptr
);
2734 if (wPreferences
.focus_mode
==WKF_CLICK
2735 && !(event
->xbutton
.state
&ControlMask
)
2736 && !WFLAGP(wwin
, no_focusable
)) {
2737 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2740 if (event
->xbutton
.button
== Button1
)
2741 wRaiseFrame(wwin
->frame
->core
);
2743 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2744 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2745 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2746 GrabModeAsync
, GrabModeAsync
, None
,
2747 None
, CurrentTime
)!=GrabSuccess
) {
2749 wwarning("pointer grab failed for window move");
2755 if (event
->xbutton
.state
& MOD_MASK
) {
2756 /* move the window */
2757 wMouseMoveWindow(wwin
, event
);
2758 XUngrabPointer(dpy
, CurrentTime
);
2760 wMouseResizeWindow(wwin
, event
);
2761 XUngrabPointer(dpy
, CurrentTime
);
2768 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2770 WWindow
*wwin
= data
;
2772 event
->xbutton
.state
&= ValidModMask
;
2774 if (event
->xbutton
.button
==Button1
) {
2775 if (event
->xbutton
.state
== 0) {
2776 if (!WFLAGP(wwin
, no_shadeable
)) {
2778 if (wwin
->flags
.shaded
)
2779 wUnshadeWindow(wwin
);
2786 if (event
->xbutton
.state
& ControlMask
)
2787 dir
|= MAX_VERTICAL
;
2789 if (event
->xbutton
.state
& ShiftMask
) {
2790 dir
|= MAX_HORIZONTAL
;
2791 if (!(event
->xbutton
.state
& ControlMask
))
2792 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2795 /* maximize window */
2796 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2797 if (wwin
->flags
.maximized
)
2798 wUnmaximizeWindow(wwin
);
2800 wMaximizeWindow(wwin
, dir
);
2803 } else if (event
->xbutton
.button
==Button3
) {
2804 if (event
->xbutton
.state
& MOD_MASK
) {
2805 wHideOtherApplications(wwin
);
2807 } else if (event
->xbutton
.button
==Button2
) {
2808 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2814 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2816 WWindow
*wwin
= desc
->parent
;
2818 event
->xbutton
.state
&= ValidModMask
;
2820 CloseWindowMenu(wwin
->screen_ptr
);
2822 if (wPreferences
.focus_mode
==WKF_CLICK
2823 && !(event
->xbutton
.state
&ControlMask
)
2824 && !WFLAGP(wwin
, no_focusable
)) {
2825 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2827 if (event
->xbutton
.button
== Button1
) {
2828 wRaiseFrame(wwin
->frame
->core
);
2831 if (event
->xbutton
.state
& MOD_MASK
) {
2832 /* move the window */
2833 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2834 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2835 GrabModeAsync
, GrabModeAsync
, None
,
2836 None
, CurrentTime
)!=GrabSuccess
) {
2838 wwarning("pointer grab failed for window move");
2842 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2843 wMouseResizeWindow(wwin
, event
);
2845 wMouseMoveWindow(wwin
, event
);
2846 XUngrabPointer(dpy
, CurrentTime
);
2852 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2854 WWindow
*wwin
= (WWindow
*)data
;
2856 #ifndef NUMLOCK_HACK
2857 if ((event
->xbutton
.state
& ValidModMask
)
2858 != (event
->xbutton
.state
& ~LockMask
)) {
2859 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2860 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2863 event
->xbutton
.state
&= ValidModMask
;
2865 CloseWindowMenu(wwin
->screen_ptr
);
2867 if (wPreferences
.focus_mode
==WKF_CLICK
2868 && !(event
->xbutton
.state
&ControlMask
)
2869 && !WFLAGP(wwin
, no_focusable
)) {
2870 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2873 if (event
->xbutton
.button
== Button1
2874 || event
->xbutton
.button
== Button2
) {
2876 if (event
->xbutton
.button
== Button1
) {
2877 if (event
->xbutton
.state
& MOD_MASK
) {
2878 wLowerFrame(wwin
->frame
->core
);
2880 wRaiseFrame(wwin
->frame
->core
);
2883 if ((event
->xbutton
.state
& ShiftMask
)
2884 && !(event
->xbutton
.state
& ControlMask
)) {
2885 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2888 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2889 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2890 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2891 GrabModeAsync
, GrabModeAsync
, None
,
2892 None
, CurrentTime
)!=GrabSuccess
) {
2894 wwarning("pointer grab failed for window move");
2899 /* move the window */
2900 wMouseMoveWindow(wwin
, event
);
2902 XUngrabPointer(dpy
, CurrentTime
);
2903 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2904 && !wwin
->flags
.internal_window
2905 && !WCHECK_STATE(WSTATE_MODAL
)) {
2906 WObjDescriptor
*desc
;
2908 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2909 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2910 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2911 GrabModeAsync
, GrabModeAsync
, None
,
2912 None
, CurrentTime
)!=GrabSuccess
) {
2914 wwarning("pointer grab failed for window move");
2919 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2920 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2922 /* allow drag select */
2923 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2924 event
->xany
.send_event
= True
;
2925 (*desc
->handle_mousedown
)(desc
, event
);
2927 XUngrabPointer(dpy
, CurrentTime
);
2934 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2936 WWindow
*wwin
= data
;
2938 event
->xbutton
.state
&= ValidModMask
;
2940 CloseWindowMenu(wwin
->screen_ptr
);
2942 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2945 /* if control-click, kill the client */
2946 if (event
->xbutton
.state
& ControlMask
) {
2950 if (wwin
->flags
.olwm_push_pin_out
) {
2952 wwin
->flags
.olwm_push_pin_out
= 0;
2954 wOLWMChangePushpinState(wwin
, True
);
2956 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2961 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2962 /* send delete message */
2963 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2970 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2972 WWindow
*wwin
= data
;
2974 CloseWindowMenu(wwin
->screen_ptr
);
2976 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2979 /* send delete message */
2980 if (wwin
->protocols
.DELETE_WINDOW
) {
2981 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2988 #ifdef XKB_BUTTON_HINT
2990 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2992 WWindow
*wwin
= data
;
2993 WFrameWindow
*fwin
= wwin
->frame
;
2994 WScreen
*scr
= fwin
->screen_ptr
;
2995 XkbStateRec staterec
;
2998 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3000 tl
= wwin
->frame
->languagemode
;
3001 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3002 wwin
->frame
->last_languagemode
= tl
;
3003 wSetFocusTo(scr
, wwin
);
3004 wwin
->frame
->languagebutton_image
=
3005 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3006 wwin
->frame
->languagemode
];
3007 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3008 if (event
->xbutton
.button
== Button3
)
3010 wRaiseFrame(fwin
->core
);
3016 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3018 WWindow
*wwin
= data
;
3020 event
->xbutton
.state
&= ValidModMask
;
3022 CloseWindowMenu(wwin
->screen_ptr
);
3024 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3027 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3028 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3032 if ((event
->xbutton
.state
& ControlMask
) ||
3033 (event
->xbutton
.button
== Button3
)) {
3035 wapp
= wApplicationOf(wwin
->main_window
);
3036 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3037 wHideApplication(wapp
);
3038 } else if (event
->xbutton
.state
==0) {
3039 wIconifyWindow(wwin
);