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 WMRemoveNotificationObserver(wwin
);
220 wwin
->flags
.destroyed
= 1;
222 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
223 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
226 WMRemoveFromBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
228 if (!WMGetBagItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
229 WMFreeBag(wwin
->screen_ptr
->shortcutWindows
[i
]);
230 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
234 if (wwin
->normal_hints
)
235 free(wwin
->normal_hints
);
238 XFree(wwin
->wm_hints
);
240 if (wwin
->wm_instance
)
241 XFree(wwin
->wm_instance
);
244 XFree(wwin
->wm_class
);
246 if (wwin
->wm_gnustep_attr
)
247 free(wwin
->wm_gnustep_attr
);
249 if (wwin
->cmap_windows
)
250 XFree(wwin
->cmap_windows
);
252 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
255 wFrameWindowDestroy(wwin
->frame
);
258 RemoveFromStackList(wwin
->icon
->core
);
259 wIconDestroy(wwin
->icon
);
260 if (wPreferences
.auto_arrange_icons
)
261 wArrangeIcons(wwin
->screen_ptr
, True
);
270 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
272 if (gs_hints
->flags
& GSWindowStyleAttr
) {
273 wwin
->client_flags
.no_titlebar
=
274 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
276 wwin
->client_flags
.no_close_button
=
277 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
279 wwin
->client_flags
.no_closable
=
280 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
282 wwin
->client_flags
.no_miniaturize_button
=
283 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
285 wwin
->client_flags
.no_miniaturizable
=
286 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
288 wwin
->client_flags
.no_resizebar
=
289 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
291 wwin
->client_flags
.no_resizable
=
292 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
294 /* setup the defaults */
295 wwin
->client_flags
.no_titlebar
= 0;
296 wwin
->client_flags
.no_closable
= 0;
297 wwin
->client_flags
.no_miniaturizable
= 0;
298 wwin
->client_flags
.no_resizable
= 0;
299 wwin
->client_flags
.no_close_button
= 0;
300 wwin
->client_flags
.no_miniaturize_button
= 0;
301 wwin
->client_flags
.no_resizebar
= 0;
303 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
304 wwin
->client_flags
.no_appicon
= 1;
310 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
311 WWindowAttributes
*mask
)
313 if (wflags
->no_appicon
&& mask
->no_appicon
)
314 wflags
->emulate_appicon
= 0;
316 if (wwin
->main_window
!=None
) {
317 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
318 if (wapp
&& !wapp
->flags
.emulated
)
319 wflags
->emulate_appicon
= 0;
322 if (wwin
->transient_for
!=None
323 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
324 wflags
->emulate_appicon
= 0;
326 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
333 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
335 WScreen
*scr
= wwin
->screen_ptr
;
337 /* sets global default stuff */
338 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
339 &wwin
->client_flags
, NULL
, True
);
341 * Decoration setting is done in this precedence (lower to higher)
342 * - use global default in the resource database
343 * - guess some settings
344 * - use GNUstep/external window attributes
345 * - set hints specified for the app in the resource DB
348 WSETUFLAG(wwin
, broken_close
, 0);
350 if (wwin
->protocols
.DELETE_WINDOW
)
351 WSETUFLAG(wwin
, kill_close
, 0);
353 WSETUFLAG(wwin
, kill_close
, 1);
355 /* transients can't be iconified or maximized */
356 if (wwin
->transient_for
) {
357 WSETUFLAG(wwin
, no_miniaturizable
, 1);
358 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
361 /* if the window can't be resized, remove the resizebar */
362 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
363 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
364 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
365 WSETUFLAG(wwin
, no_resizable
, 1);
366 WSETUFLAG(wwin
, no_resizebar
, 1);
369 /* set GNUstep window attributes */
370 if (wwin
->wm_gnustep_attr
) {
371 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
373 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
375 switch (wwin
->wm_gnustep_attr
->window_level
) {
376 case WMNormalWindowLevel
:
377 *level
= WMNormalLevel
;
379 case WMFloatingWindowLevel
:
380 *level
= WMFloatingLevel
;
382 case WMDockWindowLevel
:
383 *level
= WMDockLevel
;
385 case WMSubmenuWindowLevel
:
386 *level
= WMSubmenuLevel
;
388 case WMMainMenuWindowLevel
:
389 *level
= WMMainMenuLevel
;
392 *level
= WMNormalLevel
;
397 *level
= WMNormalLevel
;
400 int tmp_workspace
= -1;
404 wMWMCheckClientHints(wwin
);
405 #endif /* MWM_HINTS */
408 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
409 #endif /* KWM_HINTS */
412 wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
413 #endif /* GNOME_STUFF */
416 wOLWMCheckClientHints(wwin
);
417 #endif /* OLWM_HINTS */
420 if (WFLAGP(wwin
, floating
))
421 *level
= WMFloatingLevel
;
422 else if (WFLAGP(wwin
, sunken
))
423 *level
= WMSunkenLevel
;
425 *level
= WMNormalLevel
;
430 if (tmp_workspace
>= 0) {
431 *workspace
= tmp_workspace
% scr
->workspace_count
;
436 * Set attributes specified only for that window/class.
437 * This might do duplicate work with the 1st wDefaultFillAttributes().
439 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
440 &wwin
->user_flags
, &wwin
->defined_user_flags
,
443 * Sanity checks for attributes that depend on other attributes
445 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
446 wwin
->user_flags
.emulate_appicon
= 0;
448 if (wwin
->main_window
!=None
) {
449 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
450 if (wapp
&& !wapp
->flags
.emulated
)
451 wwin
->user_flags
.emulate_appicon
= 0;
454 if (wwin
->transient_for
!=None
455 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
456 wwin
->user_flags
.emulate_appicon
= 0;
458 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
459 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
460 wwin
->user_flags
.sunken
= 0;
462 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
469 wWindowCanReceiveFocus(WWindow
*wwin
)
471 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
473 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
475 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
483 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
487 w1
= wwin
->frame
->core
->width
;
488 h1
= wwin
->frame
->core
->height
;
489 w2
= obscured
->frame
->core
->width
;
490 h2
= obscured
->frame
->core
->height
;
492 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
493 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
496 if (wwin
->frame_x
+ w1
< obscured
->frame_x
497 || wwin
->frame_y
+ h1
< obscured
->frame_y
498 || wwin
->frame_x
> obscured
->frame_x
+ w2
499 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
508 *----------------------------------------------------------------
510 * reparents the window and allocates a descriptor for it.
511 * Window manager hints and other hints are fetched to configure
512 * the window decoration attributes and others. User preferences
513 * for the window are used if available, to configure window
514 * decorations and some behaviour.
515 * If in startup, windows that are override redirect,
516 * unmapped and never were managed and are Withdrawn are not
520 * the new window descriptor
523 * The window is reparented and appropriate notification
524 * is done to the client. Input mask for the window is setup.
525 * The window descriptor is also associated with various window
526 * contexts and inserted in the head of the window list.
527 * Event handler contexts are associated for some objects
528 * (buttons, titlebar and resizebar)
530 *----------------------------------------------------------------
533 wManageWindow(WScreen
*scr
, Window window
)
537 unsigned width
, height
;
538 XWindowAttributes wattribs
;
539 XSetWindowAttributes attribs
;
540 WWindowState
*win_state
;
541 WWindow
*transientOwner
= NULL
;
547 Bool withdraw
= False
;
550 /* XGrabServer(dpy); */
552 /* make sure the window is still there */
553 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
558 /* if it's an override-redirect, ignore it */
559 if (wattribs
.override_redirect
) {
564 wm_state
= PropGetWindowState(window
);
566 /* if it's startup and the window is unmapped, don't manage it */
567 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
572 if (!wFetchName(dpy
, window
, &title
)) {
577 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
582 #endif /* KWM_HINTS */
585 wwin
= wWindowCreate();
587 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
590 printf("managing window %x\n", (unsigned)window
);
594 if (wShapeSupported
) {
599 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
600 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
601 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
602 wwin
->flags
.shaped
= b_shaped
;
607 *--------------------------------------------------
609 * Get hints and other information in properties
611 *--------------------------------------------------
613 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
615 /* setup descriptor */
616 wwin
->client_win
= window
;
617 wwin
->screen_ptr
= scr
;
619 wwin
->old_border_width
= wattribs
.border_width
;
621 wwin
->event_mask
= CLIENT_EVENTS
;
622 attribs
.event_mask
= CLIENT_EVENTS
;
623 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
624 attribs
.save_under
= False
;
625 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
626 |CWSaveUnder
, &attribs
);
627 XSetWindowBorderWidth(dpy
, window
, 0);
629 /* get hints from GNUstep app */
630 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
631 wwin
->wm_gnustep_attr
= NULL
;
634 wwin
->client_leader
= PropGetClientLeader(window
);
635 if (wwin
->client_leader
!=None
)
636 wwin
->main_window
= wwin
->client_leader
;
638 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
640 if (wwin
->wm_hints
) {
641 if (wwin
->wm_hints
->flags
& StateHint
) {
643 if (wwin
->wm_hints
->initial_state
== IconicState
) {
645 wwin
->flags
.miniaturized
= 1;
647 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
653 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
654 wwin
->group_id
= wwin
->wm_hints
->window_group
;
655 /* window_group has priority over CLIENT_LEADER */
656 wwin
->main_window
= wwin
->group_id
;
658 wwin
->group_id
= None
;
661 if (wwin
->wm_hints
->flags
& UrgencyHint
)
662 wwin
->flags
.urgent
= 1;
664 wwin
->group_id
= None
;
667 PropGetProtocols(window
, &wwin
->protocols
);
669 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
670 wwin
->transient_for
= None
;
672 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
673 wwin
->transient_for
= scr
->root_win
;
675 transientOwner
= wWindowFor(wwin
->transient_for
);
676 if (transientOwner
&& transientOwner
->main_window
!=None
) {
677 wwin
->main_window
= transientOwner
->main_window
;
679 wwin->main_window = None;
684 /* guess the focus mode */
685 wwin
->focus_mode
= getFocusMode(wwin
);
687 /* get geometry stuff */
688 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
690 /* get colormap windows */
691 GetColormapWindows(wwin
);
694 *--------------------------------------------------
696 * Setup the decoration/window attributes and
699 *--------------------------------------------------
702 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
705 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
706 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
708 transientOwner
= wWindowFor(wwin
->group_id
);
710 if (transientOwner
) {
711 wwin
->transient_for
= wwin
->group_id
;
713 /* transients can't be iconified or maximized */
714 if (wwin
->transient_for
) {
715 WSETUFLAG(wwin
, no_miniaturizable
, 1);
716 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
720 #endif /* OLWM_HINTS */
723 * Make broken apps behave as a nice app.
725 if (WFLAGP(wwin
, emulate_appicon
)) {
726 wwin
->main_window
= wwin
->client_win
;
730 *------------------------------------------------------------
732 * Setup the initial state of the window
734 *------------------------------------------------------------
737 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
738 wwin
->flags
.miniaturized
= 1;
741 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
742 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
746 wGNOMECheckInitialClientState(wwin
);
749 wKWMCheckClientInitialState(wwin
);
752 /* apply previous state if it exists and we're in startup */
753 if (scr
->flags
.startup
&& wm_state
>= 0) {
755 if (wm_state
== IconicState
) {
757 wwin
->flags
.miniaturized
= 1;
759 } else if (wm_state
== WithdrawnState
) {
765 /* if there is a saved state (from file), restore it */
767 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
768 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
770 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
772 if (win_state
&& !withdraw
) {
774 if (win_state
->state
->hidden
>0)
775 wwin
->flags
.hidden
= win_state
->state
->hidden
;
777 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
778 wwin
->flags
.shaded
= win_state
->state
->shaded
;
780 if (win_state
->state
->miniaturized
>0 &&
781 !WFLAGP(wwin
, no_miniaturizable
)) {
782 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
784 if (!IS_OMNIPRESENT(wwin
)) {
785 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
787 if (w
< 0 || w
>= scr
->workspace_count
) {
788 workspace
= win_state
->state
->workspace
;
789 if (workspace
>= scr
->workspace_count
)
790 workspace
= scr
->current_workspace
;
795 workspace
= scr
->current_workspace
;
799 /* if we're restarting, restore saved state (from hints).
800 * This will overwrite previous */
804 if (getSavedState(window
, &wstate
)) {
805 wwin
->flags
.shaded
= wstate
->shaded
;
806 wwin
->flags
.hidden
= wstate
->hidden
;
807 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
808 workspace
= wstate
->workspace
;
810 if (scr
->flags
.startup
&& wstate
->window_shortcuts
>= 0) {
813 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
814 if (wstate
->window_shortcuts
& (1<<i
)) {
815 if (!scr
->shortcutWindows
[i
])
816 scr
->shortcutWindows
[i
] = WMCreateBag(4);
818 WMPutInBag(scr
->shortcutWindows
[i
], wwin
);
826 /* don't let transients start miniaturized if their owners are not */
827 if (transientOwner
&& !transientOwner
->flags
.miniaturized
828 && wwin
->flags
.miniaturized
&& !withdraw
) {
829 wwin
->flags
.miniaturized
= 0;
831 wwin
->wm_hints
->initial_state
= NormalState
;
834 /* set workspace on which the window starts */
835 if (workspace
>= 0) {
836 if (workspace
> scr
->workspace_count
-1) {
837 workspace
= workspace
% scr
->workspace_count
;
842 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
844 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
849 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
851 workspace
= transientOwner
->frame
->workspace
;
855 workspace
= scr
->current_workspace
;
860 /* setup window geometry */
861 if (win_state
&& win_state
->state
->use_geometry
) {
862 width
= win_state
->state
->w
;
863 height
= win_state
->state
->h
;
865 wWindowConstrainSize(wwin
, &width
, &height
);
867 /* do not ask for window placement if the window is
868 * transient, during startup, if the initial workspace is another one
869 * or if the window wants to start iconic.
870 * If geometry was saved, restore it. */
872 Bool dontBring
= False
;
874 if (win_state
&& win_state
->state
->use_geometry
) {
875 x
= win_state
->state
->x
;
876 y
= win_state
->state
->y
;
877 } else if ((wwin
->transient_for
==None
878 || wPreferences
.window_placement
!=WPM_MANUAL
)
879 && !scr
->flags
.startup
880 && workspace
== scr
->current_workspace
881 && !wwin
->flags
.miniaturized
882 && !wwin
->flags
.maximized
883 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
884 PlaceWindow(wwin
, &x
, &y
, width
, height
);
885 if (wPreferences
.window_placement
== WPM_MANUAL
)
889 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
890 wScreenBringInside(scr
, &x
, &y
, width
, height
);
893 if (wwin
->flags
.urgent
) {
894 if (!IS_OMNIPRESENT(wwin
))
895 wwin
->flags
.omnipresent
^= 1;
899 *--------------------------------------------------
901 * Create frame, borders and do reparenting
903 *--------------------------------------------------
905 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
906 #ifdef XKB_BUTTON_HINT
907 if (wPreferences
.modelock
)
908 foo
|= WFF_LANGUAGE_BUTTON
;
910 if (!WFLAGP(wwin
, no_titlebar
))
912 if (!WFLAGP(wwin
, no_resizebar
))
913 foo
|= WFF_RESIZEBAR
;
915 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
916 x
, y
, width
, height
, foo
,
917 scr
->window_title_texture
,
918 scr
->resizebar_texture
,
919 scr
->window_title_pixel
,
920 #ifdef DRAWSTRING_PLUGIN
923 &scr
->window_title_gc
,
926 wwin
->frame
->flags
.is_client_window_frame
= 1;
927 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
929 /* setup button images */
930 wWindowUpdateButtonImages(wwin
);
932 /* hide unused buttons */
934 if (WFLAGP(wwin
, no_close_button
))
935 foo
|= WFF_RIGHT_BUTTON
;
936 if (WFLAGP(wwin
, no_miniaturize_button
))
937 foo
|= WFF_LEFT_BUTTON
;
938 #ifdef XKB_BUTTON_HINT
939 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
940 foo
|= WFF_LANGUAGE_BUTTON
;
943 wFrameWindowHideButton(wwin
->frame
, foo
);
945 wwin
->frame
->child
= wwin
;
948 /* emulate olwm push pin. Make the button look as pushed-in for
949 * the pinned-out state. When the button is clicked, it will
950 * revert to the normal position, which means the pin is pinned-in.
952 if (wwin
->flags
.olwm_push_pin_out
)
953 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
954 #endif /* OLWM_HINTS */
956 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
960 wwin
->frame
->workspace
= workspace
;
962 wwin
->frame
->on_click_left
= windowIconifyClick
;
963 #ifdef XKB_BUTTON_HINT
964 if (wPreferences
.modelock
)
965 wwin
->frame
->on_click_language
= windowLanguageClick
;
968 wwin
->frame
->on_click_right
= windowCloseClick
;
969 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
971 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
972 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
974 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
977 XSelectInput(dpy
, wwin
->client_win
,
978 wwin
->event_mask
& ~StructureNotifyMask
);
980 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
981 0, wwin
->frame
->top_width
);
983 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
989 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
991 /* if gravity is to the south, account for the border sizes */
993 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
997 * wWindowConfigure() will init the client window's size
998 * (wwin->client.{width,height}) and all other geometry
999 * related variables (frame_x,frame_y)
1001 wWindowConfigure(wwin
, x
, y
, width
, height
);
1003 /* to make sure the window receives it's new position after reparenting */
1004 wWindowSynthConfigureNotify(wwin
);
1007 *--------------------------------------------------
1009 * Setup descriptors and save window to internal
1012 *--------------------------------------------------
1015 if (wwin
->main_window
!=None
) {
1019 /* Leader windows do not necessary set themselves as leaders.
1020 * If this is the case, point the leader of this window to
1022 leader
= wWindowFor(wwin
->main_window
);
1023 if (leader
&& leader
->main_window
==None
) {
1024 leader
->main_window
= leader
->client_win
;
1026 app
= wApplicationCreate(scr
, wwin
->main_window
);
1028 app
->last_workspace
= workspace
;
1031 * Do application specific stuff, like setting application
1035 if (wwin
->flags
.hidden
) {
1036 /* if the window was set to hidden because it was hidden
1037 * in a previous incarnation and that state was restored */
1038 app
->flags
.hidden
= 1;
1041 if (app
->flags
.hidden
) {
1042 wwin
->flags
.hidden
= 1;
1047 /* setup the frame descriptor */
1048 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1049 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1050 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1052 /* don't let windows go away if we die */
1053 XAddToSaveSet(dpy
, window
);
1055 XLowerWindow(dpy
, window
);
1057 /* if window is in this workspace and should be mapped, then map it */
1058 if (!wwin
->flags
.miniaturized
1059 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1060 && !wwin
->flags
.hidden
&& !withdraw
) {
1062 /* The following "if" is to avoid crashing of clients that expect
1063 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1064 * after the return from this function.
1066 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1067 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1069 wClientSetState(wwin
, NormalState
, None
);
1073 /* if not auto focus, then map the window under the currently
1075 #define _WIDTH(w) (w)->frame->core->width
1076 #define _HEIGHT(w) (w)->frame->core->height
1077 if (!wPreferences
.auto_focus
&& scr
->focused_window
1078 && !scr
->flags
.startup
&& !transientOwner
1079 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1080 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1081 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1082 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1083 || wwin
->flags
.maximized
)) {
1084 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1092 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1093 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1095 * The brain damaged idiotic non-click to focus modes will
1096 * have trouble with this because:
1098 * 1. window is created and mapped by the client
1099 * 2. window is mapped by wmaker in small size
1100 * 3. window is animated to grow to normal size
1101 * 4. this function returns to normal event loop
1102 * 5. eventually, the EnterNotify event that would trigger
1103 * the window focusing (if the mouse is over that window)
1104 * will be processed by wmaker.
1105 * But since this event will be rather delayed
1106 * (step 3 has a large delay) the time when the event ocurred
1107 * and when it is processed, the client that owns that window
1108 * will reject the XSetInputFocus() for it.
1110 && (wPreferences
.focus_mode
==WKF_CLICK
1111 || wPreferences
.auto_focus
)) {
1112 DoWindowBirth(wwin
);
1118 /* setup stacking descriptor */
1119 if (transientOwner
) {
1120 /* && wPreferences.on_top_transients */
1121 if (transientOwner
) {
1122 wwin
->frame
->core
->stacking
->child_of
=
1123 transientOwner
->frame
->core
;
1126 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1130 if (!scr
->focused_window
) {
1131 /* first window on the list */
1134 scr
->focused_window
= wwin
;
1138 /* add window at beginning of focus window list */
1139 tmp
= scr
->focused_window
;
1148 wGNOMEUpdateClientStateHint(wwin
, True
);
1151 wKWMUpdateClientWorkspace(wwin
);
1152 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1158 *--------------------------------------------------
1160 * Final preparations before window is ready to go
1162 *--------------------------------------------------
1165 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1168 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1169 && !wwin
->flags
.hidden
) {
1170 if (((transientOwner
&& transientOwner
->flags
.focused
)
1171 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1172 wSetFocusTo(scr
, wwin
);
1174 wWindowResetMouseGrabs(wwin
);
1176 if (!WFLAGP(wwin
, no_bind_keys
)) {
1177 wWindowSetKeyGrabs(wwin
);
1180 wGNOMEUpdateClientListHint(scr
);
1183 wwin
->flags
.kwm_managed
= 1;
1185 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1188 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1190 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1193 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1194 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1196 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1197 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1203 *------------------------------------------------------------
1204 * Setup Notification Observers
1205 *------------------------------------------------------------
1207 WMAddNotificationObserver(appearanceObserver
, wwin
,
1208 WNWindowAppearanceSettingsChanged
, wwin
);
1212 *--------------------------------------------------
1214 * Cleanup temporary stuff
1216 *--------------------------------------------------
1220 wWindowDeleteSavedState(win_state
);
1222 /* If the window must be withdrawed, then do it now.
1223 * Must do some optimization, 'though */
1225 wwin
->flags
.mapped
= 0;
1226 wClientSetState(wwin
, WithdrawnState
, None
);
1227 wUnmanageWindow(wwin
, True
, False
);
1239 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1240 char *title
, int x
, int y
, int width
, int height
)
1245 wwin
= wWindowCreate();
1247 WMAddNotificationObserver(appearanceObserver
, wwin
,
1248 WNWindowAppearanceSettingsChanged
, wwin
);
1250 wwin
->flags
.internal_window
= 1;
1252 WSETUFLAG(wwin
, omnipresent
, 1);
1253 WSETUFLAG(wwin
, no_shadeable
, 1);
1254 WSETUFLAG(wwin
, no_resizable
, 1);
1255 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1257 wwin
->focus_mode
= WFM_PASSIVE
;
1259 wwin
->client_win
= window
;
1260 wwin
->screen_ptr
= scr
;
1262 wwin
->transient_for
= owner
;
1266 wwin
->client
.width
= width
;
1267 wwin
->client
.height
= height
;
1269 wwin
->frame_x
= wwin
->client
.x
;
1270 wwin
->frame_y
= wwin
->client
.y
;
1273 foo
= WFF_RIGHT_BUTTON
;
1274 foo
|= WFF_TITLEBAR
;
1275 #ifdef XKB_BUTTON_HINT
1276 foo
|= WFF_LANGUAGE_BUTTON
;
1279 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1280 wwin
->frame_x
, wwin
->frame_y
,
1282 scr
->window_title_texture
,
1283 scr
->resizebar_texture
,
1284 scr
->window_title_pixel
,
1285 #ifdef DRAWSTRING_PLUGIN
1288 &scr
->window_title_gc
,
1291 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1293 wwin
->frame
->flags
.is_client_window_frame
= 1;
1294 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1296 wFrameWindowChangeTitle(wwin
->frame
, title
);
1298 /* setup button images */
1299 wWindowUpdateButtonImages(wwin
);
1302 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1304 wwin
->frame
->child
= wwin
;
1306 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1308 #ifdef XKB_BUTTON_HINT
1309 if (wPreferences
.modelock
)
1310 wwin
->frame
->on_click_language
= windowLanguageClick
;
1313 wwin
->frame
->on_click_right
= windowCloseClick
;
1315 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1316 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1318 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1320 wwin
->client
.y
+= wwin
->frame
->top_width
;
1321 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1322 0, wwin
->frame
->top_width
);
1324 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1325 wwin
->client
.width
, wwin
->client
.height
);
1327 /* setup the frame descriptor */
1328 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1329 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1330 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1333 XLowerWindow(dpy
, window
);
1334 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1336 /* setup stacking descriptor */
1339 wPreferences
.on_top_transients
&&
1341 wwin
->transient_for
!=None
1342 && wwin
->transient_for
!=scr
->root_win
) {
1344 tmp
= wWindowFor(wwin
->transient_for
);
1346 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1348 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1352 if (!scr
->focused_window
) {
1353 /* first window on the list */
1356 scr
->focused_window
= wwin
;
1360 /* add window at beginning of focus window list */
1361 tmp
= scr
->focused_window
;
1369 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1371 /* if (wPreferences.auto_focus)*/
1372 wSetFocusTo(scr
, wwin
);
1374 wWindowResetMouseGrabs(wwin
);
1376 wWindowSetKeyGrabs(wwin
);
1378 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1385 *----------------------------------------------------------------------
1387 * Removes the frame window from a window and destroys all data
1388 * related to it. The window will be reparented back to the root window
1389 * if restore is True.
1392 * Everything related to the window is destroyed and the window
1393 * is removed from the window lists. Focus is set to the previous on the
1395 *----------------------------------------------------------------------
1398 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1400 WCoreWindow
*frame
= wwin
->frame
->core
;
1401 WWindow
*owner
= NULL
;
1402 WWindow
*newFocusedWindow
= NULL
;
1404 WScreen
*scr
= wwin
->screen_ptr
;
1408 wwin
->frame
->workspace
= -1;
1410 wKWMUpdateClientWorkspace(wwin
);
1413 /* First close attribute editor window if open */
1414 if (wwin
->flags
.inspector_open
) {
1415 wCloseInspectorForWindow(wwin
);
1418 /* Close window menu if it's open for this window */
1419 if (wwin
->flags
.menu_open_for_me
) {
1420 CloseWindowMenu(scr
);
1424 if (!wwin
->flags
.internal_window
)
1425 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1427 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1429 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1430 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1433 XUnmapWindow(dpy
, frame
->window
);
1435 XUnmapWindow(dpy
, wwin
->client_win
);
1437 /* deselect window */
1438 wSelectWindow(wwin
, False
);
1440 /* remove all pending events on window */
1441 /* I think this only matters for autoraise */
1442 if (wPreferences
.raise_delay
)
1443 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1447 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1449 /* reparent the window back to the root */
1451 wClientRestore(wwin
);
1453 if (wwin
->transient_for
!=scr
->root_win
) {
1454 owner
= wWindowFor(wwin
->transient_for
);
1456 if (!owner
->flags
.semi_focused
) {
1459 owner
->flags
.semi_focused
= 0;
1464 wasFocused
= wwin
->flags
.focused
;
1466 /* remove from window focus list */
1467 if (!wwin
->prev
&& !wwin
->next
) {
1468 /* was the only window */
1469 scr
->focused_window
= NULL
;
1470 newFocusedWindow
= NULL
;
1475 wwin
->prev
->next
= wwin
->next
;
1477 wwin
->next
->prev
= wwin
->prev
;
1479 scr
->focused_window
= wwin
->prev
;
1480 scr
->focused_window
->next
= NULL
;
1483 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1485 /* if in click to focus mode and the window
1486 * was a transient, focus the owner window
1489 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1490 tmp
= wWindowFor(wwin
->transient_for
);
1491 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1495 /* otherwise, focus the next one in the focus list */
1497 tmp
= scr
->focused_window
;
1498 while (tmp
) { /* look for one in the window list first */
1499 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1500 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1504 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1505 tmp
= scr
->focused_window
;
1507 if (!WFLAGP(tmp
, no_focusable
)
1508 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1515 newFocusedWindow
= tmp
;
1517 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1518 || wPreferences
.focus_mode
==WKF_POINTER
) {
1523 /* This is to let the root window get the keyboard input
1524 * if Sloppy focus mode and no other window get focus.
1525 * This way keybindings will not freeze.
1528 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1529 &foo
, &foo
, &foo
, &foo
, &mask
))
1530 tmp
= wWindowFor(win
);
1533 newFocusedWindow
= tmp
;
1535 newFocusedWindow
= NULL
;
1539 if (!wwin
->flags
.internal_window
) {
1541 wGNOMERemoveClient(wwin
);
1544 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1549 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1550 (unsigned)frame
->window
);
1554 if (newFocusedWindow
!= owner
&& owner
) {
1555 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1557 wSetFocusTo(scr
, newFocusedWindow
);
1559 wWindowDestroy(wwin
);
1565 wWindowMap(WWindow
*wwin
)
1567 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1568 if (!wwin
->flags
.shaded
) {
1569 /* window will be remapped when getting MapNotify */
1570 XSelectInput(dpy
, wwin
->client_win
,
1571 wwin
->event_mask
& ~StructureNotifyMask
);
1572 XMapWindow(dpy
, wwin
->client_win
);
1573 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1575 wwin
->flags
.mapped
= 1;
1581 wWindowUnmap(WWindow
*wwin
)
1583 wwin
->flags
.mapped
= 0;
1585 /* prevent window withdrawal when getting UnmapNotify */
1586 XSelectInput(dpy
, wwin
->client_win
,
1587 wwin
->event_mask
& ~StructureNotifyMask
);
1588 XUnmapWindow(dpy
, wwin
->client_win
);
1589 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1591 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1597 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1602 #ifdef KEEP_XKB_LOCK_STATUS
1603 if (wPreferences
.modelock
) {
1604 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1606 #endif /* KEEP_XKB_LOCK_STATUS */
1608 wwin
->flags
.semi_focused
= 0;
1610 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1612 wwin
->flags
.focused
= 1;
1614 wWindowResetMouseGrabs(wwin
);
1616 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1618 if (owin
== wwin
|| !owin
)
1621 nowner
= wWindowFor(wwin
->transient_for
);
1623 /* new window is a transient for the old window */
1624 if (nowner
== owin
) {
1625 owin
->flags
.semi_focused
= 1;
1626 wWindowUnfocus(nowner
);
1630 oowner
= wWindowFor(owin
->transient_for
);
1632 /* new window is owner of old window */
1633 if (wwin
== oowner
) {
1634 wWindowUnfocus(owin
);
1639 wWindowUnfocus(owin
);
1643 /* new window has same owner of old window */
1644 if (oowner
== nowner
) {
1645 /* prevent unfocusing of owner */
1646 oowner
->flags
.semi_focused
= 0;
1647 wWindowUnfocus(owin
);
1648 oowner
->flags
.semi_focused
= 1;
1653 /* nowner != NULL && oowner != nowner */
1654 nowner
->flags
.semi_focused
= 1;
1655 wWindowUnfocus(nowner
);
1656 wWindowUnfocus(owin
);
1661 wWindowUnfocus(WWindow
*wwin
)
1663 CloseWindowMenu(wwin
->screen_ptr
);
1665 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1666 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1668 if (wwin
->transient_for
!=None
1669 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1671 owner
= wWindowFor(wwin
->transient_for
);
1672 if (owner
&& owner
->flags
.semi_focused
) {
1673 owner
->flags
.semi_focused
= 0;
1674 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1675 wWindowUnfocus(owner
);
1676 wFrameWindowPaint(owner
->frame
);
1680 wwin
->flags
.focused
= 0;
1682 wWindowResetMouseGrabs(wwin
);
1684 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1691 *----------------------------------------------------------------------
1693 * wWindowConstrainSize--
1694 * Constrains size for the client window, taking the maximal size,
1695 * window resize increments and other size hints into account.
1698 * The closest size to what was given that the client window can
1701 *----------------------------------------------------------------------
1704 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1706 int width
= *nwidth
;
1707 int height
= *nheight
;
1710 int minW
= 1, minH
= 1;
1711 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1712 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1713 int minAX
= -1, minAY
= -1;
1714 int maxAX
= -1, maxAY
= -1;
1718 if (wwin
->normal_hints
) {
1719 winc
= wwin
->normal_hints
->width_inc
;
1720 hinc
= wwin
->normal_hints
->height_inc
;
1721 minW
= wwin
->normal_hints
->min_width
;
1722 minH
= wwin
->normal_hints
->min_height
;
1723 maxW
= wwin
->normal_hints
->max_width
;
1724 maxH
= wwin
->normal_hints
->max_height
;
1725 if (wwin
->normal_hints
->flags
& PAspect
) {
1726 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1727 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1728 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1729 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1743 /* aspect ratio code borrowed from olwm */
1745 /* adjust max aspect ratio */
1746 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1747 if (maxAX
> maxAY
) {
1748 height
= (width
* maxAY
) / maxAX
;
1749 if (height
> maxH
) {
1751 width
= (height
* maxAX
) / maxAY
;
1754 width
= (height
* maxAX
) / maxAY
;
1757 height
= (width
* maxAY
) / maxAX
;
1762 /* adjust min aspect ratio */
1763 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1764 if (minAX
> minAY
) {
1765 height
= (width
* minAY
) / minAX
;
1766 if (height
< minH
) {
1768 width
= (height
* minAX
) / minAY
;
1771 width
= (height
* minAX
) / minAY
;
1774 height
= (width
* minAY
) / minAX
;
1781 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1783 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1787 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1789 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1798 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1800 WScreen
*scr
= wwin
->screen_ptr
;
1804 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1805 || workspace
== wwin
->frame
->workspace
)
1808 if (workspace
!= scr
->current_workspace
) {
1809 /* Sent to other workspace. Unmap window */
1810 if ((wwin
->flags
.mapped
1811 || wwin
->flags
.shaded
1812 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1813 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1815 wapp
= wApplicationOf(wwin
->main_window
);
1817 wapp
->last_workspace
= workspace
;
1819 if (wwin
->flags
.miniaturized
) {
1821 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1822 wwin
->icon
->mapped
= 0;
1826 wSetFocusTo(scr
, NULL
);
1830 /* brought to current workspace. Map window */
1831 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1833 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1834 wwin
->icon
->mapped
= 1;
1836 } else if (!wwin
->flags
.mapped
&&
1837 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1841 if (!IS_OMNIPRESENT(wwin
)) {
1842 wwin
->frame
->workspace
= workspace
;
1843 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1846 wGNOMEUpdateClientStateHint(wwin
, True
);
1849 wKWMUpdateClientWorkspace(wwin
);
1850 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1859 wWindowSynthConfigureNotify(WWindow
*wwin
)
1863 sevent
.type
= ConfigureNotify
;
1864 sevent
.xconfigure
.display
= dpy
;
1865 sevent
.xconfigure
.event
= wwin
->client_win
;
1866 sevent
.xconfigure
.window
= wwin
->client_win
;
1868 sevent
.xconfigure
.x
= wwin
->client
.x
;
1869 sevent
.xconfigure
.y
= wwin
->client
.y
;
1870 sevent
.xconfigure
.width
= wwin
->client
.width
;
1871 sevent
.xconfigure
.height
= wwin
->client
.height
;
1873 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1874 if (WFLAGP(wwin
, no_titlebar
))
1875 sevent
.xconfigure
.above
= None
;
1877 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1879 sevent
.xconfigure
.override_redirect
= False
;
1880 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1882 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1889 *----------------------------------------------------------------------
1890 * wWindowConfigure--
1891 * Configures the frame, decorations and client window to the
1892 * specified geometry. The geometry is not checked for validity,
1893 * wWindowConstrainSize() must be used for that.
1894 * The size parameters are for the client window, but the position is
1896 * The client window receives a ConfigureNotify event, according
1897 * to what ICCCM says.
1903 * Window size and position are changed and client window receives
1904 * a ConfigureNotify event.
1905 *----------------------------------------------------------------------
1908 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1910 int req_x
, req_y
; /* new position of the frame */
1911 int req_width
, req_height
; /* new size of the client */
1913 int synth_notify
= False
;
1916 resize
= (req_width
!=wwin
->client
.width
1917 || req_height
!=wwin
->client
.height
);
1919 * if the window is being moved but not resized then
1920 * send a synthetic ConfigureNotify
1922 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1923 synth_notify
= True
;
1926 if (WFLAGP(wwin
, dont_move_off
))
1927 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1928 req_width
, req_height
);
1930 if (req_width
< MIN_WINDOW_SIZE
)
1931 req_width
= MIN_WINDOW_SIZE
;
1932 if (req_height
< MIN_WINDOW_SIZE
)
1933 req_height
= MIN_WINDOW_SIZE
;
1935 /* If growing, resize inner part before frame,
1936 * if shrinking, resize frame before.
1937 * This will prevent the frame (that can have a different color)
1938 * to be exposed, causing flicker */
1939 if (req_height
> wwin
->frame
->core
->height
1940 || req_width
> wwin
->frame
->core
->width
)
1941 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1943 if (wwin
->flags
.shaded
) {
1944 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1945 req_width
, wwin
->frame
->core
->height
);
1946 wwin
->old_geometry
.height
= req_height
;
1950 h
= req_height
+ wwin
->frame
->top_width
1951 + wwin
->frame
->bottom_width
;
1953 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1956 if (!(req_height
> wwin
->frame
->core
->height
1957 || req_width
> wwin
->frame
->core
->width
))
1958 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1960 wwin
->client
.x
= req_x
;
1961 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1962 wwin
->client
.width
= req_width
;
1963 wwin
->client
.height
= req_height
;
1965 wwin
->client
.x
= req_x
;
1966 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1968 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1970 wwin
->frame_x
= req_x
;
1971 wwin
->frame_y
= req_y
;
1974 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1975 wWindowSetShape(wwin
);
1980 wWindowSynthConfigureNotify(wwin
);
1986 wWindowMove(wwin
, req_x
, req_y
)
1988 int req_x
, req_y
; /* new position of the frame */
1990 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1991 int synth_notify
= False
;
1993 /* Send a synthetic ConfigureNotify event for every window movement. */
1994 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1995 synth_notify
= True
;
1998 /* A single synthetic ConfigureNotify event is sent at the end of
1999 * a completed (opaque) movement in moveres.c */
2002 if (WFLAGP(wwin
, dont_move_off
))
2003 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2004 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2006 wwin
->client
.x
= req_x
;
2007 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2009 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2011 wwin
->frame_x
= req_x
;
2012 wwin
->frame_y
= req_y
;
2014 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2016 wWindowSynthConfigureNotify(wwin
);
2022 wWindowUpdateButtonImages(WWindow
*wwin
)
2024 WScreen
*scr
= wwin
->screen_ptr
;
2025 Pixmap pixmap
, mask
;
2026 WFrameWindow
*fwin
= wwin
->frame
;
2028 if (WFLAGP(wwin
, no_titlebar
))
2031 /* miniaturize button */
2033 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2034 if (wwin
->wm_gnustep_attr
2035 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2036 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2038 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2039 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2044 if (fwin
->lbutton_image
2045 && (fwin
->lbutton_image
->image
!= pixmap
2046 || fwin
->lbutton_image
->mask
!= mask
)) {
2047 wPixmapDestroy(fwin
->lbutton_image
);
2048 fwin
->lbutton_image
= NULL
;
2051 if (!fwin
->lbutton_image
) {
2052 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2053 fwin
->lbutton_image
->client_owned
= 1;
2054 fwin
->lbutton_image
->client_owned_mask
= 1;
2057 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2058 wPixmapDestroy(fwin
->lbutton_image
);
2060 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2064 #ifdef XKB_BUTTON_HINT
2065 if (!WFLAGP(wwin
, no_language_button
)) {
2066 if (fwin
->languagebutton_image
&&
2067 !fwin
->languagebutton_image
->shared
) {
2068 wPixmapDestroy(fwin
->languagebutton_image
);
2070 fwin
->languagebutton_image
=
2071 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2077 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2078 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2080 if (!WFLAGP(wwin
, no_close_button
)) {
2081 if (wwin
->wm_gnustep_attr
2082 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2083 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2085 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2086 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2090 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2091 || fwin
->rbutton_image
->mask
!= mask
)) {
2092 wPixmapDestroy(fwin
->rbutton_image
);
2093 fwin
->rbutton_image
= NULL
;
2096 if (!fwin
->rbutton_image
) {
2097 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2098 fwin
->rbutton_image
->client_owned
= 1;
2099 fwin
->rbutton_image
->client_owned_mask
= 1;
2102 } else if (WFLAGP(wwin
, kill_close
)) {
2104 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2105 wPixmapDestroy(fwin
->rbutton_image
);
2107 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2109 } else if (MGFLAGP(wwin
, broken_close
)) {
2111 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2112 wPixmapDestroy(fwin
->rbutton_image
);
2114 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2118 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2119 wPixmapDestroy(fwin
->rbutton_image
);
2121 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2125 /* force buttons to be redrawn */
2126 fwin
->flags
.need_texture_change
= 1;
2127 wFrameWindowPaint(fwin
);
2132 *---------------------------------------------------------------------------
2133 * wWindowConfigureBorders--
2134 * Update window border configuration according to attribute flags.
2136 *---------------------------------------------------------------------------
2139 wWindowConfigureBorders(WWindow
*wwin
)
2145 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2146 #ifdef XKB_BUTTON_HINT
2147 flags
|= WFF_LANGUAGE_BUTTON
;
2149 if (!WFLAGP(wwin
, no_titlebar
))
2150 flags
|= WFF_TITLEBAR
;
2151 if (!WFLAGP(wwin
, no_resizebar
))
2152 flags
|= WFF_RESIZEBAR
;
2153 if (wwin
->flags
.shaded
)
2154 flags
|= WFF_IS_SHADED
;
2156 oldh
= wwin
->frame
->top_width
;
2157 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2158 if (oldh
!= wwin
->frame
->top_width
) {
2159 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2161 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2162 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2163 wwin
->client
.width
, wwin
->client
.height
);
2167 if (!WFLAGP(wwin
, no_miniaturize_button
)
2168 && wwin
->frame
->flags
.hide_left_button
)
2169 flags
|= WFF_LEFT_BUTTON
;
2171 #ifdef XKB_BUTTON_HINT
2172 if (!WFLAGP(wwin
, no_language_button
)
2173 && wwin
->frame
->flags
.hide_language_button
)
2174 flags
|= WFF_LANGUAGE_BUTTON
;
2177 if (!WFLAGP(wwin
, no_close_button
)
2178 && wwin
->frame
->flags
.hide_right_button
)
2179 flags
|= WFF_RIGHT_BUTTON
;
2182 wWindowUpdateButtonImages(wwin
);
2183 wFrameWindowShowButton(wwin
->frame
, flags
);
2187 if (WFLAGP(wwin
, no_miniaturize_button
)
2188 && !wwin
->frame
->flags
.hide_left_button
)
2189 flags
|= WFF_LEFT_BUTTON
;
2191 #ifdef XKB_BUTTON_HINT
2192 if (WFLAGP(wwin
, no_language_button
)
2193 && !wwin
->frame
->flags
.hide_language_button
)
2194 flags
|= WFF_LANGUAGE_BUTTON
;
2197 if (WFLAGP(wwin
, no_close_button
)
2198 && !wwin
->frame
->flags
.hide_right_button
)
2199 flags
|= WFF_RIGHT_BUTTON
;
2202 wFrameWindowHideButton(wwin
->frame
, flags
);
2205 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2206 wWindowSetShape(wwin
);
2214 wWindowSaveState(WWindow
*wwin
)
2219 memset(data
, 0, sizeof(CARD32
)*10);
2220 data
[0] = wwin
->frame
->workspace
;
2221 data
[1] = wwin
->flags
.miniaturized
;
2222 data
[2] = wwin
->flags
.shaded
;
2223 data
[3] = wwin
->flags
.hidden
;
2225 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2226 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2227 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2230 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2231 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2232 (unsigned char *)data
, 10);
2237 getSavedState(Window window
, WSavedState
**state
)
2241 unsigned long nitems_ret
;
2242 unsigned long bytes_after_ret
;
2245 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2246 True
, _XA_WINDOWMAKER_STATE
,
2247 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2248 (unsigned char **)&data
)!=Success
|| !data
)
2251 *state
= malloc(sizeof(WSavedState
));
2254 (*state
)->workspace
= data
[0];
2255 (*state
)->miniaturized
= data
[1];
2256 (*state
)->shaded
= data
[2];
2257 (*state
)->hidden
= data
[3];
2258 (*state
)->use_geometry
= data
[4];
2259 (*state
)->x
= data
[5];
2260 (*state
)->y
= data
[6];
2261 (*state
)->w
= data
[7];
2262 (*state
)->h
= data
[8];
2263 (*state
)->window_shortcuts
= data
[9];
2267 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2276 wWindowClearShape(WWindow
*wwin
)
2278 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2279 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2284 wWindowSetShape(WWindow
*wwin
)
2288 #ifdef OPTIMIZE_SHAPE
2293 /* only shape is the client's */
2294 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2298 /* Get array of rectangles describing the shape mask */
2299 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2305 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2311 /* insert our decoration rectangles in the rect list */
2312 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2315 if (!WFLAGP(wwin
, no_titlebar
)) {
2317 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2318 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2319 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2322 if (!WFLAGP(wwin
, no_resizebar
)) {
2324 urec
[count
].y
= wwin
->frame
->core
->height
2325 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2326 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2327 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2331 /* shape our frame window */
2332 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2333 0, wwin
->frame
->top_width
, urec
, count
,
2334 ShapeSet
, Unsorted
);
2340 #endif /* OPTIMIZE_SHAPE */
2342 if (!WFLAGP(wwin
, no_titlebar
)) {
2345 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2346 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2349 if (!WFLAGP(wwin
, no_resizebar
)) {
2351 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2352 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2353 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2357 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2358 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2360 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2361 0, wwin
->frame
->top_width
, wwin
->client_win
,
2362 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2367 /* ====================================================================== */
2370 getFocusMode(WWindow
*wwin
)
2374 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2375 if (wwin
->wm_hints
->input
== True
) {
2376 if (wwin
->protocols
.TAKE_FOCUS
)
2377 mode
= WFM_LOCALLY_ACTIVE
;
2381 if (wwin
->protocols
.TAKE_FOCUS
)
2382 mode
= WFM_GLOBALLY_ACTIVE
;
2384 mode
= WFM_NO_INPUT
;
2394 wWindowSetKeyGrabs(WWindow
*wwin
)
2399 for (i
=0; i
<WKBD_LAST
; i
++) {
2400 key
= &wKeyBindings
[i
];
2402 if (key
->keycode
==0)
2404 if (key
->modifier
!=AnyModifier
) {
2405 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2406 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2408 /* Also grab all modifier combinations possible that include,
2409 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2410 * work even if the NumLock/ScrollLock key is on.
2412 wHackedGrabKey(key
->keycode
, key
->modifier
,
2413 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2417 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2418 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2422 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2429 wWindowResetMouseGrabs(WWindow
*wwin
)
2431 /* Mouse grabs can't be done on the client window because of
2432 * ICCCM and because clients that try to do the same will crash.
2434 * But there is a problem wich makes tbar buttons of unfocused
2435 * windows not usable as the click goes to the frame window instead
2436 * of the button itself. Must figure a way to fix that.
2439 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2441 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2442 /* grabs for Meta+drag */
2443 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2444 True
, ButtonPressMask
, GrabModeSync
,
2445 GrabModeAsync
, None
, None
);
2448 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)) {
2449 /* the passive grabs to focus the window */
2450 if (wPreferences
.focus_mode
== WKF_CLICK
)
2451 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2452 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2460 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2462 if (attr
->flags
& GSExtraFlagsAttr
) {
2463 if (MGFLAGP(wwin
, broken_close
) !=
2464 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2465 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2466 wWindowUpdateButtonImages(wwin
);
2473 wWindowAddSavedState(char *instance
, char *class, char *command
,
2474 pid_t pid
, WSavedState
*state
)
2476 WWindowState
*wstate
;
2478 wstate
= malloc(sizeof(WWindowState
));
2482 memset(wstate
, 0, sizeof(WWindowState
));
2485 wstate
->instance
= wstrdup(instance
);
2487 wstate
->class = wstrdup(class);
2489 wstate
->command
= wstrdup(command
);
2490 wstate
->state
= state
;
2492 wstate
->next
= windowState
;
2493 windowState
= wstate
;
2496 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2504 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2508 wWindowGetSavedState(Window win
)
2510 char *instance
, *class, *command
=NULL
;
2511 WWindowState
*wstate
= windowState
;
2518 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2520 command
= FlattenStringList(argv
, argc
);
2521 XFreeStringList(argv
);
2526 if (PropGetWMClass(win
, &class, &instance
)) {
2528 if (SAME(instance
, wstate
->instance
) &&
2529 SAME(class, wstate
->class) &&
2530 SAME(command
, wstate
->command
)) {
2533 wstate
= wstate
->next
;
2540 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2544 if (command
) free(command
);
2545 if (instance
) XFree(instance
);
2546 if (class) XFree(class);
2553 wWindowDeleteSavedState(WMagicNumber id
)
2555 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2557 if (!wstate
|| !windowState
)
2562 windowState
= wstate
->next
;
2564 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2565 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2567 if (wstate
->instance
) free(wstate
->instance
);
2568 if (wstate
->class) free(wstate
->class);
2569 if (wstate
->command
) free(wstate
->command
);
2570 free(wstate
->state
);
2574 if (tmp
->next
==wstate
) {
2575 tmp
->next
=wstate
->next
;
2577 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2578 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2580 if (wstate
->instance
) free(wstate
->instance
);
2581 if (wstate
->class) free(wstate
->class);
2582 if (wstate
->command
) free(wstate
->command
);
2583 free(wstate
->state
);
2594 wWindowDeleteSavedStatesForPID(pid_t pid
)
2596 WWindowState
*tmp
, *wstate
;
2602 if (tmp
->pid
== pid
) {
2603 wstate
= windowState
;
2604 windowState
= tmp
->next
;
2606 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2607 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2609 if (wstate
->instance
) free(wstate
->instance
);
2610 if (wstate
->class) free(wstate
->class);
2611 if (wstate
->command
) free(wstate
->command
);
2612 free(wstate
->state
);
2616 if (tmp
->next
->pid
==pid
) {
2618 tmp
->next
= wstate
->next
;
2620 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2621 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2623 if (wstate
->instance
) free(wstate
->instance
);
2624 if (wstate
->class) free(wstate
->class);
2625 if (wstate
->command
) free(wstate
->command
);
2626 free(wstate
->state
);
2636 /* ====================================================================== */
2639 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2641 WWindow
*wwin
= data
;
2643 #ifndef NUMLOCK_HACK
2644 if ((event
->xbutton
.state
& ValidModMask
)
2645 != (event
->xbutton
.state
& ~LockMask
)) {
2646 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2647 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2651 event
->xbutton
.state
&= ValidModMask
;
2653 CloseWindowMenu(wwin
->screen_ptr
);
2655 if (wPreferences
.focus_mode
==WKF_CLICK
2656 && !(event
->xbutton
.state
&ControlMask
)
2657 && !WFLAGP(wwin
, no_focusable
)) {
2658 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2661 if (event
->xbutton
.button
== Button1
)
2662 wRaiseFrame(wwin
->frame
->core
);
2664 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2665 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2666 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2667 GrabModeAsync
, GrabModeAsync
, None
,
2668 None
, CurrentTime
)!=GrabSuccess
) {
2670 wwarning("pointer grab failed for window move");
2676 if (event
->xbutton
.state
& MOD_MASK
) {
2677 /* move the window */
2678 wMouseMoveWindow(wwin
, event
);
2679 XUngrabPointer(dpy
, CurrentTime
);
2681 wMouseResizeWindow(wwin
, event
);
2682 XUngrabPointer(dpy
, CurrentTime
);
2689 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2691 WWindow
*wwin
= data
;
2693 event
->xbutton
.state
&= ValidModMask
;
2695 if (event
->xbutton
.button
==Button1
) {
2696 if (event
->xbutton
.state
== 0) {
2697 if (!WFLAGP(wwin
, no_shadeable
)) {
2699 if (wwin
->flags
.shaded
)
2700 wUnshadeWindow(wwin
);
2707 if (event
->xbutton
.state
& ControlMask
)
2708 dir
|= MAX_VERTICAL
;
2710 if (event
->xbutton
.state
& ShiftMask
) {
2711 dir
|= MAX_HORIZONTAL
;
2712 if (!(event
->xbutton
.state
& ControlMask
))
2713 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2716 /* maximize window */
2717 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2718 if (wwin
->flags
.maximized
)
2719 wUnmaximizeWindow(wwin
);
2721 wMaximizeWindow(wwin
, dir
);
2724 } else if (event
->xbutton
.button
==Button3
) {
2725 if (event
->xbutton
.state
& MOD_MASK
) {
2726 wHideOtherApplications(wwin
);
2728 } else if (event
->xbutton
.button
==Button2
) {
2729 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2735 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2737 WWindow
*wwin
= desc
->parent
;
2739 event
->xbutton
.state
&= ValidModMask
;
2741 CloseWindowMenu(wwin
->screen_ptr
);
2743 if (wPreferences
.focus_mode
==WKF_CLICK
2744 && !(event
->xbutton
.state
&ControlMask
)
2745 && !WFLAGP(wwin
, no_focusable
)) {
2746 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2748 if (event
->xbutton
.button
== Button1
) {
2749 wRaiseFrame(wwin
->frame
->core
);
2752 if (event
->xbutton
.state
& MOD_MASK
) {
2753 /* move the window */
2754 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2755 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2756 GrabModeAsync
, GrabModeAsync
, None
,
2757 None
, CurrentTime
)!=GrabSuccess
) {
2759 wwarning("pointer grab failed for window move");
2763 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2764 wMouseResizeWindow(wwin
, event
);
2766 wMouseMoveWindow(wwin
, event
);
2767 XUngrabPointer(dpy
, CurrentTime
);
2773 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2775 WWindow
*wwin
= (WWindow
*)data
;
2777 #ifndef NUMLOCK_HACK
2778 if ((event
->xbutton
.state
& ValidModMask
)
2779 != (event
->xbutton
.state
& ~LockMask
)) {
2780 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2781 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2784 event
->xbutton
.state
&= ValidModMask
;
2786 CloseWindowMenu(wwin
->screen_ptr
);
2788 if (wPreferences
.focus_mode
==WKF_CLICK
2789 && !(event
->xbutton
.state
&ControlMask
)
2790 && !WFLAGP(wwin
, no_focusable
)) {
2791 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2794 if (event
->xbutton
.button
== Button1
2795 || event
->xbutton
.button
== Button2
) {
2797 if (event
->xbutton
.button
== Button1
) {
2798 if (event
->xbutton
.state
& MOD_MASK
) {
2799 wLowerFrame(wwin
->frame
->core
);
2801 wRaiseFrame(wwin
->frame
->core
);
2804 if ((event
->xbutton
.state
& ShiftMask
)
2805 && !(event
->xbutton
.state
& ControlMask
)) {
2806 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2809 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2810 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2811 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2812 GrabModeAsync
, GrabModeAsync
, None
,
2813 None
, CurrentTime
)!=GrabSuccess
) {
2815 wwarning("pointer grab failed for window move");
2820 /* move the window */
2821 wMouseMoveWindow(wwin
, event
);
2823 XUngrabPointer(dpy
, CurrentTime
);
2824 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2825 && !wwin
->flags
.internal_window
2826 && !WCHECK_STATE(WSTATE_MODAL
)) {
2827 WObjDescriptor
*desc
;
2829 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2830 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2831 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2832 GrabModeAsync
, GrabModeAsync
, None
,
2833 None
, CurrentTime
)!=GrabSuccess
) {
2835 wwarning("pointer grab failed for window move");
2840 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2841 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2843 /* allow drag select */
2844 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2845 event
->xany
.send_event
= True
;
2846 (*desc
->handle_mousedown
)(desc
, event
);
2848 XUngrabPointer(dpy
, CurrentTime
);
2855 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2857 WWindow
*wwin
= data
;
2859 event
->xbutton
.state
&= ValidModMask
;
2861 CloseWindowMenu(wwin
->screen_ptr
);
2863 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2866 /* if control-click, kill the client */
2867 if (event
->xbutton
.state
& ControlMask
) {
2871 if (wwin
->flags
.olwm_push_pin_out
) {
2873 wwin
->flags
.olwm_push_pin_out
= 0;
2875 wOLWMChangePushpinState(wwin
, True
);
2877 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2882 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2883 /* send delete message */
2884 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2891 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2893 WWindow
*wwin
= data
;
2895 CloseWindowMenu(wwin
->screen_ptr
);
2897 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2900 /* send delete message */
2901 if (wwin
->protocols
.DELETE_WINDOW
) {
2902 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2909 #ifdef XKB_BUTTON_HINT
2911 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2913 WWindow
*wwin
= data
;
2914 WFrameWindow
*fwin
= wwin
->frame
;
2915 WScreen
*scr
= fwin
->screen_ptr
;
2916 XkbStateRec staterec
;
2919 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2921 tl
= wwin
->frame
->languagemode
;
2922 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2923 wwin
->frame
->last_languagemode
= tl
;
2924 wSetFocusTo(scr
, wwin
);
2925 wwin
->frame
->languagebutton_image
=
2926 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
2927 wwin
->frame
->languagemode
];
2928 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2929 if (event
->xbutton
.button
== Button3
)
2931 wRaiseFrame(fwin
->core
);
2937 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2939 WWindow
*wwin
= data
;
2941 event
->xbutton
.state
&= ValidModMask
;
2943 CloseWindowMenu(wwin
->screen_ptr
);
2945 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2948 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2949 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2953 if ((event
->xbutton
.state
& ControlMask
) ||
2954 (event
->xbutton
.button
== Button3
)) {
2956 wapp
= wApplicationOf(wwin
->main_window
);
2957 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2958 wHideApplication(wapp
);
2959 } else if (event
->xbutton
.state
==0) {
2960 wIconifyWindow(wwin
);