1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 2008-2023 Window Maker Team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 */
34 #include <X11/extensions/XRes.h>
42 /* For getting mouse wheel mappings from WINGs */
43 #include <WINGs/WINGs.h>
45 #include "WindowMaker.h"
51 #include "winspector.h"
53 #include "properties.h"
60 #include "workspace.h"
64 #include "superfluous.h"
66 #include "placement.h"
77 #define MOD_MASK wPreferences.modifier_mask
80 /***** Local Stuff *****/
81 static WWindowState
*windowState
= NULL
;
82 static FocusMode
getFocusMode(WWindow
*wwin
);
83 static int getSavedState(Window window
, WSavedState
**state
);
84 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
86 /* frame window (during window grabs) */
87 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
90 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
91 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
94 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
96 #ifdef XKB_BUTTON_HINT
97 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
100 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
101 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
104 static void release_wwindowstate(WWindowState
*wstate
);
106 /****** Notification Observers ******/
108 static void appearanceObserver(void *self
, WMNotification
* notif
)
110 WWindow
*wwin
= (WWindow
*) self
;
111 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
113 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
116 if (flags
& WFontSettings
) {
117 wWindowConfigureBorders(wwin
);
118 if (wwin
->flags
.shaded
) {
119 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
120 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
121 wWindowSynthConfigureNotify(wwin
);
124 if (flags
& WTextureSettings
)
125 wwin
->frame
->flags
.need_texture_remake
= 1;
127 if (flags
& (WTextureSettings
| WColorSettings
)) {
128 if (wwin
->frame
->titlebar
)
129 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
131 wFrameWindowPaint(wwin
->frame
);
136 /* Return the WWindow associated with a given (Xlib) Window. */
137 WWindow
*wWindowFor(Window window
)
139 WObjDescriptor
*desc
;
144 if (XFindContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
147 if (desc
->parent_type
== WCLASS_WINDOW
)
149 else if (desc
->parent_type
== WCLASS_FRAME
) {
150 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
151 if (frame
->flags
.is_client_window_frame
)
158 WWindow
*wWindowCreate(void)
162 wwin
= wmalloc(sizeof(WWindow
));
165 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
166 wwin
->client_descriptor
.parent
= wwin
;
167 wwin
->client_descriptor
.self
= wwin
;
168 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
173 void wWindowDestroy(WWindow
*wwin
)
177 if (wwin
->screen_ptr
->cmap_window
== wwin
)
178 wwin
->screen_ptr
->cmap_window
= NULL
;
180 WMRemoveNotificationObserver(wwin
);
182 wwin
->flags
.destroyed
= 1;
184 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
185 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
188 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
190 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
191 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
192 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
196 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
197 wwin
->fake_group
->retainCount
--;
198 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
199 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
200 wwin
->fake_group
->leader
= None
;
201 wwin
->fake_group
->origLeader
= None
;
206 if (wwin
->normal_hints
)
207 XFree(wwin
->normal_hints
);
210 XFree(wwin
->wm_hints
);
212 if (wwin
->wm_instance
)
213 XFree(wwin
->wm_instance
);
216 XFree(wwin
->wm_class
);
218 if (wwin
->wm_gnustep_attr
)
219 wfree(wwin
->wm_gnustep_attr
);
221 if (wwin
->cmap_windows
)
222 XFree(wwin
->cmap_windows
);
224 XDeleteContext(dpy
, wwin
->client_win
, w_global
.context
.client_win
);
227 wFrameWindowDestroy(wwin
->frame
);
230 RemoveFromStackList(wwin
->icon
->core
);
231 wIconDestroy(wwin
->icon
);
232 if (wPreferences
.auto_arrange_icons
)
233 wArrangeIcons(wwin
->screen_ptr
, True
);
235 if (wwin
->net_icon_image
)
236 RReleaseImage(wwin
->net_icon_image
);
241 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
243 if (gs_hints
->flags
& GSWindowStyleAttr
) {
244 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
245 wwin
->client_flags
.no_border
= 1;
246 wwin
->client_flags
.no_titlebar
= 1;
247 wwin
->client_flags
.no_closable
= 1;
248 wwin
->client_flags
.no_miniaturizable
= 1;
249 wwin
->client_flags
.no_resizable
= 1;
250 wwin
->client_flags
.no_close_button
= 1;
251 wwin
->client_flags
.no_miniaturize_button
= 1;
252 wwin
->client_flags
.no_resizebar
= 1;
254 wwin
->client_flags
.no_close_button
=
255 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
257 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
259 wwin
->client_flags
.no_miniaturize_button
=
260 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
262 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
264 wwin
->client_flags
.no_resizebar
=
265 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
267 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
269 /* these attributes supposedly imply in the existence
271 if (gs_hints
->window_style
& (WMResizableWindowMask
|
272 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
273 wwin
->client_flags
.no_titlebar
= 0;
275 wwin
->client_flags
.no_titlebar
=
276 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
281 /* setup the defaults */
282 wwin
->client_flags
.no_border
= 0;
283 wwin
->client_flags
.no_titlebar
= 0;
284 wwin
->client_flags
.no_closable
= 0;
285 wwin
->client_flags
.no_miniaturizable
= 0;
286 wwin
->client_flags
.no_resizable
= 0;
287 wwin
->client_flags
.no_close_button
= 0;
288 wwin
->client_flags
.no_miniaturize_button
= 0;
289 wwin
->client_flags
.no_resizebar
= 0;
291 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
292 wwin
->client_flags
.no_appicon
= 1;
295 static void discard_hints_from_gtk(WWindow
*wwin
)
299 unsigned long nb_item
, nb_remain
;
300 unsigned char *result
;
303 status
= XGetWindowProperty(dpy
, wwin
->client_win
, w_global
.atom
.desktop
.gtk_object_path
, 0, 16, False
,
304 AnyPropertyType
, &type
, &format
, &nb_item
, &nb_remain
, &result
);
305 if (status
!= Success
)
308 /* If we're here, that means the Property exists. We don't care what is inside, it means it is a GTK-based application */
313 /* GTK is asking to remove these decorations: */
314 wwin
->client_flags
.no_titlebar
= 0;
315 wwin
->client_flags
.no_close_button
= 0;
316 wwin
->client_flags
.no_miniaturize_button
= 0;
317 wwin
->client_flags
.no_resizebar
= 0;
320 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
322 WScreen
*scr
= wwin
->screen_ptr
;
324 /* sets global default stuff */
325 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
, NULL
, True
);
326 wwin
->defined_user_flags
= wwin
->user_flags
;
329 * Decoration setting is done in this precedence (lower to higher)
330 * - use global default in the resource database
331 * - guess some settings
332 * - use GNUstep/external window attributes
333 * - set hints specified for the app in the resource DB
336 wwin
->client_flags
.broken_close
= 0;
338 if (wwin
->protocols
.DELETE_WINDOW
)
339 wwin
->client_flags
.kill_close
= 0;
341 wwin
->client_flags
.kill_close
= 1;
343 /* transients can't be iconified or maximized */
344 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
345 wwin
->client_flags
.no_miniaturizable
= 1;
346 wwin
->client_flags
.no_miniaturize_button
= 1;
349 /* if the window can't be resized, remove the resizebar */
350 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
351 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
352 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
353 wwin
->client_flags
.no_resizable
= 1;
354 wwin
->client_flags
.no_resizebar
= 1;
357 /* set GNUstep window attributes */
358 if (wwin
->wm_gnustep_attr
) {
359 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
361 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
363 *level
= wwin
->wm_gnustep_attr
->window_level
;
365 * INT_MIN is the only illegal window level.
367 if (*level
== INT_MIN
)
368 *level
= INT_MIN
+ 1;
371 *level
= WMNormalLevel
;
374 int tmp_workspace
= -1;
375 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
378 wMWMCheckClientHints(wwin
);
379 #endif /* USE_MWM_HINTS */
381 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
383 if (wPreferences
.ignore_gtk_decoration_hints
)
384 discard_hints_from_gtk(wwin
);
386 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
387 * have INT_MIN that means that no window level was requested. -Dan
389 if (tmp_level
== INT_MIN
) {
390 if (WFLAGP(wwin
, floating
))
391 *level
= WMFloatingLevel
;
392 else if (WFLAGP(wwin
, sunken
))
393 *level
= WMSunkenLevel
;
395 *level
= WMNormalLevel
;
400 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
401 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
402 if (transientOwner
) {
403 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
404 if (ownerLevel
> *level
)
409 if (tmp_workspace
>= 0)
410 *workspace
= tmp_workspace
% scr
->workspace_count
;
414 * Set attributes specified only for that window/class.
415 * This might do duplicate work with the 1st wDefaultFillAttributes().
417 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
418 &wwin
->defined_user_flags
, False
);
420 /* Restore decoration if the user has enabled the
421 * IgnoreDecorationChanges option */
422 if (wwin
->user_flags
.ignore_decoration_changes
) {
423 WSETUFLAG(wwin
, no_titlebar
, 0);
424 WSETUFLAG(wwin
, no_resizable
, 0);
425 WSETUFLAG(wwin
, no_miniaturizable
, 0);
426 WSETUFLAG(wwin
, no_resizebar
, 0);
427 WSETUFLAG(wwin
, no_close_button
, 0);
428 WSETUFLAG(wwin
, no_miniaturize_button
, 0);
429 WSETUFLAG(wwin
, no_border
, 0);
430 WSETUFLAG(wwin
, no_movable
, 0);
434 * Sanity checks for attributes that depend on other attributes
436 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
437 wwin
->user_flags
.emulate_appicon
= 0;
439 if (wwin
->main_window
!= None
) {
440 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
441 if (wapp
&& !wapp
->flags
.emulated
)
442 wwin
->user_flags
.emulate_appicon
= 0;
445 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
446 wwin
->user_flags
.emulate_appicon
= 0;
448 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
449 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
450 wwin
->user_flags
.sunken
= 0;
452 /* A window that does not have a title cannot be Shaded and we don't let user override this */
453 wwin
->client_flags
.no_shadeable
= WFLAGP(wwin
, no_titlebar
);
454 wwin
->defined_user_flags
.no_shadeable
= 0;
456 /* windows that have takefocus=False shouldn't take focus at all */
457 if (wwin
->focus_mode
== WFM_NO_INPUT
)
458 wwin
->client_flags
.no_focusable
= 1;
461 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
465 w1
= wwin
->frame
->core
->width
;
466 h1
= wwin
->frame
->core
->height
;
467 w2
= obscured
->frame
->core
->width
;
468 h2
= obscured
->frame
->core
->height
;
470 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
471 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
474 if (wwin
->frame_x
+ w1
< obscured
->frame_x
475 || wwin
->frame_y
+ h1
< obscured
->frame_y
476 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
482 /* Get the corresponding Process Identification Number of the active window */
483 static pid_t
getWindowPid(Window win
)
487 pid
= wNETWMGetPidForWindow(win
);
492 XResClientIdSpec spec
;
495 XResClientIdValue
*client_ids
= NULL
;
498 spec
.mask
= XRES_CLIENT_ID_PID_MASK
;
500 status
= XResQueryClientIds(dpy
, 1, &spec
, &num_ids
, &client_ids
);
502 if (status
!= Success
)
505 for (i
= 0; i
< num_ids
; i
++) {
506 if (client_ids
[i
].spec
.mask
== XRES_CLIENT_ID_PID_MASK
) {
507 pid
= XResGetClientPid(&client_ids
[i
]);
511 XResClientIdsDestroy(num_ids
, client_ids
);
517 static void fixLeaderProperties(WWindow
*wwin
)
519 XClassHint
*classHint
;
520 XWMHints
*hints
, *clientHints
;
521 XWindowAttributes attr
;
522 Window leaders
[2], window
;
523 char **argv
, *command
;
527 classHint
= XAllocClassHint();
528 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
529 pid
= getWindowPid(wwin
->client_win
);
531 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
535 leaders
[0] = wwin
->client_leader
;
536 leaders
[1] = wwin
->group_id
;
539 command
= GetCommandForWindow(wwin
->client_win
);
541 wfree(command
); /* command already set. nothing to do. */
543 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
546 for (i
= 0; i
< 2; i
++) {
549 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
550 classHint
->res_name
= wwin
->wm_instance
;
551 classHint
->res_class
= wwin
->wm_class
;
552 XSetClassHint(dpy
, window
, classHint
);
554 hints
= XGetWMHints(dpy
, window
);
557 } else if (clientHints
) {
558 /* set window group leader to self */
559 clientHints
->window_group
= window
;
560 clientHints
->flags
|= WindowGroupHint
;
561 XSetWMHints(dpy
, window
, clientHints
);
565 command
= GetCommandForWindow(window
);
567 wfree(command
); /* command already set. nothing to do. */
569 XSetCommand(dpy
, window
, argv
, argc
);
572 /* Make sure we get notification when this window is destroyed */
573 if (XGetWindowAttributes(dpy
, window
, &attr
))
574 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
585 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
587 XClassHint
*classHint
;
593 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
595 classHint
= XAllocClassHint();
596 classHint
->res_name
= instance
;
597 classHint
->res_class
= class;
598 XSetClassHint(dpy
, leader
, classHint
);
601 /* inherit these from the original leader if available */
602 hints
= XGetWMHints(dpy
, win
);
604 hints
= XAllocWMHints();
607 /* set window group leader to self */
608 hints
->window_group
= leader
;
609 hints
->flags
|= WindowGroupHint
;
610 XSetWMHints(dpy
, leader
, hints
);
613 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
614 XSetCommand(dpy
, leader
, argv
, argc
);
615 XFreeStringList(argv
);
621 static int matchIdentifier(const void *item
, const void *cdata
)
623 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
627 *----------------------------------------------------------------
629 * reparents the window and allocates a descriptor for it.
630 * Window manager hints and other hints are fetched to configure
631 * the window decoration attributes and others. User preferences
632 * for the window are used if available, to configure window
633 * decorations and some behaviour.
634 * If in startup, windows that are override redirect,
635 * unmapped and never were managed and are Withdrawn are not
639 * the new window descriptor
642 * The window is reparented and appropriate notification
643 * is done to the client. Input mask for the window is setup.
644 * The window descriptor is also associated with various window
645 * contexts and inserted in the head of the window list.
646 * Event handler contexts are associated for some objects
647 * (buttons, titlebar and resizebar)
649 *----------------------------------------------------------------
651 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
655 unsigned width
, height
;
656 XWindowAttributes wattribs
;
657 XSetWindowAttributes attribs
;
658 WWindowState
*win_state
;
659 WWindow
*transientOwner
= NULL
;
665 Bool withdraw
= False
;
672 /* make sure the window is still there */
673 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
678 /* if it's an override-redirect, ignore it */
679 if (wattribs
.override_redirect
) {
684 wm_state
= PropGetWindowState(window
);
686 /* if it's startup and the window is unmapped, don't manage it */
687 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
692 wwin
= wWindowCreate();
694 title
= wNETWMGetWindowName(window
);
696 wwin
->flags
.net_has_title
= 1;
697 else if (!wFetchName(dpy
, window
, &title
))
700 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
703 if (w_global
.xext
.shape
.supported
) {
708 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
709 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
710 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
711 wwin
->flags
.shaped
= b_shaped
;
715 /* Get hints and other information in properties */
716 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
718 /* setup descriptor */
719 wwin
->client_win
= window
;
720 wwin
->screen_ptr
= scr
;
721 wwin
->old_border_width
= wattribs
.border_width
;
722 wwin
->event_mask
= CLIENT_EVENTS
;
723 attribs
.event_mask
= CLIENT_EVENTS
;
724 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
725 attribs
.save_under
= False
;
727 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
728 XSetWindowBorderWidth(dpy
, window
, 0);
730 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") != 0)
731 wwin
->flags
.fullscreen_monitors
[0] = -1;
733 /* get hints from GNUstep app */
734 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
735 wwin
->flags
.is_gnustep
= 1;
737 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
738 wwin
->wm_gnustep_attr
= NULL
;
740 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
741 wwin
->flags
.is_dockapp
= 1;
745 wwin
->client_leader
= PropGetClientLeader(window
);
746 if (wwin
->client_leader
!= None
)
747 wwin
->main_window
= wwin
->client_leader
;
749 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
751 if (wwin
->wm_hints
) {
752 if (wwin
->wm_hints
->flags
& StateHint
) {
753 if (wwin
->wm_hints
->initial_state
== IconicState
) {
754 wwin
->flags
.miniaturized
= 1;
755 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
756 wwin
->flags
.is_dockapp
= 1;
761 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
762 wwin
->group_id
= wwin
->wm_hints
->window_group
;
763 /* window_group has priority over CLIENT_LEADER */
764 wwin
->main_window
= wwin
->group_id
;
766 wwin
->group_id
= None
;
769 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
770 wwin
->flags
.urgent
= 1;
771 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
774 wwin
->group_id
= None
;
777 PropGetProtocols(window
, &wwin
->protocols
);
779 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
780 wwin
->transient_for
= None
;
782 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
783 wwin
->transient_for
= scr
->root_win
;
785 transientOwner
= wWindowFor(wwin
->transient_for
);
786 if (transientOwner
&& transientOwner
->main_window
!= None
)
787 wwin
->main_window
= transientOwner
->main_window
;
791 /* guess the focus mode */
792 wwin
->focus_mode
= getFocusMode(wwin
);
794 /* get geometry stuff */
795 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
797 /* get colormap windows */
798 GetColormapWindows(wwin
);
801 * Setup the decoration/window attributes and
804 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
806 /* Make broken apps behave as a nice app. */
807 if (WFLAGP(wwin
, emulate_appicon
))
808 wwin
->main_window
= wwin
->client_win
;
810 fixLeaderProperties(wwin
);
812 wwin
->orig_main_window
= wwin
->main_window
;
814 if (wwin
->flags
.is_gnustep
)
815 wwin
->client_flags
.shared_appicon
= 0;
817 if (wwin
->main_window
) {
818 XTextProperty text_prop
;
820 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, w_global
.atom
.wmaker
.menu
))
821 wwin
->client_flags
.shared_appicon
= 0;
824 if (wwin
->flags
.is_dockapp
)
825 wwin
->client_flags
.shared_appicon
= 0;
827 if (wwin
->main_window
) {
828 WApplication
*app
= wApplicationOf(wwin
->main_window
);
829 if (app
&& app
->app_icon
)
830 wwin
->client_flags
.shared_appicon
= 0;
833 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
834 char *buffer
, *instance
, *class;
835 WFakeGroupLeader
*fPtr
;
838 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
840 /* // only enter here if PropGetWMClass() succeeds */
841 PropGetWMClass(wwin
->main_window
, &class, &instance
);
842 buffer
= StrConcatDot(instance
, class);
844 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
845 if (index
!= WANotFound
) {
846 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
847 if (fPtr
->retainCount
== 0)
848 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
852 if (fPtr
->origLeader
== None
) {
853 if (ADEQUATE(wwin
->main_window
)) {
855 fPtr
->origLeader
= wwin
->main_window
;
858 wwin
->fake_group
= fPtr
;
859 wwin
->main_window
= fPtr
->leader
;
862 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
864 fPtr
->identifier
= buffer
;
865 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
866 fPtr
->origLeader
= None
;
867 fPtr
->retainCount
= 1;
869 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
871 if (ADEQUATE(wwin
->main_window
)) {
873 fPtr
->origLeader
= wwin
->main_window
;
875 wwin
->fake_group
= fPtr
;
876 wwin
->main_window
= fPtr
->leader
;
888 * Setup the initial state of the window
890 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
891 wwin
->flags
.miniaturized
= 1;
893 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
894 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
896 wNETWMCheckInitialClientState(wwin
);
898 /* apply previous state if it exists and we're in startup */
899 if (scr
->flags
.startup
&& wm_state
>= 0) {
900 if (wm_state
== IconicState
)
901 wwin
->flags
.miniaturized
= 1;
902 else if (wm_state
== WithdrawnState
)
906 /* if there is a saved state (from file), restore it */
908 if (wwin
->main_window
!= None
)
909 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
911 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
913 if (win_state
&& !withdraw
) {
914 if (win_state
->state
->hidden
> 0)
915 wwin
->flags
.hidden
= win_state
->state
->hidden
;
917 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
918 wwin
->flags
.shaded
= win_state
->state
->shaded
;
920 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
921 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
923 if (win_state
->state
->maximized
> 0)
924 wwin
->flags
.maximized
= win_state
->state
->maximized
;
926 if (!IS_OMNIPRESENT(wwin
)) {
927 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
929 if (w
< 0 || w
>= scr
->workspace_count
) {
930 workspace
= win_state
->state
->workspace
;
931 if (workspace
>= scr
->workspace_count
)
932 workspace
= scr
->current_workspace
;
937 workspace
= scr
->current_workspace
;
941 /* if we're restarting, restore saved state (from hints).
942 * This will overwrite previous */
946 if (getSavedState(window
, &wstate
)) {
947 wwin
->flags
.shaded
= wstate
->shaded
;
948 wwin
->flags
.hidden
= wstate
->hidden
;
949 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
950 wwin
->flags
.maximized
= wstate
->maximized
;
951 if (wwin
->flags
.maximized
) {
952 wwin
->old_geometry
.x
= wstate
->x
;
953 wwin
->old_geometry
.y
= wstate
->y
;
954 wwin
->old_geometry
.width
= wstate
->w
;
955 wwin
->old_geometry
.height
= wstate
->h
;
958 workspace
= wstate
->workspace
;
963 /* restore window shortcut */
964 if (wstate
!= NULL
|| win_state
!= NULL
) {
967 if (win_state
!= NULL
)
968 mask
= win_state
->state
->window_shortcuts
;
970 if (wstate
!= NULL
&& mask
== 0)
971 mask
= wstate
->window_shortcuts
;
976 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
977 if (mask
& (1 << i
)) {
978 if (!scr
->shortcutWindows
[i
])
979 scr
->shortcutWindows
[i
] = WMCreateArray(4);
981 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
991 /* don't let transients start miniaturized if their owners are not */
992 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
993 wwin
->flags
.miniaturized
= 0;
995 wwin
->wm_hints
->initial_state
= NormalState
;
998 /* set workspace on which the window starts */
999 if (workspace
>= 0) {
1000 if (workspace
> scr
->workspace_count
- 1)
1001 workspace
= workspace
% scr
->workspace_count
;
1005 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
1007 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1010 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
1011 workspace
= transientOwner
->frame
->workspace
;
1013 workspace
= scr
->current_workspace
;
1017 /* setup window geometry */
1018 if (win_state
&& win_state
->state
->w
> 0) {
1019 width
= win_state
->state
->w
;
1020 height
= win_state
->state
->h
;
1023 wWindowConstrainSize(wwin
, &width
, &height
);
1025 /* do not ask for window placement if the window is
1026 * transient, during startup, or if the window wants
1027 * to start iconic. If geometry was saved, restore it. */
1029 Bool dontBring
= False
;
1031 if (win_state
&& win_state
->state
->w
> 0) {
1032 x
= win_state
->state
->x
;
1033 y
= win_state
->state
->y
;
1034 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
1035 && !scr
->flags
.startup
1036 && !wwin
->flags
.miniaturized
1037 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
1039 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1040 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
1044 x
= transientOwner
->frame_x
+
1045 abs(((int)transientOwner
->frame
->core
->width
- (int)width
) / 2) + offs
;
1046 y
= transientOwner
->frame_y
+
1047 abs(((int)transientOwner
->frame
->core
->height
- (int)height
) / 3) + offs
;
1049 /* limit transient windows to be inside their parent's head */
1050 rect
.pos
.x
= transientOwner
->frame_x
;
1051 rect
.pos
.y
= transientOwner
->frame_y
;
1052 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1053 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1055 head
= wGetHeadForRect(scr
, rect
);
1056 rect
= wGetRectForHead(scr
, head
);
1060 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1061 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1065 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1066 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1069 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1072 if (wPreferences
.window_placement
== WPM_MANUAL
)
1075 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1080 /* Make spash screens come out in the center of a head
1081 * trouble is that most splashies never get here
1082 * they are managed trough atoms but god knows where.
1083 * Dan, do you know ? -peter
1085 * Most of them are not managed, they have set
1086 * OverrideRedirect, which means we can't do anything about
1089 /* xinerama checks for: across head and dead space */
1092 rect
.size
.width
= width
;
1093 rect
.size
.height
= height
;
1095 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1097 if (flags
& XFLAG_DEAD
)
1100 if (flags
& XFLAG_MULTIPLE
)
1104 switch (reposition
) {
1106 head
= wGetHeadForPointerLocation(scr
);
1107 rect
= wGetRectForHead(scr
, head
);
1109 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1110 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1114 rect
= wGetRectForHead(scr
, head
);
1118 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1119 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1123 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1124 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1133 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1134 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1137 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1139 if (wwin
->flags
.urgent
) {
1140 if (!IS_OMNIPRESENT(wwin
))
1141 wwin
->flags
.omnipresent
^= 1;
1144 /* Create frame, borders and do reparenting */
1145 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1146 #ifdef XKB_BUTTON_HINT
1147 if (wPreferences
.modelock
)
1148 foo
|= WFF_LANGUAGE_BUTTON
;
1150 if (HAS_TITLEBAR(wwin
))
1151 foo
|= WFF_TITLEBAR
;
1153 if (HAS_RESIZEBAR(wwin
))
1154 foo
|= WFF_RESIZEBAR
;
1156 if (HAS_BORDER(wwin
))
1159 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1160 x
, y
, width
, height
,
1161 &wPreferences
.window_title_clearance
,
1162 &wPreferences
.window_title_min_height
,
1163 &wPreferences
.window_title_max_height
,
1165 scr
->window_title_texture
,
1166 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1167 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1169 wwin
->frame
->flags
.is_client_window_frame
= 1;
1170 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1172 wNETWMCheckInitialFrameState(wwin
);
1174 /* setup button images */
1175 wWindowUpdateButtonImages(wwin
);
1177 /* hide unused buttons */
1179 if (WFLAGP(wwin
, no_close_button
))
1180 foo
|= WFF_RIGHT_BUTTON
;
1182 if (WFLAGP(wwin
, no_miniaturize_button
))
1183 foo
|= WFF_LEFT_BUTTON
;
1185 #ifdef XKB_BUTTON_HINT
1186 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1187 foo
|= WFF_LANGUAGE_BUTTON
;
1190 wFrameWindowHideButton(wwin
->frame
, foo
);
1192 wwin
->frame
->child
= wwin
;
1193 wwin
->frame
->workspace
= workspace
;
1194 wwin
->frame
->on_click_left
= windowIconifyClick
;
1196 #ifdef XKB_BUTTON_HINT
1197 if (wPreferences
.modelock
)
1198 wwin
->frame
->on_click_language
= windowLanguageClick
;
1201 wwin
->frame
->on_click_right
= windowCloseClick
;
1202 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1203 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1204 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1205 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1207 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1208 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1209 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1214 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1216 /* if gravity is to the south, account for the border sizes */
1218 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1222 * wWindowConfigure() will init the client window's size
1223 * (wwin->client.{width,height}) and all other geometry
1224 * related variables (frame_x,frame_y) */
1225 wWindowConfigure(wwin
, x
, y
, width
, height
);
1227 /* to make sure the window receives it's new position after reparenting */
1228 wWindowSynthConfigureNotify(wwin
);
1230 /* Setup descriptors and save window to internal lists */
1231 if (wwin
->main_window
!= None
) {
1235 /* Leader windows do not necessary set themselves as leaders.
1236 * If this is the case, point the leader of this window to
1238 leader
= wWindowFor(wwin
->main_window
);
1239 if (leader
&& leader
->main_window
== None
)
1240 leader
->main_window
= leader
->client_win
;
1242 app
= wApplicationCreate(wwin
);
1244 app
->last_workspace
= workspace
;
1246 /* Do application specific stuff, like setting application
1247 * wide attributes. */
1249 if (wwin
->flags
.hidden
) {
1250 /* if the window was set to hidden because it was hidden
1251 * in a previous incarnation and that state was restored */
1252 app
->flags
.hidden
= 1;
1253 } else if (app
->flags
.hidden
) {
1254 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1255 wwin
->flags
.hidden
= 1;
1257 wUnhideApplication(app
, False
, False
);
1265 /* setup the frame descriptor */
1266 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1267 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1268 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1270 /* don't let windows go away if we die */
1271 XAddToSaveSet(dpy
, window
);
1273 XLowerWindow(dpy
, window
);
1275 /* if window is in this workspace and should be mapped, then map it */
1276 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1277 && !wwin
->flags
.hidden
&& !withdraw
) {
1279 /* The following "if" is to avoid crashing of clients that expect
1280 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1281 * after the return from this function. */
1282 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1283 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1285 wClientSetState(wwin
, NormalState
, None
);
1287 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1288 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1290 * The brain damaged idiotic non-click to focus modes will
1291 * have trouble with this because:
1293 * 1. window is created and mapped by the client
1294 * 2. window is mapped by wmaker in small size
1295 * 3. window is animated to grow to normal size
1296 * 4. this function returns to normal event loop
1297 * 5. eventually, the EnterNotify event that would trigger
1298 * the window focusing (if the mouse is over that window)
1299 * will be processed by wmaker.
1300 * But since this event will be rather delayed
1301 * (step 3 has a large delay) the time when the event occurred
1302 * and when it is processed, the client that owns that window
1303 * will reject the XSetInputFocus() for it.
1305 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1306 DoWindowBirth(wwin
);
1311 /* setup stacking descriptor */
1313 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1315 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1317 if (!scr
->focused_window
) {
1318 /* first window on the list */
1321 scr
->focused_window
= wwin
;
1325 /* add window at beginning of focus window list */
1326 tmp
= scr
->focused_window
;
1335 /* raise is set to true if we un-hid the app when this window was born.
1336 * we raise, else old windows of this app will be above this new one. */
1338 wRaiseFrame(wwin
->frame
->core
);
1340 /* Update name must come after WApplication stuff is done */
1341 wWindowUpdateName(wwin
, title
);
1347 /* Final preparations before window is ready to go */
1348 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1350 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1351 if (((transientOwner
&& transientOwner
->flags
.focused
)
1352 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1354 /* only auto_focus if on same screen as mouse
1355 * (and same head for xinerama mode)
1356 * TODO: make it an option */
1358 /*TODO add checking the head of the window, is it available? */
1359 short same_screen
= 0, same_head
= 1;
1365 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1366 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1369 if (same_screen
== 1 && same_head
== 1)
1370 wSetFocusTo(scr
, wwin
);
1373 wWindowResetMouseGrabs(wwin
);
1375 if (!WFLAGP(wwin
, no_bind_keys
))
1376 wWindowSetKeyGrabs(wwin
);
1378 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1379 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1381 /* Setup Notification Observers */
1382 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1384 /* Cleanup temporary stuff */
1386 wWindowDeleteSavedState(win_state
);
1388 /* If the window must be withdrawed, then do it now.
1389 * Must do some optimization, 'though */
1391 wwin
->flags
.mapped
= 0;
1392 wClientSetState(wwin
, WithdrawnState
, None
);
1393 wUnmanageWindow(wwin
, True
, False
);
1400 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1401 const char *title
, int x
, int y
, int width
, int height
)
1406 wwin
= wWindowCreate();
1408 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1410 wwin
->flags
.internal_window
= 1;
1412 wwin
->client_flags
.omnipresent
= 1;
1413 wwin
->client_flags
.no_shadeable
= 1;
1414 wwin
->client_flags
.no_resizable
= 1;
1415 wwin
->client_flags
.no_miniaturizable
= 1;
1417 wwin
->focus_mode
= WFM_PASSIVE
;
1418 wwin
->client_win
= window
;
1419 wwin
->screen_ptr
= scr
;
1420 wwin
->transient_for
= owner
;
1423 wwin
->client
.width
= width
;
1424 wwin
->client
.height
= height
;
1425 wwin
->frame_x
= wwin
->client
.x
;
1426 wwin
->frame_y
= wwin
->client
.y
;
1428 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1429 foo
|= WFF_TITLEBAR
;
1430 #ifdef XKB_BUTTON_HINT
1431 foo
|= WFF_LANGUAGE_BUTTON
;
1434 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1435 wwin
->frame_x
, wwin
->frame_y
,
1437 &wPreferences
.window_title_clearance
,
1438 &wPreferences
.window_title_min_height
,
1439 &wPreferences
.window_title_max_height
,
1441 scr
->window_title_texture
,
1442 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1443 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1445 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
1447 wwin
->frame
->flags
.is_client_window_frame
= 1;
1448 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1450 wFrameWindowChangeTitle(wwin
->frame
, title
);
1452 /* setup button images */
1453 wWindowUpdateButtonImages(wwin
);
1456 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1458 wwin
->frame
->child
= wwin
;
1459 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1461 #ifdef XKB_BUTTON_HINT
1462 if (wPreferences
.modelock
)
1463 wwin
->frame
->on_click_language
= windowLanguageClick
;
1466 wwin
->frame
->on_click_right
= windowCloseClick
;
1467 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1468 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1469 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1470 wwin
->client
.y
+= wwin
->frame
->top_width
;
1472 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1473 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1475 /* setup the frame descriptor */
1476 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1477 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1478 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1480 XLowerWindow(dpy
, window
);
1481 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1483 /* setup stacking descriptor */
1484 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1486 tmp
= wWindowFor(wwin
->transient_for
);
1488 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1490 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1493 if (!scr
->focused_window
) {
1494 /* first window on the list */
1497 scr
->focused_window
= wwin
;
1501 /* add window at beginning of focus window list */
1502 tmp
= scr
->focused_window
;
1510 if (wwin
->flags
.is_gnustep
== 0)
1511 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1513 /* if (wPreferences.auto_focus) */
1514 wSetFocusTo(scr
, wwin
);
1515 wWindowResetMouseGrabs(wwin
);
1516 wWindowSetKeyGrabs(wwin
);
1522 *----------------------------------------------------------------------
1524 * Removes the frame window from a window and destroys all data
1525 * related to it. The window will be reparented back to the root window
1526 * if restore is True.
1529 * Everything related to the window is destroyed and the window
1530 * is removed from the window lists. Focus is set to the previous on the
1532 *----------------------------------------------------------------------
1534 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1536 WCoreWindow
*frame
= wwin
->frame
->core
;
1537 WWindow
*owner
= NULL
;
1538 WWindow
*newFocusedWindow
= NULL
;
1540 WScreen
*scr
= wwin
->screen_ptr
;
1542 /* First close attribute editor window if open */
1543 if (wwin
->flags
.inspector_open
)
1544 wCloseInspectorForWindow(wwin
);
1546 /* Close window menu if it's open for this window */
1547 if (wwin
->flags
.menu_open_for_me
)
1548 CloseWindowMenu(scr
);
1550 /* Don't restore focus to this window after a window exits
1551 * fullscreen mode */
1552 if (scr
->bfs_focused_window
== wwin
)
1553 scr
->bfs_focused_window
= NULL
;
1556 if (!wwin
->flags
.internal_window
)
1557 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1559 /* If this is a leader window, we still need to listen for
1560 * DestroyNotify and PropertyNotify. */
1561 if (wApplicationOf(wwin
->client_win
))
1562 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1564 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1566 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1567 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1570 XUnmapWindow(dpy
, frame
->window
);
1572 XUnmapWindow(dpy
, wwin
->client_win
);
1574 /* deselect window */
1575 wSelectWindow(wwin
, False
);
1577 /* remove all pending events on window */
1578 /* I think this only matters for autoraise */
1579 if (wPreferences
.raise_delay
)
1580 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1584 /* reparent the window back to the root */
1586 wClientRestore(wwin
);
1588 if (wwin
->transient_for
!= scr
->root_win
) {
1589 owner
= wWindowFor(wwin
->transient_for
);
1591 if (!owner
->flags
.semi_focused
)
1594 owner
->flags
.semi_focused
= 0;
1598 wasFocused
= wwin
->flags
.focused
;
1600 /* remove from window focus list */
1601 if (!wwin
->prev
&& !wwin
->next
) {
1602 /* was the only window */
1603 scr
->focused_window
= NULL
;
1604 newFocusedWindow
= NULL
;
1609 wwin
->prev
->next
= wwin
->next
;
1612 wwin
->next
->prev
= wwin
->prev
;
1614 scr
->focused_window
= wwin
->prev
;
1615 scr
->focused_window
->next
= NULL
;
1618 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1620 /* if in click to focus mode and the window
1621 * was a transient, focus the owner window
1624 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1625 tmp
= wWindowFor(wwin
->transient_for
);
1626 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1630 /* otherwise, focus the next one in the focus list */
1632 tmp
= scr
->focused_window
;
1633 while (tmp
) { /* look for one in the window list first */
1634 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1635 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1639 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1640 tmp
= scr
->focused_window
;
1642 if (!WFLAGP(tmp
, no_focusable
)
1643 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1650 newFocusedWindow
= tmp
;
1652 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1657 /* This is to let the root window get the keyboard input
1658 * if Sloppy focus mode and no other window get focus.
1659 * This way keybindings will not freeze.
1662 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1663 tmp
= wWindowFor(win
);
1666 newFocusedWindow
= tmp
;
1668 newFocusedWindow
= NULL
;
1672 if (!wwin
->flags
.internal_window
)
1673 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1675 if (newFocusedWindow
!= owner
&& owner
) {
1676 if (wwin
->flags
.is_gnustep
== 0)
1677 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1679 wSetFocusTo(scr
, newFocusedWindow
);
1682 /* Close menu and unhighlight */
1683 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1684 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1685 if (oapp
&& oapp
!= napp
) {
1686 wAppMenuUnmap(oapp
->menu
);
1687 if (wPreferences
.highlight_active_app
)
1688 wApplicationDeactivate(oapp
);
1691 wNETCleanupFrameExtents(wwin
);
1693 wWindowDestroy(wwin
);
1697 void wWindowMap(WWindow
*wwin
)
1699 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1700 if (!wwin
->flags
.shaded
) {
1701 /* window will be remapped when getting MapNotify */
1702 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1703 XMapWindow(dpy
, wwin
->client_win
);
1704 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1706 wwin
->flags
.mapped
= 1;
1710 void wWindowUnmap(WWindow
*wwin
)
1712 wwin
->flags
.mapped
= 0;
1714 /* prevent window withdrawal when getting UnmapNotify */
1715 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1716 XUnmapWindow(dpy
, wwin
->client_win
);
1717 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1719 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1722 void wWindowSingleFocus(WWindow
*wwin
)
1730 scr
= wwin
->screen_ptr
;
1731 wMakeWindowVisible(wwin
);
1736 /* bring window back to visible area */
1737 move
= wScreenBringInside(scr
, &x
, &y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1740 wWindowConfigure(wwin
, x
, y
, wwin
->client
.width
, wwin
->client
.height
);
1743 void wWindowFocusPrev(WWindow
*wwin
, Bool inSameWorkspace
)
1747 if (!wwin
|| !wwin
->prev
)
1754 if (inSameWorkspace
)
1755 while (tmp
&& (tmp
->frame
->workspace
!= wwin
->frame
->workspace
))
1758 wWindowSingleFocus(tmp
);
1761 void wWindowFocusNext(WWindow
*wwin
, Bool inSameWorkspace
)
1765 if (!wwin
|| !wwin
->prev
)
1769 if (inSameWorkspace
)
1770 while (tmp
&& (tmp
->frame
->workspace
!= wwin
->frame
->workspace
))
1773 wWindowSingleFocus(tmp
);
1776 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1781 #ifdef KEEP_XKB_LOCK_STATUS
1782 if (wPreferences
.modelock
)
1783 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1784 #endif /* KEEP_XKB_LOCK_STATUS */
1786 wwin
->flags
.semi_focused
= 0;
1788 if (wwin
->flags
.is_gnustep
== 0)
1789 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1791 wwin
->flags
.focused
= 1;
1793 wWindowResetMouseGrabs(wwin
);
1795 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1797 if (owin
== wwin
|| !owin
)
1800 nowner
= wWindowFor(wwin
->transient_for
);
1802 /* new window is a transient for the old window */
1803 if (nowner
== owin
) {
1804 owin
->flags
.semi_focused
= 1;
1805 wWindowUnfocus(nowner
);
1809 oowner
= wWindowFor(owin
->transient_for
);
1811 /* new window is owner of old window */
1812 if (wwin
== oowner
) {
1813 wWindowUnfocus(owin
);
1818 wWindowUnfocus(owin
);
1822 /* new window has same owner of old window */
1823 if (oowner
== nowner
) {
1824 /* prevent unfocusing of owner */
1825 oowner
->flags
.semi_focused
= 0;
1826 wWindowUnfocus(owin
);
1827 oowner
->flags
.semi_focused
= 1;
1832 /* nowner != NULL && oowner != nowner */
1833 nowner
->flags
.semi_focused
= 1;
1834 wWindowUnfocus(nowner
);
1835 wWindowUnfocus(owin
);
1838 void wWindowUnfocus(WWindow
*wwin
)
1840 CloseWindowMenu(wwin
->screen_ptr
);
1842 if (wwin
->flags
.is_gnustep
== 0)
1843 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1845 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1847 owner
= wWindowFor(wwin
->transient_for
);
1848 if (owner
&& owner
->flags
.semi_focused
) {
1849 owner
->flags
.semi_focused
= 0;
1850 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1851 wWindowUnfocus(owner
);
1852 wFrameWindowPaint(owner
->frame
);
1856 wwin
->flags
.focused
= 0;
1857 wWindowResetMouseGrabs(wwin
);
1858 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1861 void wWindowUpdateName(WWindow
*wwin
, const char *newTitle
)
1869 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1873 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1874 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1878 *----------------------------------------------------------------------
1880 * wWindowConstrainSize--
1881 * Constrains size for the client window, taking the maximal size,
1882 * window resize increments and other size hints into account.
1885 * The closest size to what was given that the client window can
1888 *----------------------------------------------------------------------
1890 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1892 int width
= (int)*nwidth
;
1893 int height
= (int)*nheight
;
1896 int minW
= 1, minH
= 1;
1897 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1898 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1899 int minAX
= -1, minAY
= -1;
1900 int maxAX
= -1, maxAY
= -1;
1905 * X11 proto defines width and height as a CARD16
1906 * if window size is guaranteed to fail, failsafe to a reasonable size
1908 if (width
> USHRT_MAX
&& height
> USHRT_MAX
) {
1914 if (wwin
->normal_hints
) {
1915 if (!wwin
->flags
.maximized
) {
1916 winc
= wwin
->normal_hints
->width_inc
;
1917 hinc
= wwin
->normal_hints
->height_inc
;
1919 minW
= wwin
->normal_hints
->min_width
;
1920 minH
= wwin
->normal_hints
->min_height
;
1921 maxW
= wwin
->normal_hints
->max_width
;
1922 maxH
= wwin
->normal_hints
->max_height
;
1923 if (wwin
->normal_hints
->flags
& PAspect
) {
1924 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1925 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1926 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1927 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1930 baseW
= wwin
->normal_hints
->base_width
;
1931 baseH
= wwin
->normal_hints
->base_height
;
1934 /* trust the mins provided by the client but not the maxs */
1940 /* if only one dimension is over the top, set a default 4/3 ratio */
1941 if (width
> maxW
&& height
< maxH
) {
1942 width
= height
* 4 / 3;
1944 if(height
> maxH
&& width
< maxW
)
1945 height
= width
* 3 / 4;
1948 /* aspect ratio code borrowed from olwm */
1950 /* adjust max aspect ratio */
1951 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1952 if (maxAX
> maxAY
) {
1953 height
= (width
* maxAY
) / maxAX
;
1954 if (height
> maxH
) {
1956 width
= (height
* maxAX
) / maxAY
;
1959 width
= (height
* maxAX
) / maxAY
;
1962 height
= (width
* maxAY
) / maxAX
;
1967 /* adjust min aspect ratio */
1968 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1969 if (minAX
> minAY
) {
1970 height
= (width
* minAY
) / minAX
;
1971 if (height
< minH
) {
1973 width
= (height
* minAX
) / minAY
;
1976 width
= (height
* minAX
) / minAY
;
1979 height
= (width
* minAY
) / minAX
;
1985 if (!wwin
->flags
.maximized
) {
1987 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1989 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1992 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1994 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1997 /* broken stupid apps may cause preposterous values for these.. */
2004 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
2005 unsigned int *width
, unsigned int *height
)
2007 int baseW
= 0, baseH
= 0;
2008 int winc
= 1, hinc
= 1;
2010 if (wwin
->normal_hints
) {
2011 baseW
= wwin
->normal_hints
->base_width
;
2012 baseH
= wwin
->normal_hints
->base_height
;
2014 winc
= wwin
->normal_hints
->width_inc
;
2015 hinc
= wwin
->normal_hints
->height_inc
;
2019 *width
= maxW
- (maxW
- baseW
) % winc
;
2022 *height
= maxH
- (maxH
- baseH
) % hinc
;
2025 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
2027 WScreen
*scr
= wwin
->screen_ptr
;
2031 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
2034 if (workspace
!= scr
->current_workspace
) {
2035 /* Sent to other workspace. Unmap window */
2036 if ((wwin
->flags
.mapped
2037 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
2038 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
2040 wapp
= wApplicationOf(wwin
->main_window
);
2042 wapp
->last_workspace
= workspace
;
2044 if (wwin
->flags
.miniaturized
) {
2046 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
2047 wwin
->icon
->mapped
= 0;
2051 wSetFocusTo(scr
, NULL
);
2055 /* brought to current workspace. Map window */
2056 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
2058 XMapWindow(dpy
, wwin
->icon
->core
->window
);
2059 wwin
->icon
->mapped
= 1;
2061 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
2065 if (!IS_OMNIPRESENT(wwin
)) {
2066 int oldWorkspace
= wwin
->frame
->workspace
;
2067 wwin
->frame
->workspace
= workspace
;
2068 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
2075 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
2077 WScreen
*scr
= wwin
->screen_ptr
;
2078 int w
= scr
->current_workspace
+ amount
;
2082 wWindowChangeWorkspace(wwin
, w
);
2083 } else if (wPreferences
.ws_cycle
) {
2084 wWindowChangeWorkspace(wwin
, scr
->workspace_count
+ w
);
2086 } else if (amount
> 0) {
2087 if (w
< scr
->workspace_count
) {
2088 wWindowChangeWorkspace(wwin
, w
);
2089 } else if (wPreferences
.ws_advance
) {
2090 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
2091 wWorkspaceMake(scr
, workspace
);
2092 wWindowChangeWorkspace(wwin
, workspace
);
2093 } else if (wPreferences
.ws_cycle
) {
2094 wWindowChangeWorkspace(wwin
, w
% scr
->workspace_count
);
2099 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2103 sevent
.type
= ConfigureNotify
;
2104 sevent
.xconfigure
.display
= dpy
;
2105 sevent
.xconfigure
.event
= wwin
->client_win
;
2106 sevent
.xconfigure
.window
= wwin
->client_win
;
2108 sevent
.xconfigure
.x
= wwin
->client
.x
;
2109 sevent
.xconfigure
.y
= wwin
->client
.y
;
2110 sevent
.xconfigure
.width
= wwin
->client
.width
;
2111 sevent
.xconfigure
.height
= wwin
->client
.height
;
2113 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2114 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2115 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2117 sevent
.xconfigure
.above
= None
;
2119 sevent
.xconfigure
.override_redirect
= False
;
2120 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2125 *----------------------------------------------------------------------
2126 * wWindowConfigure()
2128 * req_x, req_y: new requested positions for the frame
2129 * req_width, req_height: new requested sizes for the client
2131 * Configures the frame, decorations and client window to the specified
2132 * geometry, whose validity is not checked -- wWindowConstrainSize()
2133 * must be used for that.
2134 * The size parameters are for the client window, but the position is
2136 * The client window receives a ConfigureNotify event, according
2137 * to what ICCCM says.
2143 * Window size and position are changed and client window receives
2144 * a ConfigureNotify event.
2145 *----------------------------------------------------------------------
2147 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2149 int synth_notify
= False
;
2152 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2154 if (WFLAGP(wwin
, dont_move_off
))
2155 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2158 if (req_width
< MIN_WINDOW_SIZE
)
2159 req_width
= MIN_WINDOW_SIZE
;
2160 if (req_height
< MIN_WINDOW_SIZE
)
2161 req_height
= MIN_WINDOW_SIZE
;
2163 /* If growing, resize inner part before frame,
2164 * if shrinking, resize frame before.
2165 * This will prevent the frame (that can have a different color)
2166 * to be exposed, causing flicker */
2167 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2168 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2170 if (wwin
->flags
.shaded
) {
2171 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2172 wwin
->old_geometry
.height
= req_height
;
2176 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2178 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2181 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2182 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2184 wwin
->client
.x
= req_x
;
2185 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2186 wwin
->client
.width
= req_width
;
2187 wwin
->client
.height
= req_height
;
2189 if (req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) {
2190 wwin
->client
.x
= req_x
;
2191 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2192 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2195 * if the window is being moved but not resized
2196 * or if we change nothing then
2197 * send a synthetic ConfigureNotify
2199 synth_notify
= True
;
2201 wwin
->frame_x
= req_x
;
2202 wwin
->frame_y
= req_y
;
2203 if (HAS_BORDER(wwin
)) {
2204 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2205 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2208 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
&& resize
)
2209 wWindowSetShape(wwin
);
2213 wWindowSynthConfigureNotify(wwin
);
2215 wNETFrameExtents(wwin
);
2220 /* req_x, req_y: new position of the frame */
2221 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2223 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2224 int synth_notify
= False
;
2226 /* Send a synthetic ConfigureNotify event for every window movement. */
2227 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2228 synth_notify
= True
;
2230 /* A single synthetic ConfigureNotify event is sent at the end of
2231 * a completed (opaque) movement in moveres.c */
2234 if (WFLAGP(wwin
, dont_move_off
))
2235 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2236 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2238 wwin
->client
.x
= req_x
;
2239 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2240 if (HAS_BORDER(wwin
)) {
2241 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2242 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2245 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2247 wwin
->frame_x
= req_x
;
2248 wwin
->frame_y
= req_y
;
2250 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2252 wWindowSynthConfigureNotify(wwin
);
2256 void wWindowUpdateButtonImages(WWindow
*wwin
)
2258 WScreen
*scr
= wwin
->screen_ptr
;
2259 Pixmap pixmap
, mask
;
2260 WFrameWindow
*fwin
= wwin
->frame
;
2262 if (!HAS_TITLEBAR(wwin
))
2265 /* miniaturize button */
2266 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2267 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2268 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2270 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2271 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2275 if (fwin
->lbutton_image
2276 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2277 wPixmapDestroy(fwin
->lbutton_image
);
2278 fwin
->lbutton_image
= NULL
;
2281 if (!fwin
->lbutton_image
) {
2282 fwin
->lbutton_image
= wPixmapCreate(pixmap
, mask
);
2283 fwin
->lbutton_image
->client_owned
= 1;
2284 fwin
->lbutton_image
->client_owned_mask
= 1;
2287 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2288 wPixmapDestroy(fwin
->lbutton_image
);
2290 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2293 #ifdef XKB_BUTTON_HINT
2294 if (!WFLAGP(wwin
, no_language_button
)) {
2295 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2296 wPixmapDestroy(fwin
->languagebutton_image
);
2298 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2304 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2305 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2307 if (!WFLAGP(wwin
, no_close_button
)) {
2308 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2309 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2311 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2312 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2316 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2317 || fwin
->rbutton_image
->mask
!= mask
)) {
2318 wPixmapDestroy(fwin
->rbutton_image
);
2319 fwin
->rbutton_image
= NULL
;
2322 if (!fwin
->rbutton_image
) {
2323 fwin
->rbutton_image
= wPixmapCreate(pixmap
, mask
);
2324 fwin
->rbutton_image
->client_owned
= 1;
2325 fwin
->rbutton_image
->client_owned_mask
= 1;
2328 } else if (WFLAGP(wwin
, kill_close
)) {
2329 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2330 wPixmapDestroy(fwin
->rbutton_image
);
2332 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2334 } else if (MGFLAGP(wwin
, broken_close
)) {
2335 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2336 wPixmapDestroy(fwin
->rbutton_image
);
2338 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2341 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2342 wPixmapDestroy(fwin
->rbutton_image
);
2344 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2348 /* force buttons to be redrawn */
2349 fwin
->flags
.need_texture_change
= 1;
2350 wFrameWindowPaint(fwin
);
2354 *---------------------------------------------------------------------------
2355 * wWindowConfigureBorders--
2356 * Update window border configuration according to attribute flags.
2358 *---------------------------------------------------------------------------
2360 void wWindowConfigureBorders(WWindow
*wwin
)
2366 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2368 #ifdef XKB_BUTTON_HINT
2369 if (wPreferences
.modelock
)
2370 flags
|= WFF_LANGUAGE_BUTTON
;
2373 if (HAS_TITLEBAR(wwin
))
2374 flags
|= WFF_TITLEBAR
;
2375 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2376 flags
|= WFF_RESIZEBAR
;
2377 if (HAS_BORDER(wwin
))
2378 flags
|= WFF_BORDER
;
2379 if (wwin
->flags
.shaded
)
2380 flags
|= WFF_IS_SHADED
;
2381 if (wwin
->flags
.selected
)
2382 flags
|= WFF_SELECTED
;
2384 oldh
= wwin
->frame
->top_width
;
2385 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2386 if (oldh
!= wwin
->frame
->top_width
) {
2387 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2389 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2390 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2394 if (!WFLAGP(wwin
, no_miniaturize_button
)
2395 && wwin
->frame
->flags
.hide_left_button
)
2396 flags
|= WFF_LEFT_BUTTON
;
2398 #ifdef XKB_BUTTON_HINT
2399 if (!WFLAGP(wwin
, no_language_button
)
2400 && wwin
->frame
->flags
.hide_language_button
)
2401 flags
|= WFF_LANGUAGE_BUTTON
;
2404 if (!WFLAGP(wwin
, no_close_button
)
2405 && wwin
->frame
->flags
.hide_right_button
)
2406 flags
|= WFF_RIGHT_BUTTON
;
2409 wWindowUpdateButtonImages(wwin
);
2410 wFrameWindowShowButton(wwin
->frame
, flags
);
2414 if (WFLAGP(wwin
, no_miniaturize_button
)
2415 && !wwin
->frame
->flags
.hide_left_button
)
2416 flags
|= WFF_LEFT_BUTTON
;
2418 #ifdef XKB_BUTTON_HINT
2419 if (WFLAGP(wwin
, no_language_button
)
2420 && !wwin
->frame
->flags
.hide_language_button
)
2421 flags
|= WFF_LANGUAGE_BUTTON
;
2424 if (WFLAGP(wwin
, no_close_button
)
2425 && !wwin
->frame
->flags
.hide_right_button
)
2426 flags
|= WFF_RIGHT_BUTTON
;
2429 wFrameWindowHideButton(wwin
->frame
, flags
);
2432 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
)
2433 wWindowSetShape(wwin
);
2438 void wWindowSaveState(WWindow
*wwin
)
2443 memset(data
, 0, sizeof(long) * 10);
2444 data
[0] = wwin
->frame
->workspace
;
2445 data
[1] = wwin
->flags
.miniaturized
;
2446 data
[2] = wwin
->flags
.shaded
;
2447 data
[3] = wwin
->flags
.hidden
;
2448 data
[4] = wwin
->flags
.maximized
;
2449 if (wwin
->flags
.maximized
== 0) {
2450 data
[5] = wwin
->frame_x
;
2451 data
[6] = wwin
->frame_y
;
2452 data
[7] = wwin
->frame
->core
->width
;
2453 data
[8] = wwin
->frame
->core
->height
;
2455 data
[5] = wwin
->old_geometry
.x
;
2456 data
[6] = wwin
->old_geometry
.y
;
2457 data
[7] = wwin
->old_geometry
.width
;
2458 data
[8] = wwin
->old_geometry
.height
;
2461 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2462 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2463 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2467 XChangeProperty(dpy
, wwin
->client_win
, w_global
.atom
.wmaker
.state
,
2468 w_global
.atom
.wmaker
.state
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2471 static int getSavedState(Window window
, WSavedState
** state
)
2475 unsigned long nitems_ret
;
2476 unsigned long bytes_after_ret
;
2479 if (XGetWindowProperty(dpy
, window
, w_global
.atom
.wmaker
.state
, 0, 10,
2480 True
, w_global
.atom
.wmaker
.state
,
2481 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2482 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2485 if (type_ret
!= w_global
.atom
.wmaker
.state
) {
2490 *state
= wmalloc(sizeof(WSavedState
));
2492 (*state
)->workspace
= data
[0];
2493 (*state
)->miniaturized
= data
[1];
2494 (*state
)->shaded
= data
[2];
2495 (*state
)->hidden
= data
[3];
2496 (*state
)->maximized
= data
[4];
2497 (*state
)->x
= data
[5];
2498 (*state
)->y
= data
[6];
2499 (*state
)->w
= data
[7];
2500 (*state
)->h
= data
[8];
2501 (*state
)->window_shortcuts
= data
[9];
2509 void wWindowClearShape(WWindow
* wwin
)
2511 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2512 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2516 void wWindowSetShape(WWindow
* wwin
)
2520 #ifdef OPTIMIZE_SHAPE
2525 /* only shape is the client's */
2526 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2529 /* Get array of rectangles describing the shape mask */
2530 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2534 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2540 /* insert our decoration rectangles in the rect list */
2541 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2544 if (HAS_TITLEBAR(wwin
)) {
2546 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2547 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2548 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2551 if (HAS_RESIZEBAR(wwin
)) {
2553 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2554 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2555 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2559 /* shape our frame window */
2560 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2561 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2567 #endif /* OPTIMIZE_SHAPE */
2569 if (HAS_TITLEBAR(wwin
)) {
2572 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2573 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2576 if (HAS_RESIZEBAR(wwin
)) {
2578 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2579 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2580 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2584 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2585 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2587 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2588 0, wwin
->frame
->top_width
, wwin
->client_win
,
2589 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2592 #endif /* USE_XSHAPE */
2594 /* ====================================================================== */
2596 static FocusMode
getFocusMode(WWindow
* wwin
)
2600 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2601 if (wwin
->wm_hints
->input
== True
) {
2602 if (wwin
->protocols
.TAKE_FOCUS
)
2603 mode
= WFM_LOCALLY_ACTIVE
;
2607 if (wwin
->protocols
.TAKE_FOCUS
)
2608 mode
= WFM_GLOBALLY_ACTIVE
;
2610 mode
= WFM_NO_INPUT
;
2618 void wWindowSetKeyGrabs(WWindow
* wwin
)
2623 for (i
= 0; i
< WKBD_LAST
; i
++) {
2624 key
= &wKeyBindings
[i
];
2626 if (key
->keycode
== 0)
2628 if (key
->modifier
!= AnyModifier
) {
2629 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2630 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2632 /* Also grab all modifier combinations possible that include,
2633 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2634 * work even if the NumLock/ScrollLock key is on.
2636 wHackedGrabKey(key
->keycode
, key
->modifier
,
2637 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2640 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2641 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2644 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2647 void wWindowResetMouseGrabs(WWindow
* wwin
)
2649 /* Mouse grabs can't be done on the client window because of
2650 * ICCCM and because clients that try to do the same will crash.
2652 * But there is a problem which makes tbar buttons of unfocused
2653 * windows not usable as the click goes to the frame window instead
2654 * of the button itself. Must figure a way to fix that.
2657 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2659 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2660 /* grabs for Meta+drag */
2661 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2662 True
, ButtonPressMask
| ButtonReleaseMask
,
2663 GrabModeSync
, GrabModeAsync
, None
, None
);
2665 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2666 * but we only grab it for Button4 and Button 5 since a lot of apps
2667 * use CTRL+Button1-3 for app related functionality
2669 if (wPreferences
.resize_increment
> 0) {
2670 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2671 True
, ButtonPressMask
| ButtonReleaseMask
,
2672 GrabModeSync
, GrabModeAsync
, None
, None
);
2673 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2674 True
, ButtonPressMask
| ButtonReleaseMask
,
2675 GrabModeSync
, GrabModeAsync
, None
, None
);
2677 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2678 True
, ButtonPressMask
| ButtonReleaseMask
,
2679 GrabModeSync
, GrabModeAsync
, None
, None
);
2680 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2681 True
, ButtonPressMask
| ButtonReleaseMask
,
2682 GrabModeSync
, GrabModeAsync
, None
, None
);
2686 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2687 && !wwin
->flags
.is_gnustep
) {
2688 /* the passive grabs to focus the window */
2689 /* if (wPreferences.focus_mode == WKF_CLICK) */
2690 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2691 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2696 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2698 if (attr
->flags
& GSExtraFlagsAttr
) {
2699 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2700 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2701 wWindowUpdateButtonImages(wwin
);
2706 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2707 const char *command
, pid_t pid
, WSavedState
*state
)
2709 WWindowState
*wstate
;
2711 wstate
= malloc(sizeof(WWindowState
));
2715 memset(wstate
, 0, sizeof(WWindowState
));
2718 wstate
->instance
= wstrdup(instance
);
2720 wstate
->class = wstrdup(class);
2722 wstate
->command
= wstrdup(command
);
2723 wstate
->state
= state
;
2725 wstate
->next
= windowState
;
2726 windowState
= wstate
;
2731 static inline int is_same(const char *x
, const char *y
)
2733 if ((x
== NULL
) && (y
== NULL
))
2736 if ((x
== NULL
) || (y
== NULL
))
2739 if (strcmp(x
, y
) == 0)
2745 WMagicNumber
wWindowGetSavedState(Window win
)
2747 char *instance
, *class, *command
= NULL
;
2748 WWindowState
*wstate
= windowState
;
2753 command
= GetCommandForWindow(win
);
2757 if (PropGetWMClass(win
, &class, &instance
)) {
2759 if (is_same(instance
, wstate
->instance
) &&
2760 is_same(class, wstate
->class) &&
2761 is_same(command
, wstate
->command
)) {
2764 wstate
= wstate
->next
;
2780 void wWindowDeleteSavedState(WMagicNumber id
)
2782 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2784 if (!wstate
|| !windowState
)
2788 if (tmp
== wstate
) {
2789 windowState
= wstate
->next
;
2790 release_wwindowstate(wstate
);
2793 if (tmp
->next
== wstate
) {
2794 tmp
->next
= wstate
->next
;
2795 release_wwindowstate(wstate
);
2803 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2805 WWindowState
*tmp
, *wstate
;
2811 if (tmp
->pid
== pid
) {
2812 wstate
= windowState
;
2813 windowState
= tmp
->next
;
2815 release_wwindowstate(wstate
);
2818 if (tmp
->next
->pid
== pid
) {
2820 tmp
->next
= wstate
->next
;
2821 release_wwindowstate(wstate
);
2829 static void release_wwindowstate(WWindowState
*wstate
)
2831 if (wstate
->instance
)
2832 wfree(wstate
->instance
);
2835 wfree(wstate
->class);
2837 if (wstate
->command
)
2838 wfree(wstate
->command
);
2840 wfree(wstate
->state
);
2844 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2846 if (wwin
->flags
.omnipresent
== flag
)
2849 wwin
->flags
.omnipresent
= flag
;
2850 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2853 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2855 WWindow
*wwin
= data
;
2857 /* Parameter not used, but tell the compiler that it is ok */
2860 #ifndef NUMLOCK_HACK
2861 if ((event
->xbutton
.state
& ValidModMask
)
2862 != (event
->xbutton
.state
& ~LockMask
)) {
2863 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2864 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2868 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2870 CloseWindowMenu(wwin
->screen_ptr
);
2872 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2873 && !WFLAGP(wwin
, no_focusable
)) {
2874 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2877 if (event
->xbutton
.button
== Button1
)
2878 wRaiseFrame(wwin
->frame
->core
);
2880 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2881 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2882 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2883 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2888 if (event
->xbutton
.state
& MOD_MASK
) {
2889 /* move the window */
2890 wMouseMoveWindow(wwin
, event
);
2891 XUngrabPointer(dpy
, CurrentTime
);
2893 wMouseResizeWindow(wwin
, event
);
2894 XUngrabPointer(dpy
, CurrentTime
);
2898 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2900 WWindow
*wwin
= data
;
2902 /* Parameter not used, but tell the compiler that it is ok */
2905 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2907 if (event
->xbutton
.button
== Button1
) {
2908 if (event
->xbutton
.state
== 0 ) {
2909 if (!WFLAGP(wwin
, no_shadeable
) & !wPreferences
.double_click_fullscreen
) {
2911 if (wwin
->flags
.shaded
)
2912 wUnshadeWindow(wwin
);
2918 if (wPreferences
.double_click_fullscreen
) {
2921 if (event
->xbutton
.state
== 0) {
2922 /* maximize window full screen*/
2923 dir
|= (MAX_VERTICAL
|MAX_HORIZONTAL
);
2924 int ndir
= dir
^ wwin
->flags
.maximized
;
2926 wMaximizeWindow(wwin
, ndir
, wGetHeadForWindow(wwin
));
2928 wUnmaximizeWindow(wwin
);
2933 if (event
->xbutton
.state
& ControlMask
)
2934 dir
|= MAX_VERTICAL
;
2936 if (event
->xbutton
.state
& ShiftMask
) {
2937 dir
|= MAX_HORIZONTAL
;
2938 if (!(event
->xbutton
.state
& ControlMask
))
2939 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2942 /* maximize window */
2943 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2944 int ndir
= dir
^ wwin
->flags
.maximized
;
2947 wMaximizeWindow(wwin
, ndir
, wGetHeadForWindow(wwin
));
2949 wUnmaximizeWindow(wwin
);
2952 } else if (event
->xbutton
.button
== Button3
) {
2953 if (event
->xbutton
.state
& MOD_MASK
)
2954 wHideOtherApplications(wwin
);
2955 } else if (event
->xbutton
.button
== Button2
) {
2956 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2957 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2959 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2960 wUnshadeWindow(wwin
);
2964 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2966 WWindow
*wwin
= desc
->parent
;
2967 unsigned int new_width
, w_scale
;
2968 unsigned int new_height
, h_scale
;
2969 unsigned int resize_width_increment
= 0;
2970 unsigned int resize_height_increment
= 0;
2972 if (wwin
->normal_hints
) {
2973 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2974 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2975 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2976 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2978 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2979 resize_width_increment
= wPreferences
.resize_increment
;
2980 resize_height_increment
= wPreferences
.resize_increment
;
2983 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2985 CloseWindowMenu(wwin
->screen_ptr
);
2987 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2988 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2990 if (event
->xbutton
.button
== Button1
)
2991 wRaiseFrame(wwin
->frame
->core
);
2993 if (event
->xbutton
.state
& ControlMask
) {
2994 if (event
->xbutton
.button
== Button4
) {
2995 new_width
= wwin
->client
.width
- resize_width_increment
;
2996 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2997 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2999 if (event
->xbutton
.button
== Button5
) {
3000 new_width
= wwin
->client
.width
+ resize_width_increment
;
3001 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
3002 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
3006 if (event
->xbutton
.state
& MOD_MASK
) {
3007 /* move the window */
3008 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
3009 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
3010 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3013 if (event
->xbutton
.button
== Button3
) {
3014 wMouseResizeWindow(wwin
, event
);
3015 } else if (event
->xbutton
.button
== Button4
) {
3016 new_height
= wwin
->client
.height
- resize_height_increment
;
3017 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
3018 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
3019 } else if (event
->xbutton
.button
== Button5
) {
3020 new_height
= wwin
->client
.height
+ resize_height_increment
;
3021 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
3022 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
3023 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
3024 wMouseMoveWindow(wwin
, event
);
3026 XUngrabPointer(dpy
, CurrentTime
);
3030 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3032 WWindow
*wwin
= (WWindow
*) data
;
3034 /* Parameter not used, but tell the compiler that it is ok */
3037 #ifndef NUMLOCK_HACK
3038 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
3039 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
3040 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3042 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
3044 CloseWindowMenu(wwin
->screen_ptr
);
3046 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
3047 && !WFLAGP(wwin
, no_focusable
))
3048 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3050 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
3052 if (event
->xbutton
.button
== Button1
) {
3053 if (event
->xbutton
.state
& MOD_MASK
)
3054 wLowerFrame(wwin
->frame
->core
);
3056 wRaiseFrame(wwin
->frame
->core
);
3058 if ((event
->xbutton
.state
& ShiftMask
)
3059 && !(event
->xbutton
.state
& ControlMask
)) {
3060 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3063 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3064 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3065 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
3066 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3070 /* move the window */
3071 wMouseMoveWindow(wwin
, event
);
3073 XUngrabPointer(dpy
, CurrentTime
);
3074 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
3075 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
3076 WObjDescriptor
*desc
;
3078 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3079 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3080 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
3081 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3085 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
3087 /* allow drag select */
3088 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3089 event
->xany
.send_event
= True
;
3090 (*desc
->handle_mousedown
) (desc
, event
);
3092 XUngrabPointer(dpy
, CurrentTime
);
3096 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3098 WWindow
*wwin
= data
;
3100 /* Parameter not used, but tell the compiler that it is ok */
3103 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
3105 CloseWindowMenu(wwin
->screen_ptr
);
3107 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3110 /* if control-click, kill the client */
3111 if (event
->xbutton
.state
& ControlMask
) {
3114 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
3115 /* send delete message */
3116 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
3117 w_global
.timestamp
.last_event
);
3122 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3124 WWindow
*wwin
= data
;
3126 /* Parameter not used, but tell the compiler that it is ok */
3129 CloseWindowMenu(wwin
->screen_ptr
);
3131 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3134 /* send delete message */
3135 if (wwin
->protocols
.DELETE_WINDOW
)
3136 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
3137 w_global
.timestamp
.last_event
);
3142 #ifdef XKB_BUTTON_HINT
3143 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3145 WWindow
*wwin
= data
;
3146 WFrameWindow
*fwin
= wwin
->frame
;
3147 WScreen
*scr
= fwin
->screen_ptr
;
3150 /* Parameter not used, but tell the compiler that it is ok */
3153 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3155 tl
= wwin
->frame
->languagemode
;
3156 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3157 wwin
->frame
->last_languagemode
= tl
;
3158 wSetFocusTo(scr
, wwin
);
3159 wwin
->frame
->languagebutton_image
=
3160 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3161 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3162 if (event
->xbutton
.button
== Button3
)
3164 wRaiseFrame(fwin
->core
);
3168 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3170 WWindow
*wwin
= data
;
3172 /* Parameter not used, but tell the compiler that it is ok */
3175 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
3177 CloseWindowMenu(wwin
->screen_ptr
);
3179 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3182 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3183 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
3184 w_global
.timestamp
.last_event
);
3187 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3189 wapp
= wApplicationOf(wwin
->main_window
);
3190 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3191 wHideApplication(wapp
);
3192 } else if (event
->xbutton
.state
== 0) {
3193 wIconifyWindow(wwin
);