1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
29 #ifdef KEEP_XKB_LOCK_STATUS
30 #include <X11/XKBlib.h>
31 #endif /* KEEP_XKB_LOCK_STATUS */
38 /* For getting mouse wheel mappings from WINGs */
39 #include <WINGs/WINGs.h>
41 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
56 #include "workspace.h"
60 #include "superfluous.h"
62 #include "placement.h"
73 #define MOD_MASK wPreferences.modifier_mask
75 /****** Global Variables ******/
76 extern WShortKey wKeyBindings
[WKBD_LAST
];
79 extern Bool wShapeSupported
;
83 extern XContext wWinContext
;
86 extern Atom _XA_WM_DELETE_WINDOW
;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
88 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern Time LastTimestamp
;
91 /***** Local Stuff *****/
92 static WWindowState
*windowState
= NULL
;
93 static FocusMode
getFocusMode(WWindow
*wwin
);
94 static int getSavedState(Window window
, WSavedState
**state
);
95 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
97 /* frame window (during window grabs) */
98 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
101 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
105 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
107 #ifdef XKB_BUTTON_HINT
108 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
111 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
112 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
113 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
115 static void release_wwindowstate(WWindowState
*wstate
);
117 /****** Notification Observers ******/
119 static void appearanceObserver(void *self
, WMNotification
* notif
)
121 WWindow
*wwin
= (WWindow
*) self
;
122 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
124 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
127 if (flags
& WFontSettings
) {
128 wWindowConfigureBorders(wwin
);
129 if (wwin
->flags
.shaded
) {
130 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
131 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
132 wWindowSynthConfigureNotify(wwin
);
135 if (flags
& WTextureSettings
)
136 wwin
->frame
->flags
.need_texture_remake
= 1;
138 if (flags
& (WTextureSettings
| WColorSettings
)) {
139 if (wwin
->frame
->titlebar
)
140 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
142 wFrameWindowPaint(wwin
->frame
);
147 /* Return the WWindow associated with a given (Xlib) Window. */
148 WWindow
*wWindowFor(Window window
)
150 WObjDescriptor
*desc
;
155 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
158 if (desc
->parent_type
== WCLASS_WINDOW
)
160 else if (desc
->parent_type
== WCLASS_FRAME
) {
161 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
162 if (frame
->flags
.is_client_window_frame
)
169 WWindow
*wWindowCreate(void)
173 wwin
= wmalloc(sizeof(WWindow
));
176 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
177 wwin
->client_descriptor
.parent
= wwin
;
178 wwin
->client_descriptor
.self
= wwin
;
179 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
184 void wWindowDestroy(WWindow
*wwin
)
188 if (wwin
->screen_ptr
->cmap_window
== wwin
)
189 wwin
->screen_ptr
->cmap_window
= NULL
;
191 WMRemoveNotificationObserver(wwin
);
193 wwin
->flags
.destroyed
= 1;
195 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
196 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
199 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
201 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
202 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
203 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
207 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
208 wwin
->fake_group
->retainCount
--;
209 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
210 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
211 wwin
->fake_group
->leader
= None
;
212 wwin
->fake_group
->origLeader
= None
;
217 if (wwin
->normal_hints
)
218 XFree(wwin
->normal_hints
);
221 XFree(wwin
->wm_hints
);
223 if (wwin
->wm_instance
)
224 XFree(wwin
->wm_instance
);
227 XFree(wwin
->wm_class
);
229 if (wwin
->wm_gnustep_attr
)
230 wfree(wwin
->wm_gnustep_attr
);
232 if (wwin
->cmap_windows
)
233 XFree(wwin
->cmap_windows
);
235 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
238 wFrameWindowDestroy(wwin
->frame
);
241 RemoveFromStackList(wwin
->icon
->core
);
242 wIconDestroy(wwin
->icon
);
243 if (wPreferences
.auto_arrange_icons
)
244 wArrangeIcons(wwin
->screen_ptr
, True
);
246 if (wwin
->net_icon_image
)
247 RReleaseImage(wwin
->net_icon_image
);
252 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
254 if (gs_hints
->flags
& GSWindowStyleAttr
) {
255 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
256 wwin
->client_flags
.no_border
= 1;
257 wwin
->client_flags
.no_titlebar
= 1;
258 wwin
->client_flags
.no_closable
= 1;
259 wwin
->client_flags
.no_miniaturizable
= 1;
260 wwin
->client_flags
.no_resizable
= 1;
261 wwin
->client_flags
.no_close_button
= 1;
262 wwin
->client_flags
.no_miniaturize_button
= 1;
263 wwin
->client_flags
.no_resizebar
= 1;
265 wwin
->client_flags
.no_close_button
=
266 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
268 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
270 wwin
->client_flags
.no_miniaturize_button
=
271 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
273 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
275 wwin
->client_flags
.no_resizebar
=
276 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
278 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
280 /* these attributes supposedly imply in the existence
282 if (gs_hints
->window_style
& (WMResizableWindowMask
|
283 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
284 wwin
->client_flags
.no_titlebar
= 0;
286 wwin
->client_flags
.no_titlebar
=
287 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
292 /* setup the defaults */
293 wwin
->client_flags
.no_border
= 0;
294 wwin
->client_flags
.no_titlebar
= 0;
295 wwin
->client_flags
.no_closable
= 0;
296 wwin
->client_flags
.no_miniaturizable
= 0;
297 wwin
->client_flags
.no_resizable
= 0;
298 wwin
->client_flags
.no_close_button
= 0;
299 wwin
->client_flags
.no_miniaturize_button
= 0;
300 wwin
->client_flags
.no_resizebar
= 0;
302 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
303 wwin
->client_flags
.no_appicon
= 1;
306 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
308 WScreen
*scr
= wwin
->screen_ptr
;
310 /* sets global default stuff */
311 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
313 * Decoration setting is done in this precedence (lower to higher)
314 * - use global default in the resource database
315 * - guess some settings
316 * - use GNUstep/external window attributes
317 * - set hints specified for the app in the resource DB
320 WSETUFLAG(wwin
, broken_close
, 0);
322 if (wwin
->protocols
.DELETE_WINDOW
)
323 WSETUFLAG(wwin
, kill_close
, 0);
325 WSETUFLAG(wwin
, kill_close
, 1);
327 /* transients can't be iconified or maximized */
328 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
329 WSETUFLAG(wwin
, no_miniaturizable
, 1);
330 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
333 /* if the window can't be resized, remove the resizebar */
334 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
335 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
336 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
337 WSETUFLAG(wwin
, no_resizable
, 1);
338 WSETUFLAG(wwin
, no_resizebar
, 1);
341 /* set GNUstep window attributes */
342 if (wwin
->wm_gnustep_attr
) {
343 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
345 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
347 *level
= wwin
->wm_gnustep_attr
->window_level
;
349 * INT_MIN is the only illegal window level.
351 if (*level
== INT_MIN
)
352 *level
= INT_MIN
+ 1;
355 *level
= WMNormalLevel
;
358 int tmp_workspace
= -1;
359 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
362 wMWMCheckClientHints(wwin
);
363 #endif /* MWM_HINTS */
365 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
367 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
368 * have INT_MIN that means that no window level was requested. -Dan
370 if (tmp_level
== INT_MIN
) {
371 if (WFLAGP(wwin
, floating
))
372 *level
= WMFloatingLevel
;
373 else if (WFLAGP(wwin
, sunken
))
374 *level
= WMSunkenLevel
;
376 *level
= WMNormalLevel
;
381 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
382 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
383 if (transientOwner
) {
384 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
385 if (ownerLevel
> *level
)
390 if (tmp_workspace
>= 0)
391 *workspace
= tmp_workspace
% scr
->workspace_count
;
395 * Set attributes specified only for that window/class.
396 * This might do duplicate work with the 1st wDefaultFillAttributes().
398 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
399 &wwin
->defined_user_flags
, False
);
401 * Sanity checks for attributes that depend on other attributes
403 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
404 wwin
->user_flags
.emulate_appicon
= 0;
406 if (wwin
->main_window
!= None
) {
407 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
408 if (wapp
&& !wapp
->flags
.emulated
)
409 wwin
->user_flags
.emulate_appicon
= 0;
412 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
413 wwin
->user_flags
.emulate_appicon
= 0;
415 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
416 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
417 wwin
->user_flags
.sunken
= 0;
419 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
421 /* windows that have takefocus=False shouldn't take focus at all */
422 if (wwin
->focus_mode
== WFM_NO_INPUT
)
423 wwin
->client_flags
.no_focusable
= 1;
426 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
430 w1
= wwin
->frame
->core
->width
;
431 h1
= wwin
->frame
->core
->height
;
432 w2
= obscured
->frame
->core
->width
;
433 h2
= obscured
->frame
->core
->height
;
435 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
436 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
439 if (wwin
->frame_x
+ w1
< obscured
->frame_x
440 || wwin
->frame_y
+ h1
< obscured
->frame_y
441 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
447 static void fixLeaderProperties(WWindow
*wwin
)
449 XClassHint
*classHint
;
450 XWMHints
*hints
, *clientHints
;
451 XWindowAttributes attr
;
452 Window leaders
[2], window
;
453 char **argv
, *command
;
457 classHint
= XAllocClassHint();
458 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
459 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
461 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
465 leaders
[0] = wwin
->client_leader
;
466 leaders
[1] = wwin
->group_id
;
469 command
= GetCommandForWindow(wwin
->client_win
);
471 wfree(command
); /* command already set. nothing to do. */
473 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
476 for (i
= 0; i
< 2; i
++) {
479 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
480 classHint
->res_name
= wwin
->wm_instance
;
481 classHint
->res_class
= wwin
->wm_class
;
482 XSetClassHint(dpy
, window
, classHint
);
484 hints
= XGetWMHints(dpy
, window
);
487 } else if (clientHints
) {
488 /* set window group leader to self */
489 clientHints
->window_group
= window
;
490 clientHints
->flags
|= WindowGroupHint
;
491 XSetWMHints(dpy
, window
, clientHints
);
495 command
= GetCommandForWindow(window
);
497 wfree(command
); /* command already set. nothing to do. */
499 XSetCommand(dpy
, window
, argv
, argc
);
502 /* Make sure we get notification when this window is destroyed */
503 if (XGetWindowAttributes(dpy
, window
, &attr
))
504 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
515 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
517 XClassHint
*classHint
;
523 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
525 classHint
= XAllocClassHint();
526 classHint
->res_name
= instance
;
527 classHint
->res_class
= class;
528 XSetClassHint(dpy
, leader
, classHint
);
531 /* inherit these from the original leader if available */
532 hints
= XGetWMHints(dpy
, win
);
534 hints
= XAllocWMHints();
537 /* set window group leader to self */
538 hints
->window_group
= leader
;
539 hints
->flags
|= WindowGroupHint
;
540 XSetWMHints(dpy
, leader
, hints
);
543 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
544 XSetCommand(dpy
, leader
, argv
, argc
);
545 XFreeStringList(argv
);
551 static int matchIdentifier(const void *item
, const void *cdata
)
553 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
557 *----------------------------------------------------------------
559 * reparents the window and allocates a descriptor for it.
560 * Window manager hints and other hints are fetched to configure
561 * the window decoration attributes and others. User preferences
562 * for the window are used if available, to configure window
563 * decorations and some behaviour.
564 * If in startup, windows that are override redirect,
565 * unmapped and never were managed and are Withdrawn are not
569 * the new window descriptor
572 * The window is reparented and appropriate notification
573 * is done to the client. Input mask for the window is setup.
574 * The window descriptor is also associated with various window
575 * contexts and inserted in the head of the window list.
576 * Event handler contexts are associated for some objects
577 * (buttons, titlebar and resizebar)
579 *----------------------------------------------------------------
581 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
585 unsigned width
, height
;
586 XWindowAttributes wattribs
;
587 XSetWindowAttributes attribs
;
588 WWindowState
*win_state
;
589 WWindow
*transientOwner
= NULL
;
595 Bool withdraw
= False
;
602 /* make sure the window is still there */
603 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
608 /* if it's an override-redirect, ignore it */
609 if (wattribs
.override_redirect
) {
614 wm_state
= PropGetWindowState(window
);
616 /* if it's startup and the window is unmapped, don't manage it */
617 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
622 wwin
= wWindowCreate();
624 title
= wNETWMGetWindowName(window
);
626 wwin
->flags
.net_has_title
= 1;
627 else if (!wFetchName(dpy
, window
, &title
))
630 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
633 if (wShapeSupported
) {
638 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
639 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
640 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
641 wwin
->flags
.shaped
= b_shaped
;
645 /* Get hints and other information in properties */
646 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
648 /* setup descriptor */
649 wwin
->client_win
= window
;
650 wwin
->screen_ptr
= scr
;
651 wwin
->old_border_width
= wattribs
.border_width
;
652 wwin
->event_mask
= CLIENT_EVENTS
;
653 attribs
.event_mask
= CLIENT_EVENTS
;
654 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
655 attribs
.save_under
= False
;
657 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
658 XSetWindowBorderWidth(dpy
, window
, 0);
660 /* get hints from GNUstep app */
661 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
662 wwin
->flags
.is_gnustep
= 1;
664 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
665 wwin
->wm_gnustep_attr
= NULL
;
667 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
668 wwin
->flags
.is_dockapp
= 1;
672 wwin
->client_leader
= PropGetClientLeader(window
);
673 if (wwin
->client_leader
!= None
)
674 wwin
->main_window
= wwin
->client_leader
;
676 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
678 if (wwin
->wm_hints
) {
679 if (wwin
->wm_hints
->flags
& StateHint
) {
680 if (wwin
->wm_hints
->initial_state
== IconicState
) {
681 wwin
->flags
.miniaturized
= 1;
682 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
683 wwin
->flags
.is_dockapp
= 1;
688 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
689 wwin
->group_id
= wwin
->wm_hints
->window_group
;
690 /* window_group has priority over CLIENT_LEADER */
691 wwin
->main_window
= wwin
->group_id
;
693 wwin
->group_id
= None
;
696 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
697 wwin
->flags
.urgent
= 1;
698 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
701 wwin
->group_id
= None
;
704 PropGetProtocols(window
, &wwin
->protocols
);
706 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
707 wwin
->transient_for
= None
;
709 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
710 wwin
->transient_for
= scr
->root_win
;
712 transientOwner
= wWindowFor(wwin
->transient_for
);
713 if (transientOwner
&& transientOwner
->main_window
!= None
)
714 wwin
->main_window
= transientOwner
->main_window
;
718 /* guess the focus mode */
719 wwin
->focus_mode
= getFocusMode(wwin
);
721 /* get geometry stuff */
722 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
724 /* get colormap windows */
725 GetColormapWindows(wwin
);
728 * Setup the decoration/window attributes and
731 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
733 /* Make broken apps behave as a nice app. */
734 if (WFLAGP(wwin
, emulate_appicon
))
735 wwin
->main_window
= wwin
->client_win
;
737 fixLeaderProperties(wwin
);
739 wwin
->orig_main_window
= wwin
->main_window
;
741 if (wwin
->flags
.is_gnustep
)
742 WSETUFLAG(wwin
, shared_appicon
, 0);
744 if (wwin
->main_window
) {
745 extern Atom _XA_WINDOWMAKER_MENU
;
746 XTextProperty text_prop
;
748 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
))
749 WSETUFLAG(wwin
, shared_appicon
, 0);
752 if (wwin
->flags
.is_dockapp
)
753 WSETUFLAG(wwin
, shared_appicon
, 0);
755 if (wwin
->main_window
) {
756 WApplication
*app
= wApplicationOf(wwin
->main_window
);
757 if (app
&& app
->app_icon
)
758 WSETUFLAG(wwin
, shared_appicon
, 0);
761 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
762 char *buffer
, *instance
, *class;
763 WFakeGroupLeader
*fPtr
;
766 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
768 /* // only enter here if PropGetWMClass() succeds */
769 PropGetWMClass(wwin
->main_window
, &class, &instance
);
770 buffer
= StrConcatDot(instance
, class);
772 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
773 if (index
!= WANotFound
) {
774 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
775 if (fPtr
->retainCount
== 0)
776 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
780 if (fPtr
->origLeader
== None
) {
781 if (ADEQUATE(wwin
->main_window
)) {
783 fPtr
->origLeader
= wwin
->main_window
;
786 wwin
->fake_group
= fPtr
;
787 wwin
->main_window
= fPtr
->leader
;
790 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
792 fPtr
->identifier
= buffer
;
793 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
794 fPtr
->origLeader
= None
;
795 fPtr
->retainCount
= 1;
797 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
799 if (ADEQUATE(wwin
->main_window
)) {
801 fPtr
->origLeader
= wwin
->main_window
;
803 wwin
->fake_group
= fPtr
;
804 wwin
->main_window
= fPtr
->leader
;
816 * Setup the initial state of the window
818 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
819 wwin
->flags
.miniaturized
= 1;
821 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
822 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
824 wNETWMCheckInitialClientState(wwin
);
826 /* apply previous state if it exists and we're in startup */
827 if (scr
->flags
.startup
&& wm_state
>= 0) {
828 if (wm_state
== IconicState
)
829 wwin
->flags
.miniaturized
= 1;
830 else if (wm_state
== WithdrawnState
)
834 /* if there is a saved state (from file), restore it */
836 if (wwin
->main_window
!= None
)
837 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
839 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
841 if (win_state
&& !withdraw
) {
842 if (win_state
->state
->hidden
> 0)
843 wwin
->flags
.hidden
= win_state
->state
->hidden
;
845 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
846 wwin
->flags
.shaded
= win_state
->state
->shaded
;
848 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
849 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
851 if (!IS_OMNIPRESENT(wwin
)) {
852 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
854 if (w
< 0 || w
>= scr
->workspace_count
) {
855 workspace
= win_state
->state
->workspace
;
856 if (workspace
>= scr
->workspace_count
)
857 workspace
= scr
->current_workspace
;
862 workspace
= scr
->current_workspace
;
866 /* if we're restarting, restore saved state (from hints).
867 * This will overwrite previous */
871 if (getSavedState(window
, &wstate
)) {
872 wwin
->flags
.shaded
= wstate
->shaded
;
873 wwin
->flags
.hidden
= wstate
->hidden
;
874 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
875 wwin
->flags
.maximized
= wstate
->maximized
;
876 if (wwin
->flags
.maximized
) {
877 wwin
->old_geometry
.x
= wstate
->x
;
878 wwin
->old_geometry
.y
= wstate
->y
;
879 wwin
->old_geometry
.width
= wstate
->w
;
880 wwin
->old_geometry
.height
= wstate
->h
;
883 workspace
= wstate
->workspace
;
888 /* restore window shortcut */
889 if (wstate
!= NULL
|| win_state
!= NULL
) {
892 if (win_state
!= NULL
)
893 mask
= win_state
->state
->window_shortcuts
;
895 if (wstate
!= NULL
&& mask
== 0)
896 mask
= wstate
->window_shortcuts
;
901 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
902 if (mask
& (1 << i
)) {
903 if (!scr
->shortcutWindows
[i
])
904 scr
->shortcutWindows
[i
] = WMCreateArray(4);
906 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
916 /* don't let transients start miniaturized if their owners are not */
917 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
918 wwin
->flags
.miniaturized
= 0;
920 wwin
->wm_hints
->initial_state
= NormalState
;
923 /* set workspace on which the window starts */
924 if (workspace
>= 0) {
925 if (workspace
> scr
->workspace_count
- 1)
926 workspace
= workspace
% scr
->workspace_count
;
930 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
932 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
935 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
936 workspace
= transientOwner
->frame
->workspace
;
938 workspace
= scr
->current_workspace
;
942 /* setup window geometry */
943 if (win_state
&& win_state
->state
->w
> 0) {
944 width
= win_state
->state
->w
;
945 height
= win_state
->state
->h
;
948 wWindowConstrainSize(wwin
, &width
, &height
);
950 /* do not ask for window placement if the window is
951 * transient, during startup, if the initial workspace is another one
952 * or if the window wants to start iconic.
953 * If geometry was saved, restore it. */
955 Bool dontBring
= False
;
957 if (win_state
&& win_state
->state
->w
> 0) {
958 x
= win_state
->state
->x
;
959 y
= win_state
->state
->y
;
960 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
961 && !scr
->flags
.startup
962 && workspace
== scr
->current_workspace
963 && !wwin
->flags
.miniaturized
964 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
966 if (transientOwner
&& transientOwner
->flags
.mapped
) {
967 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
971 x
= transientOwner
->frame_x
+
972 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
973 y
= transientOwner
->frame_y
+
974 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
976 /* limit transient windows to be inside their parent's head */
977 rect
.pos
.x
= transientOwner
->frame_x
;
978 rect
.pos
.y
= transientOwner
->frame_y
;
979 rect
.size
.width
= transientOwner
->frame
->core
->width
;
980 rect
.size
.height
= transientOwner
->frame
->core
->height
;
982 head
= wGetHeadForRect(scr
, rect
);
983 rect
= wGetRectForHead(scr
, head
);
987 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
988 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
992 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
993 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
996 PlaceWindow(wwin
, &x
, &y
, width
, height
);
999 if (wPreferences
.window_placement
== WPM_MANUAL
)
1002 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1007 /* Make spash screens come out in the center of a head
1008 * trouble is that most splashies never get here
1009 * they are managed trough atoms but god knows where.
1010 * Dan, do you know ? -peter
1012 * Most of them are not managed, they have set
1013 * OverrideRedirect, which means we can't do anything about
1016 /* xinerama checks for: across head and dead space */
1019 rect
.size
.width
= width
;
1020 rect
.size
.height
= height
;
1022 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1024 if (flags
& XFLAG_DEAD
)
1027 if (flags
& XFLAG_MULTIPLE
)
1031 switch (reposition
) {
1033 head
= wGetHeadForPointerLocation(scr
);
1034 rect
= wGetRectForHead(scr
, head
);
1036 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1037 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1041 rect
= wGetRectForHead(scr
, head
);
1045 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1046 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1050 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1051 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1060 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1061 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1064 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1066 if (wwin
->flags
.urgent
) {
1067 if (!IS_OMNIPRESENT(wwin
))
1068 wwin
->flags
.omnipresent
^= 1;
1071 /* Create frame, borders and do reparenting */
1072 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1073 #ifdef XKB_BUTTON_HINT
1074 if (wPreferences
.modelock
)
1075 foo
|= WFF_LANGUAGE_BUTTON
;
1077 if (HAS_TITLEBAR(wwin
))
1078 foo
|= WFF_TITLEBAR
;
1080 if (HAS_RESIZEBAR(wwin
))
1081 foo
|= WFF_RESIZEBAR
;
1083 if (HAS_BORDER(wwin
))
1086 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1087 x
, y
, width
, height
,
1088 &wPreferences
.window_title_clearance
,
1089 &wPreferences
.window_title_min_height
,
1090 &wPreferences
.window_title_max_height
,
1092 scr
->window_title_texture
,
1093 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1094 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1096 wwin
->frame
->flags
.is_client_window_frame
= 1;
1097 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1099 /* setup button images */
1100 wWindowUpdateButtonImages(wwin
);
1102 /* hide unused buttons */
1104 if (WFLAGP(wwin
, no_close_button
))
1105 foo
|= WFF_RIGHT_BUTTON
;
1107 if (WFLAGP(wwin
, no_miniaturize_button
))
1108 foo
|= WFF_LEFT_BUTTON
;
1110 #ifdef XKB_BUTTON_HINT
1111 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1112 foo
|= WFF_LANGUAGE_BUTTON
;
1115 wFrameWindowHideButton(wwin
->frame
, foo
);
1117 wwin
->frame
->child
= wwin
;
1118 wwin
->frame
->workspace
= workspace
;
1119 wwin
->frame
->on_click_left
= windowIconifyClick
;
1121 #ifdef XKB_BUTTON_HINT
1122 if (wPreferences
.modelock
)
1123 wwin
->frame
->on_click_language
= windowLanguageClick
;
1126 wwin
->frame
->on_click_right
= windowCloseClick
;
1127 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1128 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1129 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1130 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1132 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1133 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1134 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1139 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1141 /* if gravity is to the south, account for the border sizes */
1143 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1147 * wWindowConfigure() will init the client window's size
1148 * (wwin->client.{width,height}) and all other geometry
1149 * related variables (frame_x,frame_y) */
1150 wWindowConfigure(wwin
, x
, y
, width
, height
);
1152 /* to make sure the window receives it's new position after reparenting */
1153 wWindowSynthConfigureNotify(wwin
);
1155 /* Setup descriptors and save window to internal lists */
1156 if (wwin
->main_window
!= None
) {
1160 /* Leader windows do not necessary set themselves as leaders.
1161 * If this is the case, point the leader of this window to
1163 leader
= wWindowFor(wwin
->main_window
);
1164 if (leader
&& leader
->main_window
== None
)
1165 leader
->main_window
= leader
->client_win
;
1167 app
= wApplicationCreate(wwin
);
1169 app
->last_workspace
= workspace
;
1171 /* Do application specific stuff, like setting application
1172 * wide attributes. */
1174 if (wwin
->flags
.hidden
) {
1175 /* if the window was set to hidden because it was hidden
1176 * in a previous incarnation and that state was restored */
1177 app
->flags
.hidden
= 1;
1178 } else if (app
->flags
.hidden
) {
1179 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1180 wwin
->flags
.hidden
= 1;
1182 wUnhideApplication(app
, False
, False
);
1190 /* setup the frame descriptor */
1191 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1192 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1193 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1195 /* don't let windows go away if we die */
1196 XAddToSaveSet(dpy
, window
);
1198 XLowerWindow(dpy
, window
);
1200 /* if window is in this workspace and should be mapped, then map it */
1201 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1202 && !wwin
->flags
.hidden
&& !withdraw
) {
1204 /* The following "if" is to avoid crashing of clients that expect
1205 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1206 * after the return from this function. */
1207 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1208 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1210 wClientSetState(wwin
, NormalState
, None
);
1212 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1213 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1215 * The brain damaged idiotic non-click to focus modes will
1216 * have trouble with this because:
1218 * 1. window is created and mapped by the client
1219 * 2. window is mapped by wmaker in small size
1220 * 3. window is animated to grow to normal size
1221 * 4. this function returns to normal event loop
1222 * 5. eventually, the EnterNotify event that would trigger
1223 * the window focusing (if the mouse is over that window)
1224 * will be processed by wmaker.
1225 * But since this event will be rather delayed
1226 * (step 3 has a large delay) the time when the event ocurred
1227 * and when it is processed, the client that owns that window
1228 * will reject the XSetInputFocus() for it.
1230 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1231 DoWindowBirth(wwin
);
1236 /* setup stacking descriptor */
1238 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1240 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1242 if (!scr
->focused_window
) {
1243 /* first window on the list */
1246 scr
->focused_window
= wwin
;
1250 /* add window at beginning of focus window list */
1251 tmp
= scr
->focused_window
;
1260 /* raise is set to true if we un-hid the app when this window was born.
1261 * we raise, else old windows of this app will be above this new one. */
1263 wRaiseFrame(wwin
->frame
->core
);
1265 /* Update name must come after WApplication stuff is done */
1266 wWindowUpdateName(wwin
, title
);
1272 /* Final preparations before window is ready to go */
1273 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1275 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1276 if (((transientOwner
&& transientOwner
->flags
.focused
)
1277 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1279 /* only auto_focus if on same screen as mouse
1280 * (and same head for xinerama mode)
1281 * TODO: make it an option */
1283 /*TODO add checking the head of the window, is it available? */
1284 short same_screen
= 0, same_head
= 1;
1290 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1291 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1294 if (same_screen
== 1 && same_head
== 1)
1295 wSetFocusTo(scr
, wwin
);
1298 wWindowResetMouseGrabs(wwin
);
1300 if (!WFLAGP(wwin
, no_bind_keys
))
1301 wWindowSetKeyGrabs(wwin
);
1303 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1304 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1306 /* Setup Notification Observers */
1307 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1309 /* Cleanup temporary stuff */
1311 wWindowDeleteSavedState(win_state
);
1313 /* If the window must be withdrawed, then do it now.
1314 * Must do some optimization, 'though */
1316 wwin
->flags
.mapped
= 0;
1317 wClientSetState(wwin
, WithdrawnState
, None
);
1318 wUnmanageWindow(wwin
, True
, False
);
1325 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1326 const char *title
, int x
, int y
, int width
, int height
)
1331 wwin
= wWindowCreate();
1333 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1335 wwin
->flags
.internal_window
= 1;
1337 WSETUFLAG(wwin
, omnipresent
, 1);
1338 WSETUFLAG(wwin
, no_shadeable
, 1);
1339 WSETUFLAG(wwin
, no_resizable
, 1);
1340 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1342 wwin
->focus_mode
= WFM_PASSIVE
;
1343 wwin
->client_win
= window
;
1344 wwin
->screen_ptr
= scr
;
1345 wwin
->transient_for
= owner
;
1348 wwin
->client
.width
= width
;
1349 wwin
->client
.height
= height
;
1350 wwin
->frame_x
= wwin
->client
.x
;
1351 wwin
->frame_y
= wwin
->client
.y
;
1353 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1354 foo
|= WFF_TITLEBAR
;
1355 #ifdef XKB_BUTTON_HINT
1356 foo
|= WFF_LANGUAGE_BUTTON
;
1359 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1360 wwin
->frame_x
, wwin
->frame_y
,
1362 &wPreferences
.window_title_clearance
,
1363 &wPreferences
.window_title_min_height
,
1364 &wPreferences
.window_title_max_height
,
1366 scr
->window_title_texture
,
1367 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1368 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1370 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1372 wwin
->frame
->flags
.is_client_window_frame
= 1;
1373 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1375 wFrameWindowChangeTitle(wwin
->frame
, title
);
1377 /* setup button images */
1378 wWindowUpdateButtonImages(wwin
);
1381 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1383 wwin
->frame
->child
= wwin
;
1384 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1386 #ifdef XKB_BUTTON_HINT
1387 if (wPreferences
.modelock
)
1388 wwin
->frame
->on_click_language
= windowLanguageClick
;
1391 wwin
->frame
->on_click_right
= windowCloseClick
;
1392 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1393 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1394 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1395 wwin
->client
.y
+= wwin
->frame
->top_width
;
1397 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1398 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1400 /* setup the frame descriptor */
1401 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1402 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1403 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1405 XLowerWindow(dpy
, window
);
1406 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1408 /* setup stacking descriptor */
1409 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1411 tmp
= wWindowFor(wwin
->transient_for
);
1413 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1415 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1418 if (!scr
->focused_window
) {
1419 /* first window on the list */
1422 scr
->focused_window
= wwin
;
1426 /* add window at beginning of focus window list */
1427 tmp
= scr
->focused_window
;
1435 if (wwin
->flags
.is_gnustep
== 0)
1436 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1438 /* if (wPreferences.auto_focus) */
1439 wSetFocusTo(scr
, wwin
);
1440 wWindowResetMouseGrabs(wwin
);
1441 wWindowSetKeyGrabs(wwin
);
1447 *----------------------------------------------------------------------
1449 * Removes the frame window from a window and destroys all data
1450 * related to it. The window will be reparented back to the root window
1451 * if restore is True.
1454 * Everything related to the window is destroyed and the window
1455 * is removed from the window lists. Focus is set to the previous on the
1457 *----------------------------------------------------------------------
1459 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1461 WCoreWindow
*frame
= wwin
->frame
->core
;
1462 WWindow
*owner
= NULL
;
1463 WWindow
*newFocusedWindow
= NULL
;
1465 WScreen
*scr
= wwin
->screen_ptr
;
1467 /* First close attribute editor window if open */
1468 if (wwin
->flags
.inspector_open
)
1469 wCloseInspectorForWindow(wwin
);
1471 /* Close window menu if it's open for this window */
1472 if (wwin
->flags
.menu_open_for_me
)
1473 CloseWindowMenu(scr
);
1476 if (!wwin
->flags
.internal_window
)
1477 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1479 /* If this is a leader window, we still need to listen for
1480 * DestroyNotify and PropertyNotify. */
1481 if (wApplicationOf(wwin
->client_win
))
1482 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1484 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1486 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1487 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1490 XUnmapWindow(dpy
, frame
->window
);
1492 XUnmapWindow(dpy
, wwin
->client_win
);
1494 /* deselect window */
1495 wSelectWindow(wwin
, False
);
1497 /* remove all pending events on window */
1498 /* I think this only matters for autoraise */
1499 if (wPreferences
.raise_delay
)
1500 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1504 /* reparent the window back to the root */
1506 wClientRestore(wwin
);
1508 if (wwin
->transient_for
!= scr
->root_win
) {
1509 owner
= wWindowFor(wwin
->transient_for
);
1511 if (!owner
->flags
.semi_focused
)
1514 owner
->flags
.semi_focused
= 0;
1518 wasFocused
= wwin
->flags
.focused
;
1520 /* remove from window focus list */
1521 if (!wwin
->prev
&& !wwin
->next
) {
1522 /* was the only window */
1523 scr
->focused_window
= NULL
;
1524 newFocusedWindow
= NULL
;
1529 wwin
->prev
->next
= wwin
->next
;
1532 wwin
->next
->prev
= wwin
->prev
;
1534 scr
->focused_window
= wwin
->prev
;
1535 scr
->focused_window
->next
= NULL
;
1538 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1540 /* if in click to focus mode and the window
1541 * was a transient, focus the owner window
1544 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1545 tmp
= wWindowFor(wwin
->transient_for
);
1546 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1550 /* otherwise, focus the next one in the focus list */
1552 tmp
= scr
->focused_window
;
1553 while (tmp
) { /* look for one in the window list first */
1554 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1555 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1559 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1560 tmp
= scr
->focused_window
;
1562 if (!WFLAGP(tmp
, no_focusable
)
1563 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1570 newFocusedWindow
= tmp
;
1572 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1577 /* This is to let the root window get the keyboard input
1578 * if Sloppy focus mode and no other window get focus.
1579 * This way keybindings will not freeze.
1582 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1583 tmp
= wWindowFor(win
);
1586 newFocusedWindow
= tmp
;
1588 newFocusedWindow
= NULL
;
1592 if (!wwin
->flags
.internal_window
)
1593 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1595 if (newFocusedWindow
!= owner
&& owner
) {
1596 if (wwin
->flags
.is_gnustep
== 0)
1597 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1599 wSetFocusTo(scr
, newFocusedWindow
);
1602 /* Close menu and unhighlight */
1603 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1604 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1605 if (oapp
&& oapp
!= napp
) {
1606 wAppMenuUnmap(oapp
->menu
);
1607 if (wPreferences
.highlight_active_app
)
1608 wApplicationDeactivate(oapp
);
1611 wNETCleanupFrameExtents(wwin
);
1613 wWindowDestroy(wwin
);
1617 void wWindowMap(WWindow
*wwin
)
1619 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1620 if (!wwin
->flags
.shaded
) {
1621 /* window will be remapped when getting MapNotify */
1622 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1623 XMapWindow(dpy
, wwin
->client_win
);
1624 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1626 wwin
->flags
.mapped
= 1;
1630 void wWindowUnmap(WWindow
*wwin
)
1632 wwin
->flags
.mapped
= 0;
1634 /* prevent window withdrawal when getting UnmapNotify */
1635 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1636 XUnmapWindow(dpy
, wwin
->client_win
);
1637 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1639 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1642 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1647 #ifdef KEEP_XKB_LOCK_STATUS
1648 if (wPreferences
.modelock
)
1649 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1650 #endif /* KEEP_XKB_LOCK_STATUS */
1652 wwin
->flags
.semi_focused
= 0;
1654 if (wwin
->flags
.is_gnustep
== 0)
1655 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1657 wwin
->flags
.focused
= 1;
1659 wWindowResetMouseGrabs(wwin
);
1661 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1663 if (owin
== wwin
|| !owin
)
1666 nowner
= wWindowFor(wwin
->transient_for
);
1668 /* new window is a transient for the old window */
1669 if (nowner
== owin
) {
1670 owin
->flags
.semi_focused
= 1;
1671 wWindowUnfocus(nowner
);
1675 oowner
= wWindowFor(owin
->transient_for
);
1677 /* new window is owner of old window */
1678 if (wwin
== oowner
) {
1679 wWindowUnfocus(owin
);
1684 wWindowUnfocus(owin
);
1688 /* new window has same owner of old window */
1689 if (oowner
== nowner
) {
1690 /* prevent unfocusing of owner */
1691 oowner
->flags
.semi_focused
= 0;
1692 wWindowUnfocus(owin
);
1693 oowner
->flags
.semi_focused
= 1;
1698 /* nowner != NULL && oowner != nowner */
1699 nowner
->flags
.semi_focused
= 1;
1700 wWindowUnfocus(nowner
);
1701 wWindowUnfocus(owin
);
1704 void wWindowUnfocus(WWindow
*wwin
)
1706 CloseWindowMenu(wwin
->screen_ptr
);
1708 if (wwin
->flags
.is_gnustep
== 0)
1709 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1711 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1713 owner
= wWindowFor(wwin
->transient_for
);
1714 if (owner
&& owner
->flags
.semi_focused
) {
1715 owner
->flags
.semi_focused
= 0;
1716 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1717 wWindowUnfocus(owner
);
1718 wFrameWindowPaint(owner
->frame
);
1722 wwin
->flags
.focused
= 0;
1723 wWindowResetMouseGrabs(wwin
);
1724 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1727 void wWindowUpdateName(WWindow
*wwin
, const char *newTitle
)
1735 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1739 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1740 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1744 *----------------------------------------------------------------------
1746 * wWindowConstrainSize--
1747 * Constrains size for the client window, taking the maximal size,
1748 * window resize increments and other size hints into account.
1751 * The closest size to what was given that the client window can
1754 *----------------------------------------------------------------------
1756 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1758 int width
= (int)*nwidth
;
1759 int height
= (int)*nheight
;
1762 int minW
= 1, minH
= 1;
1763 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1764 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1765 int minAX
= -1, minAY
= -1;
1766 int maxAX
= -1, maxAY
= -1;
1770 if (wwin
->normal_hints
) {
1771 winc
= wwin
->normal_hints
->width_inc
;
1772 hinc
= wwin
->normal_hints
->height_inc
;
1773 minW
= wwin
->normal_hints
->min_width
;
1774 minH
= wwin
->normal_hints
->min_height
;
1775 maxW
= wwin
->normal_hints
->max_width
;
1776 maxH
= wwin
->normal_hints
->max_height
;
1777 if (wwin
->normal_hints
->flags
& PAspect
) {
1778 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1779 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1780 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1781 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1784 baseW
= wwin
->normal_hints
->base_width
;
1785 baseH
= wwin
->normal_hints
->base_height
;
1798 /* aspect ratio code borrowed from olwm */
1800 /* adjust max aspect ratio */
1801 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1802 if (maxAX
> maxAY
) {
1803 height
= (width
* maxAY
) / maxAX
;
1804 if (height
> maxH
) {
1806 width
= (height
* maxAX
) / maxAY
;
1809 width
= (height
* maxAX
) / maxAY
;
1812 height
= (width
* maxAY
) / maxAX
;
1817 /* adjust min aspect ratio */
1818 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1819 if (minAX
> minAY
) {
1820 height
= (width
* minAY
) / minAX
;
1821 if (height
< minH
) {
1823 width
= (height
* minAX
) / minAY
;
1826 width
= (height
* minAX
) / minAY
;
1829 height
= (width
* minAY
) / minAX
;
1836 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1838 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1841 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1843 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1845 /* broken stupid apps may cause preposterous values for these.. */
1852 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1853 unsigned int *width
, unsigned int *height
)
1855 int baseW
= 0, baseH
= 0;
1856 int winc
= 1, hinc
= 1;
1858 if (wwin
->normal_hints
) {
1859 baseW
= wwin
->normal_hints
->base_width
;
1860 baseH
= wwin
->normal_hints
->base_height
;
1862 winc
= wwin
->normal_hints
->width_inc
;
1863 hinc
= wwin
->normal_hints
->height_inc
;
1867 *width
= maxW
- (maxW
- baseW
) % winc
;
1870 *height
= maxH
- (maxH
- baseH
) % hinc
;
1873 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1875 WScreen
*scr
= wwin
->screen_ptr
;
1879 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1882 if (workspace
!= scr
->current_workspace
) {
1883 /* Sent to other workspace. Unmap window */
1884 if ((wwin
->flags
.mapped
1885 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1886 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1888 wapp
= wApplicationOf(wwin
->main_window
);
1890 wapp
->last_workspace
= workspace
;
1892 if (wwin
->flags
.miniaturized
) {
1894 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1895 wwin
->icon
->mapped
= 0;
1899 wSetFocusTo(scr
, NULL
);
1903 /* brought to current workspace. Map window */
1904 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1906 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1907 wwin
->icon
->mapped
= 1;
1909 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1913 if (!IS_OMNIPRESENT(wwin
)) {
1914 int oldWorkspace
= wwin
->frame
->workspace
;
1915 wwin
->frame
->workspace
= workspace
;
1916 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1923 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
1925 WScreen
*scr
= wwin
->screen_ptr
;
1926 int w
= scr
->current_workspace
+ amount
;
1930 wWindowChangeWorkspace(wwin
, w
);
1931 } else if (wPreferences
.ws_cycle
) {
1932 wWindowChangeWorkspace(wwin
, scr
->workspace_count
+ w
);
1934 } else if (amount
> 0) {
1935 if (w
< scr
->workspace_count
) {
1936 wWindowChangeWorkspace(wwin
, w
);
1937 } else if (wPreferences
.ws_advance
) {
1938 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
1939 wWorkspaceMake(scr
, workspace
);
1940 wWindowChangeWorkspace(wwin
, workspace
);
1941 } else if (wPreferences
.ws_cycle
) {
1942 wWindowChangeWorkspace(wwin
, w
% scr
->workspace_count
);
1947 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1951 sevent
.type
= ConfigureNotify
;
1952 sevent
.xconfigure
.display
= dpy
;
1953 sevent
.xconfigure
.event
= wwin
->client_win
;
1954 sevent
.xconfigure
.window
= wwin
->client_win
;
1956 sevent
.xconfigure
.x
= wwin
->client
.x
;
1957 sevent
.xconfigure
.y
= wwin
->client
.y
;
1958 sevent
.xconfigure
.width
= wwin
->client
.width
;
1959 sevent
.xconfigure
.height
= wwin
->client
.height
;
1961 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1962 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1963 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1965 sevent
.xconfigure
.above
= None
;
1967 sevent
.xconfigure
.override_redirect
= False
;
1968 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1973 *----------------------------------------------------------------------
1974 * wWindowConfigure()
1976 * req_x, req_y: new requested positions for the frame
1977 * req_width, req_height: new requested sizes for the client
1979 * Configures the frame, decorations and client window to the specified
1980 * geometry, whose validity is not checked -- wWindowConstrainSize()
1981 * must be used for that.
1982 * The size parameters are for the client window, but the position is
1984 * The client window receives a ConfigureNotify event, according
1985 * to what ICCCM says.
1991 * Window size and position are changed and client window receives
1992 * a ConfigureNotify event.
1993 *----------------------------------------------------------------------
1995 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1997 int synth_notify
= False
;
2000 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2002 * if the window is being moved but not resized then
2003 * send a synthetic ConfigureNotify
2005 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
2006 synth_notify
= True
;
2008 if (WFLAGP(wwin
, dont_move_off
))
2009 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2012 if (req_width
< MIN_WINDOW_SIZE
)
2013 req_width
= MIN_WINDOW_SIZE
;
2014 if (req_height
< MIN_WINDOW_SIZE
)
2015 req_height
= MIN_WINDOW_SIZE
;
2017 /* If growing, resize inner part before frame,
2018 * if shrinking, resize frame before.
2019 * This will prevent the frame (that can have a different color)
2020 * to be exposed, causing flicker */
2021 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2022 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2024 if (wwin
->flags
.shaded
) {
2025 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2026 wwin
->old_geometry
.height
= req_height
;
2030 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2032 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2035 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2036 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2038 wwin
->client
.x
= req_x
;
2039 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2040 wwin
->client
.width
= req_width
;
2041 wwin
->client
.height
= req_height
;
2043 wwin
->client
.x
= req_x
;
2044 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2046 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2048 wwin
->frame_x
= req_x
;
2049 wwin
->frame_y
= req_y
;
2050 if (HAS_BORDER(wwin
)) {
2051 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2052 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2055 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2056 wWindowSetShape(wwin
);
2060 wWindowSynthConfigureNotify(wwin
);
2062 wNETFrameExtents(wwin
);
2067 /* req_x, req_y: new position of the frame */
2068 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2070 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2071 int synth_notify
= False
;
2073 /* Send a synthetic ConfigureNotify event for every window movement. */
2074 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2075 synth_notify
= True
;
2077 /* A single synthetic ConfigureNotify event is sent at the end of
2078 * a completed (opaque) movement in moveres.c */
2081 if (WFLAGP(wwin
, dont_move_off
))
2082 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2083 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2085 wwin
->client
.x
= req_x
;
2086 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2087 if (HAS_BORDER(wwin
)) {
2088 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2089 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2092 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2094 wwin
->frame_x
= req_x
;
2095 wwin
->frame_y
= req_y
;
2097 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2099 wWindowSynthConfigureNotify(wwin
);
2103 void wWindowUpdateButtonImages(WWindow
*wwin
)
2105 WScreen
*scr
= wwin
->screen_ptr
;
2106 Pixmap pixmap
, mask
;
2107 WFrameWindow
*fwin
= wwin
->frame
;
2109 if (!HAS_TITLEBAR(wwin
))
2112 /* miniaturize button */
2113 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2114 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2115 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2117 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2118 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2122 if (fwin
->lbutton_image
2123 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2124 wPixmapDestroy(fwin
->lbutton_image
);
2125 fwin
->lbutton_image
= NULL
;
2128 if (!fwin
->lbutton_image
) {
2129 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2130 fwin
->lbutton_image
->client_owned
= 1;
2131 fwin
->lbutton_image
->client_owned_mask
= 1;
2134 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2135 wPixmapDestroy(fwin
->lbutton_image
);
2137 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2140 #ifdef XKB_BUTTON_HINT
2141 if (!WFLAGP(wwin
, no_language_button
)) {
2142 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2143 wPixmapDestroy(fwin
->languagebutton_image
);
2145 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2151 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2152 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2154 if (!WFLAGP(wwin
, no_close_button
)) {
2155 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2156 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2158 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2159 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2163 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2164 || fwin
->rbutton_image
->mask
!= mask
)) {
2165 wPixmapDestroy(fwin
->rbutton_image
);
2166 fwin
->rbutton_image
= NULL
;
2169 if (!fwin
->rbutton_image
) {
2170 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2171 fwin
->rbutton_image
->client_owned
= 1;
2172 fwin
->rbutton_image
->client_owned_mask
= 1;
2175 } else if (WFLAGP(wwin
, kill_close
)) {
2176 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2177 wPixmapDestroy(fwin
->rbutton_image
);
2179 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2181 } else if (MGFLAGP(wwin
, broken_close
)) {
2182 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2183 wPixmapDestroy(fwin
->rbutton_image
);
2185 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2188 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2189 wPixmapDestroy(fwin
->rbutton_image
);
2191 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2195 /* force buttons to be redrawn */
2196 fwin
->flags
.need_texture_change
= 1;
2197 wFrameWindowPaint(fwin
);
2201 *---------------------------------------------------------------------------
2202 * wWindowConfigureBorders--
2203 * Update window border configuration according to attribute flags.
2205 *---------------------------------------------------------------------------
2207 void wWindowConfigureBorders(WWindow
*wwin
)
2213 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2215 #ifdef XKB_BUTTON_HINT
2216 if (wPreferences
.modelock
)
2217 flags
|= WFF_LANGUAGE_BUTTON
;
2220 if (HAS_TITLEBAR(wwin
))
2221 flags
|= WFF_TITLEBAR
;
2222 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2223 flags
|= WFF_RESIZEBAR
;
2224 if (HAS_BORDER(wwin
))
2225 flags
|= WFF_BORDER
;
2226 if (wwin
->flags
.shaded
)
2227 flags
|= WFF_IS_SHADED
;
2228 if (wwin
->flags
.selected
)
2229 flags
|= WFF_SELECTED
;
2231 oldh
= wwin
->frame
->top_width
;
2232 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2233 if (oldh
!= wwin
->frame
->top_width
) {
2234 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2236 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2237 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2241 if (!WFLAGP(wwin
, no_miniaturize_button
)
2242 && wwin
->frame
->flags
.hide_left_button
)
2243 flags
|= WFF_LEFT_BUTTON
;
2245 #ifdef XKB_BUTTON_HINT
2246 if (!WFLAGP(wwin
, no_language_button
)
2247 && wwin
->frame
->flags
.hide_language_button
)
2248 flags
|= WFF_LANGUAGE_BUTTON
;
2251 if (!WFLAGP(wwin
, no_close_button
)
2252 && wwin
->frame
->flags
.hide_right_button
)
2253 flags
|= WFF_RIGHT_BUTTON
;
2256 wWindowUpdateButtonImages(wwin
);
2257 wFrameWindowShowButton(wwin
->frame
, flags
);
2261 if (WFLAGP(wwin
, no_miniaturize_button
)
2262 && !wwin
->frame
->flags
.hide_left_button
)
2263 flags
|= WFF_LEFT_BUTTON
;
2265 #ifdef XKB_BUTTON_HINT
2266 if (WFLAGP(wwin
, no_language_button
)
2267 && !wwin
->frame
->flags
.hide_language_button
)
2268 flags
|= WFF_LANGUAGE_BUTTON
;
2271 if (WFLAGP(wwin
, no_close_button
)
2272 && !wwin
->frame
->flags
.hide_right_button
)
2273 flags
|= WFF_RIGHT_BUTTON
;
2276 wFrameWindowHideButton(wwin
->frame
, flags
);
2279 if (wShapeSupported
&& wwin
->flags
.shaped
)
2280 wWindowSetShape(wwin
);
2285 void wWindowSaveState(WWindow
* wwin
)
2290 memset(data
, 0, sizeof(long) * 10);
2291 data
[0] = wwin
->frame
->workspace
;
2292 data
[1] = wwin
->flags
.miniaturized
;
2293 data
[2] = wwin
->flags
.shaded
;
2294 data
[3] = wwin
->flags
.hidden
;
2295 data
[4] = wwin
->flags
.maximized
;
2296 if (wwin
->flags
.maximized
== 0) {
2297 data
[5] = wwin
->frame_x
;
2298 data
[6] = wwin
->frame_y
;
2299 data
[7] = wwin
->frame
->core
->width
;
2300 data
[8] = wwin
->frame
->core
->height
;
2302 data
[5] = wwin
->old_geometry
.x
;
2303 data
[6] = wwin
->old_geometry
.y
;
2304 data
[7] = wwin
->old_geometry
.width
;
2305 data
[8] = wwin
->old_geometry
.height
;
2308 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2309 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2310 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2313 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2314 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2317 static int getSavedState(Window window
, WSavedState
** state
)
2321 unsigned long nitems_ret
;
2322 unsigned long bytes_after_ret
;
2325 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2326 True
, _XA_WINDOWMAKER_STATE
,
2327 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2328 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2331 *state
= wmalloc(sizeof(WSavedState
));
2333 (*state
)->workspace
= data
[0];
2334 (*state
)->miniaturized
= data
[1];
2335 (*state
)->shaded
= data
[2];
2336 (*state
)->hidden
= data
[3];
2337 (*state
)->maximized
= data
[4];
2338 (*state
)->x
= data
[5];
2339 (*state
)->y
= data
[6];
2340 (*state
)->w
= data
[7];
2341 (*state
)->h
= data
[8];
2342 (*state
)->window_shortcuts
= data
[9];
2346 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2353 void wWindowClearShape(WWindow
* wwin
)
2355 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2356 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2360 void wWindowSetShape(WWindow
* wwin
)
2364 #ifdef OPTIMIZE_SHAPE
2369 /* only shape is the client's */
2370 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2373 /* Get array of rectangles describing the shape mask */
2374 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2378 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2384 /* insert our decoration rectangles in the rect list */
2385 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2388 if (HAS_TITLEBAR(wwin
)) {
2390 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2391 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2392 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2395 if (HAS_RESIZEBAR(wwin
)) {
2397 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2398 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2399 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2403 /* shape our frame window */
2404 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2405 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2411 #endif /* OPTIMIZE_SHAPE */
2413 if (HAS_TITLEBAR(wwin
)) {
2416 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2417 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2420 if (HAS_RESIZEBAR(wwin
)) {
2422 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2423 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2424 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2428 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2429 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2431 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2432 0, wwin
->frame
->top_width
, wwin
->client_win
,
2433 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2438 /* ====================================================================== */
2440 static FocusMode
getFocusMode(WWindow
* wwin
)
2444 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2445 if (wwin
->wm_hints
->input
== True
) {
2446 if (wwin
->protocols
.TAKE_FOCUS
)
2447 mode
= WFM_LOCALLY_ACTIVE
;
2451 if (wwin
->protocols
.TAKE_FOCUS
)
2452 mode
= WFM_GLOBALLY_ACTIVE
;
2454 mode
= WFM_NO_INPUT
;
2462 void wWindowSetKeyGrabs(WWindow
* wwin
)
2467 for (i
= 0; i
< WKBD_LAST
; i
++) {
2468 key
= &wKeyBindings
[i
];
2470 if (key
->keycode
== 0)
2472 if (key
->modifier
!= AnyModifier
) {
2473 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2474 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2476 /* Also grab all modifier combinations possible that include,
2477 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2478 * work even if the NumLock/ScrollLock key is on.
2480 wHackedGrabKey(key
->keycode
, key
->modifier
,
2481 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2484 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2485 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2488 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2491 void wWindowResetMouseGrabs(WWindow
* wwin
)
2493 /* Mouse grabs can't be done on the client window because of
2494 * ICCCM and because clients that try to do the same will crash.
2496 * But there is a problem wich makes tbar buttons of unfocused
2497 * windows not usable as the click goes to the frame window instead
2498 * of the button itself. Must figure a way to fix that.
2501 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2503 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2504 /* grabs for Meta+drag */
2505 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2506 True
, ButtonPressMask
| ButtonReleaseMask
,
2507 GrabModeSync
, GrabModeAsync
, None
, None
);
2509 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2510 * but we only grab it for Button4 and Button 5 since a lot of apps
2511 * use CTRL+Button1-3 for app related functionality
2513 if (wPreferences
.resize_increment
> 0) {
2514 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2515 True
, ButtonPressMask
| ButtonReleaseMask
,
2516 GrabModeSync
, GrabModeAsync
, None
, None
);
2517 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2518 True
, ButtonPressMask
| ButtonReleaseMask
,
2519 GrabModeSync
, GrabModeAsync
, None
, None
);
2521 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2522 True
, ButtonPressMask
| ButtonReleaseMask
,
2523 GrabModeSync
, GrabModeAsync
, None
, None
);
2524 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2525 True
, ButtonPressMask
| ButtonReleaseMask
,
2526 GrabModeSync
, GrabModeAsync
, None
, None
);
2530 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2531 && !wwin
->flags
.is_gnustep
) {
2532 /* the passive grabs to focus the window */
2533 /* if (wPreferences.focus_mode == WKF_CLICK) */
2534 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2535 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2540 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2542 if (attr
->flags
& GSExtraFlagsAttr
) {
2543 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2544 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2545 wWindowUpdateButtonImages(wwin
);
2550 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2551 const char *command
, pid_t pid
, WSavedState
* state
)
2553 WWindowState
*wstate
;
2555 wstate
= malloc(sizeof(WWindowState
));
2559 memset(wstate
, 0, sizeof(WWindowState
));
2562 wstate
->instance
= wstrdup(instance
);
2564 wstate
->class = wstrdup(class);
2566 wstate
->command
= wstrdup(command
);
2567 wstate
->state
= state
;
2569 wstate
->next
= windowState
;
2570 windowState
= wstate
;
2575 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2577 WMagicNumber
wWindowGetSavedState(Window win
)
2579 char *instance
, *class, *command
= NULL
;
2580 WWindowState
*wstate
= windowState
;
2585 command
= GetCommandForWindow(win
);
2589 if (PropGetWMClass(win
, &class, &instance
)) {
2591 if (SAME(instance
, wstate
->instance
) &&
2592 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2595 wstate
= wstate
->next
;
2611 void wWindowDeleteSavedState(WMagicNumber id
)
2613 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2615 if (!wstate
|| !windowState
)
2619 if (tmp
== wstate
) {
2620 windowState
= wstate
->next
;
2621 release_wwindowstate(wstate
);
2624 if (tmp
->next
== wstate
) {
2625 tmp
->next
= wstate
->next
;
2626 release_wwindowstate(wstate
);
2634 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2636 WWindowState
*tmp
, *wstate
;
2642 if (tmp
->pid
== pid
) {
2643 wstate
= windowState
;
2644 windowState
= tmp
->next
;
2646 release_wwindowstate(wstate
);
2649 if (tmp
->next
->pid
== pid
) {
2651 tmp
->next
= wstate
->next
;
2652 release_wwindowstate(wstate
);
2660 static void release_wwindowstate(WWindowState
*wstate
)
2662 if (wstate
->instance
)
2663 wfree(wstate
->instance
);
2666 wfree(wstate
->class);
2668 if (wstate
->command
)
2669 wfree(wstate
->command
);
2671 wfree(wstate
->state
);
2675 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2677 if (wwin
->flags
.omnipresent
== flag
)
2680 wwin
->flags
.omnipresent
= flag
;
2681 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2684 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2686 WWindow
*wwin
= data
;
2688 #ifndef NUMLOCK_HACK
2689 if ((event
->xbutton
.state
& ValidModMask
)
2690 != (event
->xbutton
.state
& ~LockMask
)) {
2691 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2692 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2696 event
->xbutton
.state
&= ValidModMask
;
2698 CloseWindowMenu(wwin
->screen_ptr
);
2700 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2701 && !WFLAGP(wwin
, no_focusable
)) {
2702 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2705 if (event
->xbutton
.button
== Button1
)
2706 wRaiseFrame(wwin
->frame
->core
);
2708 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2709 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2710 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2711 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2716 if (event
->xbutton
.state
& MOD_MASK
) {
2717 /* move the window */
2718 wMouseMoveWindow(wwin
, event
);
2719 XUngrabPointer(dpy
, CurrentTime
);
2721 wMouseResizeWindow(wwin
, event
);
2722 XUngrabPointer(dpy
, CurrentTime
);
2726 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2728 WWindow
*wwin
= data
;
2730 event
->xbutton
.state
&= ValidModMask
;
2732 if (event
->xbutton
.button
== Button1
) {
2733 if (event
->xbutton
.state
== 0) {
2734 if (!WFLAGP(wwin
, no_shadeable
)) {
2736 if (wwin
->flags
.shaded
)
2737 wUnshadeWindow(wwin
);
2744 if (event
->xbutton
.state
& ControlMask
)
2745 dir
|= MAX_VERTICAL
;
2747 if (event
->xbutton
.state
& ShiftMask
) {
2748 dir
|= MAX_HORIZONTAL
;
2749 if (!(event
->xbutton
.state
& ControlMask
))
2750 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2753 /* maximize window */
2754 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2755 int ndir
= dir
^ wwin
->flags
.maximized
;
2758 wMaximizeWindow(wwin
, ndir
);
2760 wUnmaximizeWindow(wwin
);
2763 } else if (event
->xbutton
.button
== Button3
) {
2764 if (event
->xbutton
.state
& MOD_MASK
)
2765 wHideOtherApplications(wwin
);
2766 } else if (event
->xbutton
.button
== Button2
) {
2767 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2768 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2770 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2771 wUnshadeWindow(wwin
);
2775 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2777 WWindow
*wwin
= desc
->parent
;
2778 unsigned int new_width
, w_scale
;
2779 unsigned int new_height
, h_scale
;
2780 unsigned int resize_width_increment
= 0;
2781 unsigned int resize_height_increment
= 0;
2783 if (wwin
->normal_hints
) {
2784 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2785 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2786 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2787 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2789 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2790 resize_width_increment
= wPreferences
.resize_increment
;
2791 resize_height_increment
= wPreferences
.resize_increment
;
2794 event
->xbutton
.state
&= ValidModMask
;
2796 CloseWindowMenu(wwin
->screen_ptr
);
2798 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2799 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2801 if (event
->xbutton
.button
== Button1
)
2802 wRaiseFrame(wwin
->frame
->core
);
2804 if (event
->xbutton
.state
& ControlMask
) {
2805 if (event
->xbutton
.button
== Button4
) {
2806 new_width
= wwin
->client
.width
- resize_width_increment
;
2807 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2808 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2810 if (event
->xbutton
.button
== Button5
) {
2811 new_width
= wwin
->client
.width
+ resize_width_increment
;
2812 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2813 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2817 if (event
->xbutton
.state
& MOD_MASK
) {
2818 /* move the window */
2819 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2820 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2821 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2824 if (event
->xbutton
.button
== Button3
) {
2825 wMouseResizeWindow(wwin
, event
);
2826 } else if (event
->xbutton
.button
== Button4
) {
2827 new_height
= wwin
->client
.height
- resize_height_increment
;
2828 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2829 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2830 } else if (event
->xbutton
.button
== Button5
) {
2831 new_height
= wwin
->client
.height
+ resize_height_increment
;
2832 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2833 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2834 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2835 wMouseMoveWindow(wwin
, event
);
2837 XUngrabPointer(dpy
, CurrentTime
);
2841 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2843 WWindow
*wwin
= (WWindow
*) data
;
2845 #ifndef NUMLOCK_HACK
2846 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2847 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2848 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2850 event
->xbutton
.state
&= ValidModMask
;
2852 CloseWindowMenu(wwin
->screen_ptr
);
2854 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2855 && !WFLAGP(wwin
, no_focusable
))
2856 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2858 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2860 if (event
->xbutton
.button
== Button1
) {
2861 if (event
->xbutton
.state
& MOD_MASK
)
2862 wLowerFrame(wwin
->frame
->core
);
2864 wRaiseFrame(wwin
->frame
->core
);
2866 if ((event
->xbutton
.state
& ShiftMask
)
2867 && !(event
->xbutton
.state
& ControlMask
)) {
2868 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2871 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2872 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2873 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2874 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2878 /* move the window */
2879 wMouseMoveWindow(wwin
, event
);
2881 XUngrabPointer(dpy
, CurrentTime
);
2882 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2883 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2884 WObjDescriptor
*desc
;
2886 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2887 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2888 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2889 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2893 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2895 /* allow drag select */
2896 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2897 event
->xany
.send_event
= True
;
2898 (*desc
->handle_mousedown
) (desc
, event
);
2900 XUngrabPointer(dpy
, CurrentTime
);
2904 static void windowCloseClick(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 control-click, kill the client */
2916 if (event
->xbutton
.state
& ControlMask
) {
2919 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2920 /* send delete message */
2921 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2926 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2928 WWindow
*wwin
= data
;
2930 CloseWindowMenu(wwin
->screen_ptr
);
2932 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2935 /* send delete message */
2936 if (wwin
->protocols
.DELETE_WINDOW
)
2937 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2942 #ifdef XKB_BUTTON_HINT
2943 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2945 WWindow
*wwin
= data
;
2946 WFrameWindow
*fwin
= wwin
->frame
;
2947 WScreen
*scr
= fwin
->screen_ptr
;
2950 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2952 tl
= wwin
->frame
->languagemode
;
2953 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2954 wwin
->frame
->last_languagemode
= tl
;
2955 wSetFocusTo(scr
, wwin
);
2956 wwin
->frame
->languagebutton_image
=
2957 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2958 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2959 if (event
->xbutton
.button
== Button3
)
2961 wRaiseFrame(fwin
->core
);
2965 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2967 WWindow
*wwin
= data
;
2969 event
->xbutton
.state
&= ValidModMask
;
2971 CloseWindowMenu(wwin
->screen_ptr
);
2973 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2976 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2977 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
2980 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2982 wapp
= wApplicationOf(wwin
->main_window
);
2983 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2984 wHideApplication(wapp
);
2985 } else if (event
->xbutton
.state
== 0) {
2986 wIconifyWindow(wwin
);