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 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
;
822 if (!IS_OMNIPRESENT(wwin
)) {
823 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
825 if (w
< 0 || w
>= scr
->workspace_count
) {
826 workspace
= win_state
->state
->workspace
;
827 if (workspace
>= scr
->workspace_count
)
828 workspace
= scr
->current_workspace
;
833 workspace
= scr
->current_workspace
;
837 /* if we're restarting, restore saved state (from hints).
838 * This will overwrite previous */
842 if (getSavedState(window
, &wstate
)) {
843 wwin
->flags
.shaded
= wstate
->shaded
;
844 wwin
->flags
.hidden
= wstate
->hidden
;
845 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
846 wwin
->flags
.maximized
= wstate
->maximized
;
847 if (wwin
->flags
.maximized
) {
848 wwin
->old_geometry
.x
= wstate
->x
;
849 wwin
->old_geometry
.y
= wstate
->y
;
850 wwin
->old_geometry
.width
= wstate
->w
;
851 wwin
->old_geometry
.height
= wstate
->h
;
854 workspace
= wstate
->workspace
;
859 /* restore window shortcut */
860 if (wstate
!= NULL
|| win_state
!= NULL
) {
863 if (win_state
!= NULL
)
864 mask
= win_state
->state
->window_shortcuts
;
866 if (wstate
!= NULL
&& mask
== 0)
867 mask
= wstate
->window_shortcuts
;
872 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
874 if (!scr
->shortcutWindows
[i
])
875 scr
->shortcutWindows
[i
] = WMCreateBag(4);
877 WMPutInBag(scr
->shortcutWindows
[i
], wwin
);
882 if (wstate
!= NULL
) {
887 /* don't let transients start miniaturized if their owners are not */
888 if (transientOwner
&& !transientOwner
->flags
.miniaturized
889 && wwin
->flags
.miniaturized
&& !withdraw
) {
890 wwin
->flags
.miniaturized
= 0;
892 wwin
->wm_hints
->initial_state
= NormalState
;
895 /* set workspace on which the window starts */
896 if (workspace
>= 0) {
897 if (workspace
> scr
->workspace_count
-1) {
898 workspace
= workspace
% scr
->workspace_count
;
903 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
905 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
910 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
912 workspace
= transientOwner
->frame
->workspace
;
916 workspace
= scr
->current_workspace
;
921 /* setup window geometry */
922 if (win_state
&& win_state
->state
->w
> 0) {
923 width
= win_state
->state
->w
;
924 height
= win_state
->state
->h
;
926 wWindowConstrainSize(wwin
, &width
, &height
);
928 /* do not ask for window placement if the window is
929 * transient, during startup, if the initial workspace is another one
930 * or if the window wants to start iconic.
931 * If geometry was saved, restore it. */
933 Bool dontBring
= False
;
935 if (win_state
&& win_state
->state
->w
> 0) {
936 x
= win_state
->state
->x
;
937 y
= win_state
->state
->y
;
938 } else if ((wwin
->transient_for
==None
939 || wPreferences
.window_placement
!=WPM_MANUAL
)
940 && !scr
->flags
.startup
941 && workspace
== scr
->current_workspace
942 && !wwin
->flags
.miniaturized
943 && !wwin
->flags
.maximized
944 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
946 if (transientOwner
&& transientOwner
->flags
.mapped
) {
947 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
949 x
= transientOwner
->frame_x
+
950 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
951 y
= transientOwner
->frame_y
+
952 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
956 else if (x
+ width
> scr
->scr_width
)
957 x
= scr
->scr_width
- width
;
961 else if (y
+ height
> scr
->scr_height
)
962 y
= scr
->scr_height
- height
;
964 PlaceWindow(wwin
, &x
, &y
, width
, height
);
966 if (wPreferences
.window_placement
== WPM_MANUAL
)
970 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
971 wScreenBringInside(scr
, &x
, &y
, width
, height
);
974 if (wwin
->flags
.urgent
) {
975 if (!IS_OMNIPRESENT(wwin
))
976 wwin
->flags
.omnipresent
^= 1;
980 *--------------------------------------------------
982 * Create frame, borders and do reparenting
984 *--------------------------------------------------
986 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
987 #ifdef XKB_BUTTON_HINT
988 if (wPreferences
.modelock
)
989 foo
|= WFF_LANGUAGE_BUTTON
;
991 if (!WFLAGP(wwin
, no_titlebar
))
993 if (!WFLAGP(wwin
, no_resizebar
))
994 foo
|= WFF_RESIZEBAR
;
995 if (!WFLAGP(wwin
, no_border
))
998 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1000 &wPreferences
.window_title_clearance
, foo
,
1001 scr
->window_title_texture
,
1002 scr
->resizebar_texture
,
1003 scr
->window_title_pixel
,
1004 #ifdef DRAWSTRING_PLUGIN
1007 &scr
->window_title_gc
,
1010 wwin
->frame
->flags
.is_client_window_frame
= 1;
1011 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1013 /* setup button images */
1014 wWindowUpdateButtonImages(wwin
);
1016 /* hide unused buttons */
1018 if (WFLAGP(wwin
, no_close_button
))
1019 foo
|= WFF_RIGHT_BUTTON
;
1020 if (WFLAGP(wwin
, no_miniaturize_button
))
1021 foo
|= WFF_LEFT_BUTTON
;
1022 #ifdef XKB_BUTTON_HINT
1023 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1024 foo
|= WFF_LANGUAGE_BUTTON
;
1027 wFrameWindowHideButton(wwin
->frame
, foo
);
1029 wwin
->frame
->child
= wwin
;
1032 /* emulate olwm push pin. Make the button look as pushed-in for
1033 * the pinned-out state. When the button is clicked, it will
1034 * revert to the normal position, which means the pin is pinned-in.
1036 if (wwin
->flags
.olwm_push_pin_out
)
1037 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1038 #endif /* OLWM_HINTS */
1040 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
1044 wwin
->frame
->workspace
= workspace
;
1046 wwin
->frame
->on_click_left
= windowIconifyClick
;
1047 #ifdef XKB_BUTTON_HINT
1048 if (wPreferences
.modelock
)
1049 wwin
->frame
->on_click_language
= windowLanguageClick
;
1052 wwin
->frame
->on_click_right
= windowCloseClick
;
1053 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1055 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1056 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1058 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1061 XSelectInput(dpy
, wwin
->client_win
,
1062 wwin
->event_mask
& ~StructureNotifyMask
);
1064 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1065 0, wwin
->frame
->top_width
);
1067 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1073 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1075 /* if gravity is to the south, account for the border sizes */
1077 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1081 * wWindowConfigure() will init the client window's size
1082 * (wwin->client.{width,height}) and all other geometry
1083 * related variables (frame_x,frame_y)
1085 wWindowConfigure(wwin
, x
, y
, width
, height
);
1087 /* to make sure the window receives it's new position after reparenting */
1088 wWindowSynthConfigureNotify(wwin
);
1091 *--------------------------------------------------
1093 * Setup descriptors and save window to internal
1096 *--------------------------------------------------
1099 if (wwin
->main_window
!=None
) {
1103 /* Leader windows do not necessary set themselves as leaders.
1104 * If this is the case, point the leader of this window to
1106 leader
= wWindowFor(wwin
->main_window
);
1107 if (leader
&& leader
->main_window
==None
) {
1108 leader
->main_window
= leader
->client_win
;
1110 app
= wApplicationCreate(scr
, wwin
->main_window
);
1112 app
->last_workspace
= workspace
;
1115 * Do application specific stuff, like setting application
1119 if (wwin
->flags
.hidden
) {
1120 /* if the window was set to hidden because it was hidden
1121 * in a previous incarnation and that state was restored */
1122 app
->flags
.hidden
= 1;
1125 if (app
->flags
.hidden
) {
1126 wwin
->flags
.hidden
= 1;
1131 /* setup the frame descriptor */
1132 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1133 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1134 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1136 /* don't let windows go away if we die */
1137 XAddToSaveSet(dpy
, window
);
1139 XLowerWindow(dpy
, window
);
1141 /* if window is in this workspace and should be mapped, then map it */
1142 if (!wwin
->flags
.miniaturized
1143 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1144 && !wwin
->flags
.hidden
&& !withdraw
) {
1146 /* The following "if" is to avoid crashing of clients that expect
1147 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1148 * after the return from this function.
1150 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1151 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1153 wClientSetState(wwin
, NormalState
, None
);
1157 /* if not auto focus, then map the window under the currently
1159 #define _WIDTH(w) (w)->frame->core->width
1160 #define _HEIGHT(w) (w)->frame->core->height
1161 if (!wPreferences
.auto_focus
&& scr
->focused_window
1162 && !scr
->flags
.startup
&& !transientOwner
1163 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1164 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1165 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1166 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1167 || wwin
->flags
.maximized
)) {
1168 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1176 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1177 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1179 * The brain damaged idiotic non-click to focus modes will
1180 * have trouble with this because:
1182 * 1. window is created and mapped by the client
1183 * 2. window is mapped by wmaker in small size
1184 * 3. window is animated to grow to normal size
1185 * 4. this function returns to normal event loop
1186 * 5. eventually, the EnterNotify event that would trigger
1187 * the window focusing (if the mouse is over that window)
1188 * will be processed by wmaker.
1189 * But since this event will be rather delayed
1190 * (step 3 has a large delay) the time when the event ocurred
1191 * and when it is processed, the client that owns that window
1192 * will reject the XSetInputFocus() for it.
1194 && (wPreferences
.focus_mode
==WKF_CLICK
1195 || wPreferences
.auto_focus
)) {
1196 DoWindowBirth(wwin
);
1202 /* setup stacking descriptor */
1203 if (transientOwner
) {
1204 /* && wPreferences.on_top_transients */
1205 if (transientOwner
) {
1206 wwin
->frame
->core
->stacking
->child_of
=
1207 transientOwner
->frame
->core
;
1210 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1214 if (!scr
->focused_window
) {
1215 /* first window on the list */
1218 scr
->focused_window
= wwin
;
1222 /* add window at beginning of focus window list */
1223 tmp
= scr
->focused_window
;
1232 wGNOMEUpdateClientStateHint(wwin
, True
);
1235 wKWMUpdateClientWorkspace(wwin
);
1236 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1242 *--------------------------------------------------
1244 * Final preparations before window is ready to go
1246 *--------------------------------------------------
1249 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1252 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1253 && !wwin
->flags
.hidden
) {
1254 if (((transientOwner
&& transientOwner
->flags
.focused
)
1255 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1256 wSetFocusTo(scr
, wwin
);
1258 wWindowResetMouseGrabs(wwin
);
1260 if (!WFLAGP(wwin
, no_bind_keys
)) {
1261 wWindowSetKeyGrabs(wwin
);
1264 wGNOMEUpdateClientListHint(scr
);
1267 wwin
->flags
.kwm_managed
= 1;
1269 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1272 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1274 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1277 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1278 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1280 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1281 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1287 *------------------------------------------------------------
1288 * Setup Notification Observers
1289 *------------------------------------------------------------
1291 WMAddNotificationObserver(appearanceObserver
, wwin
,
1292 WNWindowAppearanceSettingsChanged
, wwin
);
1296 *--------------------------------------------------
1298 * Cleanup temporary stuff
1300 *--------------------------------------------------
1304 wWindowDeleteSavedState(win_state
);
1306 /* If the window must be withdrawed, then do it now.
1307 * Must do some optimization, 'though */
1309 wwin
->flags
.mapped
= 0;
1310 wClientSetState(wwin
, WithdrawnState
, None
);
1311 wUnmanageWindow(wwin
, True
, False
);
1323 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1324 char *title
, int x
, int y
, int width
, int height
)
1329 wwin
= wWindowCreate();
1331 WMAddNotificationObserver(appearanceObserver
, wwin
,
1332 WNWindowAppearanceSettingsChanged
, wwin
);
1334 wwin
->flags
.internal_window
= 1;
1336 WSETUFLAG(wwin
, omnipresent
, 1);
1337 WSETUFLAG(wwin
, no_shadeable
, 1);
1338 WSETUFLAG(wwin
, no_resizable
, 1);
1339 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1341 wwin
->focus_mode
= WFM_PASSIVE
;
1343 wwin
->client_win
= window
;
1344 wwin
->screen_ptr
= scr
;
1346 wwin
->transient_for
= owner
;
1350 wwin
->client
.width
= width
;
1351 wwin
->client
.height
= height
;
1353 wwin
->frame_x
= wwin
->client
.x
;
1354 wwin
->frame_y
= wwin
->client
.y
;
1357 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1358 foo
|= WFF_TITLEBAR
;
1359 #ifdef XKB_BUTTON_HINT
1360 foo
|= WFF_LANGUAGE_BUTTON
;
1363 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1364 wwin
->frame_x
, wwin
->frame_y
,
1366 &wPreferences
.window_title_clearance
, foo
,
1367 scr
->window_title_texture
,
1368 scr
->resizebar_texture
,
1369 scr
->window_title_pixel
,
1370 #ifdef DRAWSTRING_PLUGIN
1373 &scr
->window_title_gc
,
1376 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1378 wwin
->frame
->flags
.is_client_window_frame
= 1;
1379 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1381 wFrameWindowChangeTitle(wwin
->frame
, title
);
1383 /* setup button images */
1384 wWindowUpdateButtonImages(wwin
);
1387 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1389 wwin
->frame
->child
= wwin
;
1391 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1393 #ifdef XKB_BUTTON_HINT
1394 if (wPreferences
.modelock
)
1395 wwin
->frame
->on_click_language
= windowLanguageClick
;
1398 wwin
->frame
->on_click_right
= windowCloseClick
;
1400 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1401 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1403 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1405 wwin
->client
.y
+= wwin
->frame
->top_width
;
1406 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1407 0, wwin
->frame
->top_width
);
1409 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1410 wwin
->client
.width
, wwin
->client
.height
);
1412 /* setup the frame descriptor */
1413 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1414 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1415 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1418 XLowerWindow(dpy
, window
);
1419 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1421 /* setup stacking descriptor */
1424 wPreferences
.on_top_transients
&&
1426 wwin
->transient_for
!=None
1427 && wwin
->transient_for
!=scr
->root_win
) {
1429 tmp
= wWindowFor(wwin
->transient_for
);
1431 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1433 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1437 if (!scr
->focused_window
) {
1438 /* first window on the list */
1441 scr
->focused_window
= wwin
;
1445 /* add window at beginning of focus window list */
1446 tmp
= scr
->focused_window
;
1454 if (wwin
->flags
.is_gnustep
== 0)
1455 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1457 /* if (wPreferences.auto_focus)*/
1458 wSetFocusTo(scr
, wwin
);
1460 wWindowResetMouseGrabs(wwin
);
1462 wWindowSetKeyGrabs(wwin
);
1464 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1471 *----------------------------------------------------------------------
1473 * Removes the frame window from a window and destroys all data
1474 * related to it. The window will be reparented back to the root window
1475 * if restore is True.
1478 * Everything related to the window is destroyed and the window
1479 * is removed from the window lists. Focus is set to the previous on the
1481 *----------------------------------------------------------------------
1484 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1486 WCoreWindow
*frame
= wwin
->frame
->core
;
1487 WWindow
*owner
= NULL
;
1488 WWindow
*newFocusedWindow
= NULL
;
1490 WScreen
*scr
= wwin
->screen_ptr
;
1494 wwin
->frame
->workspace
= -1;
1496 wKWMUpdateClientWorkspace(wwin
);
1499 /* First close attribute editor window if open */
1500 if (wwin
->flags
.inspector_open
) {
1501 wCloseInspectorForWindow(wwin
);
1504 /* Close window menu if it's open for this window */
1505 if (wwin
->flags
.menu_open_for_me
) {
1506 CloseWindowMenu(scr
);
1510 if (!wwin
->flags
.internal_window
)
1511 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1513 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1515 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1516 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1519 XUnmapWindow(dpy
, frame
->window
);
1521 XUnmapWindow(dpy
, wwin
->client_win
);
1523 /* deselect window */
1524 wSelectWindow(wwin
, False
);
1526 /* remove all pending events on window */
1527 /* I think this only matters for autoraise */
1528 if (wPreferences
.raise_delay
)
1529 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1533 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1535 /* reparent the window back to the root */
1537 wClientRestore(wwin
);
1539 if (wwin
->transient_for
!=scr
->root_win
) {
1540 owner
= wWindowFor(wwin
->transient_for
);
1542 if (!owner
->flags
.semi_focused
) {
1545 owner
->flags
.semi_focused
= 0;
1550 wasFocused
= wwin
->flags
.focused
;
1552 /* remove from window focus list */
1553 if (!wwin
->prev
&& !wwin
->next
) {
1554 /* was the only window */
1555 scr
->focused_window
= NULL
;
1556 newFocusedWindow
= NULL
;
1561 wwin
->prev
->next
= wwin
->next
;
1563 wwin
->next
->prev
= wwin
->prev
;
1565 scr
->focused_window
= wwin
->prev
;
1566 scr
->focused_window
->next
= NULL
;
1569 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1571 /* if in click to focus mode and the window
1572 * was a transient, focus the owner window
1575 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1576 tmp
= wWindowFor(wwin
->transient_for
);
1577 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1581 /* otherwise, focus the next one in the focus list */
1583 tmp
= scr
->focused_window
;
1584 while (tmp
) { /* look for one in the window list first */
1585 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1586 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1590 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1591 tmp
= scr
->focused_window
;
1593 if (!WFLAGP(tmp
, no_focusable
)
1594 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1601 newFocusedWindow
= tmp
;
1603 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1604 || wPreferences
.focus_mode
==WKF_POINTER
) {
1609 /* This is to let the root window get the keyboard input
1610 * if Sloppy focus mode and no other window get focus.
1611 * This way keybindings will not freeze.
1614 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1615 &foo
, &foo
, &foo
, &foo
, &mask
))
1616 tmp
= wWindowFor(win
);
1619 newFocusedWindow
= tmp
;
1621 newFocusedWindow
= NULL
;
1625 if (!wwin
->flags
.internal_window
) {
1627 wGNOMERemoveClient(wwin
);
1630 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1635 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1636 (unsigned)frame
->window
);
1640 if (newFocusedWindow
!= owner
&& owner
) {
1641 if (wwin
->flags
.is_gnustep
== 0)
1642 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1644 wSetFocusTo(scr
, newFocusedWindow
);
1646 wWindowDestroy(wwin
);
1652 wWindowMap(WWindow
*wwin
)
1654 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1655 if (!wwin
->flags
.shaded
) {
1656 /* window will be remapped when getting MapNotify */
1657 XSelectInput(dpy
, wwin
->client_win
,
1658 wwin
->event_mask
& ~StructureNotifyMask
);
1659 XMapWindow(dpy
, wwin
->client_win
);
1660 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1662 wwin
->flags
.mapped
= 1;
1668 wWindowUnmap(WWindow
*wwin
)
1670 wwin
->flags
.mapped
= 0;
1672 /* prevent window withdrawal when getting UnmapNotify */
1673 XSelectInput(dpy
, wwin
->client_win
,
1674 wwin
->event_mask
& ~StructureNotifyMask
);
1675 XUnmapWindow(dpy
, wwin
->client_win
);
1676 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1678 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1684 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1689 #ifdef KEEP_XKB_LOCK_STATUS
1690 if (wPreferences
.modelock
) {
1691 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1693 #endif /* KEEP_XKB_LOCK_STATUS */
1695 wwin
->flags
.semi_focused
= 0;
1697 if (wwin
->flags
.is_gnustep
== 0)
1698 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1700 wwin
->flags
.focused
= 1;
1702 wWindowResetMouseGrabs(wwin
);
1704 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1706 if (owin
== wwin
|| !owin
)
1709 nowner
= wWindowFor(wwin
->transient_for
);
1711 /* new window is a transient for the old window */
1712 if (nowner
== owin
) {
1713 owin
->flags
.semi_focused
= 1;
1714 wWindowUnfocus(nowner
);
1718 oowner
= wWindowFor(owin
->transient_for
);
1720 /* new window is owner of old window */
1721 if (wwin
== oowner
) {
1722 wWindowUnfocus(owin
);
1727 wWindowUnfocus(owin
);
1731 /* new window has same owner of old window */
1732 if (oowner
== nowner
) {
1733 /* prevent unfocusing of owner */
1734 oowner
->flags
.semi_focused
= 0;
1735 wWindowUnfocus(owin
);
1736 oowner
->flags
.semi_focused
= 1;
1741 /* nowner != NULL && oowner != nowner */
1742 nowner
->flags
.semi_focused
= 1;
1743 wWindowUnfocus(nowner
);
1744 wWindowUnfocus(owin
);
1749 wWindowUnfocus(WWindow
*wwin
)
1751 CloseWindowMenu(wwin
->screen_ptr
);
1753 if (wwin
->flags
.is_gnustep
== 0)
1754 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1755 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1757 if (wwin
->transient_for
!=None
1758 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1760 owner
= wWindowFor(wwin
->transient_for
);
1761 if (owner
&& owner
->flags
.semi_focused
) {
1762 owner
->flags
.semi_focused
= 0;
1763 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1764 wWindowUnfocus(owner
);
1765 wFrameWindowPaint(owner
->frame
);
1769 wwin
->flags
.focused
= 0;
1771 wWindowResetMouseGrabs(wwin
);
1773 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1780 *----------------------------------------------------------------------
1782 * wWindowConstrainSize--
1783 * Constrains size for the client window, taking the maximal size,
1784 * window resize increments and other size hints into account.
1787 * The closest size to what was given that the client window can
1790 *----------------------------------------------------------------------
1793 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1795 int width
= *nwidth
;
1796 int height
= *nheight
;
1799 int minW
= 1, minH
= 1;
1800 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1801 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1802 int minAX
= -1, minAY
= -1;
1803 int maxAX
= -1, maxAY
= -1;
1807 if (wwin
->normal_hints
) {
1808 winc
= wwin
->normal_hints
->width_inc
;
1809 hinc
= wwin
->normal_hints
->height_inc
;
1810 minW
= wwin
->normal_hints
->min_width
;
1811 minH
= wwin
->normal_hints
->min_height
;
1812 maxW
= wwin
->normal_hints
->max_width
;
1813 maxH
= wwin
->normal_hints
->max_height
;
1814 if (wwin
->normal_hints
->flags
& PAspect
) {
1815 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1816 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1817 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1818 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1832 /* aspect ratio code borrowed from olwm */
1834 /* adjust max aspect ratio */
1835 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1836 if (maxAX
> maxAY
) {
1837 height
= (width
* maxAY
) / maxAX
;
1838 if (height
> maxH
) {
1840 width
= (height
* maxAX
) / maxAY
;
1843 width
= (height
* maxAX
) / maxAY
;
1846 height
= (width
* maxAY
) / maxAX
;
1851 /* adjust min aspect ratio */
1852 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1853 if (minAX
> minAY
) {
1854 height
= (width
* minAY
) / minAX
;
1855 if (height
< minH
) {
1857 width
= (height
* minAX
) / minAY
;
1860 width
= (height
* minAX
) / minAY
;
1863 height
= (width
* minAY
) / minAX
;
1870 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1872 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1876 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1878 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1881 /* broken stupid apps may cause preposterous values for these.. */
1890 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1892 WScreen
*scr
= wwin
->screen_ptr
;
1896 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1897 || workspace
== wwin
->frame
->workspace
)
1900 if (workspace
!= scr
->current_workspace
) {
1901 /* Sent to other workspace. Unmap window */
1902 if ((wwin
->flags
.mapped
1903 || wwin
->flags
.shaded
1904 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1905 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1907 wapp
= wApplicationOf(wwin
->main_window
);
1909 wapp
->last_workspace
= workspace
;
1911 if (wwin
->flags
.miniaturized
) {
1913 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1914 wwin
->icon
->mapped
= 0;
1918 wSetFocusTo(scr
, NULL
);
1922 /* brought to current workspace. Map window */
1923 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1925 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1926 wwin
->icon
->mapped
= 1;
1928 } else if (!wwin
->flags
.mapped
&&
1929 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1933 if (!IS_OMNIPRESENT(wwin
)) {
1934 wwin
->frame
->workspace
= workspace
;
1935 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1938 wGNOMEUpdateClientStateHint(wwin
, True
);
1941 wKWMUpdateClientWorkspace(wwin
);
1942 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1951 wWindowSynthConfigureNotify(WWindow
*wwin
)
1955 sevent
.type
= ConfigureNotify
;
1956 sevent
.xconfigure
.display
= dpy
;
1957 sevent
.xconfigure
.event
= wwin
->client_win
;
1958 sevent
.xconfigure
.window
= wwin
->client_win
;
1960 sevent
.xconfigure
.x
= wwin
->client
.x
;
1961 sevent
.xconfigure
.y
= wwin
->client
.y
;
1962 sevent
.xconfigure
.width
= wwin
->client
.width
;
1963 sevent
.xconfigure
.height
= wwin
->client
.height
;
1965 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1966 if (WFLAGP(wwin
, no_titlebar
))
1967 sevent
.xconfigure
.above
= None
;
1969 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1971 sevent
.xconfigure
.override_redirect
= False
;
1972 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1974 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1981 *----------------------------------------------------------------------
1982 * wWindowConfigure--
1983 * Configures the frame, decorations and client window to the
1984 * specified geometry. The geometry is not checked for validity,
1985 * wWindowConstrainSize() must be used for that.
1986 * The size parameters are for the client window, but the position is
1988 * The client window receives a ConfigureNotify event, according
1989 * to what ICCCM says.
1995 * Window size and position are changed and client window receives
1996 * a ConfigureNotify event.
1997 *----------------------------------------------------------------------
2000 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2002 int req_x
, req_y
; /* new position of the frame */
2003 int req_width
, req_height
; /* new size of the client */
2005 int synth_notify
= False
;
2008 resize
= (req_width
!=wwin
->client
.width
2009 || req_height
!=wwin
->client
.height
);
2011 * if the window is being moved but not resized then
2012 * send a synthetic ConfigureNotify
2014 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2015 synth_notify
= True
;
2018 if (WFLAGP(wwin
, dont_move_off
))
2019 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2020 req_width
, req_height
);
2022 if (req_width
< MIN_WINDOW_SIZE
)
2023 req_width
= MIN_WINDOW_SIZE
;
2024 if (req_height
< MIN_WINDOW_SIZE
)
2025 req_height
= MIN_WINDOW_SIZE
;
2027 /* If growing, resize inner part before frame,
2028 * if shrinking, resize frame before.
2029 * This will prevent the frame (that can have a different color)
2030 * to be exposed, causing flicker */
2031 if (req_height
> wwin
->frame
->core
->height
2032 || req_width
> wwin
->frame
->core
->width
)
2033 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2035 if (wwin
->flags
.shaded
) {
2036 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2037 req_width
, wwin
->frame
->core
->height
);
2038 wwin
->old_geometry
.height
= req_height
;
2042 h
= req_height
+ wwin
->frame
->top_width
2043 + wwin
->frame
->bottom_width
;
2045 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2048 if (!(req_height
> wwin
->frame
->core
->height
2049 || req_width
> wwin
->frame
->core
->width
))
2050 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2052 wwin
->client
.x
= req_x
;
2053 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2054 wwin
->client
.width
= req_width
;
2055 wwin
->client
.height
= req_height
;
2057 wwin
->client
.x
= req_x
;
2058 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2060 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2062 wwin
->frame_x
= req_x
;
2063 wwin
->frame_y
= req_y
;
2064 if (!WFLAGP(wwin
, no_border
)) {
2065 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2066 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2070 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2071 wWindowSetShape(wwin
);
2076 wWindowSynthConfigureNotify(wwin
);
2082 wWindowMove(wwin
, req_x
, req_y
)
2084 int req_x
, req_y
; /* new position of the frame */
2086 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2087 int synth_notify
= False
;
2089 /* Send a synthetic ConfigureNotify event for every window movement. */
2090 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2091 synth_notify
= True
;
2094 /* A single synthetic ConfigureNotify event is sent at the end of
2095 * a completed (opaque) movement in moveres.c */
2098 if (WFLAGP(wwin
, dont_move_off
))
2099 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2100 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2102 wwin
->client
.x
= req_x
;
2103 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2104 if (!WFLAGP(wwin
, no_border
)) {
2105 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2106 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2109 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2111 wwin
->frame_x
= req_x
;
2112 wwin
->frame_y
= req_y
;
2114 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2116 wWindowSynthConfigureNotify(wwin
);
2122 wWindowUpdateButtonImages(WWindow
*wwin
)
2124 WScreen
*scr
= wwin
->screen_ptr
;
2125 Pixmap pixmap
, mask
;
2126 WFrameWindow
*fwin
= wwin
->frame
;
2128 if (WFLAGP(wwin
, no_titlebar
))
2131 /* miniaturize button */
2133 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2134 if (wwin
->wm_gnustep_attr
2135 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2136 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2138 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2139 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2144 if (fwin
->lbutton_image
2145 && (fwin
->lbutton_image
->image
!= pixmap
2146 || fwin
->lbutton_image
->mask
!= mask
)) {
2147 wPixmapDestroy(fwin
->lbutton_image
);
2148 fwin
->lbutton_image
= NULL
;
2151 if (!fwin
->lbutton_image
) {
2152 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2153 fwin
->lbutton_image
->client_owned
= 1;
2154 fwin
->lbutton_image
->client_owned_mask
= 1;
2157 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2158 wPixmapDestroy(fwin
->lbutton_image
);
2160 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2164 #ifdef XKB_BUTTON_HINT
2165 if (!WFLAGP(wwin
, no_language_button
)) {
2166 if (fwin
->languagebutton_image
&&
2167 !fwin
->languagebutton_image
->shared
) {
2168 wPixmapDestroy(fwin
->languagebutton_image
);
2170 fwin
->languagebutton_image
=
2171 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2177 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2178 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2180 if (!WFLAGP(wwin
, no_close_button
)) {
2181 if (wwin
->wm_gnustep_attr
2182 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2183 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2185 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2186 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2190 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2191 || fwin
->rbutton_image
->mask
!= mask
)) {
2192 wPixmapDestroy(fwin
->rbutton_image
);
2193 fwin
->rbutton_image
= NULL
;
2196 if (!fwin
->rbutton_image
) {
2197 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2198 fwin
->rbutton_image
->client_owned
= 1;
2199 fwin
->rbutton_image
->client_owned_mask
= 1;
2202 } else if (WFLAGP(wwin
, kill_close
)) {
2204 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2205 wPixmapDestroy(fwin
->rbutton_image
);
2207 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2209 } else if (MGFLAGP(wwin
, broken_close
)) {
2211 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2212 wPixmapDestroy(fwin
->rbutton_image
);
2214 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2218 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2219 wPixmapDestroy(fwin
->rbutton_image
);
2221 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2225 /* force buttons to be redrawn */
2226 fwin
->flags
.need_texture_change
= 1;
2227 wFrameWindowPaint(fwin
);
2232 *---------------------------------------------------------------------------
2233 * wWindowConfigureBorders--
2234 * Update window border configuration according to attribute flags.
2236 *---------------------------------------------------------------------------
2239 wWindowConfigureBorders(WWindow
*wwin
)
2245 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2246 #ifdef XKB_BUTTON_HINT
2247 flags
|= WFF_LANGUAGE_BUTTON
;
2249 if (!WFLAGP(wwin
, no_titlebar
))
2250 flags
|= WFF_TITLEBAR
;
2251 if (!WFLAGP(wwin
, no_resizebar
))
2252 flags
|= WFF_RESIZEBAR
;
2253 if (!WFLAGP(wwin
, no_border
))
2254 flags
|= WFF_BORDER
;
2255 if (wwin
->flags
.shaded
)
2256 flags
|= WFF_IS_SHADED
;
2258 oldh
= wwin
->frame
->top_width
;
2259 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2260 if (oldh
!= wwin
->frame
->top_width
) {
2261 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2263 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2264 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2265 wwin
->client
.width
, wwin
->client
.height
);
2269 if (!WFLAGP(wwin
, no_miniaturize_button
)
2270 && wwin
->frame
->flags
.hide_left_button
)
2271 flags
|= WFF_LEFT_BUTTON
;
2273 #ifdef XKB_BUTTON_HINT
2274 if (!WFLAGP(wwin
, no_language_button
)
2275 && wwin
->frame
->flags
.hide_language_button
)
2276 flags
|= WFF_LANGUAGE_BUTTON
;
2279 if (!WFLAGP(wwin
, no_close_button
)
2280 && wwin
->frame
->flags
.hide_right_button
)
2281 flags
|= WFF_RIGHT_BUTTON
;
2284 wWindowUpdateButtonImages(wwin
);
2285 wFrameWindowShowButton(wwin
->frame
, flags
);
2289 if (WFLAGP(wwin
, no_miniaturize_button
)
2290 && !wwin
->frame
->flags
.hide_left_button
)
2291 flags
|= WFF_LEFT_BUTTON
;
2293 #ifdef XKB_BUTTON_HINT
2294 if (WFLAGP(wwin
, no_language_button
)
2295 && !wwin
->frame
->flags
.hide_language_button
)
2296 flags
|= WFF_LANGUAGE_BUTTON
;
2299 if (WFLAGP(wwin
, no_close_button
)
2300 && !wwin
->frame
->flags
.hide_right_button
)
2301 flags
|= WFF_RIGHT_BUTTON
;
2304 wFrameWindowHideButton(wwin
->frame
, flags
);
2307 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2308 wWindowSetShape(wwin
);
2316 wWindowSaveState(WWindow
*wwin
)
2321 memset(data
, 0, sizeof(CARD32
)*10);
2322 data
[0] = wwin
->frame
->workspace
;
2323 data
[1] = wwin
->flags
.miniaturized
;
2324 data
[2] = wwin
->flags
.shaded
;
2325 data
[3] = wwin
->flags
.hidden
;
2326 data
[4] = wwin
->flags
.maximized
;
2327 if (wwin
->flags
.maximized
== 0) {
2328 data
[5] = wwin
->frame_x
;
2329 data
[6] = wwin
->frame_y
;
2330 data
[7] = wwin
->frame
->core
->width
;
2331 data
[8] = wwin
->frame
->core
->height
;
2333 data
[5] = wwin
->old_geometry
.x
;
2334 data
[6] = wwin
->old_geometry
.y
;
2335 data
[7] = wwin
->old_geometry
.width
;
2336 data
[8] = wwin
->old_geometry
.height
;
2339 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2340 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2341 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2344 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2345 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2346 (unsigned char *)data
, 10);
2351 getSavedState(Window window
, WSavedState
**state
)
2355 unsigned long nitems_ret
;
2356 unsigned long bytes_after_ret
;
2359 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2360 True
, _XA_WINDOWMAKER_STATE
,
2361 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2362 (unsigned char **)&data
)!=Success
|| !data
)
2365 *state
= malloc(sizeof(WSavedState
));
2368 (*state
)->workspace
= data
[0];
2369 (*state
)->miniaturized
= data
[1];
2370 (*state
)->shaded
= data
[2];
2371 (*state
)->hidden
= data
[3];
2372 (*state
)->maximized
= data
[4];
2373 (*state
)->x
= data
[5];
2374 (*state
)->y
= data
[6];
2375 (*state
)->w
= data
[7];
2376 (*state
)->h
= data
[8];
2377 (*state
)->window_shortcuts
= data
[9];
2381 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2390 wWindowClearShape(WWindow
*wwin
)
2392 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2393 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2398 wWindowSetShape(WWindow
*wwin
)
2402 #ifdef OPTIMIZE_SHAPE
2407 /* only shape is the client's */
2408 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2412 /* Get array of rectangles describing the shape mask */
2413 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2419 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2425 /* insert our decoration rectangles in the rect list */
2426 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2429 if (!WFLAGP(wwin
, no_titlebar
)) {
2431 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2432 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2433 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2436 if (!WFLAGP(wwin
, no_resizebar
)) {
2438 urec
[count
].y
= wwin
->frame
->core
->height
2439 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2440 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2441 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2445 /* shape our frame window */
2446 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2447 0, wwin
->frame
->top_width
, urec
, count
,
2448 ShapeSet
, Unsorted
);
2454 #endif /* OPTIMIZE_SHAPE */
2456 if (!WFLAGP(wwin
, no_titlebar
)) {
2459 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2460 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2463 if (!WFLAGP(wwin
, no_resizebar
)) {
2465 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2466 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2467 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2471 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2472 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2474 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2475 0, wwin
->frame
->top_width
, wwin
->client_win
,
2476 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2481 /* ====================================================================== */
2484 getFocusMode(WWindow
*wwin
)
2488 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2489 if (wwin
->wm_hints
->input
== True
) {
2490 if (wwin
->protocols
.TAKE_FOCUS
)
2491 mode
= WFM_LOCALLY_ACTIVE
;
2495 if (wwin
->protocols
.TAKE_FOCUS
)
2496 mode
= WFM_GLOBALLY_ACTIVE
;
2498 mode
= WFM_NO_INPUT
;
2508 wWindowSetKeyGrabs(WWindow
*wwin
)
2513 for (i
=0; i
<WKBD_LAST
; i
++) {
2514 key
= &wKeyBindings
[i
];
2516 if (key
->keycode
==0)
2518 if (key
->modifier
!=AnyModifier
) {
2519 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2520 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2522 /* Also grab all modifier combinations possible that include,
2523 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2524 * work even if the NumLock/ScrollLock key is on.
2526 wHackedGrabKey(key
->keycode
, key
->modifier
,
2527 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2531 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2532 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2536 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2543 wWindowResetMouseGrabs(WWindow
*wwin
)
2545 /* Mouse grabs can't be done on the client window because of
2546 * ICCCM and because clients that try to do the same will crash.
2548 * But there is a problem wich makes tbar buttons of unfocused
2549 * windows not usable as the click goes to the frame window instead
2550 * of the button itself. Must figure a way to fix that.
2553 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2555 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2556 /* grabs for Meta+drag */
2557 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2558 True
, ButtonPressMask
, GrabModeSync
,
2559 GrabModeAsync
, None
, None
);
2562 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2563 && !wwin
->flags
.is_gnustep
) {
2564 /* the passive grabs to focus the window */
2565 /* if (wPreferences.focus_mode == WKF_CLICK) */
2566 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2567 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2575 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2577 if (attr
->flags
& GSExtraFlagsAttr
) {
2578 if (MGFLAGP(wwin
, broken_close
) !=
2579 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2580 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2581 wWindowUpdateButtonImages(wwin
);
2588 wWindowAddSavedState(char *instance
, char *class, char *command
,
2589 pid_t pid
, WSavedState
*state
)
2591 WWindowState
*wstate
;
2593 wstate
= malloc(sizeof(WWindowState
));
2597 memset(wstate
, 0, sizeof(WWindowState
));
2600 wstate
->instance
= wstrdup(instance
);
2602 wstate
->class = wstrdup(class);
2604 wstate
->command
= wstrdup(command
);
2605 wstate
->state
= state
;
2607 wstate
->next
= windowState
;
2608 windowState
= wstate
;
2611 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2619 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2623 wWindowGetSavedState(Window win
)
2625 char *instance
, *class, *command
=NULL
;
2626 WWindowState
*wstate
= windowState
;
2633 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2635 command
= wtokenjoin(argv
, argc
);
2636 XFreeStringList(argv
);
2641 if (PropGetWMClass(win
, &class, &instance
)) {
2643 if (SAME(instance
, wstate
->instance
) &&
2644 SAME(class, wstate
->class) &&
2645 SAME(command
, wstate
->command
)) {
2648 wstate
= wstate
->next
;
2655 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2659 if (command
) wfree(command
);
2660 if (instance
) XFree(instance
);
2661 if (class) XFree(class);
2668 wWindowDeleteSavedState(WMagicNumber id
)
2670 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2672 if (!wstate
|| !windowState
)
2677 windowState
= wstate
->next
;
2679 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2680 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2682 if (wstate
->instance
) wfree(wstate
->instance
);
2683 if (wstate
->class) wfree(wstate
->class);
2684 if (wstate
->command
) wfree(wstate
->command
);
2685 wfree(wstate
->state
);
2689 if (tmp
->next
==wstate
) {
2690 tmp
->next
=wstate
->next
;
2692 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2693 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2695 if (wstate
->instance
) wfree(wstate
->instance
);
2696 if (wstate
->class) wfree(wstate
->class);
2697 if (wstate
->command
) wfree(wstate
->command
);
2698 wfree(wstate
->state
);
2709 wWindowDeleteSavedStatesForPID(pid_t pid
)
2711 WWindowState
*tmp
, *wstate
;
2717 if (tmp
->pid
== pid
) {
2718 wstate
= windowState
;
2719 windowState
= tmp
->next
;
2721 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2722 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2724 if (wstate
->instance
) wfree(wstate
->instance
);
2725 if (wstate
->class) wfree(wstate
->class);
2726 if (wstate
->command
) wfree(wstate
->command
);
2727 wfree(wstate
->state
);
2731 if (tmp
->next
->pid
==pid
) {
2733 tmp
->next
= wstate
->next
;
2735 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2736 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2738 if (wstate
->instance
) wfree(wstate
->instance
);
2739 if (wstate
->class) wfree(wstate
->class);
2740 if (wstate
->command
) wfree(wstate
->command
);
2741 wfree(wstate
->state
);
2751 /* ====================================================================== */
2754 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2756 WWindow
*wwin
= data
;
2758 #ifndef NUMLOCK_HACK
2759 if ((event
->xbutton
.state
& ValidModMask
)
2760 != (event
->xbutton
.state
& ~LockMask
)) {
2761 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2762 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2766 event
->xbutton
.state
&= ValidModMask
;
2768 CloseWindowMenu(wwin
->screen_ptr
);
2770 if (wPreferences
.focus_mode
==WKF_CLICK
2771 && !(event
->xbutton
.state
&ControlMask
)
2772 && !WFLAGP(wwin
, no_focusable
)) {
2773 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2776 if (event
->xbutton
.button
== Button1
)
2777 wRaiseFrame(wwin
->frame
->core
);
2779 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2780 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2781 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2782 GrabModeAsync
, GrabModeAsync
, None
,
2783 None
, CurrentTime
)!=GrabSuccess
) {
2785 wwarning("pointer grab failed for window move");
2791 if (event
->xbutton
.state
& MOD_MASK
) {
2792 /* move the window */
2793 wMouseMoveWindow(wwin
, event
);
2794 XUngrabPointer(dpy
, CurrentTime
);
2796 wMouseResizeWindow(wwin
, event
);
2797 XUngrabPointer(dpy
, CurrentTime
);
2804 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2806 WWindow
*wwin
= data
;
2808 event
->xbutton
.state
&= ValidModMask
;
2810 if (event
->xbutton
.button
==Button1
) {
2811 if (event
->xbutton
.state
== 0) {
2812 if (!WFLAGP(wwin
, no_shadeable
)) {
2814 if (wwin
->flags
.shaded
)
2815 wUnshadeWindow(wwin
);
2822 if (event
->xbutton
.state
& ControlMask
)
2823 dir
|= MAX_VERTICAL
;
2825 if (event
->xbutton
.state
& ShiftMask
) {
2826 dir
|= MAX_HORIZONTAL
;
2827 if (!(event
->xbutton
.state
& ControlMask
))
2828 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2831 /* maximize window */
2832 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2833 int ndir
= dir
^ wwin
->flags
.maximized
;
2834 if (wwin
->flags
.maximized
!= 0)
2835 wUnmaximizeWindow(wwin
);
2837 wMaximizeWindow(wwin
, ndir
);
2840 } else if (event
->xbutton
.button
==Button3
) {
2841 if (event
->xbutton
.state
& MOD_MASK
) {
2842 wHideOtherApplications(wwin
);
2844 } else if (event
->xbutton
.button
==Button2
) {
2845 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2851 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2853 WWindow
*wwin
= desc
->parent
;
2855 event
->xbutton
.state
&= ValidModMask
;
2857 CloseWindowMenu(wwin
->screen_ptr
);
2859 if (/*wPreferences.focus_mode==WKF_CLICK
2860 &&*/ !(event
->xbutton
.state
&ControlMask
)
2861 && !WFLAGP(wwin
, no_focusable
)) {
2862 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2864 if (event
->xbutton
.button
== Button1
) {
2865 wRaiseFrame(wwin
->frame
->core
);
2868 if (event
->xbutton
.state
& MOD_MASK
) {
2869 /* move the window */
2870 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2871 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2872 GrabModeAsync
, GrabModeAsync
, None
,
2873 None
, CurrentTime
)!=GrabSuccess
) {
2875 wwarning("pointer grab failed for window move");
2879 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2880 wMouseResizeWindow(wwin
, event
);
2882 wMouseMoveWindow(wwin
, event
);
2883 XUngrabPointer(dpy
, CurrentTime
);
2889 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2891 WWindow
*wwin
= (WWindow
*)data
;
2893 #ifndef NUMLOCK_HACK
2894 if ((event
->xbutton
.state
& ValidModMask
)
2895 != (event
->xbutton
.state
& ~LockMask
)) {
2896 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2897 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2900 event
->xbutton
.state
&= ValidModMask
;
2902 CloseWindowMenu(wwin
->screen_ptr
);
2904 if (wPreferences
.focus_mode
==WKF_CLICK
2905 && !(event
->xbutton
.state
&ControlMask
)
2906 && !WFLAGP(wwin
, no_focusable
)) {
2907 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2910 if (event
->xbutton
.button
== Button1
2911 || event
->xbutton
.button
== Button2
) {
2913 if (event
->xbutton
.button
== Button1
) {
2914 if (event
->xbutton
.state
& MOD_MASK
) {
2915 wLowerFrame(wwin
->frame
->core
);
2917 wRaiseFrame(wwin
->frame
->core
);
2920 if ((event
->xbutton
.state
& ShiftMask
)
2921 && !(event
->xbutton
.state
& ControlMask
)) {
2922 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2925 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2926 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2927 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2928 GrabModeAsync
, GrabModeAsync
, None
,
2929 None
, CurrentTime
)!=GrabSuccess
) {
2931 wwarning("pointer grab failed for window move");
2936 /* move the window */
2937 wMouseMoveWindow(wwin
, event
);
2939 XUngrabPointer(dpy
, CurrentTime
);
2940 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2941 && !wwin
->flags
.internal_window
2942 && !WCHECK_STATE(WSTATE_MODAL
)) {
2943 WObjDescriptor
*desc
;
2945 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2946 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2947 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2948 GrabModeAsync
, GrabModeAsync
, None
,
2949 None
, CurrentTime
)!=GrabSuccess
) {
2951 wwarning("pointer grab failed for window move");
2956 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2957 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2959 /* allow drag select */
2960 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2961 event
->xany
.send_event
= True
;
2962 (*desc
->handle_mousedown
)(desc
, event
);
2964 XUngrabPointer(dpy
, CurrentTime
);
2971 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2973 WWindow
*wwin
= data
;
2975 event
->xbutton
.state
&= ValidModMask
;
2977 CloseWindowMenu(wwin
->screen_ptr
);
2979 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2982 /* if control-click, kill the client */
2983 if (event
->xbutton
.state
& ControlMask
) {
2987 if (wwin
->flags
.olwm_push_pin_out
) {
2989 wwin
->flags
.olwm_push_pin_out
= 0;
2991 wOLWMChangePushpinState(wwin
, True
);
2993 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2998 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2999 /* send delete message */
3000 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3007 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3009 WWindow
*wwin
= data
;
3011 CloseWindowMenu(wwin
->screen_ptr
);
3013 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3016 /* send delete message */
3017 if (wwin
->protocols
.DELETE_WINDOW
) {
3018 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3025 #ifdef XKB_BUTTON_HINT
3027 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3029 WWindow
*wwin
= data
;
3030 WFrameWindow
*fwin
= wwin
->frame
;
3031 WScreen
*scr
= fwin
->screen_ptr
;
3032 XkbStateRec staterec
;
3035 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3037 tl
= wwin
->frame
->languagemode
;
3038 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3039 wwin
->frame
->last_languagemode
= tl
;
3040 wSetFocusTo(scr
, wwin
);
3041 wwin
->frame
->languagebutton_image
=
3042 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3043 wwin
->frame
->languagemode
];
3044 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3045 if (event
->xbutton
.button
== Button3
)
3047 wRaiseFrame(fwin
->core
);
3053 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3055 WWindow
*wwin
= data
;
3057 event
->xbutton
.state
&= ValidModMask
;
3059 CloseWindowMenu(wwin
->screen_ptr
);
3061 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3064 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3065 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3069 if ((event
->xbutton
.state
& ControlMask
) ||
3070 (event
->xbutton
.button
== Button3
)) {
3072 wapp
= wApplicationOf(wwin
->main_window
);
3073 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3074 wHideApplication(wapp
);
3075 } else if (event
->xbutton
.state
==0) {
3076 wIconifyWindow(wwin
);