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 &scr
->window_title_gc
,
1007 wwin
->frame
->flags
.is_client_window_frame
= 1;
1008 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1010 /* setup button images */
1011 wWindowUpdateButtonImages(wwin
);
1013 /* hide unused buttons */
1015 if (WFLAGP(wwin
, no_close_button
))
1016 foo
|= WFF_RIGHT_BUTTON
;
1017 if (WFLAGP(wwin
, no_miniaturize_button
))
1018 foo
|= WFF_LEFT_BUTTON
;
1019 #ifdef XKB_BUTTON_HINT
1020 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1021 foo
|= WFF_LANGUAGE_BUTTON
;
1024 wFrameWindowHideButton(wwin
->frame
, foo
);
1026 wwin
->frame
->child
= wwin
;
1029 /* emulate olwm push pin. Make the button look as pushed-in for
1030 * the pinned-out state. When the button is clicked, it will
1031 * revert to the normal position, which means the pin is pinned-in.
1033 if (wwin
->flags
.olwm_push_pin_out
)
1034 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1035 #endif /* OLWM_HINTS */
1037 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
1041 wwin
->frame
->workspace
= workspace
;
1043 wwin
->frame
->on_click_left
= windowIconifyClick
;
1044 #ifdef XKB_BUTTON_HINT
1045 if (wPreferences
.modelock
)
1046 wwin
->frame
->on_click_language
= windowLanguageClick
;
1049 wwin
->frame
->on_click_right
= windowCloseClick
;
1050 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1052 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1053 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1055 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1058 XSelectInput(dpy
, wwin
->client_win
,
1059 wwin
->event_mask
& ~StructureNotifyMask
);
1061 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1062 0, wwin
->frame
->top_width
);
1064 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1070 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1072 /* if gravity is to the south, account for the border sizes */
1074 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1078 * wWindowConfigure() will init the client window's size
1079 * (wwin->client.{width,height}) and all other geometry
1080 * related variables (frame_x,frame_y)
1082 wWindowConfigure(wwin
, x
, y
, width
, height
);
1084 /* to make sure the window receives it's new position after reparenting */
1085 wWindowSynthConfigureNotify(wwin
);
1088 *--------------------------------------------------
1090 * Setup descriptors and save window to internal
1093 *--------------------------------------------------
1096 if (wwin
->main_window
!=None
) {
1100 /* Leader windows do not necessary set themselves as leaders.
1101 * If this is the case, point the leader of this window to
1103 leader
= wWindowFor(wwin
->main_window
);
1104 if (leader
&& leader
->main_window
==None
) {
1105 leader
->main_window
= leader
->client_win
;
1107 app
= wApplicationCreate(scr
, wwin
->main_window
);
1109 app
->last_workspace
= workspace
;
1112 * Do application specific stuff, like setting application
1116 if (wwin
->flags
.hidden
) {
1117 /* if the window was set to hidden because it was hidden
1118 * in a previous incarnation and that state was restored */
1119 app
->flags
.hidden
= 1;
1122 if (app
->flags
.hidden
) {
1123 wwin
->flags
.hidden
= 1;
1128 /* setup the frame descriptor */
1129 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1130 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1131 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1133 /* don't let windows go away if we die */
1134 XAddToSaveSet(dpy
, window
);
1136 XLowerWindow(dpy
, window
);
1138 /* if window is in this workspace and should be mapped, then map it */
1139 if (!wwin
->flags
.miniaturized
1140 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1141 && !wwin
->flags
.hidden
&& !withdraw
) {
1143 /* The following "if" is to avoid crashing of clients that expect
1144 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1145 * after the return from this function.
1147 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1148 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1150 wClientSetState(wwin
, NormalState
, None
);
1154 /* if not auto focus, then map the window under the currently
1156 #define _WIDTH(w) (w)->frame->core->width
1157 #define _HEIGHT(w) (w)->frame->core->height
1158 if (!wPreferences
.auto_focus
&& scr
->focused_window
1159 && !scr
->flags
.startup
&& !transientOwner
1160 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1161 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1162 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1163 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1164 || wwin
->flags
.maximized
)) {
1165 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1173 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1174 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1176 * The brain damaged idiotic non-click to focus modes will
1177 * have trouble with this because:
1179 * 1. window is created and mapped by the client
1180 * 2. window is mapped by wmaker in small size
1181 * 3. window is animated to grow to normal size
1182 * 4. this function returns to normal event loop
1183 * 5. eventually, the EnterNotify event that would trigger
1184 * the window focusing (if the mouse is over that window)
1185 * will be processed by wmaker.
1186 * But since this event will be rather delayed
1187 * (step 3 has a large delay) the time when the event ocurred
1188 * and when it is processed, the client that owns that window
1189 * will reject the XSetInputFocus() for it.
1191 && (wPreferences
.focus_mode
==WKF_CLICK
1192 || wPreferences
.auto_focus
)) {
1193 DoWindowBirth(wwin
);
1199 /* setup stacking descriptor */
1200 if (transientOwner
) {
1201 /* && wPreferences.on_top_transients */
1202 if (transientOwner
) {
1203 wwin
->frame
->core
->stacking
->child_of
=
1204 transientOwner
->frame
->core
;
1207 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1211 if (!scr
->focused_window
) {
1212 /* first window on the list */
1215 scr
->focused_window
= wwin
;
1219 /* add window at beginning of focus window list */
1220 tmp
= scr
->focused_window
;
1229 wGNOMEUpdateClientStateHint(wwin
, True
);
1232 wKWMUpdateClientWorkspace(wwin
);
1233 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1239 *--------------------------------------------------
1241 * Final preparations before window is ready to go
1243 *--------------------------------------------------
1246 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1249 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1250 && !wwin
->flags
.hidden
) {
1251 if (((transientOwner
&& transientOwner
->flags
.focused
)
1252 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1253 wSetFocusTo(scr
, wwin
);
1255 wWindowResetMouseGrabs(wwin
);
1257 if (!WFLAGP(wwin
, no_bind_keys
)) {
1258 wWindowSetKeyGrabs(wwin
);
1261 wGNOMEUpdateClientListHint(scr
);
1264 wwin
->flags
.kwm_managed
= 1;
1266 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1269 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1271 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1274 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1275 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1277 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1278 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1284 *------------------------------------------------------------
1285 * Setup Notification Observers
1286 *------------------------------------------------------------
1288 WMAddNotificationObserver(appearanceObserver
, wwin
,
1289 WNWindowAppearanceSettingsChanged
, wwin
);
1293 *--------------------------------------------------
1295 * Cleanup temporary stuff
1297 *--------------------------------------------------
1301 wWindowDeleteSavedState(win_state
);
1303 /* If the window must be withdrawed, then do it now.
1304 * Must do some optimization, 'though */
1306 wwin
->flags
.mapped
= 0;
1307 wClientSetState(wwin
, WithdrawnState
, None
);
1308 wUnmanageWindow(wwin
, True
, False
);
1320 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1321 char *title
, int x
, int y
, int width
, int height
)
1326 wwin
= wWindowCreate();
1328 WMAddNotificationObserver(appearanceObserver
, wwin
,
1329 WNWindowAppearanceSettingsChanged
, wwin
);
1331 wwin
->flags
.internal_window
= 1;
1333 WSETUFLAG(wwin
, omnipresent
, 1);
1334 WSETUFLAG(wwin
, no_shadeable
, 1);
1335 WSETUFLAG(wwin
, no_resizable
, 1);
1336 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1338 wwin
->focus_mode
= WFM_PASSIVE
;
1340 wwin
->client_win
= window
;
1341 wwin
->screen_ptr
= scr
;
1343 wwin
->transient_for
= owner
;
1347 wwin
->client
.width
= width
;
1348 wwin
->client
.height
= height
;
1350 wwin
->frame_x
= wwin
->client
.x
;
1351 wwin
->frame_y
= wwin
->client
.y
;
1354 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1355 foo
|= WFF_TITLEBAR
;
1356 #ifdef XKB_BUTTON_HINT
1357 foo
|= WFF_LANGUAGE_BUTTON
;
1360 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1361 wwin
->frame_x
, wwin
->frame_y
,
1363 &wPreferences
.window_title_clearance
, foo
,
1364 scr
->window_title_texture
,
1365 scr
->resizebar_texture
,
1366 scr
->window_title_pixel
,
1367 &scr
->window_title_gc
,
1370 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1372 wwin
->frame
->flags
.is_client_window_frame
= 1;
1373 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1375 wFrameWindowChangeTitle(wwin
->frame
, title
);
1377 /* setup button images */
1378 wWindowUpdateButtonImages(wwin
);
1381 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1383 wwin
->frame
->child
= wwin
;
1385 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1387 #ifdef XKB_BUTTON_HINT
1388 if (wPreferences
.modelock
)
1389 wwin
->frame
->on_click_language
= windowLanguageClick
;
1392 wwin
->frame
->on_click_right
= windowCloseClick
;
1394 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1395 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1397 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1399 wwin
->client
.y
+= wwin
->frame
->top_width
;
1400 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1401 0, wwin
->frame
->top_width
);
1403 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1404 wwin
->client
.width
, wwin
->client
.height
);
1406 /* setup the frame descriptor */
1407 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1408 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1409 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1412 XLowerWindow(dpy
, window
);
1413 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1415 /* setup stacking descriptor */
1418 wPreferences
.on_top_transients
&&
1420 wwin
->transient_for
!=None
1421 && wwin
->transient_for
!=scr
->root_win
) {
1423 tmp
= wWindowFor(wwin
->transient_for
);
1425 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1427 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1431 if (!scr
->focused_window
) {
1432 /* first window on the list */
1435 scr
->focused_window
= wwin
;
1439 /* add window at beginning of focus window list */
1440 tmp
= scr
->focused_window
;
1448 if (wwin
->flags
.is_gnustep
== 0)
1449 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1451 /* if (wPreferences.auto_focus)*/
1452 wSetFocusTo(scr
, wwin
);
1454 wWindowResetMouseGrabs(wwin
);
1456 wWindowSetKeyGrabs(wwin
);
1458 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1465 *----------------------------------------------------------------------
1467 * Removes the frame window from a window and destroys all data
1468 * related to it. The window will be reparented back to the root window
1469 * if restore is True.
1472 * Everything related to the window is destroyed and the window
1473 * is removed from the window lists. Focus is set to the previous on the
1475 *----------------------------------------------------------------------
1478 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1480 WCoreWindow
*frame
= wwin
->frame
->core
;
1481 WWindow
*owner
= NULL
;
1482 WWindow
*newFocusedWindow
= NULL
;
1484 WScreen
*scr
= wwin
->screen_ptr
;
1488 wwin
->frame
->workspace
= -1;
1490 wKWMUpdateClientWorkspace(wwin
);
1493 /* First close attribute editor window if open */
1494 if (wwin
->flags
.inspector_open
) {
1495 wCloseInspectorForWindow(wwin
);
1498 /* Close window menu if it's open for this window */
1499 if (wwin
->flags
.menu_open_for_me
) {
1500 CloseWindowMenu(scr
);
1504 if (!wwin
->flags
.internal_window
)
1505 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1507 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1509 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1510 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1513 XUnmapWindow(dpy
, frame
->window
);
1515 XUnmapWindow(dpy
, wwin
->client_win
);
1517 /* deselect window */
1518 wSelectWindow(wwin
, False
);
1520 /* remove all pending events on window */
1521 /* I think this only matters for autoraise */
1522 if (wPreferences
.raise_delay
)
1523 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1527 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1529 /* reparent the window back to the root */
1531 wClientRestore(wwin
);
1533 if (wwin
->transient_for
!=scr
->root_win
) {
1534 owner
= wWindowFor(wwin
->transient_for
);
1536 if (!owner
->flags
.semi_focused
) {
1539 owner
->flags
.semi_focused
= 0;
1544 wasFocused
= wwin
->flags
.focused
;
1546 /* remove from window focus list */
1547 if (!wwin
->prev
&& !wwin
->next
) {
1548 /* was the only window */
1549 scr
->focused_window
= NULL
;
1550 newFocusedWindow
= NULL
;
1555 wwin
->prev
->next
= wwin
->next
;
1557 wwin
->next
->prev
= wwin
->prev
;
1559 scr
->focused_window
= wwin
->prev
;
1560 scr
->focused_window
->next
= NULL
;
1563 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1565 /* if in click to focus mode and the window
1566 * was a transient, focus the owner window
1569 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1570 tmp
= wWindowFor(wwin
->transient_for
);
1571 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1575 /* otherwise, focus the next one in the focus list */
1577 tmp
= scr
->focused_window
;
1578 while (tmp
) { /* look for one in the window list first */
1579 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1580 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1584 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1585 tmp
= scr
->focused_window
;
1587 if (!WFLAGP(tmp
, no_focusable
)
1588 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1595 newFocusedWindow
= tmp
;
1597 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1598 || wPreferences
.focus_mode
==WKF_POINTER
) {
1603 /* This is to let the root window get the keyboard input
1604 * if Sloppy focus mode and no other window get focus.
1605 * This way keybindings will not freeze.
1608 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1609 &foo
, &foo
, &foo
, &foo
, &mask
))
1610 tmp
= wWindowFor(win
);
1613 newFocusedWindow
= tmp
;
1615 newFocusedWindow
= NULL
;
1619 if (!wwin
->flags
.internal_window
) {
1621 wGNOMERemoveClient(wwin
);
1624 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1629 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1630 (unsigned)frame
->window
);
1634 if (newFocusedWindow
!= owner
&& owner
) {
1635 if (wwin
->flags
.is_gnustep
== 0)
1636 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1638 wSetFocusTo(scr
, newFocusedWindow
);
1640 wWindowDestroy(wwin
);
1646 wWindowMap(WWindow
*wwin
)
1648 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1649 if (!wwin
->flags
.shaded
) {
1650 /* window will be remapped when getting MapNotify */
1651 XSelectInput(dpy
, wwin
->client_win
,
1652 wwin
->event_mask
& ~StructureNotifyMask
);
1653 XMapWindow(dpy
, wwin
->client_win
);
1654 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1656 wwin
->flags
.mapped
= 1;
1662 wWindowUnmap(WWindow
*wwin
)
1664 wwin
->flags
.mapped
= 0;
1666 /* prevent window withdrawal when getting UnmapNotify */
1667 XSelectInput(dpy
, wwin
->client_win
,
1668 wwin
->event_mask
& ~StructureNotifyMask
);
1669 XUnmapWindow(dpy
, wwin
->client_win
);
1670 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1672 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1678 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1683 #ifdef KEEP_XKB_LOCK_STATUS
1684 if (wPreferences
.modelock
) {
1685 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1687 #endif /* KEEP_XKB_LOCK_STATUS */
1689 wwin
->flags
.semi_focused
= 0;
1691 if (wwin
->flags
.is_gnustep
== 0)
1692 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1694 wwin
->flags
.focused
= 1;
1696 wWindowResetMouseGrabs(wwin
);
1698 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1700 if (owin
== wwin
|| !owin
)
1703 nowner
= wWindowFor(wwin
->transient_for
);
1705 /* new window is a transient for the old window */
1706 if (nowner
== owin
) {
1707 owin
->flags
.semi_focused
= 1;
1708 wWindowUnfocus(nowner
);
1712 oowner
= wWindowFor(owin
->transient_for
);
1714 /* new window is owner of old window */
1715 if (wwin
== oowner
) {
1716 wWindowUnfocus(owin
);
1721 wWindowUnfocus(owin
);
1725 /* new window has same owner of old window */
1726 if (oowner
== nowner
) {
1727 /* prevent unfocusing of owner */
1728 oowner
->flags
.semi_focused
= 0;
1729 wWindowUnfocus(owin
);
1730 oowner
->flags
.semi_focused
= 1;
1735 /* nowner != NULL && oowner != nowner */
1736 nowner
->flags
.semi_focused
= 1;
1737 wWindowUnfocus(nowner
);
1738 wWindowUnfocus(owin
);
1743 wWindowUnfocus(WWindow
*wwin
)
1745 CloseWindowMenu(wwin
->screen_ptr
);
1747 if (wwin
->flags
.is_gnustep
== 0)
1748 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1749 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1751 if (wwin
->transient_for
!=None
1752 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1754 owner
= wWindowFor(wwin
->transient_for
);
1755 if (owner
&& owner
->flags
.semi_focused
) {
1756 owner
->flags
.semi_focused
= 0;
1757 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1758 wWindowUnfocus(owner
);
1759 wFrameWindowPaint(owner
->frame
);
1763 wwin
->flags
.focused
= 0;
1765 wWindowResetMouseGrabs(wwin
);
1767 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1774 *----------------------------------------------------------------------
1776 * wWindowConstrainSize--
1777 * Constrains size for the client window, taking the maximal size,
1778 * window resize increments and other size hints into account.
1781 * The closest size to what was given that the client window can
1784 *----------------------------------------------------------------------
1787 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1789 int width
= *nwidth
;
1790 int height
= *nheight
;
1793 int minW
= 1, minH
= 1;
1794 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1795 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1796 int minAX
= -1, minAY
= -1;
1797 int maxAX
= -1, maxAY
= -1;
1801 if (wwin
->normal_hints
) {
1802 winc
= wwin
->normal_hints
->width_inc
;
1803 hinc
= wwin
->normal_hints
->height_inc
;
1804 minW
= wwin
->normal_hints
->min_width
;
1805 minH
= wwin
->normal_hints
->min_height
;
1806 maxW
= wwin
->normal_hints
->max_width
;
1807 maxH
= wwin
->normal_hints
->max_height
;
1808 if (wwin
->normal_hints
->flags
& PAspect
) {
1809 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1810 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1811 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1812 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1826 /* aspect ratio code borrowed from olwm */
1828 /* adjust max aspect ratio */
1829 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1830 if (maxAX
> maxAY
) {
1831 height
= (width
* maxAY
) / maxAX
;
1832 if (height
> maxH
) {
1834 width
= (height
* maxAX
) / maxAY
;
1837 width
= (height
* maxAX
) / maxAY
;
1840 height
= (width
* maxAY
) / maxAX
;
1845 /* adjust min aspect ratio */
1846 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1847 if (minAX
> minAY
) {
1848 height
= (width
* minAY
) / minAX
;
1849 if (height
< minH
) {
1851 width
= (height
* minAX
) / minAY
;
1854 width
= (height
* minAX
) / minAY
;
1857 height
= (width
* minAY
) / minAX
;
1864 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1866 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1870 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1872 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1875 /* broken stupid apps may cause preposterous values for these.. */
1884 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1886 WScreen
*scr
= wwin
->screen_ptr
;
1890 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1891 || workspace
== wwin
->frame
->workspace
)
1894 if (workspace
!= scr
->current_workspace
) {
1895 /* Sent to other workspace. Unmap window */
1896 if ((wwin
->flags
.mapped
1897 || wwin
->flags
.shaded
1898 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1899 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1901 wapp
= wApplicationOf(wwin
->main_window
);
1903 wapp
->last_workspace
= workspace
;
1905 if (wwin
->flags
.miniaturized
) {
1907 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1908 wwin
->icon
->mapped
= 0;
1912 wSetFocusTo(scr
, NULL
);
1916 /* brought to current workspace. Map window */
1917 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1919 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1920 wwin
->icon
->mapped
= 1;
1922 } else if (!wwin
->flags
.mapped
&&
1923 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1927 if (!IS_OMNIPRESENT(wwin
)) {
1928 wwin
->frame
->workspace
= workspace
;
1929 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1932 wGNOMEUpdateClientStateHint(wwin
, True
);
1935 wKWMUpdateClientWorkspace(wwin
);
1936 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1945 wWindowSynthConfigureNotify(WWindow
*wwin
)
1949 sevent
.type
= ConfigureNotify
;
1950 sevent
.xconfigure
.display
= dpy
;
1951 sevent
.xconfigure
.event
= wwin
->client_win
;
1952 sevent
.xconfigure
.window
= wwin
->client_win
;
1954 sevent
.xconfigure
.x
= wwin
->client
.x
;
1955 sevent
.xconfigure
.y
= wwin
->client
.y
;
1956 sevent
.xconfigure
.width
= wwin
->client
.width
;
1957 sevent
.xconfigure
.height
= wwin
->client
.height
;
1959 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1960 if (WFLAGP(wwin
, no_titlebar
))
1961 sevent
.xconfigure
.above
= None
;
1963 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1965 sevent
.xconfigure
.override_redirect
= False
;
1966 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1968 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1975 *----------------------------------------------------------------------
1976 * wWindowConfigure--
1977 * Configures the frame, decorations and client window to the
1978 * specified geometry. The geometry is not checked for validity,
1979 * wWindowConstrainSize() must be used for that.
1980 * The size parameters are for the client window, but the position is
1982 * The client window receives a ConfigureNotify event, according
1983 * to what ICCCM says.
1989 * Window size and position are changed and client window receives
1990 * a ConfigureNotify event.
1991 *----------------------------------------------------------------------
1994 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1996 int req_x
, req_y
; /* new position of the frame */
1997 int req_width
, req_height
; /* new size of the client */
1999 int synth_notify
= False
;
2002 resize
= (req_width
!=wwin
->client
.width
2003 || req_height
!=wwin
->client
.height
);
2005 * if the window is being moved but not resized then
2006 * send a synthetic ConfigureNotify
2008 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2009 synth_notify
= True
;
2012 if (WFLAGP(wwin
, dont_move_off
))
2013 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2014 req_width
, req_height
);
2016 if (req_width
< MIN_WINDOW_SIZE
)
2017 req_width
= MIN_WINDOW_SIZE
;
2018 if (req_height
< MIN_WINDOW_SIZE
)
2019 req_height
= MIN_WINDOW_SIZE
;
2021 /* If growing, resize inner part before frame,
2022 * if shrinking, resize frame before.
2023 * This will prevent the frame (that can have a different color)
2024 * to be exposed, causing flicker */
2025 if (req_height
> wwin
->frame
->core
->height
2026 || req_width
> wwin
->frame
->core
->width
)
2027 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2029 if (wwin
->flags
.shaded
) {
2030 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2031 req_width
, wwin
->frame
->core
->height
);
2032 wwin
->old_geometry
.height
= req_height
;
2036 h
= req_height
+ wwin
->frame
->top_width
2037 + wwin
->frame
->bottom_width
;
2039 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2042 if (!(req_height
> wwin
->frame
->core
->height
2043 || req_width
> wwin
->frame
->core
->width
))
2044 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2046 wwin
->client
.x
= req_x
;
2047 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2048 wwin
->client
.width
= req_width
;
2049 wwin
->client
.height
= req_height
;
2051 wwin
->client
.x
= req_x
;
2052 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2054 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2056 wwin
->frame_x
= req_x
;
2057 wwin
->frame_y
= req_y
;
2058 if (!WFLAGP(wwin
, no_border
)) {
2059 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2060 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2064 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2065 wWindowSetShape(wwin
);
2070 wWindowSynthConfigureNotify(wwin
);
2076 wWindowMove(wwin
, req_x
, req_y
)
2078 int req_x
, req_y
; /* new position of the frame */
2080 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2081 int synth_notify
= False
;
2083 /* Send a synthetic ConfigureNotify event for every window movement. */
2084 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2085 synth_notify
= True
;
2088 /* A single synthetic ConfigureNotify event is sent at the end of
2089 * a completed (opaque) movement in moveres.c */
2092 if (WFLAGP(wwin
, dont_move_off
))
2093 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2094 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2096 wwin
->client
.x
= req_x
;
2097 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2098 if (!WFLAGP(wwin
, no_border
)) {
2099 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2100 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2103 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2105 wwin
->frame_x
= req_x
;
2106 wwin
->frame_y
= req_y
;
2108 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2110 wWindowSynthConfigureNotify(wwin
);
2116 wWindowUpdateButtonImages(WWindow
*wwin
)
2118 WScreen
*scr
= wwin
->screen_ptr
;
2119 Pixmap pixmap
, mask
;
2120 WFrameWindow
*fwin
= wwin
->frame
;
2122 if (WFLAGP(wwin
, no_titlebar
))
2125 /* miniaturize button */
2127 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2128 if (wwin
->wm_gnustep_attr
2129 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2130 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2132 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2133 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2138 if (fwin
->lbutton_image
2139 && (fwin
->lbutton_image
->image
!= pixmap
2140 || fwin
->lbutton_image
->mask
!= mask
)) {
2141 wPixmapDestroy(fwin
->lbutton_image
);
2142 fwin
->lbutton_image
= NULL
;
2145 if (!fwin
->lbutton_image
) {
2146 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2147 fwin
->lbutton_image
->client_owned
= 1;
2148 fwin
->lbutton_image
->client_owned_mask
= 1;
2151 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2152 wPixmapDestroy(fwin
->lbutton_image
);
2154 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2158 #ifdef XKB_BUTTON_HINT
2159 if (!WFLAGP(wwin
, no_language_button
)) {
2160 if (fwin
->languagebutton_image
&&
2161 !fwin
->languagebutton_image
->shared
) {
2162 wPixmapDestroy(fwin
->languagebutton_image
);
2164 fwin
->languagebutton_image
=
2165 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2171 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2172 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2174 if (!WFLAGP(wwin
, no_close_button
)) {
2175 if (wwin
->wm_gnustep_attr
2176 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2177 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2179 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2180 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2184 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2185 || fwin
->rbutton_image
->mask
!= mask
)) {
2186 wPixmapDestroy(fwin
->rbutton_image
);
2187 fwin
->rbutton_image
= NULL
;
2190 if (!fwin
->rbutton_image
) {
2191 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2192 fwin
->rbutton_image
->client_owned
= 1;
2193 fwin
->rbutton_image
->client_owned_mask
= 1;
2196 } else if (WFLAGP(wwin
, kill_close
)) {
2198 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2199 wPixmapDestroy(fwin
->rbutton_image
);
2201 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2203 } else if (MGFLAGP(wwin
, broken_close
)) {
2205 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2206 wPixmapDestroy(fwin
->rbutton_image
);
2208 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2212 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2213 wPixmapDestroy(fwin
->rbutton_image
);
2215 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2219 /* force buttons to be redrawn */
2220 fwin
->flags
.need_texture_change
= 1;
2221 wFrameWindowPaint(fwin
);
2226 *---------------------------------------------------------------------------
2227 * wWindowConfigureBorders--
2228 * Update window border configuration according to attribute flags.
2230 *---------------------------------------------------------------------------
2233 wWindowConfigureBorders(WWindow
*wwin
)
2239 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2240 #ifdef XKB_BUTTON_HINT
2241 flags
|= WFF_LANGUAGE_BUTTON
;
2243 if (!WFLAGP(wwin
, no_titlebar
))
2244 flags
|= WFF_TITLEBAR
;
2245 if (!WFLAGP(wwin
, no_resizebar
))
2246 flags
|= WFF_RESIZEBAR
;
2247 if (!WFLAGP(wwin
, no_border
))
2248 flags
|= WFF_BORDER
;
2249 if (wwin
->flags
.shaded
)
2250 flags
|= WFF_IS_SHADED
;
2252 oldh
= wwin
->frame
->top_width
;
2253 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2254 if (oldh
!= wwin
->frame
->top_width
) {
2255 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2257 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2258 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2259 wwin
->client
.width
, wwin
->client
.height
);
2263 if (!WFLAGP(wwin
, no_miniaturize_button
)
2264 && wwin
->frame
->flags
.hide_left_button
)
2265 flags
|= WFF_LEFT_BUTTON
;
2267 #ifdef XKB_BUTTON_HINT
2268 if (!WFLAGP(wwin
, no_language_button
)
2269 && wwin
->frame
->flags
.hide_language_button
)
2270 flags
|= WFF_LANGUAGE_BUTTON
;
2273 if (!WFLAGP(wwin
, no_close_button
)
2274 && wwin
->frame
->flags
.hide_right_button
)
2275 flags
|= WFF_RIGHT_BUTTON
;
2278 wWindowUpdateButtonImages(wwin
);
2279 wFrameWindowShowButton(wwin
->frame
, flags
);
2283 if (WFLAGP(wwin
, no_miniaturize_button
)
2284 && !wwin
->frame
->flags
.hide_left_button
)
2285 flags
|= WFF_LEFT_BUTTON
;
2287 #ifdef XKB_BUTTON_HINT
2288 if (WFLAGP(wwin
, no_language_button
)
2289 && !wwin
->frame
->flags
.hide_language_button
)
2290 flags
|= WFF_LANGUAGE_BUTTON
;
2293 if (WFLAGP(wwin
, no_close_button
)
2294 && !wwin
->frame
->flags
.hide_right_button
)
2295 flags
|= WFF_RIGHT_BUTTON
;
2298 wFrameWindowHideButton(wwin
->frame
, flags
);
2301 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2302 wWindowSetShape(wwin
);
2310 wWindowSaveState(WWindow
*wwin
)
2315 memset(data
, 0, sizeof(CARD32
)*10);
2316 data
[0] = wwin
->frame
->workspace
;
2317 data
[1] = wwin
->flags
.miniaturized
;
2318 data
[2] = wwin
->flags
.shaded
;
2319 data
[3] = wwin
->flags
.hidden
;
2320 data
[4] = wwin
->flags
.maximized
;
2321 if (wwin
->flags
.maximized
== 0) {
2322 data
[5] = wwin
->frame_x
;
2323 data
[6] = wwin
->frame_y
;
2324 data
[7] = wwin
->frame
->core
->width
;
2325 data
[8] = wwin
->frame
->core
->height
;
2327 data
[5] = wwin
->old_geometry
.x
;
2328 data
[6] = wwin
->old_geometry
.y
;
2329 data
[7] = wwin
->old_geometry
.width
;
2330 data
[8] = wwin
->old_geometry
.height
;
2333 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2334 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2335 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2338 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2339 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2340 (unsigned char *)data
, 10);
2345 getSavedState(Window window
, WSavedState
**state
)
2349 unsigned long nitems_ret
;
2350 unsigned long bytes_after_ret
;
2353 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2354 True
, _XA_WINDOWMAKER_STATE
,
2355 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2356 (unsigned char **)&data
)!=Success
|| !data
)
2359 *state
= malloc(sizeof(WSavedState
));
2362 (*state
)->workspace
= data
[0];
2363 (*state
)->miniaturized
= data
[1];
2364 (*state
)->shaded
= data
[2];
2365 (*state
)->hidden
= data
[3];
2366 (*state
)->maximized
= data
[4];
2367 (*state
)->x
= data
[5];
2368 (*state
)->y
= data
[6];
2369 (*state
)->w
= data
[7];
2370 (*state
)->h
= data
[8];
2371 (*state
)->window_shortcuts
= data
[9];
2375 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2384 wWindowClearShape(WWindow
*wwin
)
2386 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2387 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2392 wWindowSetShape(WWindow
*wwin
)
2396 #ifdef OPTIMIZE_SHAPE
2401 /* only shape is the client's */
2402 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2406 /* Get array of rectangles describing the shape mask */
2407 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2413 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2419 /* insert our decoration rectangles in the rect list */
2420 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2423 if (!WFLAGP(wwin
, no_titlebar
)) {
2425 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2426 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2427 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2430 if (!WFLAGP(wwin
, no_resizebar
)) {
2432 urec
[count
].y
= wwin
->frame
->core
->height
2433 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2434 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2435 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2439 /* shape our frame window */
2440 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2441 0, wwin
->frame
->top_width
, urec
, count
,
2442 ShapeSet
, Unsorted
);
2448 #endif /* OPTIMIZE_SHAPE */
2450 if (!WFLAGP(wwin
, no_titlebar
)) {
2453 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2454 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2457 if (!WFLAGP(wwin
, no_resizebar
)) {
2459 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2460 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2461 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2465 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2466 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2468 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2469 0, wwin
->frame
->top_width
, wwin
->client_win
,
2470 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2475 /* ====================================================================== */
2478 getFocusMode(WWindow
*wwin
)
2482 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2483 if (wwin
->wm_hints
->input
== True
) {
2484 if (wwin
->protocols
.TAKE_FOCUS
)
2485 mode
= WFM_LOCALLY_ACTIVE
;
2489 if (wwin
->protocols
.TAKE_FOCUS
)
2490 mode
= WFM_GLOBALLY_ACTIVE
;
2492 mode
= WFM_NO_INPUT
;
2502 wWindowSetKeyGrabs(WWindow
*wwin
)
2507 for (i
=0; i
<WKBD_LAST
; i
++) {
2508 key
= &wKeyBindings
[i
];
2510 if (key
->keycode
==0)
2512 if (key
->modifier
!=AnyModifier
) {
2513 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2514 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2516 /* Also grab all modifier combinations possible that include,
2517 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2518 * work even if the NumLock/ScrollLock key is on.
2520 wHackedGrabKey(key
->keycode
, key
->modifier
,
2521 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2525 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2526 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2530 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2537 wWindowResetMouseGrabs(WWindow
*wwin
)
2539 /* Mouse grabs can't be done on the client window because of
2540 * ICCCM and because clients that try to do the same will crash.
2542 * But there is a problem wich makes tbar buttons of unfocused
2543 * windows not usable as the click goes to the frame window instead
2544 * of the button itself. Must figure a way to fix that.
2547 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2549 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2550 /* grabs for Meta+drag */
2551 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2552 True
, ButtonPressMask
, GrabModeSync
,
2553 GrabModeAsync
, None
, None
);
2556 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2557 && !wwin
->flags
.is_gnustep
) {
2558 /* the passive grabs to focus the window */
2559 /* if (wPreferences.focus_mode == WKF_CLICK) */
2560 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2561 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2569 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2571 if (attr
->flags
& GSExtraFlagsAttr
) {
2572 if (MGFLAGP(wwin
, broken_close
) !=
2573 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2574 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2575 wWindowUpdateButtonImages(wwin
);
2582 wWindowAddSavedState(char *instance
, char *class, char *command
,
2583 pid_t pid
, WSavedState
*state
)
2585 WWindowState
*wstate
;
2587 wstate
= malloc(sizeof(WWindowState
));
2591 memset(wstate
, 0, sizeof(WWindowState
));
2594 wstate
->instance
= wstrdup(instance
);
2596 wstate
->class = wstrdup(class);
2598 wstate
->command
= wstrdup(command
);
2599 wstate
->state
= state
;
2601 wstate
->next
= windowState
;
2602 windowState
= wstate
;
2605 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2613 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2617 wWindowGetSavedState(Window win
)
2619 char *instance
, *class, *command
=NULL
;
2620 WWindowState
*wstate
= windowState
;
2627 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2629 command
= wtokenjoin(argv
, argc
);
2630 XFreeStringList(argv
);
2635 if (PropGetWMClass(win
, &class, &instance
)) {
2637 if (SAME(instance
, wstate
->instance
) &&
2638 SAME(class, wstate
->class) &&
2639 SAME(command
, wstate
->command
)) {
2642 wstate
= wstate
->next
;
2649 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2653 if (command
) wfree(command
);
2654 if (instance
) XFree(instance
);
2655 if (class) XFree(class);
2662 wWindowDeleteSavedState(WMagicNumber id
)
2664 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2666 if (!wstate
|| !windowState
)
2671 windowState
= wstate
->next
;
2673 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2674 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2676 if (wstate
->instance
) wfree(wstate
->instance
);
2677 if (wstate
->class) wfree(wstate
->class);
2678 if (wstate
->command
) wfree(wstate
->command
);
2679 wfree(wstate
->state
);
2683 if (tmp
->next
==wstate
) {
2684 tmp
->next
=wstate
->next
;
2686 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2687 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2689 if (wstate
->instance
) wfree(wstate
->instance
);
2690 if (wstate
->class) wfree(wstate
->class);
2691 if (wstate
->command
) wfree(wstate
->command
);
2692 wfree(wstate
->state
);
2703 wWindowDeleteSavedStatesForPID(pid_t pid
)
2705 WWindowState
*tmp
, *wstate
;
2711 if (tmp
->pid
== pid
) {
2712 wstate
= windowState
;
2713 windowState
= tmp
->next
;
2715 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2716 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2718 if (wstate
->instance
) wfree(wstate
->instance
);
2719 if (wstate
->class) wfree(wstate
->class);
2720 if (wstate
->command
) wfree(wstate
->command
);
2721 wfree(wstate
->state
);
2725 if (tmp
->next
->pid
==pid
) {
2727 tmp
->next
= wstate
->next
;
2729 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2730 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2732 if (wstate
->instance
) wfree(wstate
->instance
);
2733 if (wstate
->class) wfree(wstate
->class);
2734 if (wstate
->command
) wfree(wstate
->command
);
2735 wfree(wstate
->state
);
2745 /* ====================================================================== */
2748 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2750 WWindow
*wwin
= data
;
2752 #ifndef NUMLOCK_HACK
2753 if ((event
->xbutton
.state
& ValidModMask
)
2754 != (event
->xbutton
.state
& ~LockMask
)) {
2755 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2756 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2760 event
->xbutton
.state
&= ValidModMask
;
2762 CloseWindowMenu(wwin
->screen_ptr
);
2764 if (wPreferences
.focus_mode
==WKF_CLICK
2765 && !(event
->xbutton
.state
&ControlMask
)
2766 && !WFLAGP(wwin
, no_focusable
)) {
2767 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2770 if (event
->xbutton
.button
== Button1
)
2771 wRaiseFrame(wwin
->frame
->core
);
2773 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2774 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2775 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2776 GrabModeAsync
, GrabModeAsync
, None
,
2777 None
, CurrentTime
)!=GrabSuccess
) {
2779 wwarning("pointer grab failed for window move");
2785 if (event
->xbutton
.state
& MOD_MASK
) {
2786 /* move the window */
2787 wMouseMoveWindow(wwin
, event
);
2788 XUngrabPointer(dpy
, CurrentTime
);
2790 wMouseResizeWindow(wwin
, event
);
2791 XUngrabPointer(dpy
, CurrentTime
);
2798 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2800 WWindow
*wwin
= data
;
2802 event
->xbutton
.state
&= ValidModMask
;
2804 if (event
->xbutton
.button
==Button1
) {
2805 if (event
->xbutton
.state
== 0) {
2806 if (!WFLAGP(wwin
, no_shadeable
)) {
2808 if (wwin
->flags
.shaded
)
2809 wUnshadeWindow(wwin
);
2816 if (event
->xbutton
.state
& ControlMask
)
2817 dir
|= MAX_VERTICAL
;
2819 if (event
->xbutton
.state
& ShiftMask
) {
2820 dir
|= MAX_HORIZONTAL
;
2821 if (!(event
->xbutton
.state
& ControlMask
))
2822 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2825 /* maximize window */
2826 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2827 int ndir
= dir
^ wwin
->flags
.maximized
;
2828 if (wwin
->flags
.maximized
!= 0)
2829 wUnmaximizeWindow(wwin
);
2831 wMaximizeWindow(wwin
, ndir
);
2834 } else if (event
->xbutton
.button
==Button3
) {
2835 if (event
->xbutton
.state
& MOD_MASK
) {
2836 wHideOtherApplications(wwin
);
2838 } else if (event
->xbutton
.button
==Button2
) {
2839 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2845 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2847 WWindow
*wwin
= desc
->parent
;
2849 event
->xbutton
.state
&= ValidModMask
;
2851 CloseWindowMenu(wwin
->screen_ptr
);
2853 if (/*wPreferences.focus_mode==WKF_CLICK
2854 &&*/ !(event
->xbutton
.state
&ControlMask
)
2855 && !WFLAGP(wwin
, no_focusable
)) {
2856 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2858 if (event
->xbutton
.button
== Button1
) {
2859 wRaiseFrame(wwin
->frame
->core
);
2862 if (event
->xbutton
.state
& MOD_MASK
) {
2863 /* move the window */
2864 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2865 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2866 GrabModeAsync
, GrabModeAsync
, None
,
2867 None
, CurrentTime
)!=GrabSuccess
) {
2869 wwarning("pointer grab failed for window move");
2873 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2874 wMouseResizeWindow(wwin
, event
);
2876 wMouseMoveWindow(wwin
, event
);
2877 XUngrabPointer(dpy
, CurrentTime
);
2883 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2885 WWindow
*wwin
= (WWindow
*)data
;
2887 #ifndef NUMLOCK_HACK
2888 if ((event
->xbutton
.state
& ValidModMask
)
2889 != (event
->xbutton
.state
& ~LockMask
)) {
2890 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2891 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2894 event
->xbutton
.state
&= ValidModMask
;
2896 CloseWindowMenu(wwin
->screen_ptr
);
2898 if (wPreferences
.focus_mode
==WKF_CLICK
2899 && !(event
->xbutton
.state
&ControlMask
)
2900 && !WFLAGP(wwin
, no_focusable
)) {
2901 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2904 if (event
->xbutton
.button
== Button1
2905 || event
->xbutton
.button
== Button2
) {
2907 if (event
->xbutton
.button
== Button1
) {
2908 if (event
->xbutton
.state
& MOD_MASK
) {
2909 wLowerFrame(wwin
->frame
->core
);
2911 wRaiseFrame(wwin
->frame
->core
);
2914 if ((event
->xbutton
.state
& ShiftMask
)
2915 && !(event
->xbutton
.state
& ControlMask
)) {
2916 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2919 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2920 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2921 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2922 GrabModeAsync
, GrabModeAsync
, None
,
2923 None
, CurrentTime
)!=GrabSuccess
) {
2925 wwarning("pointer grab failed for window move");
2930 /* move the window */
2931 wMouseMoveWindow(wwin
, event
);
2933 XUngrabPointer(dpy
, CurrentTime
);
2934 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2935 && !wwin
->flags
.internal_window
2936 && !WCHECK_STATE(WSTATE_MODAL
)) {
2937 WObjDescriptor
*desc
;
2939 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2940 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2941 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2942 GrabModeAsync
, GrabModeAsync
, None
,
2943 None
, CurrentTime
)!=GrabSuccess
) {
2945 wwarning("pointer grab failed for window move");
2950 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2951 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2953 /* allow drag select */
2954 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2955 event
->xany
.send_event
= True
;
2956 (*desc
->handle_mousedown
)(desc
, event
);
2958 XUngrabPointer(dpy
, CurrentTime
);
2965 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2967 WWindow
*wwin
= data
;
2969 event
->xbutton
.state
&= ValidModMask
;
2971 CloseWindowMenu(wwin
->screen_ptr
);
2973 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2976 /* if control-click, kill the client */
2977 if (event
->xbutton
.state
& ControlMask
) {
2981 if (wwin
->flags
.olwm_push_pin_out
) {
2983 wwin
->flags
.olwm_push_pin_out
= 0;
2985 wOLWMChangePushpinState(wwin
, True
);
2987 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2992 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2993 /* send delete message */
2994 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3001 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3003 WWindow
*wwin
= data
;
3005 CloseWindowMenu(wwin
->screen_ptr
);
3007 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3010 /* send delete message */
3011 if (wwin
->protocols
.DELETE_WINDOW
) {
3012 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3019 #ifdef XKB_BUTTON_HINT
3021 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3023 WWindow
*wwin
= data
;
3024 WFrameWindow
*fwin
= wwin
->frame
;
3025 WScreen
*scr
= fwin
->screen_ptr
;
3026 XkbStateRec staterec
;
3029 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3031 tl
= wwin
->frame
->languagemode
;
3032 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3033 wwin
->frame
->last_languagemode
= tl
;
3034 wSetFocusTo(scr
, wwin
);
3035 wwin
->frame
->languagebutton_image
=
3036 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3037 wwin
->frame
->languagemode
];
3038 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3039 if (event
->xbutton
.button
== Button3
)
3041 wRaiseFrame(fwin
->core
);
3047 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3049 WWindow
*wwin
= data
;
3051 event
->xbutton
.state
&= ValidModMask
;
3053 CloseWindowMenu(wwin
->screen_ptr
);
3055 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3058 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3059 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3063 if ((event
->xbutton
.state
& ControlMask
) ||
3064 (event
->xbutton
.button
== Button3
)) {
3066 wapp
= wApplicationOf(wwin
->main_window
);
3067 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3068 wHideApplication(wapp
);
3069 } else if (event
->xbutton
.state
==0) {
3070 wIconifyWindow(wwin
);