1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
38 #include "WindowMaker.h"
44 #include "winspector.h"
46 #include "properties.h"
53 #include "workspace.h"
66 # include "openlook.h"
69 /****** Global Variables ******/
71 extern WShortKey wKeyBindings
[WKBD_LAST
];
74 extern Bool wShapeSupported
;
78 extern XContext wWinContext
;
81 extern Cursor wCursor
[WCUR_LAST
];
84 extern Atom _XA_WM_DELETE_WINDOW
;
85 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
87 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern WPreferences wPreferences
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern Time LastTimestamp
;
96 extern void DoWindowBirth(WWindow
*);
99 /***** Local Stuff *****/
102 static WWindowState
*windowState
=NULL
;
106 /* local functions */
107 static FocusMode
getFocusMode(WWindow
*wwin
);
109 static int getSavedState(Window window
, WSavedState
**state
);
111 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
116 /* frame window (during window grabs) */
117 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
120 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
121 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
126 #ifdef XKB_BUTTON_HINT
127 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
130 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
131 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
133 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
136 /****** Notification Observers ******/
139 appearanceObserver(void *self
, WMNotification
*notif
)
141 WWindow
*wwin
= (WWindow
*)self
;
142 int flags
= (int)WMGetNotificationClientData(notif
);
144 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
147 if (flags
& WFontSettings
) {
148 wWindowConfigureBorders(wwin
);
150 if (flags
& WTextureSettings
) {
151 wwin
->frame
->flags
.need_texture_remake
= 1;
153 if (flags
& (WTextureSettings
| WColorSettings
)) {
154 if (wwin
->frame
->titlebar
)
155 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
157 wFrameWindowPaint(wwin
->frame
);
161 /************************************/
164 wWindowFor(Window window
)
166 WObjDescriptor
*desc
;
171 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
174 if (desc
->parent_type
==WCLASS_WINDOW
)
176 else if (desc
->parent_type
==WCLASS_FRAME
) {
177 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
178 if (frame
->flags
.is_client_window_frame
)
191 wwin
= wmalloc(sizeof(WWindow
));
194 memset(wwin
, 0, sizeof(WWindow
));
196 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
197 wwin
->client_descriptor
.parent
= wwin
;
198 wwin
->client_descriptor
.self
= wwin
;
199 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
206 wWindowDestroy(WWindow
*wwin
)
210 WMRemoveNotificationObserver(wwin
);
212 wwin
->flags
.destroyed
= 1;
214 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
215 wwin
->screen_ptr
->shortcutSelectedWindows
[i
] = list_remove_elem(wwin
->screen_ptr
->shortcutSelectedWindows
[i
], wwin
);
216 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
) {
217 if (wwin
->screen_ptr
->shortcutSelectedWindows
[i
]) {
218 LinkedList
*list
= wwin
->screen_ptr
->shortcutSelectedWindows
[i
];
219 wwin
->screen_ptr
->shortcutWindow
[i
] =
222 else wwin
->screen_ptr
->shortcutWindow
[i
] = NULL
;
226 if (wwin
->normal_hints
)
227 free(wwin
->normal_hints
);
230 XFree(wwin
->wm_hints
);
232 if (wwin
->wm_instance
)
233 XFree(wwin
->wm_instance
);
236 XFree(wwin
->wm_class
);
238 if (wwin
->wm_gnustep_attr
)
239 free(wwin
->wm_gnustep_attr
);
241 if (wwin
->cmap_windows
)
242 XFree(wwin
->cmap_windows
);
244 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
247 wFrameWindowDestroy(wwin
->frame
);
250 RemoveFromStackList(wwin
->icon
->core
);
251 wIconDestroy(wwin
->icon
);
252 if (wPreferences
.auto_arrange_icons
)
253 wArrangeIcons(wwin
->screen_ptr
, True
);
262 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
264 if (gs_hints
->flags
& GSWindowStyleAttr
) {
265 wwin
->client_flags
.no_titlebar
=
266 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
268 wwin
->client_flags
.no_close_button
=
269 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
271 wwin
->client_flags
.no_closable
=
272 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
274 wwin
->client_flags
.no_miniaturize_button
=
275 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
277 wwin
->client_flags
.no_miniaturizable
=
278 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
280 wwin
->client_flags
.no_resizebar
=
281 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
283 wwin
->client_flags
.no_resizable
=
284 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
286 /* setup the defaults */
287 wwin
->client_flags
.no_titlebar
= 0;
288 wwin
->client_flags
.no_closable
= 0;
289 wwin
->client_flags
.no_miniaturizable
= 0;
290 wwin
->client_flags
.no_resizable
= 0;
291 wwin
->client_flags
.no_close_button
= 0;
292 wwin
->client_flags
.no_miniaturize_button
= 0;
293 wwin
->client_flags
.no_resizebar
= 0;
295 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
296 wwin
->client_flags
.no_appicon
= 1;
302 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
303 WWindowAttributes
*mask
)
305 if (wflags
->no_appicon
&& mask
->no_appicon
)
306 wflags
->emulate_appicon
= 0;
308 if (wwin
->main_window
!=None
) {
309 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
310 if (wapp
&& !wapp
->flags
.emulated
)
311 wflags
->emulate_appicon
= 0;
314 if (wwin
->transient_for
!=None
315 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
316 wflags
->emulate_appicon
= 0;
318 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
325 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
327 WScreen
*scr
= wwin
->screen_ptr
;
329 /* sets global default stuff */
330 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
331 &wwin
->client_flags
, NULL
, True
);
333 * Decoration setting is done in this precedence (lower to higher)
334 * - use global default in the resource database
335 * - guess some settings
336 * - use GNUstep/external window attributes
337 * - set hints specified for the app in the resource DB
340 WSETUFLAG(wwin
, broken_close
, 0);
342 if (wwin
->protocols
.DELETE_WINDOW
)
343 WSETUFLAG(wwin
, kill_close
, 0);
345 WSETUFLAG(wwin
, kill_close
, 1);
347 /* transients can't be iconified or maximized */
348 if (wwin
->transient_for
) {
349 WSETUFLAG(wwin
, no_miniaturizable
, 1);
350 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
353 /* if the window can't be resized, remove the resizebar */
354 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
355 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
356 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
357 WSETUFLAG(wwin
, no_resizable
, 1);
358 WSETUFLAG(wwin
, no_resizebar
, 1);
361 /* set GNUstep window attributes */
362 if (wwin
->wm_gnustep_attr
) {
363 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
365 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
367 switch (wwin
->wm_gnustep_attr
->window_level
) {
368 case WMNormalWindowLevel
:
369 *level
= WMNormalLevel
;
371 case WMFloatingWindowLevel
:
372 *level
= WMFloatingLevel
;
374 case WMDockWindowLevel
:
375 *level
= WMDockLevel
;
377 case WMSubmenuWindowLevel
:
378 *level
= WMSubmenuLevel
;
380 case WMMainMenuWindowLevel
:
381 *level
= WMMainMenuLevel
;
384 *level
= WMNormalLevel
;
389 *level
= WMNormalLevel
;
392 int tmp_workspace
= -1;
396 wMWMCheckClientHints(wwin
);
397 #endif /* MWM_HINTS */
400 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
401 #endif /* KWM_HINTS */
404 wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
405 #endif /* GNOME_STUFF */
408 wOLWMCheckClientHints(wwin
);
409 #endif /* OLWM_HINTS */
412 if (WFLAGP(wwin
, floating
))
413 *level
= WMFloatingLevel
;
414 else if (WFLAGP(wwin
, sunken
))
415 *level
= WMSunkenLevel
;
417 *level
= WMNormalLevel
;
422 if (tmp_workspace
>= 0) {
423 *workspace
= tmp_workspace
% scr
->workspace_count
;
428 * Set attributes specified only for that window/class.
429 * This might do duplicate work with the 1st wDefaultFillAttributes().
431 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
432 &wwin
->user_flags
, &wwin
->defined_user_flags
,
435 * Sanity checks for attributes that depend on other attributes
437 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
438 wwin
->user_flags
.emulate_appicon
= 0;
440 if (wwin
->main_window
!=None
) {
441 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
442 if (wapp
&& !wapp
->flags
.emulated
)
443 wwin
->user_flags
.emulate_appicon
= 0;
446 if (wwin
->transient_for
!=None
447 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
448 wwin
->user_flags
.emulate_appicon
= 0;
450 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
451 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
452 wwin
->user_flags
.sunken
= 0;
454 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
461 wWindowCanReceiveFocus(WWindow
*wwin
)
463 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
465 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
467 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
475 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
479 w1
= wwin
->frame
->core
->width
;
480 h1
= wwin
->frame
->core
->height
;
481 w2
= obscured
->frame
->core
->width
;
482 h2
= obscured
->frame
->core
->height
;
484 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
485 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
488 if (wwin
->frame_x
+ w1
< obscured
->frame_x
489 || wwin
->frame_y
+ h1
< obscured
->frame_y
490 || wwin
->frame_x
> obscured
->frame_x
+ w2
491 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
500 *----------------------------------------------------------------
502 * reparents the window and allocates a descriptor for it.
503 * Window manager hints and other hints are fetched to configure
504 * the window decoration attributes and others. User preferences
505 * for the window are used if available, to configure window
506 * decorations and some behaviour.
507 * If in startup, windows that are override redirect,
508 * unmapped and never were managed and are Withdrawn are not
512 * the new window descriptor
515 * The window is reparented and appropriate notification
516 * is done to the client. Input mask for the window is setup.
517 * The window descriptor is also associated with various window
518 * contexts and inserted in the head of the window list.
519 * Event handler contexts are associated for some objects
520 * (buttons, titlebar and resizebar)
522 *----------------------------------------------------------------
525 wManageWindow(WScreen
*scr
, Window window
)
529 unsigned width
, height
;
530 XWindowAttributes wattribs
;
531 XSetWindowAttributes attribs
;
532 WWindowState
*win_state
;
533 WWindow
*transientOwner
= NULL
;
539 Bool withdraw
= False
;
542 /* XGrabServer(dpy); */
544 /* make sure the window is still there */
545 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
550 /* if it's an override-redirect, ignore it */
551 if (wattribs
.override_redirect
) {
556 wm_state
= PropGetWindowState(window
);
558 /* if it's startup and the window is unmapped, don't manage it */
559 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
564 if (!wFetchName(dpy
, window
, &title
)) {
569 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
574 #endif /* KWM_HINTS */
577 wwin
= wWindowCreate();
579 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
582 printf("managing window %x\n", (unsigned)window
);
586 if (wShapeSupported
) {
591 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
592 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
593 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
594 wwin
->flags
.shaped
= b_shaped
;
599 *--------------------------------------------------
601 * Get hints and other information in properties
603 *--------------------------------------------------
605 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
607 /* setup descriptor */
608 wwin
->client_win
= window
;
609 wwin
->screen_ptr
= scr
;
611 wwin
->old_border_width
= wattribs
.border_width
;
613 wwin
->event_mask
= CLIENT_EVENTS
;
614 attribs
.event_mask
= CLIENT_EVENTS
;
615 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
616 attribs
.save_under
= False
;
617 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
618 |CWSaveUnder
, &attribs
);
619 XSetWindowBorderWidth(dpy
, window
, 0);
621 /* get hints from GNUstep app */
622 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
623 wwin
->wm_gnustep_attr
= NULL
;
626 wwin
->client_leader
= PropGetClientLeader(window
);
627 if (wwin
->client_leader
!=None
)
628 wwin
->main_window
= wwin
->client_leader
;
630 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
632 if (wwin
->wm_hints
) {
633 if (wwin
->wm_hints
->flags
& StateHint
) {
635 if (wwin
->wm_hints
->initial_state
== IconicState
) {
637 wwin
->flags
.miniaturized
= 1;
639 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
645 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
646 wwin
->group_id
= wwin
->wm_hints
->window_group
;
647 /* window_group has priority over CLIENT_LEADER */
648 wwin
->main_window
= wwin
->group_id
;
650 wwin
->group_id
= None
;
653 if (wwin
->wm_hints
->flags
& UrgencyHint
)
654 wwin
->flags
.urgent
= 1;
656 wwin
->group_id
= None
;
659 PropGetProtocols(window
, &wwin
->protocols
);
661 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
662 wwin
->transient_for
= None
;
664 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
665 wwin
->transient_for
= scr
->root_win
;
667 transientOwner
= wWindowFor(wwin
->transient_for
);
668 if (transientOwner
&& transientOwner
->main_window
!=None
) {
669 wwin
->main_window
= transientOwner
->main_window
;
671 wwin->main_window = None;
676 /* guess the focus mode */
677 wwin
->focus_mode
= getFocusMode(wwin
);
679 /* get geometry stuff */
680 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
682 /* get colormap windows */
683 GetColormapWindows(wwin
);
686 *--------------------------------------------------
688 * Setup the decoration/window attributes and
691 *--------------------------------------------------
694 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
697 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
698 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
700 transientOwner
= wWindowFor(wwin
->group_id
);
702 if (transientOwner
) {
703 wwin
->transient_for
= wwin
->group_id
;
705 /* transients can't be iconified or maximized */
706 if (wwin
->transient_for
) {
707 WSETUFLAG(wwin
, no_miniaturizable
, 1);
708 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
712 #endif /* OLWM_HINTS */
715 * Make broken apps behave as a nice app.
717 if (WFLAGP(wwin
, emulate_appicon
)) {
718 wwin
->main_window
= wwin
->client_win
;
722 *------------------------------------------------------------
724 * Setup the initial state of the window
726 *------------------------------------------------------------
729 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
730 wwin
->flags
.miniaturized
= 1;
733 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
734 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
738 wGNOMECheckInitialClientState(wwin
);
741 wKWMCheckClientInitialState(wwin
);
744 /* apply previous state if it exists and we're in startup */
745 if (scr
->flags
.startup
&& wm_state
>= 0) {
747 if (wm_state
== IconicState
) {
749 wwin
->flags
.miniaturized
= 1;
751 } else if (wm_state
== WithdrawnState
) {
757 /* if there is a saved state (from file), restore it */
759 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
760 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
762 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
764 if (win_state
&& !withdraw
) {
766 if (win_state
->state
->hidden
>0)
767 wwin
->flags
.hidden
= win_state
->state
->hidden
;
769 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
770 wwin
->flags
.shaded
= win_state
->state
->shaded
;
772 if (win_state
->state
->miniaturized
>0 &&
773 !WFLAGP(wwin
, no_miniaturizable
)) {
774 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
776 if (!IS_OMNIPRESENT(wwin
)) {
777 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
779 if (w
< 0 || w
>= scr
->workspace_count
) {
780 workspace
= win_state
->state
->workspace
;
781 if (workspace
>= scr
->workspace_count
)
782 workspace
= scr
->current_workspace
;
787 workspace
= scr
->current_workspace
;
791 /* if we're restarting, restore saved state (from hints).
792 * This will overwrite previous */
796 if (getSavedState(window
, &wstate
)) {
797 wwin
->flags
.shaded
= wstate
->shaded
;
798 wwin
->flags
.hidden
= wstate
->hidden
;
799 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
800 workspace
= wstate
->workspace
;
802 if (scr
->flags
.startup
&& wstate
->window_shortcuts
>= 0) {
805 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
806 if (wstate
->window_shortcuts
& (1<<i
))
807 scr
->shortcutWindow
[i
] = wwin
;
814 /* don't let transients start miniaturized if their owners are not */
815 if (transientOwner
&& !transientOwner
->flags
.miniaturized
816 && wwin
->flags
.miniaturized
&& !withdraw
) {
817 wwin
->flags
.miniaturized
= 0;
819 wwin
->wm_hints
->initial_state
= NormalState
;
822 /* set workspace on which the window starts */
823 if (workspace
>= 0) {
824 if (workspace
> scr
->workspace_count
-1) {
825 workspace
= workspace
% scr
->workspace_count
;
830 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
832 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
837 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
839 workspace
= transientOwner
->frame
->workspace
;
843 workspace
= scr
->current_workspace
;
848 /* setup window geometry */
849 if (win_state
&& win_state
->state
->use_geometry
) {
850 width
= win_state
->state
->w
;
851 height
= win_state
->state
->h
;
853 wWindowConstrainSize(wwin
, &width
, &height
);
855 /* do not ask for window placement if the window is
856 * transient, during startup, if the initial workspace is another one
857 * or if the window wants to start iconic.
858 * If geometry was saved, restore it. */
860 Bool dontBring
= False
;
862 if (win_state
&& win_state
->state
->use_geometry
) {
863 x
= win_state
->state
->x
;
864 y
= win_state
->state
->y
;
865 } else if ((wwin
->transient_for
==None
866 || wPreferences
.window_placement
!=WPM_MANUAL
)
867 && !scr
->flags
.startup
868 && workspace
== scr
->current_workspace
869 && !wwin
->flags
.miniaturized
870 && !wwin
->flags
.maximized
871 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
872 PlaceWindow(wwin
, &x
, &y
, width
, height
);
873 if (wPreferences
.window_placement
== WPM_MANUAL
)
877 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
878 wScreenBringInside(scr
, &x
, &y
, width
, height
);
881 if (wwin
->flags
.urgent
) {
882 if (!IS_OMNIPRESENT(wwin
))
883 wwin
->flags
.omnipresent
^= 1;
887 *--------------------------------------------------
889 * Create frame, borders and do reparenting
891 *--------------------------------------------------
893 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
894 #ifdef XKB_BUTTON_HINT
895 if (wPreferences
.modelock
)
896 foo
|= WFF_LANGUAGE_BUTTON
;
898 if (!WFLAGP(wwin
, no_titlebar
))
900 if (!WFLAGP(wwin
, no_resizebar
))
901 foo
|= WFF_RESIZEBAR
;
903 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
904 x
, y
, width
, height
, foo
,
905 scr
->window_title_texture
,
906 scr
->resizebar_texture
,
907 scr
->window_title_pixel
,
908 #ifdef DRAWSTRING_PLUGIN
911 &scr
->window_title_gc
,
914 wwin
->frame
->flags
.is_client_window_frame
= 1;
915 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
917 /* setup button images */
918 wWindowUpdateButtonImages(wwin
);
920 /* hide unused buttons */
922 if (WFLAGP(wwin
, no_close_button
))
923 foo
|= WFF_RIGHT_BUTTON
;
924 if (WFLAGP(wwin
, no_miniaturize_button
))
925 foo
|= WFF_LEFT_BUTTON
;
926 #ifdef XKB_BUTTON_HINT
927 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
928 foo
|= WFF_LANGUAGE_BUTTON
;
931 wFrameWindowHideButton(wwin
->frame
, foo
);
933 wwin
->frame
->child
= wwin
;
936 /* emulate olwm push pin. Make the button look as pushed-in for
937 * the pinned-out state. When the button is clicked, it will
938 * revert to the normal position, which means the pin is pinned-in.
940 if (wwin
->flags
.olwm_push_pin_out
)
941 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
942 #endif /* OLWM_HINTS */
944 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
948 wwin
->frame
->workspace
= workspace
;
950 wwin
->frame
->on_click_left
= windowIconifyClick
;
951 #ifdef XKB_BUTTON_HINT
952 if (wPreferences
.modelock
)
953 wwin
->frame
->on_click_language
= windowLanguageClick
;
956 wwin
->frame
->on_click_right
= windowCloseClick
;
957 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
959 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
960 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
962 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
965 XSelectInput(dpy
, wwin
->client_win
,
966 wwin
->event_mask
& ~StructureNotifyMask
);
968 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
969 0, wwin
->frame
->top_width
);
971 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
977 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
979 /* if gravity is to the south, account for the border sizes */
981 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
985 * wWindowConfigure() will init the client window's size
986 * (wwin->client.{width,height}) and all other geometry
987 * related variables (frame_x,frame_y)
989 wWindowConfigure(wwin
, x
, y
, width
, height
);
991 /* to make sure the window receives it's new position after reparenting */
992 wWindowSynthConfigureNotify(wwin
);
995 *--------------------------------------------------
997 * Setup descriptors and save window to internal
1000 *--------------------------------------------------
1003 if (wwin
->main_window
!=None
) {
1007 /* Leader windows do not necessary set themselves as leaders.
1008 * If this is the case, point the leader of this window to
1010 leader
= wWindowFor(wwin
->main_window
);
1011 if (leader
&& leader
->main_window
==None
) {
1012 leader
->main_window
= leader
->client_win
;
1014 app
= wApplicationCreate(scr
, wwin
->main_window
);
1016 app
->last_workspace
= workspace
;
1019 * Do application specific stuff, like setting application
1023 if (wwin
->flags
.hidden
) {
1024 /* if the window was set to hidden because it was hidden
1025 * in a previous incarnation and that state was restored */
1026 app
->flags
.hidden
= 1;
1029 if (app
->flags
.hidden
) {
1030 wwin
->flags
.hidden
= 1;
1035 /* setup the frame descriptor */
1036 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1037 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1038 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1040 /* don't let windows go away if we die */
1041 XAddToSaveSet(dpy
, window
);
1043 XLowerWindow(dpy
, window
);
1045 /* if window is in this workspace and should be mapped, then map it */
1046 if (!wwin
->flags
.miniaturized
1047 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1048 && !wwin
->flags
.hidden
&& !withdraw
) {
1050 /* The following "if" is to avoid crashing of clients that expect
1051 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1052 * after the return from this function.
1054 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1055 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1057 wClientSetState(wwin
, NormalState
, None
);
1061 /* if not auto focus, then map the window under the currently
1063 #define _WIDTH(w) (w)->frame->core->width
1064 #define _HEIGHT(w) (w)->frame->core->height
1065 if (!wPreferences
.auto_focus
&& scr
->focused_window
1066 && !scr
->flags
.startup
&& !transientOwner
1067 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1068 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1069 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1070 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1071 || wwin
->flags
.maximized
)) {
1072 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1080 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1081 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1083 * The brain damaged idiotic non-click to focus modes will
1084 * have trouble with this because:
1086 * 1. window is created and mapped by the client
1087 * 2. window is mapped by wmaker in small size
1088 * 3. window is animated to grow to normal size
1089 * 4. this function returns to normal event loop
1090 * 5. eventually, the EnterNotify event that would trigger
1091 * the window focusing (if the mouse is over that window)
1092 * will be processed by wmaker.
1093 * But since this event will be rather delayed
1094 * (step 3 has a large delay) the time when the event ocurred
1095 * and when it is processed, the client that owns that window
1096 * will reject the XSetInputFocus() for it.
1098 && (wPreferences
.focus_mode
==WKF_CLICK
1099 || wPreferences
.auto_focus
)) {
1100 DoWindowBirth(wwin
);
1106 /* setup stacking descriptor */
1107 if (transientOwner
) {
1108 /* && wPreferences.on_top_transients */
1109 if (transientOwner
) {
1110 wwin
->frame
->core
->stacking
->child_of
=
1111 transientOwner
->frame
->core
;
1114 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1118 if (!scr
->focused_window
) {
1119 /* first window on the list */
1122 scr
->focused_window
= wwin
;
1126 /* add window at beginning of focus window list */
1127 tmp
= scr
->focused_window
;
1136 wGNOMEUpdateClientStateHint(wwin
, True
);
1139 wKWMUpdateClientWorkspace(wwin
);
1140 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1146 *--------------------------------------------------
1148 * Final preparations before window is ready to go
1150 *--------------------------------------------------
1153 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1156 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1157 && !wwin
->flags
.hidden
) {
1158 if (((transientOwner
&& transientOwner
->flags
.focused
)
1159 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1160 wSetFocusTo(scr
, wwin
);
1162 wWindowResetMouseGrabs(wwin
);
1164 if (!WFLAGP(wwin
, no_bind_keys
)) {
1165 wWindowSetKeyGrabs(wwin
);
1168 wGNOMEUpdateClientListHint(scr
);
1171 wwin
->flags
.kwm_managed
= 1;
1173 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1176 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1178 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1181 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1182 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1184 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1185 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1191 *------------------------------------------------------------
1192 * Setup Notification Observers
1193 *------------------------------------------------------------
1195 WMAddNotificationObserver(appearanceObserver
, wwin
,
1196 WNWindowAppearanceSettingsChanged
, wwin
);
1200 *--------------------------------------------------
1202 * Cleanup temporary stuff
1204 *--------------------------------------------------
1208 wWindowDeleteSavedState(win_state
);
1210 /* If the window must be withdrawed, then do it now.
1211 * Must do some optimization, 'though */
1213 wwin
->flags
.mapped
= 0;
1214 wClientSetState(wwin
, WithdrawnState
, None
);
1215 wUnmanageWindow(wwin
, True
, False
);
1227 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1228 char *title
, int x
, int y
, int width
, int height
)
1233 wwin
= wWindowCreate();
1235 WMAddNotificationObserver(appearanceObserver
, wwin
,
1236 WNWindowAppearanceSettingsChanged
, wwin
);
1238 wwin
->flags
.internal_window
= 1;
1240 WSETUFLAG(wwin
, omnipresent
, 1);
1241 WSETUFLAG(wwin
, no_shadeable
, 1);
1242 WSETUFLAG(wwin
, no_resizable
, 1);
1243 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1245 wwin
->focus_mode
= WFM_PASSIVE
;
1247 wwin
->client_win
= window
;
1248 wwin
->screen_ptr
= scr
;
1250 wwin
->transient_for
= owner
;
1254 wwin
->client
.width
= width
;
1255 wwin
->client
.height
= height
;
1257 wwin
->frame_x
= wwin
->client
.x
;
1258 wwin
->frame_y
= wwin
->client
.y
;
1261 foo
= WFF_RIGHT_BUTTON
;
1262 foo
|= WFF_TITLEBAR
;
1263 #ifdef XKB_BUTTON_HINT
1264 foo
|= WFF_LANGUAGE_BUTTON
;
1267 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1268 wwin
->frame_x
, wwin
->frame_y
,
1270 scr
->window_title_texture
,
1271 scr
->resizebar_texture
,
1272 scr
->window_title_pixel
,
1273 #ifdef DRAWSTRING_PLUGIN
1276 &scr
->window_title_gc
,
1279 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1281 wwin
->frame
->flags
.is_client_window_frame
= 1;
1282 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1284 wFrameWindowChangeTitle(wwin
->frame
, title
);
1286 /* setup button images */
1287 wWindowUpdateButtonImages(wwin
);
1290 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1292 wwin
->frame
->child
= wwin
;
1294 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1296 #ifdef XKB_BUTTON_HINT
1297 if (wPreferences
.modelock
)
1298 wwin
->frame
->on_click_language
= windowLanguageClick
;
1301 wwin
->frame
->on_click_right
= windowCloseClick
;
1303 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1304 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1306 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1308 wwin
->client
.y
+= wwin
->frame
->top_width
;
1309 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1310 0, wwin
->frame
->top_width
);
1312 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1313 wwin
->client
.width
, wwin
->client
.height
);
1315 /* setup the frame descriptor */
1316 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1317 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1318 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1321 XLowerWindow(dpy
, window
);
1322 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1324 /* setup stacking descriptor */
1327 wPreferences
.on_top_transients
&&
1329 wwin
->transient_for
!=None
1330 && wwin
->transient_for
!=scr
->root_win
) {
1332 tmp
= wWindowFor(wwin
->transient_for
);
1334 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1336 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1340 if (!scr
->focused_window
) {
1341 /* first window on the list */
1344 scr
->focused_window
= wwin
;
1348 /* add window at beginning of focus window list */
1349 tmp
= scr
->focused_window
;
1357 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1359 /* if (wPreferences.auto_focus)*/
1360 wSetFocusTo(scr
, wwin
);
1362 wWindowResetMouseGrabs(wwin
);
1364 wWindowSetKeyGrabs(wwin
);
1366 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1373 *----------------------------------------------------------------------
1375 * Removes the frame window from a window and destroys all data
1376 * related to it. The window will be reparented back to the root window
1377 * if restore is True.
1380 * Everything related to the window is destroyed and the window
1381 * is removed from the window lists. Focus is set to the previous on the
1383 *----------------------------------------------------------------------
1386 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1388 WCoreWindow
*frame
= wwin
->frame
->core
;
1389 WWindow
*owner
= NULL
;
1390 WWindow
*newFocusedWindow
= NULL
;
1392 WScreen
*scr
= wwin
->screen_ptr
;
1396 wwin
->frame
->workspace
= -1;
1398 wKWMUpdateClientWorkspace(wwin
);
1401 /* First close attribute editor window if open */
1402 if (wwin
->flags
.inspector_open
) {
1403 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1404 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1407 /* Close window menu if it's open for this window */
1408 if (wwin
->flags
.menu_open_for_me
) {
1409 CloseWindowMenu(scr
);
1413 if (!wwin
->flags
.internal_window
)
1414 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1416 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1418 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1419 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1422 XUnmapWindow(dpy
, frame
->window
);
1424 XUnmapWindow(dpy
, wwin
->client_win
);
1426 /* deselect window */
1427 wSelectWindow(wwin
, False
);
1429 /* remove all pending events on window */
1430 /* I think this only matters for autoraise */
1431 if (wPreferences
.raise_delay
)
1432 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1436 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1438 /* reparent the window back to the root */
1440 wClientRestore(wwin
);
1442 if (wwin
->transient_for
!=scr
->root_win
) {
1443 owner
= wWindowFor(wwin
->transient_for
);
1445 if (!owner
->flags
.semi_focused
) {
1448 owner
->flags
.semi_focused
= 0;
1453 wasFocused
= wwin
->flags
.focused
;
1455 /* remove from window focus list */
1456 if (!wwin
->prev
&& !wwin
->next
) {
1457 /* was the only window */
1458 scr
->focused_window
= NULL
;
1459 newFocusedWindow
= NULL
;
1464 wwin
->prev
->next
= wwin
->next
;
1466 wwin
->next
->prev
= wwin
->prev
;
1468 scr
->focused_window
= wwin
->prev
;
1469 scr
->focused_window
->next
= NULL
;
1472 /* if in click to focus mode and the window
1473 * was a transient, focus the owner window
1476 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1477 tmp
= wWindowFor(wwin
->transient_for
);
1478 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1482 /* otherwise, focus the next one in the focus list */
1484 tmp
= scr
->focused_window
;
1486 if (!WFLAGP(tmp
, no_focusable
)
1487 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1492 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1493 newFocusedWindow
= tmp
;
1494 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1495 || wPreferences
.focus_mode
==WKF_POINTER
) {
1500 /* This is to let the root window get the keyboard input
1501 * if Sloppy focus mode and no other window get focus.
1502 * This way keybindings will not freeze.
1505 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1506 &foo
, &foo
, &foo
, &foo
, &mask
))
1507 tmp
= wWindowFor(win
);
1510 newFocusedWindow
= tmp
;
1512 newFocusedWindow
= NULL
;
1516 if (!wwin
->flags
.internal_window
) {
1518 wGNOMERemoveClient(wwin
);
1521 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1526 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1527 (unsigned)frame
->window
);
1531 if (newFocusedWindow
!= owner
&& owner
) {
1532 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1534 wSetFocusTo(scr
, newFocusedWindow
);
1536 wWindowDestroy(wwin
);
1542 wWindowMap(WWindow
*wwin
)
1544 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1545 if (!wwin
->flags
.shaded
) {
1546 /* window will be remapped when getting MapNotify */
1547 XSelectInput(dpy
, wwin
->client_win
,
1548 wwin
->event_mask
& ~StructureNotifyMask
);
1549 XMapWindow(dpy
, wwin
->client_win
);
1550 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1552 wwin
->flags
.mapped
= 1;
1558 wWindowUnmap(WWindow
*wwin
)
1560 wwin
->flags
.mapped
= 0;
1562 /* prevent window withdrawal when getting UnmapNotify */
1563 XSelectInput(dpy
, wwin
->client_win
,
1564 wwin
->event_mask
& ~StructureNotifyMask
);
1565 XUnmapWindow(dpy
, wwin
->client_win
);
1566 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1568 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1574 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1579 #ifdef KEEP_XKB_LOCK_STATUS
1580 if (wPreferences
.modelock
) {
1581 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1583 #endif /* KEEP_XKB_LOCK_STATUS */
1585 wwin
->flags
.semi_focused
= 0;
1587 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1589 wwin
->flags
.focused
= 1;
1591 wWindowResetMouseGrabs(wwin
);
1593 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1595 if (owin
== wwin
|| !owin
)
1598 nowner
= wWindowFor(wwin
->transient_for
);
1600 /* new window is a transient for the old window */
1601 if (nowner
== owin
) {
1602 owin
->flags
.semi_focused
= 1;
1603 wWindowUnfocus(nowner
);
1607 oowner
= wWindowFor(owin
->transient_for
);
1609 /* new window is owner of old window */
1610 if (wwin
== oowner
) {
1611 wWindowUnfocus(owin
);
1616 wWindowUnfocus(owin
);
1620 /* new window has same owner of old window */
1621 if (oowner
== nowner
) {
1622 /* prevent unfocusing of owner */
1623 oowner
->flags
.semi_focused
= 0;
1624 wWindowUnfocus(owin
);
1625 oowner
->flags
.semi_focused
= 1;
1630 /* nowner != NULL && oowner != nowner */
1631 nowner
->flags
.semi_focused
= 1;
1632 wWindowUnfocus(nowner
);
1633 wWindowUnfocus(owin
);
1638 wWindowUnfocus(WWindow
*wwin
)
1640 CloseWindowMenu(wwin
->screen_ptr
);
1642 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1643 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1645 if (wwin
->transient_for
!=None
1646 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1648 owner
= wWindowFor(wwin
->transient_for
);
1649 if (owner
&& owner
->flags
.semi_focused
) {
1650 owner
->flags
.semi_focused
= 0;
1651 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1652 wWindowUnfocus(owner
);
1653 wFrameWindowPaint(owner
->frame
);
1657 wwin
->flags
.focused
= 0;
1659 wWindowResetMouseGrabs(wwin
);
1661 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1668 *----------------------------------------------------------------------
1670 * wWindowConstrainSize--
1671 * Constrains size for the client window, taking the maximal size,
1672 * window resize increments and other size hints into account.
1675 * The closest size to what was given that the client window can
1678 *----------------------------------------------------------------------
1681 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1683 int width
= *nwidth
;
1684 int height
= *nheight
;
1687 int minW
= 1, minH
= 1;
1688 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1689 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1690 int minAX
= -1, minAY
= -1;
1691 int maxAX
= -1, maxAY
= -1;
1695 if (wwin
->normal_hints
) {
1696 winc
= wwin
->normal_hints
->width_inc
;
1697 hinc
= wwin
->normal_hints
->height_inc
;
1698 minW
= wwin
->normal_hints
->min_width
;
1699 minH
= wwin
->normal_hints
->min_height
;
1700 maxW
= wwin
->normal_hints
->max_width
;
1701 maxH
= wwin
->normal_hints
->max_height
;
1702 if (wwin
->normal_hints
->flags
& PAspect
) {
1703 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1704 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1705 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1706 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1720 /* aspect ratio code borrowed from olwm */
1722 /* adjust max aspect ratio */
1723 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1724 if (maxAX
> maxAY
) {
1725 height
= (width
* maxAY
) / maxAX
;
1726 if (height
> maxH
) {
1728 width
= (height
* maxAX
) / maxAY
;
1731 width
= (height
* maxAX
) / maxAY
;
1734 height
= (width
* maxAY
) / maxAX
;
1739 /* adjust min aspect ratio */
1740 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1741 if (minAX
> minAY
) {
1742 height
= (width
* minAY
) / minAX
;
1743 if (height
< minH
) {
1745 width
= (height
* minAX
) / minAY
;
1748 width
= (height
* minAX
) / minAY
;
1751 height
= (width
* minAY
) / minAX
;
1758 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1760 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1764 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1766 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1775 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1777 WScreen
*scr
= wwin
->screen_ptr
;
1781 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1782 || workspace
== wwin
->frame
->workspace
)
1785 if (workspace
!= scr
->current_workspace
) {
1786 /* Sent to other workspace. Unmap window */
1787 if ((wwin
->flags
.mapped
1788 || wwin
->flags
.shaded
1789 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1790 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1792 wapp
= wApplicationOf(wwin
->main_window
);
1794 wapp
->last_workspace
= workspace
;
1796 if (wwin
->flags
.miniaturized
) {
1797 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1798 wwin
->icon
->mapped
= 0;
1801 wSetFocusTo(scr
, NULL
);
1805 /* brought to current workspace. Map window */
1806 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1807 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1808 wwin
->icon
->mapped
= 1;
1809 } else if (!wwin
->flags
.mapped
&&
1810 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1814 if (!IS_OMNIPRESENT(wwin
)) {
1815 wwin
->frame
->workspace
= workspace
;
1816 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1819 wGNOMEUpdateClientStateHint(wwin
, True
);
1822 wKWMUpdateClientWorkspace(wwin
);
1823 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1832 wWindowSynthConfigureNotify(WWindow
*wwin
)
1836 sevent
.type
= ConfigureNotify
;
1837 sevent
.xconfigure
.display
= dpy
;
1838 sevent
.xconfigure
.event
= wwin
->client_win
;
1839 sevent
.xconfigure
.window
= wwin
->client_win
;
1841 sevent
.xconfigure
.x
= wwin
->client
.x
;
1842 sevent
.xconfigure
.y
= wwin
->client
.y
;
1843 sevent
.xconfigure
.width
= wwin
->client
.width
;
1844 sevent
.xconfigure
.height
= wwin
->client
.height
;
1846 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1847 if (WFLAGP(wwin
, no_titlebar
))
1848 sevent
.xconfigure
.above
= None
;
1850 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1852 sevent
.xconfigure
.override_redirect
= False
;
1853 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1855 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1862 *----------------------------------------------------------------------
1863 * wWindowConfigure--
1864 * Configures the frame, decorations and client window to the
1865 * specified geometry. The geometry is not checked for validity,
1866 * wWindowConstrainSize() must be used for that.
1867 * The size parameters are for the client window, but the position is
1869 * The client window receives a ConfigureNotify event, according
1870 * to what ICCCM says.
1876 * Window size and position are changed and client window receives
1877 * a ConfigureNotify event.
1878 *----------------------------------------------------------------------
1881 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1883 int req_x
, req_y
; /* new position of the frame */
1884 int req_width
, req_height
; /* new size of the client */
1886 int synth_notify
= False
;
1889 resize
= (req_width
!=wwin
->client
.width
1890 || req_height
!=wwin
->client
.height
);
1892 * if the window is being moved but not resized then
1893 * send a synthetic ConfigureNotify
1895 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1896 synth_notify
= True
;
1899 if (WFLAGP(wwin
, dont_move_off
))
1900 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1901 req_width
, req_height
);
1903 if (req_width
< MIN_WINDOW_SIZE
)
1904 req_width
= MIN_WINDOW_SIZE
;
1905 if (req_height
< MIN_WINDOW_SIZE
)
1906 req_height
= MIN_WINDOW_SIZE
;
1908 /* If growing, resize inner part before frame,
1909 * if shrinking, resize frame before.
1910 * This will prevent the frame (that can have a different color)
1911 * to be exposed, causing flicker */
1912 if (req_height
> wwin
->frame
->core
->height
1913 || req_width
> wwin
->frame
->core
->width
)
1914 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1916 if (wwin
->flags
.shaded
) {
1917 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1918 req_width
, wwin
->frame
->core
->height
);
1919 wwin
->old_geometry
.height
= req_height
;
1923 h
= req_height
+ wwin
->frame
->top_width
1924 + wwin
->frame
->bottom_width
;
1926 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1929 if (!(req_height
> wwin
->frame
->core
->height
1930 || req_width
> wwin
->frame
->core
->width
))
1931 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1933 wwin
->client
.x
= req_x
;
1934 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1935 wwin
->client
.width
= req_width
;
1936 wwin
->client
.height
= req_height
;
1938 wwin
->client
.x
= req_x
;
1939 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1941 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1943 wwin
->frame_x
= req_x
;
1944 wwin
->frame_y
= req_y
;
1947 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1948 wWindowSetShape(wwin
);
1953 wWindowSynthConfigureNotify(wwin
);
1959 wWindowMove(wwin
, req_x
, req_y
)
1961 int req_x
, req_y
; /* new position of the frame */
1963 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1964 int synth_notify
= False
;
1966 /* Send a synthetic ConfigureNotify event for every window movement. */
1967 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1968 synth_notify
= True
;
1971 /* A single synthetic ConfigureNotify event is sent at the end of
1972 * a completed (opaque) movement in moveres.c */
1975 if (WFLAGP(wwin
, dont_move_off
))
1976 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1977 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1979 wwin
->client
.x
= req_x
;
1980 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1982 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1984 wwin
->frame_x
= req_x
;
1985 wwin
->frame_y
= req_y
;
1987 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1989 wWindowSynthConfigureNotify(wwin
);
1995 wWindowUpdateButtonImages(WWindow
*wwin
)
1997 WScreen
*scr
= wwin
->screen_ptr
;
1998 Pixmap pixmap
, mask
;
1999 WFrameWindow
*fwin
= wwin
->frame
;
2001 if (WFLAGP(wwin
, no_titlebar
))
2004 /* miniaturize button */
2006 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2007 if (wwin
->wm_gnustep_attr
2008 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2009 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2011 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2012 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2017 if (fwin
->lbutton_image
2018 && (fwin
->lbutton_image
->image
!= pixmap
2019 || fwin
->lbutton_image
->mask
!= mask
)) {
2020 wPixmapDestroy(fwin
->lbutton_image
);
2021 fwin
->lbutton_image
= NULL
;
2024 if (!fwin
->lbutton_image
) {
2025 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2026 fwin
->lbutton_image
->client_owned
= 1;
2027 fwin
->lbutton_image
->client_owned_mask
= 1;
2030 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2031 wPixmapDestroy(fwin
->lbutton_image
);
2033 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2037 #ifdef XKB_BUTTON_HINT
2038 if (!WFLAGP(wwin
, no_language_button
)) {
2039 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2040 wPixmapDestroy(fwin
->languagebutton_image
);
2042 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2048 if (!WFLAGP(wwin
, no_close_button
)) {
2049 if (wwin
->wm_gnustep_attr
2050 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
2051 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2053 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
2054 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2059 if (fwin
->rbutton_image
2060 && (fwin
->rbutton_image
->image
!= pixmap
2061 || fwin
->rbutton_image
->mask
!= mask
)) {
2062 wPixmapDestroy(fwin
->rbutton_image
);
2063 fwin
->rbutton_image
= NULL
;
2066 if (!fwin
->rbutton_image
) {
2067 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2068 fwin
->rbutton_image
->client_owned
= 1;
2069 fwin
->rbutton_image
->client_owned_mask
= 1;
2071 } else if (WFLAGP(wwin
, kill_close
)) {
2072 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2073 wPixmapDestroy(fwin
->rbutton_image
);
2075 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2076 } else if (WFLAGP(wwin
, broken_close
)) {
2077 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2078 wPixmapDestroy(fwin
->rbutton_image
);
2080 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2082 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2083 wPixmapDestroy(fwin
->rbutton_image
);
2085 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2089 /* force buttons to be redrawn */
2090 fwin
->flags
.need_texture_change
= 1;
2091 wFrameWindowPaint(fwin
);
2096 *---------------------------------------------------------------------------
2097 * wWindowConfigureBorders--
2098 * Update window border configuration according to attribute flags.
2100 *---------------------------------------------------------------------------
2103 wWindowConfigureBorders(WWindow
*wwin
)
2109 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2110 #ifdef XKB_BUTTON_HINT
2111 flags
|= WFF_LANGUAGE_BUTTON
;
2113 if (!WFLAGP(wwin
, no_titlebar
))
2114 flags
|= WFF_TITLEBAR
;
2115 if (!WFLAGP(wwin
, no_resizebar
))
2116 flags
|= WFF_RESIZEBAR
;
2117 if (wwin
->flags
.shaded
)
2118 flags
|= WFF_IS_SHADED
;
2120 oldh
= wwin
->frame
->top_width
;
2121 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2122 if (oldh
!= wwin
->frame
->top_width
) {
2123 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2125 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2126 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2127 wwin
->client
.width
, wwin
->client
.height
);
2131 if (!WFLAGP(wwin
, no_miniaturize_button
)
2132 && wwin
->frame
->flags
.hide_left_button
)
2133 flags
|= WFF_LEFT_BUTTON
;
2135 #ifdef XKB_BUTTON_HINT
2136 if (!WFLAGP(wwin
, no_language_button
)
2137 && wwin
->frame
->flags
.hide_language_button
)
2138 flags
|= WFF_LANGUAGE_BUTTON
;
2141 if (!WFLAGP(wwin
, no_close_button
)
2142 && wwin
->frame
->flags
.hide_right_button
)
2143 flags
|= WFF_RIGHT_BUTTON
;
2146 wWindowUpdateButtonImages(wwin
);
2147 wFrameWindowShowButton(wwin
->frame
, flags
);
2151 if (WFLAGP(wwin
, no_miniaturize_button
)
2152 && !wwin
->frame
->flags
.hide_left_button
)
2153 flags
|= WFF_LEFT_BUTTON
;
2155 #ifdef XKB_BUTTON_HINT
2156 if (WFLAGP(wwin
, no_language_button
)
2157 && !wwin
->frame
->flags
.hide_language_button
)
2158 flags
|= WFF_LANGUAGE_BUTTON
;
2161 if (WFLAGP(wwin
, no_close_button
)
2162 && !wwin
->frame
->flags
.hide_right_button
)
2163 flags
|= WFF_RIGHT_BUTTON
;
2166 wFrameWindowHideButton(wwin
->frame
, flags
);
2169 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2170 wWindowSetShape(wwin
);
2178 wWindowSaveState(WWindow
*wwin
)
2183 memset(data
, 0, sizeof(CARD32
)*10);
2184 data
[0] = wwin
->frame
->workspace
;
2185 data
[1] = wwin
->flags
.miniaturized
;
2186 data
[2] = wwin
->flags
.shaded
;
2187 data
[3] = wwin
->flags
.hidden
;
2189 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2190 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
)
2193 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2194 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2195 (unsigned char *)data
, 10);
2200 getSavedState(Window window
, WSavedState
**state
)
2204 unsigned long nitems_ret
;
2205 unsigned long bytes_after_ret
;
2208 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2209 True
, _XA_WINDOWMAKER_STATE
,
2210 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2211 (unsigned char **)&data
)!=Success
|| !data
)
2214 *state
= malloc(sizeof(WSavedState
));
2217 (*state
)->workspace
= data
[0];
2218 (*state
)->miniaturized
= data
[1];
2219 (*state
)->shaded
= data
[2];
2220 (*state
)->hidden
= data
[3];
2221 (*state
)->use_geometry
= data
[4];
2222 (*state
)->x
= data
[5];
2223 (*state
)->y
= data
[6];
2224 (*state
)->w
= data
[7];
2225 (*state
)->h
= data
[8];
2226 (*state
)->window_shortcuts
= data
[9];
2230 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2239 wWindowClearShape(WWindow
*wwin
)
2241 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2242 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2247 wWindowSetShape(WWindow
*wwin
)
2251 #ifdef OPTIMIZE_SHAPE
2256 /* only shape is the client's */
2257 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2261 /* Get array of rectangles describing the shape mask */
2262 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2268 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2274 /* insert our decoration rectangles in the rect list */
2275 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2278 if (!WFLAGP(wwin
, no_titlebar
)) {
2280 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2281 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2282 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2285 if (!WFLAGP(wwin
, no_resizebar
)) {
2287 urec
[count
].y
= wwin
->frame
->core
->height
2288 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2289 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2290 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2294 /* shape our frame window */
2295 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2296 0, wwin
->frame
->top_width
, urec
, count
,
2297 ShapeSet
, Unsorted
);
2303 #endif /* OPTIMIZE_SHAPE */
2305 if (!WFLAGP(wwin
, no_titlebar
)) {
2308 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2309 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2312 if (!WFLAGP(wwin
, no_resizebar
)) {
2314 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2315 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2316 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2320 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2321 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2323 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2324 0, wwin
->frame
->top_width
, wwin
->client_win
,
2325 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2330 /* ====================================================================== */
2333 getFocusMode(WWindow
*wwin
)
2337 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2338 if (wwin
->wm_hints
->input
== True
) {
2339 if (wwin
->protocols
.TAKE_FOCUS
)
2340 mode
= WFM_LOCALLY_ACTIVE
;
2344 if (wwin
->protocols
.TAKE_FOCUS
)
2345 mode
= WFM_GLOBALLY_ACTIVE
;
2347 mode
= WFM_NO_INPUT
;
2357 wWindowSetKeyGrabs(WWindow
*wwin
)
2362 for (i
=0; i
<WKBD_LAST
; i
++) {
2363 key
= &wKeyBindings
[i
];
2365 if (key
->keycode
==0)
2367 if (key
->modifier
!=AnyModifier
) {
2368 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2369 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2371 /* Also grab all modifier combinations possible that include,
2372 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2373 * work even if the NumLock/ScrollLock key is on.
2375 wHackedGrabKey(key
->keycode
, key
->modifier
,
2376 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2380 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2381 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2385 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2392 wWindowResetMouseGrabs(WWindow
*wwin
)
2394 /* Mouse grabs can't be done on the client window because of
2395 * ICCCM and because clients that try to do the same will crash.
2397 * But there is a problem wich makes tbar buttons of unfocused
2398 * windows not usable as the click goes to the frame window instead
2399 * of the button itself. Must figure a way to fix that.
2402 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2404 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2405 /* grabs for Meta+drag */
2406 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2407 True
, ButtonPressMask
, GrabModeSync
,
2408 GrabModeAsync
, None
, None
);
2411 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)) {
2412 /* the passive grabs to focus the window */
2413 if (wPreferences
.focus_mode
== WKF_CLICK
)
2414 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2415 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2423 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2426 if (attr
->flags
& GSExtraFlagsAttr
) {
2427 if (WFLAGP(wwin
, broken_close
) !=
2428 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2430 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2432 wWindowUpdateButtonImages(wwin
);
2440 wWindowAddSavedState(char *instance
, char *class, char *command
,
2441 pid_t pid
, WSavedState
*state
)
2443 WWindowState
*wstate
;
2445 wstate
= malloc(sizeof(WWindowState
));
2449 memset(wstate
, 0, sizeof(WWindowState
));
2452 wstate
->instance
= wstrdup(instance
);
2454 wstate
->class = wstrdup(class);
2456 wstate
->command
= wstrdup(command
);
2457 wstate
->state
= state
;
2459 wstate
->next
= windowState
;
2460 windowState
= wstate
;
2463 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2471 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2475 wWindowGetSavedState(Window win
)
2477 char *instance
, *class, *command
=NULL
;
2478 WWindowState
*wstate
= windowState
;
2485 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2487 command
= FlattenStringList(argv
, argc
);
2488 XFreeStringList(argv
);
2493 if (PropGetWMClass(win
, &class, &instance
)) {
2495 if (SAME(instance
, wstate
->instance
) &&
2496 SAME(class, wstate
->class) &&
2497 SAME(command
, wstate
->command
)) {
2500 wstate
= wstate
->next
;
2507 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2511 if (command
) free(command
);
2512 if (instance
) XFree(instance
);
2513 if (class) XFree(class);
2520 wWindowDeleteSavedState(WMagicNumber id
)
2522 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2524 if (!wstate
|| !windowState
)
2529 windowState
= wstate
->next
;
2531 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2532 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2534 if (wstate
->instance
) free(wstate
->instance
);
2535 if (wstate
->class) free(wstate
->class);
2536 if (wstate
->command
) free(wstate
->command
);
2537 free(wstate
->state
);
2541 if (tmp
->next
==wstate
) {
2542 tmp
->next
=wstate
->next
;
2544 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2545 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2547 if (wstate
->instance
) free(wstate
->instance
);
2548 if (wstate
->class) free(wstate
->class);
2549 if (wstate
->command
) free(wstate
->command
);
2550 free(wstate
->state
);
2561 wWindowDeleteSavedStatesForPID(pid_t pid
)
2563 WWindowState
*tmp
, *wstate
;
2569 if (tmp
->pid
== pid
) {
2570 wstate
= windowState
;
2571 windowState
= tmp
->next
;
2573 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2574 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2576 if (wstate
->instance
) free(wstate
->instance
);
2577 if (wstate
->class) free(wstate
->class);
2578 if (wstate
->command
) free(wstate
->command
);
2579 free(wstate
->state
);
2583 if (tmp
->next
->pid
==pid
) {
2585 tmp
->next
= wstate
->next
;
2587 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2588 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2590 if (wstate
->instance
) free(wstate
->instance
);
2591 if (wstate
->class) free(wstate
->class);
2592 if (wstate
->command
) free(wstate
->command
);
2593 free(wstate
->state
);
2603 /* ====================================================================== */
2606 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2608 WWindow
*wwin
= 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."));
2618 event
->xbutton
.state
&= ValidModMask
;
2620 CloseWindowMenu(wwin
->screen_ptr
);
2622 if (wPreferences
.focus_mode
==WKF_CLICK
2623 && !(event
->xbutton
.state
&ControlMask
)
2624 && !WFLAGP(wwin
, no_focusable
)) {
2625 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2628 if (event
->xbutton
.button
== Button1
)
2629 wRaiseFrame(wwin
->frame
->core
);
2631 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2632 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2633 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2634 GrabModeAsync
, GrabModeAsync
, None
,
2635 None
, CurrentTime
)!=GrabSuccess
) {
2637 wwarning("pointer grab failed for window move");
2643 if (event
->xbutton
.state
& MOD_MASK
) {
2644 /* move the window */
2645 wMouseMoveWindow(wwin
, event
);
2646 XUngrabPointer(dpy
, CurrentTime
);
2648 wMouseResizeWindow(wwin
, event
);
2649 XUngrabPointer(dpy
, CurrentTime
);
2656 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2658 WWindow
*wwin
= data
;
2660 event
->xbutton
.state
&= ValidModMask
;
2662 if (event
->xbutton
.button
==Button1
) {
2663 if (event
->xbutton
.state
== 0) {
2664 if (!WFLAGP(wwin
, no_shadeable
)) {
2666 if (wwin
->flags
.shaded
)
2667 wUnshadeWindow(wwin
);
2674 if (event
->xbutton
.state
& ControlMask
)
2675 dir
|= MAX_VERTICAL
;
2677 if (event
->xbutton
.state
& ShiftMask
) {
2678 dir
|= MAX_HORIZONTAL
;
2679 if (!(event
->xbutton
.state
& ControlMask
))
2680 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2683 /* maximize window */
2684 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2685 if (wwin
->flags
.maximized
)
2686 wUnmaximizeWindow(wwin
);
2688 wMaximizeWindow(wwin
, dir
);
2691 } else if (event
->xbutton
.button
==Button3
) {
2692 if (event
->xbutton
.state
& MOD_MASK
) {
2693 wHideOtherApplications(wwin
);
2695 } else if (event
->xbutton
.button
==Button2
) {
2696 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2702 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2704 WWindow
*wwin
= desc
->parent
;
2706 event
->xbutton
.state
&= ValidModMask
;
2708 CloseWindowMenu(wwin
->screen_ptr
);
2710 if (wPreferences
.focus_mode
==WKF_CLICK
2711 && !(event
->xbutton
.state
&ControlMask
)
2712 && !WFLAGP(wwin
, no_focusable
)) {
2713 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2715 if (event
->xbutton
.button
== Button1
) {
2716 wRaiseFrame(wwin
->frame
->core
);
2719 if (event
->xbutton
.state
& MOD_MASK
) {
2720 /* move the window */
2721 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2722 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2723 GrabModeAsync
, GrabModeAsync
, None
,
2724 None
, CurrentTime
)!=GrabSuccess
) {
2726 wwarning("pointer grab failed for window move");
2730 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2731 wMouseResizeWindow(wwin
, event
);
2733 wMouseMoveWindow(wwin
, event
);
2734 XUngrabPointer(dpy
, CurrentTime
);
2740 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2742 WWindow
*wwin
= (WWindow
*)data
;
2744 #ifndef NUMLOCK_HACK
2745 if ((event
->xbutton
.state
& ValidModMask
)
2746 != (event
->xbutton
.state
& ~LockMask
)) {
2747 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2748 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2751 event
->xbutton
.state
&= ValidModMask
;
2753 CloseWindowMenu(wwin
->screen_ptr
);
2755 if (wPreferences
.focus_mode
==WKF_CLICK
2756 && !(event
->xbutton
.state
&ControlMask
)
2757 && !WFLAGP(wwin
, no_focusable
)) {
2758 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2761 if (event
->xbutton
.button
== Button1
2762 || event
->xbutton
.button
== Button2
) {
2764 if (event
->xbutton
.button
== Button1
) {
2765 if (event
->xbutton
.state
& MOD_MASK
) {
2766 wLowerFrame(wwin
->frame
->core
);
2768 wRaiseFrame(wwin
->frame
->core
);
2771 if ((event
->xbutton
.state
& ShiftMask
)
2772 && !(event
->xbutton
.state
& ControlMask
)) {
2773 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2776 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2777 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2778 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2779 GrabModeAsync
, GrabModeAsync
, None
,
2780 None
, CurrentTime
)!=GrabSuccess
) {
2782 wwarning("pointer grab failed for window move");
2787 /* move the window */
2788 wMouseMoveWindow(wwin
, event
);
2790 XUngrabPointer(dpy
, CurrentTime
);
2791 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2792 && !wwin
->flags
.internal_window
2793 && !WCHECK_STATE(WSTATE_MODAL
)) {
2794 WObjDescriptor
*desc
;
2796 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2797 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2798 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2799 GrabModeAsync
, GrabModeAsync
, None
,
2800 None
, CurrentTime
)!=GrabSuccess
) {
2802 wwarning("pointer grab failed for window move");
2807 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2808 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2810 /* allow drag select */
2811 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2812 event
->xany
.send_event
= True
;
2813 (*desc
->handle_mousedown
)(desc
, event
);
2815 XUngrabPointer(dpy
, CurrentTime
);
2822 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2824 WWindow
*wwin
= data
;
2826 event
->xbutton
.state
&= ValidModMask
;
2828 CloseWindowMenu(wwin
->screen_ptr
);
2830 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2833 /* if control-click, kill the client */
2834 if (event
->xbutton
.state
& ControlMask
) {
2838 if (wwin
->flags
.olwm_push_pin_out
) {
2840 wwin
->flags
.olwm_push_pin_out
= 0;
2842 wOLWMChangePushpinState(wwin
, True
);
2844 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2849 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2850 /* send delete message */
2851 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2858 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2860 WWindow
*wwin
= data
;
2862 CloseWindowMenu(wwin
->screen_ptr
);
2864 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2867 /* send delete message */
2868 if (wwin
->protocols
.DELETE_WINDOW
) {
2869 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2876 #ifdef XKB_BUTTON_HINT
2878 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2880 WWindow
*wwin
= data
;
2881 WFrameWindow
*fwin
= wwin
->frame
;
2882 WScreen
*scr
= fwin
->screen_ptr
;
2883 XkbStateRec staterec
;
2886 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2888 tl
= wwin
->frame
->languagemode
;
2889 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2890 wwin
->frame
->last_languagemode
= tl
;
2891 wSetFocusTo(scr
, wwin
);
2892 wwin
->frame
->languagebutton_image
=
2893 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
2894 wwin
->frame
->languagemode
];
2895 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2896 if (event
->xbutton
.button
== Button3
)
2898 wRaiseFrame(fwin
->core
);
2904 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2906 WWindow
*wwin
= data
;
2908 event
->xbutton
.state
&= ValidModMask
;
2910 CloseWindowMenu(wwin
->screen_ptr
);
2912 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2915 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2916 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2920 if ((event
->xbutton
.state
& ControlMask
) ||
2921 (event
->xbutton
.button
== Button3
)) {
2923 wapp
= wApplicationOf(wwin
->main_window
);
2924 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2925 wHideApplication(wapp
);
2926 } else if (event
->xbutton
.state
==0) {
2927 wIconifyWindow(wwin
);