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
|| 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
;
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
820 || wPreferences
.window_placement
!=WPM_MANUAL
)
821 && !scr
->flags
.startup
822 && workspace
== scr
->current_workspace
823 && !wwin
->flags
.miniaturized
824 && !wwin
->flags
.maximized
825 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
826 PlaceWindow(wwin
, &x
, &y
, width
, height
);
827 if (wPreferences
.window_placement
== WPM_MANUAL
)
831 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
832 wScreenBringInside(scr
, &x
, &y
, width
, height
);
835 if (wwin
->flags
.urgent
) {
836 if (!IS_OMNIPRESENT(wwin
))
837 wwin
->flags
.omnipresent
^= 1;
841 *--------------------------------------------------
843 * Create frame, borders and do reparenting
845 *--------------------------------------------------
847 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
848 if (!WFLAGP(wwin
, no_titlebar
))
850 if (!WFLAGP(wwin
, no_resizebar
))
851 foo
|= WFF_RESIZEBAR
;
853 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
854 x
, y
, width
, height
, foo
,
855 scr
->window_title_texture
,
856 (WTexture
**)scr
->resizebar_texture
,
857 scr
->window_title_pixel
,
858 &scr
->window_title_gc
,
861 wwin
->frame
->flags
.is_client_window_frame
= 1;
862 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
864 /* setup button images */
865 wWindowUpdateButtonImages(wwin
);
867 /* hide unused buttons */
869 if (WFLAGP(wwin
, no_close_button
))
870 foo
|= WFF_RIGHT_BUTTON
;
871 if (WFLAGP(wwin
, no_miniaturize_button
))
872 foo
|= WFF_LEFT_BUTTON
;
874 wFrameWindowHideButton(wwin
->frame
, foo
);
876 wwin
->frame
->child
= wwin
;
879 /* emulate olwm push pin. Make the button look as pushed-in for
880 * the pinned-out state. When the button is clicked, it will
881 * revert to the normal position, which means the pin is pinned-in.
883 if (wwin
->flags
.olwm_push_pin_out
)
884 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
885 #endif /* OLWM_HINTS */
887 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
891 wwin
->frame
->workspace
= workspace
;
893 wwin
->frame
->on_click_left
= windowIconifyClick
;
895 wwin
->frame
->on_click_right
= windowCloseClick
;
896 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
898 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
899 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
901 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
904 XSelectInput(dpy
, wwin
->client_win
,
905 wwin
->event_mask
& ~StructureNotifyMask
);
907 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
908 0, wwin
->frame
->top_width
);
910 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
916 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
918 /* if gravity is to the south, account for the border sizes */
920 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
924 * wWindowConfigure() will init the client window's size
925 * (wwin->client.{width,height}) and all other geometry
926 * related variables (frame_x,frame_y)
928 wWindowConfigure(wwin
, x
, y
, width
, height
);
930 /* to make sure the window receives it's new position after reparenting */
931 wWindowSynthConfigureNotify(wwin
);
934 *--------------------------------------------------
936 * Setup descriptors and save window to internal
939 *--------------------------------------------------
942 if (wwin
->main_window
!=None
) {
946 /* Leader windows do not necessary set themselves as leaders.
947 * If this is the case, point the leader of this window to
949 leader
= wWindowFor(wwin
->main_window
);
950 if (leader
&& leader
->main_window
==None
) {
951 leader
->main_window
= leader
->client_win
;
953 app
= wApplicationCreate(scr
, wwin
->main_window
);
955 app
->last_workspace
= workspace
;
958 * Do application specific stuff, like setting application
962 if (wwin
->flags
.hidden
) {
963 /* if the window was set to hidden because it was hidden
964 * in a previous incarnation and that state was restored */
965 app
->flags
.hidden
= 1;
968 if (app
->flags
.hidden
) {
969 wwin
->flags
.hidden
= 1;
974 /* setup the frame descriptor */
975 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
976 wwin
->frame
->core
->descriptor
.parent
= wwin
;
977 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
979 /* don't let windows go away if we die */
980 XAddToSaveSet(dpy
, window
);
982 XLowerWindow(dpy
, window
);
984 /* if window is in this workspace and should be mapped, then map it */
985 if (!wwin
->flags
.miniaturized
986 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
987 && !wwin
->flags
.hidden
&& !withdraw
) {
989 /* The following "if" is to avoid crashing of clients that expect
990 * WM_STATE set before they get mapped. Else WM_STATE is set later,
991 * after the return from this function.
993 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
994 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
996 wClientSetState(wwin
, NormalState
, None
);
999 /* if not auto focus, then map the window under the currently
1001 #define _WIDTH(w) (w)->frame->core->width
1002 #define _HEIGHT(w) (w)->frame->core->height
1003 if (!wPreferences
.auto_focus
&& scr
->focused_window
1004 && !scr
->flags
.startup
&& !transientOwner
1005 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1006 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1007 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1008 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1009 || wwin
->flags
.maximized
)) {
1010 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1016 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1017 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1019 * The brain damaged idiotic non-click to focus modes will
1020 * have trouble with this because:
1022 * 1. window is created and mapped by the client
1023 * 2. window is mapped by wmaker in small size
1024 * 3. window is animated to grow to normal size
1025 * 4. this function returns to normal event loop
1026 * 5. eventually, the EnterNotify event that would trigger
1027 * the window focusing (if the mouse is over that window)
1028 * will be processed by wmaker.
1029 * But since this event will be rather delayed
1030 * (step 3 has a large delay) the time when the event ocurred
1031 * and when it is processed, the client that owns that window
1032 * will reject the XSetInputFocus() for it.
1034 && (wPreferences
.focus_mode
==WKF_CLICK
1035 || wPreferences
.auto_focus
)) {
1036 DoWindowBirth(wwin
);
1042 /* setup stacking descriptor */
1043 if (transientOwner
) {
1044 /* && wPreferences.on_top_transients */
1045 if (transientOwner
) {
1046 wwin
->frame
->core
->stacking
->child_of
=
1047 transientOwner
->frame
->core
;
1050 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1054 if (!scr
->focused_window
) {
1055 /* first window on the list */
1058 scr
->focused_window
= wwin
;
1062 /* add window at beginning of focus window list */
1063 tmp
= scr
->focused_window
;
1072 wGNOMEUpdateClientStateHint(wwin
, True
);
1075 wKWMUpdateClientWorkspace(wwin
);
1076 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1082 *--------------------------------------------------
1084 * Final preparations before window is ready to go
1086 *--------------------------------------------------
1089 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1092 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1093 && !wwin
->flags
.hidden
) {
1094 if ((transientOwner
&& transientOwner
->flags
.focused
)
1095 || wPreferences
.auto_focus
)
1096 wSetFocusTo(scr
, wwin
);
1098 wWindowResetMouseGrabs(wwin
);
1100 if (!WFLAGP(wwin
, no_bind_keys
)) {
1101 wWindowSetKeyGrabs(wwin
);
1104 wGNOMEUpdateClientListHint(scr
);
1107 wwin
->flags
.kwm_managed
= 1;
1109 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1112 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1114 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1117 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1118 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1120 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1121 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1127 *--------------------------------------------------
1129 * Cleanup temporary stuff
1131 *--------------------------------------------------
1135 wWindowDeleteSavedState(win_state
);
1137 /* If the window must be withdrawed, then do it now.
1138 * Must do some optimization, 'though */
1140 wwin
->flags
.mapped
= 0;
1141 wClientSetState(wwin
, WithdrawnState
, None
);
1142 wUnmanageWindow(wwin
, True
, False
);
1154 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1155 char *title
, int x
, int y
, int width
, int height
)
1160 wwin
= wWindowCreate();
1162 wwin
->flags
.internal_window
= 1;
1164 WSETUFLAG(wwin
, omnipresent
, 1);
1165 WSETUFLAG(wwin
, no_shadeable
, 1);
1166 WSETUFLAG(wwin
, no_resizable
, 1);
1167 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1169 wwin
->focus_mode
= WFM_PASSIVE
;
1171 wwin
->client_win
= window
;
1172 wwin
->screen_ptr
= scr
;
1174 wwin
->transient_for
= owner
;
1178 wwin
->client
.width
= width
;
1179 wwin
->client
.height
= height
;
1181 wwin
->frame_x
= wwin
->client
.x
;
1182 wwin
->frame_y
= wwin
->client
.y
;
1185 foo
= WFF_RIGHT_BUTTON
;
1186 foo
|= WFF_TITLEBAR
;
1188 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1189 wwin
->frame_x
, wwin
->frame_y
,
1191 scr
->window_title_texture
,
1192 (WTexture
**)scr
->resizebar_texture
,
1193 scr
->window_title_pixel
,
1194 &scr
->window_title_gc
,
1197 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1199 wwin
->frame
->flags
.is_client_window_frame
= 1;
1200 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1202 wFrameWindowChangeTitle(wwin
->frame
, title
);
1204 /* setup button images */
1205 wWindowUpdateButtonImages(wwin
);
1208 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1210 wwin
->frame
->child
= wwin
;
1212 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1214 wwin
->frame
->on_click_right
= windowCloseClick
;
1216 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1217 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1219 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1221 wwin
->client
.y
+= wwin
->frame
->top_width
;
1222 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1223 0, wwin
->frame
->top_width
);
1225 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1226 wwin
->client
.width
, wwin
->client
.height
);
1228 /* setup the frame descriptor */
1229 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1230 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1231 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1234 XLowerWindow(dpy
, window
);
1235 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1237 /* setup stacking descriptor */
1240 wPreferences
.on_top_transients
&&
1242 wwin
->transient_for
!=None
1243 && wwin
->transient_for
!=scr
->root_win
) {
1245 tmp
= wWindowFor(wwin
->transient_for
);
1247 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1249 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1253 if (!scr
->focused_window
) {
1254 /* first window on the list */
1257 scr
->focused_window
= wwin
;
1261 /* add window at beginning of focus window list */
1262 tmp
= scr
->focused_window
;
1270 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1272 /* if (wPreferences.auto_focus)*/
1273 wSetFocusTo(scr
, wwin
);
1275 wWindowResetMouseGrabs(wwin
);
1277 wWindowSetKeyGrabs(wwin
);
1279 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1286 *----------------------------------------------------------------------
1288 * Removes the frame window from a window and destroys all data
1289 * related to it. The window will be reparented back to the root window
1290 * if restore is True.
1293 * Everything related to the window is destroyed and the window
1294 * is removed from the window lists. Focus is set to the previous on the
1296 *----------------------------------------------------------------------
1299 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1301 WCoreWindow
*frame
= wwin
->frame
->core
;
1302 WWindow
*owner
= NULL
;
1303 WWindow
*newFocusedWindow
= NULL
;
1305 WScreen
*scr
= wwin
->screen_ptr
;
1309 wwin
->frame
->workspace
= -1;
1311 wKWMUpdateClientWorkspace(wwin
);
1314 /* First close attribute editor window if open */
1315 if (wwin
->flags
.inspector_open
) {
1316 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1317 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1320 /* Close window menu if it's open for this window */
1321 if (wwin
->flags
.menu_open_for_me
) {
1322 CloseWindowMenu(scr
);
1326 if (!wwin
->flags
.internal_window
)
1327 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1329 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1331 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1332 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1335 XUnmapWindow(dpy
, frame
->window
);
1337 XUnmapWindow(dpy
, wwin
->client_win
);
1339 /* deselect window */
1340 wSelectWindow(wwin
, False
);
1342 /* remove all pending events on window */
1343 /* I think this only matters for autoraise */
1344 if (wPreferences
.raise_delay
)
1345 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1349 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1351 /* reparent the window back to the root */
1353 wClientRestore(wwin
);
1355 if (wwin
->transient_for
!=scr
->root_win
) {
1356 owner
= wWindowFor(wwin
->transient_for
);
1358 if (!owner
->flags
.semi_focused
) {
1361 owner
->flags
.semi_focused
= 0;
1366 wasFocused
= wwin
->flags
.focused
;
1368 /* remove from window focus list */
1369 if (!wwin
->prev
&& !wwin
->next
) {
1370 /* was the only window */
1371 scr
->focused_window
= NULL
;
1372 newFocusedWindow
= NULL
;
1377 wwin
->prev
->next
= wwin
->next
;
1379 wwin
->next
->prev
= wwin
->prev
;
1381 scr
->focused_window
= wwin
->prev
;
1382 scr
->focused_window
->next
= NULL
;
1385 /* if in click to focus mode and the window
1386 * was a transient, focus the owner window
1389 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1390 tmp
= wWindowFor(wwin
->transient_for
);
1391 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1395 /* otherwise, focus the next one in the focus list */
1397 tmp
= scr
->focused_window
;
1399 if (!WFLAGP(tmp
, no_focusable
)
1400 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1405 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1406 newFocusedWindow
= tmp
;
1407 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1408 || wPreferences
.focus_mode
==WKF_POINTER
) {
1413 /* This is to let the root window get the keyboard input
1414 * if Sloppy focus mode and no other window get focus.
1415 * This way keybindings will not freeze.
1418 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1419 &foo
, &foo
, &foo
, &foo
, &mask
))
1420 tmp
= wWindowFor(win
);
1423 newFocusedWindow
= tmp
;
1425 newFocusedWindow
= NULL
;
1429 if (!wwin
->flags
.internal_window
) {
1431 wGNOMERemoveClient(wwin
);
1434 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1439 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1440 (unsigned)frame
->window
);
1444 if (newFocusedWindow
!= owner
&& owner
) {
1445 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1447 wSetFocusTo(scr
, newFocusedWindow
);
1449 wWindowDestroy(wwin
);
1455 wWindowMap(WWindow
*wwin
)
1457 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1458 if (!wwin
->flags
.shaded
) {
1459 /* window will be remapped when getting MapNotify */
1460 XSelectInput(dpy
, wwin
->client_win
,
1461 wwin
->event_mask
& ~StructureNotifyMask
);
1462 XMapWindow(dpy
, wwin
->client_win
);
1463 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1465 wwin
->flags
.mapped
= 1;
1471 wWindowUnmap(WWindow
*wwin
)
1473 wwin
->flags
.mapped
= 0;
1475 /* prevent window withdrawal when getting UnmapNotify */
1476 XSelectInput(dpy
, wwin
->client_win
,
1477 wwin
->event_mask
& ~StructureNotifyMask
);
1478 XUnmapWindow(dpy
, wwin
->client_win
);
1479 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1481 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1487 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1492 #ifdef KEEP_XKB_LOCK_STATUS
1493 if (wPreferences
.modelock
) {
1494 if (!wwin
->flags
.focused
) {
1495 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1498 #endif /* KEEP_XKB_LOCK_STATUS */
1500 wwin
->flags
.semi_focused
= 0;
1502 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1504 wWindowResetMouseGrabs(wwin
);
1506 wwin
->flags
.focused
= 1;
1508 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1510 if (owin
== wwin
|| !owin
)
1513 nowner
= wWindowFor(wwin
->transient_for
);
1515 /* new window is a transient for the old window */
1516 if (nowner
== owin
) {
1517 owin
->flags
.semi_focused
= 1;
1518 wWindowUnfocus(nowner
);
1522 /* new window is owner of old window */
1523 if (wwin
== oowner
) {
1524 wWindowUnfocus(owin
);
1529 wWindowUnfocus(owin
);
1533 /* new window has same owner of old window */
1534 oowner
= wWindowFor(owin
->transient_for
);
1535 if (oowner
== nowner
) {
1536 /* prevent unfocusing of owner */
1537 oowner
->flags
.semi_focused
= 0;
1538 wWindowUnfocus(owin
);
1539 oowner
->flags
.semi_focused
= 1;
1544 /* nowner != NULL && oowner != nowner */
1545 nowner
->flags
.semi_focused
= 1;
1546 wWindowUnfocus(nowner
);
1547 wWindowUnfocus(owin
);
1552 wWindowUnfocus(WWindow
*wwin
)
1554 CloseWindowMenu(wwin
->screen_ptr
);
1556 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1557 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1559 if (wwin
->transient_for
!=None
1560 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1562 owner
= wWindowFor(wwin
->transient_for
);
1563 if (owner
&& owner
->flags
.semi_focused
) {
1564 owner
->flags
.semi_focused
= 0;
1565 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1566 wWindowUnfocus(owner
);
1567 wFrameWindowPaint(owner
->frame
);
1571 wwin
->flags
.focused
= 0;
1572 wWindowResetMouseGrabs(wwin
);
1574 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1581 *----------------------------------------------------------------------
1583 * wWindowConstrainSize--
1584 * Constrains size for the client window, taking the maximal size,
1585 * window resize increments and other size hints into account.
1588 * The closest size to what was given that the client window can
1591 *----------------------------------------------------------------------
1594 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1596 XSizeHints
*sizeh
= wwin
->normal_hints
;
1597 int width
= *nwidth
;
1598 int height
= *nheight
;
1599 int winc
= sizeh
->width_inc
;
1600 int hinc
= sizeh
->height_inc
;
1602 if (width
< sizeh
->min_width
)
1603 width
= sizeh
->min_width
;
1604 if (height
< sizeh
->min_height
)
1605 height
= sizeh
->min_height
;
1607 if (width
> sizeh
->max_width
)
1608 width
= sizeh
->max_width
;
1609 if (height
> sizeh
->max_height
)
1610 height
= sizeh
->max_height
;
1612 /* aspect ratio code borrowed from olwm */
1613 if (sizeh
->flags
& PAspect
) {
1614 /* adjust max aspect ratio */
1615 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1616 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1617 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1618 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1619 if (height
> sizeh
->max_height
) {
1620 height
= sizeh
->max_height
;
1621 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1624 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1625 if (width
> sizeh
->max_width
) {
1626 width
= sizeh
->max_width
;
1627 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1632 /* adjust min aspect ratio */
1633 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1634 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1635 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1636 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1637 if (height
< sizeh
->min_height
) {
1638 height
= sizeh
->min_height
;
1639 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1642 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1643 if (width
> sizeh
->min_width
) {
1644 width
= sizeh
->min_width
;
1645 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1651 if (sizeh
->base_width
!= 0) {
1652 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1653 + sizeh
->base_width
;
1655 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1659 if (sizeh
->base_width
!= 0) {
1660 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1661 + sizeh
->base_height
;
1663 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1664 + sizeh
->min_height
;
1673 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1675 WScreen
*scr
= wwin
->screen_ptr
;
1679 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1680 || workspace
== wwin
->frame
->workspace
)
1683 if (workspace
!= scr
->current_workspace
) {
1684 /* Sent to other workspace. Unmap window */
1685 if ((wwin
->flags
.mapped
1686 || wwin
->flags
.shaded
1687 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1688 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1690 wapp
= wApplicationOf(wwin
->main_window
);
1692 wapp
->last_workspace
= workspace
;
1694 if (wwin
->flags
.miniaturized
) {
1695 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1696 wwin
->icon
->mapped
= 0;
1699 wSetFocusTo(scr
, NULL
);
1703 /* brought to current workspace. Map window */
1704 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1705 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1706 wwin
->icon
->mapped
= 1;
1707 } else if (!wwin
->flags
.mapped
&&
1708 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1712 if (!IS_OMNIPRESENT(wwin
)) {
1713 wwin
->frame
->workspace
= workspace
;
1714 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1717 wGNOMEUpdateClientStateHint(wwin
, True
);
1720 wKWMUpdateClientWorkspace(wwin
);
1721 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1730 wWindowSynthConfigureNotify(WWindow
*wwin
)
1734 sevent
.type
= ConfigureNotify
;
1735 sevent
.xconfigure
.display
= dpy
;
1736 sevent
.xconfigure
.event
= wwin
->client_win
;
1737 sevent
.xconfigure
.window
= wwin
->client_win
;
1739 sevent
.xconfigure
.x
= wwin
->client
.x
;
1740 sevent
.xconfigure
.y
= wwin
->client
.y
;
1741 sevent
.xconfigure
.width
= wwin
->client
.width
;
1742 sevent
.xconfigure
.height
= wwin
->client
.height
;
1744 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1745 if (WFLAGP(wwin
, no_titlebar
))
1746 sevent
.xconfigure
.above
= None
;
1748 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1750 sevent
.xconfigure
.override_redirect
= False
;
1751 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1753 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1760 *----------------------------------------------------------------------
1761 * wWindowConfigure--
1762 * Configures the frame, decorations and client window to the
1763 * specified geometry. The geometry is not checked for validity,
1764 * wWindowConstrainSize() must be used for that.
1765 * The size parameters are for the client window, but the position is
1767 * The client window receives a ConfigureNotify event, according
1768 * to what ICCCM says.
1774 * Window size and position are changed and client window receives
1775 * a ConfigureNotify event.
1776 *----------------------------------------------------------------------
1779 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1781 int req_x
, req_y
; /* new position of the frame */
1782 int req_width
, req_height
; /* new size of the client */
1784 int synth_notify
= False
;
1787 resize
= (req_width
!=wwin
->client
.width
1788 || req_height
!=wwin
->client
.height
);
1790 * if the window is being moved but not resized then
1791 * send a synthetic ConfigureNotify
1793 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1794 synth_notify
= True
;
1797 if (WFLAGP(wwin
, dont_move_off
))
1798 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1799 req_width
, req_height
);
1801 if (req_width
< MIN_WINDOW_SIZE
)
1802 req_width
= MIN_WINDOW_SIZE
;
1803 if (req_height
< MIN_WINDOW_SIZE
)
1804 req_height
= MIN_WINDOW_SIZE
;
1806 /* If growing, resize inner part before frame,
1807 * if shrinking, resize frame before.
1808 * This will prevent the frame (that can have a different color)
1809 * to be exposed, causing flicker */
1810 if (req_height
> wwin
->frame
->core
->height
1811 || req_width
> wwin
->frame
->core
->width
)
1812 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1814 if (wwin
->flags
.shaded
) {
1815 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1816 req_width
, wwin
->frame
->core
->height
);
1817 wwin
->old_geometry
.height
= req_height
;
1821 h
= req_height
+ wwin
->frame
->top_width
1822 + wwin
->frame
->bottom_width
;
1824 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1827 if (!(req_height
> wwin
->frame
->core
->height
1828 || req_width
> wwin
->frame
->core
->width
))
1829 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1831 wwin
->client
.x
= req_x
;
1832 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1833 wwin
->client
.width
= req_width
;
1834 wwin
->client
.height
= req_height
;
1836 wwin
->client
.x
= req_x
;
1837 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1839 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1841 wwin
->frame_x
= req_x
;
1842 wwin
->frame_y
= req_y
;
1845 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1846 wWindowSetShape(wwin
);
1851 wWindowSynthConfigureNotify(wwin
);
1857 wWindowMove(wwin
, req_x
, req_y
)
1859 int req_x
, req_y
; /* new position of the frame */
1861 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1862 int synth_notify
= False
;
1864 /* Send a synthetic ConfigureNotify event for every window movement. */
1865 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1866 synth_notify
= True
;
1869 /* A single synthetic ConfigureNotify event is sent at the end of
1870 * a completed (opaque) movement in moveres.c */
1873 if (WFLAGP(wwin
, dont_move_off
))
1874 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1875 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1877 wwin
->client
.x
= req_x
;
1878 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1880 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1882 wwin
->frame_x
= req_x
;
1883 wwin
->frame_y
= req_y
;
1885 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1887 wWindowSynthConfigureNotify(wwin
);
1893 wWindowUpdateButtonImages(WWindow
*wwin
)
1895 WScreen
*scr
= wwin
->screen_ptr
;
1896 Pixmap pixmap
, mask
;
1897 WFrameWindow
*fwin
= wwin
->frame
;
1899 if (WFLAGP(wwin
, no_titlebar
))
1902 /* miniaturize button */
1904 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
1905 if (wwin
->wm_gnustep_attr
1906 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1907 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1909 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1910 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1915 if (fwin
->lbutton_image
1916 && (fwin
->lbutton_image
->image
!= pixmap
1917 || fwin
->lbutton_image
->mask
!= mask
)) {
1918 wPixmapDestroy(fwin
->lbutton_image
);
1919 fwin
->lbutton_image
= NULL
;
1922 if (!fwin
->lbutton_image
) {
1923 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1924 fwin
->lbutton_image
->client_owned
= 1;
1925 fwin
->lbutton_image
->client_owned_mask
= 1;
1928 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
1929 wPixmapDestroy(fwin
->lbutton_image
);
1931 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
1937 if (!WFLAGP(wwin
, no_close_button
)) {
1938 if (wwin
->wm_gnustep_attr
1939 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
1940 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
1942 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
1943 mask
= wwin
->wm_gnustep_attr
->close_mask
;
1948 if (fwin
->rbutton_image
1949 && (fwin
->rbutton_image
->image
!= pixmap
1950 || fwin
->rbutton_image
->mask
!= mask
)) {
1951 wPixmapDestroy(fwin
->rbutton_image
);
1952 fwin
->rbutton_image
= NULL
;
1955 if (!fwin
->rbutton_image
) {
1956 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1957 fwin
->rbutton_image
->client_owned
= 1;
1958 fwin
->rbutton_image
->client_owned_mask
= 1;
1960 } else if (WFLAGP(wwin
, kill_close
)) {
1961 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1962 wPixmapDestroy(fwin
->rbutton_image
);
1964 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
1965 } else if (WFLAGP(wwin
, broken_close
)) {
1966 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1967 wPixmapDestroy(fwin
->rbutton_image
);
1969 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
1971 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1972 wPixmapDestroy(fwin
->rbutton_image
);
1974 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
1978 /* force buttons to be redrawn */
1979 fwin
->flags
.need_texture_change
= 1;
1980 wFrameWindowPaint(fwin
);
1985 *---------------------------------------------------------------------------
1986 * wWindowConfigureBorders--
1987 * Update window border configuration according to attribute flags.
1989 *---------------------------------------------------------------------------
1992 wWindowConfigureBorders(WWindow
*wwin
)
1998 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
1999 if (!WFLAGP(wwin
, no_titlebar
))
2000 flags
|= WFF_TITLEBAR
;
2001 if (!WFLAGP(wwin
, no_resizebar
))
2002 flags
|= WFF_RESIZEBAR
;
2003 if (wwin
->flags
.shaded
)
2004 flags
|= WFF_IS_SHADED
;
2006 oldh
= wwin
->frame
->top_width
;
2007 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2008 if (oldh
!= wwin
->frame
->top_width
) {
2009 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2011 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2012 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2013 wwin
->client
.width
, wwin
->client
.height
);
2017 if (!WFLAGP(wwin
, no_miniaturize_button
)
2018 && wwin
->frame
->flags
.hide_left_button
)
2019 flags
|= WFF_LEFT_BUTTON
;
2021 if (!WFLAGP(wwin
, no_close_button
)
2022 && wwin
->frame
->flags
.hide_right_button
)
2023 flags
|= WFF_RIGHT_BUTTON
;
2026 wWindowUpdateButtonImages(wwin
);
2027 wFrameWindowShowButton(wwin
->frame
, flags
);
2031 if (WFLAGP(wwin
, no_miniaturize_button
)
2032 && !wwin
->frame
->flags
.hide_left_button
)
2033 flags
|= WFF_LEFT_BUTTON
;
2035 if (WFLAGP(wwin
, no_close_button
)
2036 && !wwin
->frame
->flags
.hide_right_button
)
2037 flags
|= WFF_RIGHT_BUTTON
;
2040 wFrameWindowHideButton(wwin
->frame
, flags
);
2043 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2044 wWindowSetShape(wwin
);
2052 wWindowSaveState(WWindow
*wwin
)
2056 memset(data
, 0, sizeof(CARD32
)*9);
2057 data
[0] = wwin
->frame
->workspace
;
2058 data
[1] = wwin
->flags
.miniaturized
;
2059 data
[2] = wwin
->flags
.shaded
;
2060 data
[3] = wwin
->flags
.hidden
;
2062 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2063 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2064 (unsigned char *)data
, 9);
2069 getSavedState(Window window
, WSavedState
**state
)
2073 unsigned long nitems_ret
;
2074 unsigned long bytes_after_ret
;
2077 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 9,
2078 True
, _XA_WINDOWMAKER_STATE
,
2079 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2080 (unsigned char **)&data
)!=Success
|| !data
)
2083 *state
= malloc(sizeof(WSavedState
));
2086 (*state
)->workspace
= data
[0];
2087 (*state
)->miniaturized
= data
[1];
2088 (*state
)->shaded
= data
[2];
2089 (*state
)->hidden
= data
[3];
2090 (*state
)->use_geometry
= data
[4];
2091 (*state
)->x
= data
[5];
2092 (*state
)->y
= data
[6];
2093 (*state
)->w
= data
[7];
2094 (*state
)->h
= data
[8];
2098 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2107 wWindowClearShape(WWindow
*wwin
)
2109 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2110 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2115 wWindowSetShape(WWindow
*wwin
)
2119 #ifdef OPTIMIZE_SHAPE
2124 /* only shape is the client's */
2125 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2129 /* Get array of rectangles describing the shape mask */
2130 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2136 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2142 /* insert our decoration rectangles in the rect list */
2143 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2146 if (!WFLAGP(wwin
, no_titlebar
)) {
2148 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2149 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2150 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2153 if (!WFLAGP(wwin
, no_resizebar
)) {
2155 urec
[count
].y
= wwin
->frame
->core
->height
2156 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2157 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2158 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2162 /* shape our frame window */
2163 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2164 0, wwin
->frame
->top_width
, urec
, count
,
2165 ShapeSet
, Unsorted
);
2171 #endif /* OPTIMIZE_SHAPE */
2173 if (!WFLAGP(wwin
, no_titlebar
)) {
2176 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2177 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2180 if (!WFLAGP(wwin
, no_resizebar
)) {
2182 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2183 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2184 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2188 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2189 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2191 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2192 0, wwin
->frame
->top_width
, wwin
->client_win
,
2193 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2198 /* ====================================================================== */
2201 getFocusMode(WWindow
*wwin
)
2205 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2206 if (wwin
->wm_hints
->input
== True
) {
2207 if (wwin
->protocols
.TAKE_FOCUS
)
2208 mode
= WFM_LOCALLY_ACTIVE
;
2212 if (wwin
->protocols
.TAKE_FOCUS
)
2213 mode
= WFM_GLOBALLY_ACTIVE
;
2215 mode
= WFM_NO_INPUT
;
2225 wWindowSetKeyGrabs(WWindow
*wwin
)
2230 for (i
=0; i
<WKBD_LAST
; i
++) {
2231 key
= &wKeyBindings
[i
];
2233 if (key
->keycode
==0)
2235 if (key
->modifier
!=AnyModifier
) {
2236 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2237 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2239 /* Also grab all modifier combinations possible that include,
2240 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2241 * work even if the NumLock/ScrollLock key is on.
2243 wHackedGrabKey(key
->keycode
, key
->modifier
,
2244 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2248 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2249 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2253 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2260 wWindowResetMouseGrabs(WWindow
*wwin
)
2262 /* Mouse grabs can't be done on the client window because of
2263 * ICCCM and because clients that try to do the same will crash.
2265 * But there is a problem wich makes tbar buttons of unfocused
2266 * windows not usable as the click goes to the frame window instead
2267 * of the button itself. Must figure a way to fix that.
2270 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2272 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2273 /* grabs for Meta+drag */
2274 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2275 True
, ButtonPressMask
, GrabModeSync
,
2276 GrabModeAsync
, None
, None
);
2279 if (!wwin
->flags
.focused
) {
2280 /* the passive grabs to focus the window */
2281 if (wPreferences
.focus_mode
== WKF_CLICK
)
2282 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2283 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2291 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2294 if (attr
->flags
& GSExtraFlagsAttr
) {
2295 if (WFLAGP(wwin
, broken_close
) !=
2296 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2298 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2300 wWindowUpdateButtonImages(wwin
);
2308 wWindowAddSavedState(char *instance
, char *class, char *command
,
2309 pid_t pid
, WSavedState
*state
)
2311 WWindowState
*wstate
;
2313 wstate
= malloc(sizeof(WWindowState
));
2317 memset(wstate
, 0, sizeof(WWindowState
));
2320 wstate
->instance
= wstrdup(instance
);
2322 wstate
->class = wstrdup(class);
2324 wstate
->command
= wstrdup(command
);
2325 wstate
->state
= state
;
2327 wstate
->next
= windowState
;
2328 windowState
= wstate
;
2331 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2339 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2343 wWindowGetSavedState(Window win
)
2345 char *instance
, *class, *command
=NULL
;
2346 WWindowState
*wstate
= windowState
;
2353 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2355 command
= FlattenStringList(argv
, argc
);
2356 XFreeStringList(argv
);
2361 if (PropGetWMClass(win
, &class, &instance
)) {
2363 if (SAME(instance
, wstate
->instance
) &&
2364 SAME(class, wstate
->class) &&
2365 SAME(command
, wstate
->command
)) {
2368 wstate
= wstate
->next
;
2375 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2379 if (command
) free(command
);
2380 if (instance
) XFree(instance
);
2381 if (class) XFree(class);
2388 wWindowDeleteSavedState(WMagicNumber id
)
2390 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2392 if (!wstate
|| !windowState
)
2397 windowState
= wstate
->next
;
2399 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2400 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2402 if (wstate
->instance
) free(wstate
->instance
);
2403 if (wstate
->class) free(wstate
->class);
2404 if (wstate
->command
) free(wstate
->command
);
2405 free(wstate
->state
);
2409 if (tmp
->next
==wstate
) {
2410 tmp
->next
=wstate
->next
;
2412 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2413 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2415 if (wstate
->instance
) free(wstate
->instance
);
2416 if (wstate
->class) free(wstate
->class);
2417 if (wstate
->command
) free(wstate
->command
);
2418 free(wstate
->state
);
2429 wWindowDeleteSavedStatesForPID(pid_t pid
)
2431 WWindowState
*tmp
, *wstate
;
2437 if (tmp
->pid
== pid
) {
2438 wstate
= windowState
;
2439 windowState
= tmp
->next
;
2441 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2442 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2444 if (wstate
->instance
) free(wstate
->instance
);
2445 if (wstate
->class) free(wstate
->class);
2446 if (wstate
->command
) free(wstate
->command
);
2447 free(wstate
->state
);
2451 if (tmp
->next
->pid
==pid
) {
2453 tmp
->next
= wstate
->next
;
2455 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2456 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2458 if (wstate
->instance
) free(wstate
->instance
);
2459 if (wstate
->class) free(wstate
->class);
2460 if (wstate
->command
) free(wstate
->command
);
2461 free(wstate
->state
);
2471 /* ====================================================================== */
2474 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2476 WWindow
*wwin
= data
;
2478 #ifndef NUMLOCK_HACK
2479 if ((event
->xbutton
.state
& ValidModMask
)
2480 != (event
->xbutton
.state
& ~LockMask
)) {
2481 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2482 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2486 event
->xbutton
.state
&= ValidModMask
;
2488 CloseWindowMenu(wwin
->screen_ptr
);
2490 if (wPreferences
.focus_mode
==WKF_CLICK
2491 && !(event
->xbutton
.state
&ControlMask
)) {
2492 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2495 if (event
->xbutton
.button
== Button1
)
2496 wRaiseFrame(wwin
->frame
->core
);
2498 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2499 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2500 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2501 GrabModeAsync
, GrabModeAsync
, None
,
2502 None
, CurrentTime
)!=GrabSuccess
) {
2504 wwarning("pointer grab failed for window move");
2510 if (event
->xbutton
.state
& MOD_MASK
) {
2511 /* move the window */
2512 wMouseMoveWindow(wwin
, event
);
2513 XUngrabPointer(dpy
, CurrentTime
);
2515 wMouseResizeWindow(wwin
, event
);
2516 XUngrabPointer(dpy
, CurrentTime
);
2523 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2525 WWindow
*wwin
= data
;
2527 event
->xbutton
.state
&= ValidModMask
;
2529 if (event
->xbutton
.button
==Button1
) {
2530 if (event
->xbutton
.state
== 0) {
2531 if (!WFLAGP(wwin
, no_shadeable
)) {
2533 if (wwin
->flags
.shaded
)
2534 wUnshadeWindow(wwin
);
2541 if (event
->xbutton
.state
& ControlMask
)
2542 dir
|= MAX_VERTICAL
;
2544 if (event
->xbutton
.state
& ShiftMask
) {
2545 dir
|= MAX_HORIZONTAL
;
2546 if (!(event
->xbutton
.state
& ControlMask
))
2547 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2550 /* maximize window */
2551 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2552 if (wwin
->flags
.maximized
)
2553 wUnmaximizeWindow(wwin
);
2555 wMaximizeWindow(wwin
, dir
);
2558 } else if (event
->xbutton
.button
==Button3
) {
2559 if (event
->xbutton
.state
& MOD_MASK
) {
2560 wHideOtherApplications(wwin
);
2562 } else if (event
->xbutton
.button
==Button2
) {
2563 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2569 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2571 WWindow
*wwin
= desc
->parent
;
2573 event
->xbutton
.state
&= ValidModMask
;
2575 CloseWindowMenu(wwin
->screen_ptr
);
2577 if (wPreferences
.focus_mode
==WKF_CLICK
2578 && !(event
->xbutton
.state
&ControlMask
)) {
2579 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2581 if (event
->xbutton
.button
== Button1
) {
2582 wRaiseFrame(wwin
->frame
->core
);
2585 if (event
->xbutton
.state
& MOD_MASK
) {
2586 /* move the window */
2587 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2588 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2589 GrabModeAsync
, GrabModeAsync
, None
,
2590 None
, CurrentTime
)!=GrabSuccess
) {
2592 wwarning("pointer grab failed for window move");
2596 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2597 wMouseResizeWindow(wwin
, event
);
2599 wMouseMoveWindow(wwin
, event
);
2600 XUngrabPointer(dpy
, CurrentTime
);
2606 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2608 WWindow
*wwin
= (WWindow
*)data
;
2610 #ifndef NUMLOCK_HACK
2611 if ((event
->xbutton
.state
& ValidModMask
)
2612 != (event
->xbutton
.state
& ~LockMask
)) {
2613 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2614 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2617 event
->xbutton
.state
&= ValidModMask
;
2619 CloseWindowMenu(wwin
->screen_ptr
);
2621 if (wPreferences
.focus_mode
==WKF_CLICK
2622 && !(event
->xbutton
.state
&ControlMask
)) {
2623 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2626 if (event
->xbutton
.button
== Button1
2627 || event
->xbutton
.button
== Button2
) {
2629 if (event
->xbutton
.button
== Button1
) {
2630 if (event
->xbutton
.state
& MOD_MASK
) {
2631 wLowerFrame(wwin
->frame
->core
);
2633 wRaiseFrame(wwin
->frame
->core
);
2636 if ((event
->xbutton
.state
& ShiftMask
)
2637 && !(event
->xbutton
.state
& ControlMask
)) {
2638 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2641 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2642 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2643 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2644 GrabModeAsync
, GrabModeAsync
, None
,
2645 None
, CurrentTime
)!=GrabSuccess
) {
2647 wwarning("pointer grab failed for window move");
2652 /* move the window */
2653 wMouseMoveWindow(wwin
, event
);
2655 XUngrabPointer(dpy
, CurrentTime
);
2656 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2657 && !wwin
->flags
.internal_window
2658 && !WCHECK_STATE(WSTATE_MODAL
)) {
2659 WObjDescriptor
*desc
;
2661 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2662 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2663 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2664 GrabModeAsync
, GrabModeAsync
, None
,
2665 None
, CurrentTime
)!=GrabSuccess
) {
2667 wwarning("pointer grab failed for window move");
2672 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2673 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2675 /* allow drag select */
2676 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2677 event
->xany
.send_event
= True
;
2678 (*desc
->handle_mousedown
)(desc
, event
);
2680 XUngrabPointer(dpy
, CurrentTime
);
2687 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2689 WWindow
*wwin
= data
;
2691 event
->xbutton
.state
&= ValidModMask
;
2693 CloseWindowMenu(wwin
->screen_ptr
);
2695 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2698 /* if control-click, kill the client */
2699 if (event
->xbutton
.state
& ControlMask
) {
2703 if (wwin
->flags
.olwm_push_pin_out
) {
2705 wwin
->flags
.olwm_push_pin_out
= 0;
2707 wOLWMChangePushpinState(wwin
, True
);
2709 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2714 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2715 /* send delete message */
2716 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2723 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2725 WWindow
*wwin
= data
;
2727 CloseWindowMenu(wwin
->screen_ptr
);
2729 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2732 /* send delete message */
2733 if (wwin
->protocols
.DELETE_WINDOW
) {
2734 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2742 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2744 WWindow
*wwin
= data
;
2746 event
->xbutton
.state
&= ValidModMask
;
2748 CloseWindowMenu(wwin
->screen_ptr
);
2750 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2753 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2754 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2758 if ((event
->xbutton
.state
& ControlMask
) ||
2759 (event
->xbutton
.button
== Button3
)) {
2761 wapp
= wApplicationOf(wwin
->main_window
);
2762 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2763 wHideApplication(wapp
);
2764 } else if (event
->xbutton
.state
==0) {
2765 wIconifyWindow(wwin
);