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 &scr
->window_title_gc
,
911 wwin
->frame
->flags
.is_client_window_frame
= 1;
912 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
914 /* setup button images */
915 wWindowUpdateButtonImages(wwin
);
917 /* hide unused buttons */
919 if (WFLAGP(wwin
, no_close_button
))
920 foo
|= WFF_RIGHT_BUTTON
;
921 if (WFLAGP(wwin
, no_miniaturize_button
))
922 foo
|= WFF_LEFT_BUTTON
;
923 #ifdef XKB_BUTTON_HINT
924 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
925 foo
|= WFF_LANGUAGE_BUTTON
;
928 wFrameWindowHideButton(wwin
->frame
, foo
);
930 wwin
->frame
->child
= wwin
;
933 /* emulate olwm push pin. Make the button look as pushed-in for
934 * the pinned-out state. When the button is clicked, it will
935 * revert to the normal position, which means the pin is pinned-in.
937 if (wwin
->flags
.olwm_push_pin_out
)
938 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
939 #endif /* OLWM_HINTS */
941 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
945 wwin
->frame
->workspace
= workspace
;
947 wwin
->frame
->on_click_left
= windowIconifyClick
;
948 #ifdef XKB_BUTTON_HINT
949 if (wPreferences
.modelock
)
950 wwin
->frame
->on_click_language
= windowLanguageClick
;
953 wwin
->frame
->on_click_right
= windowCloseClick
;
954 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
956 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
957 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
959 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
962 XSelectInput(dpy
, wwin
->client_win
,
963 wwin
->event_mask
& ~StructureNotifyMask
);
965 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
966 0, wwin
->frame
->top_width
);
968 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
974 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
976 /* if gravity is to the south, account for the border sizes */
978 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
982 * wWindowConfigure() will init the client window's size
983 * (wwin->client.{width,height}) and all other geometry
984 * related variables (frame_x,frame_y)
986 wWindowConfigure(wwin
, x
, y
, width
, height
);
988 /* to make sure the window receives it's new position after reparenting */
989 wWindowSynthConfigureNotify(wwin
);
992 *--------------------------------------------------
994 * Setup descriptors and save window to internal
997 *--------------------------------------------------
1000 if (wwin
->main_window
!=None
) {
1004 /* Leader windows do not necessary set themselves as leaders.
1005 * If this is the case, point the leader of this window to
1007 leader
= wWindowFor(wwin
->main_window
);
1008 if (leader
&& leader
->main_window
==None
) {
1009 leader
->main_window
= leader
->client_win
;
1011 app
= wApplicationCreate(scr
, wwin
->main_window
);
1013 app
->last_workspace
= workspace
;
1016 * Do application specific stuff, like setting application
1020 if (wwin
->flags
.hidden
) {
1021 /* if the window was set to hidden because it was hidden
1022 * in a previous incarnation and that state was restored */
1023 app
->flags
.hidden
= 1;
1026 if (app
->flags
.hidden
) {
1027 wwin
->flags
.hidden
= 1;
1032 /* setup the frame descriptor */
1033 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1034 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1035 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1037 /* don't let windows go away if we die */
1038 XAddToSaveSet(dpy
, window
);
1040 XLowerWindow(dpy
, window
);
1042 /* if window is in this workspace and should be mapped, then map it */
1043 if (!wwin
->flags
.miniaturized
1044 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1045 && !wwin
->flags
.hidden
&& !withdraw
) {
1047 /* The following "if" is to avoid crashing of clients that expect
1048 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1049 * after the return from this function.
1051 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1052 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1054 wClientSetState(wwin
, NormalState
, None
);
1058 /* if not auto focus, then map the window under the currently
1060 #define _WIDTH(w) (w)->frame->core->width
1061 #define _HEIGHT(w) (w)->frame->core->height
1062 if (!wPreferences
.auto_focus
&& scr
->focused_window
1063 && !scr
->flags
.startup
&& !transientOwner
1064 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1065 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1066 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1067 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1068 || wwin
->flags
.maximized
)) {
1069 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1077 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1078 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1080 * The brain damaged idiotic non-click to focus modes will
1081 * have trouble with this because:
1083 * 1. window is created and mapped by the client
1084 * 2. window is mapped by wmaker in small size
1085 * 3. window is animated to grow to normal size
1086 * 4. this function returns to normal event loop
1087 * 5. eventually, the EnterNotify event that would trigger
1088 * the window focusing (if the mouse is over that window)
1089 * will be processed by wmaker.
1090 * But since this event will be rather delayed
1091 * (step 3 has a large delay) the time when the event ocurred
1092 * and when it is processed, the client that owns that window
1093 * will reject the XSetInputFocus() for it.
1095 && (wPreferences
.focus_mode
==WKF_CLICK
1096 || wPreferences
.auto_focus
)) {
1097 DoWindowBirth(wwin
);
1103 /* setup stacking descriptor */
1104 if (transientOwner
) {
1105 /* && wPreferences.on_top_transients */
1106 if (transientOwner
) {
1107 wwin
->frame
->core
->stacking
->child_of
=
1108 transientOwner
->frame
->core
;
1111 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1115 if (!scr
->focused_window
) {
1116 /* first window on the list */
1119 scr
->focused_window
= wwin
;
1123 /* add window at beginning of focus window list */
1124 tmp
= scr
->focused_window
;
1133 wGNOMEUpdateClientStateHint(wwin
, True
);
1136 wKWMUpdateClientWorkspace(wwin
);
1137 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1143 *--------------------------------------------------
1145 * Final preparations before window is ready to go
1147 *--------------------------------------------------
1150 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1153 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1154 && !wwin
->flags
.hidden
) {
1155 if (((transientOwner
&& transientOwner
->flags
.focused
)
1156 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1157 wSetFocusTo(scr
, wwin
);
1159 wWindowResetMouseGrabs(wwin
);
1161 if (!WFLAGP(wwin
, no_bind_keys
)) {
1162 wWindowSetKeyGrabs(wwin
);
1165 wGNOMEUpdateClientListHint(scr
);
1168 wwin
->flags
.kwm_managed
= 1;
1170 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1173 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1175 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1178 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1179 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1181 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1182 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1188 *------------------------------------------------------------
1189 * Setup Notification Observers
1190 *------------------------------------------------------------
1192 WMAddNotificationObserver(appearanceObserver
, wwin
,
1193 WNWindowAppearanceSettingsChanged
, wwin
);
1197 *--------------------------------------------------
1199 * Cleanup temporary stuff
1201 *--------------------------------------------------
1205 wWindowDeleteSavedState(win_state
);
1207 /* If the window must be withdrawed, then do it now.
1208 * Must do some optimization, 'though */
1210 wwin
->flags
.mapped
= 0;
1211 wClientSetState(wwin
, WithdrawnState
, None
);
1212 wUnmanageWindow(wwin
, True
, False
);
1224 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1225 char *title
, int x
, int y
, int width
, int height
)
1230 wwin
= wWindowCreate();
1232 WMAddNotificationObserver(appearanceObserver
, wwin
,
1233 WNWindowAppearanceSettingsChanged
, wwin
);
1235 wwin
->flags
.internal_window
= 1;
1237 WSETUFLAG(wwin
, omnipresent
, 1);
1238 WSETUFLAG(wwin
, no_shadeable
, 1);
1239 WSETUFLAG(wwin
, no_resizable
, 1);
1240 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1242 wwin
->focus_mode
= WFM_PASSIVE
;
1244 wwin
->client_win
= window
;
1245 wwin
->screen_ptr
= scr
;
1247 wwin
->transient_for
= owner
;
1251 wwin
->client
.width
= width
;
1252 wwin
->client
.height
= height
;
1254 wwin
->frame_x
= wwin
->client
.x
;
1255 wwin
->frame_y
= wwin
->client
.y
;
1258 foo
= WFF_RIGHT_BUTTON
;
1259 foo
|= WFF_TITLEBAR
;
1260 #ifdef XKB_BUTTON_HINT
1261 foo
|= WFF_LANGUAGE_BUTTON
;
1264 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1265 wwin
->frame_x
, wwin
->frame_y
,
1267 scr
->window_title_texture
,
1268 scr
->resizebar_texture
,
1269 scr
->window_title_pixel
,
1270 &scr
->window_title_gc
,
1273 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1275 wwin
->frame
->flags
.is_client_window_frame
= 1;
1276 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1278 wFrameWindowChangeTitle(wwin
->frame
, title
);
1280 /* setup button images */
1281 wWindowUpdateButtonImages(wwin
);
1284 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1286 wwin
->frame
->child
= wwin
;
1288 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1290 #ifdef XKB_BUTTON_HINT
1291 if (wPreferences
.modelock
)
1292 wwin
->frame
->on_click_language
= windowLanguageClick
;
1295 wwin
->frame
->on_click_right
= windowCloseClick
;
1297 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1298 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1300 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1302 wwin
->client
.y
+= wwin
->frame
->top_width
;
1303 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1304 0, wwin
->frame
->top_width
);
1306 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1307 wwin
->client
.width
, wwin
->client
.height
);
1309 /* setup the frame descriptor */
1310 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1311 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1312 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1315 XLowerWindow(dpy
, window
);
1316 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1318 /* setup stacking descriptor */
1321 wPreferences
.on_top_transients
&&
1323 wwin
->transient_for
!=None
1324 && wwin
->transient_for
!=scr
->root_win
) {
1326 tmp
= wWindowFor(wwin
->transient_for
);
1328 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1330 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1334 if (!scr
->focused_window
) {
1335 /* first window on the list */
1338 scr
->focused_window
= wwin
;
1342 /* add window at beginning of focus window list */
1343 tmp
= scr
->focused_window
;
1351 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1353 /* if (wPreferences.auto_focus)*/
1354 wSetFocusTo(scr
, wwin
);
1356 wWindowResetMouseGrabs(wwin
);
1358 wWindowSetKeyGrabs(wwin
);
1360 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1367 *----------------------------------------------------------------------
1369 * Removes the frame window from a window and destroys all data
1370 * related to it. The window will be reparented back to the root window
1371 * if restore is True.
1374 * Everything related to the window is destroyed and the window
1375 * is removed from the window lists. Focus is set to the previous on the
1377 *----------------------------------------------------------------------
1380 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1382 WCoreWindow
*frame
= wwin
->frame
->core
;
1383 WWindow
*owner
= NULL
;
1384 WWindow
*newFocusedWindow
= NULL
;
1386 WScreen
*scr
= wwin
->screen_ptr
;
1390 wwin
->frame
->workspace
= -1;
1392 wKWMUpdateClientWorkspace(wwin
);
1395 /* First close attribute editor window if open */
1396 if (wwin
->flags
.inspector_open
) {
1397 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1398 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1401 /* Close window menu if it's open for this window */
1402 if (wwin
->flags
.menu_open_for_me
) {
1403 CloseWindowMenu(scr
);
1407 if (!wwin
->flags
.internal_window
)
1408 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1410 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1412 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1413 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1416 XUnmapWindow(dpy
, frame
->window
);
1418 XUnmapWindow(dpy
, wwin
->client_win
);
1420 /* deselect window */
1421 wSelectWindow(wwin
, False
);
1423 /* remove all pending events on window */
1424 /* I think this only matters for autoraise */
1425 if (wPreferences
.raise_delay
)
1426 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1430 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1432 /* reparent the window back to the root */
1434 wClientRestore(wwin
);
1436 if (wwin
->transient_for
!=scr
->root_win
) {
1437 owner
= wWindowFor(wwin
->transient_for
);
1439 if (!owner
->flags
.semi_focused
) {
1442 owner
->flags
.semi_focused
= 0;
1447 wasFocused
= wwin
->flags
.focused
;
1449 /* remove from window focus list */
1450 if (!wwin
->prev
&& !wwin
->next
) {
1451 /* was the only window */
1452 scr
->focused_window
= NULL
;
1453 newFocusedWindow
= NULL
;
1458 wwin
->prev
->next
= wwin
->next
;
1460 wwin
->next
->prev
= wwin
->prev
;
1462 scr
->focused_window
= wwin
->prev
;
1463 scr
->focused_window
->next
= NULL
;
1466 /* if in click to focus mode and the window
1467 * was a transient, focus the owner window
1470 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1471 tmp
= wWindowFor(wwin
->transient_for
);
1472 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1476 /* otherwise, focus the next one in the focus list */
1478 tmp
= scr
->focused_window
;
1480 if (!WFLAGP(tmp
, no_focusable
)
1481 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1486 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1487 newFocusedWindow
= tmp
;
1488 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1489 || wPreferences
.focus_mode
==WKF_POINTER
) {
1494 /* This is to let the root window get the keyboard input
1495 * if Sloppy focus mode and no other window get focus.
1496 * This way keybindings will not freeze.
1499 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1500 &foo
, &foo
, &foo
, &foo
, &mask
))
1501 tmp
= wWindowFor(win
);
1504 newFocusedWindow
= tmp
;
1506 newFocusedWindow
= NULL
;
1510 if (!wwin
->flags
.internal_window
) {
1512 wGNOMERemoveClient(wwin
);
1515 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1520 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1521 (unsigned)frame
->window
);
1525 if (newFocusedWindow
!= owner
&& owner
) {
1526 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1528 wSetFocusTo(scr
, newFocusedWindow
);
1530 wWindowDestroy(wwin
);
1536 wWindowMap(WWindow
*wwin
)
1538 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1539 if (!wwin
->flags
.shaded
) {
1540 /* window will be remapped when getting MapNotify */
1541 XSelectInput(dpy
, wwin
->client_win
,
1542 wwin
->event_mask
& ~StructureNotifyMask
);
1543 XMapWindow(dpy
, wwin
->client_win
);
1544 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1546 wwin
->flags
.mapped
= 1;
1552 wWindowUnmap(WWindow
*wwin
)
1554 wwin
->flags
.mapped
= 0;
1556 /* prevent window withdrawal when getting UnmapNotify */
1557 XSelectInput(dpy
, wwin
->client_win
,
1558 wwin
->event_mask
& ~StructureNotifyMask
);
1559 XUnmapWindow(dpy
, wwin
->client_win
);
1560 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1562 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1568 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1573 #ifdef KEEP_XKB_LOCK_STATUS
1574 if (wPreferences
.modelock
) {
1575 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1577 #endif /* KEEP_XKB_LOCK_STATUS */
1579 wwin
->flags
.semi_focused
= 0;
1581 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1583 wwin
->flags
.focused
= 1;
1585 wWindowResetMouseGrabs(wwin
);
1587 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1589 if (owin
== wwin
|| !owin
)
1592 nowner
= wWindowFor(wwin
->transient_for
);
1594 /* new window is a transient for the old window */
1595 if (nowner
== owin
) {
1596 owin
->flags
.semi_focused
= 1;
1597 wWindowUnfocus(nowner
);
1601 oowner
= wWindowFor(owin
->transient_for
);
1603 /* new window is owner of old window */
1604 if (wwin
== oowner
) {
1605 wWindowUnfocus(owin
);
1610 wWindowUnfocus(owin
);
1614 /* new window has same owner of old window */
1615 if (oowner
== nowner
) {
1616 /* prevent unfocusing of owner */
1617 oowner
->flags
.semi_focused
= 0;
1618 wWindowUnfocus(owin
);
1619 oowner
->flags
.semi_focused
= 1;
1624 /* nowner != NULL && oowner != nowner */
1625 nowner
->flags
.semi_focused
= 1;
1626 wWindowUnfocus(nowner
);
1627 wWindowUnfocus(owin
);
1632 wWindowUnfocus(WWindow
*wwin
)
1634 CloseWindowMenu(wwin
->screen_ptr
);
1636 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1637 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1639 if (wwin
->transient_for
!=None
1640 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1642 owner
= wWindowFor(wwin
->transient_for
);
1643 if (owner
&& owner
->flags
.semi_focused
) {
1644 owner
->flags
.semi_focused
= 0;
1645 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1646 wWindowUnfocus(owner
);
1647 wFrameWindowPaint(owner
->frame
);
1651 wwin
->flags
.focused
= 0;
1653 wWindowResetMouseGrabs(wwin
);
1655 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1662 *----------------------------------------------------------------------
1664 * wWindowConstrainSize--
1665 * Constrains size for the client window, taking the maximal size,
1666 * window resize increments and other size hints into account.
1669 * The closest size to what was given that the client window can
1672 *----------------------------------------------------------------------
1675 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1677 XSizeHints
*sizeh
= wwin
->normal_hints
;
1678 int width
= *nwidth
;
1679 int height
= *nheight
;
1680 int winc
= sizeh
->width_inc
;
1681 int hinc
= sizeh
->height_inc
;
1683 if (width
< sizeh
->min_width
)
1684 width
= sizeh
->min_width
;
1685 if (height
< sizeh
->min_height
)
1686 height
= sizeh
->min_height
;
1688 if (width
> sizeh
->max_width
)
1689 width
= sizeh
->max_width
;
1690 if (height
> sizeh
->max_height
)
1691 height
= sizeh
->max_height
;
1693 /* aspect ratio code borrowed from olwm */
1694 if (sizeh
->flags
& PAspect
) {
1695 /* adjust max aspect ratio */
1696 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1697 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1698 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1699 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1700 if (height
> sizeh
->max_height
) {
1701 height
= sizeh
->max_height
;
1702 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1705 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1706 if (width
> sizeh
->max_width
) {
1707 width
= sizeh
->max_width
;
1708 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1713 /* adjust min aspect ratio */
1714 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1715 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1716 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1717 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1718 if (height
< sizeh
->min_height
) {
1719 height
= sizeh
->min_height
;
1720 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1723 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1724 if (width
< sizeh
->min_width
) {
1725 width
= sizeh
->min_width
;
1726 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1732 if (sizeh
->base_width
!= 0) {
1733 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1734 + sizeh
->base_width
;
1736 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1740 if (sizeh
->base_width
!= 0) {
1741 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1742 + sizeh
->base_height
;
1744 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1745 + sizeh
->min_height
;
1754 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1756 WScreen
*scr
= wwin
->screen_ptr
;
1760 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1761 || workspace
== wwin
->frame
->workspace
)
1764 if (workspace
!= scr
->current_workspace
) {
1765 /* Sent to other workspace. Unmap window */
1766 if ((wwin
->flags
.mapped
1767 || wwin
->flags
.shaded
1768 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1769 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1771 wapp
= wApplicationOf(wwin
->main_window
);
1773 wapp
->last_workspace
= workspace
;
1775 if (wwin
->flags
.miniaturized
) {
1776 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1777 wwin
->icon
->mapped
= 0;
1780 wSetFocusTo(scr
, NULL
);
1784 /* brought to current workspace. Map window */
1785 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1786 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1787 wwin
->icon
->mapped
= 1;
1788 } else if (!wwin
->flags
.mapped
&&
1789 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1793 if (!IS_OMNIPRESENT(wwin
)) {
1794 wwin
->frame
->workspace
= workspace
;
1795 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1798 wGNOMEUpdateClientStateHint(wwin
, True
);
1801 wKWMUpdateClientWorkspace(wwin
);
1802 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1811 wWindowSynthConfigureNotify(WWindow
*wwin
)
1815 sevent
.type
= ConfigureNotify
;
1816 sevent
.xconfigure
.display
= dpy
;
1817 sevent
.xconfigure
.event
= wwin
->client_win
;
1818 sevent
.xconfigure
.window
= wwin
->client_win
;
1820 sevent
.xconfigure
.x
= wwin
->client
.x
;
1821 sevent
.xconfigure
.y
= wwin
->client
.y
;
1822 sevent
.xconfigure
.width
= wwin
->client
.width
;
1823 sevent
.xconfigure
.height
= wwin
->client
.height
;
1825 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1826 if (WFLAGP(wwin
, no_titlebar
))
1827 sevent
.xconfigure
.above
= None
;
1829 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1831 sevent
.xconfigure
.override_redirect
= False
;
1832 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1834 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1841 *----------------------------------------------------------------------
1842 * wWindowConfigure--
1843 * Configures the frame, decorations and client window to the
1844 * specified geometry. The geometry is not checked for validity,
1845 * wWindowConstrainSize() must be used for that.
1846 * The size parameters are for the client window, but the position is
1848 * The client window receives a ConfigureNotify event, according
1849 * to what ICCCM says.
1855 * Window size and position are changed and client window receives
1856 * a ConfigureNotify event.
1857 *----------------------------------------------------------------------
1860 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1862 int req_x
, req_y
; /* new position of the frame */
1863 int req_width
, req_height
; /* new size of the client */
1865 int synth_notify
= False
;
1868 resize
= (req_width
!=wwin
->client
.width
1869 || req_height
!=wwin
->client
.height
);
1871 * if the window is being moved but not resized then
1872 * send a synthetic ConfigureNotify
1874 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1875 synth_notify
= True
;
1878 if (WFLAGP(wwin
, dont_move_off
))
1879 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1880 req_width
, req_height
);
1882 if (req_width
< MIN_WINDOW_SIZE
)
1883 req_width
= MIN_WINDOW_SIZE
;
1884 if (req_height
< MIN_WINDOW_SIZE
)
1885 req_height
= MIN_WINDOW_SIZE
;
1887 /* If growing, resize inner part before frame,
1888 * if shrinking, resize frame before.
1889 * This will prevent the frame (that can have a different color)
1890 * to be exposed, causing flicker */
1891 if (req_height
> wwin
->frame
->core
->height
1892 || req_width
> wwin
->frame
->core
->width
)
1893 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1895 if (wwin
->flags
.shaded
) {
1896 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
1897 req_width
, wwin
->frame
->core
->height
);
1898 wwin
->old_geometry
.height
= req_height
;
1902 h
= req_height
+ wwin
->frame
->top_width
1903 + wwin
->frame
->bottom_width
;
1905 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
1908 if (!(req_height
> wwin
->frame
->core
->height
1909 || req_width
> wwin
->frame
->core
->width
))
1910 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1912 wwin
->client
.x
= req_x
;
1913 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1914 wwin
->client
.width
= req_width
;
1915 wwin
->client
.height
= req_height
;
1917 wwin
->client
.x
= req_x
;
1918 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1920 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1922 wwin
->frame_x
= req_x
;
1923 wwin
->frame_y
= req_y
;
1926 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1927 wWindowSetShape(wwin
);
1932 wWindowSynthConfigureNotify(wwin
);
1938 wWindowMove(wwin
, req_x
, req_y
)
1940 int req_x
, req_y
; /* new position of the frame */
1942 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1943 int synth_notify
= False
;
1945 /* Send a synthetic ConfigureNotify event for every window movement. */
1946 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1947 synth_notify
= True
;
1950 /* A single synthetic ConfigureNotify event is sent at the end of
1951 * a completed (opaque) movement in moveres.c */
1954 if (WFLAGP(wwin
, dont_move_off
))
1955 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1956 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1958 wwin
->client
.x
= req_x
;
1959 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1961 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1963 wwin
->frame_x
= req_x
;
1964 wwin
->frame_y
= req_y
;
1966 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1968 wWindowSynthConfigureNotify(wwin
);
1974 wWindowUpdateButtonImages(WWindow
*wwin
)
1976 WScreen
*scr
= wwin
->screen_ptr
;
1977 Pixmap pixmap
, mask
;
1978 WFrameWindow
*fwin
= wwin
->frame
;
1980 if (WFLAGP(wwin
, no_titlebar
))
1983 /* miniaturize button */
1985 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
1986 if (wwin
->wm_gnustep_attr
1987 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1988 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1990 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1991 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1996 if (fwin
->lbutton_image
1997 && (fwin
->lbutton_image
->image
!= pixmap
1998 || fwin
->lbutton_image
->mask
!= mask
)) {
1999 wPixmapDestroy(fwin
->lbutton_image
);
2000 fwin
->lbutton_image
= NULL
;
2003 if (!fwin
->lbutton_image
) {
2004 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2005 fwin
->lbutton_image
->client_owned
= 1;
2006 fwin
->lbutton_image
->client_owned_mask
= 1;
2009 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2010 wPixmapDestroy(fwin
->lbutton_image
);
2012 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2016 #ifdef XKB_BUTTON_HINT
2017 if (!WFLAGP(wwin
, no_language_button
)) {
2018 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2019 wPixmapDestroy(fwin
->languagebutton_image
);
2021 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2027 if (!WFLAGP(wwin
, no_close_button
)) {
2028 if (wwin
->wm_gnustep_attr
2029 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
2030 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2032 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
2033 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2038 if (fwin
->rbutton_image
2039 && (fwin
->rbutton_image
->image
!= pixmap
2040 || fwin
->rbutton_image
->mask
!= mask
)) {
2041 wPixmapDestroy(fwin
->rbutton_image
);
2042 fwin
->rbutton_image
= NULL
;
2045 if (!fwin
->rbutton_image
) {
2046 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2047 fwin
->rbutton_image
->client_owned
= 1;
2048 fwin
->rbutton_image
->client_owned_mask
= 1;
2050 } else if (WFLAGP(wwin
, kill_close
)) {
2051 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2052 wPixmapDestroy(fwin
->rbutton_image
);
2054 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2055 } else if (WFLAGP(wwin
, broken_close
)) {
2056 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2057 wPixmapDestroy(fwin
->rbutton_image
);
2059 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2061 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
2062 wPixmapDestroy(fwin
->rbutton_image
);
2064 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2068 /* force buttons to be redrawn */
2069 fwin
->flags
.need_texture_change
= 1;
2070 wFrameWindowPaint(fwin
);
2075 *---------------------------------------------------------------------------
2076 * wWindowConfigureBorders--
2077 * Update window border configuration according to attribute flags.
2079 *---------------------------------------------------------------------------
2082 wWindowConfigureBorders(WWindow
*wwin
)
2088 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2089 if (!WFLAGP(wwin
, no_titlebar
))
2090 flags
|= WFF_TITLEBAR
;
2091 if (!WFLAGP(wwin
, no_resizebar
))
2092 flags
|= WFF_RESIZEBAR
;
2093 if (wwin
->flags
.shaded
)
2094 flags
|= WFF_IS_SHADED
;
2096 oldh
= wwin
->frame
->top_width
;
2097 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2098 if (oldh
!= wwin
->frame
->top_width
) {
2099 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2101 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2102 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2103 wwin
->client
.width
, wwin
->client
.height
);
2107 if (!WFLAGP(wwin
, no_miniaturize_button
)
2108 && wwin
->frame
->flags
.hide_left_button
)
2109 flags
|= WFF_LEFT_BUTTON
;
2111 if (!WFLAGP(wwin
, no_close_button
)
2112 && wwin
->frame
->flags
.hide_right_button
)
2113 flags
|= WFF_RIGHT_BUTTON
;
2116 wWindowUpdateButtonImages(wwin
);
2117 wFrameWindowShowButton(wwin
->frame
, flags
);
2121 if (WFLAGP(wwin
, no_miniaturize_button
)
2122 && !wwin
->frame
->flags
.hide_left_button
)
2123 flags
|= WFF_LEFT_BUTTON
;
2125 if (WFLAGP(wwin
, no_close_button
)
2126 && !wwin
->frame
->flags
.hide_right_button
)
2127 flags
|= WFF_RIGHT_BUTTON
;
2130 wFrameWindowHideButton(wwin
->frame
, flags
);
2133 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2134 wWindowSetShape(wwin
);
2142 wWindowSaveState(WWindow
*wwin
)
2147 memset(data
, 0, sizeof(CARD32
)*10);
2148 data
[0] = wwin
->frame
->workspace
;
2149 data
[1] = wwin
->flags
.miniaturized
;
2150 data
[2] = wwin
->flags
.shaded
;
2151 data
[3] = wwin
->flags
.hidden
;
2153 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2154 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
)
2157 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2158 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2159 (unsigned char *)data
, 10);
2164 getSavedState(Window window
, WSavedState
**state
)
2168 unsigned long nitems_ret
;
2169 unsigned long bytes_after_ret
;
2172 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2173 True
, _XA_WINDOWMAKER_STATE
,
2174 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2175 (unsigned char **)&data
)!=Success
|| !data
)
2178 *state
= malloc(sizeof(WSavedState
));
2181 (*state
)->workspace
= data
[0];
2182 (*state
)->miniaturized
= data
[1];
2183 (*state
)->shaded
= data
[2];
2184 (*state
)->hidden
= data
[3];
2185 (*state
)->use_geometry
= data
[4];
2186 (*state
)->x
= data
[5];
2187 (*state
)->y
= data
[6];
2188 (*state
)->w
= data
[7];
2189 (*state
)->h
= data
[8];
2190 (*state
)->window_shortcuts
= data
[9];
2194 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2203 wWindowClearShape(WWindow
*wwin
)
2205 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2206 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2211 wWindowSetShape(WWindow
*wwin
)
2215 #ifdef OPTIMIZE_SHAPE
2220 /* only shape is the client's */
2221 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2225 /* Get array of rectangles describing the shape mask */
2226 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2232 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2238 /* insert our decoration rectangles in the rect list */
2239 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2242 if (!WFLAGP(wwin
, no_titlebar
)) {
2244 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2245 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2246 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2249 if (!WFLAGP(wwin
, no_resizebar
)) {
2251 urec
[count
].y
= wwin
->frame
->core
->height
2252 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2253 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2254 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2258 /* shape our frame window */
2259 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2260 0, wwin
->frame
->top_width
, urec
, count
,
2261 ShapeSet
, Unsorted
);
2267 #endif /* OPTIMIZE_SHAPE */
2269 if (!WFLAGP(wwin
, no_titlebar
)) {
2272 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2273 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2276 if (!WFLAGP(wwin
, no_resizebar
)) {
2278 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2279 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2280 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2284 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2285 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2287 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2288 0, wwin
->frame
->top_width
, wwin
->client_win
,
2289 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2294 /* ====================================================================== */
2297 getFocusMode(WWindow
*wwin
)
2301 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2302 if (wwin
->wm_hints
->input
== True
) {
2303 if (wwin
->protocols
.TAKE_FOCUS
)
2304 mode
= WFM_LOCALLY_ACTIVE
;
2308 if (wwin
->protocols
.TAKE_FOCUS
)
2309 mode
= WFM_GLOBALLY_ACTIVE
;
2311 mode
= WFM_NO_INPUT
;
2321 wWindowSetKeyGrabs(WWindow
*wwin
)
2326 for (i
=0; i
<WKBD_LAST
; i
++) {
2327 key
= &wKeyBindings
[i
];
2329 if (key
->keycode
==0)
2331 if (key
->modifier
!=AnyModifier
) {
2332 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2333 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2335 /* Also grab all modifier combinations possible that include,
2336 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2337 * work even if the NumLock/ScrollLock key is on.
2339 wHackedGrabKey(key
->keycode
, key
->modifier
,
2340 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2344 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2345 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2349 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2356 wWindowResetMouseGrabs(WWindow
*wwin
)
2358 /* Mouse grabs can't be done on the client window because of
2359 * ICCCM and because clients that try to do the same will crash.
2361 * But there is a problem wich makes tbar buttons of unfocused
2362 * windows not usable as the click goes to the frame window instead
2363 * of the button itself. Must figure a way to fix that.
2366 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2368 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2369 /* grabs for Meta+drag */
2370 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2371 True
, ButtonPressMask
, GrabModeSync
,
2372 GrabModeAsync
, None
, None
);
2375 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)) {
2376 /* the passive grabs to focus the window */
2377 if (wPreferences
.focus_mode
== WKF_CLICK
)
2378 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2379 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2387 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2390 if (attr
->flags
& GSExtraFlagsAttr
) {
2391 if (WFLAGP(wwin
, broken_close
) !=
2392 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2394 wwin
->client_flags
.broken_close
= !WFLAGP(wwin
, broken_close
);
2396 wWindowUpdateButtonImages(wwin
);
2404 wWindowAddSavedState(char *instance
, char *class, char *command
,
2405 pid_t pid
, WSavedState
*state
)
2407 WWindowState
*wstate
;
2409 wstate
= malloc(sizeof(WWindowState
));
2413 memset(wstate
, 0, sizeof(WWindowState
));
2416 wstate
->instance
= wstrdup(instance
);
2418 wstate
->class = wstrdup(class);
2420 wstate
->command
= wstrdup(command
);
2421 wstate
->state
= state
;
2423 wstate
->next
= windowState
;
2424 windowState
= wstate
;
2427 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2435 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2439 wWindowGetSavedState(Window win
)
2441 char *instance
, *class, *command
=NULL
;
2442 WWindowState
*wstate
= windowState
;
2449 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2451 command
= FlattenStringList(argv
, argc
);
2452 XFreeStringList(argv
);
2457 if (PropGetWMClass(win
, &class, &instance
)) {
2459 if (SAME(instance
, wstate
->instance
) &&
2460 SAME(class, wstate
->class) &&
2461 SAME(command
, wstate
->command
)) {
2464 wstate
= wstate
->next
;
2471 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2475 if (command
) free(command
);
2476 if (instance
) XFree(instance
);
2477 if (class) XFree(class);
2484 wWindowDeleteSavedState(WMagicNumber id
)
2486 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2488 if (!wstate
|| !windowState
)
2493 windowState
= wstate
->next
;
2495 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2496 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2498 if (wstate
->instance
) free(wstate
->instance
);
2499 if (wstate
->class) free(wstate
->class);
2500 if (wstate
->command
) free(wstate
->command
);
2501 free(wstate
->state
);
2505 if (tmp
->next
==wstate
) {
2506 tmp
->next
=wstate
->next
;
2508 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2509 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2511 if (wstate
->instance
) free(wstate
->instance
);
2512 if (wstate
->class) free(wstate
->class);
2513 if (wstate
->command
) free(wstate
->command
);
2514 free(wstate
->state
);
2525 wWindowDeleteSavedStatesForPID(pid_t pid
)
2527 WWindowState
*tmp
, *wstate
;
2533 if (tmp
->pid
== pid
) {
2534 wstate
= windowState
;
2535 windowState
= tmp
->next
;
2537 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2538 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2540 if (wstate
->instance
) free(wstate
->instance
);
2541 if (wstate
->class) free(wstate
->class);
2542 if (wstate
->command
) free(wstate
->command
);
2543 free(wstate
->state
);
2547 if (tmp
->next
->pid
==pid
) {
2549 tmp
->next
= wstate
->next
;
2551 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2552 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2554 if (wstate
->instance
) free(wstate
->instance
);
2555 if (wstate
->class) free(wstate
->class);
2556 if (wstate
->command
) free(wstate
->command
);
2557 free(wstate
->state
);
2567 /* ====================================================================== */
2570 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2572 WWindow
*wwin
= data
;
2574 #ifndef NUMLOCK_HACK
2575 if ((event
->xbutton
.state
& ValidModMask
)
2576 != (event
->xbutton
.state
& ~LockMask
)) {
2577 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2578 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2582 event
->xbutton
.state
&= ValidModMask
;
2584 CloseWindowMenu(wwin
->screen_ptr
);
2586 if (wPreferences
.focus_mode
==WKF_CLICK
2587 && !(event
->xbutton
.state
&ControlMask
)
2588 && !WFLAGP(wwin
, no_focusable
)) {
2589 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2592 if (event
->xbutton
.button
== Button1
)
2593 wRaiseFrame(wwin
->frame
->core
);
2595 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2596 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2597 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2598 GrabModeAsync
, GrabModeAsync
, None
,
2599 None
, CurrentTime
)!=GrabSuccess
) {
2601 wwarning("pointer grab failed for window move");
2607 if (event
->xbutton
.state
& MOD_MASK
) {
2608 /* move the window */
2609 wMouseMoveWindow(wwin
, event
);
2610 XUngrabPointer(dpy
, CurrentTime
);
2612 wMouseResizeWindow(wwin
, event
);
2613 XUngrabPointer(dpy
, CurrentTime
);
2620 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2622 WWindow
*wwin
= data
;
2624 event
->xbutton
.state
&= ValidModMask
;
2626 if (event
->xbutton
.button
==Button1
) {
2627 if (event
->xbutton
.state
== 0) {
2628 if (!WFLAGP(wwin
, no_shadeable
)) {
2630 if (wwin
->flags
.shaded
)
2631 wUnshadeWindow(wwin
);
2638 if (event
->xbutton
.state
& ControlMask
)
2639 dir
|= MAX_VERTICAL
;
2641 if (event
->xbutton
.state
& ShiftMask
) {
2642 dir
|= MAX_HORIZONTAL
;
2643 if (!(event
->xbutton
.state
& ControlMask
))
2644 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2647 /* maximize window */
2648 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2649 if (wwin
->flags
.maximized
)
2650 wUnmaximizeWindow(wwin
);
2652 wMaximizeWindow(wwin
, dir
);
2655 } else if (event
->xbutton
.button
==Button3
) {
2656 if (event
->xbutton
.state
& MOD_MASK
) {
2657 wHideOtherApplications(wwin
);
2659 } else if (event
->xbutton
.button
==Button2
) {
2660 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2666 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2668 WWindow
*wwin
= desc
->parent
;
2670 event
->xbutton
.state
&= ValidModMask
;
2672 CloseWindowMenu(wwin
->screen_ptr
);
2674 if (wPreferences
.focus_mode
==WKF_CLICK
2675 && !(event
->xbutton
.state
&ControlMask
)
2676 && !WFLAGP(wwin
, no_focusable
)) {
2677 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2679 if (event
->xbutton
.button
== Button1
) {
2680 wRaiseFrame(wwin
->frame
->core
);
2683 if (event
->xbutton
.state
& MOD_MASK
) {
2684 /* move the window */
2685 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2686 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2687 GrabModeAsync
, GrabModeAsync
, None
,
2688 None
, CurrentTime
)!=GrabSuccess
) {
2690 wwarning("pointer grab failed for window move");
2694 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2695 wMouseResizeWindow(wwin
, event
);
2697 wMouseMoveWindow(wwin
, event
);
2698 XUngrabPointer(dpy
, CurrentTime
);
2704 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2706 WWindow
*wwin
= (WWindow
*)data
;
2708 #ifndef NUMLOCK_HACK
2709 if ((event
->xbutton
.state
& ValidModMask
)
2710 != (event
->xbutton
.state
& ~LockMask
)) {
2711 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2712 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2715 event
->xbutton
.state
&= ValidModMask
;
2717 CloseWindowMenu(wwin
->screen_ptr
);
2719 if (wPreferences
.focus_mode
==WKF_CLICK
2720 && !(event
->xbutton
.state
&ControlMask
)
2721 && !WFLAGP(wwin
, no_focusable
)) {
2722 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2725 if (event
->xbutton
.button
== Button1
2726 || event
->xbutton
.button
== Button2
) {
2728 if (event
->xbutton
.button
== Button1
) {
2729 if (event
->xbutton
.state
& MOD_MASK
) {
2730 wLowerFrame(wwin
->frame
->core
);
2732 wRaiseFrame(wwin
->frame
->core
);
2735 if ((event
->xbutton
.state
& ShiftMask
)
2736 && !(event
->xbutton
.state
& ControlMask
)) {
2737 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2740 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2741 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2742 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2743 GrabModeAsync
, GrabModeAsync
, None
,
2744 None
, CurrentTime
)!=GrabSuccess
) {
2746 wwarning("pointer grab failed for window move");
2751 /* move the window */
2752 wMouseMoveWindow(wwin
, event
);
2754 XUngrabPointer(dpy
, CurrentTime
);
2755 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2756 && !wwin
->flags
.internal_window
2757 && !WCHECK_STATE(WSTATE_MODAL
)) {
2758 WObjDescriptor
*desc
;
2760 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2761 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2762 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2763 GrabModeAsync
, GrabModeAsync
, None
,
2764 None
, CurrentTime
)!=GrabSuccess
) {
2766 wwarning("pointer grab failed for window move");
2771 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2772 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2774 /* allow drag select */
2775 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2776 event
->xany
.send_event
= True
;
2777 (*desc
->handle_mousedown
)(desc
, event
);
2779 XUngrabPointer(dpy
, CurrentTime
);
2786 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2788 WWindow
*wwin
= data
;
2790 event
->xbutton
.state
&= ValidModMask
;
2792 CloseWindowMenu(wwin
->screen_ptr
);
2794 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2797 /* if control-click, kill the client */
2798 if (event
->xbutton
.state
& ControlMask
) {
2802 if (wwin
->flags
.olwm_push_pin_out
) {
2804 wwin
->flags
.olwm_push_pin_out
= 0;
2806 wOLWMChangePushpinState(wwin
, True
);
2808 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2813 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2814 /* send delete message */
2815 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2822 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2824 WWindow
*wwin
= data
;
2826 CloseWindowMenu(wwin
->screen_ptr
);
2828 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2831 /* send delete message */
2832 if (wwin
->protocols
.DELETE_WINDOW
) {
2833 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2840 #ifdef XKB_BUTTON_HINT
2842 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2844 WWindow
*wwin
= data
;
2845 WFrameWindow
*fwin
= wwin
->frame
;
2846 WScreen
*scr
= fwin
->screen_ptr
;
2847 XkbStateRec staterec
;
2850 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2852 tl
= wwin
->frame
->languagemode
;
2853 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2854 wwin
->frame
->last_languagemode
= tl
;
2855 wFrameWindowPaint(fwin
);
2856 wSetFocusTo(scr
, wwin
);
2857 if (event
->xbutton
.button
== Button3
)
2859 wRaiseFrame(fwin
->core
);
2865 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2867 WWindow
*wwin
= data
;
2869 event
->xbutton
.state
&= ValidModMask
;
2871 CloseWindowMenu(wwin
->screen_ptr
);
2873 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2876 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2877 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2881 if ((event
->xbutton
.state
& ControlMask
) ||
2882 (event
->xbutton
.button
== Button3
)) {
2884 wapp
= wApplicationOf(wwin
->main_window
);
2885 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2886 wHideApplication(wapp
);
2887 } else if (event
->xbutton
.state
==0) {
2888 wIconifyWindow(wwin
);