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
);
137 wWindowFor(Window window
)
139 WObjDescriptor
*desc
;
144 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
147 if (desc
->parent_type
==WCLASS_WINDOW
)
149 else if (desc
->parent_type
==WCLASS_FRAME
) {
150 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
151 if (frame
->flags
.is_client_window_frame
)
163 wwin
= wmalloc(sizeof(WWindow
));
166 memset(wwin
, 0, sizeof(WWindow
));
168 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
169 wwin
->client_descriptor
.parent
= wwin
;
170 wwin
->client_descriptor
.self
= wwin
;
171 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
177 wWindowDestroy(WWindow
*wwin
)
181 wwin
->flags
.destroyed
= 1;
183 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
184 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
) {
185 wwin
->screen_ptr
->shortcutWindow
[i
] = NULL
;
189 if (wwin
->normal_hints
)
190 free(wwin
->normal_hints
);
193 XFree(wwin
->wm_hints
);
195 if (wwin
->wm_instance
)
196 XFree(wwin
->wm_instance
);
199 XFree(wwin
->wm_class
);
201 if (wwin
->wm_gnustep_attr
)
202 free(wwin
->wm_gnustep_attr
);
204 if (wwin
->cmap_windows
)
205 XFree(wwin
->cmap_windows
);
207 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
210 wFrameWindowDestroy(wwin
->frame
);
213 RemoveFromStackList(wwin
->icon
->core
);
214 wIconDestroy(wwin
->icon
);
215 if (wPreferences
.auto_arrange_icons
)
216 wArrangeIcons(wwin
->screen_ptr
, True
);
225 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
227 if (gs_hints
->flags
& GSWindowStyleAttr
) {
228 wwin
->client_flags
.no_titlebar
=
229 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
231 wwin
->client_flags
.no_close_button
=
232 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
234 wwin
->client_flags
.no_closable
=
235 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
237 wwin
->client_flags
.no_miniaturize_button
=
238 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
240 wwin
->client_flags
.no_miniaturizable
=
241 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
243 wwin
->client_flags
.no_resizebar
=
244 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
246 wwin
->client_flags
.no_resizable
=
247 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
249 /* setup the defaults */
250 wwin
->client_flags
.no_titlebar
= 0;
251 wwin
->client_flags
.no_closable
= 0;
252 wwin
->client_flags
.no_miniaturizable
= 0;
253 wwin
->client_flags
.no_resizable
= 0;
254 wwin
->client_flags
.no_close_button
= 0;
255 wwin
->client_flags
.no_miniaturize_button
= 0;
256 wwin
->client_flags
.no_resizebar
= 0;
258 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
259 wwin
->client_flags
.no_appicon
= 1;
265 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
266 WWindowAttributes
*mask
)
268 if (wflags
->no_appicon
&& mask
->no_appicon
)
269 wflags
->emulate_appicon
= 0;
271 if (wwin
->main_window
!=None
) {
272 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
273 if (wapp
&& !wapp
->flags
.emulated
)
274 wflags
->emulate_appicon
= 0;
277 if (wwin
->transient_for
!=None
278 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
279 wflags
->emulate_appicon
= 0;
281 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
288 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
290 WScreen
*scr
= wwin
->screen_ptr
;
292 /* sets global default stuff */
293 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
294 &wwin
->client_flags
, NULL
, True
);
296 * Decoration setting is done in this precedence (lower to higher)
297 * - use global default in the resource database
298 * - guess some settings
299 * - use GNUstep/external window attributes
300 * - set hints specified for the app in the resource DB
303 WSETUFLAG(wwin
, broken_close
, 0);
305 if (wwin
->protocols
.DELETE_WINDOW
)
306 WSETUFLAG(wwin
, kill_close
, 0);
308 WSETUFLAG(wwin
, kill_close
, 1);
310 /* transients can't be iconified or maximized */
311 if (wwin
->transient_for
) {
312 WSETUFLAG(wwin
, no_miniaturizable
, 1);
313 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
316 /* if the window can't be resized, remove the resizebar */
317 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
318 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
319 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
320 WSETUFLAG(wwin
, no_resizable
, 1);
321 WSETUFLAG(wwin
, no_resizebar
, 1);
324 /* set GNUstep window attributes */
325 if (wwin
->wm_gnustep_attr
) {
326 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
328 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
330 switch (wwin
->wm_gnustep_attr
->window_level
) {
331 case WMNormalWindowLevel
:
332 *level
= WMNormalLevel
;
334 case WMFloatingWindowLevel
:
335 *level
= WMFloatingLevel
;
337 case WMDockWindowLevel
:
338 *level
= WMDockLevel
;
340 case WMSubmenuWindowLevel
:
341 *level
= WMSubmenuLevel
;
343 case WMMainMenuWindowLevel
:
344 *level
= WMMainMenuLevel
;
347 *level
= WMNormalLevel
;
352 *level
= WMNormalLevel
;
355 int tmp_workspace
= -1;
359 wMWMCheckClientHints(wwin
);
360 #endif /* MWM_HINTS */
363 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
364 #endif /* KWM_HINTS */
367 wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
368 #endif /* GNOME_STUFF */
371 wOLWMCheckClientHints(wwin
);
372 #endif /* OLWM_HINTS */
375 if (WFLAGP(wwin
, floating
))
376 *level
= WMFloatingLevel
;
377 else if (WFLAGP(wwin
, sunken
))
378 *level
= WMSunkenLevel
;
380 *level
= WMNormalLevel
;
385 if (tmp_workspace
>= 0) {
386 *workspace
= tmp_workspace
% scr
->workspace_count
;
391 * Set attributes specified only for that window/class.
392 * This might do duplicate work with the 1st wDefaultFillAttributes().
394 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
395 &wwin
->user_flags
, &wwin
->defined_user_flags
,
398 * Sanity checks for attributes that depend on other attributes
400 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
401 wwin
->user_flags
.emulate_appicon
= 0;
403 if (wwin
->main_window
!=None
) {
404 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
405 if (wapp
&& !wapp
->flags
.emulated
)
406 wwin
->user_flags
.emulate_appicon
= 0;
409 if (wwin
->transient_for
!=None
410 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
411 wwin
->user_flags
.emulate_appicon
= 0;
413 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
414 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
415 wwin
->user_flags
.sunken
= 0;
417 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
424 wWindowCanReceiveFocus(WWindow
*wwin
)
426 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
428 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
430 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
438 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
442 w1
= wwin
->frame
->core
->width
;
443 h1
= wwin
->frame
->core
->height
;
444 w2
= obscured
->frame
->core
->width
;
445 h2
= obscured
->frame
->core
->height
;
447 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
448 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
451 if (wwin
->frame_x
+ w1
< obscured
->frame_x
452 || wwin
->frame_y
+ h1
< obscured
->frame_y
453 || wwin
->frame_x
> obscured
->frame_x
+ w2
454 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
463 *----------------------------------------------------------------
465 * reparents the window and allocates a descriptor for it.
466 * Window manager hints and other hints are fetched to configure
467 * the window decoration attributes and others. User preferences
468 * for the window are used if available, to configure window
469 * decorations and some behaviour.
470 * If in startup, windows that are override redirect,
471 * unmapped and never were managed and are Withdrawn are not
475 * the new window descriptor
478 * The window is reparented and appropriate notification
479 * is done to the client. Input mask for the window is setup.
480 * The window descriptor is also associated with various window
481 * contexts and inserted in the head of the window list.
482 * Event handler contexts are associated for some objects
483 * (buttons, titlebar and resizebar)
485 *----------------------------------------------------------------
488 wManageWindow(WScreen
*scr
, Window window
)
492 unsigned width
, height
;
493 XWindowAttributes wattribs
;
494 XSetWindowAttributes attribs
;
495 WWindowState
*win_state
;
496 WWindow
*transientOwner
= NULL
;
502 Bool withdraw
= False
;
505 /* XGrabServer(dpy); */
507 /* make sure the window is still there */
508 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
513 /* if it's an override-redirect, ignore it */
514 if (wattribs
.override_redirect
) {
519 wm_state
= PropGetWindowState(window
);
521 /* if it's startup and the window is unmapped, don't manage it */
522 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
527 if (!wFetchName(dpy
, window
, &title
)) {
532 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
537 #endif /* KWM_HINTS */
540 wwin
= wWindowCreate();
542 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
545 printf("managing window %x\n", (unsigned)window
);
549 if (wShapeSupported
) {
554 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
555 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
556 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
557 wwin
->flags
.shaped
= b_shaped
;
562 *--------------------------------------------------
564 * Get hints and other information in properties
566 *--------------------------------------------------
568 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
570 /* setup descriptor */
571 wwin
->client_win
= window
;
572 wwin
->screen_ptr
= scr
;
574 wwin
->old_border_width
= wattribs
.border_width
;
576 wwin
->event_mask
= CLIENT_EVENTS
;
577 attribs
.event_mask
= CLIENT_EVENTS
;
578 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
579 attribs
.save_under
= False
;
580 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
581 |CWSaveUnder
, &attribs
);
582 XSetWindowBorderWidth(dpy
, window
, 0);
584 /* get hints from GNUstep app */
585 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
586 wwin
->wm_gnustep_attr
= NULL
;
589 wwin
->client_leader
= PropGetClientLeader(window
);
590 if (wwin
->client_leader
!=None
)
591 wwin
->main_window
= wwin
->client_leader
;
593 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
595 if (wwin
->wm_hints
) {
596 if (wwin
->wm_hints
->flags
& StateHint
) {
598 if (wwin
->wm_hints
->initial_state
== IconicState
) {
600 wwin
->flags
.miniaturized
= 1;
602 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
608 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
609 wwin
->group_id
= wwin
->wm_hints
->window_group
;
610 /* window_group has priority over CLIENT_LEADER */
611 wwin
->main_window
= wwin
->group_id
;
613 wwin
->group_id
= None
;
616 if (wwin
->wm_hints
->flags
& UrgencyHint
)
617 wwin
->flags
.urgent
= 1;
619 wwin
->group_id
= None
;
622 PropGetProtocols(window
, &wwin
->protocols
);
624 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
625 wwin
->transient_for
= None
;
627 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
628 wwin
->transient_for
= scr
->root_win
;
630 transientOwner
= wWindowFor(wwin
->transient_for
);
631 if (transientOwner
&& transientOwner
->main_window
!=None
) {
632 wwin
->main_window
= transientOwner
->main_window
;
634 wwin->main_window = None;
639 /* guess the focus mode */
640 wwin
->focus_mode
= getFocusMode(wwin
);
642 /* get geometry stuff */
643 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
645 /* get colormap windows */
646 GetColormapWindows(wwin
);
649 *--------------------------------------------------
651 * Setup the decoration/window attributes and
654 *--------------------------------------------------
657 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
660 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
661 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
663 transientOwner
= wWindowFor(wwin
->group_id
);
665 if (transientOwner
) {
666 wwin
->transient_for
= wwin
->group_id
;
668 /* transients can't be iconified or maximized */
669 if (wwin
->transient_for
) {
670 WSETUFLAG(wwin
, no_miniaturizable
, 1);
671 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
675 #endif /* OLWM_HINTS */
678 * Make broken apps behave as a nice app.
680 if (WFLAGP(wwin
, emulate_appicon
)) {
681 wwin
->main_window
= wwin
->client_win
;
685 *------------------------------------------------------------
687 * Setup the initial state of the window
689 *------------------------------------------------------------
692 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
693 wwin
->flags
.miniaturized
= 1;
696 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
697 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
701 wGNOMECheckInitialClientState(wwin
);
704 wKWMCheckClientInitialState(wwin
);
707 /* apply previous state if it exists and we're in startup */
708 if (scr
->flags
.startup
&& wm_state
>= 0) {
710 if (wm_state
== IconicState
) {
712 wwin
->flags
.miniaturized
= 1;
714 } else if (wm_state
== WithdrawnState
) {
720 /* if there is a saved state (from file), restore it */
722 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
723 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
725 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
727 if (win_state
&& !withdraw
) {
729 if (win_state
->state
->hidden
>0)
730 wwin
->flags
.hidden
= win_state
->state
->hidden
;
732 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
733 wwin
->flags
.shaded
= win_state
->state
->shaded
;
735 if (win_state
->state
->miniaturized
>0 &&
736 !WFLAGP(wwin
, no_miniaturizable
)) {
737 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
739 if (!IS_OMNIPRESENT(wwin
)) {
740 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
742 if (w
< 0 || w
>= scr
->workspace_count
) {
743 workspace
= win_state
->state
->workspace
;
744 if (workspace
>= scr
->workspace_count
)
745 workspace
= scr
->current_workspace
;
750 workspace
= scr
->current_workspace
;
754 /* if we're restarting, restore saved state (from hints).
755 * This will overwrite previous */
759 if (getSavedState(window
, &wstate
)) {
760 wwin
->flags
.shaded
= wstate
->shaded
;
761 wwin
->flags
.hidden
= wstate
->hidden
;
762 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
763 workspace
= wstate
->workspace
;
765 if (scr
->flags
.startup
&& wstate
->window_shortcuts
>= 0) {
768 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
769 if (wstate
->window_shortcuts
& (1<<i
))
770 scr
->shortcutWindow
[i
] = wwin
;
777 /* don't let transients start miniaturized if their owners are not */
778 if (transientOwner
&& !transientOwner
->flags
.miniaturized
779 && wwin
->flags
.miniaturized
&& !withdraw
) {
780 wwin
->flags
.miniaturized
= 0;
782 wwin
->wm_hints
->initial_state
= NormalState
;
785 /* set workspace on which the window starts */
786 if (workspace
>= 0) {
787 if (workspace
> scr
->workspace_count
-1) {
788 workspace
= workspace
% scr
->workspace_count
;
793 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
795 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
800 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
802 workspace
= transientOwner
->frame
->workspace
;
806 workspace
= scr
->current_workspace
;
811 /* setup window geometry */
812 if (win_state
&& win_state
->state
->use_geometry
) {
813 width
= win_state
->state
->w
;
814 height
= win_state
->state
->h
;
816 wWindowConstrainSize(wwin
, &width
, &height
);
818 /* do not ask for window placement if the window is
819 * transient, during startup, if the initial workspace is another one
820 * or if the window wants to start iconic.
821 * If geometry was saved, restore it. */
823 Bool dontBring
= False
;
825 if (win_state
&& win_state
->state
->use_geometry
) {
826 x
= win_state
->state
->x
;
827 y
= win_state
->state
->y
;
828 } else if ((wwin
->transient_for
==None
829 || wPreferences
.window_placement
!=WPM_MANUAL
)
830 && !scr
->flags
.startup
831 && workspace
== scr
->current_workspace
832 && !wwin
->flags
.miniaturized
833 && !wwin
->flags
.maximized
834 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
835 PlaceWindow(wwin
, &x
, &y
, width
, height
);
836 if (wPreferences
.window_placement
== WPM_MANUAL
)
840 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
841 wScreenBringInside(scr
, &x
, &y
, width
, height
);
844 if (wwin
->flags
.urgent
) {
845 if (!IS_OMNIPRESENT(wwin
))
846 wwin
->flags
.omnipresent
^= 1;
850 *--------------------------------------------------
852 * Create frame, borders and do reparenting
854 *--------------------------------------------------
856 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
857 if (!WFLAGP(wwin
, no_titlebar
))
859 if (!WFLAGP(wwin
, no_resizebar
))
860 foo
|= WFF_RESIZEBAR
;
862 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
863 x
, y
, width
, height
, foo
,
864 scr
->window_title_texture
,
865 (WTexture
**)scr
->resizebar_texture
,
866 scr
->window_title_pixel
,
867 &scr
->window_title_gc
,
870 wwin
->frame
->flags
.is_client_window_frame
= 1;
871 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
873 /* setup button images */
874 wWindowUpdateButtonImages(wwin
);
876 /* hide unused buttons */
878 if (WFLAGP(wwin
, no_close_button
))
879 foo
|= WFF_RIGHT_BUTTON
;
880 if (WFLAGP(wwin
, no_miniaturize_button
))
881 foo
|= WFF_LEFT_BUTTON
;
883 wFrameWindowHideButton(wwin
->frame
, foo
);
885 wwin
->frame
->child
= wwin
;
888 /* emulate olwm push pin. Make the button look as pushed-in for
889 * the pinned-out state. When the button is clicked, it will
890 * revert to the normal position, which means the pin is pinned-in.
892 if (wwin
->flags
.olwm_push_pin_out
)
893 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
894 #endif /* OLWM_HINTS */
896 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
900 wwin
->frame
->workspace
= workspace
;
902 wwin
->frame
->on_click_left
= windowIconifyClick
;
904 wwin
->frame
->on_click_right
= windowCloseClick
;
905 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
907 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
908 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
910 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
913 XSelectInput(dpy
, wwin
->client_win
,
914 wwin
->event_mask
& ~StructureNotifyMask
);
916 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
917 0, wwin
->frame
->top_width
);
919 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
925 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
927 /* if gravity is to the south, account for the border sizes */
929 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
933 * wWindowConfigure() will init the client window's size
934 * (wwin->client.{width,height}) and all other geometry
935 * related variables (frame_x,frame_y)
937 wWindowConfigure(wwin
, x
, y
, width
, height
);
939 /* to make sure the window receives it's new position after reparenting */
940 wWindowSynthConfigureNotify(wwin
);
943 *--------------------------------------------------
945 * Setup descriptors and save window to internal
948 *--------------------------------------------------
951 if (wwin
->main_window
!=None
) {
955 /* Leader windows do not necessary set themselves as leaders.
956 * If this is the case, point the leader of this window to
958 leader
= wWindowFor(wwin
->main_window
);
959 if (leader
&& leader
->main_window
==None
) {
960 leader
->main_window
= leader
->client_win
;
962 app
= wApplicationCreate(scr
, wwin
->main_window
);
964 app
->last_workspace
= workspace
;
967 * Do application specific stuff, like setting application
971 if (wwin
->flags
.hidden
) {
972 /* if the window was set to hidden because it was hidden
973 * in a previous incarnation and that state was restored */
974 app
->flags
.hidden
= 1;
977 if (app
->flags
.hidden
) {
978 wwin
->flags
.hidden
= 1;
983 /* setup the frame descriptor */
984 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
985 wwin
->frame
->core
->descriptor
.parent
= wwin
;
986 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
988 /* don't let windows go away if we die */
989 XAddToSaveSet(dpy
, window
);
991 XLowerWindow(dpy
, window
);
993 /* if window is in this workspace and should be mapped, then map it */
994 if (!wwin
->flags
.miniaturized
995 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
996 && !wwin
->flags
.hidden
&& !withdraw
) {
998 /* The following "if" is to avoid crashing of clients that expect
999 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1000 * after the return from this function.
1002 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1003 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1005 wClientSetState(wwin
, NormalState
, None
);
1009 /* if not auto focus, then map the window under the currently
1011 #define _WIDTH(w) (w)->frame->core->width
1012 #define _HEIGHT(w) (w)->frame->core->height
1013 if (!wPreferences
.auto_focus
&& scr
->focused_window
1014 && !scr
->flags
.startup
&& !transientOwner
1015 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1016 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1017 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1018 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1019 || wwin
->flags
.maximized
)) {
1020 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1028 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1029 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1031 * The brain damaged idiotic non-click to focus modes will
1032 * have trouble with this because:
1034 * 1. window is created and mapped by the client
1035 * 2. window is mapped by wmaker in small size
1036 * 3. window is animated to grow to normal size
1037 * 4. this function returns to normal event loop
1038 * 5. eventually, the EnterNotify event that would trigger
1039 * the window focusing (if the mouse is over that window)
1040 * will be processed by wmaker.
1041 * But since this event will be rather delayed
1042 * (step 3 has a large delay) the time when the event ocurred
1043 * and when it is processed, the client that owns that window
1044 * will reject the XSetInputFocus() for it.
1046 && (wPreferences
.focus_mode
==WKF_CLICK
1047 || wPreferences
.auto_focus
)) {
1048 DoWindowBirth(wwin
);
1054 /* setup stacking descriptor */
1055 if (transientOwner
) {
1056 /* && wPreferences.on_top_transients */
1057 if (transientOwner
) {
1058 wwin
->frame
->core
->stacking
->child_of
=
1059 transientOwner
->frame
->core
;
1062 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1066 if (!scr
->focused_window
) {
1067 /* first window on the list */
1070 scr
->focused_window
= wwin
;
1074 /* add window at beginning of focus window list */
1075 tmp
= scr
->focused_window
;
1084 wGNOMEUpdateClientStateHint(wwin
, True
);
1087 wKWMUpdateClientWorkspace(wwin
);
1088 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1094 *--------------------------------------------------
1096 * Final preparations before window is ready to go
1098 *--------------------------------------------------
1101 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1104 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1105 && !wwin
->flags
.hidden
) {
1106 if ((transientOwner
&& transientOwner
->flags
.focused
)
1107 || wPreferences
.auto_focus
)
1108 wSetFocusTo(scr
, wwin
);
1110 wWindowResetMouseGrabs(wwin
);
1112 if (!WFLAGP(wwin
, no_bind_keys
)) {
1113 wWindowSetKeyGrabs(wwin
);
1116 wGNOMEUpdateClientListHint(scr
);
1119 wwin
->flags
.kwm_managed
= 1;
1121 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1124 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1126 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1129 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1130 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1132 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1133 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1139 *--------------------------------------------------
1141 * Cleanup temporary stuff
1143 *--------------------------------------------------
1147 wWindowDeleteSavedState(win_state
);
1149 /* If the window must be withdrawed, then do it now.
1150 * Must do some optimization, 'though */
1152 wwin
->flags
.mapped
= 0;
1153 wClientSetState(wwin
, WithdrawnState
, None
);
1154 wUnmanageWindow(wwin
, True
, False
);
1166 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1167 char *title
, int x
, int y
, int width
, int height
)
1172 wwin
= wWindowCreate();
1174 wwin
->flags
.internal_window
= 1;
1176 WSETUFLAG(wwin
, omnipresent
, 1);
1177 WSETUFLAG(wwin
, no_shadeable
, 1);
1178 WSETUFLAG(wwin
, no_resizable
, 1);
1179 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1181 wwin
->focus_mode
= WFM_PASSIVE
;
1183 wwin
->client_win
= window
;
1184 wwin
->screen_ptr
= scr
;
1186 wwin
->transient_for
= owner
;
1190 wwin
->client
.width
= width
;
1191 wwin
->client
.height
= height
;
1193 wwin
->frame_x
= wwin
->client
.x
;
1194 wwin
->frame_y
= wwin
->client
.y
;
1197 foo
= WFF_RIGHT_BUTTON
;
1198 foo
|= WFF_TITLEBAR
;
1200 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1201 wwin
->frame_x
, wwin
->frame_y
,
1203 scr
->window_title_texture
,
1204 (WTexture
**)scr
->resizebar_texture
,
1205 scr
->window_title_pixel
,
1206 &scr
->window_title_gc
,
1209 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1211 wwin
->frame
->flags
.is_client_window_frame
= 1;
1212 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1214 wFrameWindowChangeTitle(wwin
->frame
, title
);
1216 /* setup button images */
1217 wWindowUpdateButtonImages(wwin
);
1220 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1222 wwin
->frame
->child
= wwin
;
1224 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1226 wwin
->frame
->on_click_right
= windowCloseClick
;
1228 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1229 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1231 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1233 wwin
->client
.y
+= wwin
->frame
->top_width
;
1234 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1235 0, wwin
->frame
->top_width
);
1237 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1238 wwin
->client
.width
, wwin
->client
.height
);
1240 /* setup the frame descriptor */
1241 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1242 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1243 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1246 XLowerWindow(dpy
, window
);
1247 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1249 /* setup stacking descriptor */
1252 wPreferences
.on_top_transients
&&
1254 wwin
->transient_for
!=None
1255 && wwin
->transient_for
!=scr
->root_win
) {
1257 tmp
= wWindowFor(wwin
->transient_for
);
1259 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1261 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1265 if (!scr
->focused_window
) {
1266 /* first window on the list */
1269 scr
->focused_window
= wwin
;
1273 /* add window at beginning of focus window list */
1274 tmp
= scr
->focused_window
;
1282 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1284 /* if (wPreferences.auto_focus)*/
1285 wSetFocusTo(scr
, wwin
);
1287 wWindowResetMouseGrabs(wwin
);
1289 wWindowSetKeyGrabs(wwin
);
1291 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1298 *----------------------------------------------------------------------
1300 * Removes the frame window from a window and destroys all data
1301 * related to it. The window will be reparented back to the root window
1302 * if restore is True.
1305 * Everything related to the window is destroyed and the window
1306 * is removed from the window lists. Focus is set to the previous on the
1308 *----------------------------------------------------------------------
1311 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1313 WCoreWindow
*frame
= wwin
->frame
->core
;
1314 WWindow
*owner
= NULL
;
1315 WWindow
*newFocusedWindow
= NULL
;
1317 WScreen
*scr
= wwin
->screen_ptr
;
1321 wwin
->frame
->workspace
= -1;
1323 wKWMUpdateClientWorkspace(wwin
);
1326 /* First close attribute editor window if open */
1327 if (wwin
->flags
.inspector_open
) {
1328 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1329 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1332 /* Close window menu if it's open for this window */
1333 if (wwin
->flags
.menu_open_for_me
) {
1334 CloseWindowMenu(scr
);
1338 if (!wwin
->flags
.internal_window
)
1339 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1341 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1343 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1344 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1347 XUnmapWindow(dpy
, frame
->window
);
1349 XUnmapWindow(dpy
, wwin
->client_win
);
1351 /* deselect window */
1352 wSelectWindow(wwin
, False
);
1354 /* remove all pending events on window */
1355 /* I think this only matters for autoraise */
1356 if (wPreferences
.raise_delay
)
1357 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1361 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1363 /* reparent the window back to the root */
1365 wClientRestore(wwin
);
1367 if (wwin
->transient_for
!=scr
->root_win
) {
1368 owner
= wWindowFor(wwin
->transient_for
);
1370 if (!owner
->flags
.semi_focused
) {
1373 owner
->flags
.semi_focused
= 0;
1378 wasFocused
= wwin
->flags
.focused
;
1380 /* remove from window focus list */
1381 if (!wwin
->prev
&& !wwin
->next
) {
1382 /* was the only window */
1383 scr
->focused_window
= NULL
;
1384 newFocusedWindow
= NULL
;
1389 wwin
->prev
->next
= wwin
->next
;
1391 wwin
->next
->prev
= wwin
->prev
;
1393 scr
->focused_window
= wwin
->prev
;
1394 scr
->focused_window
->next
= NULL
;
1397 /* if in click to focus mode and the window
1398 * was a transient, focus the owner window
1401 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1402 tmp
= wWindowFor(wwin
->transient_for
);
1403 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1407 /* otherwise, focus the next one in the focus list */
1409 tmp
= scr
->focused_window
;
1411 if (!WFLAGP(tmp
, no_focusable
)
1412 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1417 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1418 newFocusedWindow
= tmp
;
1419 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1420 || wPreferences
.focus_mode
==WKF_POINTER
) {
1425 /* This is to let the root window get the keyboard input
1426 * if Sloppy focus mode and no other window get focus.
1427 * This way keybindings will not freeze.
1430 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1431 &foo
, &foo
, &foo
, &foo
, &mask
))
1432 tmp
= wWindowFor(win
);
1435 newFocusedWindow
= tmp
;
1437 newFocusedWindow
= NULL
;
1441 if (!wwin
->flags
.internal_window
) {
1443 wGNOMERemoveClient(wwin
);
1446 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1451 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1452 (unsigned)frame
->window
);
1456 if (newFocusedWindow
!= owner
&& owner
) {
1457 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1459 wSetFocusTo(scr
, newFocusedWindow
);
1461 wWindowDestroy(wwin
);
1467 wWindowMap(WWindow
*wwin
)
1469 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1470 if (!wwin
->flags
.shaded
) {
1471 /* window will be remapped when getting MapNotify */
1472 XSelectInput(dpy
, wwin
->client_win
,
1473 wwin
->event_mask
& ~StructureNotifyMask
);
1474 XMapWindow(dpy
, wwin
->client_win
);
1475 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1477 wwin
->flags
.mapped
= 1;
1483 wWindowUnmap(WWindow
*wwin
)
1485 wwin
->flags
.mapped
= 0;
1487 /* prevent window withdrawal when getting UnmapNotify */
1488 XSelectInput(dpy
, wwin
->client_win
,
1489 wwin
->event_mask
& ~StructureNotifyMask
);
1490 XUnmapWindow(dpy
, wwin
->client_win
);
1491 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1493 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1499 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1504 #ifdef KEEP_XKB_LOCK_STATUS
1505 if (wPreferences
.modelock
) {
1506 if (!wwin
->flags
.focused
) {
1507 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1510 #endif /* KEEP_XKB_LOCK_STATUS */
1512 wwin
->flags
.semi_focused
= 0;
1514 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1516 wWindowResetMouseGrabs(wwin
);
1518 wwin
->flags
.focused
= 1;
1520 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1522 if (owin
== wwin
|| !owin
)
1525 nowner
= wWindowFor(wwin
->transient_for
);
1527 /* new window is a transient for the old window */
1528 if (nowner
== owin
) {
1529 owin
->flags
.semi_focused
= 1;
1530 wWindowUnfocus(nowner
);
1534 /* new window is owner of old window */
1535 if (wwin
== oowner
) {
1536 wWindowUnfocus(owin
);
1541 wWindowUnfocus(owin
);
1545 /* new window has same owner of old window */
1546 oowner
= wWindowFor(owin
->transient_for
);
1547 if (oowner
== nowner
) {
1548 /* prevent unfocusing of owner */
1549 oowner
->flags
.semi_focused
= 0;
1550 wWindowUnfocus(owin
);
1551 oowner
->flags
.semi_focused
= 1;
1556 /* nowner != NULL && oowner != nowner */
1557 nowner
->flags
.semi_focused
= 1;
1558 wWindowUnfocus(nowner
);
1559 wWindowUnfocus(owin
);
1564 wWindowUnfocus(WWindow
*wwin
)
1566 CloseWindowMenu(wwin
->screen_ptr
);
1568 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1569 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1571 if (wwin
->transient_for
!=None
1572 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1574 owner
= wWindowFor(wwin
->transient_for
);
1575 if (owner
&& owner
->flags
.semi_focused
) {
1576 owner
->flags
.semi_focused
= 0;
1577 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1578 wWindowUnfocus(owner
);
1579 wFrameWindowPaint(owner
->frame
);
1583 wwin
->flags
.focused
= 0;
1584 wWindowResetMouseGrabs(wwin
);
1586 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1593 *----------------------------------------------------------------------
1595 * wWindowConstrainSize--
1596 * Constrains size for the client window, taking the maximal size,
1597 * window resize increments and other size hints into account.
1600 * The closest size to what was given that the client window can
1603 *----------------------------------------------------------------------
1606 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1608 XSizeHints
*sizeh
= wwin
->normal_hints
;
1609 int width
= *nwidth
;
1610 int height
= *nheight
;
1611 int winc
= sizeh
->width_inc
;
1612 int hinc
= sizeh
->height_inc
;
1614 if (width
< sizeh
->min_width
)
1615 width
= sizeh
->min_width
;
1616 if (height
< sizeh
->min_height
)
1617 height
= sizeh
->min_height
;
1619 if (width
> sizeh
->max_width
)
1620 width
= sizeh
->max_width
;
1621 if (height
> sizeh
->max_height
)
1622 height
= sizeh
->max_height
;
1624 /* aspect ratio code borrowed from olwm */
1625 if (sizeh
->flags
& PAspect
) {
1626 /* adjust max aspect ratio */
1627 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1628 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1629 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1630 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1631 if (height
> sizeh
->max_height
) {
1632 height
= sizeh
->max_height
;
1633 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1636 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1637 if (width
> sizeh
->max_width
) {
1638 width
= sizeh
->max_width
;
1639 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1644 /* adjust min aspect ratio */
1645 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1646 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1647 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1648 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1649 if (height
< sizeh
->min_height
) {
1650 height
= sizeh
->min_height
;
1651 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1654 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1655 if (width
< sizeh
->min_width
) {
1656 width
= sizeh
->min_width
;
1657 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1663 if (sizeh
->base_width
!= 0) {
1664 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1665 + sizeh
->base_width
;
1667 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1671 if (sizeh
->base_width
!= 0) {
1672 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1673 + sizeh
->base_height
;
1675 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1676 + sizeh
->min_height
;
1685 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1687 WScreen
*scr
= wwin
->screen_ptr
;
1691 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1692 || workspace
== wwin
->frame
->workspace
)
1695 if (workspace
!= scr
->current_workspace
) {
1696 /* Sent to other workspace. Unmap window */
1697 if ((wwin
->flags
.mapped
1698 || wwin
->flags
.shaded
1699 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1700 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1702 wapp
= wApplicationOf(wwin
->main_window
);
1704 wapp
->last_workspace
= workspace
;
1706 if (wwin
->flags
.miniaturized
) {
1707 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1708 wwin
->icon
->mapped
= 0;
1711 wSetFocusTo(scr
, NULL
);
1715 /* brought to current workspace. Map window */
1716 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1717 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1718 wwin
->icon
->mapped
= 1;
1719 } else if (!wwin
->flags
.mapped
&&
1720 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1724 if (!IS_OMNIPRESENT(wwin
)) {
1725 wwin
->frame
->workspace
= workspace
;
1726 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1729 wGNOMEUpdateClientStateHint(wwin
, True
);
1732 wKWMUpdateClientWorkspace(wwin
);
1733 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1742 wWindowSynthConfigureNotify(WWindow
*wwin
)
1746 sevent
.type
= ConfigureNotify
;
1747 sevent
.xconfigure
.display
= dpy
;
1748 sevent
.xconfigure
.event
= wwin
->client_win
;
1749 sevent
.xconfigure
.window
= wwin
->client_win
;
1751 sevent
.xconfigure
.x
= wwin
->client
.x
;
1752 sevent
.xconfigure
.y
= wwin
->client
.y
;
1753 sevent
.xconfigure
.width
= wwin
->client
.width
;
1754 sevent
.xconfigure
.height
= wwin
->client
.height
;
1756 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1757 if (WFLAGP(wwin
, no_titlebar
))
1758 sevent
.xconfigure
.above
= None
;
1760 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1762 sevent
.xconfigure
.override_redirect
= False
;
1763 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1765 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1772 *----------------------------------------------------------------------
1773 * wWindowConfigure--
1774 * Configures the frame, decorations and client window to the
1775 * specified geometry. The geometry is not checked for validity,
1776 * wWindowConstrainSize() must be used for that.
1777 * The size parameters are for the client window, but the position is
1779 * The client window receives a ConfigureNotify event, according
1780 * to what ICCCM says.
1786 * Window size and position are changed and client window receives
1787 * a ConfigureNotify event.
1788 *----------------------------------------------------------------------
1791 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1793 int req_x
, req_y
; /* new position of the frame */
1794 int req_width
, req_height
; /* new size of the client */
1796 int synth_notify
= False
;
1799 resize
= (req_width
!=wwin
->client
.width
1800 || req_height
!=wwin
->client
.height
);
1802 * if the window is being moved but not resized then
1803 * send a synthetic ConfigureNotify
1805 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1806 synth_notify
= True
;
1809 if (WFLAGP(wwin
, dont_move_off
))
1810 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1811 req_width
, req_height
);
1813 if (req_width
< MIN_WINDOW_SIZE
)
1814 req_width
= MIN_WINDOW_SIZE
;
1815 if (req_height
< MIN_WINDOW_SIZE
)
1816 req_height
= MIN_WINDOW_SIZE
;
1818 /* If growing, resize inner part before frame,
1819 * if shrinking, resize frame before.
1820 * This will prevent the frame (that can have a different color)
1821 * to be exposed, causing flicker */
1822 if (req_height
> wwin
->frame
->core
->height
1823 || req_width
> wwin
->frame
->core
->width
)
1824 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1826 if (wwin
->flags
.shaded
) {
1827 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1828 req_width
, wwin
->frame
->core
->height
);
1829 wwin
->old_geometry
.height
= req_height
;
1833 h
= req_height
+ wwin
->frame
->top_width
1834 + wwin
->frame
->bottom_width
;
1836 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1839 if (!(req_height
> wwin
->frame
->core
->height
1840 || req_width
> wwin
->frame
->core
->width
))
1841 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1843 wwin
->client
.x
= req_x
;
1844 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1845 wwin
->client
.width
= req_width
;
1846 wwin
->client
.height
= req_height
;
1848 wwin
->client
.x
= req_x
;
1849 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1851 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1853 wwin
->frame_x
= req_x
;
1854 wwin
->frame_y
= req_y
;
1857 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1858 wWindowSetShape(wwin
);
1863 wWindowSynthConfigureNotify(wwin
);
1869 wWindowMove(wwin
, req_x
, req_y
)
1871 int req_x
, req_y
; /* new position of the frame */
1873 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1874 int synth_notify
= False
;
1876 /* Send a synthetic ConfigureNotify event for every window movement. */
1877 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1878 synth_notify
= True
;
1881 /* A single synthetic ConfigureNotify event is sent at the end of
1882 * a completed (opaque) movement in moveres.c */
1885 if (WFLAGP(wwin
, dont_move_off
))
1886 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1887 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1889 wwin
->client
.x
= req_x
;
1890 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1892 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1894 wwin
->frame_x
= req_x
;
1895 wwin
->frame_y
= req_y
;
1897 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1899 wWindowSynthConfigureNotify(wwin
);
1905 wWindowUpdateButtonImages(WWindow
*wwin
)
1907 WScreen
*scr
= wwin
->screen_ptr
;
1908 Pixmap pixmap
, mask
;
1909 WFrameWindow
*fwin
= wwin
->frame
;
1911 if (WFLAGP(wwin
, no_titlebar
))
1914 /* miniaturize button */
1916 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
1917 if (wwin
->wm_gnustep_attr
1918 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1919 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1921 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1922 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1927 if (fwin
->lbutton_image
1928 && (fwin
->lbutton_image
->image
!= pixmap
1929 || fwin
->lbutton_image
->mask
!= mask
)) {
1930 wPixmapDestroy(fwin
->lbutton_image
);
1931 fwin
->lbutton_image
= NULL
;
1934 if (!fwin
->lbutton_image
) {
1935 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1936 fwin
->lbutton_image
->client_owned
= 1;
1937 fwin
->lbutton_image
->client_owned_mask
= 1;
1940 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
1941 wPixmapDestroy(fwin
->lbutton_image
);
1943 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
1949 if (!WFLAGP(wwin
, no_close_button
)) {
1950 if (wwin
->wm_gnustep_attr
1951 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
1952 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
1954 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
1955 mask
= wwin
->wm_gnustep_attr
->close_mask
;
1960 if (fwin
->rbutton_image
1961 && (fwin
->rbutton_image
->image
!= pixmap
1962 || fwin
->rbutton_image
->mask
!= mask
)) {
1963 wPixmapDestroy(fwin
->rbutton_image
);
1964 fwin
->rbutton_image
= NULL
;
1967 if (!fwin
->rbutton_image
) {
1968 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1969 fwin
->rbutton_image
->client_owned
= 1;
1970 fwin
->rbutton_image
->client_owned_mask
= 1;
1972 } else if (WFLAGP(wwin
, kill_close
)) {
1973 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1974 wPixmapDestroy(fwin
->rbutton_image
);
1976 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
1977 } else if (WFLAGP(wwin
, broken_close
)) {
1978 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1979 wPixmapDestroy(fwin
->rbutton_image
);
1981 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
1983 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1984 wPixmapDestroy(fwin
->rbutton_image
);
1986 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
1990 /* force buttons to be redrawn */
1991 fwin
->flags
.need_texture_change
= 1;
1992 wFrameWindowPaint(fwin
);
1997 *---------------------------------------------------------------------------
1998 * wWindowConfigureBorders--
1999 * Update window border configuration according to attribute flags.
2001 *---------------------------------------------------------------------------
2004 wWindowConfigureBorders(WWindow
*wwin
)
2010 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2011 if (!WFLAGP(wwin
, no_titlebar
))
2012 flags
|= WFF_TITLEBAR
;
2013 if (!WFLAGP(wwin
, no_resizebar
))
2014 flags
|= WFF_RESIZEBAR
;
2015 if (wwin
->flags
.shaded
)
2016 flags
|= WFF_IS_SHADED
;
2018 oldh
= wwin
->frame
->top_width
;
2019 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2020 if (oldh
!= wwin
->frame
->top_width
) {
2021 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2023 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2024 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2025 wwin
->client
.width
, wwin
->client
.height
);
2029 if (!WFLAGP(wwin
, no_miniaturize_button
)
2030 && wwin
->frame
->flags
.hide_left_button
)
2031 flags
|= WFF_LEFT_BUTTON
;
2033 if (!WFLAGP(wwin
, no_close_button
)
2034 && wwin
->frame
->flags
.hide_right_button
)
2035 flags
|= WFF_RIGHT_BUTTON
;
2038 wWindowUpdateButtonImages(wwin
);
2039 wFrameWindowShowButton(wwin
->frame
, flags
);
2043 if (WFLAGP(wwin
, no_miniaturize_button
)
2044 && !wwin
->frame
->flags
.hide_left_button
)
2045 flags
|= WFF_LEFT_BUTTON
;
2047 if (WFLAGP(wwin
, no_close_button
)
2048 && !wwin
->frame
->flags
.hide_right_button
)
2049 flags
|= WFF_RIGHT_BUTTON
;
2052 wFrameWindowHideButton(wwin
->frame
, flags
);
2055 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2056 wWindowSetShape(wwin
);
2064 wWindowSaveState(WWindow
*wwin
)
2069 memset(data
, 0, sizeof(CARD32
)*10);
2070 data
[0] = wwin
->frame
->workspace
;
2071 data
[1] = wwin
->flags
.miniaturized
;
2072 data
[2] = wwin
->flags
.shaded
;
2073 data
[3] = wwin
->flags
.hidden
;
2075 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2076 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
)
2079 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2080 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2081 (unsigned char *)data
, 10);
2086 getSavedState(Window window
, WSavedState
**state
)
2090 unsigned long nitems_ret
;
2091 unsigned long bytes_after_ret
;
2094 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2095 True
, _XA_WINDOWMAKER_STATE
,
2096 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2097 (unsigned char **)&data
)!=Success
|| !data
)
2100 *state
= malloc(sizeof(WSavedState
));
2103 (*state
)->workspace
= data
[0];
2104 (*state
)->miniaturized
= data
[1];
2105 (*state
)->shaded
= data
[2];
2106 (*state
)->hidden
= data
[3];
2107 (*state
)->use_geometry
= data
[4];
2108 (*state
)->x
= data
[5];
2109 (*state
)->y
= data
[6];
2110 (*state
)->w
= data
[7];
2111 (*state
)->h
= data
[8];
2112 (*state
)->window_shortcuts
= data
[9];
2116 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2125 wWindowClearShape(WWindow
*wwin
)
2127 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2128 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2133 wWindowSetShape(WWindow
*wwin
)
2137 #ifdef OPTIMIZE_SHAPE
2142 /* only shape is the client's */
2143 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2147 /* Get array of rectangles describing the shape mask */
2148 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2154 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2160 /* insert our decoration rectangles in the rect list */
2161 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2164 if (!WFLAGP(wwin
, no_titlebar
)) {
2166 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2167 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2168 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2171 if (!WFLAGP(wwin
, no_resizebar
)) {
2173 urec
[count
].y
= wwin
->frame
->core
->height
2174 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2175 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2176 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2180 /* shape our frame window */
2181 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2182 0, wwin
->frame
->top_width
, urec
, count
,
2183 ShapeSet
, Unsorted
);
2189 #endif /* OPTIMIZE_SHAPE */
2191 if (!WFLAGP(wwin
, no_titlebar
)) {
2194 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2195 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2198 if (!WFLAGP(wwin
, no_resizebar
)) {
2200 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2201 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2202 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2206 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2207 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2209 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2210 0, wwin
->frame
->top_width
, wwin
->client_win
,
2211 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2216 /* ====================================================================== */
2219 getFocusMode(WWindow
*wwin
)
2223 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2224 if (wwin
->wm_hints
->input
== True
) {
2225 if (wwin
->protocols
.TAKE_FOCUS
)
2226 mode
= WFM_LOCALLY_ACTIVE
;
2230 if (wwin
->protocols
.TAKE_FOCUS
)
2231 mode
= WFM_GLOBALLY_ACTIVE
;
2233 mode
= WFM_NO_INPUT
;
2243 wWindowSetKeyGrabs(WWindow
*wwin
)
2248 for (i
=0; i
<WKBD_LAST
; i
++) {
2249 key
= &wKeyBindings
[i
];
2251 if (key
->keycode
==0)
2253 if (key
->modifier
!=AnyModifier
) {
2254 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2255 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2257 /* Also grab all modifier combinations possible that include,
2258 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2259 * work even if the NumLock/ScrollLock key is on.
2261 wHackedGrabKey(key
->keycode
, key
->modifier
,
2262 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2266 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2267 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2271 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2278 wWindowResetMouseGrabs(WWindow
*wwin
)
2280 /* Mouse grabs can't be done on the client window because of
2281 * ICCCM and because clients that try to do the same will crash.
2283 * But there is a problem wich makes tbar buttons of unfocused
2284 * windows not usable as the click goes to the frame window instead
2285 * of the button itself. Must figure a way to fix that.
2288 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2290 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2291 /* grabs for Meta+drag */
2292 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2293 True
, ButtonPressMask
, GrabModeSync
,
2294 GrabModeAsync
, None
, None
);
2297 if (!wwin
->flags
.focused
) {
2298 /* the passive grabs to focus the window */
2299 if (wPreferences
.focus_mode
== WKF_CLICK
)
2300 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2301 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2309 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2312 if (attr
->flags
& GSExtraFlagsAttr
) {
2313 if (WFLAGP(wwin
, broken_close
) !=
2314 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2316 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2318 wWindowUpdateButtonImages(wwin
);
2326 wWindowAddSavedState(char *instance
, char *class, char *command
,
2327 pid_t pid
, WSavedState
*state
)
2329 WWindowState
*wstate
;
2331 wstate
= malloc(sizeof(WWindowState
));
2335 memset(wstate
, 0, sizeof(WWindowState
));
2338 wstate
->instance
= wstrdup(instance
);
2340 wstate
->class = wstrdup(class);
2342 wstate
->command
= wstrdup(command
);
2343 wstate
->state
= state
;
2345 wstate
->next
= windowState
;
2346 windowState
= wstate
;
2349 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2357 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2361 wWindowGetSavedState(Window win
)
2363 char *instance
, *class, *command
=NULL
;
2364 WWindowState
*wstate
= windowState
;
2371 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2373 command
= FlattenStringList(argv
, argc
);
2374 XFreeStringList(argv
);
2379 if (PropGetWMClass(win
, &class, &instance
)) {
2381 if (SAME(instance
, wstate
->instance
) &&
2382 SAME(class, wstate
->class) &&
2383 SAME(command
, wstate
->command
)) {
2386 wstate
= wstate
->next
;
2393 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2397 if (command
) free(command
);
2398 if (instance
) XFree(instance
);
2399 if (class) XFree(class);
2406 wWindowDeleteSavedState(WMagicNumber id
)
2408 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2410 if (!wstate
|| !windowState
)
2415 windowState
= wstate
->next
;
2417 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2418 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2420 if (wstate
->instance
) free(wstate
->instance
);
2421 if (wstate
->class) free(wstate
->class);
2422 if (wstate
->command
) free(wstate
->command
);
2423 free(wstate
->state
);
2427 if (tmp
->next
==wstate
) {
2428 tmp
->next
=wstate
->next
;
2430 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2431 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2433 if (wstate
->instance
) free(wstate
->instance
);
2434 if (wstate
->class) free(wstate
->class);
2435 if (wstate
->command
) free(wstate
->command
);
2436 free(wstate
->state
);
2447 wWindowDeleteSavedStatesForPID(pid_t pid
)
2449 WWindowState
*tmp
, *wstate
;
2455 if (tmp
->pid
== pid
) {
2456 wstate
= windowState
;
2457 windowState
= tmp
->next
;
2459 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2460 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2462 if (wstate
->instance
) free(wstate
->instance
);
2463 if (wstate
->class) free(wstate
->class);
2464 if (wstate
->command
) free(wstate
->command
);
2465 free(wstate
->state
);
2469 if (tmp
->next
->pid
==pid
) {
2471 tmp
->next
= wstate
->next
;
2473 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2474 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2476 if (wstate
->instance
) free(wstate
->instance
);
2477 if (wstate
->class) free(wstate
->class);
2478 if (wstate
->command
) free(wstate
->command
);
2479 free(wstate
->state
);
2489 /* ====================================================================== */
2492 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2494 WWindow
*wwin
= data
;
2496 #ifndef NUMLOCK_HACK
2497 if ((event
->xbutton
.state
& ValidModMask
)
2498 != (event
->xbutton
.state
& ~LockMask
)) {
2499 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2500 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2504 event
->xbutton
.state
&= ValidModMask
;
2506 CloseWindowMenu(wwin
->screen_ptr
);
2508 if (wPreferences
.focus_mode
==WKF_CLICK
2509 && !(event
->xbutton
.state
&ControlMask
)) {
2510 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2513 if (event
->xbutton
.button
== Button1
)
2514 wRaiseFrame(wwin
->frame
->core
);
2516 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2517 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2518 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2519 GrabModeAsync
, GrabModeAsync
, None
,
2520 None
, CurrentTime
)!=GrabSuccess
) {
2522 wwarning("pointer grab failed for window move");
2528 if (event
->xbutton
.state
& MOD_MASK
) {
2529 /* move the window */
2530 wMouseMoveWindow(wwin
, event
);
2531 XUngrabPointer(dpy
, CurrentTime
);
2533 wMouseResizeWindow(wwin
, event
);
2534 XUngrabPointer(dpy
, CurrentTime
);
2541 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2543 WWindow
*wwin
= data
;
2545 event
->xbutton
.state
&= ValidModMask
;
2547 if (event
->xbutton
.button
==Button1
) {
2548 if (event
->xbutton
.state
== 0) {
2549 if (!WFLAGP(wwin
, no_shadeable
)) {
2551 if (wwin
->flags
.shaded
)
2552 wUnshadeWindow(wwin
);
2559 if (event
->xbutton
.state
& ControlMask
)
2560 dir
|= MAX_VERTICAL
;
2562 if (event
->xbutton
.state
& ShiftMask
) {
2563 dir
|= MAX_HORIZONTAL
;
2564 if (!(event
->xbutton
.state
& ControlMask
))
2565 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2568 /* maximize window */
2569 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2570 if (wwin
->flags
.maximized
)
2571 wUnmaximizeWindow(wwin
);
2573 wMaximizeWindow(wwin
, dir
);
2576 } else if (event
->xbutton
.button
==Button3
) {
2577 if (event
->xbutton
.state
& MOD_MASK
) {
2578 wHideOtherApplications(wwin
);
2580 } else if (event
->xbutton
.button
==Button2
) {
2581 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2587 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2589 WWindow
*wwin
= desc
->parent
;
2591 event
->xbutton
.state
&= ValidModMask
;
2593 CloseWindowMenu(wwin
->screen_ptr
);
2595 if (wPreferences
.focus_mode
==WKF_CLICK
2596 && !(event
->xbutton
.state
&ControlMask
)) {
2597 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2599 if (event
->xbutton
.button
== Button1
) {
2600 wRaiseFrame(wwin
->frame
->core
);
2603 if (event
->xbutton
.state
& MOD_MASK
) {
2604 /* move the window */
2605 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2606 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2607 GrabModeAsync
, GrabModeAsync
, None
,
2608 None
, CurrentTime
)!=GrabSuccess
) {
2610 wwarning("pointer grab failed for window move");
2614 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2615 wMouseResizeWindow(wwin
, event
);
2617 wMouseMoveWindow(wwin
, event
);
2618 XUngrabPointer(dpy
, CurrentTime
);
2624 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2626 WWindow
*wwin
= (WWindow
*)data
;
2628 #ifndef NUMLOCK_HACK
2629 if ((event
->xbutton
.state
& ValidModMask
)
2630 != (event
->xbutton
.state
& ~LockMask
)) {
2631 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2632 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2635 event
->xbutton
.state
&= ValidModMask
;
2637 CloseWindowMenu(wwin
->screen_ptr
);
2639 if (wPreferences
.focus_mode
==WKF_CLICK
2640 && !(event
->xbutton
.state
&ControlMask
)) {
2641 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2644 if (event
->xbutton
.button
== Button1
2645 || event
->xbutton
.button
== Button2
) {
2647 if (event
->xbutton
.button
== Button1
) {
2648 if (event
->xbutton
.state
& MOD_MASK
) {
2649 wLowerFrame(wwin
->frame
->core
);
2651 wRaiseFrame(wwin
->frame
->core
);
2654 if ((event
->xbutton
.state
& ShiftMask
)
2655 && !(event
->xbutton
.state
& ControlMask
)) {
2656 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2659 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2660 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2661 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2662 GrabModeAsync
, GrabModeAsync
, None
,
2663 None
, CurrentTime
)!=GrabSuccess
) {
2665 wwarning("pointer grab failed for window move");
2670 /* move the window */
2671 wMouseMoveWindow(wwin
, event
);
2673 XUngrabPointer(dpy
, CurrentTime
);
2674 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2675 && !wwin
->flags
.internal_window
2676 && !WCHECK_STATE(WSTATE_MODAL
)) {
2677 WObjDescriptor
*desc
;
2679 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2680 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2681 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2682 GrabModeAsync
, GrabModeAsync
, None
,
2683 None
, CurrentTime
)!=GrabSuccess
) {
2685 wwarning("pointer grab failed for window move");
2690 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2691 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2693 /* allow drag select */
2694 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2695 event
->xany
.send_event
= True
;
2696 (*desc
->handle_mousedown
)(desc
, event
);
2698 XUngrabPointer(dpy
, CurrentTime
);
2705 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2707 WWindow
*wwin
= data
;
2709 event
->xbutton
.state
&= ValidModMask
;
2711 CloseWindowMenu(wwin
->screen_ptr
);
2713 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2716 /* if control-click, kill the client */
2717 if (event
->xbutton
.state
& ControlMask
) {
2721 if (wwin
->flags
.olwm_push_pin_out
) {
2723 wwin
->flags
.olwm_push_pin_out
= 0;
2725 wOLWMChangePushpinState(wwin
, True
);
2727 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2732 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2733 /* send delete message */
2734 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2741 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2743 WWindow
*wwin
= data
;
2745 CloseWindowMenu(wwin
->screen_ptr
);
2747 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2750 /* send delete message */
2751 if (wwin
->protocols
.DELETE_WINDOW
) {
2752 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2760 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2762 WWindow
*wwin
= data
;
2764 event
->xbutton
.state
&= ValidModMask
;
2766 CloseWindowMenu(wwin
->screen_ptr
);
2768 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2771 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2772 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2776 if ((event
->xbutton
.state
& ControlMask
) ||
2777 (event
->xbutton
.button
== Button3
)) {
2779 wapp
= wApplicationOf(wwin
->main_window
);
2780 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2781 wHideApplication(wapp
);
2782 } else if (event
->xbutton
.state
==0) {
2783 wIconifyWindow(wwin
);