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
;
82 /***** Local Stuff *****/
83 static WWindowState
*windowState
= NULL
;
84 static FocusMode
getFocusMode(WWindow
*wwin
);
85 static int getSavedState(Window window
, WSavedState
**state
);
86 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
88 /* frame window (during window grabs) */
89 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
92 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
93 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
96 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
98 #ifdef XKB_BUTTON_HINT
99 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
103 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
104 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
106 static void release_wwindowstate(WWindowState
*wstate
);
108 /****** Notification Observers ******/
110 static void appearanceObserver(void *self
, WMNotification
* notif
)
112 WWindow
*wwin
= (WWindow
*) self
;
113 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
115 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
118 if (flags
& WFontSettings
) {
119 wWindowConfigureBorders(wwin
);
120 if (wwin
->flags
.shaded
) {
121 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
122 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
123 wWindowSynthConfigureNotify(wwin
);
126 if (flags
& WTextureSettings
)
127 wwin
->frame
->flags
.need_texture_remake
= 1;
129 if (flags
& (WTextureSettings
| WColorSettings
)) {
130 if (wwin
->frame
->titlebar
)
131 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
133 wFrameWindowPaint(wwin
->frame
);
138 /* Return the WWindow associated with a given (Xlib) Window. */
139 WWindow
*wWindowFor(Window window
)
141 WObjDescriptor
*desc
;
146 if (XFindContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
149 if (desc
->parent_type
== WCLASS_WINDOW
)
151 else if (desc
->parent_type
== WCLASS_FRAME
) {
152 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
153 if (frame
->flags
.is_client_window_frame
)
160 WWindow
*wWindowCreate(void)
164 wwin
= wmalloc(sizeof(WWindow
));
167 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
168 wwin
->client_descriptor
.parent
= wwin
;
169 wwin
->client_descriptor
.self
= wwin
;
170 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
175 void wWindowDestroy(WWindow
*wwin
)
179 if (wwin
->screen_ptr
->cmap_window
== wwin
)
180 wwin
->screen_ptr
->cmap_window
= NULL
;
182 WMRemoveNotificationObserver(wwin
);
184 wwin
->flags
.destroyed
= 1;
186 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
187 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
190 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
192 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
193 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
194 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
198 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
199 wwin
->fake_group
->retainCount
--;
200 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
201 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
202 wwin
->fake_group
->leader
= None
;
203 wwin
->fake_group
->origLeader
= None
;
208 if (wwin
->normal_hints
)
209 XFree(wwin
->normal_hints
);
212 XFree(wwin
->wm_hints
);
214 if (wwin
->wm_instance
)
215 XFree(wwin
->wm_instance
);
218 XFree(wwin
->wm_class
);
220 if (wwin
->wm_gnustep_attr
)
221 wfree(wwin
->wm_gnustep_attr
);
223 if (wwin
->cmap_windows
)
224 XFree(wwin
->cmap_windows
);
226 XDeleteContext(dpy
, wwin
->client_win
, w_global
.context
.client_win
);
229 wFrameWindowDestroy(wwin
->frame
);
232 RemoveFromStackList(wwin
->icon
->core
);
233 wIconDestroy(wwin
->icon
);
234 if (wPreferences
.auto_arrange_icons
)
235 wArrangeIcons(wwin
->screen_ptr
, True
);
237 if (wwin
->net_icon_image
)
238 RReleaseImage(wwin
->net_icon_image
);
243 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
245 if (gs_hints
->flags
& GSWindowStyleAttr
) {
246 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
247 wwin
->client_flags
.no_border
= 1;
248 wwin
->client_flags
.no_titlebar
= 1;
249 wwin
->client_flags
.no_closable
= 1;
250 wwin
->client_flags
.no_miniaturizable
= 1;
251 wwin
->client_flags
.no_resizable
= 1;
252 wwin
->client_flags
.no_close_button
= 1;
253 wwin
->client_flags
.no_miniaturize_button
= 1;
254 wwin
->client_flags
.no_resizebar
= 1;
256 wwin
->client_flags
.no_close_button
=
257 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
259 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
261 wwin
->client_flags
.no_miniaturize_button
=
262 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
264 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
266 wwin
->client_flags
.no_resizebar
=
267 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
269 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
271 /* these attributes supposedly imply in the existence
273 if (gs_hints
->window_style
& (WMResizableWindowMask
|
274 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
275 wwin
->client_flags
.no_titlebar
= 0;
277 wwin
->client_flags
.no_titlebar
=
278 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
283 /* setup the defaults */
284 wwin
->client_flags
.no_border
= 0;
285 wwin
->client_flags
.no_titlebar
= 0;
286 wwin
->client_flags
.no_closable
= 0;
287 wwin
->client_flags
.no_miniaturizable
= 0;
288 wwin
->client_flags
.no_resizable
= 0;
289 wwin
->client_flags
.no_close_button
= 0;
290 wwin
->client_flags
.no_miniaturize_button
= 0;
291 wwin
->client_flags
.no_resizebar
= 0;
293 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
294 wwin
->client_flags
.no_appicon
= 1;
297 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
299 WScreen
*scr
= wwin
->screen_ptr
;
301 /* sets global default stuff */
302 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
304 * Decoration setting is done in this precedence (lower to higher)
305 * - use global default in the resource database
306 * - guess some settings
307 * - use GNUstep/external window attributes
308 * - set hints specified for the app in the resource DB
311 WSETUFLAG(wwin
, broken_close
, 0);
313 if (wwin
->protocols
.DELETE_WINDOW
)
314 WSETUFLAG(wwin
, kill_close
, 0);
316 WSETUFLAG(wwin
, kill_close
, 1);
318 /* transients can't be iconified or maximized */
319 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
320 WSETUFLAG(wwin
, no_miniaturizable
, 1);
321 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
324 /* if the window can't be resized, remove the resizebar */
325 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
326 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
327 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
328 WSETUFLAG(wwin
, no_resizable
, 1);
329 WSETUFLAG(wwin
, no_resizebar
, 1);
332 /* set GNUstep window attributes */
333 if (wwin
->wm_gnustep_attr
) {
334 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
336 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
338 *level
= wwin
->wm_gnustep_attr
->window_level
;
340 * INT_MIN is the only illegal window level.
342 if (*level
== INT_MIN
)
343 *level
= INT_MIN
+ 1;
346 *level
= WMNormalLevel
;
349 int tmp_workspace
= -1;
350 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
353 wMWMCheckClientHints(wwin
);
354 #endif /* MWM_HINTS */
356 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
358 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
359 * have INT_MIN that means that no window level was requested. -Dan
361 if (tmp_level
== INT_MIN
) {
362 if (WFLAGP(wwin
, floating
))
363 *level
= WMFloatingLevel
;
364 else if (WFLAGP(wwin
, sunken
))
365 *level
= WMSunkenLevel
;
367 *level
= WMNormalLevel
;
372 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
373 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
374 if (transientOwner
) {
375 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
376 if (ownerLevel
> *level
)
381 if (tmp_workspace
>= 0)
382 *workspace
= tmp_workspace
% w_global
.workspace
.count
;
386 * Set attributes specified only for that window/class.
387 * This might do duplicate work with the 1st wDefaultFillAttributes().
389 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
390 &wwin
->defined_user_flags
, False
);
392 * Sanity checks for attributes that depend on other attributes
394 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
395 wwin
->user_flags
.emulate_appicon
= 0;
397 if (wwin
->main_window
!= None
) {
398 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
399 if (wapp
&& !wapp
->flags
.emulated
)
400 wwin
->user_flags
.emulate_appicon
= 0;
403 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
404 wwin
->user_flags
.emulate_appicon
= 0;
406 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
407 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
408 wwin
->user_flags
.sunken
= 0;
410 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
412 /* windows that have takefocus=False shouldn't take focus at all */
413 if (wwin
->focus_mode
== WFM_NO_INPUT
)
414 wwin
->client_flags
.no_focusable
= 1;
417 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
421 w1
= wwin
->frame
->core
->width
;
422 h1
= wwin
->frame
->core
->height
;
423 w2
= obscured
->frame
->core
->width
;
424 h2
= obscured
->frame
->core
->height
;
426 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
427 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
430 if (wwin
->frame_x
+ w1
< obscured
->frame_x
431 || wwin
->frame_y
+ h1
< obscured
->frame_y
432 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
438 static void fixLeaderProperties(WWindow
*wwin
)
440 XClassHint
*classHint
;
441 XWMHints
*hints
, *clientHints
;
442 XWindowAttributes attr
;
443 Window leaders
[2], window
;
444 char **argv
, *command
;
448 classHint
= XAllocClassHint();
449 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
450 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
452 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
456 leaders
[0] = wwin
->client_leader
;
457 leaders
[1] = wwin
->group_id
;
460 command
= GetCommandForWindow(wwin
->client_win
);
462 wfree(command
); /* command already set. nothing to do. */
464 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
467 for (i
= 0; i
< 2; i
++) {
470 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
471 classHint
->res_name
= wwin
->wm_instance
;
472 classHint
->res_class
= wwin
->wm_class
;
473 XSetClassHint(dpy
, window
, classHint
);
475 hints
= XGetWMHints(dpy
, window
);
478 } else if (clientHints
) {
479 /* set window group leader to self */
480 clientHints
->window_group
= window
;
481 clientHints
->flags
|= WindowGroupHint
;
482 XSetWMHints(dpy
, window
, clientHints
);
486 command
= GetCommandForWindow(window
);
488 wfree(command
); /* command already set. nothing to do. */
490 XSetCommand(dpy
, window
, argv
, argc
);
493 /* Make sure we get notification when this window is destroyed */
494 if (XGetWindowAttributes(dpy
, window
, &attr
))
495 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
506 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
508 XClassHint
*classHint
;
514 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
516 classHint
= XAllocClassHint();
517 classHint
->res_name
= instance
;
518 classHint
->res_class
= class;
519 XSetClassHint(dpy
, leader
, classHint
);
522 /* inherit these from the original leader if available */
523 hints
= XGetWMHints(dpy
, win
);
525 hints
= XAllocWMHints();
528 /* set window group leader to self */
529 hints
->window_group
= leader
;
530 hints
->flags
|= WindowGroupHint
;
531 XSetWMHints(dpy
, leader
, hints
);
534 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
535 XSetCommand(dpy
, leader
, argv
, argc
);
536 XFreeStringList(argv
);
542 static int matchIdentifier(const void *item
, const void *cdata
)
544 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
548 *----------------------------------------------------------------
550 * reparents the window and allocates a descriptor for it.
551 * Window manager hints and other hints are fetched to configure
552 * the window decoration attributes and others. User preferences
553 * for the window are used if available, to configure window
554 * decorations and some behaviour.
555 * If in startup, windows that are override redirect,
556 * unmapped and never were managed and are Withdrawn are not
560 * the new window descriptor
563 * The window is reparented and appropriate notification
564 * is done to the client. Input mask for the window is setup.
565 * The window descriptor is also associated with various window
566 * contexts and inserted in the head of the window list.
567 * Event handler contexts are associated for some objects
568 * (buttons, titlebar and resizebar)
570 *----------------------------------------------------------------
572 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
576 unsigned width
, height
;
577 XWindowAttributes wattribs
;
578 XSetWindowAttributes attribs
;
579 WWindowState
*win_state
;
580 WWindow
*transientOwner
= NULL
;
586 Bool withdraw
= False
;
593 /* make sure the window is still there */
594 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
599 /* if it's an override-redirect, ignore it */
600 if (wattribs
.override_redirect
) {
605 wm_state
= PropGetWindowState(window
);
607 /* if it's startup and the window is unmapped, don't manage it */
608 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
613 wwin
= wWindowCreate();
615 title
= wNETWMGetWindowName(window
);
617 wwin
->flags
.net_has_title
= 1;
618 else if (!wFetchName(dpy
, window
, &title
))
621 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
624 if (wShapeSupported
) {
629 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
630 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
631 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
632 wwin
->flags
.shaped
= b_shaped
;
636 /* Get hints and other information in properties */
637 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
639 /* setup descriptor */
640 wwin
->client_win
= window
;
641 wwin
->screen_ptr
= scr
;
642 wwin
->old_border_width
= wattribs
.border_width
;
643 wwin
->event_mask
= CLIENT_EVENTS
;
644 attribs
.event_mask
= CLIENT_EVENTS
;
645 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
646 attribs
.save_under
= False
;
648 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
649 XSetWindowBorderWidth(dpy
, window
, 0);
651 /* get hints from GNUstep app */
652 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
653 wwin
->flags
.is_gnustep
= 1;
655 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
656 wwin
->wm_gnustep_attr
= NULL
;
658 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
659 wwin
->flags
.is_dockapp
= 1;
663 wwin
->client_leader
= PropGetClientLeader(window
);
664 if (wwin
->client_leader
!= None
)
665 wwin
->main_window
= wwin
->client_leader
;
667 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
669 if (wwin
->wm_hints
) {
670 if (wwin
->wm_hints
->flags
& StateHint
) {
671 if (wwin
->wm_hints
->initial_state
== IconicState
) {
672 wwin
->flags
.miniaturized
= 1;
673 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
674 wwin
->flags
.is_dockapp
= 1;
679 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
680 wwin
->group_id
= wwin
->wm_hints
->window_group
;
681 /* window_group has priority over CLIENT_LEADER */
682 wwin
->main_window
= wwin
->group_id
;
684 wwin
->group_id
= None
;
687 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
688 wwin
->flags
.urgent
= 1;
689 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
692 wwin
->group_id
= None
;
695 PropGetProtocols(window
, &wwin
->protocols
);
697 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
698 wwin
->transient_for
= None
;
700 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
701 wwin
->transient_for
= scr
->root_win
;
703 transientOwner
= wWindowFor(wwin
->transient_for
);
704 if (transientOwner
&& transientOwner
->main_window
!= None
)
705 wwin
->main_window
= transientOwner
->main_window
;
709 /* guess the focus mode */
710 wwin
->focus_mode
= getFocusMode(wwin
);
712 /* get geometry stuff */
713 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
715 /* get colormap windows */
716 GetColormapWindows(wwin
);
719 * Setup the decoration/window attributes and
722 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
724 /* Make broken apps behave as a nice app. */
725 if (WFLAGP(wwin
, emulate_appicon
))
726 wwin
->main_window
= wwin
->client_win
;
728 fixLeaderProperties(wwin
);
730 wwin
->orig_main_window
= wwin
->main_window
;
732 if (wwin
->flags
.is_gnustep
)
733 WSETUFLAG(wwin
, shared_appicon
, 0);
735 if (wwin
->main_window
) {
736 XTextProperty text_prop
;
738 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, w_global
.atom
.wmaker
.menu
))
739 WSETUFLAG(wwin
, shared_appicon
, 0);
742 if (wwin
->flags
.is_dockapp
)
743 WSETUFLAG(wwin
, shared_appicon
, 0);
745 if (wwin
->main_window
) {
746 WApplication
*app
= wApplicationOf(wwin
->main_window
);
747 if (app
&& app
->app_icon
)
748 WSETUFLAG(wwin
, shared_appicon
, 0);
751 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
752 char *buffer
, *instance
, *class;
753 WFakeGroupLeader
*fPtr
;
756 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
758 /* // only enter here if PropGetWMClass() succeds */
759 PropGetWMClass(wwin
->main_window
, &class, &instance
);
760 buffer
= StrConcatDot(instance
, class);
762 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
763 if (index
!= WANotFound
) {
764 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
765 if (fPtr
->retainCount
== 0)
766 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
770 if (fPtr
->origLeader
== None
) {
771 if (ADEQUATE(wwin
->main_window
)) {
773 fPtr
->origLeader
= wwin
->main_window
;
776 wwin
->fake_group
= fPtr
;
777 wwin
->main_window
= fPtr
->leader
;
780 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
782 fPtr
->identifier
= buffer
;
783 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
784 fPtr
->origLeader
= None
;
785 fPtr
->retainCount
= 1;
787 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
789 if (ADEQUATE(wwin
->main_window
)) {
791 fPtr
->origLeader
= wwin
->main_window
;
793 wwin
->fake_group
= fPtr
;
794 wwin
->main_window
= fPtr
->leader
;
806 * Setup the initial state of the window
808 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
809 wwin
->flags
.miniaturized
= 1;
811 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
812 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
814 wNETWMCheckInitialClientState(wwin
);
816 /* apply previous state if it exists and we're in startup */
817 if (scr
->flags
.startup
&& wm_state
>= 0) {
818 if (wm_state
== IconicState
)
819 wwin
->flags
.miniaturized
= 1;
820 else if (wm_state
== WithdrawnState
)
824 /* if there is a saved state (from file), restore it */
826 if (wwin
->main_window
!= None
)
827 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
829 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
831 if (win_state
&& !withdraw
) {
832 if (win_state
->state
->hidden
> 0)
833 wwin
->flags
.hidden
= win_state
->state
->hidden
;
835 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
836 wwin
->flags
.shaded
= win_state
->state
->shaded
;
838 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
839 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
841 if (!IS_OMNIPRESENT(wwin
)) {
842 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
844 if (w
< 0 || w
>= w_global
.workspace
.count
) {
845 workspace
= win_state
->state
->workspace
;
846 if (workspace
>= w_global
.workspace
.count
)
847 workspace
= scr
->current_workspace
;
852 workspace
= scr
->current_workspace
;
856 /* if we're restarting, restore saved state (from hints).
857 * This will overwrite previous */
861 if (getSavedState(window
, &wstate
)) {
862 wwin
->flags
.shaded
= wstate
->shaded
;
863 wwin
->flags
.hidden
= wstate
->hidden
;
864 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
865 wwin
->flags
.maximized
= wstate
->maximized
;
866 if (wwin
->flags
.maximized
) {
867 wwin
->old_geometry
.x
= wstate
->x
;
868 wwin
->old_geometry
.y
= wstate
->y
;
869 wwin
->old_geometry
.width
= wstate
->w
;
870 wwin
->old_geometry
.height
= wstate
->h
;
873 workspace
= wstate
->workspace
;
878 /* restore window shortcut */
879 if (wstate
!= NULL
|| win_state
!= NULL
) {
882 if (win_state
!= NULL
)
883 mask
= win_state
->state
->window_shortcuts
;
885 if (wstate
!= NULL
&& mask
== 0)
886 mask
= wstate
->window_shortcuts
;
891 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
892 if (mask
& (1 << i
)) {
893 if (!scr
->shortcutWindows
[i
])
894 scr
->shortcutWindows
[i
] = WMCreateArray(4);
896 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
906 /* don't let transients start miniaturized if their owners are not */
907 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
908 wwin
->flags
.miniaturized
= 0;
910 wwin
->wm_hints
->initial_state
= NormalState
;
913 /* set workspace on which the window starts */
914 if (workspace
>= 0) {
915 if (workspace
> w_global
.workspace
.count
- 1)
916 workspace
= workspace
% w_global
.workspace
.count
;
920 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
922 if (w
>= 0 && w
< w_global
.workspace
.count
&& !(IS_OMNIPRESENT(wwin
))) {
925 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
926 workspace
= transientOwner
->frame
->workspace
;
928 workspace
= scr
->current_workspace
;
932 /* setup window geometry */
933 if (win_state
&& win_state
->state
->w
> 0) {
934 width
= win_state
->state
->w
;
935 height
= win_state
->state
->h
;
938 wWindowConstrainSize(wwin
, &width
, &height
);
940 /* do not ask for window placement if the window is
941 * transient, during startup, if the initial workspace is another one
942 * or if the window wants to start iconic.
943 * If geometry was saved, restore it. */
945 Bool dontBring
= False
;
947 if (win_state
&& win_state
->state
->w
> 0) {
948 x
= win_state
->state
->x
;
949 y
= win_state
->state
->y
;
950 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
951 && !scr
->flags
.startup
952 && workspace
== scr
->current_workspace
953 && !wwin
->flags
.miniaturized
954 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
956 if (transientOwner
&& transientOwner
->flags
.mapped
) {
957 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
961 x
= transientOwner
->frame_x
+
962 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
963 y
= transientOwner
->frame_y
+
964 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
966 /* limit transient windows to be inside their parent's head */
967 rect
.pos
.x
= transientOwner
->frame_x
;
968 rect
.pos
.y
= transientOwner
->frame_y
;
969 rect
.size
.width
= transientOwner
->frame
->core
->width
;
970 rect
.size
.height
= transientOwner
->frame
->core
->height
;
972 head
= wGetHeadForRect(scr
, rect
);
973 rect
= wGetRectForHead(scr
, head
);
977 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
978 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
982 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
983 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
986 PlaceWindow(wwin
, &x
, &y
, width
, height
);
989 if (wPreferences
.window_placement
== WPM_MANUAL
)
992 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
997 /* Make spash screens come out in the center of a head
998 * trouble is that most splashies never get here
999 * they are managed trough atoms but god knows where.
1000 * Dan, do you know ? -peter
1002 * Most of them are not managed, they have set
1003 * OverrideRedirect, which means we can't do anything about
1006 /* xinerama checks for: across head and dead space */
1009 rect
.size
.width
= width
;
1010 rect
.size
.height
= height
;
1012 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1014 if (flags
& XFLAG_DEAD
)
1017 if (flags
& XFLAG_MULTIPLE
)
1021 switch (reposition
) {
1023 head
= wGetHeadForPointerLocation(scr
);
1024 rect
= wGetRectForHead(scr
, head
);
1026 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1027 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1031 rect
= wGetRectForHead(scr
, head
);
1035 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1036 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1040 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1041 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1050 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1051 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1054 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1056 if (wwin
->flags
.urgent
) {
1057 if (!IS_OMNIPRESENT(wwin
))
1058 wwin
->flags
.omnipresent
^= 1;
1061 /* Create frame, borders and do reparenting */
1062 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1063 #ifdef XKB_BUTTON_HINT
1064 if (wPreferences
.modelock
)
1065 foo
|= WFF_LANGUAGE_BUTTON
;
1067 if (HAS_TITLEBAR(wwin
))
1068 foo
|= WFF_TITLEBAR
;
1070 if (HAS_RESIZEBAR(wwin
))
1071 foo
|= WFF_RESIZEBAR
;
1073 if (HAS_BORDER(wwin
))
1076 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1077 x
, y
, width
, height
,
1078 &wPreferences
.window_title_clearance
,
1079 &wPreferences
.window_title_min_height
,
1080 &wPreferences
.window_title_max_height
,
1082 scr
->window_title_texture
,
1083 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1084 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1086 wwin
->frame
->flags
.is_client_window_frame
= 1;
1087 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1089 /* setup button images */
1090 wWindowUpdateButtonImages(wwin
);
1092 /* hide unused buttons */
1094 if (WFLAGP(wwin
, no_close_button
))
1095 foo
|= WFF_RIGHT_BUTTON
;
1097 if (WFLAGP(wwin
, no_miniaturize_button
))
1098 foo
|= WFF_LEFT_BUTTON
;
1100 #ifdef XKB_BUTTON_HINT
1101 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1102 foo
|= WFF_LANGUAGE_BUTTON
;
1105 wFrameWindowHideButton(wwin
->frame
, foo
);
1107 wwin
->frame
->child
= wwin
;
1108 wwin
->frame
->workspace
= workspace
;
1109 wwin
->frame
->on_click_left
= windowIconifyClick
;
1111 #ifdef XKB_BUTTON_HINT
1112 if (wPreferences
.modelock
)
1113 wwin
->frame
->on_click_language
= windowLanguageClick
;
1116 wwin
->frame
->on_click_right
= windowCloseClick
;
1117 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1118 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1119 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1120 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1122 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1123 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1124 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1129 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1131 /* if gravity is to the south, account for the border sizes */
1133 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1137 * wWindowConfigure() will init the client window's size
1138 * (wwin->client.{width,height}) and all other geometry
1139 * related variables (frame_x,frame_y) */
1140 wWindowConfigure(wwin
, x
, y
, width
, height
);
1142 /* to make sure the window receives it's new position after reparenting */
1143 wWindowSynthConfigureNotify(wwin
);
1145 /* Setup descriptors and save window to internal lists */
1146 if (wwin
->main_window
!= None
) {
1150 /* Leader windows do not necessary set themselves as leaders.
1151 * If this is the case, point the leader of this window to
1153 leader
= wWindowFor(wwin
->main_window
);
1154 if (leader
&& leader
->main_window
== None
)
1155 leader
->main_window
= leader
->client_win
;
1157 app
= wApplicationCreate(wwin
);
1159 app
->last_workspace
= workspace
;
1161 /* Do application specific stuff, like setting application
1162 * wide attributes. */
1164 if (wwin
->flags
.hidden
) {
1165 /* if the window was set to hidden because it was hidden
1166 * in a previous incarnation and that state was restored */
1167 app
->flags
.hidden
= 1;
1168 } else if (app
->flags
.hidden
) {
1169 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1170 wwin
->flags
.hidden
= 1;
1172 wUnhideApplication(app
, False
, False
);
1180 /* setup the frame descriptor */
1181 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1182 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1183 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1185 /* don't let windows go away if we die */
1186 XAddToSaveSet(dpy
, window
);
1188 XLowerWindow(dpy
, window
);
1190 /* if window is in this workspace and should be mapped, then map it */
1191 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1192 && !wwin
->flags
.hidden
&& !withdraw
) {
1194 /* The following "if" is to avoid crashing of clients that expect
1195 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1196 * after the return from this function. */
1197 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1198 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1200 wClientSetState(wwin
, NormalState
, None
);
1202 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1203 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1205 * The brain damaged idiotic non-click to focus modes will
1206 * have trouble with this because:
1208 * 1. window is created and mapped by the client
1209 * 2. window is mapped by wmaker in small size
1210 * 3. window is animated to grow to normal size
1211 * 4. this function returns to normal event loop
1212 * 5. eventually, the EnterNotify event that would trigger
1213 * the window focusing (if the mouse is over that window)
1214 * will be processed by wmaker.
1215 * But since this event will be rather delayed
1216 * (step 3 has a large delay) the time when the event ocurred
1217 * and when it is processed, the client that owns that window
1218 * will reject the XSetInputFocus() for it.
1220 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1221 DoWindowBirth(wwin
);
1226 /* setup stacking descriptor */
1228 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1230 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1232 if (!scr
->focused_window
) {
1233 /* first window on the list */
1236 scr
->focused_window
= wwin
;
1240 /* add window at beginning of focus window list */
1241 tmp
= scr
->focused_window
;
1250 /* raise is set to true if we un-hid the app when this window was born.
1251 * we raise, else old windows of this app will be above this new one. */
1253 wRaiseFrame(wwin
->frame
->core
);
1255 /* Update name must come after WApplication stuff is done */
1256 wWindowUpdateName(wwin
, title
);
1262 /* Final preparations before window is ready to go */
1263 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1265 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1266 if (((transientOwner
&& transientOwner
->flags
.focused
)
1267 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1269 /* only auto_focus if on same screen as mouse
1270 * (and same head for xinerama mode)
1271 * TODO: make it an option */
1273 /*TODO add checking the head of the window, is it available? */
1274 short same_screen
= 0, same_head
= 1;
1280 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1281 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1284 if (same_screen
== 1 && same_head
== 1)
1285 wSetFocusTo(scr
, wwin
);
1288 wWindowResetMouseGrabs(wwin
);
1290 if (!WFLAGP(wwin
, no_bind_keys
))
1291 wWindowSetKeyGrabs(wwin
);
1293 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1294 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1296 /* Setup Notification Observers */
1297 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1299 /* Cleanup temporary stuff */
1301 wWindowDeleteSavedState(win_state
);
1303 /* If the window must be withdrawed, then do it now.
1304 * Must do some optimization, 'though */
1306 wwin
->flags
.mapped
= 0;
1307 wClientSetState(wwin
, WithdrawnState
, None
);
1308 wUnmanageWindow(wwin
, True
, False
);
1315 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1316 const char *title
, int x
, int y
, int width
, int height
)
1321 wwin
= wWindowCreate();
1323 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1325 wwin
->flags
.internal_window
= 1;
1327 WSETUFLAG(wwin
, omnipresent
, 1);
1328 WSETUFLAG(wwin
, no_shadeable
, 1);
1329 WSETUFLAG(wwin
, no_resizable
, 1);
1330 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1332 wwin
->focus_mode
= WFM_PASSIVE
;
1333 wwin
->client_win
= window
;
1334 wwin
->screen_ptr
= scr
;
1335 wwin
->transient_for
= owner
;
1338 wwin
->client
.width
= width
;
1339 wwin
->client
.height
= height
;
1340 wwin
->frame_x
= wwin
->client
.x
;
1341 wwin
->frame_y
= wwin
->client
.y
;
1343 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1344 foo
|= WFF_TITLEBAR
;
1345 #ifdef XKB_BUTTON_HINT
1346 foo
|= WFF_LANGUAGE_BUTTON
;
1349 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1350 wwin
->frame_x
, wwin
->frame_y
,
1352 &wPreferences
.window_title_clearance
,
1353 &wPreferences
.window_title_min_height
,
1354 &wPreferences
.window_title_max_height
,
1356 scr
->window_title_texture
,
1357 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1358 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1360 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
1362 wwin
->frame
->flags
.is_client_window_frame
= 1;
1363 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1365 wFrameWindowChangeTitle(wwin
->frame
, title
);
1367 /* setup button images */
1368 wWindowUpdateButtonImages(wwin
);
1371 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1373 wwin
->frame
->child
= wwin
;
1374 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1376 #ifdef XKB_BUTTON_HINT
1377 if (wPreferences
.modelock
)
1378 wwin
->frame
->on_click_language
= windowLanguageClick
;
1381 wwin
->frame
->on_click_right
= windowCloseClick
;
1382 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1383 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1384 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1385 wwin
->client
.y
+= wwin
->frame
->top_width
;
1387 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1388 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1390 /* setup the frame descriptor */
1391 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1392 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1393 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1395 XLowerWindow(dpy
, window
);
1396 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1398 /* setup stacking descriptor */
1399 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1401 tmp
= wWindowFor(wwin
->transient_for
);
1403 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1405 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1408 if (!scr
->focused_window
) {
1409 /* first window on the list */
1412 scr
->focused_window
= wwin
;
1416 /* add window at beginning of focus window list */
1417 tmp
= scr
->focused_window
;
1425 if (wwin
->flags
.is_gnustep
== 0)
1426 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1428 /* if (wPreferences.auto_focus) */
1429 wSetFocusTo(scr
, wwin
);
1430 wWindowResetMouseGrabs(wwin
);
1431 wWindowSetKeyGrabs(wwin
);
1437 *----------------------------------------------------------------------
1439 * Removes the frame window from a window and destroys all data
1440 * related to it. The window will be reparented back to the root window
1441 * if restore is True.
1444 * Everything related to the window is destroyed and the window
1445 * is removed from the window lists. Focus is set to the previous on the
1447 *----------------------------------------------------------------------
1449 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1451 WCoreWindow
*frame
= wwin
->frame
->core
;
1452 WWindow
*owner
= NULL
;
1453 WWindow
*newFocusedWindow
= NULL
;
1455 WScreen
*scr
= wwin
->screen_ptr
;
1457 /* First close attribute editor window if open */
1458 if (wwin
->flags
.inspector_open
)
1459 wCloseInspectorForWindow(wwin
);
1461 /* Close window menu if it's open for this window */
1462 if (wwin
->flags
.menu_open_for_me
)
1463 CloseWindowMenu(scr
);
1466 if (!wwin
->flags
.internal_window
)
1467 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1469 /* If this is a leader window, we still need to listen for
1470 * DestroyNotify and PropertyNotify. */
1471 if (wApplicationOf(wwin
->client_win
))
1472 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1474 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1476 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1477 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1480 XUnmapWindow(dpy
, frame
->window
);
1482 XUnmapWindow(dpy
, wwin
->client_win
);
1484 /* deselect window */
1485 wSelectWindow(wwin
, False
);
1487 /* remove all pending events on window */
1488 /* I think this only matters for autoraise */
1489 if (wPreferences
.raise_delay
)
1490 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1494 /* reparent the window back to the root */
1496 wClientRestore(wwin
);
1498 if (wwin
->transient_for
!= scr
->root_win
) {
1499 owner
= wWindowFor(wwin
->transient_for
);
1501 if (!owner
->flags
.semi_focused
)
1504 owner
->flags
.semi_focused
= 0;
1508 wasFocused
= wwin
->flags
.focused
;
1510 /* remove from window focus list */
1511 if (!wwin
->prev
&& !wwin
->next
) {
1512 /* was the only window */
1513 scr
->focused_window
= NULL
;
1514 newFocusedWindow
= NULL
;
1519 wwin
->prev
->next
= wwin
->next
;
1522 wwin
->next
->prev
= wwin
->prev
;
1524 scr
->focused_window
= wwin
->prev
;
1525 scr
->focused_window
->next
= NULL
;
1528 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1530 /* if in click to focus mode and the window
1531 * was a transient, focus the owner window
1534 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1535 tmp
= wWindowFor(wwin
->transient_for
);
1536 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1540 /* otherwise, focus the next one in the focus list */
1542 tmp
= scr
->focused_window
;
1543 while (tmp
) { /* look for one in the window list first */
1544 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1545 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1549 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1550 tmp
= scr
->focused_window
;
1552 if (!WFLAGP(tmp
, no_focusable
)
1553 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1560 newFocusedWindow
= tmp
;
1562 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1567 /* This is to let the root window get the keyboard input
1568 * if Sloppy focus mode and no other window get focus.
1569 * This way keybindings will not freeze.
1572 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1573 tmp
= wWindowFor(win
);
1576 newFocusedWindow
= tmp
;
1578 newFocusedWindow
= NULL
;
1582 if (!wwin
->flags
.internal_window
)
1583 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1585 if (newFocusedWindow
!= owner
&& owner
) {
1586 if (wwin
->flags
.is_gnustep
== 0)
1587 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1589 wSetFocusTo(scr
, newFocusedWindow
);
1592 /* Close menu and unhighlight */
1593 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1594 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1595 if (oapp
&& oapp
!= napp
) {
1596 wAppMenuUnmap(oapp
->menu
);
1597 if (wPreferences
.highlight_active_app
)
1598 wApplicationDeactivate(oapp
);
1601 wNETCleanupFrameExtents(wwin
);
1603 wWindowDestroy(wwin
);
1607 void wWindowMap(WWindow
*wwin
)
1609 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1610 if (!wwin
->flags
.shaded
) {
1611 /* window will be remapped when getting MapNotify */
1612 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1613 XMapWindow(dpy
, wwin
->client_win
);
1614 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1616 wwin
->flags
.mapped
= 1;
1620 void wWindowUnmap(WWindow
*wwin
)
1622 wwin
->flags
.mapped
= 0;
1624 /* prevent window withdrawal when getting UnmapNotify */
1625 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1626 XUnmapWindow(dpy
, wwin
->client_win
);
1627 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1629 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1632 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1637 #ifdef KEEP_XKB_LOCK_STATUS
1638 if (wPreferences
.modelock
)
1639 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1640 #endif /* KEEP_XKB_LOCK_STATUS */
1642 wwin
->flags
.semi_focused
= 0;
1644 if (wwin
->flags
.is_gnustep
== 0)
1645 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1647 wwin
->flags
.focused
= 1;
1649 wWindowResetMouseGrabs(wwin
);
1651 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1653 if (owin
== wwin
|| !owin
)
1656 nowner
= wWindowFor(wwin
->transient_for
);
1658 /* new window is a transient for the old window */
1659 if (nowner
== owin
) {
1660 owin
->flags
.semi_focused
= 1;
1661 wWindowUnfocus(nowner
);
1665 oowner
= wWindowFor(owin
->transient_for
);
1667 /* new window is owner of old window */
1668 if (wwin
== oowner
) {
1669 wWindowUnfocus(owin
);
1674 wWindowUnfocus(owin
);
1678 /* new window has same owner of old window */
1679 if (oowner
== nowner
) {
1680 /* prevent unfocusing of owner */
1681 oowner
->flags
.semi_focused
= 0;
1682 wWindowUnfocus(owin
);
1683 oowner
->flags
.semi_focused
= 1;
1688 /* nowner != NULL && oowner != nowner */
1689 nowner
->flags
.semi_focused
= 1;
1690 wWindowUnfocus(nowner
);
1691 wWindowUnfocus(owin
);
1694 void wWindowUnfocus(WWindow
*wwin
)
1696 CloseWindowMenu(wwin
->screen_ptr
);
1698 if (wwin
->flags
.is_gnustep
== 0)
1699 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1701 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1703 owner
= wWindowFor(wwin
->transient_for
);
1704 if (owner
&& owner
->flags
.semi_focused
) {
1705 owner
->flags
.semi_focused
= 0;
1706 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1707 wWindowUnfocus(owner
);
1708 wFrameWindowPaint(owner
->frame
);
1712 wwin
->flags
.focused
= 0;
1713 wWindowResetMouseGrabs(wwin
);
1714 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1717 void wWindowUpdateName(WWindow
*wwin
, const char *newTitle
)
1725 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1729 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1730 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1734 *----------------------------------------------------------------------
1736 * wWindowConstrainSize--
1737 * Constrains size for the client window, taking the maximal size,
1738 * window resize increments and other size hints into account.
1741 * The closest size to what was given that the client window can
1744 *----------------------------------------------------------------------
1746 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1748 int width
= (int)*nwidth
;
1749 int height
= (int)*nheight
;
1752 int minW
= 1, minH
= 1;
1753 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1754 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1755 int minAX
= -1, minAY
= -1;
1756 int maxAX
= -1, maxAY
= -1;
1760 if (wwin
->normal_hints
) {
1761 winc
= wwin
->normal_hints
->width_inc
;
1762 hinc
= wwin
->normal_hints
->height_inc
;
1763 minW
= wwin
->normal_hints
->min_width
;
1764 minH
= wwin
->normal_hints
->min_height
;
1765 maxW
= wwin
->normal_hints
->max_width
;
1766 maxH
= wwin
->normal_hints
->max_height
;
1767 if (wwin
->normal_hints
->flags
& PAspect
) {
1768 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1769 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1770 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1771 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1774 baseW
= wwin
->normal_hints
->base_width
;
1775 baseH
= wwin
->normal_hints
->base_height
;
1788 /* aspect ratio code borrowed from olwm */
1790 /* adjust max aspect ratio */
1791 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1792 if (maxAX
> maxAY
) {
1793 height
= (width
* maxAY
) / maxAX
;
1794 if (height
> maxH
) {
1796 width
= (height
* maxAX
) / maxAY
;
1799 width
= (height
* maxAX
) / maxAY
;
1802 height
= (width
* maxAY
) / maxAX
;
1807 /* adjust min aspect ratio */
1808 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1809 if (minAX
> minAY
) {
1810 height
= (width
* minAY
) / minAX
;
1811 if (height
< minH
) {
1813 width
= (height
* minAX
) / minAY
;
1816 width
= (height
* minAX
) / minAY
;
1819 height
= (width
* minAY
) / minAX
;
1826 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1828 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1831 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1833 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1835 /* broken stupid apps may cause preposterous values for these.. */
1842 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1843 unsigned int *width
, unsigned int *height
)
1845 int baseW
= 0, baseH
= 0;
1846 int winc
= 1, hinc
= 1;
1848 if (wwin
->normal_hints
) {
1849 baseW
= wwin
->normal_hints
->base_width
;
1850 baseH
= wwin
->normal_hints
->base_height
;
1852 winc
= wwin
->normal_hints
->width_inc
;
1853 hinc
= wwin
->normal_hints
->height_inc
;
1857 *width
= maxW
- (maxW
- baseW
) % winc
;
1860 *height
= maxH
- (maxH
- baseH
) % hinc
;
1863 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1865 WScreen
*scr
= wwin
->screen_ptr
;
1869 if (workspace
>= w_global
.workspace
.count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1872 if (workspace
!= scr
->current_workspace
) {
1873 /* Sent to other workspace. Unmap window */
1874 if ((wwin
->flags
.mapped
1875 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1876 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1878 wapp
= wApplicationOf(wwin
->main_window
);
1880 wapp
->last_workspace
= workspace
;
1882 if (wwin
->flags
.miniaturized
) {
1884 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1885 wwin
->icon
->mapped
= 0;
1889 wSetFocusTo(scr
, NULL
);
1893 /* brought to current workspace. Map window */
1894 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1896 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1897 wwin
->icon
->mapped
= 1;
1899 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1903 if (!IS_OMNIPRESENT(wwin
)) {
1904 int oldWorkspace
= wwin
->frame
->workspace
;
1905 wwin
->frame
->workspace
= workspace
;
1906 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1913 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
1915 WScreen
*scr
= wwin
->screen_ptr
;
1916 int w
= scr
->current_workspace
+ amount
;
1920 wWindowChangeWorkspace(wwin
, w
);
1921 } else if (wPreferences
.ws_cycle
) {
1922 wWindowChangeWorkspace(wwin
, w_global
.workspace
.count
+ w
);
1924 } else if (amount
> 0) {
1925 if (w
< w_global
.workspace
.count
) {
1926 wWindowChangeWorkspace(wwin
, w
);
1927 } else if (wPreferences
.ws_advance
) {
1928 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
1929 wWorkspaceMake(scr
, workspace
);
1930 wWindowChangeWorkspace(wwin
, workspace
);
1931 } else if (wPreferences
.ws_cycle
) {
1932 wWindowChangeWorkspace(wwin
, w
% w_global
.workspace
.count
);
1937 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1941 sevent
.type
= ConfigureNotify
;
1942 sevent
.xconfigure
.display
= dpy
;
1943 sevent
.xconfigure
.event
= wwin
->client_win
;
1944 sevent
.xconfigure
.window
= wwin
->client_win
;
1946 sevent
.xconfigure
.x
= wwin
->client
.x
;
1947 sevent
.xconfigure
.y
= wwin
->client
.y
;
1948 sevent
.xconfigure
.width
= wwin
->client
.width
;
1949 sevent
.xconfigure
.height
= wwin
->client
.height
;
1951 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1952 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1953 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1955 sevent
.xconfigure
.above
= None
;
1957 sevent
.xconfigure
.override_redirect
= False
;
1958 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1963 *----------------------------------------------------------------------
1964 * wWindowConfigure()
1966 * req_x, req_y: new requested positions for the frame
1967 * req_width, req_height: new requested sizes for the client
1969 * Configures the frame, decorations and client window to the specified
1970 * geometry, whose validity is not checked -- wWindowConstrainSize()
1971 * must be used for that.
1972 * The size parameters are for the client window, but the position is
1974 * The client window receives a ConfigureNotify event, according
1975 * to what ICCCM says.
1981 * Window size and position are changed and client window receives
1982 * a ConfigureNotify event.
1983 *----------------------------------------------------------------------
1985 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1987 int synth_notify
= False
;
1990 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1992 * if the window is being moved but not resized then
1993 * send a synthetic ConfigureNotify
1995 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
1996 synth_notify
= True
;
1998 if (WFLAGP(wwin
, dont_move_off
))
1999 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2002 if (req_width
< MIN_WINDOW_SIZE
)
2003 req_width
= MIN_WINDOW_SIZE
;
2004 if (req_height
< MIN_WINDOW_SIZE
)
2005 req_height
= MIN_WINDOW_SIZE
;
2007 /* If growing, resize inner part before frame,
2008 * if shrinking, resize frame before.
2009 * This will prevent the frame (that can have a different color)
2010 * to be exposed, causing flicker */
2011 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2012 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2014 if (wwin
->flags
.shaded
) {
2015 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2016 wwin
->old_geometry
.height
= req_height
;
2020 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2022 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2025 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2026 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2028 wwin
->client
.x
= req_x
;
2029 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2030 wwin
->client
.width
= req_width
;
2031 wwin
->client
.height
= req_height
;
2033 wwin
->client
.x
= req_x
;
2034 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2036 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2038 wwin
->frame_x
= req_x
;
2039 wwin
->frame_y
= req_y
;
2040 if (HAS_BORDER(wwin
)) {
2041 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2042 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2045 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2046 wWindowSetShape(wwin
);
2050 wWindowSynthConfigureNotify(wwin
);
2052 wNETFrameExtents(wwin
);
2057 /* req_x, req_y: new position of the frame */
2058 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2060 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2061 int synth_notify
= False
;
2063 /* Send a synthetic ConfigureNotify event for every window movement. */
2064 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2065 synth_notify
= True
;
2067 /* A single synthetic ConfigureNotify event is sent at the end of
2068 * a completed (opaque) movement in moveres.c */
2071 if (WFLAGP(wwin
, dont_move_off
))
2072 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2073 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2075 wwin
->client
.x
= req_x
;
2076 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2077 if (HAS_BORDER(wwin
)) {
2078 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2079 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2082 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2084 wwin
->frame_x
= req_x
;
2085 wwin
->frame_y
= req_y
;
2087 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2089 wWindowSynthConfigureNotify(wwin
);
2093 void wWindowUpdateButtonImages(WWindow
*wwin
)
2095 WScreen
*scr
= wwin
->screen_ptr
;
2096 Pixmap pixmap
, mask
;
2097 WFrameWindow
*fwin
= wwin
->frame
;
2099 if (!HAS_TITLEBAR(wwin
))
2102 /* miniaturize button */
2103 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2104 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2105 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2107 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2108 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2112 if (fwin
->lbutton_image
2113 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2114 wPixmapDestroy(fwin
->lbutton_image
);
2115 fwin
->lbutton_image
= NULL
;
2118 if (!fwin
->lbutton_image
) {
2119 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2120 fwin
->lbutton_image
->client_owned
= 1;
2121 fwin
->lbutton_image
->client_owned_mask
= 1;
2124 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2125 wPixmapDestroy(fwin
->lbutton_image
);
2127 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2130 #ifdef XKB_BUTTON_HINT
2131 if (!WFLAGP(wwin
, no_language_button
)) {
2132 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2133 wPixmapDestroy(fwin
->languagebutton_image
);
2135 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2141 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2142 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2144 if (!WFLAGP(wwin
, no_close_button
)) {
2145 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2146 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2148 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2149 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2153 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2154 || fwin
->rbutton_image
->mask
!= mask
)) {
2155 wPixmapDestroy(fwin
->rbutton_image
);
2156 fwin
->rbutton_image
= NULL
;
2159 if (!fwin
->rbutton_image
) {
2160 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2161 fwin
->rbutton_image
->client_owned
= 1;
2162 fwin
->rbutton_image
->client_owned_mask
= 1;
2165 } else if (WFLAGP(wwin
, kill_close
)) {
2166 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2167 wPixmapDestroy(fwin
->rbutton_image
);
2169 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2171 } else if (MGFLAGP(wwin
, broken_close
)) {
2172 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2173 wPixmapDestroy(fwin
->rbutton_image
);
2175 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2178 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2179 wPixmapDestroy(fwin
->rbutton_image
);
2181 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2185 /* force buttons to be redrawn */
2186 fwin
->flags
.need_texture_change
= 1;
2187 wFrameWindowPaint(fwin
);
2191 *---------------------------------------------------------------------------
2192 * wWindowConfigureBorders--
2193 * Update window border configuration according to attribute flags.
2195 *---------------------------------------------------------------------------
2197 void wWindowConfigureBorders(WWindow
*wwin
)
2203 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2205 #ifdef XKB_BUTTON_HINT
2206 if (wPreferences
.modelock
)
2207 flags
|= WFF_LANGUAGE_BUTTON
;
2210 if (HAS_TITLEBAR(wwin
))
2211 flags
|= WFF_TITLEBAR
;
2212 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2213 flags
|= WFF_RESIZEBAR
;
2214 if (HAS_BORDER(wwin
))
2215 flags
|= WFF_BORDER
;
2216 if (wwin
->flags
.shaded
)
2217 flags
|= WFF_IS_SHADED
;
2218 if (wwin
->flags
.selected
)
2219 flags
|= WFF_SELECTED
;
2221 oldh
= wwin
->frame
->top_width
;
2222 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2223 if (oldh
!= wwin
->frame
->top_width
) {
2224 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2226 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2227 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2231 if (!WFLAGP(wwin
, no_miniaturize_button
)
2232 && wwin
->frame
->flags
.hide_left_button
)
2233 flags
|= WFF_LEFT_BUTTON
;
2235 #ifdef XKB_BUTTON_HINT
2236 if (!WFLAGP(wwin
, no_language_button
)
2237 && wwin
->frame
->flags
.hide_language_button
)
2238 flags
|= WFF_LANGUAGE_BUTTON
;
2241 if (!WFLAGP(wwin
, no_close_button
)
2242 && wwin
->frame
->flags
.hide_right_button
)
2243 flags
|= WFF_RIGHT_BUTTON
;
2246 wWindowUpdateButtonImages(wwin
);
2247 wFrameWindowShowButton(wwin
->frame
, flags
);
2251 if (WFLAGP(wwin
, no_miniaturize_button
)
2252 && !wwin
->frame
->flags
.hide_left_button
)
2253 flags
|= WFF_LEFT_BUTTON
;
2255 #ifdef XKB_BUTTON_HINT
2256 if (WFLAGP(wwin
, no_language_button
)
2257 && !wwin
->frame
->flags
.hide_language_button
)
2258 flags
|= WFF_LANGUAGE_BUTTON
;
2261 if (WFLAGP(wwin
, no_close_button
)
2262 && !wwin
->frame
->flags
.hide_right_button
)
2263 flags
|= WFF_RIGHT_BUTTON
;
2266 wFrameWindowHideButton(wwin
->frame
, flags
);
2269 if (wShapeSupported
&& wwin
->flags
.shaped
)
2270 wWindowSetShape(wwin
);
2275 void wWindowSaveState(WWindow
* wwin
)
2280 memset(data
, 0, sizeof(long) * 10);
2281 data
[0] = wwin
->frame
->workspace
;
2282 data
[1] = wwin
->flags
.miniaturized
;
2283 data
[2] = wwin
->flags
.shaded
;
2284 data
[3] = wwin
->flags
.hidden
;
2285 data
[4] = wwin
->flags
.maximized
;
2286 if (wwin
->flags
.maximized
== 0) {
2287 data
[5] = wwin
->frame_x
;
2288 data
[6] = wwin
->frame_y
;
2289 data
[7] = wwin
->frame
->core
->width
;
2290 data
[8] = wwin
->frame
->core
->height
;
2292 data
[5] = wwin
->old_geometry
.x
;
2293 data
[6] = wwin
->old_geometry
.y
;
2294 data
[7] = wwin
->old_geometry
.width
;
2295 data
[8] = wwin
->old_geometry
.height
;
2298 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2299 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2300 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2303 XChangeProperty(dpy
, wwin
->client_win
, w_global
.atom
.wmaker
.state
,
2304 w_global
.atom
.wmaker
.state
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2307 static int getSavedState(Window window
, WSavedState
** state
)
2311 unsigned long nitems_ret
;
2312 unsigned long bytes_after_ret
;
2315 if (XGetWindowProperty(dpy
, window
, w_global
.atom
.wmaker
.state
, 0, 10,
2316 True
, w_global
.atom
.wmaker
.state
,
2317 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2318 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2321 *state
= wmalloc(sizeof(WSavedState
));
2323 (*state
)->workspace
= data
[0];
2324 (*state
)->miniaturized
= data
[1];
2325 (*state
)->shaded
= data
[2];
2326 (*state
)->hidden
= data
[3];
2327 (*state
)->maximized
= data
[4];
2328 (*state
)->x
= data
[5];
2329 (*state
)->y
= data
[6];
2330 (*state
)->w
= data
[7];
2331 (*state
)->h
= data
[8];
2332 (*state
)->window_shortcuts
= data
[9];
2336 if (*state
&& type_ret
== w_global
.atom
.wmaker
.state
)
2343 void wWindowClearShape(WWindow
* wwin
)
2345 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2346 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2350 void wWindowSetShape(WWindow
* wwin
)
2354 #ifdef OPTIMIZE_SHAPE
2359 /* only shape is the client's */
2360 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2363 /* Get array of rectangles describing the shape mask */
2364 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2368 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2374 /* insert our decoration rectangles in the rect list */
2375 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2378 if (HAS_TITLEBAR(wwin
)) {
2380 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2381 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2382 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2385 if (HAS_RESIZEBAR(wwin
)) {
2387 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2388 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2389 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2393 /* shape our frame window */
2394 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2395 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2401 #endif /* OPTIMIZE_SHAPE */
2403 if (HAS_TITLEBAR(wwin
)) {
2406 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2407 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2410 if (HAS_RESIZEBAR(wwin
)) {
2412 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2413 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2414 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2418 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2419 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2421 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2422 0, wwin
->frame
->top_width
, wwin
->client_win
,
2423 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2428 /* ====================================================================== */
2430 static FocusMode
getFocusMode(WWindow
* wwin
)
2434 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2435 if (wwin
->wm_hints
->input
== True
) {
2436 if (wwin
->protocols
.TAKE_FOCUS
)
2437 mode
= WFM_LOCALLY_ACTIVE
;
2441 if (wwin
->protocols
.TAKE_FOCUS
)
2442 mode
= WFM_GLOBALLY_ACTIVE
;
2444 mode
= WFM_NO_INPUT
;
2452 void wWindowSetKeyGrabs(WWindow
* wwin
)
2457 for (i
= 0; i
< WKBD_LAST
; i
++) {
2458 key
= &wKeyBindings
[i
];
2460 if (key
->keycode
== 0)
2462 if (key
->modifier
!= AnyModifier
) {
2463 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2464 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2466 /* Also grab all modifier combinations possible that include,
2467 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2468 * work even if the NumLock/ScrollLock key is on.
2470 wHackedGrabKey(key
->keycode
, key
->modifier
,
2471 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2474 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2475 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2478 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2481 void wWindowResetMouseGrabs(WWindow
* wwin
)
2483 /* Mouse grabs can't be done on the client window because of
2484 * ICCCM and because clients that try to do the same will crash.
2486 * But there is a problem wich makes tbar buttons of unfocused
2487 * windows not usable as the click goes to the frame window instead
2488 * of the button itself. Must figure a way to fix that.
2491 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2493 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2494 /* grabs for Meta+drag */
2495 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2496 True
, ButtonPressMask
| ButtonReleaseMask
,
2497 GrabModeSync
, GrabModeAsync
, None
, None
);
2499 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2500 * but we only grab it for Button4 and Button 5 since a lot of apps
2501 * use CTRL+Button1-3 for app related functionality
2503 if (wPreferences
.resize_increment
> 0) {
2504 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2505 True
, ButtonPressMask
| ButtonReleaseMask
,
2506 GrabModeSync
, GrabModeAsync
, None
, None
);
2507 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2508 True
, ButtonPressMask
| ButtonReleaseMask
,
2509 GrabModeSync
, GrabModeAsync
, None
, None
);
2511 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2512 True
, ButtonPressMask
| ButtonReleaseMask
,
2513 GrabModeSync
, GrabModeAsync
, None
, None
);
2514 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2515 True
, ButtonPressMask
| ButtonReleaseMask
,
2516 GrabModeSync
, GrabModeAsync
, None
, None
);
2520 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2521 && !wwin
->flags
.is_gnustep
) {
2522 /* the passive grabs to focus the window */
2523 /* if (wPreferences.focus_mode == WKF_CLICK) */
2524 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2525 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2530 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2532 if (attr
->flags
& GSExtraFlagsAttr
) {
2533 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2534 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2535 wWindowUpdateButtonImages(wwin
);
2540 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2541 const char *command
, pid_t pid
, WSavedState
* state
)
2543 WWindowState
*wstate
;
2545 wstate
= malloc(sizeof(WWindowState
));
2549 memset(wstate
, 0, sizeof(WWindowState
));
2552 wstate
->instance
= wstrdup(instance
);
2554 wstate
->class = wstrdup(class);
2556 wstate
->command
= wstrdup(command
);
2557 wstate
->state
= state
;
2559 wstate
->next
= windowState
;
2560 windowState
= wstate
;
2565 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2567 WMagicNumber
wWindowGetSavedState(Window win
)
2569 char *instance
, *class, *command
= NULL
;
2570 WWindowState
*wstate
= windowState
;
2575 command
= GetCommandForWindow(win
);
2579 if (PropGetWMClass(win
, &class, &instance
)) {
2581 if (SAME(instance
, wstate
->instance
) &&
2582 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2585 wstate
= wstate
->next
;
2601 void wWindowDeleteSavedState(WMagicNumber id
)
2603 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2605 if (!wstate
|| !windowState
)
2609 if (tmp
== wstate
) {
2610 windowState
= wstate
->next
;
2611 release_wwindowstate(wstate
);
2614 if (tmp
->next
== wstate
) {
2615 tmp
->next
= wstate
->next
;
2616 release_wwindowstate(wstate
);
2624 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2626 WWindowState
*tmp
, *wstate
;
2632 if (tmp
->pid
== pid
) {
2633 wstate
= windowState
;
2634 windowState
= tmp
->next
;
2636 release_wwindowstate(wstate
);
2639 if (tmp
->next
->pid
== pid
) {
2641 tmp
->next
= wstate
->next
;
2642 release_wwindowstate(wstate
);
2650 static void release_wwindowstate(WWindowState
*wstate
)
2652 if (wstate
->instance
)
2653 wfree(wstate
->instance
);
2656 wfree(wstate
->class);
2658 if (wstate
->command
)
2659 wfree(wstate
->command
);
2661 wfree(wstate
->state
);
2665 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2667 if (wwin
->flags
.omnipresent
== flag
)
2670 wwin
->flags
.omnipresent
= flag
;
2671 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2674 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2676 WWindow
*wwin
= data
;
2678 #ifndef NUMLOCK_HACK
2679 if ((event
->xbutton
.state
& ValidModMask
)
2680 != (event
->xbutton
.state
& ~LockMask
)) {
2681 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2682 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2686 event
->xbutton
.state
&= ValidModMask
;
2688 CloseWindowMenu(wwin
->screen_ptr
);
2690 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2691 && !WFLAGP(wwin
, no_focusable
)) {
2692 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2695 if (event
->xbutton
.button
== Button1
)
2696 wRaiseFrame(wwin
->frame
->core
);
2698 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2699 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2700 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2701 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2706 if (event
->xbutton
.state
& MOD_MASK
) {
2707 /* move the window */
2708 wMouseMoveWindow(wwin
, event
);
2709 XUngrabPointer(dpy
, CurrentTime
);
2711 wMouseResizeWindow(wwin
, event
);
2712 XUngrabPointer(dpy
, CurrentTime
);
2716 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2718 WWindow
*wwin
= data
;
2720 event
->xbutton
.state
&= ValidModMask
;
2722 if (event
->xbutton
.button
== Button1
) {
2723 if (event
->xbutton
.state
== 0) {
2724 if (!WFLAGP(wwin
, no_shadeable
)) {
2726 if (wwin
->flags
.shaded
)
2727 wUnshadeWindow(wwin
);
2734 if (event
->xbutton
.state
& ControlMask
)
2735 dir
|= MAX_VERTICAL
;
2737 if (event
->xbutton
.state
& ShiftMask
) {
2738 dir
|= MAX_HORIZONTAL
;
2739 if (!(event
->xbutton
.state
& ControlMask
))
2740 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2743 /* maximize window */
2744 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2745 int ndir
= dir
^ wwin
->flags
.maximized
;
2748 wMaximizeWindow(wwin
, ndir
);
2750 wUnmaximizeWindow(wwin
);
2753 } else if (event
->xbutton
.button
== Button3
) {
2754 if (event
->xbutton
.state
& MOD_MASK
)
2755 wHideOtherApplications(wwin
);
2756 } else if (event
->xbutton
.button
== Button2
) {
2757 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2758 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2760 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2761 wUnshadeWindow(wwin
);
2765 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2767 WWindow
*wwin
= desc
->parent
;
2768 unsigned int new_width
, w_scale
;
2769 unsigned int new_height
, h_scale
;
2770 unsigned int resize_width_increment
= 0;
2771 unsigned int resize_height_increment
= 0;
2773 if (wwin
->normal_hints
) {
2774 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2775 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2776 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2777 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2779 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2780 resize_width_increment
= wPreferences
.resize_increment
;
2781 resize_height_increment
= wPreferences
.resize_increment
;
2784 event
->xbutton
.state
&= ValidModMask
;
2786 CloseWindowMenu(wwin
->screen_ptr
);
2788 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2789 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2791 if (event
->xbutton
.button
== Button1
)
2792 wRaiseFrame(wwin
->frame
->core
);
2794 if (event
->xbutton
.state
& ControlMask
) {
2795 if (event
->xbutton
.button
== Button4
) {
2796 new_width
= wwin
->client
.width
- resize_width_increment
;
2797 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2798 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2800 if (event
->xbutton
.button
== Button5
) {
2801 new_width
= wwin
->client
.width
+ resize_width_increment
;
2802 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2803 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2807 if (event
->xbutton
.state
& MOD_MASK
) {
2808 /* move the window */
2809 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2810 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2811 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2814 if (event
->xbutton
.button
== Button3
) {
2815 wMouseResizeWindow(wwin
, event
);
2816 } else if (event
->xbutton
.button
== Button4
) {
2817 new_height
= wwin
->client
.height
- resize_height_increment
;
2818 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2819 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2820 } else if (event
->xbutton
.button
== Button5
) {
2821 new_height
= wwin
->client
.height
+ resize_height_increment
;
2822 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2823 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2824 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2825 wMouseMoveWindow(wwin
, event
);
2827 XUngrabPointer(dpy
, CurrentTime
);
2831 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2833 WWindow
*wwin
= (WWindow
*) data
;
2835 #ifndef NUMLOCK_HACK
2836 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2837 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2838 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2840 event
->xbutton
.state
&= ValidModMask
;
2842 CloseWindowMenu(wwin
->screen_ptr
);
2844 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2845 && !WFLAGP(wwin
, no_focusable
))
2846 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2848 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2850 if (event
->xbutton
.button
== Button1
) {
2851 if (event
->xbutton
.state
& MOD_MASK
)
2852 wLowerFrame(wwin
->frame
->core
);
2854 wRaiseFrame(wwin
->frame
->core
);
2856 if ((event
->xbutton
.state
& ShiftMask
)
2857 && !(event
->xbutton
.state
& ControlMask
)) {
2858 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2861 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2862 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2863 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2864 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2868 /* move the window */
2869 wMouseMoveWindow(wwin
, event
);
2871 XUngrabPointer(dpy
, CurrentTime
);
2872 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2873 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2874 WObjDescriptor
*desc
;
2876 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2877 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2878 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2879 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2883 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2885 /* allow drag select */
2886 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2887 event
->xany
.send_event
= True
;
2888 (*desc
->handle_mousedown
) (desc
, event
);
2890 XUngrabPointer(dpy
, CurrentTime
);
2894 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2896 WWindow
*wwin
= data
;
2898 event
->xbutton
.state
&= ValidModMask
;
2900 CloseWindowMenu(wwin
->screen_ptr
);
2902 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2905 /* if control-click, kill the client */
2906 if (event
->xbutton
.state
& ControlMask
) {
2909 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2910 /* send delete message */
2911 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
2912 w_global
.timestamp
.last_event
);
2917 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2919 WWindow
*wwin
= data
;
2921 CloseWindowMenu(wwin
->screen_ptr
);
2923 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2926 /* send delete message */
2927 if (wwin
->protocols
.DELETE_WINDOW
)
2928 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
2929 w_global
.timestamp
.last_event
);
2934 #ifdef XKB_BUTTON_HINT
2935 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2937 WWindow
*wwin
= data
;
2938 WFrameWindow
*fwin
= wwin
->frame
;
2939 WScreen
*scr
= fwin
->screen_ptr
;
2942 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2944 tl
= wwin
->frame
->languagemode
;
2945 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2946 wwin
->frame
->last_languagemode
= tl
;
2947 wSetFocusTo(scr
, wwin
);
2948 wwin
->frame
->languagebutton_image
=
2949 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2950 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2951 if (event
->xbutton
.button
== Button3
)
2953 wRaiseFrame(fwin
->core
);
2957 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2959 WWindow
*wwin
= data
;
2961 event
->xbutton
.state
&= ValidModMask
;
2963 CloseWindowMenu(wwin
->screen_ptr
);
2965 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2968 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2969 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
2970 w_global
.timestamp
.last_event
);
2973 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2975 wapp
= wApplicationOf(wwin
->main_window
);
2976 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2977 wHideApplication(wapp
);
2978 } else if (event
->xbutton
.state
== 0) {
2979 wIconifyWindow(wwin
);