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_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
)
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
;
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
;
768 /* don't let transients start miniaturized if their owners are not */
769 if (transientOwner
&& !transientOwner
->flags
.miniaturized
770 && wwin
->flags
.miniaturized
&& !withdraw
) {
771 wwin
->flags
.miniaturized
= 0;
773 wwin
->wm_hints
->initial_state
= NormalState
;
776 /* set workspace on which the window starts */
777 if (workspace
>= 0) {
778 if (workspace
> scr
->workspace_count
-1) {
779 workspace
= workspace
% scr
->workspace_count
;
784 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
786 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
791 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
793 workspace
= transientOwner
->frame
->workspace
;
797 workspace
= scr
->current_workspace
;
802 /* setup window geometry */
803 if (win_state
&& win_state
->state
->use_geometry
) {
804 width
= win_state
->state
->w
;
805 height
= win_state
->state
->h
;
807 wWindowConstrainSize(wwin
, &width
, &height
);
809 /* do not ask for window placement if the window is
810 * transient, during startup, if the initial workspace is another one
811 * or if the window wants to start iconic.
812 * If geometry was saved, restore it. */
814 Bool dontBring
= False
;
816 if (win_state
&& win_state
->state
->use_geometry
) {
817 x
= win_state
->state
->x
;
818 y
= win_state
->state
->y
;
819 } else if (wwin
->transient_for
==None
&& !scr
->flags
.startup
820 && workspace
== scr
->current_workspace
821 && !wwin
->flags
.miniaturized
822 && !wwin
->flags
.maximized
823 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
824 PlaceWindow(wwin
, &x
, &y
, width
, height
);
825 if (wPreferences
.window_placement
== WPM_MANUAL
)
829 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
830 wScreenBringInside(scr
, &x
, &y
, width
, height
);
833 if (wwin
->flags
.urgent
) {
834 if (!IS_OMNIPRESENT(wwin
))
835 wwin
->flags
.omnipresent
^= 1;
839 *--------------------------------------------------
841 * Create frame, borders and do reparenting
843 *--------------------------------------------------
845 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
846 if (!WFLAGP(wwin
, no_titlebar
))
848 if (!WFLAGP(wwin
, no_resizebar
))
849 foo
|= WFF_RESIZEBAR
;
851 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
852 x
, y
, width
, height
, foo
,
853 scr
->window_title_texture
,
854 (WTexture
**)scr
->resizebar_texture
,
855 scr
->window_title_pixel
,
856 &scr
->window_title_gc
,
859 wwin
->frame
->flags
.is_client_window_frame
= 1;
860 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
862 /* setup button images */
863 wWindowUpdateButtonImages(wwin
);
865 /* hide unused buttons */
867 if (WFLAGP(wwin
, no_close_button
))
868 foo
|= WFF_RIGHT_BUTTON
;
869 if (WFLAGP(wwin
, no_miniaturize_button
))
870 foo
|= WFF_LEFT_BUTTON
;
872 wFrameWindowHideButton(wwin
->frame
, foo
);
874 wwin
->frame
->child
= wwin
;
877 /* emulate olwm push pin. Make the button look as pushed-in for
878 * the pinned-out state. When the button is clicked, it will
879 * revert to the normal position, which means the pin is pinned-in.
881 if (wwin
->flags
.olwm_push_pin_out
)
882 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
883 #endif /* OLWM_HINTS */
885 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
889 wwin
->frame
->workspace
= workspace
;
891 wwin
->frame
->on_click_left
= windowIconifyClick
;
893 wwin
->frame
->on_click_right
= windowCloseClick
;
894 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
896 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
897 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
899 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
902 XSelectInput(dpy
, wwin
->client_win
,
903 wwin
->event_mask
& ~StructureNotifyMask
);
905 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
906 0, wwin
->frame
->top_width
);
908 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
914 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
916 /* if gravity is to the south, account for the border sizes */
918 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
921 * wWindowConfigure() will init the client window's size
922 * (wwin->client.{width,height}) and all other geometry
923 * related variables (frame_x,frame_y)
925 wWindowConfigure(wwin
, x
, y
, width
, height
);
927 /* to make sure the window receives it's new position after reparenting */
928 wWindowSynthConfigureNotify(wwin
);
931 *--------------------------------------------------
933 * Setup descriptors and save window to internal
936 *--------------------------------------------------
939 if (wwin
->main_window
!=None
) {
943 /* Leader windows do not necessary set themselves as leaders.
944 * If this is the case, point the leader of this window to
946 leader
= wWindowFor(wwin
->main_window
);
947 if (leader
&& leader
->main_window
==None
) {
948 leader
->main_window
= leader
->client_win
;
950 app
= wApplicationCreate(scr
, wwin
->main_window
);
952 app
->last_workspace
= workspace
;
955 * Do application specific stuff, like setting application
959 if (wwin
->flags
.hidden
) {
960 /* if the window was set to hidden because it was hidden
961 * in a previous incarnation and that state was restored */
962 app
->flags
.hidden
= 1;
965 if (app
->flags
.hidden
) {
966 wwin
->flags
.hidden
= 1;
971 /* setup the frame descriptor */
972 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
973 wwin
->frame
->core
->descriptor
.parent
= wwin
;
974 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
976 /* don't let windows go away if we die */
977 XAddToSaveSet(dpy
, window
);
979 XLowerWindow(dpy
, window
);
981 /* if window is in this workspace and should be mapped, then map it */
982 if (!wwin
->flags
.miniaturized
983 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
984 && !wwin
->flags
.hidden
&& !withdraw
) {
986 /* The following "if" is to avoid crashing of clients that expect
987 * WM_STATE set before they get mapped. Else WM_STATE is set later,
988 * after the return from this function.
990 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
991 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
993 wClientSetState(wwin
, NormalState
, None
);
996 /* if not auto focus, then map the window under the currently
998 #define _WIDTH(w) (w)->frame->core->width
999 #define _HEIGHT(w) (w)->frame->core->height
1000 if (!wPreferences
.auto_focus
&& scr
->focused_window
1001 && !scr
->flags
.startup
&& !transientOwner
1002 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1003 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1004 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1005 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1006 || wwin
->flags
.maximized
)) {
1007 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1013 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1014 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1016 * The brain damaged idiotic non-click to focus modes will
1017 * have trouble with this because:
1019 * 1. window is created and mapped by the client
1020 * 2. window is mapped by wmaker in small size
1021 * 3. window is animated to grow to normal size
1022 * 4. this function returns to normal event loop
1023 * 5. eventually, the EnterNotify event that would trigger
1024 * the window focusing (if the mouse is over that window)
1025 * will be processed by wmaker.
1026 * But since this event will be rather delayed
1027 * (step 3 has a large delay) the time when the event ocurred
1028 * and when it is processed, the client that owns that window
1029 * will reject the XSetInputFocus() for it.
1031 && (wPreferences
.focus_mode
==WKF_CLICK
1032 || wPreferences
.auto_focus
)) {
1033 DoWindowBirth(wwin
);
1039 /* setup stacking descriptor */
1040 if (transientOwner
) {
1041 /* && wPreferences.on_top_transients */
1042 if (transientOwner
) {
1043 wwin
->frame
->core
->stacking
->child_of
=
1044 transientOwner
->frame
->core
;
1047 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1051 if (!scr
->focused_window
) {
1052 /* first window on the list */
1055 scr
->focused_window
= wwin
;
1059 /* add window at beginning of focus window list */
1060 tmp
= scr
->focused_window
;
1069 wGNOMEUpdateClientStateHint(wwin
, True
);
1072 wKWMUpdateClientWorkspace(wwin
);
1073 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1079 *--------------------------------------------------
1081 * Final preparations before window is ready to go
1083 *--------------------------------------------------
1086 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1089 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1090 && !wwin
->flags
.hidden
) {
1091 if ((transientOwner
&& transientOwner
->flags
.focused
)
1092 || wPreferences
.auto_focus
)
1093 wSetFocusTo(scr
, wwin
);
1095 wWindowResetMouseGrabs(wwin
);
1097 if (!WFLAGP(wwin
, no_bind_keys
)) {
1098 wWindowSetKeyGrabs(wwin
);
1101 wGNOMEUpdateClientListHint(scr
);
1104 wwin
->flags
.kwm_managed
= 1;
1106 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1109 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1111 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1114 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1115 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1117 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1118 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1124 *--------------------------------------------------
1126 * Cleanup temporary stuff
1128 *--------------------------------------------------
1132 wWindowDeleteSavedState(win_state
);
1134 /* If the window must be withdrawed, then do it now.
1135 * Must do some optimization, 'though */
1137 wwin
->flags
.mapped
= 0;
1138 wClientSetState(wwin
, WithdrawnState
, None
);
1139 wUnmanageWindow(wwin
, True
, False
);
1151 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1152 char *title
, int x
, int y
, int width
, int height
)
1157 wwin
= wWindowCreate();
1159 wwin
->flags
.internal_window
= 1;
1161 WSETUFLAG(wwin
, omnipresent
, 1);
1162 WSETUFLAG(wwin
, no_shadeable
, 1);
1163 WSETUFLAG(wwin
, no_resizable
, 1);
1164 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1166 wwin
->focus_mode
= WFM_PASSIVE
;
1168 wwin
->client_win
= window
;
1169 wwin
->screen_ptr
= scr
;
1171 wwin
->transient_for
= owner
;
1175 wwin
->client
.width
= width
;
1176 wwin
->client
.height
= height
;
1178 wwin
->frame_x
= wwin
->client
.x
;
1179 wwin
->frame_y
= wwin
->client
.y
;
1182 foo
= WFF_RIGHT_BUTTON
;
1183 foo
|= WFF_TITLEBAR
;
1185 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1186 wwin
->frame_x
, wwin
->frame_y
,
1188 scr
->window_title_texture
,
1189 (WTexture
**)scr
->resizebar_texture
,
1190 scr
->window_title_pixel
,
1191 &scr
->window_title_gc
,
1194 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1196 wwin
->frame
->flags
.is_client_window_frame
= 1;
1197 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1199 wFrameWindowChangeTitle(wwin
->frame
, title
);
1201 /* setup button images */
1202 wWindowUpdateButtonImages(wwin
);
1205 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1207 wwin
->frame
->child
= wwin
;
1209 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1211 wwin
->frame
->on_click_right
= windowCloseClick
;
1213 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1214 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1216 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1218 wwin
->client
.y
+= wwin
->frame
->top_width
;
1219 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1220 0, wwin
->frame
->top_width
);
1222 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1223 wwin
->client
.width
, wwin
->client
.height
);
1225 /* setup the frame descriptor */
1226 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1227 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1228 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1231 XLowerWindow(dpy
, window
);
1232 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1234 /* setup stacking descriptor */
1237 wPreferences
.on_top_transients
&&
1239 wwin
->transient_for
!=None
1240 && wwin
->transient_for
!=scr
->root_win
) {
1242 tmp
= wWindowFor(wwin
->transient_for
);
1244 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1246 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1250 if (!scr
->focused_window
) {
1251 /* first window on the list */
1254 scr
->focused_window
= wwin
;
1258 /* add window at beginning of focus window list */
1259 tmp
= scr
->focused_window
;
1267 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1269 /* if (wPreferences.auto_focus)*/
1270 wSetFocusTo(scr
, wwin
);
1272 wWindowResetMouseGrabs(wwin
);
1274 wWindowSetKeyGrabs(wwin
);
1276 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1283 *----------------------------------------------------------------------
1285 * Removes the frame window from a window and destroys all data
1286 * related to it. The window will be reparented back to the root window
1287 * if restore is True.
1290 * Everything related to the window is destroyed and the window
1291 * is removed from the window lists. Focus is set to the previous on the
1293 *----------------------------------------------------------------------
1296 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1298 WCoreWindow
*frame
= wwin
->frame
->core
;
1299 WWindow
*owner
= NULL
;
1300 WWindow
*newFocusedWindow
= NULL
;
1302 WScreen
*scr
= wwin
->screen_ptr
;
1306 wwin
->frame
->workspace
= -1;
1308 wKWMUpdateClientWorkspace(wwin
);
1311 /* First close attribute editor window if open */
1312 if (wwin
->flags
.inspector_open
) {
1313 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1314 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1317 /* Close window menu if it's open for this window */
1318 if (wwin
->flags
.menu_open_for_me
) {
1319 CloseWindowMenu(scr
);
1323 if (!wwin
->flags
.internal_window
)
1324 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1326 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1328 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1329 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1332 XUnmapWindow(dpy
, frame
->window
);
1334 /* deselect window */
1335 wSelectWindow(wwin
, False
);
1337 /* remove all pending events on window */
1338 /* I think this only matters for autoraise */
1339 if (wPreferences
.raise_delay
)
1340 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1344 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1346 /* reparent the window back to the root */
1348 wClientRestore(wwin
);
1350 if (wwin
->transient_for
!=scr
->root_win
) {
1351 owner
= wWindowFor(wwin
->transient_for
);
1353 if (!owner
->flags
.semi_focused
) {
1356 owner
->flags
.semi_focused
= 0;
1361 wasFocused
= wwin
->flags
.focused
;
1363 /* remove from window focus list */
1364 if (!wwin
->prev
&& !wwin
->next
) {
1365 /* was the only window */
1366 scr
->focused_window
= NULL
;
1367 newFocusedWindow
= NULL
;
1372 wwin
->prev
->next
= wwin
->next
;
1374 wwin
->next
->prev
= wwin
->prev
;
1376 scr
->focused_window
= wwin
->prev
;
1377 scr
->focused_window
->next
= NULL
;
1380 /* if in click to focus mode and the window
1381 * was a transient, focus the owner window
1384 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1385 tmp
= wWindowFor(wwin
->transient_for
);
1386 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1390 /* otherwise, focus the next one in the focus list */
1392 tmp
= scr
->focused_window
;
1394 if (!WFLAGP(tmp
, no_focusable
)
1395 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1400 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1401 newFocusedWindow
= tmp
;
1402 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1403 || wPreferences
.focus_mode
==WKF_POINTER
) {
1408 /* This is to let the root window get the keyboard input
1409 * if Sloppy focus mode and no other window get focus.
1410 * This way keybindings will not freeze.
1413 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1414 &foo
, &foo
, &foo
, &foo
, &mask
))
1415 tmp
= wWindowFor(win
);
1418 newFocusedWindow
= tmp
;
1420 newFocusedWindow
= NULL
;
1424 if (!wwin
->flags
.internal_window
) {
1426 wGNOMERemoveClient(wwin
);
1429 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1434 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1435 (unsigned)frame
->window
);
1439 if (newFocusedWindow
!= owner
&& owner
) {
1440 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1442 wSetFocusTo(scr
, newFocusedWindow
);
1444 wWindowDestroy(wwin
);
1450 wWindowMap(WWindow
*wwin
)
1452 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1453 if (!wwin
->flags
.shaded
) {
1454 /* window will be remapped when getting MapNotify */
1455 XSelectInput(dpy
, wwin
->client_win
,
1456 wwin
->event_mask
& ~StructureNotifyMask
);
1457 XMapWindow(dpy
, wwin
->client_win
);
1458 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1460 wwin
->flags
.mapped
= 1;
1466 wWindowUnmap(WWindow
*wwin
)
1468 wwin
->flags
.mapped
= 0;
1470 /* prevent window withdrawal when getting UnmapNotify */
1471 XSelectInput(dpy
, wwin
->client_win
,
1472 wwin
->event_mask
& ~StructureNotifyMask
);
1473 XUnmapWindow(dpy
, wwin
->client_win
);
1474 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1476 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1482 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1487 #ifdef KEEP_XKB_LOCK_STATUS
1488 if (wPreferences
.modelock
) {
1489 if (!wwin
->flags
.focused
) {
1490 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->languagemode
);
1493 #endif /* KEEP_XKB_LOCK_STATUS */
1495 wwin
->flags
.semi_focused
= 0;
1497 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1499 wWindowResetMouseGrabs(wwin
);
1501 wwin
->flags
.focused
= 1;
1503 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1505 if (owin
== wwin
|| !owin
)
1508 nowner
= wWindowFor(wwin
->transient_for
);
1510 /* new window is a transient for the old window */
1511 if (nowner
== owin
) {
1512 owin
->flags
.semi_focused
= 1;
1513 wWindowUnfocus(nowner
);
1517 /* new window is owner of old window */
1518 if (wwin
== oowner
) {
1519 wWindowUnfocus(owin
);
1524 wWindowUnfocus(owin
);
1528 /* new window has same owner of old window */
1529 oowner
= wWindowFor(owin
->transient_for
);
1530 if (oowner
== nowner
) {
1531 /* prevent unfocusing of owner */
1532 oowner
->flags
.semi_focused
= 0;
1533 wWindowUnfocus(owin
);
1534 oowner
->flags
.semi_focused
= 1;
1539 /* nowner != NULL && oowner != nowner */
1540 nowner
->flags
.semi_focused
= 1;
1541 wWindowUnfocus(nowner
);
1542 wWindowUnfocus(owin
);
1547 wWindowUnfocus(WWindow
*wwin
)
1549 #ifdef KEEP_XKB_LOCK_STATUS
1550 static XkbStateRec staterec
;
1551 if (wPreferences
.modelock
) {
1552 if (wwin
->flags
.focused
) {
1553 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1554 wwin
->languagemode
=staterec
.compat_state
&32?1:0;
1555 XkbLockGroup(dpy
,XkbUseCoreKbd
,0); /* reset to workspace */
1558 #endif /* KEEP_XKB_LOCK_STATUS */
1560 CloseWindowMenu(wwin
->screen_ptr
);
1562 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1563 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1565 if (wwin
->transient_for
!=None
1566 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1568 owner
= wWindowFor(wwin
->transient_for
);
1569 if (owner
&& owner
->flags
.semi_focused
) {
1570 owner
->flags
.semi_focused
= 0;
1571 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1572 wWindowUnfocus(owner
);
1573 wFrameWindowPaint(owner
->frame
);
1577 wwin
->flags
.focused
= 0;
1578 wWindowResetMouseGrabs(wwin
);
1580 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1587 *----------------------------------------------------------------------
1589 * wWindowConstrainSize--
1590 * Constrains size for the client window, taking the maximal size,
1591 * window resize increments and other size hints into account.
1594 * The closest size to what was given that the client window can
1597 *----------------------------------------------------------------------
1600 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1602 XSizeHints
*sizeh
= wwin
->normal_hints
;
1603 int width
= *nwidth
;
1604 int height
= *nheight
;
1605 int winc
= sizeh
->width_inc
;
1606 int hinc
= sizeh
->height_inc
;
1608 if (width
< sizeh
->min_width
)
1609 width
= sizeh
->min_width
;
1610 if (height
< sizeh
->min_height
)
1611 height
= sizeh
->min_height
;
1613 if (width
> sizeh
->max_width
)
1614 width
= sizeh
->max_width
;
1615 if (height
> sizeh
->max_height
)
1616 height
= sizeh
->max_height
;
1618 /* aspect ratio code borrowed from olwm */
1619 if (sizeh
->flags
& PAspect
) {
1620 /* adjust max aspect ratio */
1621 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1622 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1623 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1624 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1625 if (height
> sizeh
->max_height
) {
1626 height
= sizeh
->max_height
;
1627 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1630 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1631 if (width
> sizeh
->max_width
) {
1632 width
= sizeh
->max_width
;
1633 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1638 /* adjust min aspect ratio */
1639 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1640 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1641 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1642 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1643 if (height
< sizeh
->min_height
) {
1644 height
= sizeh
->min_height
;
1645 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1648 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1649 if (width
> sizeh
->min_width
) {
1650 width
= sizeh
->min_width
;
1651 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1657 if (sizeh
->base_width
!= 0) {
1658 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1659 + sizeh
->base_width
;
1661 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1665 if (sizeh
->base_width
!= 0) {
1666 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1667 + sizeh
->base_height
;
1669 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1670 + sizeh
->min_height
;
1679 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1681 WScreen
*scr
= wwin
->screen_ptr
;
1685 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1686 || workspace
== wwin
->frame
->workspace
)
1689 if (workspace
!= scr
->current_workspace
) {
1690 /* Sent to other workspace. Unmap window */
1691 if ((wwin
->flags
.mapped
1692 || wwin
->flags
.shaded
1693 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1694 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1696 wapp
= wApplicationOf(wwin
->main_window
);
1698 wapp
->last_workspace
= workspace
;
1700 if (wwin
->flags
.miniaturized
) {
1701 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1702 wwin
->icon
->mapped
= 0;
1705 wSetFocusTo(scr
, NULL
);
1709 /* brought to current workspace. Map window */
1710 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1711 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1712 wwin
->icon
->mapped
= 1;
1713 } else if (!wwin
->flags
.mapped
&&
1714 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1718 if (!IS_OMNIPRESENT(wwin
)) {
1719 wwin
->frame
->workspace
= workspace
;
1720 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1723 wGNOMEUpdateClientStateHint(wwin
, True
);
1726 wKWMUpdateClientWorkspace(wwin
);
1727 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1736 wWindowSynthConfigureNotify(WWindow
*wwin
)
1740 sevent
.type
= ConfigureNotify
;
1741 sevent
.xconfigure
.display
= dpy
;
1742 sevent
.xconfigure
.event
= wwin
->client_win
;
1743 sevent
.xconfigure
.window
= wwin
->client_win
;
1745 sevent
.xconfigure
.x
= wwin
->client
.x
;
1746 sevent
.xconfigure
.y
= wwin
->client
.y
;
1747 sevent
.xconfigure
.width
= wwin
->client
.width
;
1748 sevent
.xconfigure
.height
= wwin
->client
.height
;
1750 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1751 if (WFLAGP(wwin
, no_titlebar
))
1752 sevent
.xconfigure
.above
= None
;
1754 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1756 sevent
.xconfigure
.override_redirect
= False
;
1757 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1759 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1766 *----------------------------------------------------------------------
1767 * wWindowConfigure--
1768 * Configures the frame, decorations and client window to the
1769 * specified geometry. The geometry is not checked for validity,
1770 * wWindowConstrainSize() must be used for that.
1771 * The size parameters are for the client window, but the position is
1773 * The client window receives a ConfigureNotify event, according
1774 * to what ICCCM says.
1780 * Window size and position are changed and client window receives
1781 * a ConfigureNotify event.
1782 *----------------------------------------------------------------------
1785 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1787 int req_x
, req_y
; /* new position of the frame */
1788 int req_width
, req_height
; /* new size of the client */
1790 int synth_notify
= False
;
1793 resize
= (req_width
!=wwin
->client
.width
1794 || req_height
!=wwin
->client
.height
);
1796 * if the window is being moved but not resized then
1797 * send a synthetic ConfigureNotify
1799 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1800 synth_notify
= True
;
1803 if (WFLAGP(wwin
, dont_move_off
))
1804 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1805 req_width
, req_height
);
1807 if (req_width
< MIN_WINDOW_SIZE
)
1808 req_width
= MIN_WINDOW_SIZE
;
1809 if (req_height
< MIN_WINDOW_SIZE
)
1810 req_height
= MIN_WINDOW_SIZE
;
1812 /* If growing, resize inner part before frame,
1813 * if shrinking, resize frame before.
1814 * This will prevent the frame (that can have a different color)
1815 * to be exposed, causing flicker */
1816 if (req_height
> wwin
->frame
->core
->height
1817 || req_width
> wwin
->frame
->core
->width
)
1818 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1820 if (wwin
->flags
.shaded
) {
1821 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1822 req_width
, wwin
->frame
->core
->height
);
1823 wwin
->old_geometry
.height
= req_height
;
1827 h
= req_height
+ wwin
->frame
->top_width
1828 + wwin
->frame
->bottom_width
;
1830 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1833 if (!(req_height
> wwin
->frame
->core
->height
1834 || req_width
> wwin
->frame
->core
->width
))
1835 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1837 wwin
->client
.x
= req_x
;
1838 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1839 wwin
->client
.width
= req_width
;
1840 wwin
->client
.height
= req_height
;
1842 wwin
->client
.x
= req_x
;
1843 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1845 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1847 wwin
->frame_x
= req_x
;
1848 wwin
->frame_y
= req_y
;
1851 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1852 wWindowSetShape(wwin
);
1857 wWindowSynthConfigureNotify(wwin
);
1863 wWindowMove(wwin
, req_x
, req_y
)
1865 int req_x
, req_y
; /* new position of the frame */
1867 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1868 int synth_notify
= False
;
1870 /* Send a synthetic ConfigureNotify event for every window movement. */
1871 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1872 synth_notify
= True
;
1875 /* A single synthetic ConfigureNotify event is sent at the end of
1876 * a completed (opaque) movement in moveres.c */
1879 if (WFLAGP(wwin
, dont_move_off
))
1880 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1881 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1883 wwin
->client
.x
= req_x
;
1884 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1886 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1888 wwin
->frame_x
= req_x
;
1889 wwin
->frame_y
= req_y
;
1891 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1893 wWindowSynthConfigureNotify(wwin
);
1899 wWindowUpdateButtonImages(WWindow
*wwin
)
1901 WScreen
*scr
= wwin
->screen_ptr
;
1902 Pixmap pixmap
, mask
;
1903 WFrameWindow
*fwin
= wwin
->frame
;
1905 if (WFLAGP(wwin
, no_titlebar
))
1908 /* miniaturize button */
1910 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
1911 if (wwin
->wm_gnustep_attr
1912 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1913 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1915 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1916 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1921 if (fwin
->lbutton_image
1922 && (fwin
->lbutton_image
->image
!= pixmap
1923 || fwin
->lbutton_image
->mask
!= mask
)) {
1924 wPixmapDestroy(fwin
->lbutton_image
);
1925 fwin
->lbutton_image
= NULL
;
1928 if (!fwin
->lbutton_image
) {
1929 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1930 fwin
->lbutton_image
->client_owned
= 1;
1931 fwin
->lbutton_image
->client_owned_mask
= 1;
1934 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
1935 wPixmapDestroy(fwin
->lbutton_image
);
1937 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
1943 if (!WFLAGP(wwin
, no_close_button
)) {
1944 if (wwin
->wm_gnustep_attr
1945 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
1946 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
1948 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
1949 mask
= wwin
->wm_gnustep_attr
->close_mask
;
1954 if (fwin
->rbutton_image
1955 && (fwin
->rbutton_image
->image
!= pixmap
1956 || fwin
->rbutton_image
->mask
!= mask
)) {
1957 wPixmapDestroy(fwin
->rbutton_image
);
1958 fwin
->rbutton_image
= NULL
;
1961 if (!fwin
->rbutton_image
) {
1962 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1963 fwin
->rbutton_image
->client_owned
= 1;
1964 fwin
->rbutton_image
->client_owned_mask
= 1;
1966 } else if (WFLAGP(wwin
, kill_close
)) {
1967 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1968 wPixmapDestroy(fwin
->rbutton_image
);
1970 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
1971 } else if (WFLAGP(wwin
, broken_close
)) {
1972 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1973 wPixmapDestroy(fwin
->rbutton_image
);
1975 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
1977 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1978 wPixmapDestroy(fwin
->rbutton_image
);
1980 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
1984 /* force buttons to be redrawn */
1985 fwin
->flags
.need_texture_change
= 1;
1986 wFrameWindowPaint(fwin
);
1991 *---------------------------------------------------------------------------
1992 * wWindowConfigureBorders--
1993 * Update window border configuration according to attribute flags.
1995 *---------------------------------------------------------------------------
1998 wWindowConfigureBorders(WWindow
*wwin
)
2004 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2005 if (!WFLAGP(wwin
, no_titlebar
))
2006 flags
|= WFF_TITLEBAR
;
2007 if (!WFLAGP(wwin
, no_resizebar
))
2008 flags
|= WFF_RESIZEBAR
;
2009 if (wwin
->flags
.shaded
)
2010 flags
|= WFF_IS_SHADED
;
2012 oldh
= wwin
->frame
->top_width
;
2013 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2014 if (oldh
!= wwin
->frame
->top_width
) {
2015 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2017 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2018 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2019 wwin
->client
.width
, wwin
->client
.height
);
2023 if (!WFLAGP(wwin
, no_miniaturize_button
)
2024 && wwin
->frame
->flags
.hide_left_button
)
2025 flags
|= WFF_LEFT_BUTTON
;
2027 if (!WFLAGP(wwin
, no_close_button
)
2028 && wwin
->frame
->flags
.hide_right_button
)
2029 flags
|= WFF_RIGHT_BUTTON
;
2032 wWindowUpdateButtonImages(wwin
);
2033 wFrameWindowShowButton(wwin
->frame
, flags
);
2037 if (WFLAGP(wwin
, no_miniaturize_button
)
2038 && !wwin
->frame
->flags
.hide_left_button
)
2039 flags
|= WFF_LEFT_BUTTON
;
2041 if (WFLAGP(wwin
, no_close_button
)
2042 && !wwin
->frame
->flags
.hide_right_button
)
2043 flags
|= WFF_RIGHT_BUTTON
;
2046 wFrameWindowHideButton(wwin
->frame
, flags
);
2049 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2050 wWindowSetShape(wwin
);
2058 wWindowSaveState(WWindow
*wwin
)
2062 memset(data
, 0, sizeof(CARD32
)*9);
2063 data
[0] = wwin
->frame
->workspace
;
2064 data
[1] = wwin
->flags
.miniaturized
;
2065 data
[2] = wwin
->flags
.shaded
;
2066 data
[3] = wwin
->flags
.hidden
;
2068 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2069 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2070 (unsigned char *)data
, 9);
2075 getSavedState(Window window
, WSavedState
**state
)
2079 unsigned long nitems_ret
;
2080 unsigned long bytes_after_ret
;
2083 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 9,
2084 True
, _XA_WINDOWMAKER_STATE
,
2085 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2086 (unsigned char **)&data
)!=Success
|| !data
)
2089 *state
= malloc(sizeof(WSavedState
));
2092 (*state
)->workspace
= data
[0];
2093 (*state
)->miniaturized
= data
[1];
2094 (*state
)->shaded
= data
[2];
2095 (*state
)->hidden
= data
[3];
2096 (*state
)->use_geometry
= data
[4];
2097 (*state
)->x
= data
[5];
2098 (*state
)->y
= data
[6];
2099 (*state
)->w
= data
[7];
2100 (*state
)->h
= data
[8];
2104 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2113 wWindowClearShape(WWindow
*wwin
)
2115 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2116 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2121 wWindowSetShape(WWindow
*wwin
)
2125 #ifdef OPTIMIZE_SHAPE
2130 /* only shape is the client's */
2131 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2135 /* Get array of rectangles describing the shape mask */
2136 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2142 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2148 /* insert our decoration rectangles in the rect list */
2149 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2152 if (!WFLAGP(wwin
, no_titlebar
)) {
2154 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2155 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2156 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2159 if (!WFLAGP(wwin
, no_resizebar
)) {
2161 urec
[count
].y
= wwin
->frame
->core
->height
2162 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2163 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2164 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2168 /* shape our frame window */
2169 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2170 0, wwin
->frame
->top_width
, urec
, count
,
2171 ShapeSet
, Unsorted
);
2177 #endif /* OPTIMIZE_SHAPE */
2179 if (!WFLAGP(wwin
, no_titlebar
)) {
2182 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2183 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2186 if (!WFLAGP(wwin
, no_resizebar
)) {
2188 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2189 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2190 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2194 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2195 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2197 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2198 0, wwin
->frame
->top_width
, wwin
->client_win
,
2199 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2204 /* ====================================================================== */
2207 getFocusMode(WWindow
*wwin
)
2211 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2212 if (wwin
->wm_hints
->input
== True
) {
2213 if (wwin
->protocols
.TAKE_FOCUS
)
2214 mode
= WFM_LOCALLY_ACTIVE
;
2218 if (wwin
->protocols
.TAKE_FOCUS
)
2219 mode
= WFM_GLOBALLY_ACTIVE
;
2221 mode
= WFM_NO_INPUT
;
2231 wWindowSetKeyGrabs(WWindow
*wwin
)
2236 for (i
=0; i
<WKBD_LAST
; i
++) {
2237 key
= &wKeyBindings
[i
];
2239 if (key
->keycode
==0)
2241 if (key
->modifier
!=AnyModifier
) {
2242 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2243 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2245 /* Also grab all modifier combinations possible that include,
2246 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2247 * work even if the NumLock/ScrollLock key is on.
2249 wHackedGrabKey(key
->keycode
, key
->modifier
,
2250 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2254 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2255 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2259 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2266 wWindowResetMouseGrabs(WWindow
*wwin
)
2268 /* Mouse grabs can't be done on the client window because of
2269 * ICCCM and because clients that try to do the same will crash.
2271 * But there is a problem wich makes tbar buttons of unfocused
2272 * windows not usable as the click goes to the frame window instead
2273 * of the button itself. Must figure a way to fix that.
2276 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2278 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2279 /* grabs for Meta+drag */
2280 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2281 True
, ButtonPressMask
, GrabModeSync
,
2282 GrabModeAsync
, None
, None
);
2285 if (!wwin
->flags
.focused
) {
2286 /* the passive grabs to focus the window */
2287 if (wPreferences
.focus_mode
== WKF_CLICK
)
2288 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2289 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2297 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2300 if (attr
->flags
& GSExtraFlagsAttr
) {
2301 if (WFLAGP(wwin
, broken_close
) !=
2302 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2304 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2306 wWindowUpdateButtonImages(wwin
);
2314 wWindowAddSavedState(char *instance
, char *class, char *command
,
2315 pid_t pid
, WSavedState
*state
)
2317 WWindowState
*wstate
;
2319 wstate
= malloc(sizeof(WWindowState
));
2323 memset(wstate
, 0, sizeof(WWindowState
));
2326 wstate
->instance
= wstrdup(instance
);
2328 wstate
->class = wstrdup(class);
2330 wstate
->command
= wstrdup(command
);
2331 wstate
->state
= state
;
2333 wstate
->next
= windowState
;
2334 windowState
= wstate
;
2337 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2345 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2349 wWindowGetSavedState(Window win
)
2351 char *instance
, *class, *command
=NULL
;
2352 WWindowState
*wstate
= windowState
;
2359 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2361 command
= FlattenStringList(argv
, argc
);
2362 XFreeStringList(argv
);
2367 if (PropGetWMClass(win
, &class, &instance
)) {
2369 if (SAME(instance
, wstate
->instance
) &&
2370 SAME(class, wstate
->class) &&
2371 SAME(command
, wstate
->command
)) {
2374 wstate
= wstate
->next
;
2381 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2385 if (command
) free(command
);
2386 if (instance
) XFree(instance
);
2387 if (class) XFree(class);
2394 wWindowDeleteSavedState(WMagicNumber id
)
2396 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2398 if (!wstate
|| !windowState
)
2403 windowState
= wstate
->next
;
2405 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2406 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2408 if (wstate
->instance
) free(wstate
->instance
);
2409 if (wstate
->class) free(wstate
->class);
2410 if (wstate
->command
) free(wstate
->command
);
2411 free(wstate
->state
);
2415 if (tmp
->next
==wstate
) {
2416 tmp
->next
=wstate
->next
;
2418 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2419 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2421 if (wstate
->instance
) free(wstate
->instance
);
2422 if (wstate
->class) free(wstate
->class);
2423 if (wstate
->command
) free(wstate
->command
);
2424 free(wstate
->state
);
2435 wWindowDeleteSavedStatesForPID(pid_t pid
)
2437 WWindowState
*tmp
, *wstate
;
2443 if (tmp
->pid
== pid
) {
2444 wstate
= windowState
;
2445 windowState
= tmp
->next
;
2447 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2448 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2450 if (wstate
->instance
) free(wstate
->instance
);
2451 if (wstate
->class) free(wstate
->class);
2452 if (wstate
->command
) free(wstate
->command
);
2453 free(wstate
->state
);
2457 if (tmp
->next
->pid
==pid
) {
2459 tmp
->next
= wstate
->next
;
2461 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2462 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2464 if (wstate
->instance
) free(wstate
->instance
);
2465 if (wstate
->class) free(wstate
->class);
2466 if (wstate
->command
) free(wstate
->command
);
2467 free(wstate
->state
);
2477 /* ====================================================================== */
2480 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2482 WWindow
*wwin
= data
;
2484 #ifndef NUMLOCK_HACK
2485 if ((event
->xbutton
.state
& ValidModMask
)
2486 != (event
->xbutton
.state
& ~LockMask
)) {
2487 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2488 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2492 event
->xbutton
.state
&= ValidModMask
;
2494 CloseWindowMenu(wwin
->screen_ptr
);
2496 if (wPreferences
.focus_mode
==WKF_CLICK
2497 && !(event
->xbutton
.state
&ControlMask
)) {
2498 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2501 if (event
->xbutton
.button
== Button1
)
2502 wRaiseFrame(wwin
->frame
->core
);
2504 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2505 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2506 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2507 GrabModeAsync
, GrabModeAsync
, None
,
2508 None
, CurrentTime
)!=GrabSuccess
) {
2510 wwarning("pointer grab failed for window move");
2516 if (event
->xbutton
.state
& MOD_MASK
) {
2517 /* move the window */
2518 wMouseMoveWindow(wwin
, event
);
2519 XUngrabPointer(dpy
, CurrentTime
);
2521 wMouseResizeWindow(wwin
, event
);
2522 XUngrabPointer(dpy
, CurrentTime
);
2529 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2531 WWindow
*wwin
= data
;
2533 event
->xbutton
.state
&= ValidModMask
;
2535 if (event
->xbutton
.button
==Button1
) {
2536 if (event
->xbutton
.state
== 0) {
2537 if (!WFLAGP(wwin
, no_shadeable
)) {
2539 if (wwin
->flags
.shaded
)
2540 wUnshadeWindow(wwin
);
2547 if (event
->xbutton
.state
& ControlMask
)
2548 dir
|= MAX_VERTICAL
;
2550 if (event
->xbutton
.state
& ShiftMask
) {
2551 dir
|= MAX_HORIZONTAL
;
2552 if (!(event
->xbutton
.state
& ControlMask
))
2553 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2556 /* maximize window */
2557 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2558 if (wwin
->flags
.maximized
)
2559 wUnmaximizeWindow(wwin
);
2561 wMaximizeWindow(wwin
, dir
);
2564 } else if (event
->xbutton
.button
==Button3
) {
2565 if (event
->xbutton
.state
& MOD_MASK
) {
2566 wHideOtherApplications(wwin
);
2568 } else if (event
->xbutton
.button
==Button2
) {
2569 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2575 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2577 WWindow
*wwin
= desc
->parent
;
2579 event
->xbutton
.state
&= ValidModMask
;
2581 CloseWindowMenu(wwin
->screen_ptr
);
2583 if (wPreferences
.focus_mode
==WKF_CLICK
2584 && !(event
->xbutton
.state
&ControlMask
)) {
2585 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2587 if (event
->xbutton
.button
== Button1
) {
2588 wRaiseFrame(wwin
->frame
->core
);
2591 if (event
->xbutton
.state
& MOD_MASK
) {
2592 /* move the window */
2593 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2594 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2595 GrabModeAsync
, GrabModeAsync
, None
,
2596 None
, CurrentTime
)!=GrabSuccess
) {
2598 wwarning("pointer grab failed for window move");
2602 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2603 wMouseResizeWindow(wwin
, event
);
2605 wMouseMoveWindow(wwin
, event
);
2606 XUngrabPointer(dpy
, CurrentTime
);
2612 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2614 WWindow
*wwin
= (WWindow
*)data
;
2616 #ifndef NUMLOCK_HACK
2617 if ((event
->xbutton
.state
& ValidModMask
)
2618 != (event
->xbutton
.state
& ~LockMask
)) {
2619 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2620 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2623 event
->xbutton
.state
&= ValidModMask
;
2625 CloseWindowMenu(wwin
->screen_ptr
);
2627 if (wPreferences
.focus_mode
==WKF_CLICK
2628 && !(event
->xbutton
.state
&ControlMask
)) {
2629 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2632 if (event
->xbutton
.button
== Button1
2633 || event
->xbutton
.button
== Button2
) {
2635 if (event
->xbutton
.button
== Button1
) {
2636 if (event
->xbutton
.state
& MOD_MASK
) {
2637 wLowerFrame(wwin
->frame
->core
);
2639 wRaiseFrame(wwin
->frame
->core
);
2642 if ((event
->xbutton
.state
& ShiftMask
)
2643 && !(event
->xbutton
.state
& ControlMask
)) {
2644 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2647 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2648 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2649 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2650 GrabModeAsync
, GrabModeAsync
, None
,
2651 None
, CurrentTime
)!=GrabSuccess
) {
2653 wwarning("pointer grab failed for window move");
2658 /* move the window */
2659 wMouseMoveWindow(wwin
, event
);
2661 XUngrabPointer(dpy
, CurrentTime
);
2662 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2663 && !wwin
->flags
.internal_window
2664 && !WCHECK_STATE(WSTATE_MODAL
)) {
2665 WObjDescriptor
*desc
;
2667 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2668 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2669 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2670 GrabModeAsync
, GrabModeAsync
, None
,
2671 None
, CurrentTime
)!=GrabSuccess
) {
2673 wwarning("pointer grab failed for window move");
2678 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2679 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2681 /* allow drag select */
2682 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2683 event
->xany
.send_event
= True
;
2684 (*desc
->handle_mousedown
)(desc
, event
);
2686 XUngrabPointer(dpy
, CurrentTime
);
2693 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2695 WWindow
*wwin
= data
;
2697 event
->xbutton
.state
&= ValidModMask
;
2699 CloseWindowMenu(wwin
->screen_ptr
);
2701 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2704 /* if control-click, kill the client */
2705 if (event
->xbutton
.state
& ControlMask
) {
2709 if (wwin
->flags
.olwm_push_pin_out
) {
2711 wwin
->flags
.olwm_push_pin_out
= 0;
2713 wOLWMChangePushpinState(wwin
, True
);
2715 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2720 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2721 /* send delete message */
2722 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2729 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2731 WWindow
*wwin
= data
;
2733 CloseWindowMenu(wwin
->screen_ptr
);
2735 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2738 /* send delete message */
2739 if (wwin
->protocols
.DELETE_WINDOW
) {
2740 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2748 windowIconifyClick(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 (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2760 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2764 if ((event
->xbutton
.state
& ControlMask
) ||
2765 (event
->xbutton
.button
== Button3
)) {
2767 wapp
= wApplicationOf(wwin
->main_window
);
2768 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2769 wHideApplication(wapp
);
2770 } else if (event
->xbutton
.state
==0) {
2771 wIconifyWindow(wwin
);