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"
65 # include "openlook.h"
68 /****** Global Variables ******/
70 extern WShortKey wKeyBindings
[WKBD_LAST
];
73 extern Bool wShapeSupported
;
77 extern XContext wWinContext
;
80 extern Cursor wCursor
[WCUR_LAST
];
83 extern Atom _XA_WM_DELETE_WINDOW
;
84 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
86 extern Atom _XA_WINDOWMAKER_STATE
;
88 extern WPreferences wPreferences
;
90 #define MOD_MASK wPreferences.modifier_mask
92 extern Time LastTimestamp
;
95 extern void DoWindowBirth(WWindow
*);
98 /***** Local Stuff *****/
101 static WWindowState
*windowState
=NULL
;
105 /* local functions */
106 static FocusMode
getFocusMode(WWindow
*wwin
);
108 static int getSavedState(Window window
, WSavedState
**state
);
110 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
115 /* frame window (during window grabs) */
116 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
119 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
120 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
123 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
126 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
127 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
129 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
132 /****** Notification Observers ******/
135 appearanceObserver(void *self
, WMNotification
*notif
)
137 WWindow
*wwin
= (WWindow
*)self
;
138 int flags
= (int)WMGetNotificationClientData(notif
);
140 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
143 if (flags
& WFontSettings
) {
144 wWindowConfigureBorders(wwin
);
146 if (flags
& WTextureSettings
) {
147 wwin
->frame
->flags
.need_texture_remake
= 1;
149 if (flags
& (WTextureSettings
| WColorSettings
)) {
150 if (wwin
->frame
->titlebar
)
151 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
153 wFrameWindowPaint(wwin
->frame
);
157 /************************************/
160 wWindowFor(Window window
)
162 WObjDescriptor
*desc
;
167 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
170 if (desc
->parent_type
==WCLASS_WINDOW
)
172 else if (desc
->parent_type
==WCLASS_FRAME
) {
173 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
174 if (frame
->flags
.is_client_window_frame
)
187 wwin
= wmalloc(sizeof(WWindow
));
190 memset(wwin
, 0, sizeof(WWindow
));
192 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
193 wwin
->client_descriptor
.parent
= wwin
;
194 wwin
->client_descriptor
.self
= wwin
;
195 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
202 wWindowDestroy(WWindow
*wwin
)
206 WMRemoveNotificationObserver(wwin
);
208 wwin
->flags
.destroyed
= 1;
210 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
211 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
) {
212 wwin
->screen_ptr
->shortcutWindow
[i
] = NULL
;
216 if (wwin
->normal_hints
)
217 free(wwin
->normal_hints
);
220 XFree(wwin
->wm_hints
);
222 if (wwin
->wm_instance
)
223 XFree(wwin
->wm_instance
);
226 XFree(wwin
->wm_class
);
228 if (wwin
->wm_gnustep_attr
)
229 free(wwin
->wm_gnustep_attr
);
231 if (wwin
->cmap_windows
)
232 XFree(wwin
->cmap_windows
);
234 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
237 wFrameWindowDestroy(wwin
->frame
);
240 RemoveFromStackList(wwin
->icon
->core
);
241 wIconDestroy(wwin
->icon
);
242 if (wPreferences
.auto_arrange_icons
)
243 wArrangeIcons(wwin
->screen_ptr
, True
);
252 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
254 if (gs_hints
->flags
& GSWindowStyleAttr
) {
255 wwin
->client_flags
.no_titlebar
=
256 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
258 wwin
->client_flags
.no_close_button
=
259 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
261 wwin
->client_flags
.no_closable
=
262 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
264 wwin
->client_flags
.no_miniaturize_button
=
265 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
267 wwin
->client_flags
.no_miniaturizable
=
268 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
270 wwin
->client_flags
.no_resizebar
=
271 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
273 wwin
->client_flags
.no_resizable
=
274 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
276 /* setup the defaults */
277 wwin
->client_flags
.no_titlebar
= 0;
278 wwin
->client_flags
.no_closable
= 0;
279 wwin
->client_flags
.no_miniaturizable
= 0;
280 wwin
->client_flags
.no_resizable
= 0;
281 wwin
->client_flags
.no_close_button
= 0;
282 wwin
->client_flags
.no_miniaturize_button
= 0;
283 wwin
->client_flags
.no_resizebar
= 0;
285 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
286 wwin
->client_flags
.no_appicon
= 1;
292 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
293 WWindowAttributes
*mask
)
295 if (wflags
->no_appicon
&& mask
->no_appicon
)
296 wflags
->emulate_appicon
= 0;
298 if (wwin
->main_window
!=None
) {
299 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
300 if (wapp
&& !wapp
->flags
.emulated
)
301 wflags
->emulate_appicon
= 0;
304 if (wwin
->transient_for
!=None
305 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
306 wflags
->emulate_appicon
= 0;
308 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
315 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
317 WScreen
*scr
= wwin
->screen_ptr
;
319 /* sets global default stuff */
320 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
321 &wwin
->client_flags
, NULL
, True
);
323 * Decoration setting is done in this precedence (lower to higher)
324 * - use global default in the resource database
325 * - guess some settings
326 * - use GNUstep/external window attributes
327 * - set hints specified for the app in the resource DB
330 WSETUFLAG(wwin
, broken_close
, 0);
332 if (wwin
->protocols
.DELETE_WINDOW
)
333 WSETUFLAG(wwin
, kill_close
, 0);
335 WSETUFLAG(wwin
, kill_close
, 1);
337 /* transients can't be iconified or maximized */
338 if (wwin
->transient_for
) {
339 WSETUFLAG(wwin
, no_miniaturizable
, 1);
340 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
343 /* if the window can't be resized, remove the resizebar */
344 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
345 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
346 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
347 WSETUFLAG(wwin
, no_resizable
, 1);
348 WSETUFLAG(wwin
, no_resizebar
, 1);
351 /* set GNUstep window attributes */
352 if (wwin
->wm_gnustep_attr
) {
353 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
355 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
357 switch (wwin
->wm_gnustep_attr
->window_level
) {
358 case WMNormalWindowLevel
:
359 *level
= WMNormalLevel
;
361 case WMFloatingWindowLevel
:
362 *level
= WMFloatingLevel
;
364 case WMDockWindowLevel
:
365 *level
= WMDockLevel
;
367 case WMSubmenuWindowLevel
:
368 *level
= WMSubmenuLevel
;
370 case WMMainMenuWindowLevel
:
371 *level
= WMMainMenuLevel
;
374 *level
= WMNormalLevel
;
379 *level
= WMNormalLevel
;
382 int tmp_workspace
= -1;
386 wMWMCheckClientHints(wwin
);
387 #endif /* MWM_HINTS */
390 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
391 #endif /* KWM_HINTS */
394 wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
395 #endif /* GNOME_STUFF */
398 wOLWMCheckClientHints(wwin
);
399 #endif /* OLWM_HINTS */
402 if (WFLAGP(wwin
, floating
))
403 *level
= WMFloatingLevel
;
404 else if (WFLAGP(wwin
, sunken
))
405 *level
= WMSunkenLevel
;
407 *level
= WMNormalLevel
;
412 if (tmp_workspace
>= 0) {
413 *workspace
= tmp_workspace
% scr
->workspace_count
;
418 * Set attributes specified only for that window/class.
419 * This might do duplicate work with the 1st wDefaultFillAttributes().
421 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
422 &wwin
->user_flags
, &wwin
->defined_user_flags
,
425 * Sanity checks for attributes that depend on other attributes
427 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
428 wwin
->user_flags
.emulate_appicon
= 0;
430 if (wwin
->main_window
!=None
) {
431 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
432 if (wapp
&& !wapp
->flags
.emulated
)
433 wwin
->user_flags
.emulate_appicon
= 0;
436 if (wwin
->transient_for
!=None
437 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
438 wwin
->user_flags
.emulate_appicon
= 0;
440 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
441 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
442 wwin
->user_flags
.sunken
= 0;
444 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
451 wWindowCanReceiveFocus(WWindow
*wwin
)
453 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
455 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
457 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
465 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
469 w1
= wwin
->frame
->core
->width
;
470 h1
= wwin
->frame
->core
->height
;
471 w2
= obscured
->frame
->core
->width
;
472 h2
= obscured
->frame
->core
->height
;
474 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
475 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
478 if (wwin
->frame_x
+ w1
< obscured
->frame_x
479 || wwin
->frame_y
+ h1
< obscured
->frame_y
480 || wwin
->frame_x
> obscured
->frame_x
+ w2
481 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
490 *----------------------------------------------------------------
492 * reparents the window and allocates a descriptor for it.
493 * Window manager hints and other hints are fetched to configure
494 * the window decoration attributes and others. User preferences
495 * for the window are used if available, to configure window
496 * decorations and some behaviour.
497 * If in startup, windows that are override redirect,
498 * unmapped and never were managed and are Withdrawn are not
502 * the new window descriptor
505 * The window is reparented and appropriate notification
506 * is done to the client. Input mask for the window is setup.
507 * The window descriptor is also associated with various window
508 * contexts and inserted in the head of the window list.
509 * Event handler contexts are associated for some objects
510 * (buttons, titlebar and resizebar)
512 *----------------------------------------------------------------
515 wManageWindow(WScreen
*scr
, Window window
)
519 unsigned width
, height
;
520 XWindowAttributes wattribs
;
521 XSetWindowAttributes attribs
;
522 WWindowState
*win_state
;
523 WWindow
*transientOwner
= NULL
;
529 Bool withdraw
= False
;
532 /* XGrabServer(dpy); */
534 /* make sure the window is still there */
535 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
540 /* if it's an override-redirect, ignore it */
541 if (wattribs
.override_redirect
) {
546 wm_state
= PropGetWindowState(window
);
548 /* if it's startup and the window is unmapped, don't manage it */
549 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
554 if (!wFetchName(dpy
, window
, &title
)) {
559 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
564 #endif /* KWM_HINTS */
567 wwin
= wWindowCreate();
569 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
572 printf("managing window %x\n", (unsigned)window
);
576 if (wShapeSupported
) {
581 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
582 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
583 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
584 wwin
->flags
.shaped
= b_shaped
;
589 *--------------------------------------------------
591 * Get hints and other information in properties
593 *--------------------------------------------------
595 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
597 /* setup descriptor */
598 wwin
->client_win
= window
;
599 wwin
->screen_ptr
= scr
;
601 wwin
->old_border_width
= wattribs
.border_width
;
603 wwin
->event_mask
= CLIENT_EVENTS
;
604 attribs
.event_mask
= CLIENT_EVENTS
;
605 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
606 attribs
.save_under
= False
;
607 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
608 |CWSaveUnder
, &attribs
);
609 XSetWindowBorderWidth(dpy
, window
, 0);
611 /* get hints from GNUstep app */
612 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
613 wwin
->wm_gnustep_attr
= NULL
;
616 wwin
->client_leader
= PropGetClientLeader(window
);
617 if (wwin
->client_leader
!=None
)
618 wwin
->main_window
= wwin
->client_leader
;
620 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
622 if (wwin
->wm_hints
) {
623 if (wwin
->wm_hints
->flags
& StateHint
) {
625 if (wwin
->wm_hints
->initial_state
== IconicState
) {
627 wwin
->flags
.miniaturized
= 1;
629 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
635 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
636 wwin
->group_id
= wwin
->wm_hints
->window_group
;
637 /* window_group has priority over CLIENT_LEADER */
638 wwin
->main_window
= wwin
->group_id
;
640 wwin
->group_id
= None
;
643 if (wwin
->wm_hints
->flags
& UrgencyHint
)
644 wwin
->flags
.urgent
= 1;
646 wwin
->group_id
= None
;
649 PropGetProtocols(window
, &wwin
->protocols
);
651 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
652 wwin
->transient_for
= None
;
654 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
655 wwin
->transient_for
= scr
->root_win
;
657 transientOwner
= wWindowFor(wwin
->transient_for
);
658 if (transientOwner
&& transientOwner
->main_window
!=None
) {
659 wwin
->main_window
= transientOwner
->main_window
;
661 wwin->main_window = None;
666 /* guess the focus mode */
667 wwin
->focus_mode
= getFocusMode(wwin
);
669 /* get geometry stuff */
670 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
672 /* get colormap windows */
673 GetColormapWindows(wwin
);
676 *--------------------------------------------------
678 * Setup the decoration/window attributes and
681 *--------------------------------------------------
684 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
687 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
688 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
690 transientOwner
= wWindowFor(wwin
->group_id
);
692 if (transientOwner
) {
693 wwin
->transient_for
= wwin
->group_id
;
695 /* transients can't be iconified or maximized */
696 if (wwin
->transient_for
) {
697 WSETUFLAG(wwin
, no_miniaturizable
, 1);
698 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
702 #endif /* OLWM_HINTS */
705 * Make broken apps behave as a nice app.
707 if (WFLAGP(wwin
, emulate_appicon
)) {
708 wwin
->main_window
= wwin
->client_win
;
712 *------------------------------------------------------------
714 * Setup the initial state of the window
716 *------------------------------------------------------------
719 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
720 wwin
->flags
.miniaturized
= 1;
723 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
724 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
728 wGNOMECheckInitialClientState(wwin
);
731 wKWMCheckClientInitialState(wwin
);
734 /* apply previous state if it exists and we're in startup */
735 if (scr
->flags
.startup
&& wm_state
>= 0) {
737 if (wm_state
== IconicState
) {
739 wwin
->flags
.miniaturized
= 1;
741 } else if (wm_state
== WithdrawnState
) {
747 /* if there is a saved state (from file), restore it */
749 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
750 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
752 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
754 if (win_state
&& !withdraw
) {
756 if (win_state
->state
->hidden
>0)
757 wwin
->flags
.hidden
= win_state
->state
->hidden
;
759 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
760 wwin
->flags
.shaded
= win_state
->state
->shaded
;
762 if (win_state
->state
->miniaturized
>0 &&
763 !WFLAGP(wwin
, no_miniaturizable
)) {
764 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
766 if (!IS_OMNIPRESENT(wwin
)) {
767 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
769 if (w
< 0 || w
>= scr
->workspace_count
) {
770 workspace
= win_state
->state
->workspace
;
771 if (workspace
>= scr
->workspace_count
)
772 workspace
= scr
->current_workspace
;
777 workspace
= scr
->current_workspace
;
781 /* if we're restarting, restore saved state (from hints).
782 * This will overwrite previous */
786 if (getSavedState(window
, &wstate
)) {
787 wwin
->flags
.shaded
= wstate
->shaded
;
788 wwin
->flags
.hidden
= wstate
->hidden
;
789 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
790 workspace
= wstate
->workspace
;
792 if (scr
->flags
.startup
&& wstate
->window_shortcuts
>= 0) {
795 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
796 if (wstate
->window_shortcuts
& (1<<i
))
797 scr
->shortcutWindow
[i
] = wwin
;
804 /* don't let transients start miniaturized if their owners are not */
805 if (transientOwner
&& !transientOwner
->flags
.miniaturized
806 && wwin
->flags
.miniaturized
&& !withdraw
) {
807 wwin
->flags
.miniaturized
= 0;
809 wwin
->wm_hints
->initial_state
= NormalState
;
812 /* set workspace on which the window starts */
813 if (workspace
>= 0) {
814 if (workspace
> scr
->workspace_count
-1) {
815 workspace
= workspace
% scr
->workspace_count
;
820 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
822 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
827 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
829 workspace
= transientOwner
->frame
->workspace
;
833 workspace
= scr
->current_workspace
;
838 /* setup window geometry */
839 if (win_state
&& win_state
->state
->use_geometry
) {
840 width
= win_state
->state
->w
;
841 height
= win_state
->state
->h
;
843 wWindowConstrainSize(wwin
, &width
, &height
);
845 /* do not ask for window placement if the window is
846 * transient, during startup, if the initial workspace is another one
847 * or if the window wants to start iconic.
848 * If geometry was saved, restore it. */
850 Bool dontBring
= False
;
852 if (win_state
&& win_state
->state
->use_geometry
) {
853 x
= win_state
->state
->x
;
854 y
= win_state
->state
->y
;
855 } else if ((wwin
->transient_for
==None
856 || wPreferences
.window_placement
!=WPM_MANUAL
)
857 && !scr
->flags
.startup
858 && workspace
== scr
->current_workspace
859 && !wwin
->flags
.miniaturized
860 && !wwin
->flags
.maximized
861 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
862 PlaceWindow(wwin
, &x
, &y
, width
, height
);
863 if (wPreferences
.window_placement
== WPM_MANUAL
)
867 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
868 wScreenBringInside(scr
, &x
, &y
, width
, height
);
871 if (wwin
->flags
.urgent
) {
872 if (!IS_OMNIPRESENT(wwin
))
873 wwin
->flags
.omnipresent
^= 1;
877 *--------------------------------------------------
879 * Create frame, borders and do reparenting
881 *--------------------------------------------------
883 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
884 if (!WFLAGP(wwin
, no_titlebar
))
886 if (!WFLAGP(wwin
, no_resizebar
))
887 foo
|= WFF_RESIZEBAR
;
889 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
890 x
, y
, width
, height
, foo
,
891 scr
->window_title_texture
,
892 scr
->resizebar_texture
,
893 scr
->window_title_pixel
,
894 &scr
->window_title_gc
,
897 wwin
->frame
->flags
.is_client_window_frame
= 1;
898 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
900 /* setup button images */
901 wWindowUpdateButtonImages(wwin
);
903 /* hide unused buttons */
905 if (WFLAGP(wwin
, no_close_button
))
906 foo
|= WFF_RIGHT_BUTTON
;
907 if (WFLAGP(wwin
, no_miniaturize_button
))
908 foo
|= WFF_LEFT_BUTTON
;
910 wFrameWindowHideButton(wwin
->frame
, foo
);
912 wwin
->frame
->child
= wwin
;
915 /* emulate olwm push pin. Make the button look as pushed-in for
916 * the pinned-out state. When the button is clicked, it will
917 * revert to the normal position, which means the pin is pinned-in.
919 if (wwin
->flags
.olwm_push_pin_out
)
920 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
921 #endif /* OLWM_HINTS */
923 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
927 wwin
->frame
->workspace
= workspace
;
929 wwin
->frame
->on_click_left
= windowIconifyClick
;
931 wwin
->frame
->on_click_right
= windowCloseClick
;
932 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
934 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
935 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
937 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
940 XSelectInput(dpy
, wwin
->client_win
,
941 wwin
->event_mask
& ~StructureNotifyMask
);
943 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
944 0, wwin
->frame
->top_width
);
946 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
952 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
954 /* if gravity is to the south, account for the border sizes */
956 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
960 * wWindowConfigure() will init the client window's size
961 * (wwin->client.{width,height}) and all other geometry
962 * related variables (frame_x,frame_y)
964 wWindowConfigure(wwin
, x
, y
, width
, height
);
966 /* to make sure the window receives it's new position after reparenting */
967 wWindowSynthConfigureNotify(wwin
);
970 *--------------------------------------------------
972 * Setup descriptors and save window to internal
975 *--------------------------------------------------
978 if (wwin
->main_window
!=None
) {
982 /* Leader windows do not necessary set themselves as leaders.
983 * If this is the case, point the leader of this window to
985 leader
= wWindowFor(wwin
->main_window
);
986 if (leader
&& leader
->main_window
==None
) {
987 leader
->main_window
= leader
->client_win
;
989 app
= wApplicationCreate(scr
, wwin
->main_window
);
991 app
->last_workspace
= workspace
;
994 * Do application specific stuff, like setting application
998 if (wwin
->flags
.hidden
) {
999 /* if the window was set to hidden because it was hidden
1000 * in a previous incarnation and that state was restored */
1001 app
->flags
.hidden
= 1;
1004 if (app
->flags
.hidden
) {
1005 wwin
->flags
.hidden
= 1;
1010 /* setup the frame descriptor */
1011 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1012 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1013 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1015 /* don't let windows go away if we die */
1016 XAddToSaveSet(dpy
, window
);
1018 XLowerWindow(dpy
, window
);
1020 /* if window is in this workspace and should be mapped, then map it */
1021 if (!wwin
->flags
.miniaturized
1022 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1023 && !wwin
->flags
.hidden
&& !withdraw
) {
1025 /* The following "if" is to avoid crashing of clients that expect
1026 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1027 * after the return from this function.
1029 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1030 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1032 wClientSetState(wwin
, NormalState
, None
);
1036 /* if not auto focus, then map the window under the currently
1038 #define _WIDTH(w) (w)->frame->core->width
1039 #define _HEIGHT(w) (w)->frame->core->height
1040 if (!wPreferences
.auto_focus
&& scr
->focused_window
1041 && !scr
->flags
.startup
&& !transientOwner
1042 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1043 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1044 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1045 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1046 || wwin
->flags
.maximized
)) {
1047 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1055 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1056 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1058 * The brain damaged idiotic non-click to focus modes will
1059 * have trouble with this because:
1061 * 1. window is created and mapped by the client
1062 * 2. window is mapped by wmaker in small size
1063 * 3. window is animated to grow to normal size
1064 * 4. this function returns to normal event loop
1065 * 5. eventually, the EnterNotify event that would trigger
1066 * the window focusing (if the mouse is over that window)
1067 * will be processed by wmaker.
1068 * But since this event will be rather delayed
1069 * (step 3 has a large delay) the time when the event ocurred
1070 * and when it is processed, the client that owns that window
1071 * will reject the XSetInputFocus() for it.
1073 && (wPreferences
.focus_mode
==WKF_CLICK
1074 || wPreferences
.auto_focus
)) {
1075 DoWindowBirth(wwin
);
1081 /* setup stacking descriptor */
1082 if (transientOwner
) {
1083 /* && wPreferences.on_top_transients */
1084 if (transientOwner
) {
1085 wwin
->frame
->core
->stacking
->child_of
=
1086 transientOwner
->frame
->core
;
1089 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1093 if (!scr
->focused_window
) {
1094 /* first window on the list */
1097 scr
->focused_window
= wwin
;
1101 /* add window at beginning of focus window list */
1102 tmp
= scr
->focused_window
;
1111 wGNOMEUpdateClientStateHint(wwin
, True
);
1114 wKWMUpdateClientWorkspace(wwin
);
1115 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1121 *--------------------------------------------------
1123 * Final preparations before window is ready to go
1125 *--------------------------------------------------
1128 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1131 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1132 && !wwin
->flags
.hidden
) {
1133 if ((transientOwner
&& transientOwner
->flags
.focused
)
1134 || wPreferences
.auto_focus
)
1135 wSetFocusTo(scr
, wwin
);
1137 wWindowResetMouseGrabs(wwin
);
1139 if (!WFLAGP(wwin
, no_bind_keys
)) {
1140 wWindowSetKeyGrabs(wwin
);
1143 wGNOMEUpdateClientListHint(scr
);
1146 wwin
->flags
.kwm_managed
= 1;
1148 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1151 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1153 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1156 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1157 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1159 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1160 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1166 *------------------------------------------------------------
1167 * Setup Notification Observers
1168 *------------------------------------------------------------
1170 WMAddNotificationObserver(appearanceObserver
, wwin
,
1171 WNWindowAppearanceSettingsChanged
, wwin
);
1175 *--------------------------------------------------
1177 * Cleanup temporary stuff
1179 *--------------------------------------------------
1183 wWindowDeleteSavedState(win_state
);
1185 /* If the window must be withdrawed, then do it now.
1186 * Must do some optimization, 'though */
1188 wwin
->flags
.mapped
= 0;
1189 wClientSetState(wwin
, WithdrawnState
, None
);
1190 wUnmanageWindow(wwin
, True
, False
);
1202 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1203 char *title
, int x
, int y
, int width
, int height
)
1208 wwin
= wWindowCreate();
1210 WMAddNotificationObserver(appearanceObserver
, wwin
,
1211 WNWindowAppearanceSettingsChanged
, wwin
);
1213 wwin
->flags
.internal_window
= 1;
1215 WSETUFLAG(wwin
, omnipresent
, 1);
1216 WSETUFLAG(wwin
, no_shadeable
, 1);
1217 WSETUFLAG(wwin
, no_resizable
, 1);
1218 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1220 wwin
->focus_mode
= WFM_PASSIVE
;
1222 wwin
->client_win
= window
;
1223 wwin
->screen_ptr
= scr
;
1225 wwin
->transient_for
= owner
;
1229 wwin
->client
.width
= width
;
1230 wwin
->client
.height
= height
;
1232 wwin
->frame_x
= wwin
->client
.x
;
1233 wwin
->frame_y
= wwin
->client
.y
;
1236 foo
= WFF_RIGHT_BUTTON
;
1237 foo
|= WFF_TITLEBAR
;
1239 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1240 wwin
->frame_x
, wwin
->frame_y
,
1242 scr
->window_title_texture
,
1243 scr
->resizebar_texture
,
1244 scr
->window_title_pixel
,
1245 &scr
->window_title_gc
,
1248 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1250 wwin
->frame
->flags
.is_client_window_frame
= 1;
1251 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1253 wFrameWindowChangeTitle(wwin
->frame
, title
);
1255 /* setup button images */
1256 wWindowUpdateButtonImages(wwin
);
1259 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1261 wwin
->frame
->child
= wwin
;
1263 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1265 wwin
->frame
->on_click_right
= windowCloseClick
;
1267 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1268 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1270 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1272 wwin
->client
.y
+= wwin
->frame
->top_width
;
1273 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1274 0, wwin
->frame
->top_width
);
1276 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1277 wwin
->client
.width
, wwin
->client
.height
);
1279 /* setup the frame descriptor */
1280 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1281 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1282 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1285 XLowerWindow(dpy
, window
);
1286 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1288 /* setup stacking descriptor */
1291 wPreferences
.on_top_transients
&&
1293 wwin
->transient_for
!=None
1294 && wwin
->transient_for
!=scr
->root_win
) {
1296 tmp
= wWindowFor(wwin
->transient_for
);
1298 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1300 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1304 if (!scr
->focused_window
) {
1305 /* first window on the list */
1308 scr
->focused_window
= wwin
;
1312 /* add window at beginning of focus window list */
1313 tmp
= scr
->focused_window
;
1321 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1323 /* if (wPreferences.auto_focus)*/
1324 wSetFocusTo(scr
, wwin
);
1326 wWindowResetMouseGrabs(wwin
);
1328 wWindowSetKeyGrabs(wwin
);
1330 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1337 *----------------------------------------------------------------------
1339 * Removes the frame window from a window and destroys all data
1340 * related to it. The window will be reparented back to the root window
1341 * if restore is True.
1344 * Everything related to the window is destroyed and the window
1345 * is removed from the window lists. Focus is set to the previous on the
1347 *----------------------------------------------------------------------
1350 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1352 WCoreWindow
*frame
= wwin
->frame
->core
;
1353 WWindow
*owner
= NULL
;
1354 WWindow
*newFocusedWindow
= NULL
;
1356 WScreen
*scr
= wwin
->screen_ptr
;
1360 wwin
->frame
->workspace
= -1;
1362 wKWMUpdateClientWorkspace(wwin
);
1365 /* First close attribute editor window if open */
1366 if (wwin
->flags
.inspector_open
) {
1367 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1368 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1371 /* Close window menu if it's open for this window */
1372 if (wwin
->flags
.menu_open_for_me
) {
1373 CloseWindowMenu(scr
);
1377 if (!wwin
->flags
.internal_window
)
1378 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1380 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1382 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1383 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1386 XUnmapWindow(dpy
, frame
->window
);
1388 XUnmapWindow(dpy
, wwin
->client_win
);
1390 /* deselect window */
1391 wSelectWindow(wwin
, False
);
1393 /* remove all pending events on window */
1394 /* I think this only matters for autoraise */
1395 if (wPreferences
.raise_delay
)
1396 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1400 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1402 /* reparent the window back to the root */
1404 wClientRestore(wwin
);
1406 if (wwin
->transient_for
!=scr
->root_win
) {
1407 owner
= wWindowFor(wwin
->transient_for
);
1409 if (!owner
->flags
.semi_focused
) {
1412 owner
->flags
.semi_focused
= 0;
1417 wasFocused
= wwin
->flags
.focused
;
1419 /* remove from window focus list */
1420 if (!wwin
->prev
&& !wwin
->next
) {
1421 /* was the only window */
1422 scr
->focused_window
= NULL
;
1423 newFocusedWindow
= NULL
;
1428 wwin
->prev
->next
= wwin
->next
;
1430 wwin
->next
->prev
= wwin
->prev
;
1432 scr
->focused_window
= wwin
->prev
;
1433 scr
->focused_window
->next
= NULL
;
1436 /* if in click to focus mode and the window
1437 * was a transient, focus the owner window
1440 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1441 tmp
= wWindowFor(wwin
->transient_for
);
1442 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1446 /* otherwise, focus the next one in the focus list */
1448 tmp
= scr
->focused_window
;
1450 if (!WFLAGP(tmp
, no_focusable
)
1451 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1456 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1457 newFocusedWindow
= tmp
;
1458 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1459 || wPreferences
.focus_mode
==WKF_POINTER
) {
1464 /* This is to let the root window get the keyboard input
1465 * if Sloppy focus mode and no other window get focus.
1466 * This way keybindings will not freeze.
1469 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1470 &foo
, &foo
, &foo
, &foo
, &mask
))
1471 tmp
= wWindowFor(win
);
1474 newFocusedWindow
= tmp
;
1476 newFocusedWindow
= NULL
;
1480 if (!wwin
->flags
.internal_window
) {
1482 wGNOMERemoveClient(wwin
);
1485 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1490 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1491 (unsigned)frame
->window
);
1495 if (newFocusedWindow
!= owner
&& owner
) {
1496 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1498 wSetFocusTo(scr
, newFocusedWindow
);
1500 wWindowDestroy(wwin
);
1506 wWindowMap(WWindow
*wwin
)
1508 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1509 if (!wwin
->flags
.shaded
) {
1510 /* window will be remapped when getting MapNotify */
1511 XSelectInput(dpy
, wwin
->client_win
,
1512 wwin
->event_mask
& ~StructureNotifyMask
);
1513 XMapWindow(dpy
, wwin
->client_win
);
1514 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1516 wwin
->flags
.mapped
= 1;
1522 wWindowUnmap(WWindow
*wwin
)
1524 wwin
->flags
.mapped
= 0;
1526 /* prevent window withdrawal when getting UnmapNotify */
1527 XSelectInput(dpy
, wwin
->client_win
,
1528 wwin
->event_mask
& ~StructureNotifyMask
);
1529 XUnmapWindow(dpy
, wwin
->client_win
);
1530 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1532 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1538 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1543 #ifdef KEEP_XKB_LOCK_STATUS
1544 if (wPreferences
.modelock
) {
1545 if (!wwin
->flags
.focused
) {
1546 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1549 #endif /* KEEP_XKB_LOCK_STATUS */
1551 wwin
->flags
.semi_focused
= 0;
1553 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1555 wWindowResetMouseGrabs(wwin
);
1557 wwin
->flags
.focused
= 1;
1559 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1561 if (owin
== wwin
|| !owin
)
1564 nowner
= wWindowFor(wwin
->transient_for
);
1566 /* new window is a transient for the old window */
1567 if (nowner
== owin
) {
1568 owin
->flags
.semi_focused
= 1;
1569 wWindowUnfocus(nowner
);
1573 oowner
= wWindowFor(owin
->transient_for
);
1575 /* new window is owner of old window */
1576 if (wwin
== oowner
) {
1577 wWindowUnfocus(owin
);
1582 wWindowUnfocus(owin
);
1586 /* new window has same owner of old window */
1587 if (oowner
== nowner
) {
1588 /* prevent unfocusing of owner */
1589 oowner
->flags
.semi_focused
= 0;
1590 wWindowUnfocus(owin
);
1591 oowner
->flags
.semi_focused
= 1;
1596 /* nowner != NULL && oowner != nowner */
1597 nowner
->flags
.semi_focused
= 1;
1598 wWindowUnfocus(nowner
);
1599 wWindowUnfocus(owin
);
1604 wWindowUnfocus(WWindow
*wwin
)
1606 CloseWindowMenu(wwin
->screen_ptr
);
1608 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1609 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1611 if (wwin
->transient_for
!=None
1612 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1614 owner
= wWindowFor(wwin
->transient_for
);
1615 if (owner
&& owner
->flags
.semi_focused
) {
1616 owner
->flags
.semi_focused
= 0;
1617 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1618 wWindowUnfocus(owner
);
1619 wFrameWindowPaint(owner
->frame
);
1623 wwin
->flags
.focused
= 0;
1624 wWindowResetMouseGrabs(wwin
);
1626 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1633 *----------------------------------------------------------------------
1635 * wWindowConstrainSize--
1636 * Constrains size for the client window, taking the maximal size,
1637 * window resize increments and other size hints into account.
1640 * The closest size to what was given that the client window can
1643 *----------------------------------------------------------------------
1646 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1648 XSizeHints
*sizeh
= wwin
->normal_hints
;
1649 int width
= *nwidth
;
1650 int height
= *nheight
;
1651 int winc
= sizeh
->width_inc
;
1652 int hinc
= sizeh
->height_inc
;
1654 if (width
< sizeh
->min_width
)
1655 width
= sizeh
->min_width
;
1656 if (height
< sizeh
->min_height
)
1657 height
= sizeh
->min_height
;
1659 if (width
> sizeh
->max_width
)
1660 width
= sizeh
->max_width
;
1661 if (height
> sizeh
->max_height
)
1662 height
= sizeh
->max_height
;
1664 /* aspect ratio code borrowed from olwm */
1665 if (sizeh
->flags
& PAspect
) {
1666 /* adjust max aspect ratio */
1667 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1668 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1669 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1670 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1671 if (height
> sizeh
->max_height
) {
1672 height
= sizeh
->max_height
;
1673 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1676 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1677 if (width
> sizeh
->max_width
) {
1678 width
= sizeh
->max_width
;
1679 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1684 /* adjust min aspect ratio */
1685 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1686 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1687 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1688 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1689 if (height
< sizeh
->min_height
) {
1690 height
= sizeh
->min_height
;
1691 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1694 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1695 if (width
< sizeh
->min_width
) {
1696 width
= sizeh
->min_width
;
1697 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1703 if (sizeh
->base_width
!= 0) {
1704 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1705 + sizeh
->base_width
;
1707 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1711 if (sizeh
->base_width
!= 0) {
1712 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1713 + sizeh
->base_height
;
1715 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1716 + sizeh
->min_height
;
1725 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1727 WScreen
*scr
= wwin
->screen_ptr
;
1731 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1732 || workspace
== wwin
->frame
->workspace
)
1735 if (workspace
!= scr
->current_workspace
) {
1736 /* Sent to other workspace. Unmap window */
1737 if ((wwin
->flags
.mapped
1738 || wwin
->flags
.shaded
1739 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1740 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1742 wapp
= wApplicationOf(wwin
->main_window
);
1744 wapp
->last_workspace
= workspace
;
1746 if (wwin
->flags
.miniaturized
) {
1747 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1748 wwin
->icon
->mapped
= 0;
1751 wSetFocusTo(scr
, NULL
);
1755 /* brought to current workspace. Map window */
1756 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1757 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1758 wwin
->icon
->mapped
= 1;
1759 } else if (!wwin
->flags
.mapped
&&
1760 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1764 if (!IS_OMNIPRESENT(wwin
)) {
1765 wwin
->frame
->workspace
= workspace
;
1766 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1769 wGNOMEUpdateClientStateHint(wwin
, True
);
1772 wKWMUpdateClientWorkspace(wwin
);
1773 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1782 wWindowSynthConfigureNotify(WWindow
*wwin
)
1786 sevent
.type
= ConfigureNotify
;
1787 sevent
.xconfigure
.display
= dpy
;
1788 sevent
.xconfigure
.event
= wwin
->client_win
;
1789 sevent
.xconfigure
.window
= wwin
->client_win
;
1791 sevent
.xconfigure
.x
= wwin
->client
.x
;
1792 sevent
.xconfigure
.y
= wwin
->client
.y
;
1793 sevent
.xconfigure
.width
= wwin
->client
.width
;
1794 sevent
.xconfigure
.height
= wwin
->client
.height
;
1796 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1797 if (WFLAGP(wwin
, no_titlebar
))
1798 sevent
.xconfigure
.above
= None
;
1800 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1802 sevent
.xconfigure
.override_redirect
= False
;
1803 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1805 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1812 *----------------------------------------------------------------------
1813 * wWindowConfigure--
1814 * Configures the frame, decorations and client window to the
1815 * specified geometry. The geometry is not checked for validity,
1816 * wWindowConstrainSize() must be used for that.
1817 * The size parameters are for the client window, but the position is
1819 * The client window receives a ConfigureNotify event, according
1820 * to what ICCCM says.
1826 * Window size and position are changed and client window receives
1827 * a ConfigureNotify event.
1828 *----------------------------------------------------------------------
1831 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1833 int req_x
, req_y
; /* new position of the frame */
1834 int req_width
, req_height
; /* new size of the client */
1836 int synth_notify
= False
;
1839 resize
= (req_width
!=wwin
->client
.width
1840 || req_height
!=wwin
->client
.height
);
1842 * if the window is being moved but not resized then
1843 * send a synthetic ConfigureNotify
1845 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1846 synth_notify
= True
;
1849 if (WFLAGP(wwin
, dont_move_off
))
1850 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1851 req_width
, req_height
);
1853 if (req_width
< MIN_WINDOW_SIZE
)
1854 req_width
= MIN_WINDOW_SIZE
;
1855 if (req_height
< MIN_WINDOW_SIZE
)
1856 req_height
= MIN_WINDOW_SIZE
;
1858 /* If growing, resize inner part before frame,
1859 * if shrinking, resize frame before.
1860 * This will prevent the frame (that can have a different color)
1861 * to be exposed, causing flicker */
1862 if (req_height
> wwin
->frame
->core
->height
1863 || req_width
> wwin
->frame
->core
->width
)
1864 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1866 if (wwin
->flags
.shaded
) {
1867 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1868 req_width
, wwin
->frame
->core
->height
);
1869 wwin
->old_geometry
.height
= req_height
;
1873 h
= req_height
+ wwin
->frame
->top_width
1874 + wwin
->frame
->bottom_width
;
1876 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1879 if (!(req_height
> wwin
->frame
->core
->height
1880 || req_width
> wwin
->frame
->core
->width
))
1881 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1883 wwin
->client
.x
= req_x
;
1884 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1885 wwin
->client
.width
= req_width
;
1886 wwin
->client
.height
= req_height
;
1888 wwin
->client
.x
= req_x
;
1889 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1891 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1893 wwin
->frame_x
= req_x
;
1894 wwin
->frame_y
= req_y
;
1897 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1898 wWindowSetShape(wwin
);
1903 wWindowSynthConfigureNotify(wwin
);
1909 wWindowMove(wwin
, req_x
, req_y
)
1911 int req_x
, req_y
; /* new position of the frame */
1913 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1914 int synth_notify
= False
;
1916 /* Send a synthetic ConfigureNotify event for every window movement. */
1917 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1918 synth_notify
= True
;
1921 /* A single synthetic ConfigureNotify event is sent at the end of
1922 * a completed (opaque) movement in moveres.c */
1925 if (WFLAGP(wwin
, dont_move_off
))
1926 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1927 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1929 wwin
->client
.x
= req_x
;
1930 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1932 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1934 wwin
->frame_x
= req_x
;
1935 wwin
->frame_y
= req_y
;
1937 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1939 wWindowSynthConfigureNotify(wwin
);
1945 wWindowUpdateButtonImages(WWindow
*wwin
)
1947 WScreen
*scr
= wwin
->screen_ptr
;
1948 Pixmap pixmap
, mask
;
1949 WFrameWindow
*fwin
= wwin
->frame
;
1951 if (WFLAGP(wwin
, no_titlebar
))
1954 /* miniaturize button */
1956 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
1957 if (wwin
->wm_gnustep_attr
1958 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1959 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1961 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1962 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1967 if (fwin
->lbutton_image
1968 && (fwin
->lbutton_image
->image
!= pixmap
1969 || fwin
->lbutton_image
->mask
!= mask
)) {
1970 wPixmapDestroy(fwin
->lbutton_image
);
1971 fwin
->lbutton_image
= NULL
;
1974 if (!fwin
->lbutton_image
) {
1975 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1976 fwin
->lbutton_image
->client_owned
= 1;
1977 fwin
->lbutton_image
->client_owned_mask
= 1;
1980 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
1981 wPixmapDestroy(fwin
->lbutton_image
);
1983 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
1989 if (!WFLAGP(wwin
, no_close_button
)) {
1990 if (wwin
->wm_gnustep_attr
1991 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
1992 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
1994 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
1995 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2000 if (fwin
->rbutton_image
2001 && (fwin
->rbutton_image
->image
!= pixmap
2002 || fwin
->rbutton_image
->mask
!= mask
)) {
2003 wPixmapDestroy(fwin
->rbutton_image
);
2004 fwin
->rbutton_image
= NULL
;
2007 if (!fwin
->rbutton_image
) {
2008 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2009 fwin
->rbutton_image
->client_owned
= 1;
2010 fwin
->rbutton_image
->client_owned_mask
= 1;
2012 } else if (WFLAGP(wwin
, kill_close
)) {
2013 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2014 wPixmapDestroy(fwin
->rbutton_image
);
2016 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2017 } else if (WFLAGP(wwin
, broken_close
)) {
2018 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2019 wPixmapDestroy(fwin
->rbutton_image
);
2021 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2023 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2024 wPixmapDestroy(fwin
->rbutton_image
);
2026 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2030 /* force buttons to be redrawn */
2031 fwin
->flags
.need_texture_change
= 1;
2032 wFrameWindowPaint(fwin
);
2037 *---------------------------------------------------------------------------
2038 * wWindowConfigureBorders--
2039 * Update window border configuration according to attribute flags.
2041 *---------------------------------------------------------------------------
2044 wWindowConfigureBorders(WWindow
*wwin
)
2050 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2051 if (!WFLAGP(wwin
, no_titlebar
))
2052 flags
|= WFF_TITLEBAR
;
2053 if (!WFLAGP(wwin
, no_resizebar
))
2054 flags
|= WFF_RESIZEBAR
;
2055 if (wwin
->flags
.shaded
)
2056 flags
|= WFF_IS_SHADED
;
2058 oldh
= wwin
->frame
->top_width
;
2059 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2060 if (oldh
!= wwin
->frame
->top_width
) {
2061 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2063 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2064 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2065 wwin
->client
.width
, wwin
->client
.height
);
2069 if (!WFLAGP(wwin
, no_miniaturize_button
)
2070 && wwin
->frame
->flags
.hide_left_button
)
2071 flags
|= WFF_LEFT_BUTTON
;
2073 if (!WFLAGP(wwin
, no_close_button
)
2074 && wwin
->frame
->flags
.hide_right_button
)
2075 flags
|= WFF_RIGHT_BUTTON
;
2078 wWindowUpdateButtonImages(wwin
);
2079 wFrameWindowShowButton(wwin
->frame
, flags
);
2083 if (WFLAGP(wwin
, no_miniaturize_button
)
2084 && !wwin
->frame
->flags
.hide_left_button
)
2085 flags
|= WFF_LEFT_BUTTON
;
2087 if (WFLAGP(wwin
, no_close_button
)
2088 && !wwin
->frame
->flags
.hide_right_button
)
2089 flags
|= WFF_RIGHT_BUTTON
;
2092 wFrameWindowHideButton(wwin
->frame
, flags
);
2095 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2096 wWindowSetShape(wwin
);
2104 wWindowSaveState(WWindow
*wwin
)
2109 memset(data
, 0, sizeof(CARD32
)*10);
2110 data
[0] = wwin
->frame
->workspace
;
2111 data
[1] = wwin
->flags
.miniaturized
;
2112 data
[2] = wwin
->flags
.shaded
;
2113 data
[3] = wwin
->flags
.hidden
;
2115 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2116 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
)
2119 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2120 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2121 (unsigned char *)data
, 10);
2126 getSavedState(Window window
, WSavedState
**state
)
2130 unsigned long nitems_ret
;
2131 unsigned long bytes_after_ret
;
2134 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2135 True
, _XA_WINDOWMAKER_STATE
,
2136 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2137 (unsigned char **)&data
)!=Success
|| !data
)
2140 *state
= malloc(sizeof(WSavedState
));
2143 (*state
)->workspace
= data
[0];
2144 (*state
)->miniaturized
= data
[1];
2145 (*state
)->shaded
= data
[2];
2146 (*state
)->hidden
= data
[3];
2147 (*state
)->use_geometry
= data
[4];
2148 (*state
)->x
= data
[5];
2149 (*state
)->y
= data
[6];
2150 (*state
)->w
= data
[7];
2151 (*state
)->h
= data
[8];
2152 (*state
)->window_shortcuts
= data
[9];
2156 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2165 wWindowClearShape(WWindow
*wwin
)
2167 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2168 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2173 wWindowSetShape(WWindow
*wwin
)
2177 #ifdef OPTIMIZE_SHAPE
2182 /* only shape is the client's */
2183 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2187 /* Get array of rectangles describing the shape mask */
2188 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2194 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2200 /* insert our decoration rectangles in the rect list */
2201 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2204 if (!WFLAGP(wwin
, no_titlebar
)) {
2206 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2207 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2208 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2211 if (!WFLAGP(wwin
, no_resizebar
)) {
2213 urec
[count
].y
= wwin
->frame
->core
->height
2214 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2215 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2216 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2220 /* shape our frame window */
2221 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2222 0, wwin
->frame
->top_width
, urec
, count
,
2223 ShapeSet
, Unsorted
);
2229 #endif /* OPTIMIZE_SHAPE */
2231 if (!WFLAGP(wwin
, no_titlebar
)) {
2234 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2235 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2238 if (!WFLAGP(wwin
, no_resizebar
)) {
2240 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2241 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2242 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2246 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2247 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2249 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2250 0, wwin
->frame
->top_width
, wwin
->client_win
,
2251 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2256 /* ====================================================================== */
2259 getFocusMode(WWindow
*wwin
)
2263 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2264 if (wwin
->wm_hints
->input
== True
) {
2265 if (wwin
->protocols
.TAKE_FOCUS
)
2266 mode
= WFM_LOCALLY_ACTIVE
;
2270 if (wwin
->protocols
.TAKE_FOCUS
)
2271 mode
= WFM_GLOBALLY_ACTIVE
;
2273 mode
= WFM_NO_INPUT
;
2283 wWindowSetKeyGrabs(WWindow
*wwin
)
2288 for (i
=0; i
<WKBD_LAST
; i
++) {
2289 key
= &wKeyBindings
[i
];
2291 if (key
->keycode
==0)
2293 if (key
->modifier
!=AnyModifier
) {
2294 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2295 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2297 /* Also grab all modifier combinations possible that include,
2298 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2299 * work even if the NumLock/ScrollLock key is on.
2301 wHackedGrabKey(key
->keycode
, key
->modifier
,
2302 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2306 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2307 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2311 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2318 wWindowResetMouseGrabs(WWindow
*wwin
)
2320 /* Mouse grabs can't be done on the client window because of
2321 * ICCCM and because clients that try to do the same will crash.
2323 * But there is a problem wich makes tbar buttons of unfocused
2324 * windows not usable as the click goes to the frame window instead
2325 * of the button itself. Must figure a way to fix that.
2328 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2330 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2331 /* grabs for Meta+drag */
2332 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2333 True
, ButtonPressMask
, GrabModeSync
,
2334 GrabModeAsync
, None
, None
);
2337 if (!wwin
->flags
.focused
) {
2338 /* the passive grabs to focus the window */
2339 if (wPreferences
.focus_mode
== WKF_CLICK
)
2340 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2341 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2349 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2352 if (attr
->flags
& GSExtraFlagsAttr
) {
2353 if (WFLAGP(wwin
, broken_close
) !=
2354 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2356 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2358 wWindowUpdateButtonImages(wwin
);
2366 wWindowAddSavedState(char *instance
, char *class, char *command
,
2367 pid_t pid
, WSavedState
*state
)
2369 WWindowState
*wstate
;
2371 wstate
= malloc(sizeof(WWindowState
));
2375 memset(wstate
, 0, sizeof(WWindowState
));
2378 wstate
->instance
= wstrdup(instance
);
2380 wstate
->class = wstrdup(class);
2382 wstate
->command
= wstrdup(command
);
2383 wstate
->state
= state
;
2385 wstate
->next
= windowState
;
2386 windowState
= wstate
;
2389 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2397 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2401 wWindowGetSavedState(Window win
)
2403 char *instance
, *class, *command
=NULL
;
2404 WWindowState
*wstate
= windowState
;
2411 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2413 command
= FlattenStringList(argv
, argc
);
2414 XFreeStringList(argv
);
2419 if (PropGetWMClass(win
, &class, &instance
)) {
2421 if (SAME(instance
, wstate
->instance
) &&
2422 SAME(class, wstate
->class) &&
2423 SAME(command
, wstate
->command
)) {
2426 wstate
= wstate
->next
;
2433 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2437 if (command
) free(command
);
2438 if (instance
) XFree(instance
);
2439 if (class) XFree(class);
2446 wWindowDeleteSavedState(WMagicNumber id
)
2448 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2450 if (!wstate
|| !windowState
)
2455 windowState
= wstate
->next
;
2457 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2458 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2460 if (wstate
->instance
) free(wstate
->instance
);
2461 if (wstate
->class) free(wstate
->class);
2462 if (wstate
->command
) free(wstate
->command
);
2463 free(wstate
->state
);
2467 if (tmp
->next
==wstate
) {
2468 tmp
->next
=wstate
->next
;
2470 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2471 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2473 if (wstate
->instance
) free(wstate
->instance
);
2474 if (wstate
->class) free(wstate
->class);
2475 if (wstate
->command
) free(wstate
->command
);
2476 free(wstate
->state
);
2487 wWindowDeleteSavedStatesForPID(pid_t pid
)
2489 WWindowState
*tmp
, *wstate
;
2495 if (tmp
->pid
== pid
) {
2496 wstate
= windowState
;
2497 windowState
= tmp
->next
;
2499 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2500 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2502 if (wstate
->instance
) free(wstate
->instance
);
2503 if (wstate
->class) free(wstate
->class);
2504 if (wstate
->command
) free(wstate
->command
);
2505 free(wstate
->state
);
2509 if (tmp
->next
->pid
==pid
) {
2511 tmp
->next
= wstate
->next
;
2513 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2514 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2516 if (wstate
->instance
) free(wstate
->instance
);
2517 if (wstate
->class) free(wstate
->class);
2518 if (wstate
->command
) free(wstate
->command
);
2519 free(wstate
->state
);
2529 /* ====================================================================== */
2532 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2534 WWindow
*wwin
= data
;
2536 #ifndef NUMLOCK_HACK
2537 if ((event
->xbutton
.state
& ValidModMask
)
2538 != (event
->xbutton
.state
& ~LockMask
)) {
2539 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2540 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2544 event
->xbutton
.state
&= ValidModMask
;
2546 CloseWindowMenu(wwin
->screen_ptr
);
2548 if (wPreferences
.focus_mode
==WKF_CLICK
2549 && !(event
->xbutton
.state
&ControlMask
)
2550 && !WFLAGP(wwin
, no_focusable
)) {
2551 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2554 if (event
->xbutton
.button
== Button1
)
2555 wRaiseFrame(wwin
->frame
->core
);
2557 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2558 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2559 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2560 GrabModeAsync
, GrabModeAsync
, None
,
2561 None
, CurrentTime
)!=GrabSuccess
) {
2563 wwarning("pointer grab failed for window move");
2569 if (event
->xbutton
.state
& MOD_MASK
) {
2570 /* move the window */
2571 wMouseMoveWindow(wwin
, event
);
2572 XUngrabPointer(dpy
, CurrentTime
);
2574 wMouseResizeWindow(wwin
, event
);
2575 XUngrabPointer(dpy
, CurrentTime
);
2582 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2584 WWindow
*wwin
= data
;
2586 event
->xbutton
.state
&= ValidModMask
;
2588 if (event
->xbutton
.button
==Button1
) {
2589 if (event
->xbutton
.state
== 0) {
2590 if (!WFLAGP(wwin
, no_shadeable
)) {
2592 if (wwin
->flags
.shaded
)
2593 wUnshadeWindow(wwin
);
2600 if (event
->xbutton
.state
& ControlMask
)
2601 dir
|= MAX_VERTICAL
;
2603 if (event
->xbutton
.state
& ShiftMask
) {
2604 dir
|= MAX_HORIZONTAL
;
2605 if (!(event
->xbutton
.state
& ControlMask
))
2606 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2609 /* maximize window */
2610 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2611 if (wwin
->flags
.maximized
)
2612 wUnmaximizeWindow(wwin
);
2614 wMaximizeWindow(wwin
, dir
);
2617 } else if (event
->xbutton
.button
==Button3
) {
2618 if (event
->xbutton
.state
& MOD_MASK
) {
2619 wHideOtherApplications(wwin
);
2621 } else if (event
->xbutton
.button
==Button2
) {
2622 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2628 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2630 WWindow
*wwin
= desc
->parent
;
2632 event
->xbutton
.state
&= ValidModMask
;
2634 CloseWindowMenu(wwin
->screen_ptr
);
2636 if (wPreferences
.focus_mode
==WKF_CLICK
2637 && !(event
->xbutton
.state
&ControlMask
)
2638 && !WFLAGP(wwin
, no_focusable
)) {
2639 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2641 if (event
->xbutton
.button
== Button1
) {
2642 wRaiseFrame(wwin
->frame
->core
);
2645 if (event
->xbutton
.state
& MOD_MASK
) {
2646 /* move the window */
2647 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2648 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2649 GrabModeAsync
, GrabModeAsync
, None
,
2650 None
, CurrentTime
)!=GrabSuccess
) {
2652 wwarning("pointer grab failed for window move");
2656 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2657 wMouseResizeWindow(wwin
, event
);
2659 wMouseMoveWindow(wwin
, event
);
2660 XUngrabPointer(dpy
, CurrentTime
);
2666 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2668 WWindow
*wwin
= (WWindow
*)data
;
2670 #ifndef NUMLOCK_HACK
2671 if ((event
->xbutton
.state
& ValidModMask
)
2672 != (event
->xbutton
.state
& ~LockMask
)) {
2673 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2674 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2677 event
->xbutton
.state
&= ValidModMask
;
2679 CloseWindowMenu(wwin
->screen_ptr
);
2681 if (wPreferences
.focus_mode
==WKF_CLICK
2682 && !(event
->xbutton
.state
&ControlMask
)
2683 && !WFLAGP(wwin
, no_focusable
)) {
2684 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2687 if (event
->xbutton
.button
== Button1
2688 || event
->xbutton
.button
== Button2
) {
2690 if (event
->xbutton
.button
== Button1
) {
2691 if (event
->xbutton
.state
& MOD_MASK
) {
2692 wLowerFrame(wwin
->frame
->core
);
2694 wRaiseFrame(wwin
->frame
->core
);
2697 if ((event
->xbutton
.state
& ShiftMask
)
2698 && !(event
->xbutton
.state
& ControlMask
)) {
2699 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2702 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2703 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2704 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2705 GrabModeAsync
, GrabModeAsync
, None
,
2706 None
, CurrentTime
)!=GrabSuccess
) {
2708 wwarning("pointer grab failed for window move");
2713 /* move the window */
2714 wMouseMoveWindow(wwin
, event
);
2716 XUngrabPointer(dpy
, CurrentTime
);
2717 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2718 && !wwin
->flags
.internal_window
2719 && !WCHECK_STATE(WSTATE_MODAL
)) {
2720 WObjDescriptor
*desc
;
2722 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2723 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2724 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2725 GrabModeAsync
, GrabModeAsync
, None
,
2726 None
, CurrentTime
)!=GrabSuccess
) {
2728 wwarning("pointer grab failed for window move");
2733 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2734 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2736 /* allow drag select */
2737 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2738 event
->xany
.send_event
= True
;
2739 (*desc
->handle_mousedown
)(desc
, event
);
2741 XUngrabPointer(dpy
, CurrentTime
);
2748 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2750 WWindow
*wwin
= data
;
2752 event
->xbutton
.state
&= ValidModMask
;
2754 CloseWindowMenu(wwin
->screen_ptr
);
2756 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2759 /* if control-click, kill the client */
2760 if (event
->xbutton
.state
& ControlMask
) {
2764 if (wwin
->flags
.olwm_push_pin_out
) {
2766 wwin
->flags
.olwm_push_pin_out
= 0;
2768 wOLWMChangePushpinState(wwin
, True
);
2770 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2775 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2776 /* send delete message */
2777 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2784 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2786 WWindow
*wwin
= data
;
2788 CloseWindowMenu(wwin
->screen_ptr
);
2790 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2793 /* send delete message */
2794 if (wwin
->protocols
.DELETE_WINDOW
) {
2795 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2803 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2805 WWindow
*wwin
= data
;
2807 event
->xbutton
.state
&= ValidModMask
;
2809 CloseWindowMenu(wwin
->screen_ptr
);
2811 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2814 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2815 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2819 if ((event
->xbutton
.state
& ControlMask
) ||
2820 (event
->xbutton
.button
== Button3
)) {
2822 wapp
= wApplicationOf(wwin
->main_window
);
2823 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2824 wHideApplication(wapp
);
2825 } else if (event
->xbutton
.state
==0) {
2826 wIconifyWindow(wwin
);