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
,
917 &wPreferences
.window_title_clearance
, foo
,
918 scr
->window_title_texture
,
919 scr
->resizebar_texture
,
920 scr
->window_title_pixel
,
921 #ifdef DRAWSTRING_PLUGIN
924 &scr
->window_title_gc
,
927 wwin
->frame
->flags
.is_client_window_frame
= 1;
928 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
930 /* setup button images */
931 wWindowUpdateButtonImages(wwin
);
933 /* hide unused buttons */
935 if (WFLAGP(wwin
, no_close_button
))
936 foo
|= WFF_RIGHT_BUTTON
;
937 if (WFLAGP(wwin
, no_miniaturize_button
))
938 foo
|= WFF_LEFT_BUTTON
;
939 #ifdef XKB_BUTTON_HINT
940 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
941 foo
|= WFF_LANGUAGE_BUTTON
;
944 wFrameWindowHideButton(wwin
->frame
, foo
);
946 wwin
->frame
->child
= wwin
;
949 /* emulate olwm push pin. Make the button look as pushed-in for
950 * the pinned-out state. When the button is clicked, it will
951 * revert to the normal position, which means the pin is pinned-in.
953 if (wwin
->flags
.olwm_push_pin_out
)
954 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
955 #endif /* OLWM_HINTS */
957 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
961 wwin
->frame
->workspace
= workspace
;
963 wwin
->frame
->on_click_left
= windowIconifyClick
;
964 #ifdef XKB_BUTTON_HINT
965 if (wPreferences
.modelock
)
966 wwin
->frame
->on_click_language
= windowLanguageClick
;
969 wwin
->frame
->on_click_right
= windowCloseClick
;
970 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
972 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
973 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
975 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
978 XSelectInput(dpy
, wwin
->client_win
,
979 wwin
->event_mask
& ~StructureNotifyMask
);
981 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
982 0, wwin
->frame
->top_width
);
984 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
990 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
992 /* if gravity is to the south, account for the border sizes */
994 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
998 * wWindowConfigure() will init the client window's size
999 * (wwin->client.{width,height}) and all other geometry
1000 * related variables (frame_x,frame_y)
1002 wWindowConfigure(wwin
, x
, y
, width
, height
);
1004 /* to make sure the window receives it's new position after reparenting */
1005 wWindowSynthConfigureNotify(wwin
);
1008 *--------------------------------------------------
1010 * Setup descriptors and save window to internal
1013 *--------------------------------------------------
1016 if (wwin
->main_window
!=None
) {
1020 /* Leader windows do not necessary set themselves as leaders.
1021 * If this is the case, point the leader of this window to
1023 leader
= wWindowFor(wwin
->main_window
);
1024 if (leader
&& leader
->main_window
==None
) {
1025 leader
->main_window
= leader
->client_win
;
1027 app
= wApplicationCreate(scr
, wwin
->main_window
);
1029 app
->last_workspace
= workspace
;
1032 * Do application specific stuff, like setting application
1036 if (wwin
->flags
.hidden
) {
1037 /* if the window was set to hidden because it was hidden
1038 * in a previous incarnation and that state was restored */
1039 app
->flags
.hidden
= 1;
1042 if (app
->flags
.hidden
) {
1043 wwin
->flags
.hidden
= 1;
1048 /* setup the frame descriptor */
1049 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1050 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1051 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1053 /* don't let windows go away if we die */
1054 XAddToSaveSet(dpy
, window
);
1056 XLowerWindow(dpy
, window
);
1058 /* if window is in this workspace and should be mapped, then map it */
1059 if (!wwin
->flags
.miniaturized
1060 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1061 && !wwin
->flags
.hidden
&& !withdraw
) {
1063 /* The following "if" is to avoid crashing of clients that expect
1064 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1065 * after the return from this function.
1067 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1068 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1070 wClientSetState(wwin
, NormalState
, None
);
1074 /* if not auto focus, then map the window under the currently
1076 #define _WIDTH(w) (w)->frame->core->width
1077 #define _HEIGHT(w) (w)->frame->core->height
1078 if (!wPreferences
.auto_focus
&& scr
->focused_window
1079 && !scr
->flags
.startup
&& !transientOwner
1080 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1081 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1082 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1083 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1084 || wwin
->flags
.maximized
)) {
1085 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1093 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1094 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1096 * The brain damaged idiotic non-click to focus modes will
1097 * have trouble with this because:
1099 * 1. window is created and mapped by the client
1100 * 2. window is mapped by wmaker in small size
1101 * 3. window is animated to grow to normal size
1102 * 4. this function returns to normal event loop
1103 * 5. eventually, the EnterNotify event that would trigger
1104 * the window focusing (if the mouse is over that window)
1105 * will be processed by wmaker.
1106 * But since this event will be rather delayed
1107 * (step 3 has a large delay) the time when the event ocurred
1108 * and when it is processed, the client that owns that window
1109 * will reject the XSetInputFocus() for it.
1111 && (wPreferences
.focus_mode
==WKF_CLICK
1112 || wPreferences
.auto_focus
)) {
1113 DoWindowBirth(wwin
);
1119 /* setup stacking descriptor */
1120 if (transientOwner
) {
1121 /* && wPreferences.on_top_transients */
1122 if (transientOwner
) {
1123 wwin
->frame
->core
->stacking
->child_of
=
1124 transientOwner
->frame
->core
;
1127 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1131 if (!scr
->focused_window
) {
1132 /* first window on the list */
1135 scr
->focused_window
= wwin
;
1139 /* add window at beginning of focus window list */
1140 tmp
= scr
->focused_window
;
1149 wGNOMEUpdateClientStateHint(wwin
, True
);
1152 wKWMUpdateClientWorkspace(wwin
);
1153 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1159 *--------------------------------------------------
1161 * Final preparations before window is ready to go
1163 *--------------------------------------------------
1166 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1169 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1170 && !wwin
->flags
.hidden
) {
1171 if (((transientOwner
&& transientOwner
->flags
.focused
)
1172 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1173 wSetFocusTo(scr
, wwin
);
1175 wWindowResetMouseGrabs(wwin
);
1177 if (!WFLAGP(wwin
, no_bind_keys
)) {
1178 wWindowSetKeyGrabs(wwin
);
1181 wGNOMEUpdateClientListHint(scr
);
1184 wwin
->flags
.kwm_managed
= 1;
1186 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1189 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1191 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1194 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1195 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1197 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1198 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1204 *------------------------------------------------------------
1205 * Setup Notification Observers
1206 *------------------------------------------------------------
1208 WMAddNotificationObserver(appearanceObserver
, wwin
,
1209 WNWindowAppearanceSettingsChanged
, wwin
);
1213 *--------------------------------------------------
1215 * Cleanup temporary stuff
1217 *--------------------------------------------------
1221 wWindowDeleteSavedState(win_state
);
1223 /* If the window must be withdrawed, then do it now.
1224 * Must do some optimization, 'though */
1226 wwin
->flags
.mapped
= 0;
1227 wClientSetState(wwin
, WithdrawnState
, None
);
1228 wUnmanageWindow(wwin
, True
, False
);
1240 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1241 char *title
, int x
, int y
, int width
, int height
)
1246 wwin
= wWindowCreate();
1248 WMAddNotificationObserver(appearanceObserver
, wwin
,
1249 WNWindowAppearanceSettingsChanged
, wwin
);
1251 wwin
->flags
.internal_window
= 1;
1253 WSETUFLAG(wwin
, omnipresent
, 1);
1254 WSETUFLAG(wwin
, no_shadeable
, 1);
1255 WSETUFLAG(wwin
, no_resizable
, 1);
1256 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1258 wwin
->focus_mode
= WFM_PASSIVE
;
1260 wwin
->client_win
= window
;
1261 wwin
->screen_ptr
= scr
;
1263 wwin
->transient_for
= owner
;
1267 wwin
->client
.width
= width
;
1268 wwin
->client
.height
= height
;
1270 wwin
->frame_x
= wwin
->client
.x
;
1271 wwin
->frame_y
= wwin
->client
.y
;
1274 foo
= WFF_RIGHT_BUTTON
;
1275 foo
|= WFF_TITLEBAR
;
1276 #ifdef XKB_BUTTON_HINT
1277 foo
|= WFF_LANGUAGE_BUTTON
;
1280 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1281 wwin
->frame_x
, wwin
->frame_y
,
1283 &wPreferences
.window_title_clearance
, foo
,
1284 scr
->window_title_texture
,
1285 scr
->resizebar_texture
,
1286 scr
->window_title_pixel
,
1287 #ifdef DRAWSTRING_PLUGIN
1290 &scr
->window_title_gc
,
1293 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1295 wwin
->frame
->flags
.is_client_window_frame
= 1;
1296 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1298 wFrameWindowChangeTitle(wwin
->frame
, title
);
1300 /* setup button images */
1301 wWindowUpdateButtonImages(wwin
);
1304 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1306 wwin
->frame
->child
= wwin
;
1308 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1310 #ifdef XKB_BUTTON_HINT
1311 if (wPreferences
.modelock
)
1312 wwin
->frame
->on_click_language
= windowLanguageClick
;
1315 wwin
->frame
->on_click_right
= windowCloseClick
;
1317 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1318 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1320 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1322 wwin
->client
.y
+= wwin
->frame
->top_width
;
1323 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1324 0, wwin
->frame
->top_width
);
1326 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1327 wwin
->client
.width
, wwin
->client
.height
);
1329 /* setup the frame descriptor */
1330 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1331 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1332 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1335 XLowerWindow(dpy
, window
);
1336 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1338 /* setup stacking descriptor */
1341 wPreferences
.on_top_transients
&&
1343 wwin
->transient_for
!=None
1344 && wwin
->transient_for
!=scr
->root_win
) {
1346 tmp
= wWindowFor(wwin
->transient_for
);
1348 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1350 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1354 if (!scr
->focused_window
) {
1355 /* first window on the list */
1358 scr
->focused_window
= wwin
;
1362 /* add window at beginning of focus window list */
1363 tmp
= scr
->focused_window
;
1371 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1373 /* if (wPreferences.auto_focus)*/
1374 wSetFocusTo(scr
, wwin
);
1376 wWindowResetMouseGrabs(wwin
);
1378 wWindowSetKeyGrabs(wwin
);
1380 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1387 *----------------------------------------------------------------------
1389 * Removes the frame window from a window and destroys all data
1390 * related to it. The window will be reparented back to the root window
1391 * if restore is True.
1394 * Everything related to the window is destroyed and the window
1395 * is removed from the window lists. Focus is set to the previous on the
1397 *----------------------------------------------------------------------
1400 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1402 WCoreWindow
*frame
= wwin
->frame
->core
;
1403 WWindow
*owner
= NULL
;
1404 WWindow
*newFocusedWindow
= NULL
;
1406 WScreen
*scr
= wwin
->screen_ptr
;
1410 wwin
->frame
->workspace
= -1;
1412 wKWMUpdateClientWorkspace(wwin
);
1415 /* First close attribute editor window if open */
1416 if (wwin
->flags
.inspector_open
) {
1417 wCloseInspectorForWindow(wwin
);
1420 /* Close window menu if it's open for this window */
1421 if (wwin
->flags
.menu_open_for_me
) {
1422 CloseWindowMenu(scr
);
1426 if (!wwin
->flags
.internal_window
)
1427 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1429 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1431 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1432 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1435 XUnmapWindow(dpy
, frame
->window
);
1437 XUnmapWindow(dpy
, wwin
->client_win
);
1439 /* deselect window */
1440 wSelectWindow(wwin
, False
);
1442 /* remove all pending events on window */
1443 /* I think this only matters for autoraise */
1444 if (wPreferences
.raise_delay
)
1445 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1449 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1451 /* reparent the window back to the root */
1453 wClientRestore(wwin
);
1455 if (wwin
->transient_for
!=scr
->root_win
) {
1456 owner
= wWindowFor(wwin
->transient_for
);
1458 if (!owner
->flags
.semi_focused
) {
1461 owner
->flags
.semi_focused
= 0;
1466 wasFocused
= wwin
->flags
.focused
;
1468 /* remove from window focus list */
1469 if (!wwin
->prev
&& !wwin
->next
) {
1470 /* was the only window */
1471 scr
->focused_window
= NULL
;
1472 newFocusedWindow
= NULL
;
1477 wwin
->prev
->next
= wwin
->next
;
1479 wwin
->next
->prev
= wwin
->prev
;
1481 scr
->focused_window
= wwin
->prev
;
1482 scr
->focused_window
->next
= NULL
;
1485 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1487 /* if in click to focus mode and the window
1488 * was a transient, focus the owner window
1491 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1492 tmp
= wWindowFor(wwin
->transient_for
);
1493 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1497 /* otherwise, focus the next one in the focus list */
1499 tmp
= scr
->focused_window
;
1500 while (tmp
) { /* look for one in the window list first */
1501 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1502 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1506 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1507 tmp
= scr
->focused_window
;
1509 if (!WFLAGP(tmp
, no_focusable
)
1510 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1517 newFocusedWindow
= tmp
;
1519 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1520 || wPreferences
.focus_mode
==WKF_POINTER
) {
1525 /* This is to let the root window get the keyboard input
1526 * if Sloppy focus mode and no other window get focus.
1527 * This way keybindings will not freeze.
1530 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1531 &foo
, &foo
, &foo
, &foo
, &mask
))
1532 tmp
= wWindowFor(win
);
1535 newFocusedWindow
= tmp
;
1537 newFocusedWindow
= NULL
;
1541 if (!wwin
->flags
.internal_window
) {
1543 wGNOMERemoveClient(wwin
);
1546 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1551 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1552 (unsigned)frame
->window
);
1556 if (newFocusedWindow
!= owner
&& owner
) {
1557 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1559 wSetFocusTo(scr
, newFocusedWindow
);
1561 wWindowDestroy(wwin
);
1567 wWindowMap(WWindow
*wwin
)
1569 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1570 if (!wwin
->flags
.shaded
) {
1571 /* window will be remapped when getting MapNotify */
1572 XSelectInput(dpy
, wwin
->client_win
,
1573 wwin
->event_mask
& ~StructureNotifyMask
);
1574 XMapWindow(dpy
, wwin
->client_win
);
1575 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1577 wwin
->flags
.mapped
= 1;
1583 wWindowUnmap(WWindow
*wwin
)
1585 wwin
->flags
.mapped
= 0;
1587 /* prevent window withdrawal when getting UnmapNotify */
1588 XSelectInput(dpy
, wwin
->client_win
,
1589 wwin
->event_mask
& ~StructureNotifyMask
);
1590 XUnmapWindow(dpy
, wwin
->client_win
);
1591 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1593 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1599 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1604 #ifdef KEEP_XKB_LOCK_STATUS
1605 if (wPreferences
.modelock
) {
1606 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1608 #endif /* KEEP_XKB_LOCK_STATUS */
1610 wwin
->flags
.semi_focused
= 0;
1612 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1614 wwin
->flags
.focused
= 1;
1616 wWindowResetMouseGrabs(wwin
);
1618 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1620 if (owin
== wwin
|| !owin
)
1623 nowner
= wWindowFor(wwin
->transient_for
);
1625 /* new window is a transient for the old window */
1626 if (nowner
== owin
) {
1627 owin
->flags
.semi_focused
= 1;
1628 wWindowUnfocus(nowner
);
1632 oowner
= wWindowFor(owin
->transient_for
);
1634 /* new window is owner of old window */
1635 if (wwin
== oowner
) {
1636 wWindowUnfocus(owin
);
1641 wWindowUnfocus(owin
);
1645 /* new window has same owner of old window */
1646 if (oowner
== nowner
) {
1647 /* prevent unfocusing of owner */
1648 oowner
->flags
.semi_focused
= 0;
1649 wWindowUnfocus(owin
);
1650 oowner
->flags
.semi_focused
= 1;
1655 /* nowner != NULL && oowner != nowner */
1656 nowner
->flags
.semi_focused
= 1;
1657 wWindowUnfocus(nowner
);
1658 wWindowUnfocus(owin
);
1663 wWindowUnfocus(WWindow
*wwin
)
1665 CloseWindowMenu(wwin
->screen_ptr
);
1667 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1668 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1670 if (wwin
->transient_for
!=None
1671 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1673 owner
= wWindowFor(wwin
->transient_for
);
1674 if (owner
&& owner
->flags
.semi_focused
) {
1675 owner
->flags
.semi_focused
= 0;
1676 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1677 wWindowUnfocus(owner
);
1678 wFrameWindowPaint(owner
->frame
);
1682 wwin
->flags
.focused
= 0;
1684 wWindowResetMouseGrabs(wwin
);
1686 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1693 *----------------------------------------------------------------------
1695 * wWindowConstrainSize--
1696 * Constrains size for the client window, taking the maximal size,
1697 * window resize increments and other size hints into account.
1700 * The closest size to what was given that the client window can
1703 *----------------------------------------------------------------------
1706 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1708 int width
= *nwidth
;
1709 int height
= *nheight
;
1712 int minW
= 1, minH
= 1;
1713 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1714 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1715 int minAX
= -1, minAY
= -1;
1716 int maxAX
= -1, maxAY
= -1;
1720 if (wwin
->normal_hints
) {
1721 winc
= wwin
->normal_hints
->width_inc
;
1722 hinc
= wwin
->normal_hints
->height_inc
;
1723 minW
= wwin
->normal_hints
->min_width
;
1724 minH
= wwin
->normal_hints
->min_height
;
1725 maxW
= wwin
->normal_hints
->max_width
;
1726 maxH
= wwin
->normal_hints
->max_height
;
1727 if (wwin
->normal_hints
->flags
& PAspect
) {
1728 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1729 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1730 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1731 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1745 /* aspect ratio code borrowed from olwm */
1747 /* adjust max aspect ratio */
1748 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1749 if (maxAX
> maxAY
) {
1750 height
= (width
* maxAY
) / maxAX
;
1751 if (height
> maxH
) {
1753 width
= (height
* maxAX
) / maxAY
;
1756 width
= (height
* maxAX
) / maxAY
;
1759 height
= (width
* maxAY
) / maxAX
;
1764 /* adjust min aspect ratio */
1765 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1766 if (minAX
> minAY
) {
1767 height
= (width
* minAY
) / minAX
;
1768 if (height
< minH
) {
1770 width
= (height
* minAX
) / minAY
;
1773 width
= (height
* minAX
) / minAY
;
1776 height
= (width
* minAY
) / minAX
;
1783 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1785 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1789 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1791 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1800 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1802 WScreen
*scr
= wwin
->screen_ptr
;
1806 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1807 || workspace
== wwin
->frame
->workspace
)
1810 if (workspace
!= scr
->current_workspace
) {
1811 /* Sent to other workspace. Unmap window */
1812 if ((wwin
->flags
.mapped
1813 || wwin
->flags
.shaded
1814 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1815 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1817 wapp
= wApplicationOf(wwin
->main_window
);
1819 wapp
->last_workspace
= workspace
;
1821 if (wwin
->flags
.miniaturized
) {
1823 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1824 wwin
->icon
->mapped
= 0;
1828 wSetFocusTo(scr
, NULL
);
1832 /* brought to current workspace. Map window */
1833 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1835 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1836 wwin
->icon
->mapped
= 1;
1838 } else if (!wwin
->flags
.mapped
&&
1839 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1843 if (!IS_OMNIPRESENT(wwin
)) {
1844 wwin
->frame
->workspace
= workspace
;
1845 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1848 wGNOMEUpdateClientStateHint(wwin
, True
);
1851 wKWMUpdateClientWorkspace(wwin
);
1852 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1861 wWindowSynthConfigureNotify(WWindow
*wwin
)
1865 sevent
.type
= ConfigureNotify
;
1866 sevent
.xconfigure
.display
= dpy
;
1867 sevent
.xconfigure
.event
= wwin
->client_win
;
1868 sevent
.xconfigure
.window
= wwin
->client_win
;
1870 sevent
.xconfigure
.x
= wwin
->client
.x
;
1871 sevent
.xconfigure
.y
= wwin
->client
.y
;
1872 sevent
.xconfigure
.width
= wwin
->client
.width
;
1873 sevent
.xconfigure
.height
= wwin
->client
.height
;
1875 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1876 if (WFLAGP(wwin
, no_titlebar
))
1877 sevent
.xconfigure
.above
= None
;
1879 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1881 sevent
.xconfigure
.override_redirect
= False
;
1882 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1884 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1891 *----------------------------------------------------------------------
1892 * wWindowConfigure--
1893 * Configures the frame, decorations and client window to the
1894 * specified geometry. The geometry is not checked for validity,
1895 * wWindowConstrainSize() must be used for that.
1896 * The size parameters are for the client window, but the position is
1898 * The client window receives a ConfigureNotify event, according
1899 * to what ICCCM says.
1905 * Window size and position are changed and client window receives
1906 * a ConfigureNotify event.
1907 *----------------------------------------------------------------------
1910 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1912 int req_x
, req_y
; /* new position of the frame */
1913 int req_width
, req_height
; /* new size of the client */
1915 int synth_notify
= False
;
1918 resize
= (req_width
!=wwin
->client
.width
1919 || req_height
!=wwin
->client
.height
);
1921 * if the window is being moved but not resized then
1922 * send a synthetic ConfigureNotify
1924 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1925 synth_notify
= True
;
1928 if (WFLAGP(wwin
, dont_move_off
))
1929 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1930 req_width
, req_height
);
1932 if (req_width
< MIN_WINDOW_SIZE
)
1933 req_width
= MIN_WINDOW_SIZE
;
1934 if (req_height
< MIN_WINDOW_SIZE
)
1935 req_height
= MIN_WINDOW_SIZE
;
1937 /* If growing, resize inner part before frame,
1938 * if shrinking, resize frame before.
1939 * This will prevent the frame (that can have a different color)
1940 * to be exposed, causing flicker */
1941 if (req_height
> wwin
->frame
->core
->height
1942 || req_width
> wwin
->frame
->core
->width
)
1943 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1945 if (wwin
->flags
.shaded
) {
1946 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1947 req_width
, wwin
->frame
->core
->height
);
1948 wwin
->old_geometry
.height
= req_height
;
1952 h
= req_height
+ wwin
->frame
->top_width
1953 + wwin
->frame
->bottom_width
;
1955 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1958 if (!(req_height
> wwin
->frame
->core
->height
1959 || req_width
> wwin
->frame
->core
->width
))
1960 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1962 wwin
->client
.x
= req_x
;
1963 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1964 wwin
->client
.width
= req_width
;
1965 wwin
->client
.height
= req_height
;
1967 wwin
->client
.x
= req_x
;
1968 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1970 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1972 wwin
->frame_x
= req_x
;
1973 wwin
->frame_y
= req_y
;
1976 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1977 wWindowSetShape(wwin
);
1982 wWindowSynthConfigureNotify(wwin
);
1988 wWindowMove(wwin
, req_x
, req_y
)
1990 int req_x
, req_y
; /* new position of the frame */
1992 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1993 int synth_notify
= False
;
1995 /* Send a synthetic ConfigureNotify event for every window movement. */
1996 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1997 synth_notify
= True
;
2000 /* A single synthetic ConfigureNotify event is sent at the end of
2001 * a completed (opaque) movement in moveres.c */
2004 if (WFLAGP(wwin
, dont_move_off
))
2005 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2006 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2008 wwin
->client
.x
= req_x
;
2009 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2011 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2013 wwin
->frame_x
= req_x
;
2014 wwin
->frame_y
= req_y
;
2016 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2018 wWindowSynthConfigureNotify(wwin
);
2024 wWindowUpdateButtonImages(WWindow
*wwin
)
2026 WScreen
*scr
= wwin
->screen_ptr
;
2027 Pixmap pixmap
, mask
;
2028 WFrameWindow
*fwin
= wwin
->frame
;
2030 if (WFLAGP(wwin
, no_titlebar
))
2033 /* miniaturize button */
2035 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2036 if (wwin
->wm_gnustep_attr
2037 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2038 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2040 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2041 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2046 if (fwin
->lbutton_image
2047 && (fwin
->lbutton_image
->image
!= pixmap
2048 || fwin
->lbutton_image
->mask
!= mask
)) {
2049 wPixmapDestroy(fwin
->lbutton_image
);
2050 fwin
->lbutton_image
= NULL
;
2053 if (!fwin
->lbutton_image
) {
2054 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2055 fwin
->lbutton_image
->client_owned
= 1;
2056 fwin
->lbutton_image
->client_owned_mask
= 1;
2059 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2060 wPixmapDestroy(fwin
->lbutton_image
);
2062 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2066 #ifdef XKB_BUTTON_HINT
2067 if (!WFLAGP(wwin
, no_language_button
)) {
2068 if (fwin
->languagebutton_image
&&
2069 !fwin
->languagebutton_image
->shared
) {
2070 wPixmapDestroy(fwin
->languagebutton_image
);
2072 fwin
->languagebutton_image
=
2073 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2079 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2080 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2082 if (!WFLAGP(wwin
, no_close_button
)) {
2083 if (wwin
->wm_gnustep_attr
2084 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2085 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2087 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2088 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2092 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2093 || fwin
->rbutton_image
->mask
!= mask
)) {
2094 wPixmapDestroy(fwin
->rbutton_image
);
2095 fwin
->rbutton_image
= NULL
;
2098 if (!fwin
->rbutton_image
) {
2099 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2100 fwin
->rbutton_image
->client_owned
= 1;
2101 fwin
->rbutton_image
->client_owned_mask
= 1;
2104 } else if (WFLAGP(wwin
, kill_close
)) {
2106 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2107 wPixmapDestroy(fwin
->rbutton_image
);
2109 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2111 } else if (MGFLAGP(wwin
, broken_close
)) {
2113 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2114 wPixmapDestroy(fwin
->rbutton_image
);
2116 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2120 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2121 wPixmapDestroy(fwin
->rbutton_image
);
2123 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2127 /* force buttons to be redrawn */
2128 fwin
->flags
.need_texture_change
= 1;
2129 wFrameWindowPaint(fwin
);
2134 *---------------------------------------------------------------------------
2135 * wWindowConfigureBorders--
2136 * Update window border configuration according to attribute flags.
2138 *---------------------------------------------------------------------------
2141 wWindowConfigureBorders(WWindow
*wwin
)
2147 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2148 #ifdef XKB_BUTTON_HINT
2149 flags
|= WFF_LANGUAGE_BUTTON
;
2151 if (!WFLAGP(wwin
, no_titlebar
))
2152 flags
|= WFF_TITLEBAR
;
2153 if (!WFLAGP(wwin
, no_resizebar
))
2154 flags
|= WFF_RESIZEBAR
;
2155 if (wwin
->flags
.shaded
)
2156 flags
|= WFF_IS_SHADED
;
2158 oldh
= wwin
->frame
->top_width
;
2159 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2160 if (oldh
!= wwin
->frame
->top_width
) {
2161 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2163 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2164 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2165 wwin
->client
.width
, wwin
->client
.height
);
2169 if (!WFLAGP(wwin
, no_miniaturize_button
)
2170 && wwin
->frame
->flags
.hide_left_button
)
2171 flags
|= WFF_LEFT_BUTTON
;
2173 #ifdef XKB_BUTTON_HINT
2174 if (!WFLAGP(wwin
, no_language_button
)
2175 && wwin
->frame
->flags
.hide_language_button
)
2176 flags
|= WFF_LANGUAGE_BUTTON
;
2179 if (!WFLAGP(wwin
, no_close_button
)
2180 && wwin
->frame
->flags
.hide_right_button
)
2181 flags
|= WFF_RIGHT_BUTTON
;
2184 wWindowUpdateButtonImages(wwin
);
2185 wFrameWindowShowButton(wwin
->frame
, flags
);
2189 if (WFLAGP(wwin
, no_miniaturize_button
)
2190 && !wwin
->frame
->flags
.hide_left_button
)
2191 flags
|= WFF_LEFT_BUTTON
;
2193 #ifdef XKB_BUTTON_HINT
2194 if (WFLAGP(wwin
, no_language_button
)
2195 && !wwin
->frame
->flags
.hide_language_button
)
2196 flags
|= WFF_LANGUAGE_BUTTON
;
2199 if (WFLAGP(wwin
, no_close_button
)
2200 && !wwin
->frame
->flags
.hide_right_button
)
2201 flags
|= WFF_RIGHT_BUTTON
;
2204 wFrameWindowHideButton(wwin
->frame
, flags
);
2207 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2208 wWindowSetShape(wwin
);
2216 wWindowSaveState(WWindow
*wwin
)
2221 memset(data
, 0, sizeof(CARD32
)*10);
2222 data
[0] = wwin
->frame
->workspace
;
2223 data
[1] = wwin
->flags
.miniaturized
;
2224 data
[2] = wwin
->flags
.shaded
;
2225 data
[3] = wwin
->flags
.hidden
;
2227 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2228 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2229 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2232 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2233 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2234 (unsigned char *)data
, 10);
2239 getSavedState(Window window
, WSavedState
**state
)
2243 unsigned long nitems_ret
;
2244 unsigned long bytes_after_ret
;
2247 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2248 True
, _XA_WINDOWMAKER_STATE
,
2249 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2250 (unsigned char **)&data
)!=Success
|| !data
)
2253 *state
= malloc(sizeof(WSavedState
));
2256 (*state
)->workspace
= data
[0];
2257 (*state
)->miniaturized
= data
[1];
2258 (*state
)->shaded
= data
[2];
2259 (*state
)->hidden
= data
[3];
2260 (*state
)->use_geometry
= data
[4];
2261 (*state
)->x
= data
[5];
2262 (*state
)->y
= data
[6];
2263 (*state
)->w
= data
[7];
2264 (*state
)->h
= data
[8];
2265 (*state
)->window_shortcuts
= data
[9];
2269 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2278 wWindowClearShape(WWindow
*wwin
)
2280 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2281 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2286 wWindowSetShape(WWindow
*wwin
)
2290 #ifdef OPTIMIZE_SHAPE
2295 /* only shape is the client's */
2296 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2300 /* Get array of rectangles describing the shape mask */
2301 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2307 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2313 /* insert our decoration rectangles in the rect list */
2314 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2317 if (!WFLAGP(wwin
, no_titlebar
)) {
2319 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2320 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2321 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2324 if (!WFLAGP(wwin
, no_resizebar
)) {
2326 urec
[count
].y
= wwin
->frame
->core
->height
2327 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2328 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2329 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2333 /* shape our frame window */
2334 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2335 0, wwin
->frame
->top_width
, urec
, count
,
2336 ShapeSet
, Unsorted
);
2342 #endif /* OPTIMIZE_SHAPE */
2344 if (!WFLAGP(wwin
, no_titlebar
)) {
2347 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2348 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2351 if (!WFLAGP(wwin
, no_resizebar
)) {
2353 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2354 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2355 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2359 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2360 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2362 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2363 0, wwin
->frame
->top_width
, wwin
->client_win
,
2364 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2369 /* ====================================================================== */
2372 getFocusMode(WWindow
*wwin
)
2376 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2377 if (wwin
->wm_hints
->input
== True
) {
2378 if (wwin
->protocols
.TAKE_FOCUS
)
2379 mode
= WFM_LOCALLY_ACTIVE
;
2383 if (wwin
->protocols
.TAKE_FOCUS
)
2384 mode
= WFM_GLOBALLY_ACTIVE
;
2386 mode
= WFM_NO_INPUT
;
2396 wWindowSetKeyGrabs(WWindow
*wwin
)
2401 for (i
=0; i
<WKBD_LAST
; i
++) {
2402 key
= &wKeyBindings
[i
];
2404 if (key
->keycode
==0)
2406 if (key
->modifier
!=AnyModifier
) {
2407 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2408 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2410 /* Also grab all modifier combinations possible that include,
2411 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2412 * work even if the NumLock/ScrollLock key is on.
2414 wHackedGrabKey(key
->keycode
, key
->modifier
,
2415 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2419 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2420 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2424 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2431 wWindowResetMouseGrabs(WWindow
*wwin
)
2433 /* Mouse grabs can't be done on the client window because of
2434 * ICCCM and because clients that try to do the same will crash.
2436 * But there is a problem wich makes tbar buttons of unfocused
2437 * windows not usable as the click goes to the frame window instead
2438 * of the button itself. Must figure a way to fix that.
2441 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2443 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2444 /* grabs for Meta+drag */
2445 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2446 True
, ButtonPressMask
, GrabModeSync
,
2447 GrabModeAsync
, None
, None
);
2450 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)) {
2451 /* the passive grabs to focus the window */
2452 if (wPreferences
.focus_mode
== WKF_CLICK
)
2453 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2454 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2462 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2464 if (attr
->flags
& GSExtraFlagsAttr
) {
2465 if (MGFLAGP(wwin
, broken_close
) !=
2466 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2467 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2468 wWindowUpdateButtonImages(wwin
);
2475 wWindowAddSavedState(char *instance
, char *class, char *command
,
2476 pid_t pid
, WSavedState
*state
)
2478 WWindowState
*wstate
;
2480 wstate
= malloc(sizeof(WWindowState
));
2484 memset(wstate
, 0, sizeof(WWindowState
));
2487 wstate
->instance
= wstrdup(instance
);
2489 wstate
->class = wstrdup(class);
2491 wstate
->command
= wstrdup(command
);
2492 wstate
->state
= state
;
2494 wstate
->next
= windowState
;
2495 windowState
= wstate
;
2498 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2506 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2510 wWindowGetSavedState(Window win
)
2512 char *instance
, *class, *command
=NULL
;
2513 WWindowState
*wstate
= windowState
;
2520 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2522 command
= FlattenStringList(argv
, argc
);
2523 XFreeStringList(argv
);
2528 if (PropGetWMClass(win
, &class, &instance
)) {
2530 if (SAME(instance
, wstate
->instance
) &&
2531 SAME(class, wstate
->class) &&
2532 SAME(command
, wstate
->command
)) {
2535 wstate
= wstate
->next
;
2542 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2546 if (command
) free(command
);
2547 if (instance
) XFree(instance
);
2548 if (class) XFree(class);
2555 wWindowDeleteSavedState(WMagicNumber id
)
2557 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2559 if (!wstate
|| !windowState
)
2564 windowState
= wstate
->next
;
2566 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2567 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2569 if (wstate
->instance
) free(wstate
->instance
);
2570 if (wstate
->class) free(wstate
->class);
2571 if (wstate
->command
) free(wstate
->command
);
2572 free(wstate
->state
);
2576 if (tmp
->next
==wstate
) {
2577 tmp
->next
=wstate
->next
;
2579 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2580 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2582 if (wstate
->instance
) free(wstate
->instance
);
2583 if (wstate
->class) free(wstate
->class);
2584 if (wstate
->command
) free(wstate
->command
);
2585 free(wstate
->state
);
2596 wWindowDeleteSavedStatesForPID(pid_t pid
)
2598 WWindowState
*tmp
, *wstate
;
2604 if (tmp
->pid
== pid
) {
2605 wstate
= windowState
;
2606 windowState
= tmp
->next
;
2608 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2609 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2611 if (wstate
->instance
) free(wstate
->instance
);
2612 if (wstate
->class) free(wstate
->class);
2613 if (wstate
->command
) free(wstate
->command
);
2614 free(wstate
->state
);
2618 if (tmp
->next
->pid
==pid
) {
2620 tmp
->next
= wstate
->next
;
2622 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2623 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2625 if (wstate
->instance
) free(wstate
->instance
);
2626 if (wstate
->class) free(wstate
->class);
2627 if (wstate
->command
) free(wstate
->command
);
2628 free(wstate
->state
);
2638 /* ====================================================================== */
2641 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2643 WWindow
*wwin
= data
;
2645 #ifndef NUMLOCK_HACK
2646 if ((event
->xbutton
.state
& ValidModMask
)
2647 != (event
->xbutton
.state
& ~LockMask
)) {
2648 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2649 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2653 event
->xbutton
.state
&= ValidModMask
;
2655 CloseWindowMenu(wwin
->screen_ptr
);
2657 if (wPreferences
.focus_mode
==WKF_CLICK
2658 && !(event
->xbutton
.state
&ControlMask
)
2659 && !WFLAGP(wwin
, no_focusable
)) {
2660 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2663 if (event
->xbutton
.button
== Button1
)
2664 wRaiseFrame(wwin
->frame
->core
);
2666 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2667 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2668 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2669 GrabModeAsync
, GrabModeAsync
, None
,
2670 None
, CurrentTime
)!=GrabSuccess
) {
2672 wwarning("pointer grab failed for window move");
2678 if (event
->xbutton
.state
& MOD_MASK
) {
2679 /* move the window */
2680 wMouseMoveWindow(wwin
, event
);
2681 XUngrabPointer(dpy
, CurrentTime
);
2683 wMouseResizeWindow(wwin
, event
);
2684 XUngrabPointer(dpy
, CurrentTime
);
2691 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2693 WWindow
*wwin
= data
;
2695 event
->xbutton
.state
&= ValidModMask
;
2697 if (event
->xbutton
.button
==Button1
) {
2698 if (event
->xbutton
.state
== 0) {
2699 if (!WFLAGP(wwin
, no_shadeable
)) {
2701 if (wwin
->flags
.shaded
)
2702 wUnshadeWindow(wwin
);
2709 if (event
->xbutton
.state
& ControlMask
)
2710 dir
|= MAX_VERTICAL
;
2712 if (event
->xbutton
.state
& ShiftMask
) {
2713 dir
|= MAX_HORIZONTAL
;
2714 if (!(event
->xbutton
.state
& ControlMask
))
2715 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2718 /* maximize window */
2719 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2720 if (wwin
->flags
.maximized
)
2721 wUnmaximizeWindow(wwin
);
2723 wMaximizeWindow(wwin
, dir
);
2726 } else if (event
->xbutton
.button
==Button3
) {
2727 if (event
->xbutton
.state
& MOD_MASK
) {
2728 wHideOtherApplications(wwin
);
2730 } else if (event
->xbutton
.button
==Button2
) {
2731 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2737 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2739 WWindow
*wwin
= desc
->parent
;
2741 event
->xbutton
.state
&= ValidModMask
;
2743 CloseWindowMenu(wwin
->screen_ptr
);
2745 if (wPreferences
.focus_mode
==WKF_CLICK
2746 && !(event
->xbutton
.state
&ControlMask
)
2747 && !WFLAGP(wwin
, no_focusable
)) {
2748 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2750 if (event
->xbutton
.button
== Button1
) {
2751 wRaiseFrame(wwin
->frame
->core
);
2754 if (event
->xbutton
.state
& MOD_MASK
) {
2755 /* move the window */
2756 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2757 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2758 GrabModeAsync
, GrabModeAsync
, None
,
2759 None
, CurrentTime
)!=GrabSuccess
) {
2761 wwarning("pointer grab failed for window move");
2765 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2766 wMouseResizeWindow(wwin
, event
);
2768 wMouseMoveWindow(wwin
, event
);
2769 XUngrabPointer(dpy
, CurrentTime
);
2775 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2777 WWindow
*wwin
= (WWindow
*)data
;
2779 #ifndef NUMLOCK_HACK
2780 if ((event
->xbutton
.state
& ValidModMask
)
2781 != (event
->xbutton
.state
& ~LockMask
)) {
2782 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2783 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2786 event
->xbutton
.state
&= ValidModMask
;
2788 CloseWindowMenu(wwin
->screen_ptr
);
2790 if (wPreferences
.focus_mode
==WKF_CLICK
2791 && !(event
->xbutton
.state
&ControlMask
)
2792 && !WFLAGP(wwin
, no_focusable
)) {
2793 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2796 if (event
->xbutton
.button
== Button1
2797 || event
->xbutton
.button
== Button2
) {
2799 if (event
->xbutton
.button
== Button1
) {
2800 if (event
->xbutton
.state
& MOD_MASK
) {
2801 wLowerFrame(wwin
->frame
->core
);
2803 wRaiseFrame(wwin
->frame
->core
);
2806 if ((event
->xbutton
.state
& ShiftMask
)
2807 && !(event
->xbutton
.state
& ControlMask
)) {
2808 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2811 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2812 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2813 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2814 GrabModeAsync
, GrabModeAsync
, None
,
2815 None
, CurrentTime
)!=GrabSuccess
) {
2817 wwarning("pointer grab failed for window move");
2822 /* move the window */
2823 wMouseMoveWindow(wwin
, event
);
2825 XUngrabPointer(dpy
, CurrentTime
);
2826 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2827 && !wwin
->flags
.internal_window
2828 && !WCHECK_STATE(WSTATE_MODAL
)) {
2829 WObjDescriptor
*desc
;
2831 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2832 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2833 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2834 GrabModeAsync
, GrabModeAsync
, None
,
2835 None
, CurrentTime
)!=GrabSuccess
) {
2837 wwarning("pointer grab failed for window move");
2842 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2843 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2845 /* allow drag select */
2846 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2847 event
->xany
.send_event
= True
;
2848 (*desc
->handle_mousedown
)(desc
, event
);
2850 XUngrabPointer(dpy
, CurrentTime
);
2857 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2859 WWindow
*wwin
= data
;
2861 event
->xbutton
.state
&= ValidModMask
;
2863 CloseWindowMenu(wwin
->screen_ptr
);
2865 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2868 /* if control-click, kill the client */
2869 if (event
->xbutton
.state
& ControlMask
) {
2873 if (wwin
->flags
.olwm_push_pin_out
) {
2875 wwin
->flags
.olwm_push_pin_out
= 0;
2877 wOLWMChangePushpinState(wwin
, True
);
2879 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2884 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2885 /* send delete message */
2886 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2893 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2895 WWindow
*wwin
= data
;
2897 CloseWindowMenu(wwin
->screen_ptr
);
2899 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2902 /* send delete message */
2903 if (wwin
->protocols
.DELETE_WINDOW
) {
2904 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2911 #ifdef XKB_BUTTON_HINT
2913 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2915 WWindow
*wwin
= data
;
2916 WFrameWindow
*fwin
= wwin
->frame
;
2917 WScreen
*scr
= fwin
->screen_ptr
;
2918 XkbStateRec staterec
;
2921 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2923 tl
= wwin
->frame
->languagemode
;
2924 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2925 wwin
->frame
->last_languagemode
= tl
;
2926 wSetFocusTo(scr
, wwin
);
2927 wwin
->frame
->languagebutton_image
=
2928 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
2929 wwin
->frame
->languagemode
];
2930 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2931 if (event
->xbutton
.button
== Button3
)
2933 wRaiseFrame(fwin
->core
);
2939 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2941 WWindow
*wwin
= data
;
2943 event
->xbutton
.state
&= ValidModMask
;
2945 CloseWindowMenu(wwin
->screen_ptr
);
2947 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2950 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2951 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2955 if ((event
->xbutton
.state
& ControlMask
) ||
2956 (event
->xbutton
.button
== Button3
)) {
2958 wapp
= wApplicationOf(wwin
->main_window
);
2959 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2960 wHideApplication(wapp
);
2961 } else if (event
->xbutton
.state
==0) {
2962 wIconifyWindow(wwin
);