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
];
78 /***** Local Stuff *****/
79 static WWindowState
*windowState
= NULL
;
80 static FocusMode
getFocusMode(WWindow
*wwin
);
81 static int getSavedState(Window window
, WSavedState
**state
);
82 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
84 /* frame window (during window grabs) */
85 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
88 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
89 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
92 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
94 #ifdef XKB_BUTTON_HINT
95 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
98 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
99 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
100 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void release_wwindowstate(WWindowState
*wstate
);
104 /****** Notification Observers ******/
106 static void appearanceObserver(void *self
, WMNotification
* notif
)
108 WWindow
*wwin
= (WWindow
*) self
;
109 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
111 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
114 if (flags
& WFontSettings
) {
115 wWindowConfigureBorders(wwin
);
116 if (wwin
->flags
.shaded
) {
117 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
118 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
119 wWindowSynthConfigureNotify(wwin
);
122 if (flags
& WTextureSettings
)
123 wwin
->frame
->flags
.need_texture_remake
= 1;
125 if (flags
& (WTextureSettings
| WColorSettings
)) {
126 if (wwin
->frame
->titlebar
)
127 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
129 wFrameWindowPaint(wwin
->frame
);
134 /* Return the WWindow associated with a given (Xlib) Window. */
135 WWindow
*wWindowFor(Window window
)
137 WObjDescriptor
*desc
;
142 if (XFindContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
145 if (desc
->parent_type
== WCLASS_WINDOW
)
147 else if (desc
->parent_type
== WCLASS_FRAME
) {
148 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
149 if (frame
->flags
.is_client_window_frame
)
156 WWindow
*wWindowCreate(void)
160 wwin
= wmalloc(sizeof(WWindow
));
163 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
164 wwin
->client_descriptor
.parent
= wwin
;
165 wwin
->client_descriptor
.self
= wwin
;
166 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
171 void wWindowDestroy(WWindow
*wwin
)
175 if (wwin
->screen_ptr
->cmap_window
== wwin
)
176 wwin
->screen_ptr
->cmap_window
= NULL
;
178 WMRemoveNotificationObserver(wwin
);
180 wwin
->flags
.destroyed
= 1;
182 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
183 if (!w_global
.shortcut
.windows
[i
])
186 WMRemoveFromArray(w_global
.shortcut
.windows
[i
], wwin
);
188 if (!WMGetArrayItemCount(w_global
.shortcut
.windows
[i
])) {
189 WMFreeArray(w_global
.shortcut
.windows
[i
]);
190 w_global
.shortcut
.windows
[i
] = NULL
;
194 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
195 wwin
->fake_group
->retainCount
--;
196 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
197 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
198 wwin
->fake_group
->leader
= None
;
199 wwin
->fake_group
->origLeader
= None
;
204 if (wwin
->normal_hints
)
205 XFree(wwin
->normal_hints
);
208 XFree(wwin
->wm_hints
);
210 if (wwin
->wm_instance
)
211 XFree(wwin
->wm_instance
);
214 XFree(wwin
->wm_class
);
216 if (wwin
->wm_gnustep_attr
)
217 wfree(wwin
->wm_gnustep_attr
);
219 if (wwin
->cmap_windows
)
220 XFree(wwin
->cmap_windows
);
222 XDeleteContext(dpy
, wwin
->client_win
, w_global
.context
.client_win
);
225 wFrameWindowDestroy(wwin
->frame
);
228 RemoveFromStackList(wwin
->icon
->core
);
229 wIconDestroy(wwin
->icon
);
230 if (wPreferences
.auto_arrange_icons
)
231 wArrangeIcons(wwin
->screen_ptr
, True
);
233 if (wwin
->net_icon_image
)
234 RReleaseImage(wwin
->net_icon_image
);
239 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
241 if (gs_hints
->flags
& GSWindowStyleAttr
) {
242 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
243 wwin
->client_flags
.no_border
= 1;
244 wwin
->client_flags
.no_titlebar
= 1;
245 wwin
->client_flags
.no_closable
= 1;
246 wwin
->client_flags
.no_miniaturizable
= 1;
247 wwin
->client_flags
.no_resizable
= 1;
248 wwin
->client_flags
.no_close_button
= 1;
249 wwin
->client_flags
.no_miniaturize_button
= 1;
250 wwin
->client_flags
.no_resizebar
= 1;
252 wwin
->client_flags
.no_close_button
=
253 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
255 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
257 wwin
->client_flags
.no_miniaturize_button
=
258 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
260 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
262 wwin
->client_flags
.no_resizebar
=
263 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
265 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
267 /* these attributes supposedly imply in the existence
269 if (gs_hints
->window_style
& (WMResizableWindowMask
|
270 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
271 wwin
->client_flags
.no_titlebar
= 0;
273 wwin
->client_flags
.no_titlebar
=
274 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
279 /* setup the defaults */
280 wwin
->client_flags
.no_border
= 0;
281 wwin
->client_flags
.no_titlebar
= 0;
282 wwin
->client_flags
.no_closable
= 0;
283 wwin
->client_flags
.no_miniaturizable
= 0;
284 wwin
->client_flags
.no_resizable
= 0;
285 wwin
->client_flags
.no_close_button
= 0;
286 wwin
->client_flags
.no_miniaturize_button
= 0;
287 wwin
->client_flags
.no_resizebar
= 0;
289 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
290 wwin
->client_flags
.no_appicon
= 1;
293 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
295 WScreen
*scr
= wwin
->screen_ptr
;
297 /* sets global default stuff */
298 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
300 * Decoration setting is done in this precedence (lower to higher)
301 * - use global default in the resource database
302 * - guess some settings
303 * - use GNUstep/external window attributes
304 * - set hints specified for the app in the resource DB
307 WSETUFLAG(wwin
, broken_close
, 0);
309 if (wwin
->protocols
.DELETE_WINDOW
)
310 WSETUFLAG(wwin
, kill_close
, 0);
312 WSETUFLAG(wwin
, kill_close
, 1);
314 /* transients can't be iconified or maximized */
315 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
316 WSETUFLAG(wwin
, no_miniaturizable
, 1);
317 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
320 /* if the window can't be resized, remove the resizebar */
321 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
322 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
323 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
324 WSETUFLAG(wwin
, no_resizable
, 1);
325 WSETUFLAG(wwin
, no_resizebar
, 1);
328 /* set GNUstep window attributes */
329 if (wwin
->wm_gnustep_attr
) {
330 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
332 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
334 *level
= wwin
->wm_gnustep_attr
->window_level
;
336 * INT_MIN is the only illegal window level.
338 if (*level
== INT_MIN
)
339 *level
= INT_MIN
+ 1;
342 *level
= WMNormalLevel
;
345 int tmp_workspace
= -1;
346 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
349 wMWMCheckClientHints(wwin
);
350 #endif /* MWM_HINTS */
352 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
354 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
355 * have INT_MIN that means that no window level was requested. -Dan
357 if (tmp_level
== INT_MIN
) {
358 if (WFLAGP(wwin
, floating
))
359 *level
= WMFloatingLevel
;
360 else if (WFLAGP(wwin
, sunken
))
361 *level
= WMSunkenLevel
;
363 *level
= WMNormalLevel
;
368 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
369 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
370 if (transientOwner
) {
371 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
372 if (ownerLevel
> *level
)
377 if (tmp_workspace
>= 0)
378 *workspace
= tmp_workspace
% w_global
.workspace
.count
;
382 * Set attributes specified only for that window/class.
383 * This might do duplicate work with the 1st wDefaultFillAttributes().
385 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
386 &wwin
->defined_user_flags
, False
);
388 * Sanity checks for attributes that depend on other attributes
390 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
391 wwin
->user_flags
.emulate_appicon
= 0;
393 if (wwin
->main_window
!= None
) {
394 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
395 if (wapp
&& !wapp
->flags
.emulated
)
396 wwin
->user_flags
.emulate_appicon
= 0;
399 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
400 wwin
->user_flags
.emulate_appicon
= 0;
402 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
403 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
404 wwin
->user_flags
.sunken
= 0;
406 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
408 /* windows that have takefocus=False shouldn't take focus at all */
409 if (wwin
->focus_mode
== WFM_NO_INPUT
)
410 wwin
->client_flags
.no_focusable
= 1;
413 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
417 w1
= wwin
->frame
->core
->width
;
418 h1
= wwin
->frame
->core
->height
;
419 w2
= obscured
->frame
->core
->width
;
420 h2
= obscured
->frame
->core
->height
;
422 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
423 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
426 if (wwin
->frame_x
+ w1
< obscured
->frame_x
427 || wwin
->frame_y
+ h1
< obscured
->frame_y
428 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
434 static void fixLeaderProperties(WWindow
*wwin
)
436 XClassHint
*classHint
;
437 XWMHints
*hints
, *clientHints
;
438 XWindowAttributes attr
;
439 Window leaders
[2], window
;
440 char **argv
, *command
;
444 classHint
= XAllocClassHint();
445 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
446 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
448 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
452 leaders
[0] = wwin
->client_leader
;
453 leaders
[1] = wwin
->group_id
;
456 command
= GetCommandForWindow(wwin
->client_win
);
458 wfree(command
); /* command already set. nothing to do. */
460 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
463 for (i
= 0; i
< 2; i
++) {
466 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
467 classHint
->res_name
= wwin
->wm_instance
;
468 classHint
->res_class
= wwin
->wm_class
;
469 XSetClassHint(dpy
, window
, classHint
);
471 hints
= XGetWMHints(dpy
, window
);
474 } else if (clientHints
) {
475 /* set window group leader to self */
476 clientHints
->window_group
= window
;
477 clientHints
->flags
|= WindowGroupHint
;
478 XSetWMHints(dpy
, window
, clientHints
);
482 command
= GetCommandForWindow(window
);
484 wfree(command
); /* command already set. nothing to do. */
486 XSetCommand(dpy
, window
, argv
, argc
);
489 /* Make sure we get notification when this window is destroyed */
490 if (XGetWindowAttributes(dpy
, window
, &attr
))
491 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
502 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
504 XClassHint
*classHint
;
510 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
512 classHint
= XAllocClassHint();
513 classHint
->res_name
= instance
;
514 classHint
->res_class
= class;
515 XSetClassHint(dpy
, leader
, classHint
);
518 /* inherit these from the original leader if available */
519 hints
= XGetWMHints(dpy
, win
);
521 hints
= XAllocWMHints();
524 /* set window group leader to self */
525 hints
->window_group
= leader
;
526 hints
->flags
|= WindowGroupHint
;
527 XSetWMHints(dpy
, leader
, hints
);
530 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
531 XSetCommand(dpy
, leader
, argv
, argc
);
532 XFreeStringList(argv
);
538 static int matchIdentifier(const void *item
, const void *cdata
)
540 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
544 *----------------------------------------------------------------
546 * reparents the window and allocates a descriptor for it.
547 * Window manager hints and other hints are fetched to configure
548 * the window decoration attributes and others. User preferences
549 * for the window are used if available, to configure window
550 * decorations and some behaviour.
551 * If in startup, windows that are override redirect,
552 * unmapped and never were managed and are Withdrawn are not
556 * the new window descriptor
559 * The window is reparented and appropriate notification
560 * is done to the client. Input mask for the window is setup.
561 * The window descriptor is also associated with various window
562 * contexts and inserted in the head of the window list.
563 * Event handler contexts are associated for some objects
564 * (buttons, titlebar and resizebar)
566 *----------------------------------------------------------------
568 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
572 unsigned width
, height
;
573 XWindowAttributes wattribs
;
574 XSetWindowAttributes attribs
;
575 WWindowState
*win_state
;
576 WWindow
*transientOwner
= NULL
;
582 Bool withdraw
= False
;
589 /* make sure the window is still there */
590 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
595 /* if it's an override-redirect, ignore it */
596 if (wattribs
.override_redirect
) {
601 wm_state
= PropGetWindowState(window
);
603 /* if it's startup and the window is unmapped, don't manage it */
604 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
609 wwin
= wWindowCreate();
611 title
= wNETWMGetWindowName(window
);
613 wwin
->flags
.net_has_title
= 1;
614 else if (!wFetchName(dpy
, window
, &title
))
617 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
620 if (w_global
.xext
.shape
.supported
) {
625 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
626 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
627 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
628 wwin
->flags
.shaped
= b_shaped
;
632 /* Get hints and other information in properties */
633 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
635 /* setup descriptor */
636 wwin
->client_win
= window
;
637 wwin
->screen_ptr
= scr
;
638 wwin
->old_border_width
= wattribs
.border_width
;
639 wwin
->event_mask
= CLIENT_EVENTS
;
640 attribs
.event_mask
= CLIENT_EVENTS
;
641 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
642 attribs
.save_under
= False
;
644 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
645 XSetWindowBorderWidth(dpy
, window
, 0);
647 /* get hints from GNUstep app */
648 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
649 wwin
->flags
.is_gnustep
= 1;
651 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
652 wwin
->wm_gnustep_attr
= NULL
;
654 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
655 wwin
->flags
.is_dockapp
= 1;
659 wwin
->client_leader
= PropGetClientLeader(window
);
660 if (wwin
->client_leader
!= None
)
661 wwin
->main_window
= wwin
->client_leader
;
663 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
665 if (wwin
->wm_hints
) {
666 if (wwin
->wm_hints
->flags
& StateHint
) {
667 if (wwin
->wm_hints
->initial_state
== IconicState
) {
668 wwin
->flags
.miniaturized
= 1;
669 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
670 wwin
->flags
.is_dockapp
= 1;
675 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
676 wwin
->group_id
= wwin
->wm_hints
->window_group
;
677 /* window_group has priority over CLIENT_LEADER */
678 wwin
->main_window
= wwin
->group_id
;
680 wwin
->group_id
= None
;
683 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
684 wwin
->flags
.urgent
= 1;
685 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
688 wwin
->group_id
= None
;
691 PropGetProtocols(window
, &wwin
->protocols
);
693 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
694 wwin
->transient_for
= None
;
696 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
697 wwin
->transient_for
= scr
->root_win
;
699 transientOwner
= wWindowFor(wwin
->transient_for
);
700 if (transientOwner
&& transientOwner
->main_window
!= None
)
701 wwin
->main_window
= transientOwner
->main_window
;
705 /* guess the focus mode */
706 wwin
->focus_mode
= getFocusMode(wwin
);
708 /* get geometry stuff */
709 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
711 /* get colormap windows */
712 GetColormapWindows(wwin
);
715 * Setup the decoration/window attributes and
718 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
720 /* Make broken apps behave as a nice app. */
721 if (WFLAGP(wwin
, emulate_appicon
))
722 wwin
->main_window
= wwin
->client_win
;
724 fixLeaderProperties(wwin
);
726 wwin
->orig_main_window
= wwin
->main_window
;
728 if (wwin
->flags
.is_gnustep
)
729 WSETUFLAG(wwin
, shared_appicon
, 0);
731 if (wwin
->main_window
) {
732 XTextProperty text_prop
;
734 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, w_global
.atom
.wmaker
.menu
))
735 WSETUFLAG(wwin
, shared_appicon
, 0);
738 if (wwin
->flags
.is_dockapp
)
739 WSETUFLAG(wwin
, shared_appicon
, 0);
741 if (wwin
->main_window
) {
742 WApplication
*app
= wApplicationOf(wwin
->main_window
);
743 if (app
&& app
->app_icon
)
744 WSETUFLAG(wwin
, shared_appicon
, 0);
747 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
748 char *buffer
, *instance
, *class;
749 WFakeGroupLeader
*fPtr
;
752 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
754 /* // only enter here if PropGetWMClass() succeds */
755 PropGetWMClass(wwin
->main_window
, &class, &instance
);
756 buffer
= StrConcatDot(instance
, class);
758 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
759 if (index
!= WANotFound
) {
760 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
761 if (fPtr
->retainCount
== 0)
762 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
766 if (fPtr
->origLeader
== None
) {
767 if (ADEQUATE(wwin
->main_window
)) {
769 fPtr
->origLeader
= wwin
->main_window
;
772 wwin
->fake_group
= fPtr
;
773 wwin
->main_window
= fPtr
->leader
;
776 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
778 fPtr
->identifier
= buffer
;
779 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
780 fPtr
->origLeader
= None
;
781 fPtr
->retainCount
= 1;
783 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
785 if (ADEQUATE(wwin
->main_window
)) {
787 fPtr
->origLeader
= wwin
->main_window
;
789 wwin
->fake_group
= fPtr
;
790 wwin
->main_window
= fPtr
->leader
;
802 * Setup the initial state of the window
804 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
805 wwin
->flags
.miniaturized
= 1;
807 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
808 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
810 wNETWMCheckInitialClientState(wwin
);
812 /* apply previous state if it exists and we're in startup */
813 if (scr
->flags
.startup
&& wm_state
>= 0) {
814 if (wm_state
== IconicState
)
815 wwin
->flags
.miniaturized
= 1;
816 else if (wm_state
== WithdrawnState
)
820 /* if there is a saved state (from file), restore it */
822 if (wwin
->main_window
!= None
)
823 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
825 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
827 if (win_state
&& !withdraw
) {
828 if (win_state
->state
->hidden
> 0)
829 wwin
->flags
.hidden
= win_state
->state
->hidden
;
831 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
832 wwin
->flags
.shaded
= win_state
->state
->shaded
;
834 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
835 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
837 if (!IS_OMNIPRESENT(wwin
)) {
838 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
840 if (w
< 0 || w
>= w_global
.workspace
.count
) {
841 workspace
= win_state
->state
->workspace
;
842 if (workspace
>= w_global
.workspace
.count
)
843 workspace
= w_global
.workspace
.current
;
848 workspace
= w_global
.workspace
.current
;
852 /* if we're restarting, restore saved state (from hints).
853 * This will overwrite previous */
857 if (getSavedState(window
, &wstate
)) {
858 wwin
->flags
.shaded
= wstate
->shaded
;
859 wwin
->flags
.hidden
= wstate
->hidden
;
860 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
861 wwin
->flags
.maximized
= wstate
->maximized
;
862 if (wwin
->flags
.maximized
) {
863 wwin
->old_geometry
.x
= wstate
->x
;
864 wwin
->old_geometry
.y
= wstate
->y
;
865 wwin
->old_geometry
.width
= wstate
->w
;
866 wwin
->old_geometry
.height
= wstate
->h
;
869 workspace
= wstate
->workspace
;
874 /* restore window shortcut */
875 if (wstate
!= NULL
|| win_state
!= NULL
) {
878 if (win_state
!= NULL
)
879 mask
= win_state
->state
->window_shortcuts
;
881 if (wstate
!= NULL
&& mask
== 0)
882 mask
= wstate
->window_shortcuts
;
887 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
888 if (mask
& (1 << i
)) {
889 if (!w_global
.shortcut
.windows
[i
])
890 w_global
.shortcut
.windows
[i
] = WMCreateArray(4);
892 WMAddToArray(w_global
.shortcut
.windows
[i
], wwin
);
902 /* don't let transients start miniaturized if their owners are not */
903 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
904 wwin
->flags
.miniaturized
= 0;
906 wwin
->wm_hints
->initial_state
= NormalState
;
909 /* set workspace on which the window starts */
910 if (workspace
>= 0) {
911 if (workspace
> w_global
.workspace
.count
- 1)
912 workspace
= workspace
% w_global
.workspace
.count
;
916 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
918 if (w
>= 0 && w
< w_global
.workspace
.count
&& !(IS_OMNIPRESENT(wwin
))) {
921 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
922 workspace
= transientOwner
->frame
->workspace
;
924 workspace
= w_global
.workspace
.current
;
928 /* setup window geometry */
929 if (win_state
&& win_state
->state
->w
> 0) {
930 width
= win_state
->state
->w
;
931 height
= win_state
->state
->h
;
934 wWindowConstrainSize(wwin
, &width
, &height
);
936 /* do not ask for window placement if the window is
937 * transient, during startup, if the initial workspace is another one
938 * or if the window wants to start iconic.
939 * If geometry was saved, restore it. */
941 Bool dontBring
= False
;
943 if (win_state
&& win_state
->state
->w
> 0) {
944 x
= win_state
->state
->x
;
945 y
= win_state
->state
->y
;
946 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
947 && !scr
->flags
.startup
948 && workspace
== w_global
.workspace
.current
949 && !wwin
->flags
.miniaturized
950 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
952 if (transientOwner
&& transientOwner
->flags
.mapped
) {
953 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
957 x
= transientOwner
->frame_x
+
958 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
959 y
= transientOwner
->frame_y
+
960 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
962 /* limit transient windows to be inside their parent's head */
963 rect
.pos
.x
= transientOwner
->frame_x
;
964 rect
.pos
.y
= transientOwner
->frame_y
;
965 rect
.size
.width
= transientOwner
->frame
->core
->width
;
966 rect
.size
.height
= transientOwner
->frame
->core
->height
;
968 head
= wGetHeadForRect(scr
, rect
);
969 rect
= wGetRectForHead(scr
, head
);
973 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
974 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
978 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
979 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
982 PlaceWindow(wwin
, &x
, &y
, width
, height
);
985 if (wPreferences
.window_placement
== WPM_MANUAL
)
988 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
993 /* Make spash screens come out in the center of a head
994 * trouble is that most splashies never get here
995 * they are managed trough atoms but god knows where.
996 * Dan, do you know ? -peter
998 * Most of them are not managed, they have set
999 * OverrideRedirect, which means we can't do anything about
1002 /* xinerama checks for: across head and dead space */
1005 rect
.size
.width
= width
;
1006 rect
.size
.height
= height
;
1008 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1010 if (flags
& XFLAG_DEAD
)
1013 if (flags
& XFLAG_MULTIPLE
)
1017 switch (reposition
) {
1019 head
= wGetHeadForPointerLocation(scr
);
1020 rect
= wGetRectForHead(scr
, head
);
1022 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1023 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1027 rect
= wGetRectForHead(scr
, head
);
1031 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1032 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1036 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1037 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1046 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1047 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1050 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1052 if (wwin
->flags
.urgent
) {
1053 if (!IS_OMNIPRESENT(wwin
))
1054 wwin
->flags
.omnipresent
^= 1;
1057 /* Create frame, borders and do reparenting */
1058 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1059 #ifdef XKB_BUTTON_HINT
1060 if (wPreferences
.modelock
)
1061 foo
|= WFF_LANGUAGE_BUTTON
;
1063 if (HAS_TITLEBAR(wwin
))
1064 foo
|= WFF_TITLEBAR
;
1066 if (HAS_RESIZEBAR(wwin
))
1067 foo
|= WFF_RESIZEBAR
;
1069 if (HAS_BORDER(wwin
))
1072 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1073 x
, y
, width
, height
,
1074 &wPreferences
.window_title_clearance
,
1075 &wPreferences
.window_title_min_height
,
1076 &wPreferences
.window_title_max_height
,
1078 scr
->window_title_texture
,
1079 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1080 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1082 wwin
->frame
->flags
.is_client_window_frame
= 1;
1083 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1085 /* setup button images */
1086 wWindowUpdateButtonImages(wwin
);
1088 /* hide unused buttons */
1090 if (WFLAGP(wwin
, no_close_button
))
1091 foo
|= WFF_RIGHT_BUTTON
;
1093 if (WFLAGP(wwin
, no_miniaturize_button
))
1094 foo
|= WFF_LEFT_BUTTON
;
1096 #ifdef XKB_BUTTON_HINT
1097 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1098 foo
|= WFF_LANGUAGE_BUTTON
;
1101 wFrameWindowHideButton(wwin
->frame
, foo
);
1103 wwin
->frame
->child
= wwin
;
1104 wwin
->frame
->workspace
= workspace
;
1105 wwin
->frame
->on_click_left
= windowIconifyClick
;
1107 #ifdef XKB_BUTTON_HINT
1108 if (wPreferences
.modelock
)
1109 wwin
->frame
->on_click_language
= windowLanguageClick
;
1112 wwin
->frame
->on_click_right
= windowCloseClick
;
1113 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1114 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1115 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1116 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1118 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1119 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1120 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1125 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1127 /* if gravity is to the south, account for the border sizes */
1129 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1133 * wWindowConfigure() will init the client window's size
1134 * (wwin->client.{width,height}) and all other geometry
1135 * related variables (frame_x,frame_y) */
1136 wWindowConfigure(wwin
, x
, y
, width
, height
);
1138 /* to make sure the window receives it's new position after reparenting */
1139 wWindowSynthConfigureNotify(wwin
);
1141 /* Setup descriptors and save window to internal lists */
1142 if (wwin
->main_window
!= None
) {
1146 /* Leader windows do not necessary set themselves as leaders.
1147 * If this is the case, point the leader of this window to
1149 leader
= wWindowFor(wwin
->main_window
);
1150 if (leader
&& leader
->main_window
== None
)
1151 leader
->main_window
= leader
->client_win
;
1153 app
= wApplicationCreate(wwin
);
1155 app
->last_workspace
= workspace
;
1157 /* Do application specific stuff, like setting application
1158 * wide attributes. */
1160 if (wwin
->flags
.hidden
) {
1161 /* if the window was set to hidden because it was hidden
1162 * in a previous incarnation and that state was restored */
1163 app
->flags
.hidden
= 1;
1164 } else if (app
->flags
.hidden
) {
1165 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1166 wwin
->flags
.hidden
= 1;
1168 wUnhideApplication(app
, False
, False
);
1176 /* setup the frame descriptor */
1177 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1178 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1179 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1181 /* don't let windows go away if we die */
1182 XAddToSaveSet(dpy
, window
);
1184 XLowerWindow(dpy
, window
);
1186 /* if window is in this workspace and should be mapped, then map it */
1187 if (!wwin
->flags
.miniaturized
&& (workspace
== w_global
.workspace
.current
|| IS_OMNIPRESENT(wwin
))
1188 && !wwin
->flags
.hidden
&& !withdraw
) {
1190 /* The following "if" is to avoid crashing of clients that expect
1191 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1192 * after the return from this function. */
1193 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1194 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1196 wClientSetState(wwin
, NormalState
, None
);
1198 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1199 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1201 * The brain damaged idiotic non-click to focus modes will
1202 * have trouble with this because:
1204 * 1. window is created and mapped by the client
1205 * 2. window is mapped by wmaker in small size
1206 * 3. window is animated to grow to normal size
1207 * 4. this function returns to normal event loop
1208 * 5. eventually, the EnterNotify event that would trigger
1209 * the window focusing (if the mouse is over that window)
1210 * will be processed by wmaker.
1211 * But since this event will be rather delayed
1212 * (step 3 has a large delay) the time when the event ocurred
1213 * and when it is processed, the client that owns that window
1214 * will reject the XSetInputFocus() for it.
1216 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1217 DoWindowBirth(wwin
);
1222 /* setup stacking descriptor */
1224 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1226 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1228 if (!scr
->focused_window
) {
1229 /* first window on the list */
1232 scr
->focused_window
= wwin
;
1236 /* add window at beginning of focus window list */
1237 tmp
= scr
->focused_window
;
1246 /* raise is set to true if we un-hid the app when this window was born.
1247 * we raise, else old windows of this app will be above this new one. */
1249 wRaiseFrame(wwin
->frame
->core
);
1251 /* Update name must come after WApplication stuff is done */
1252 wWindowUpdateName(wwin
, title
);
1258 /* Final preparations before window is ready to go */
1259 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1261 if (!wwin
->flags
.miniaturized
&& workspace
== w_global
.workspace
.current
&& !wwin
->flags
.hidden
) {
1262 if (((transientOwner
&& transientOwner
->flags
.focused
)
1263 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1265 /* only auto_focus if on same screen as mouse
1266 * (and same head for xinerama mode)
1267 * TODO: make it an option */
1269 /*TODO add checking the head of the window, is it available? */
1270 short same_screen
= 0, same_head
= 1;
1276 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1277 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1280 if (same_screen
== 1 && same_head
== 1)
1281 wSetFocusTo(scr
, wwin
);
1284 wWindowResetMouseGrabs(wwin
);
1286 if (!WFLAGP(wwin
, no_bind_keys
))
1287 wWindowSetKeyGrabs(wwin
);
1289 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1290 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1292 /* Setup Notification Observers */
1293 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1295 /* Cleanup temporary stuff */
1297 wWindowDeleteSavedState(win_state
);
1299 /* If the window must be withdrawed, then do it now.
1300 * Must do some optimization, 'though */
1302 wwin
->flags
.mapped
= 0;
1303 wClientSetState(wwin
, WithdrawnState
, None
);
1304 wUnmanageWindow(wwin
, True
, False
);
1311 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1312 const char *title
, int x
, int y
, int width
, int height
)
1317 wwin
= wWindowCreate();
1319 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1321 wwin
->flags
.internal_window
= 1;
1323 WSETUFLAG(wwin
, omnipresent
, 1);
1324 WSETUFLAG(wwin
, no_shadeable
, 1);
1325 WSETUFLAG(wwin
, no_resizable
, 1);
1326 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1328 wwin
->focus_mode
= WFM_PASSIVE
;
1329 wwin
->client_win
= window
;
1330 wwin
->screen_ptr
= scr
;
1331 wwin
->transient_for
= owner
;
1334 wwin
->client
.width
= width
;
1335 wwin
->client
.height
= height
;
1336 wwin
->frame_x
= wwin
->client
.x
;
1337 wwin
->frame_y
= wwin
->client
.y
;
1339 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1340 foo
|= WFF_TITLEBAR
;
1341 #ifdef XKB_BUTTON_HINT
1342 foo
|= WFF_LANGUAGE_BUTTON
;
1345 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1346 wwin
->frame_x
, wwin
->frame_y
,
1348 &wPreferences
.window_title_clearance
,
1349 &wPreferences
.window_title_min_height
,
1350 &wPreferences
.window_title_max_height
,
1352 scr
->window_title_texture
,
1353 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1354 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1356 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
1358 wwin
->frame
->flags
.is_client_window_frame
= 1;
1359 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1361 wFrameWindowChangeTitle(wwin
->frame
, title
);
1363 /* setup button images */
1364 wWindowUpdateButtonImages(wwin
);
1367 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1369 wwin
->frame
->child
= wwin
;
1370 wwin
->frame
->workspace
= w_global
.workspace
.current
;
1372 #ifdef XKB_BUTTON_HINT
1373 if (wPreferences
.modelock
)
1374 wwin
->frame
->on_click_language
= windowLanguageClick
;
1377 wwin
->frame
->on_click_right
= windowCloseClick
;
1378 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1379 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1380 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1381 wwin
->client
.y
+= wwin
->frame
->top_width
;
1383 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1384 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1386 /* setup the frame descriptor */
1387 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1388 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1389 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1391 XLowerWindow(dpy
, window
);
1392 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1394 /* setup stacking descriptor */
1395 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1397 tmp
= wWindowFor(wwin
->transient_for
);
1399 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1401 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1404 if (!scr
->focused_window
) {
1405 /* first window on the list */
1408 scr
->focused_window
= wwin
;
1412 /* add window at beginning of focus window list */
1413 tmp
= scr
->focused_window
;
1421 if (wwin
->flags
.is_gnustep
== 0)
1422 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1424 /* if (wPreferences.auto_focus) */
1425 wSetFocusTo(scr
, wwin
);
1426 wWindowResetMouseGrabs(wwin
);
1427 wWindowSetKeyGrabs(wwin
);
1433 *----------------------------------------------------------------------
1435 * Removes the frame window from a window and destroys all data
1436 * related to it. The window will be reparented back to the root window
1437 * if restore is True.
1440 * Everything related to the window is destroyed and the window
1441 * is removed from the window lists. Focus is set to the previous on the
1443 *----------------------------------------------------------------------
1445 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1447 WCoreWindow
*frame
= wwin
->frame
->core
;
1448 WWindow
*owner
= NULL
;
1449 WWindow
*newFocusedWindow
= NULL
;
1451 WScreen
*scr
= wwin
->screen_ptr
;
1453 /* First close attribute editor window if open */
1454 if (wwin
->flags
.inspector_open
)
1455 wCloseInspectorForWindow(wwin
);
1457 /* Close window menu if it's open for this window */
1458 if (wwin
->flags
.menu_open_for_me
)
1459 CloseWindowMenu(scr
);
1462 if (!wwin
->flags
.internal_window
)
1463 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1465 /* If this is a leader window, we still need to listen for
1466 * DestroyNotify and PropertyNotify. */
1467 if (wApplicationOf(wwin
->client_win
))
1468 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1470 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1472 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1473 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1476 XUnmapWindow(dpy
, frame
->window
);
1478 XUnmapWindow(dpy
, wwin
->client_win
);
1480 /* deselect window */
1481 wSelectWindow(wwin
, False
);
1483 /* remove all pending events on window */
1484 /* I think this only matters for autoraise */
1485 if (wPreferences
.raise_delay
)
1486 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1490 /* reparent the window back to the root */
1492 wClientRestore(wwin
);
1494 if (wwin
->transient_for
!= scr
->root_win
) {
1495 owner
= wWindowFor(wwin
->transient_for
);
1497 if (!owner
->flags
.semi_focused
)
1500 owner
->flags
.semi_focused
= 0;
1504 wasFocused
= wwin
->flags
.focused
;
1506 /* remove from window focus list */
1507 if (!wwin
->prev
&& !wwin
->next
) {
1508 /* was the only window */
1509 scr
->focused_window
= NULL
;
1510 newFocusedWindow
= NULL
;
1515 wwin
->prev
->next
= wwin
->next
;
1518 wwin
->next
->prev
= wwin
->prev
;
1520 scr
->focused_window
= wwin
->prev
;
1521 scr
->focused_window
->next
= NULL
;
1524 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1526 /* if in click to focus mode and the window
1527 * was a transient, focus the owner window
1530 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1531 tmp
= wWindowFor(wwin
->transient_for
);
1532 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1536 /* otherwise, focus the next one in the focus list */
1538 tmp
= scr
->focused_window
;
1539 while (tmp
) { /* look for one in the window list first */
1540 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1541 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1545 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1546 tmp
= scr
->focused_window
;
1548 if (!WFLAGP(tmp
, no_focusable
)
1549 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1556 newFocusedWindow
= tmp
;
1558 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1563 /* This is to let the root window get the keyboard input
1564 * if Sloppy focus mode and no other window get focus.
1565 * This way keybindings will not freeze.
1568 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1569 tmp
= wWindowFor(win
);
1572 newFocusedWindow
= tmp
;
1574 newFocusedWindow
= NULL
;
1578 if (!wwin
->flags
.internal_window
)
1579 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1581 if (newFocusedWindow
!= owner
&& owner
) {
1582 if (wwin
->flags
.is_gnustep
== 0)
1583 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1585 wSetFocusTo(scr
, newFocusedWindow
);
1588 /* Close menu and unhighlight */
1589 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1590 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1591 if (oapp
&& oapp
!= napp
) {
1592 wAppMenuUnmap(oapp
->menu
);
1593 if (wPreferences
.highlight_active_app
)
1594 wApplicationDeactivate(oapp
);
1597 wNETCleanupFrameExtents(wwin
);
1599 wWindowDestroy(wwin
);
1603 void wWindowMap(WWindow
*wwin
)
1605 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1606 if (!wwin
->flags
.shaded
) {
1607 /* window will be remapped when getting MapNotify */
1608 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1609 XMapWindow(dpy
, wwin
->client_win
);
1610 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1612 wwin
->flags
.mapped
= 1;
1616 void wWindowUnmap(WWindow
*wwin
)
1618 wwin
->flags
.mapped
= 0;
1620 /* prevent window withdrawal when getting UnmapNotify */
1621 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1622 XUnmapWindow(dpy
, wwin
->client_win
);
1623 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1625 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1628 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1633 #ifdef KEEP_XKB_LOCK_STATUS
1634 if (wPreferences
.modelock
)
1635 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1636 #endif /* KEEP_XKB_LOCK_STATUS */
1638 wwin
->flags
.semi_focused
= 0;
1640 if (wwin
->flags
.is_gnustep
== 0)
1641 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1643 wwin
->flags
.focused
= 1;
1645 wWindowResetMouseGrabs(wwin
);
1647 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1649 if (owin
== wwin
|| !owin
)
1652 nowner
= wWindowFor(wwin
->transient_for
);
1654 /* new window is a transient for the old window */
1655 if (nowner
== owin
) {
1656 owin
->flags
.semi_focused
= 1;
1657 wWindowUnfocus(nowner
);
1661 oowner
= wWindowFor(owin
->transient_for
);
1663 /* new window is owner of old window */
1664 if (wwin
== oowner
) {
1665 wWindowUnfocus(owin
);
1670 wWindowUnfocus(owin
);
1674 /* new window has same owner of old window */
1675 if (oowner
== nowner
) {
1676 /* prevent unfocusing of owner */
1677 oowner
->flags
.semi_focused
= 0;
1678 wWindowUnfocus(owin
);
1679 oowner
->flags
.semi_focused
= 1;
1684 /* nowner != NULL && oowner != nowner */
1685 nowner
->flags
.semi_focused
= 1;
1686 wWindowUnfocus(nowner
);
1687 wWindowUnfocus(owin
);
1690 void wWindowUnfocus(WWindow
*wwin
)
1692 CloseWindowMenu(wwin
->screen_ptr
);
1694 if (wwin
->flags
.is_gnustep
== 0)
1695 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1697 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1699 owner
= wWindowFor(wwin
->transient_for
);
1700 if (owner
&& owner
->flags
.semi_focused
) {
1701 owner
->flags
.semi_focused
= 0;
1702 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1703 wWindowUnfocus(owner
);
1704 wFrameWindowPaint(owner
->frame
);
1708 wwin
->flags
.focused
= 0;
1709 wWindowResetMouseGrabs(wwin
);
1710 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1713 void wWindowUpdateName(WWindow
*wwin
, const char *newTitle
)
1721 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1725 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1726 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1730 *----------------------------------------------------------------------
1732 * wWindowConstrainSize--
1733 * Constrains size for the client window, taking the maximal size,
1734 * window resize increments and other size hints into account.
1737 * The closest size to what was given that the client window can
1740 *----------------------------------------------------------------------
1742 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1744 int width
= (int)*nwidth
;
1745 int height
= (int)*nheight
;
1748 int minW
= 1, minH
= 1;
1749 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1750 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1751 int minAX
= -1, minAY
= -1;
1752 int maxAX
= -1, maxAY
= -1;
1756 if (wwin
->normal_hints
) {
1757 winc
= wwin
->normal_hints
->width_inc
;
1758 hinc
= wwin
->normal_hints
->height_inc
;
1759 minW
= wwin
->normal_hints
->min_width
;
1760 minH
= wwin
->normal_hints
->min_height
;
1761 maxW
= wwin
->normal_hints
->max_width
;
1762 maxH
= wwin
->normal_hints
->max_height
;
1763 if (wwin
->normal_hints
->flags
& PAspect
) {
1764 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1765 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1766 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1767 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1770 baseW
= wwin
->normal_hints
->base_width
;
1771 baseH
= wwin
->normal_hints
->base_height
;
1784 /* aspect ratio code borrowed from olwm */
1786 /* adjust max aspect ratio */
1787 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1788 if (maxAX
> maxAY
) {
1789 height
= (width
* maxAY
) / maxAX
;
1790 if (height
> maxH
) {
1792 width
= (height
* maxAX
) / maxAY
;
1795 width
= (height
* maxAX
) / maxAY
;
1798 height
= (width
* maxAY
) / maxAX
;
1803 /* adjust min aspect ratio */
1804 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1805 if (minAX
> minAY
) {
1806 height
= (width
* minAY
) / minAX
;
1807 if (height
< minH
) {
1809 width
= (height
* minAX
) / minAY
;
1812 width
= (height
* minAX
) / minAY
;
1815 height
= (width
* minAY
) / minAX
;
1822 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1824 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1827 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1829 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1831 /* broken stupid apps may cause preposterous values for these.. */
1838 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1839 unsigned int *width
, unsigned int *height
)
1841 int baseW
= 0, baseH
= 0;
1842 int winc
= 1, hinc
= 1;
1844 if (wwin
->normal_hints
) {
1845 baseW
= wwin
->normal_hints
->base_width
;
1846 baseH
= wwin
->normal_hints
->base_height
;
1848 winc
= wwin
->normal_hints
->width_inc
;
1849 hinc
= wwin
->normal_hints
->height_inc
;
1853 *width
= maxW
- (maxW
- baseW
) % winc
;
1856 *height
= maxH
- (maxH
- baseH
) % hinc
;
1859 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1861 WScreen
*scr
= wwin
->screen_ptr
;
1865 if (workspace
>= w_global
.workspace
.count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1868 if (workspace
!= w_global
.workspace
.current
) {
1869 /* Sent to other workspace. Unmap window */
1870 if ((wwin
->flags
.mapped
1871 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1872 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1874 wapp
= wApplicationOf(wwin
->main_window
);
1876 wapp
->last_workspace
= workspace
;
1878 if (wwin
->flags
.miniaturized
) {
1880 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1881 wwin
->icon
->mapped
= 0;
1885 wSetFocusTo(scr
, NULL
);
1889 /* brought to current workspace. Map window */
1890 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1892 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1893 wwin
->icon
->mapped
= 1;
1895 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1899 if (!IS_OMNIPRESENT(wwin
)) {
1900 int oldWorkspace
= wwin
->frame
->workspace
;
1901 wwin
->frame
->workspace
= workspace
;
1902 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1909 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
1911 WScreen
*scr
= wwin
->screen_ptr
;
1912 int w
= w_global
.workspace
.current
+ amount
;
1916 wWindowChangeWorkspace(wwin
, w
);
1917 } else if (wPreferences
.ws_cycle
) {
1918 wWindowChangeWorkspace(wwin
, w_global
.workspace
.count
+ w
);
1920 } else if (amount
> 0) {
1921 if (w
< w_global
.workspace
.count
) {
1922 wWindowChangeWorkspace(wwin
, w
);
1923 } else if (wPreferences
.ws_advance
) {
1924 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
1925 wWorkspaceMake(scr
, workspace
);
1926 wWindowChangeWorkspace(wwin
, workspace
);
1927 } else if (wPreferences
.ws_cycle
) {
1928 wWindowChangeWorkspace(wwin
, w
% w_global
.workspace
.count
);
1933 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1937 sevent
.type
= ConfigureNotify
;
1938 sevent
.xconfigure
.display
= dpy
;
1939 sevent
.xconfigure
.event
= wwin
->client_win
;
1940 sevent
.xconfigure
.window
= wwin
->client_win
;
1942 sevent
.xconfigure
.x
= wwin
->client
.x
;
1943 sevent
.xconfigure
.y
= wwin
->client
.y
;
1944 sevent
.xconfigure
.width
= wwin
->client
.width
;
1945 sevent
.xconfigure
.height
= wwin
->client
.height
;
1947 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1948 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1949 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1951 sevent
.xconfigure
.above
= None
;
1953 sevent
.xconfigure
.override_redirect
= False
;
1954 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1959 *----------------------------------------------------------------------
1960 * wWindowConfigure()
1962 * req_x, req_y: new requested positions for the frame
1963 * req_width, req_height: new requested sizes for the client
1965 * Configures the frame, decorations and client window to the specified
1966 * geometry, whose validity is not checked -- wWindowConstrainSize()
1967 * must be used for that.
1968 * The size parameters are for the client window, but the position is
1970 * The client window receives a ConfigureNotify event, according
1971 * to what ICCCM says.
1977 * Window size and position are changed and client window receives
1978 * a ConfigureNotify event.
1979 *----------------------------------------------------------------------
1981 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1983 int synth_notify
= False
;
1986 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1988 * if the window is being moved but not resized then
1989 * send a synthetic ConfigureNotify
1991 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
1992 synth_notify
= True
;
1994 if (WFLAGP(wwin
, dont_move_off
))
1995 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
1998 if (req_width
< MIN_WINDOW_SIZE
)
1999 req_width
= MIN_WINDOW_SIZE
;
2000 if (req_height
< MIN_WINDOW_SIZE
)
2001 req_height
= MIN_WINDOW_SIZE
;
2003 /* If growing, resize inner part before frame,
2004 * if shrinking, resize frame before.
2005 * This will prevent the frame (that can have a different color)
2006 * to be exposed, causing flicker */
2007 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2008 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2010 if (wwin
->flags
.shaded
) {
2011 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2012 wwin
->old_geometry
.height
= req_height
;
2016 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2018 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2021 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2022 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2024 wwin
->client
.x
= req_x
;
2025 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2026 wwin
->client
.width
= req_width
;
2027 wwin
->client
.height
= req_height
;
2029 wwin
->client
.x
= req_x
;
2030 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2032 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2034 wwin
->frame_x
= req_x
;
2035 wwin
->frame_y
= req_y
;
2036 if (HAS_BORDER(wwin
)) {
2037 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2038 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2041 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
&& resize
)
2042 wWindowSetShape(wwin
);
2046 wWindowSynthConfigureNotify(wwin
);
2048 wNETFrameExtents(wwin
);
2053 /* req_x, req_y: new position of the frame */
2054 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2056 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2057 int synth_notify
= False
;
2059 /* Send a synthetic ConfigureNotify event for every window movement. */
2060 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2061 synth_notify
= True
;
2063 /* A single synthetic ConfigureNotify event is sent at the end of
2064 * a completed (opaque) movement in moveres.c */
2067 if (WFLAGP(wwin
, dont_move_off
))
2068 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2069 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2071 wwin
->client
.x
= req_x
;
2072 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2073 if (HAS_BORDER(wwin
)) {
2074 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2075 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2078 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2080 wwin
->frame_x
= req_x
;
2081 wwin
->frame_y
= req_y
;
2083 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2085 wWindowSynthConfigureNotify(wwin
);
2089 void wWindowUpdateButtonImages(WWindow
*wwin
)
2091 WScreen
*scr
= wwin
->screen_ptr
;
2092 Pixmap pixmap
, mask
;
2093 WFrameWindow
*fwin
= wwin
->frame
;
2095 if (!HAS_TITLEBAR(wwin
))
2098 /* miniaturize button */
2099 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2100 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2101 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2103 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2104 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2108 if (fwin
->lbutton_image
2109 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2110 wPixmapDestroy(fwin
->lbutton_image
);
2111 fwin
->lbutton_image
= NULL
;
2114 if (!fwin
->lbutton_image
) {
2115 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2116 fwin
->lbutton_image
->client_owned
= 1;
2117 fwin
->lbutton_image
->client_owned_mask
= 1;
2120 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2121 wPixmapDestroy(fwin
->lbutton_image
);
2123 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2126 #ifdef XKB_BUTTON_HINT
2127 if (!WFLAGP(wwin
, no_language_button
)) {
2128 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2129 wPixmapDestroy(fwin
->languagebutton_image
);
2131 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2137 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2138 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2140 if (!WFLAGP(wwin
, no_close_button
)) {
2141 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2142 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2144 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2145 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2149 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2150 || fwin
->rbutton_image
->mask
!= mask
)) {
2151 wPixmapDestroy(fwin
->rbutton_image
);
2152 fwin
->rbutton_image
= NULL
;
2155 if (!fwin
->rbutton_image
) {
2156 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2157 fwin
->rbutton_image
->client_owned
= 1;
2158 fwin
->rbutton_image
->client_owned_mask
= 1;
2161 } else if (WFLAGP(wwin
, kill_close
)) {
2162 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2163 wPixmapDestroy(fwin
->rbutton_image
);
2165 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2167 } else if (MGFLAGP(wwin
, broken_close
)) {
2168 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2169 wPixmapDestroy(fwin
->rbutton_image
);
2171 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2174 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2175 wPixmapDestroy(fwin
->rbutton_image
);
2177 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2181 /* force buttons to be redrawn */
2182 fwin
->flags
.need_texture_change
= 1;
2183 wFrameWindowPaint(fwin
);
2187 *---------------------------------------------------------------------------
2188 * wWindowConfigureBorders--
2189 * Update window border configuration according to attribute flags.
2191 *---------------------------------------------------------------------------
2193 void wWindowConfigureBorders(WWindow
*wwin
)
2199 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2201 #ifdef XKB_BUTTON_HINT
2202 if (wPreferences
.modelock
)
2203 flags
|= WFF_LANGUAGE_BUTTON
;
2206 if (HAS_TITLEBAR(wwin
))
2207 flags
|= WFF_TITLEBAR
;
2208 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2209 flags
|= WFF_RESIZEBAR
;
2210 if (HAS_BORDER(wwin
))
2211 flags
|= WFF_BORDER
;
2212 if (wwin
->flags
.shaded
)
2213 flags
|= WFF_IS_SHADED
;
2214 if (wwin
->flags
.selected
)
2215 flags
|= WFF_SELECTED
;
2217 oldh
= wwin
->frame
->top_width
;
2218 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2219 if (oldh
!= wwin
->frame
->top_width
) {
2220 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2222 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2223 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2227 if (!WFLAGP(wwin
, no_miniaturize_button
)
2228 && wwin
->frame
->flags
.hide_left_button
)
2229 flags
|= WFF_LEFT_BUTTON
;
2231 #ifdef XKB_BUTTON_HINT
2232 if (!WFLAGP(wwin
, no_language_button
)
2233 && wwin
->frame
->flags
.hide_language_button
)
2234 flags
|= WFF_LANGUAGE_BUTTON
;
2237 if (!WFLAGP(wwin
, no_close_button
)
2238 && wwin
->frame
->flags
.hide_right_button
)
2239 flags
|= WFF_RIGHT_BUTTON
;
2242 wWindowUpdateButtonImages(wwin
);
2243 wFrameWindowShowButton(wwin
->frame
, flags
);
2247 if (WFLAGP(wwin
, no_miniaturize_button
)
2248 && !wwin
->frame
->flags
.hide_left_button
)
2249 flags
|= WFF_LEFT_BUTTON
;
2251 #ifdef XKB_BUTTON_HINT
2252 if (WFLAGP(wwin
, no_language_button
)
2253 && !wwin
->frame
->flags
.hide_language_button
)
2254 flags
|= WFF_LANGUAGE_BUTTON
;
2257 if (WFLAGP(wwin
, no_close_button
)
2258 && !wwin
->frame
->flags
.hide_right_button
)
2259 flags
|= WFF_RIGHT_BUTTON
;
2262 wFrameWindowHideButton(wwin
->frame
, flags
);
2265 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
)
2266 wWindowSetShape(wwin
);
2271 void wWindowSaveState(WWindow
*wwin
)
2276 memset(data
, 0, sizeof(long) * 10);
2277 data
[0] = wwin
->frame
->workspace
;
2278 data
[1] = wwin
->flags
.miniaturized
;
2279 data
[2] = wwin
->flags
.shaded
;
2280 data
[3] = wwin
->flags
.hidden
;
2281 data
[4] = wwin
->flags
.maximized
;
2282 if (wwin
->flags
.maximized
== 0) {
2283 data
[5] = wwin
->frame_x
;
2284 data
[6] = wwin
->frame_y
;
2285 data
[7] = wwin
->frame
->core
->width
;
2286 data
[8] = wwin
->frame
->core
->height
;
2288 data
[5] = wwin
->old_geometry
.x
;
2289 data
[6] = wwin
->old_geometry
.y
;
2290 data
[7] = wwin
->old_geometry
.width
;
2291 data
[8] = wwin
->old_geometry
.height
;
2294 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2295 if (w_global
.shortcut
.windows
[i
] &&
2296 WMCountInArray(w_global
.shortcut
.windows
[i
], wwin
))
2300 XChangeProperty(dpy
, wwin
->client_win
, w_global
.atom
.wmaker
.state
,
2301 w_global
.atom
.wmaker
.state
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2304 static int getSavedState(Window window
, WSavedState
** state
)
2308 unsigned long nitems_ret
;
2309 unsigned long bytes_after_ret
;
2312 if (XGetWindowProperty(dpy
, window
, w_global
.atom
.wmaker
.state
, 0, 10,
2313 True
, w_global
.atom
.wmaker
.state
,
2314 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2315 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2318 *state
= wmalloc(sizeof(WSavedState
));
2320 (*state
)->workspace
= data
[0];
2321 (*state
)->miniaturized
= data
[1];
2322 (*state
)->shaded
= data
[2];
2323 (*state
)->hidden
= data
[3];
2324 (*state
)->maximized
= data
[4];
2325 (*state
)->x
= data
[5];
2326 (*state
)->y
= data
[6];
2327 (*state
)->w
= data
[7];
2328 (*state
)->h
= data
[8];
2329 (*state
)->window_shortcuts
= data
[9];
2333 if (*state
&& type_ret
== w_global
.atom
.wmaker
.state
)
2340 void wWindowClearShape(WWindow
* wwin
)
2342 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2343 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2347 void wWindowSetShape(WWindow
* wwin
)
2351 #ifdef OPTIMIZE_SHAPE
2356 /* only shape is the client's */
2357 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2360 /* Get array of rectangles describing the shape mask */
2361 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2365 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2371 /* insert our decoration rectangles in the rect list */
2372 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2375 if (HAS_TITLEBAR(wwin
)) {
2377 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2378 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2379 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2382 if (HAS_RESIZEBAR(wwin
)) {
2384 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2385 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2386 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2390 /* shape our frame window */
2391 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2392 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2398 #endif /* OPTIMIZE_SHAPE */
2400 if (HAS_TITLEBAR(wwin
)) {
2403 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2404 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2407 if (HAS_RESIZEBAR(wwin
)) {
2409 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2410 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2411 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2415 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2416 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2418 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2419 0, wwin
->frame
->top_width
, wwin
->client_win
,
2420 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2425 /* ====================================================================== */
2427 static FocusMode
getFocusMode(WWindow
* wwin
)
2431 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2432 if (wwin
->wm_hints
->input
== True
) {
2433 if (wwin
->protocols
.TAKE_FOCUS
)
2434 mode
= WFM_LOCALLY_ACTIVE
;
2438 if (wwin
->protocols
.TAKE_FOCUS
)
2439 mode
= WFM_GLOBALLY_ACTIVE
;
2441 mode
= WFM_NO_INPUT
;
2449 void wWindowSetKeyGrabs(WWindow
* wwin
)
2454 for (i
= 0; i
< WKBD_LAST
; i
++) {
2455 key
= &wKeyBindings
[i
];
2457 if (key
->keycode
== 0)
2459 if (key
->modifier
!= AnyModifier
) {
2460 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2461 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2463 /* Also grab all modifier combinations possible that include,
2464 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2465 * work even if the NumLock/ScrollLock key is on.
2467 wHackedGrabKey(key
->keycode
, key
->modifier
,
2468 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2471 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2472 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2475 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2478 void wWindowResetMouseGrabs(WWindow
* wwin
)
2480 /* Mouse grabs can't be done on the client window because of
2481 * ICCCM and because clients that try to do the same will crash.
2483 * But there is a problem wich makes tbar buttons of unfocused
2484 * windows not usable as the click goes to the frame window instead
2485 * of the button itself. Must figure a way to fix that.
2488 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2490 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2491 /* grabs for Meta+drag */
2492 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2493 True
, ButtonPressMask
| ButtonReleaseMask
,
2494 GrabModeSync
, GrabModeAsync
, None
, None
);
2496 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2497 * but we only grab it for Button4 and Button 5 since a lot of apps
2498 * use CTRL+Button1-3 for app related functionality
2500 if (wPreferences
.resize_increment
> 0) {
2501 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2502 True
, ButtonPressMask
| ButtonReleaseMask
,
2503 GrabModeSync
, GrabModeAsync
, None
, None
);
2504 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2505 True
, ButtonPressMask
| ButtonReleaseMask
,
2506 GrabModeSync
, GrabModeAsync
, None
, None
);
2508 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2509 True
, ButtonPressMask
| ButtonReleaseMask
,
2510 GrabModeSync
, GrabModeAsync
, None
, None
);
2511 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2512 True
, ButtonPressMask
| ButtonReleaseMask
,
2513 GrabModeSync
, GrabModeAsync
, None
, None
);
2517 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2518 && !wwin
->flags
.is_gnustep
) {
2519 /* the passive grabs to focus the window */
2520 /* if (wPreferences.focus_mode == WKF_CLICK) */
2521 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2522 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2527 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2529 if (attr
->flags
& GSExtraFlagsAttr
) {
2530 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2531 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2532 wWindowUpdateButtonImages(wwin
);
2537 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2538 const char *command
, pid_t pid
, WSavedState
* state
)
2540 WWindowState
*wstate
;
2542 wstate
= malloc(sizeof(WWindowState
));
2546 memset(wstate
, 0, sizeof(WWindowState
));
2549 wstate
->instance
= wstrdup(instance
);
2551 wstate
->class = wstrdup(class);
2553 wstate
->command
= wstrdup(command
);
2554 wstate
->state
= state
;
2556 wstate
->next
= windowState
;
2557 windowState
= wstate
;
2562 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2564 WMagicNumber
wWindowGetSavedState(Window win
)
2566 char *instance
, *class, *command
= NULL
;
2567 WWindowState
*wstate
= windowState
;
2572 command
= GetCommandForWindow(win
);
2576 if (PropGetWMClass(win
, &class, &instance
)) {
2578 if (SAME(instance
, wstate
->instance
) &&
2579 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2582 wstate
= wstate
->next
;
2598 void wWindowDeleteSavedState(WMagicNumber id
)
2600 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2602 if (!wstate
|| !windowState
)
2606 if (tmp
== wstate
) {
2607 windowState
= wstate
->next
;
2608 release_wwindowstate(wstate
);
2611 if (tmp
->next
== wstate
) {
2612 tmp
->next
= wstate
->next
;
2613 release_wwindowstate(wstate
);
2621 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2623 WWindowState
*tmp
, *wstate
;
2629 if (tmp
->pid
== pid
) {
2630 wstate
= windowState
;
2631 windowState
= tmp
->next
;
2633 release_wwindowstate(wstate
);
2636 if (tmp
->next
->pid
== pid
) {
2638 tmp
->next
= wstate
->next
;
2639 release_wwindowstate(wstate
);
2647 static void release_wwindowstate(WWindowState
*wstate
)
2649 if (wstate
->instance
)
2650 wfree(wstate
->instance
);
2653 wfree(wstate
->class);
2655 if (wstate
->command
)
2656 wfree(wstate
->command
);
2658 wfree(wstate
->state
);
2662 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2664 if (wwin
->flags
.omnipresent
== flag
)
2667 wwin
->flags
.omnipresent
= flag
;
2668 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2671 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2673 WWindow
*wwin
= data
;
2675 #ifndef NUMLOCK_HACK
2676 if ((event
->xbutton
.state
& ValidModMask
)
2677 != (event
->xbutton
.state
& ~LockMask
)) {
2678 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2679 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2683 event
->xbutton
.state
&= ValidModMask
;
2685 CloseWindowMenu(wwin
->screen_ptr
);
2687 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2688 && !WFLAGP(wwin
, no_focusable
)) {
2689 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2692 if (event
->xbutton
.button
== Button1
)
2693 wRaiseFrame(wwin
->frame
->core
);
2695 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2696 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2697 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2698 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2703 if (event
->xbutton
.state
& MOD_MASK
) {
2704 /* move the window */
2705 wMouseMoveWindow(wwin
, event
);
2706 XUngrabPointer(dpy
, CurrentTime
);
2708 wMouseResizeWindow(wwin
, event
);
2709 XUngrabPointer(dpy
, CurrentTime
);
2713 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2715 WWindow
*wwin
= data
;
2717 event
->xbutton
.state
&= ValidModMask
;
2719 if (event
->xbutton
.button
== Button1
) {
2720 if (event
->xbutton
.state
== 0) {
2721 if (!WFLAGP(wwin
, no_shadeable
)) {
2723 if (wwin
->flags
.shaded
)
2724 wUnshadeWindow(wwin
);
2731 if (event
->xbutton
.state
& ControlMask
)
2732 dir
|= MAX_VERTICAL
;
2734 if (event
->xbutton
.state
& ShiftMask
) {
2735 dir
|= MAX_HORIZONTAL
;
2736 if (!(event
->xbutton
.state
& ControlMask
))
2737 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2740 /* maximize window */
2741 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2742 int ndir
= dir
^ wwin
->flags
.maximized
;
2745 wMaximizeWindow(wwin
, ndir
);
2747 wUnmaximizeWindow(wwin
);
2750 } else if (event
->xbutton
.button
== Button3
) {
2751 if (event
->xbutton
.state
& MOD_MASK
)
2752 wHideOtherApplications(wwin
);
2753 } else if (event
->xbutton
.button
== Button2
) {
2754 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2755 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2757 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2758 wUnshadeWindow(wwin
);
2762 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2764 WWindow
*wwin
= desc
->parent
;
2765 unsigned int new_width
, w_scale
;
2766 unsigned int new_height
, h_scale
;
2767 unsigned int resize_width_increment
= 0;
2768 unsigned int resize_height_increment
= 0;
2770 if (wwin
->normal_hints
) {
2771 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2772 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2773 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2774 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2776 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2777 resize_width_increment
= wPreferences
.resize_increment
;
2778 resize_height_increment
= wPreferences
.resize_increment
;
2781 event
->xbutton
.state
&= ValidModMask
;
2783 CloseWindowMenu(wwin
->screen_ptr
);
2785 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2786 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2788 if (event
->xbutton
.button
== Button1
)
2789 wRaiseFrame(wwin
->frame
->core
);
2791 if (event
->xbutton
.state
& ControlMask
) {
2792 if (event
->xbutton
.button
== Button4
) {
2793 new_width
= wwin
->client
.width
- resize_width_increment
;
2794 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2795 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2797 if (event
->xbutton
.button
== Button5
) {
2798 new_width
= wwin
->client
.width
+ resize_width_increment
;
2799 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2800 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2804 if (event
->xbutton
.state
& MOD_MASK
) {
2805 /* move the window */
2806 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2807 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2808 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2811 if (event
->xbutton
.button
== Button3
) {
2812 wMouseResizeWindow(wwin
, event
);
2813 } else if (event
->xbutton
.button
== Button4
) {
2814 new_height
= wwin
->client
.height
- resize_height_increment
;
2815 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2816 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2817 } else if (event
->xbutton
.button
== Button5
) {
2818 new_height
= wwin
->client
.height
+ resize_height_increment
;
2819 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2820 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2821 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2822 wMouseMoveWindow(wwin
, event
);
2824 XUngrabPointer(dpy
, CurrentTime
);
2828 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2830 WWindow
*wwin
= (WWindow
*) data
;
2832 #ifndef NUMLOCK_HACK
2833 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2834 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2835 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2837 event
->xbutton
.state
&= ValidModMask
;
2839 CloseWindowMenu(wwin
->screen_ptr
);
2841 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2842 && !WFLAGP(wwin
, no_focusable
))
2843 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2845 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2847 if (event
->xbutton
.button
== Button1
) {
2848 if (event
->xbutton
.state
& MOD_MASK
)
2849 wLowerFrame(wwin
->frame
->core
);
2851 wRaiseFrame(wwin
->frame
->core
);
2853 if ((event
->xbutton
.state
& ShiftMask
)
2854 && !(event
->xbutton
.state
& ControlMask
)) {
2855 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2858 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2859 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2860 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2861 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2865 /* move the window */
2866 wMouseMoveWindow(wwin
, event
);
2868 XUngrabPointer(dpy
, CurrentTime
);
2869 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2870 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2871 WObjDescriptor
*desc
;
2873 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2874 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2875 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2876 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2880 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2882 /* allow drag select */
2883 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2884 event
->xany
.send_event
= True
;
2885 (*desc
->handle_mousedown
) (desc
, event
);
2887 XUngrabPointer(dpy
, CurrentTime
);
2891 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2893 WWindow
*wwin
= data
;
2895 event
->xbutton
.state
&= ValidModMask
;
2897 CloseWindowMenu(wwin
->screen_ptr
);
2899 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2902 /* if control-click, kill the client */
2903 if (event
->xbutton
.state
& ControlMask
) {
2906 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2907 /* send delete message */
2908 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
2909 w_global
.timestamp
.last_event
);
2914 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2916 WWindow
*wwin
= data
;
2918 CloseWindowMenu(wwin
->screen_ptr
);
2920 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2923 /* send delete message */
2924 if (wwin
->protocols
.DELETE_WINDOW
)
2925 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
2926 w_global
.timestamp
.last_event
);
2931 #ifdef XKB_BUTTON_HINT
2932 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2934 WWindow
*wwin
= data
;
2935 WFrameWindow
*fwin
= wwin
->frame
;
2936 WScreen
*scr
= fwin
->screen_ptr
;
2939 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2941 tl
= wwin
->frame
->languagemode
;
2942 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2943 wwin
->frame
->last_languagemode
= tl
;
2944 wSetFocusTo(scr
, wwin
);
2945 wwin
->frame
->languagebutton_image
=
2946 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2947 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2948 if (event
->xbutton
.button
== Button3
)
2950 wRaiseFrame(fwin
->core
);
2954 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2956 WWindow
*wwin
= data
;
2958 event
->xbutton
.state
&= ValidModMask
;
2960 CloseWindowMenu(wwin
->screen_ptr
);
2962 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2965 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2966 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
2967 w_global
.timestamp
.last_event
);
2970 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2972 wapp
= wApplicationOf(wwin
->main_window
);
2973 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2974 wHideApplication(wapp
);
2975 } else if (event
->xbutton
.state
== 0) {
2976 wIconifyWindow(wwin
);