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/WINGsP.h>
41 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
57 #include "workspace.h"
61 #include "superfluous.h"
69 #define MOD_MASK wPreferences.modifier_mask
71 /****** Global Variables ******/
72 extern WShortKey wKeyBindings
[WKBD_LAST
];
75 extern Bool wShapeSupported
;
79 extern XContext wWinContext
;
82 extern Atom _XA_WM_DELETE_WINDOW
;
83 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
84 extern Atom _XA_WINDOWMAKER_STATE
;
85 extern WPreferences wPreferences
;
86 extern Time LastTimestamp
;
88 /***** Local Stuff *****/
89 static WWindowState
*windowState
= NULL
;
90 static FocusMode
getFocusMode(WWindow
*wwin
);
91 static int getSavedState(Window window
, WSavedState
**state
);
92 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
94 /* frame window (during window grabs) */
95 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
98 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
99 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
104 #ifdef XKB_BUTTON_HINT
105 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
109 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
110 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
112 /****** Notification Observers ******/
114 static void appearanceObserver(void *self
, WMNotification
* notif
)
116 WWindow
*wwin
= (WWindow
*) self
;
117 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
119 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
122 if (flags
& WFontSettings
) {
123 wWindowConfigureBorders(wwin
);
124 if (wwin
->flags
.shaded
) {
125 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
126 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
127 wWindowSynthConfigureNotify(wwin
);
130 if (flags
& WTextureSettings
)
131 wwin
->frame
->flags
.need_texture_remake
= 1;
133 if (flags
& (WTextureSettings
| WColorSettings
)) {
134 if (wwin
->frame
->titlebar
)
135 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
137 wFrameWindowPaint(wwin
->frame
);
142 WWindow
*wWindowFor(Window window
)
144 WObjDescriptor
*desc
;
149 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
152 if (desc
->parent_type
== WCLASS_WINDOW
)
154 else if (desc
->parent_type
== WCLASS_FRAME
) {
155 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
156 if (frame
->flags
.is_client_window_frame
)
163 WWindow
*wWindowCreate(void)
167 wwin
= wmalloc(sizeof(WWindow
));
170 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
171 wwin
->client_descriptor
.parent
= wwin
;
172 wwin
->client_descriptor
.self
= wwin
;
173 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
178 void wWindowDestroy(WWindow
*wwin
)
182 if (wwin
->screen_ptr
->cmap_window
== wwin
)
183 wwin
->screen_ptr
->cmap_window
= NULL
;
185 WMRemoveNotificationObserver(wwin
);
187 wwin
->flags
.destroyed
= 1;
189 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
190 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
193 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
195 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
196 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
197 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
201 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
202 wwin
->fake_group
->retainCount
--;
203 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
204 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
205 wwin
->fake_group
->leader
= None
;
206 wwin
->fake_group
->origLeader
= None
;
211 if (wwin
->normal_hints
)
212 XFree(wwin
->normal_hints
);
215 XFree(wwin
->wm_hints
);
217 if (wwin
->wm_instance
)
218 XFree(wwin
->wm_instance
);
221 XFree(wwin
->wm_class
);
223 if (wwin
->wm_gnustep_attr
)
224 wfree(wwin
->wm_gnustep_attr
);
226 if (wwin
->cmap_windows
)
227 XFree(wwin
->cmap_windows
);
229 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
232 wFrameWindowDestroy(wwin
->frame
);
235 RemoveFromStackList(wwin
->icon
->core
);
236 wIconDestroy(wwin
->icon
);
237 if (wPreferences
.auto_arrange_icons
)
238 wArrangeIcons(wwin
->screen_ptr
, True
);
240 if (wwin
->net_icon_image
)
241 RReleaseImage(wwin
->net_icon_image
);
246 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
248 if (gs_hints
->flags
& GSWindowStyleAttr
) {
249 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
250 wwin
->client_flags
.no_border
= 1;
251 wwin
->client_flags
.no_titlebar
= 1;
252 wwin
->client_flags
.no_closable
= 1;
253 wwin
->client_flags
.no_miniaturizable
= 1;
254 wwin
->client_flags
.no_resizable
= 1;
255 wwin
->client_flags
.no_close_button
= 1;
256 wwin
->client_flags
.no_miniaturize_button
= 1;
257 wwin
->client_flags
.no_resizebar
= 1;
259 wwin
->client_flags
.no_close_button
=
260 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
262 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
264 wwin
->client_flags
.no_miniaturize_button
=
265 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
267 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
269 wwin
->client_flags
.no_resizebar
=
270 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
272 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
274 /* these attributes supposedly imply in the existence
276 if (gs_hints
->window_style
& (WMResizableWindowMask
|
277 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
278 wwin
->client_flags
.no_titlebar
= 0;
280 wwin
->client_flags
.no_titlebar
=
281 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
286 /* setup the defaults */
287 wwin
->client_flags
.no_border
= 0;
288 wwin
->client_flags
.no_titlebar
= 0;
289 wwin
->client_flags
.no_closable
= 0;
290 wwin
->client_flags
.no_miniaturizable
= 0;
291 wwin
->client_flags
.no_resizable
= 0;
292 wwin
->client_flags
.no_close_button
= 0;
293 wwin
->client_flags
.no_miniaturize_button
= 0;
294 wwin
->client_flags
.no_resizebar
= 0;
296 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
297 wwin
->client_flags
.no_appicon
= 1;
300 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
302 WScreen
*scr
= wwin
->screen_ptr
;
304 /* sets global default stuff */
305 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
307 * Decoration setting is done in this precedence (lower to higher)
308 * - use global default in the resource database
309 * - guess some settings
310 * - use GNUstep/external window attributes
311 * - set hints specified for the app in the resource DB
314 WSETUFLAG(wwin
, broken_close
, 0);
316 if (wwin
->protocols
.DELETE_WINDOW
)
317 WSETUFLAG(wwin
, kill_close
, 0);
319 WSETUFLAG(wwin
, kill_close
, 1);
321 /* transients can't be iconified or maximized */
322 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
323 WSETUFLAG(wwin
, no_miniaturizable
, 1);
324 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
327 /* if the window can't be resized, remove the resizebar */
328 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
329 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
330 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
331 WSETUFLAG(wwin
, no_resizable
, 1);
332 WSETUFLAG(wwin
, no_resizebar
, 1);
335 /* set GNUstep window attributes */
336 if (wwin
->wm_gnustep_attr
) {
337 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
339 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
341 *level
= wwin
->wm_gnustep_attr
->window_level
;
343 * INT_MIN is the only illegal window level.
345 if (*level
== INT_MIN
)
346 *level
= INT_MIN
+ 1;
349 *level
= WMNormalLevel
;
352 int tmp_workspace
= -1;
353 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
359 wMWMCheckClientHints(wwin
);
360 #endif /* MWM_HINTS */
363 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
365 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
366 * have INT_MIN that means that no window level was requested. -Dan
368 if (tmp_level
== INT_MIN
) {
369 if (WFLAGP(wwin
, floating
))
370 *level
= WMFloatingLevel
;
371 else if (WFLAGP(wwin
, sunken
))
372 *level
= WMSunkenLevel
;
374 *level
= WMNormalLevel
;
379 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
380 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
381 if (transientOwner
) {
382 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
383 if (ownerLevel
> *level
)
388 if (tmp_workspace
>= 0)
389 *workspace
= tmp_workspace
% scr
->workspace_count
;
393 * Set attributes specified only for that window/class.
394 * This might do duplicate work with the 1st wDefaultFillAttributes().
396 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
397 &wwin
->defined_user_flags
, False
);
399 * Sanity checks for attributes that depend on other attributes
401 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
402 wwin
->user_flags
.emulate_appicon
= 0;
404 if (wwin
->main_window
!= None
) {
405 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
406 if (wapp
&& !wapp
->flags
.emulated
)
407 wwin
->user_flags
.emulate_appicon
= 0;
410 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
411 wwin
->user_flags
.emulate_appicon
= 0;
413 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
414 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
415 wwin
->user_flags
.sunken
= 0;
417 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
419 /* windows that have takefocus=False shouldn't take focus at all */
420 if (wwin
->focus_mode
== WFM_NO_INPUT
)
421 wwin
->client_flags
.no_focusable
= 1;
424 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
428 w1
= wwin
->frame
->core
->width
;
429 h1
= wwin
->frame
->core
->height
;
430 w2
= obscured
->frame
->core
->width
;
431 h2
= obscured
->frame
->core
->height
;
433 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
434 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
437 if (wwin
->frame_x
+ w1
< obscured
->frame_x
438 || wwin
->frame_y
+ h1
< obscured
->frame_y
439 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
445 static void fixLeaderProperties(WWindow
*wwin
)
447 XClassHint
*classHint
;
448 XWMHints
*hints
, *clientHints
;
449 XWindowAttributes attr
;
450 Window leaders
[2], window
;
451 char **argv
, *command
;
455 classHint
= XAllocClassHint();
456 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
457 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
459 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
463 leaders
[0] = wwin
->client_leader
;
464 leaders
[1] = wwin
->group_id
;
467 command
= GetCommandForWindow(wwin
->client_win
);
469 wfree(command
); /* command already set. nothing to do. */
471 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
474 for (i
= 0; i
< 2; i
++) {
477 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
478 classHint
->res_name
= wwin
->wm_instance
;
479 classHint
->res_class
= wwin
->wm_class
;
480 XSetClassHint(dpy
, window
, classHint
);
482 hints
= XGetWMHints(dpy
, window
);
485 } else if (clientHints
) {
486 /* set window group leader to self */
487 clientHints
->window_group
= window
;
488 clientHints
->flags
|= WindowGroupHint
;
489 XSetWMHints(dpy
, window
, clientHints
);
493 command
= GetCommandForWindow(window
);
495 wfree(command
); /* command already set. nothing to do. */
497 XSetCommand(dpy
, window
, argv
, argc
);
500 /* Make sure we get notification when this window is destroyed */
501 if (XGetWindowAttributes(dpy
, window
, &attr
))
502 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
513 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
515 XClassHint
*classHint
;
521 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
523 classHint
= XAllocClassHint();
524 classHint
->res_name
= instance
;
525 classHint
->res_class
= class;
526 XSetClassHint(dpy
, leader
, classHint
);
529 /* inherit these from the original leader if available */
530 hints
= XGetWMHints(dpy
, win
);
532 hints
= XAllocWMHints();
535 /* set window group leader to self */
536 hints
->window_group
= leader
;
537 hints
->flags
|= WindowGroupHint
;
538 XSetWMHints(dpy
, leader
, hints
);
541 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
542 XSetCommand(dpy
, leader
, argv
, argc
);
543 XFreeStringList(argv
);
549 static int matchIdentifier(const void *item
, const void *cdata
)
551 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
555 *----------------------------------------------------------------
557 * reparents the window and allocates a descriptor for it.
558 * Window manager hints and other hints are fetched to configure
559 * the window decoration attributes and others. User preferences
560 * for the window are used if available, to configure window
561 * decorations and some behaviour.
562 * If in startup, windows that are override redirect,
563 * unmapped and never were managed and are Withdrawn are not
567 * the new window descriptor
570 * The window is reparented and appropriate notification
571 * is done to the client. Input mask for the window is setup.
572 * The window descriptor is also associated with various window
573 * contexts and inserted in the head of the window list.
574 * Event handler contexts are associated for some objects
575 * (buttons, titlebar and resizebar)
577 *----------------------------------------------------------------
579 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
583 unsigned width
, height
;
584 XWindowAttributes wattribs
;
585 XSetWindowAttributes attribs
;
586 WWindowState
*win_state
;
587 WWindow
*transientOwner
= NULL
;
593 Bool withdraw
= False
;
599 /* make sure the window is still there */
600 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
605 /* if it's an override-redirect, ignore it */
606 if (wattribs
.override_redirect
) {
611 wm_state
= PropGetWindowState(window
);
613 /* if it's startup and the window is unmapped, don't manage it */
614 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
619 wwin
= wWindowCreate();
621 title
= wNETWMGetWindowName(window
);
623 wwin
->flags
.net_has_title
= 1;
624 if (!title
&& !wFetchName(dpy
, window
, &title
))
627 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
630 if (wShapeSupported
) {
635 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
636 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
637 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
638 wwin
->flags
.shaped
= b_shaped
;
643 * Get hints and other information in properties
645 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
647 /* setup descriptor */
648 wwin
->client_win
= window
;
649 wwin
->screen_ptr
= scr
;
650 wwin
->old_border_width
= wattribs
.border_width
;
651 wwin
->event_mask
= CLIENT_EVENTS
;
652 attribs
.event_mask
= CLIENT_EVENTS
;
653 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
654 attribs
.save_under
= False
;
656 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
657 XSetWindowBorderWidth(dpy
, window
, 0);
659 /* get hints from GNUstep app */
660 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
661 wwin
->flags
.is_gnustep
= 1;
663 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
664 wwin
->wm_gnustep_attr
= NULL
;
666 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
667 wwin
->flags
.is_dockapp
= 1;
671 wwin
->client_leader
= PropGetClientLeader(window
);
672 if (wwin
->client_leader
!= None
)
673 wwin
->main_window
= wwin
->client_leader
;
675 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
677 if (wwin
->wm_hints
) {
678 if (wwin
->wm_hints
->flags
& StateHint
) {
680 if (wwin
->wm_hints
->initial_state
== IconicState
) {
681 wwin
->flags
.miniaturized
= 1;
682 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
683 wwin
->flags
.is_dockapp
= 1;
688 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
689 wwin
->group_id
= wwin
->wm_hints
->window_group
;
690 /* window_group has priority over CLIENT_LEADER */
691 wwin
->main_window
= wwin
->group_id
;
693 wwin
->group_id
= None
;
696 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
697 wwin
->flags
.urgent
= 1;
698 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
701 wwin
->group_id
= None
;
704 PropGetProtocols(window
, &wwin
->protocols
);
706 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
707 wwin
->transient_for
= None
;
709 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
710 wwin
->transient_for
= scr
->root_win
;
712 transientOwner
= wWindowFor(wwin
->transient_for
);
713 if (transientOwner
&& transientOwner
->main_window
!= None
)
714 wwin
->main_window
= transientOwner
->main_window
;
718 /* guess the focus mode */
719 wwin
->focus_mode
= getFocusMode(wwin
);
721 /* get geometry stuff */
722 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
724 /* get colormap windows */
725 GetColormapWindows(wwin
);
728 * Setup the decoration/window attributes and
731 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
733 /* Make broken apps behave as a nice app. */
734 if (WFLAGP(wwin
, emulate_appicon
))
735 wwin
->main_window
= wwin
->client_win
;
737 fixLeaderProperties(wwin
);
739 wwin
->orig_main_window
= wwin
->main_window
;
741 if (wwin
->flags
.is_gnustep
)
742 WSETUFLAG(wwin
, shared_appicon
, 0);
744 if (wwin
->main_window
) {
745 extern Atom _XA_WINDOWMAKER_MENU
;
746 XTextProperty text_prop
;
748 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
))
749 WSETUFLAG(wwin
, shared_appicon
, 0);
752 if (wwin
->flags
.is_dockapp
)
753 WSETUFLAG(wwin
, shared_appicon
, 0);
755 if (wwin
->main_window
) {
756 WApplication
*app
= wApplicationOf(wwin
->main_window
);
757 if (app
&& app
->app_icon
)
758 WSETUFLAG(wwin
, shared_appicon
, 0);
761 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
762 char *buffer
, *instance
, *class;
763 WFakeGroupLeader
*fPtr
;
766 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
768 /* // only enter here if PropGetWMClass() succeds */
769 PropGetWMClass(wwin
->main_window
, &class, &instance
);
770 buffer
= StrConcatDot(instance
, class);
772 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
773 if (index
!= WANotFound
) {
774 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
775 if (fPtr
->retainCount
== 0)
776 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
780 if (fPtr
->origLeader
== None
) {
781 if (ADEQUATE(wwin
->main_window
)) {
783 fPtr
->origLeader
= wwin
->main_window
;
786 wwin
->fake_group
= fPtr
;
787 /*wwin->group_id = fPtr->leader; */
788 wwin
->main_window
= fPtr
->leader
;
791 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
793 fPtr
->identifier
= buffer
;
794 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
795 fPtr
->origLeader
= None
;
796 fPtr
->retainCount
= 1;
798 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
800 if (ADEQUATE(wwin
->main_window
)) {
802 fPtr
->origLeader
= wwin
->main_window
;
804 wwin
->fake_group
= fPtr
;
805 /*wwin->group_id = fPtr->leader; */
806 wwin
->main_window
= fPtr
->leader
;
816 * Setup the initial state of the window
818 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
819 wwin
->flags
.miniaturized
= 1;
821 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
822 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
824 wNETWMCheckInitialClientState(wwin
);
826 /* apply previous state if it exists and we're in startup */
827 if (scr
->flags
.startup
&& wm_state
>= 0) {
828 if (wm_state
== IconicState
) {
829 wwin
->flags
.miniaturized
= 1;
830 } else if (wm_state
== WithdrawnState
) {
835 /* if there is a saved state (from file), restore it */
837 if (wwin
->main_window
!= None
)
838 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
840 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
842 if (win_state
&& !withdraw
) {
843 if (win_state
->state
->hidden
> 0)
844 wwin
->flags
.hidden
= win_state
->state
->hidden
;
846 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
847 wwin
->flags
.shaded
= win_state
->state
->shaded
;
849 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
850 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
852 if (!IS_OMNIPRESENT(wwin
)) {
853 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
855 if (w
< 0 || w
>= scr
->workspace_count
) {
856 workspace
= win_state
->state
->workspace
;
857 if (workspace
>= scr
->workspace_count
)
858 workspace
= scr
->current_workspace
;
863 workspace
= scr
->current_workspace
;
867 /* if we're restarting, restore saved state (from hints).
868 * This will overwrite previous */
872 if (getSavedState(window
, &wstate
)) {
873 wwin
->flags
.shaded
= wstate
->shaded
;
874 wwin
->flags
.hidden
= wstate
->hidden
;
875 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
876 wwin
->flags
.maximized
= wstate
->maximized
;
877 if (wwin
->flags
.maximized
) {
878 wwin
->old_geometry
.x
= wstate
->x
;
879 wwin
->old_geometry
.y
= wstate
->y
;
880 wwin
->old_geometry
.width
= wstate
->w
;
881 wwin
->old_geometry
.height
= wstate
->h
;
884 workspace
= wstate
->workspace
;
889 /* restore window shortcut */
890 if (wstate
!= NULL
|| win_state
!= NULL
) {
893 if (win_state
!= NULL
)
894 mask
= win_state
->state
->window_shortcuts
;
896 if (wstate
!= NULL
&& mask
== 0)
897 mask
= wstate
->window_shortcuts
;
902 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
903 if (mask
& (1 << i
)) {
904 if (!scr
->shortcutWindows
[i
])
905 scr
->shortcutWindows
[i
] = WMCreateArray(4);
907 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
916 /* don't let transients start miniaturized if their owners are not */
917 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
918 wwin
->flags
.miniaturized
= 0;
920 wwin
->wm_hints
->initial_state
= NormalState
;
923 /* set workspace on which the window starts */
924 if (workspace
>= 0) {
925 if (workspace
> scr
->workspace_count
- 1)
926 workspace
= workspace
% scr
->workspace_count
;
930 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
932 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
935 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
936 workspace
= transientOwner
->frame
->workspace
;
938 workspace
= scr
->current_workspace
;
942 /* setup window geometry */
943 if (win_state
&& win_state
->state
->w
> 0) {
944 width
= win_state
->state
->w
;
945 height
= win_state
->state
->h
;
947 wWindowConstrainSize(wwin
, &width
, &height
);
949 /* do not ask for window placement if the window is
950 * transient, during startup, if the initial workspace is another one
951 * or if the window wants to start iconic.
952 * If geometry was saved, restore it. */
954 Bool dontBring
= False
;
956 if (win_state
&& win_state
->state
->w
> 0) {
957 x
= win_state
->state
->x
;
958 y
= win_state
->state
->y
;
959 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
960 && !scr
->flags
.startup
961 && workspace
== scr
->current_workspace
962 && !wwin
->flags
.miniaturized
963 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
965 if (transientOwner
&& transientOwner
->flags
.mapped
) {
966 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
970 x
= transientOwner
->frame_x
+
971 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
972 y
= transientOwner
->frame_y
+
973 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
976 * limit transient windows to be inside their parent's head
978 rect
.pos
.x
= transientOwner
->frame_x
;
979 rect
.pos
.y
= transientOwner
->frame_y
;
980 rect
.size
.width
= transientOwner
->frame
->core
->width
;
981 rect
.size
.height
= transientOwner
->frame
->core
->height
;
983 head
= wGetHeadForRect(scr
, rect
);
984 rect
= wGetRectForHead(scr
, head
);
988 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
989 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
993 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
994 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
997 PlaceWindow(wwin
, &x
, &y
, width
, height
);
999 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1002 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1008 * Make spash screens come out in the center of a head
1009 * trouble is that most splashies never get here
1010 * they are managed trough atoms but god knows where.
1011 * Dan, do you know ? -peter
1013 * Most of them are not managed, they have set
1014 * OverrideRedirect, which means we can't do anything about
1019 * xinerama checks for: across head and dead space
1023 rect
.size
.width
= width
;
1024 rect
.size
.height
= height
;
1026 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1028 if (flags
& XFLAG_DEAD
)
1031 if (flags
& XFLAG_MULTIPLE
)
1035 switch (reposition
) {
1037 head
= wGetHeadForPointerLocation(scr
);
1038 rect
= wGetRectForHead(scr
, head
);
1040 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1041 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1045 rect
= wGetRectForHead(scr
, head
);
1049 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1050 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1054 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1055 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1064 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1065 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1068 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1070 if (wwin
->flags
.urgent
) {
1071 if (!IS_OMNIPRESENT(wwin
))
1072 wwin
->flags
.omnipresent
^= 1;
1076 * Create frame, borders and do reparenting
1078 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1079 #ifdef XKB_BUTTON_HINT
1080 if (wPreferences
.modelock
)
1081 foo
|= WFF_LANGUAGE_BUTTON
;
1083 if (HAS_TITLEBAR(wwin
))
1084 foo
|= WFF_TITLEBAR
;
1085 if (HAS_RESIZEBAR(wwin
))
1086 foo
|= WFF_RESIZEBAR
;
1087 if (HAS_BORDER(wwin
))
1090 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1091 x
, y
, width
, height
,
1092 &wPreferences
.window_title_clearance
,
1093 &wPreferences
.window_title_min_height
,
1094 &wPreferences
.window_title_max_height
,
1096 scr
->window_title_texture
,
1097 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1098 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1100 wwin
->frame
->flags
.is_client_window_frame
= 1;
1101 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1103 /* setup button images */
1104 wWindowUpdateButtonImages(wwin
);
1106 /* hide unused buttons */
1108 if (WFLAGP(wwin
, no_close_button
))
1109 foo
|= WFF_RIGHT_BUTTON
;
1110 if (WFLAGP(wwin
, no_miniaturize_button
))
1111 foo
|= WFF_LEFT_BUTTON
;
1112 #ifdef XKB_BUTTON_HINT
1113 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1114 foo
|= WFF_LANGUAGE_BUTTON
;
1117 wFrameWindowHideButton(wwin
->frame
, foo
);
1119 wwin
->frame
->child
= wwin
;
1120 wwin
->frame
->workspace
= workspace
;
1121 wwin
->frame
->on_click_left
= windowIconifyClick
;
1123 #ifdef XKB_BUTTON_HINT
1124 if (wPreferences
.modelock
)
1125 wwin
->frame
->on_click_language
= windowLanguageClick
;
1128 wwin
->frame
->on_click_right
= windowCloseClick
;
1129 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1130 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1131 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1132 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1134 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1135 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1136 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1141 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1143 /* if gravity is to the south, account for the border sizes */
1145 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1149 * wWindowConfigure() will init the client window's size
1150 * (wwin->client.{width,height}) and all other geometry
1151 * related variables (frame_x,frame_y)
1153 wWindowConfigure(wwin
, x
, y
, width
, height
);
1155 /* to make sure the window receives it's new position after reparenting */
1156 wWindowSynthConfigureNotify(wwin
);
1159 * Setup descriptors and save window to internal
1162 if (wwin
->main_window
!= None
) {
1166 /* Leader windows do not necessary set themselves as leaders.
1167 * If this is the case, point the leader of this window to
1169 leader
= wWindowFor(wwin
->main_window
);
1170 if (leader
&& leader
->main_window
== None
)
1171 leader
->main_window
= leader
->client_win
;
1173 app
= wApplicationCreate(wwin
);
1175 app
->last_workspace
= workspace
;
1178 * Do application specific stuff, like setting application
1182 if (wwin
->flags
.hidden
) {
1183 /* if the window was set to hidden because it was hidden
1184 * in a previous incarnation and that state was restored */
1185 app
->flags
.hidden
= 1;
1186 } else if (app
->flags
.hidden
) {
1187 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1188 wwin
->flags
.hidden
= 1;
1190 wUnhideApplication(app
, False
, False
);
1198 /* setup the frame descriptor */
1199 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1200 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1201 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1203 /* don't let windows go away if we die */
1204 XAddToSaveSet(dpy
, window
);
1206 XLowerWindow(dpy
, window
);
1208 /* if window is in this workspace and should be mapped, then map it */
1209 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1210 && !wwin
->flags
.hidden
&& !withdraw
) {
1212 /* The following "if" is to avoid crashing of clients that expect
1213 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1214 * after the return from this function.
1216 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1217 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1219 wClientSetState(wwin
, NormalState
, None
);
1221 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1222 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1224 * The brain damaged idiotic non-click to focus modes will
1225 * have trouble with this because:
1227 * 1. window is created and mapped by the client
1228 * 2. window is mapped by wmaker in small size
1229 * 3. window is animated to grow to normal size
1230 * 4. this function returns to normal event loop
1231 * 5. eventually, the EnterNotify event that would trigger
1232 * the window focusing (if the mouse is over that window)
1233 * will be processed by wmaker.
1234 * But since this event will be rather delayed
1235 * (step 3 has a large delay) the time when the event ocurred
1236 * and when it is processed, the client that owns that window
1237 * will reject the XSetInputFocus() for it.
1239 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1240 DoWindowBirth(wwin
);
1245 /* setup stacking descriptor */
1247 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1249 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1251 if (!scr
->focused_window
) {
1252 /* first window on the list */
1255 scr
->focused_window
= wwin
;
1259 /* add window at beginning of focus window list */
1260 tmp
= scr
->focused_window
;
1268 /* raise is set to true if we un-hid the app when this window was born.
1269 * we raise, else old windows of this app will be above this new one. */
1271 wRaiseFrame(wwin
->frame
->core
);
1273 /* Update name must come after WApplication stuff is done */
1274 wWindowUpdateName(wwin
, title
);
1281 * Final preparations before window is ready to go
1283 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1285 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1286 if (((transientOwner
&& transientOwner
->flags
.focused
)
1287 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1289 /* only auto_focus if on same screen as mouse
1290 * (and same head for xinerama mode)
1291 * TODO: make it an option */
1293 /*TODO add checking the head of the window, is it available? */
1294 short same_screen
= 0, same_head
= 1;
1300 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1301 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1304 if (same_screen
== 1 && same_head
== 1)
1305 wSetFocusTo(scr
, wwin
);
1308 wWindowResetMouseGrabs(wwin
);
1310 if (!WFLAGP(wwin
, no_bind_keys
))
1311 wWindowSetKeyGrabs(wwin
);
1313 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1314 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1316 /* Setup Notification Observers */
1317 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1319 /* Cleanup temporary stuff */
1321 wWindowDeleteSavedState(win_state
);
1323 /* If the window must be withdrawed, then do it now.
1324 * Must do some optimization, 'though */
1326 wwin
->flags
.mapped
= 0;
1327 wClientSetState(wwin
, WithdrawnState
, None
);
1328 wUnmanageWindow(wwin
, True
, False
);
1335 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1336 char *title
, int x
, int y
, int width
, int height
)
1341 wwin
= wWindowCreate();
1343 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1345 wwin
->flags
.internal_window
= 1;
1347 WSETUFLAG(wwin
, omnipresent
, 1);
1348 WSETUFLAG(wwin
, no_shadeable
, 1);
1349 WSETUFLAG(wwin
, no_resizable
, 1);
1350 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1352 wwin
->focus_mode
= WFM_PASSIVE
;
1353 wwin
->client_win
= window
;
1354 wwin
->screen_ptr
= scr
;
1355 wwin
->transient_for
= owner
;
1358 wwin
->client
.width
= width
;
1359 wwin
->client
.height
= height
;
1360 wwin
->frame_x
= wwin
->client
.x
;
1361 wwin
->frame_y
= wwin
->client
.y
;
1363 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1364 foo
|= WFF_TITLEBAR
;
1365 #ifdef XKB_BUTTON_HINT
1366 foo
|= WFF_LANGUAGE_BUTTON
;
1369 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1370 wwin
->frame_x
, wwin
->frame_y
,
1372 &wPreferences
.window_title_clearance
,
1373 &wPreferences
.window_title_min_height
,
1374 &wPreferences
.window_title_max_height
,
1376 scr
->window_title_texture
,
1377 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1378 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1380 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1382 wwin
->frame
->flags
.is_client_window_frame
= 1;
1383 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1385 wFrameWindowChangeTitle(wwin
->frame
, title
);
1387 /* setup button images */
1388 wWindowUpdateButtonImages(wwin
);
1391 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1393 wwin
->frame
->child
= wwin
;
1394 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1396 #ifdef XKB_BUTTON_HINT
1397 if (wPreferences
.modelock
)
1398 wwin
->frame
->on_click_language
= windowLanguageClick
;
1401 wwin
->frame
->on_click_right
= windowCloseClick
;
1402 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1403 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1404 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1405 wwin
->client
.y
+= wwin
->frame
->top_width
;
1407 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1408 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1410 /* setup the frame descriptor */
1411 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1412 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1413 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1415 XLowerWindow(dpy
, window
);
1416 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1418 /* setup stacking descriptor */
1419 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1421 tmp
= wWindowFor(wwin
->transient_for
);
1423 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1425 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1428 if (!scr
->focused_window
) {
1429 /* first window on the list */
1432 scr
->focused_window
= wwin
;
1436 /* add window at beginning of focus window list */
1437 tmp
= scr
->focused_window
;
1445 if (wwin
->flags
.is_gnustep
== 0)
1446 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1448 /* if (wPreferences.auto_focus) */
1449 wSetFocusTo(scr
, wwin
);
1450 wWindowResetMouseGrabs(wwin
);
1451 wWindowSetKeyGrabs(wwin
);
1457 *----------------------------------------------------------------------
1459 * Removes the frame window from a window and destroys all data
1460 * related to it. The window will be reparented back to the root window
1461 * if restore is True.
1464 * Everything related to the window is destroyed and the window
1465 * is removed from the window lists. Focus is set to the previous on the
1467 *----------------------------------------------------------------------
1469 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1471 WCoreWindow
*frame
= wwin
->frame
->core
;
1472 WWindow
*owner
= NULL
;
1473 WWindow
*newFocusedWindow
= NULL
;
1475 WScreen
*scr
= wwin
->screen_ptr
;
1477 /* First close attribute editor window if open */
1478 if (wwin
->flags
.inspector_open
)
1479 wCloseInspectorForWindow(wwin
);
1481 /* Close window menu if it's open for this window */
1482 if (wwin
->flags
.menu_open_for_me
)
1483 CloseWindowMenu(scr
);
1486 if (!wwin
->flags
.internal_window
)
1487 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1489 /* If this is a leader window, we still need to listen for
1490 * DestroyNotify and PropertyNotify. */
1491 if (wApplicationOf(wwin
->client_win
))
1492 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1494 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1496 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1497 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1500 XUnmapWindow(dpy
, frame
->window
);
1502 XUnmapWindow(dpy
, wwin
->client_win
);
1504 /* deselect window */
1505 wSelectWindow(wwin
, False
);
1507 /* remove all pending events on window */
1508 /* I think this only matters for autoraise */
1509 if (wPreferences
.raise_delay
)
1510 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1514 /* reparent the window back to the root */
1516 wClientRestore(wwin
);
1518 if (wwin
->transient_for
!= scr
->root_win
) {
1519 owner
= wWindowFor(wwin
->transient_for
);
1521 if (!owner
->flags
.semi_focused
)
1524 owner
->flags
.semi_focused
= 0;
1528 wasFocused
= wwin
->flags
.focused
;
1530 /* remove from window focus list */
1531 if (!wwin
->prev
&& !wwin
->next
) {
1532 /* was the only window */
1533 scr
->focused_window
= NULL
;
1534 newFocusedWindow
= NULL
;
1539 wwin
->prev
->next
= wwin
->next
;
1542 wwin
->next
->prev
= wwin
->prev
;
1544 scr
->focused_window
= wwin
->prev
;
1545 scr
->focused_window
->next
= NULL
;
1548 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1550 /* if in click to focus mode and the window
1551 * was a transient, focus the owner window
1554 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1555 tmp
= wWindowFor(wwin
->transient_for
);
1556 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1560 /* otherwise, focus the next one in the focus list */
1562 tmp
= scr
->focused_window
;
1563 while (tmp
) { /* look for one in the window list first */
1564 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1565 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1569 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1570 tmp
= scr
->focused_window
;
1572 if (!WFLAGP(tmp
, no_focusable
)
1573 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1580 newFocusedWindow
= tmp
;
1582 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1587 /* This is to let the root window get the keyboard input
1588 * if Sloppy focus mode and no other window get focus.
1589 * This way keybindings will not freeze.
1592 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1593 tmp
= wWindowFor(win
);
1596 newFocusedWindow
= tmp
;
1598 newFocusedWindow
= NULL
;
1602 if (!wwin
->flags
.internal_window
)
1603 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1605 if (newFocusedWindow
!= owner
&& owner
) {
1606 if (wwin
->flags
.is_gnustep
== 0)
1607 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1609 wSetFocusTo(scr
, newFocusedWindow
);
1612 /* Close menu and unhighlight */
1613 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1614 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1615 if (oapp
&& oapp
!= napp
) {
1616 wAppMenuUnmap(oapp
->menu
);
1617 wApplicationDeactivate(oapp
);
1620 wWindowDestroy(wwin
);
1624 void wWindowMap(WWindow
*wwin
)
1626 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1627 if (!wwin
->flags
.shaded
) {
1628 /* window will be remapped when getting MapNotify */
1629 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1630 XMapWindow(dpy
, wwin
->client_win
);
1631 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1633 wwin
->flags
.mapped
= 1;
1637 void wWindowUnmap(WWindow
*wwin
)
1639 wwin
->flags
.mapped
= 0;
1641 /* prevent window withdrawal when getting UnmapNotify */
1642 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1643 XUnmapWindow(dpy
, wwin
->client_win
);
1644 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1646 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1649 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1654 #ifdef KEEP_XKB_LOCK_STATUS
1655 if (wPreferences
.modelock
)
1656 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1657 #endif /* KEEP_XKB_LOCK_STATUS */
1659 wwin
->flags
.semi_focused
= 0;
1661 if (wwin
->flags
.is_gnustep
== 0)
1662 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1664 wwin
->flags
.focused
= 1;
1666 wWindowResetMouseGrabs(wwin
);
1668 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1670 if (owin
== wwin
|| !owin
)
1673 nowner
= wWindowFor(wwin
->transient_for
);
1675 /* new window is a transient for the old window */
1676 if (nowner
== owin
) {
1677 owin
->flags
.semi_focused
= 1;
1678 wWindowUnfocus(nowner
);
1682 oowner
= wWindowFor(owin
->transient_for
);
1684 /* new window is owner of old window */
1685 if (wwin
== oowner
) {
1686 wWindowUnfocus(owin
);
1691 wWindowUnfocus(owin
);
1695 /* new window has same owner of old window */
1696 if (oowner
== nowner
) {
1697 /* prevent unfocusing of owner */
1698 oowner
->flags
.semi_focused
= 0;
1699 wWindowUnfocus(owin
);
1700 oowner
->flags
.semi_focused
= 1;
1705 /* nowner != NULL && oowner != nowner */
1706 nowner
->flags
.semi_focused
= 1;
1707 wWindowUnfocus(nowner
);
1708 wWindowUnfocus(owin
);
1711 void wWindowUnfocus(WWindow
*wwin
)
1713 CloseWindowMenu(wwin
->screen_ptr
);
1715 if (wwin
->flags
.is_gnustep
== 0)
1716 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1718 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1720 owner
= wWindowFor(wwin
->transient_for
);
1721 if (owner
&& owner
->flags
.semi_focused
) {
1722 owner
->flags
.semi_focused
= 0;
1723 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1724 wWindowUnfocus(owner
);
1725 wFrameWindowPaint(owner
->frame
);
1729 wwin
->flags
.focused
= 0;
1730 wWindowResetMouseGrabs(wwin
);
1731 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1734 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1742 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1746 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1747 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1751 *----------------------------------------------------------------------
1753 * wWindowConstrainSize--
1754 * Constrains size for the client window, taking the maximal size,
1755 * window resize increments and other size hints into account.
1758 * The closest size to what was given that the client window can
1761 *----------------------------------------------------------------------
1763 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1765 int width
= (int)*nwidth
;
1766 int height
= (int)*nheight
;
1769 int minW
= 1, minH
= 1;
1770 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1771 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1772 int minAX
= -1, minAY
= -1;
1773 int maxAX
= -1, maxAY
= -1;
1777 if (wwin
->normal_hints
) {
1778 winc
= wwin
->normal_hints
->width_inc
;
1779 hinc
= wwin
->normal_hints
->height_inc
;
1780 minW
= wwin
->normal_hints
->min_width
;
1781 minH
= wwin
->normal_hints
->min_height
;
1782 maxW
= wwin
->normal_hints
->max_width
;
1783 maxH
= wwin
->normal_hints
->max_height
;
1784 if (wwin
->normal_hints
->flags
& PAspect
) {
1785 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1786 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1787 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1788 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1791 baseW
= wwin
->normal_hints
->base_width
;
1792 baseH
= wwin
->normal_hints
->base_height
;
1805 /* aspect ratio code borrowed from olwm */
1807 /* adjust max aspect ratio */
1808 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1809 if (maxAX
> maxAY
) {
1810 height
= (width
* maxAY
) / maxAX
;
1811 if (height
> maxH
) {
1813 width
= (height
* maxAX
) / maxAY
;
1816 width
= (height
* maxAX
) / maxAY
;
1819 height
= (width
* maxAY
) / maxAX
;
1824 /* adjust min aspect ratio */
1825 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1826 if (minAX
> minAY
) {
1827 height
= (width
* minAY
) / minAX
;
1828 if (height
< minH
) {
1830 width
= (height
* minAX
) / minAY
;
1833 width
= (height
* minAX
) / minAY
;
1836 height
= (width
* minAY
) / minAX
;
1843 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1845 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1848 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1850 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1852 /* broken stupid apps may cause preposterous values for these.. */
1859 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1860 unsigned int *width
, unsigned int *height
)
1862 int baseW
= 0, baseH
= 0;
1863 int winc
= 1, hinc
= 1;
1865 if (wwin
->normal_hints
) {
1866 baseW
= wwin
->normal_hints
->base_width
;
1867 baseH
= wwin
->normal_hints
->base_height
;
1869 winc
= wwin
->normal_hints
->width_inc
;
1870 hinc
= wwin
->normal_hints
->height_inc
;
1874 *width
= maxW
- (maxW
- baseW
) % winc
;
1877 *height
= maxH
- (maxH
- baseH
) % hinc
;
1880 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1882 WScreen
*scr
= wwin
->screen_ptr
;
1886 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1889 if (workspace
!= scr
->current_workspace
) {
1890 /* Sent to other workspace. Unmap window */
1891 if ((wwin
->flags
.mapped
1892 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1893 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1895 wapp
= wApplicationOf(wwin
->main_window
);
1897 wapp
->last_workspace
= workspace
;
1899 if (wwin
->flags
.miniaturized
) {
1901 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1902 wwin
->icon
->mapped
= 0;
1906 wSetFocusTo(scr
, NULL
);
1910 /* brought to current workspace. Map window */
1911 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1913 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1914 wwin
->icon
->mapped
= 1;
1916 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1920 if (!IS_OMNIPRESENT(wwin
)) {
1921 int oldWorkspace
= wwin
->frame
->workspace
;
1922 wwin
->frame
->workspace
= workspace
;
1923 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1930 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1934 sevent
.type
= ConfigureNotify
;
1935 sevent
.xconfigure
.display
= dpy
;
1936 sevent
.xconfigure
.event
= wwin
->client_win
;
1937 sevent
.xconfigure
.window
= wwin
->client_win
;
1939 sevent
.xconfigure
.x
= wwin
->client
.x
;
1940 sevent
.xconfigure
.y
= wwin
->client
.y
;
1941 sevent
.xconfigure
.width
= wwin
->client
.width
;
1942 sevent
.xconfigure
.height
= wwin
->client
.height
;
1944 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1945 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1946 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1948 sevent
.xconfigure
.above
= None
;
1950 sevent
.xconfigure
.override_redirect
= False
;
1951 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1956 *----------------------------------------------------------------------
1957 * wWindowConfigure()
1959 * req_x, req_y: new requested positions for the frame
1960 * req_width, req_height: new requested sizes for the client
1962 * Configures the frame, decorations and client window to the specified
1963 * geometry, whose validity is not checked -- wWindowConstrainSize()
1964 * must be used for that.
1965 * The size parameters are for the client window, but the position is
1967 * The client window receives a ConfigureNotify event, according
1968 * to what ICCCM says.
1974 * Window size and position are changed and client window receives
1975 * a ConfigureNotify event.
1976 *----------------------------------------------------------------------
1978 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1980 int synth_notify
= False
;
1983 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1985 * if the window is being moved but not resized then
1986 * send a synthetic ConfigureNotify
1988 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
1989 synth_notify
= True
;
1991 if (WFLAGP(wwin
, dont_move_off
))
1992 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
1995 if (req_width
< MIN_WINDOW_SIZE
)
1996 req_width
= MIN_WINDOW_SIZE
;
1997 if (req_height
< MIN_WINDOW_SIZE
)
1998 req_height
= MIN_WINDOW_SIZE
;
2000 /* If growing, resize inner part before frame,
2001 * if shrinking, resize frame before.
2002 * This will prevent the frame (that can have a different color)
2003 * to be exposed, causing flicker */
2004 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2005 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2007 if (wwin
->flags
.shaded
) {
2008 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2009 wwin
->old_geometry
.height
= req_height
;
2013 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2015 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2018 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2019 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2021 wwin
->client
.x
= req_x
;
2022 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2023 wwin
->client
.width
= req_width
;
2024 wwin
->client
.height
= req_height
;
2026 wwin
->client
.x
= req_x
;
2027 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2029 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2031 wwin
->frame_x
= req_x
;
2032 wwin
->frame_y
= req_y
;
2033 if (HAS_BORDER(wwin
)) {
2034 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2035 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2038 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2039 wWindowSetShape(wwin
);
2043 wWindowSynthConfigureNotify(wwin
);
2045 wNETFrameExtents(wwin
);
2050 /* req_x, req_y: new position of the frame */
2051 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2053 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2054 int synth_notify
= False
;
2056 /* Send a synthetic ConfigureNotify event for every window movement. */
2057 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2058 synth_notify
= True
;
2060 /* A single synthetic ConfigureNotify event is sent at the end of
2061 * a completed (opaque) movement in moveres.c */
2064 if (WFLAGP(wwin
, dont_move_off
))
2065 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2066 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2068 wwin
->client
.x
= req_x
;
2069 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2070 if (HAS_BORDER(wwin
)) {
2071 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2072 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2075 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2077 wwin
->frame_x
= req_x
;
2078 wwin
->frame_y
= req_y
;
2080 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2082 wWindowSynthConfigureNotify(wwin
);
2086 void wWindowUpdateButtonImages(WWindow
*wwin
)
2088 WScreen
*scr
= wwin
->screen_ptr
;
2089 Pixmap pixmap
, mask
;
2090 WFrameWindow
*fwin
= wwin
->frame
;
2092 if (!HAS_TITLEBAR(wwin
))
2095 /* miniaturize button */
2096 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2097 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2098 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2100 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2101 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2105 if (fwin
->lbutton_image
2106 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2107 wPixmapDestroy(fwin
->lbutton_image
);
2108 fwin
->lbutton_image
= NULL
;
2111 if (!fwin
->lbutton_image
) {
2112 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2113 fwin
->lbutton_image
->client_owned
= 1;
2114 fwin
->lbutton_image
->client_owned_mask
= 1;
2117 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2118 wPixmapDestroy(fwin
->lbutton_image
);
2120 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2123 #ifdef XKB_BUTTON_HINT
2124 if (!WFLAGP(wwin
, no_language_button
)) {
2125 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2126 wPixmapDestroy(fwin
->languagebutton_image
);
2128 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2134 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2135 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2137 if (!WFLAGP(wwin
, no_close_button
)) {
2138 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2139 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2141 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2142 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2146 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2147 || fwin
->rbutton_image
->mask
!= mask
)) {
2148 wPixmapDestroy(fwin
->rbutton_image
);
2149 fwin
->rbutton_image
= NULL
;
2152 if (!fwin
->rbutton_image
) {
2153 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2154 fwin
->rbutton_image
->client_owned
= 1;
2155 fwin
->rbutton_image
->client_owned_mask
= 1;
2158 } else if (WFLAGP(wwin
, kill_close
)) {
2159 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2160 wPixmapDestroy(fwin
->rbutton_image
);
2162 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2164 } else if (MGFLAGP(wwin
, broken_close
)) {
2165 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2166 wPixmapDestroy(fwin
->rbutton_image
);
2168 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2171 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2172 wPixmapDestroy(fwin
->rbutton_image
);
2174 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2178 /* force buttons to be redrawn */
2179 fwin
->flags
.need_texture_change
= 1;
2180 wFrameWindowPaint(fwin
);
2184 *---------------------------------------------------------------------------
2185 * wWindowConfigureBorders--
2186 * Update window border configuration according to attribute flags.
2188 *---------------------------------------------------------------------------
2190 void wWindowConfigureBorders(WWindow
*wwin
)
2196 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2198 #ifdef XKB_BUTTON_HINT
2199 if (wPreferences
.modelock
)
2200 flags
|= WFF_LANGUAGE_BUTTON
;
2203 if (HAS_TITLEBAR(wwin
))
2204 flags
|= WFF_TITLEBAR
;
2205 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2206 flags
|= WFF_RESIZEBAR
;
2207 if (HAS_BORDER(wwin
))
2208 flags
|= WFF_BORDER
;
2209 if (wwin
->flags
.shaded
)
2210 flags
|= WFF_IS_SHADED
;
2212 oldh
= wwin
->frame
->top_width
;
2213 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2214 if (oldh
!= wwin
->frame
->top_width
) {
2215 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2217 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2218 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2222 if (!WFLAGP(wwin
, no_miniaturize_button
)
2223 && wwin
->frame
->flags
.hide_left_button
)
2224 flags
|= WFF_LEFT_BUTTON
;
2226 #ifdef XKB_BUTTON_HINT
2227 if (!WFLAGP(wwin
, no_language_button
)
2228 && wwin
->frame
->flags
.hide_language_button
)
2229 flags
|= WFF_LANGUAGE_BUTTON
;
2232 if (!WFLAGP(wwin
, no_close_button
)
2233 && wwin
->frame
->flags
.hide_right_button
)
2234 flags
|= WFF_RIGHT_BUTTON
;
2237 wWindowUpdateButtonImages(wwin
);
2238 wFrameWindowShowButton(wwin
->frame
, flags
);
2242 if (WFLAGP(wwin
, no_miniaturize_button
)
2243 && !wwin
->frame
->flags
.hide_left_button
)
2244 flags
|= WFF_LEFT_BUTTON
;
2246 #ifdef XKB_BUTTON_HINT
2247 if (WFLAGP(wwin
, no_language_button
)
2248 && !wwin
->frame
->flags
.hide_language_button
)
2249 flags
|= WFF_LANGUAGE_BUTTON
;
2252 if (WFLAGP(wwin
, no_close_button
)
2253 && !wwin
->frame
->flags
.hide_right_button
)
2254 flags
|= WFF_RIGHT_BUTTON
;
2257 wFrameWindowHideButton(wwin
->frame
, flags
);
2260 if (wShapeSupported
&& wwin
->flags
.shaped
)
2261 wWindowSetShape(wwin
);
2266 void wWindowSaveState(WWindow
* wwin
)
2271 memset(data
, 0, sizeof(long) * 10);
2272 data
[0] = wwin
->frame
->workspace
;
2273 data
[1] = wwin
->flags
.miniaturized
;
2274 data
[2] = wwin
->flags
.shaded
;
2275 data
[3] = wwin
->flags
.hidden
;
2276 data
[4] = wwin
->flags
.maximized
;
2277 if (wwin
->flags
.maximized
== 0) {
2278 data
[5] = wwin
->frame_x
;
2279 data
[6] = wwin
->frame_y
;
2280 data
[7] = wwin
->frame
->core
->width
;
2281 data
[8] = wwin
->frame
->core
->height
;
2283 data
[5] = wwin
->old_geometry
.x
;
2284 data
[6] = wwin
->old_geometry
.y
;
2285 data
[7] = wwin
->old_geometry
.width
;
2286 data
[8] = wwin
->old_geometry
.height
;
2289 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2290 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2291 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2294 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2295 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2298 static int getSavedState(Window window
, WSavedState
** state
)
2302 unsigned long nitems_ret
;
2303 unsigned long bytes_after_ret
;
2306 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2307 True
, _XA_WINDOWMAKER_STATE
,
2308 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2309 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2312 *state
= wmalloc(sizeof(WSavedState
));
2314 (*state
)->workspace
= data
[0];
2315 (*state
)->miniaturized
= data
[1];
2316 (*state
)->shaded
= data
[2];
2317 (*state
)->hidden
= data
[3];
2318 (*state
)->maximized
= data
[4];
2319 (*state
)->x
= data
[5];
2320 (*state
)->y
= data
[6];
2321 (*state
)->w
= data
[7];
2322 (*state
)->h
= data
[8];
2323 (*state
)->window_shortcuts
= data
[9];
2327 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2334 void wWindowClearShape(WWindow
* wwin
)
2336 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2337 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2341 void wWindowSetShape(WWindow
* wwin
)
2345 #ifdef OPTIMIZE_SHAPE
2350 /* only shape is the client's */
2351 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2354 /* Get array of rectangles describing the shape mask */
2355 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2359 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2365 /* insert our decoration rectangles in the rect list */
2366 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2369 if (HAS_TITLEBAR(wwin
)) {
2371 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2372 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2373 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2376 if (HAS_RESIZEBAR(wwin
)) {
2378 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2379 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2380 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2384 /* shape our frame window */
2385 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2386 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2392 #endif /* OPTIMIZE_SHAPE */
2394 if (HAS_TITLEBAR(wwin
)) {
2397 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2398 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2401 if (HAS_RESIZEBAR(wwin
)) {
2403 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2404 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2405 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2409 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2410 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2412 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2413 0, wwin
->frame
->top_width
, wwin
->client_win
,
2414 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2419 /* ====================================================================== */
2421 static FocusMode
getFocusMode(WWindow
* wwin
)
2425 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2426 if (wwin
->wm_hints
->input
== True
) {
2427 if (wwin
->protocols
.TAKE_FOCUS
)
2428 mode
= WFM_LOCALLY_ACTIVE
;
2432 if (wwin
->protocols
.TAKE_FOCUS
)
2433 mode
= WFM_GLOBALLY_ACTIVE
;
2435 mode
= WFM_NO_INPUT
;
2443 void wWindowSetKeyGrabs(WWindow
* wwin
)
2448 for (i
= 0; i
< WKBD_LAST
; i
++) {
2449 key
= &wKeyBindings
[i
];
2451 if (key
->keycode
== 0)
2453 if (key
->modifier
!= AnyModifier
) {
2454 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2455 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2457 /* Also grab all modifier combinations possible that include,
2458 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2459 * work even if the NumLock/ScrollLock key is on.
2461 wHackedGrabKey(key
->keycode
, key
->modifier
,
2462 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2465 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2466 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2469 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2472 void wWindowResetMouseGrabs(WWindow
* wwin
)
2474 /* Mouse grabs can't be done on the client window because of
2475 * ICCCM and because clients that try to do the same will crash.
2477 * But there is a problem wich makes tbar buttons of unfocused
2478 * windows not usable as the click goes to the frame window instead
2479 * of the button itself. Must figure a way to fix that.
2482 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2484 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2485 /* grabs for Meta+drag */
2486 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2487 True
, ButtonPressMask
| ButtonReleaseMask
,
2488 GrabModeSync
, GrabModeAsync
, None
, None
);
2490 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2491 * but we only grab it for Button4 and Button 5 since a lot of apps
2492 * use CTRL+Button1-3 for app related functionality
2494 if (wPreferences
.resize_increment
> 0) {
2495 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2496 True
, ButtonPressMask
| ButtonReleaseMask
,
2497 GrabModeSync
, GrabModeAsync
, None
, None
);
2498 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2499 True
, ButtonPressMask
| ButtonReleaseMask
,
2500 GrabModeSync
, GrabModeAsync
, None
, None
);
2502 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2503 True
, ButtonPressMask
| ButtonReleaseMask
,
2504 GrabModeSync
, GrabModeAsync
, None
, None
);
2505 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2506 True
, ButtonPressMask
| ButtonReleaseMask
,
2507 GrabModeSync
, GrabModeAsync
, None
, None
);
2511 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2512 && !wwin
->flags
.is_gnustep
) {
2513 /* the passive grabs to focus the window */
2514 /* if (wPreferences.focus_mode == WKF_CLICK) */
2515 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2516 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2521 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2523 if (attr
->flags
& GSExtraFlagsAttr
) {
2524 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2525 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2526 wWindowUpdateButtonImages(wwin
);
2531 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2533 WWindowState
*wstate
;
2535 wstate
= malloc(sizeof(WWindowState
));
2539 memset(wstate
, 0, sizeof(WWindowState
));
2542 wstate
->instance
= wstrdup(instance
);
2544 wstate
->class = wstrdup(class);
2546 wstate
->command
= wstrdup(command
);
2547 wstate
->state
= state
;
2549 wstate
->next
= windowState
;
2550 windowState
= wstate
;
2555 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2557 WMagicNumber
wWindowGetSavedState(Window win
)
2559 char *instance
, *class, *command
= NULL
;
2560 WWindowState
*wstate
= windowState
;
2565 command
= GetCommandForWindow(win
);
2569 if (PropGetWMClass(win
, &class, &instance
)) {
2571 if (SAME(instance
, wstate
->instance
) &&
2572 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2575 wstate
= wstate
->next
;
2591 void wWindowDeleteSavedState(WMagicNumber id
)
2593 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2595 if (!wstate
|| !windowState
)
2599 if (tmp
== wstate
) {
2600 windowState
= wstate
->next
;
2601 if (wstate
->instance
)
2602 wfree(wstate
->instance
);
2604 wfree(wstate
->class);
2605 if (wstate
->command
)
2606 wfree(wstate
->command
);
2607 wfree(wstate
->state
);
2611 if (tmp
->next
== wstate
) {
2612 tmp
->next
= wstate
->next
;
2613 if (wstate
->instance
)
2614 wfree(wstate
->instance
);
2616 wfree(wstate
->class);
2617 if (wstate
->command
)
2618 wfree(wstate
->command
);
2619 wfree(wstate
->state
);
2628 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2630 WWindowState
*tmp
, *wstate
;
2636 if (tmp
->pid
== pid
) {
2637 wstate
= windowState
;
2638 windowState
= tmp
->next
;
2639 if (wstate
->instance
)
2640 wfree(wstate
->instance
);
2642 wfree(wstate
->class);
2643 if (wstate
->command
)
2644 wfree(wstate
->command
);
2645 wfree(wstate
->state
);
2649 if (tmp
->next
->pid
== pid
) {
2651 tmp
->next
= wstate
->next
;
2652 if (wstate
->instance
)
2653 wfree(wstate
->instance
);
2655 wfree(wstate
->class);
2656 if (wstate
->command
)
2657 wfree(wstate
->command
);
2658 wfree(wstate
->state
);
2667 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2669 if (wwin
->flags
.omnipresent
== flag
)
2672 wwin
->flags
.omnipresent
= flag
;
2673 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2676 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2678 WWindow
*wwin
= data
;
2680 #ifndef NUMLOCK_HACK
2681 if ((event
->xbutton
.state
& ValidModMask
)
2682 != (event
->xbutton
.state
& ~LockMask
)) {
2683 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2684 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2688 event
->xbutton
.state
&= ValidModMask
;
2690 CloseWindowMenu(wwin
->screen_ptr
);
2692 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2693 && !WFLAGP(wwin
, no_focusable
)) {
2694 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2697 if (event
->xbutton
.button
== Button1
)
2698 wRaiseFrame(wwin
->frame
->core
);
2700 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2701 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2702 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2703 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2708 if (event
->xbutton
.state
& MOD_MASK
) {
2709 /* move the window */
2710 wMouseMoveWindow(wwin
, event
);
2711 XUngrabPointer(dpy
, CurrentTime
);
2713 wMouseResizeWindow(wwin
, event
);
2714 XUngrabPointer(dpy
, CurrentTime
);
2718 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2720 WWindow
*wwin
= data
;
2722 event
->xbutton
.state
&= ValidModMask
;
2724 if (event
->xbutton
.button
== Button1
) {
2725 if (event
->xbutton
.state
== 0) {
2726 if (!WFLAGP(wwin
, no_shadeable
)) {
2728 if (wwin
->flags
.shaded
)
2729 wUnshadeWindow(wwin
);
2736 if (event
->xbutton
.state
& ControlMask
)
2737 dir
|= MAX_VERTICAL
;
2739 if (event
->xbutton
.state
& ShiftMask
) {
2740 dir
|= MAX_HORIZONTAL
;
2741 if (!(event
->xbutton
.state
& ControlMask
))
2742 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2745 /* maximize window */
2746 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2747 int ndir
= dir
^ wwin
->flags
.maximized
;
2750 wMaximizeWindow(wwin
, ndir
);
2752 wUnmaximizeWindow(wwin
);
2755 } else if (event
->xbutton
.button
== Button3
) {
2756 if (event
->xbutton
.state
& MOD_MASK
)
2757 wHideOtherApplications(wwin
);
2758 } else if (event
->xbutton
.button
== Button2
) {
2759 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2760 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2762 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2763 wUnshadeWindow(wwin
);
2767 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2769 WWindow
*wwin
= desc
->parent
;
2770 unsigned int new_width
, w_scale
;
2771 unsigned int new_height
, h_scale
;
2772 unsigned int resize_width_increment
= 0;
2773 unsigned int resize_height_increment
= 0;
2775 if (wwin
->normal_hints
) {
2776 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2777 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2778 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2779 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2781 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2782 resize_width_increment
= wPreferences
.resize_increment
;
2783 resize_height_increment
= wPreferences
.resize_increment
;
2786 event
->xbutton
.state
&= ValidModMask
;
2788 CloseWindowMenu(wwin
->screen_ptr
);
2790 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2791 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2793 if (event
->xbutton
.button
== Button1
)
2794 wRaiseFrame(wwin
->frame
->core
);
2796 if (event
->xbutton
.state
& ControlMask
) {
2797 if (event
->xbutton
.button
== Button4
) {
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
);
2802 if (event
->xbutton
.button
== Button5
) {
2803 new_width
= wwin
->client
.width
+ resize_width_increment
;
2804 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2805 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2809 if (event
->xbutton
.state
& MOD_MASK
) {
2810 /* move the window */
2811 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2812 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2813 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2816 if (event
->xbutton
.button
== Button3
) {
2817 wMouseResizeWindow(wwin
, event
);
2818 } else if (event
->xbutton
.button
== Button4
) {
2819 new_height
= wwin
->client
.height
- resize_height_increment
;
2820 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2821 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2822 } else if (event
->xbutton
.button
== Button5
) {
2823 new_height
= wwin
->client
.height
+ resize_height_increment
;
2824 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2825 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2826 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2827 wMouseMoveWindow(wwin
, event
);
2829 XUngrabPointer(dpy
, CurrentTime
);
2833 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2835 WWindow
*wwin
= (WWindow
*) data
;
2837 #ifndef NUMLOCK_HACK
2838 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2839 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2840 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2842 event
->xbutton
.state
&= ValidModMask
;
2844 CloseWindowMenu(wwin
->screen_ptr
);
2846 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2847 && !WFLAGP(wwin
, no_focusable
))
2848 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2850 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2852 if (event
->xbutton
.button
== Button1
) {
2853 if (event
->xbutton
.state
& MOD_MASK
)
2854 wLowerFrame(wwin
->frame
->core
);
2856 wRaiseFrame(wwin
->frame
->core
);
2858 if ((event
->xbutton
.state
& ShiftMask
)
2859 && !(event
->xbutton
.state
& ControlMask
)) {
2860 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2863 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2864 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2865 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2866 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2870 /* move the window */
2871 wMouseMoveWindow(wwin
, event
);
2873 XUngrabPointer(dpy
, CurrentTime
);
2874 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2875 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2876 WObjDescriptor
*desc
;
2878 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2879 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2880 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2881 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2885 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2887 /* allow drag select */
2888 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2889 event
->xany
.send_event
= True
;
2890 (*desc
->handle_mousedown
) (desc
, event
);
2892 XUngrabPointer(dpy
, CurrentTime
);
2896 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2898 WWindow
*wwin
= data
;
2900 event
->xbutton
.state
&= ValidModMask
;
2902 CloseWindowMenu(wwin
->screen_ptr
);
2904 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2907 /* if control-click, kill the client */
2908 if (event
->xbutton
.state
& ControlMask
) {
2911 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2912 /* send delete message */
2913 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2918 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2920 WWindow
*wwin
= data
;
2922 CloseWindowMenu(wwin
->screen_ptr
);
2924 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2927 /* send delete message */
2928 if (wwin
->protocols
.DELETE_WINDOW
)
2929 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
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
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
2972 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2974 wapp
= wApplicationOf(wwin
->main_window
);
2975 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2976 wHideApplication(wapp
);
2977 } else if (event
->xbutton
.state
== 0) {
2978 wIconifyWindow(wwin
);