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
76 /***** Local Stuff *****/
77 static WWindowState
*windowState
= NULL
;
78 static FocusMode
getFocusMode(WWindow
*wwin
);
79 static int getSavedState(Window window
, WSavedState
**state
);
80 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
82 /* frame window (during window grabs) */
83 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
86 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
87 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
90 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
92 #ifdef XKB_BUTTON_HINT
93 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
96 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
97 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
98 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
100 static void release_wwindowstate(WWindowState
*wstate
);
102 /****** Notification Observers ******/
104 static void appearanceObserver(void *self
, WMNotification
* notif
)
106 WWindow
*wwin
= (WWindow
*) self
;
107 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
109 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
112 if (flags
& WFontSettings
) {
113 wWindowConfigureBorders(wwin
);
114 if (wwin
->flags
.shaded
) {
115 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
116 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
117 wWindowSynthConfigureNotify(wwin
);
120 if (flags
& WTextureSettings
)
121 wwin
->frame
->flags
.need_texture_remake
= 1;
123 if (flags
& (WTextureSettings
| WColorSettings
)) {
124 if (wwin
->frame
->titlebar
)
125 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
127 wFrameWindowPaint(wwin
->frame
);
132 /* Return the WWindow associated with a given (Xlib) Window. */
133 WWindow
*wWindowFor(Window window
)
135 WObjDescriptor
*desc
;
140 if (XFindContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
143 if (desc
->parent_type
== WCLASS_WINDOW
)
145 else if (desc
->parent_type
== WCLASS_FRAME
) {
146 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
147 if (frame
->flags
.is_client_window_frame
)
154 WWindow
*wWindowCreate(void)
158 wwin
= wmalloc(sizeof(WWindow
));
161 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
162 wwin
->client_descriptor
.parent
= wwin
;
163 wwin
->client_descriptor
.self
= wwin
;
164 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
169 void wWindowDestroy(WWindow
*wwin
)
173 if (wwin
->screen_ptr
->cmap_window
== wwin
)
174 wwin
->screen_ptr
->cmap_window
= NULL
;
176 WMRemoveNotificationObserver(wwin
);
178 wwin
->flags
.destroyed
= 1;
180 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
181 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
184 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
186 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
187 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
188 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
192 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
193 wwin
->fake_group
->retainCount
--;
194 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
195 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
196 wwin
->fake_group
->leader
= None
;
197 wwin
->fake_group
->origLeader
= None
;
202 if (wwin
->normal_hints
)
203 XFree(wwin
->normal_hints
);
206 XFree(wwin
->wm_hints
);
208 if (wwin
->wm_instance
)
209 XFree(wwin
->wm_instance
);
212 XFree(wwin
->wm_class
);
214 if (wwin
->wm_gnustep_attr
)
215 wfree(wwin
->wm_gnustep_attr
);
217 if (wwin
->cmap_windows
)
218 XFree(wwin
->cmap_windows
);
220 XDeleteContext(dpy
, wwin
->client_win
, w_global
.context
.client_win
);
223 wFrameWindowDestroy(wwin
->frame
);
226 RemoveFromStackList(wwin
->icon
->core
);
227 wIconDestroy(wwin
->icon
);
228 if (wPreferences
.auto_arrange_icons
)
229 wArrangeIcons(wwin
->screen_ptr
, True
);
231 if (wwin
->net_icon_image
)
232 RReleaseImage(wwin
->net_icon_image
);
237 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
239 if (gs_hints
->flags
& GSWindowStyleAttr
) {
240 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
241 wwin
->client_flags
.no_border
= 1;
242 wwin
->client_flags
.no_titlebar
= 1;
243 wwin
->client_flags
.no_closable
= 1;
244 wwin
->client_flags
.no_miniaturizable
= 1;
245 wwin
->client_flags
.no_resizable
= 1;
246 wwin
->client_flags
.no_close_button
= 1;
247 wwin
->client_flags
.no_miniaturize_button
= 1;
248 wwin
->client_flags
.no_resizebar
= 1;
250 wwin
->client_flags
.no_close_button
=
251 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
253 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
255 wwin
->client_flags
.no_miniaturize_button
=
256 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
258 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
260 wwin
->client_flags
.no_resizebar
=
261 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
263 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
265 /* these attributes supposedly imply in the existence
267 if (gs_hints
->window_style
& (WMResizableWindowMask
|
268 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
269 wwin
->client_flags
.no_titlebar
= 0;
271 wwin
->client_flags
.no_titlebar
=
272 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
277 /* setup the defaults */
278 wwin
->client_flags
.no_border
= 0;
279 wwin
->client_flags
.no_titlebar
= 0;
280 wwin
->client_flags
.no_closable
= 0;
281 wwin
->client_flags
.no_miniaturizable
= 0;
282 wwin
->client_flags
.no_resizable
= 0;
283 wwin
->client_flags
.no_close_button
= 0;
284 wwin
->client_flags
.no_miniaturize_button
= 0;
285 wwin
->client_flags
.no_resizebar
= 0;
287 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
288 wwin
->client_flags
.no_appicon
= 1;
291 static void discard_hints_from_gtk(WWindow
*wwin
)
295 unsigned long nb_item
, nb_remain
;
296 unsigned char *result
;
299 status
= XGetWindowProperty(dpy
, wwin
->client_win
, w_global
.atom
.desktop
.gtk_object_path
, 0, 16, False
,
300 AnyPropertyType
, &type
, &format
, &nb_item
, &nb_remain
, &result
);
301 if (status
!= Success
)
304 /* If we're here, that means the Property exists. We don't care what is inside, it means it is a GTK-based application */
309 /* GTK is asking to remove these decorations: */
310 wwin
->client_flags
.no_titlebar
= 0;
311 wwin
->client_flags
.no_close_button
= 0;
312 wwin
->client_flags
.no_miniaturize_button
= 0;
313 wwin
->client_flags
.no_resizebar
= 0;
316 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
318 WScreen
*scr
= wwin
->screen_ptr
;
320 /* sets global default stuff */
321 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
, NULL
, True
);
322 wwin
->defined_user_flags
= wwin
->user_flags
;
325 * Decoration setting is done in this precedence (lower to higher)
326 * - use global default in the resource database
327 * - guess some settings
328 * - use GNUstep/external window attributes
329 * - set hints specified for the app in the resource DB
332 wwin
->client_flags
.broken_close
= 0;
334 if (wwin
->protocols
.DELETE_WINDOW
)
335 wwin
->client_flags
.kill_close
= 0;
337 wwin
->client_flags
.kill_close
= 1;
339 /* transients can't be iconified or maximized */
340 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
341 wwin
->client_flags
.no_miniaturizable
= 1;
342 wwin
->client_flags
.no_miniaturize_button
= 1;
345 /* if the window can't be resized, remove the resizebar */
346 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
347 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
348 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
349 wwin
->client_flags
.no_resizable
= 1;
350 wwin
->client_flags
.no_resizebar
= 1;
353 /* set GNUstep window attributes */
354 if (wwin
->wm_gnustep_attr
) {
355 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
357 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
359 *level
= wwin
->wm_gnustep_attr
->window_level
;
361 * INT_MIN is the only illegal window level.
363 if (*level
== INT_MIN
)
364 *level
= INT_MIN
+ 1;
367 *level
= WMNormalLevel
;
370 int tmp_workspace
= -1;
371 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
374 wMWMCheckClientHints(wwin
);
375 #endif /* USE_MWM_HINTS */
377 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
379 if (wPreferences
.ignore_gtk_decoration_hints
)
380 discard_hints_from_gtk(wwin
);
382 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
383 * have INT_MIN that means that no window level was requested. -Dan
385 if (tmp_level
== INT_MIN
) {
386 if (WFLAGP(wwin
, floating
))
387 *level
= WMFloatingLevel
;
388 else if (WFLAGP(wwin
, sunken
))
389 *level
= WMSunkenLevel
;
391 *level
= WMNormalLevel
;
396 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
397 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
398 if (transientOwner
) {
399 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
400 if (ownerLevel
> *level
)
405 if (tmp_workspace
>= 0)
406 *workspace
= tmp_workspace
% scr
->workspace_count
;
410 * Set attributes specified only for that window/class.
411 * This might do duplicate work with the 1st wDefaultFillAttributes().
413 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
414 &wwin
->defined_user_flags
, False
);
416 * Sanity checks for attributes that depend on other attributes
418 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
419 wwin
->user_flags
.emulate_appicon
= 0;
421 if (wwin
->main_window
!= None
) {
422 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
423 if (wapp
&& !wapp
->flags
.emulated
)
424 wwin
->user_flags
.emulate_appicon
= 0;
427 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
428 wwin
->user_flags
.emulate_appicon
= 0;
430 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
431 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
432 wwin
->user_flags
.sunken
= 0;
434 /* A window that does not have a title cannot be Shaded and we don't let user override this */
435 wwin
->client_flags
.no_shadeable
= WFLAGP(wwin
, no_titlebar
);
436 wwin
->defined_user_flags
.no_shadeable
= 0;
438 /* windows that have takefocus=False shouldn't take focus at all */
439 if (wwin
->focus_mode
== WFM_NO_INPUT
)
440 wwin
->client_flags
.no_focusable
= 1;
443 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
447 w1
= wwin
->frame
->core
->width
;
448 h1
= wwin
->frame
->core
->height
;
449 w2
= obscured
->frame
->core
->width
;
450 h2
= obscured
->frame
->core
->height
;
452 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
453 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
456 if (wwin
->frame_x
+ w1
< obscured
->frame_x
457 || wwin
->frame_y
+ h1
< obscured
->frame_y
458 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
464 static void fixLeaderProperties(WWindow
*wwin
)
466 XClassHint
*classHint
;
467 XWMHints
*hints
, *clientHints
;
468 XWindowAttributes attr
;
469 Window leaders
[2], window
;
470 char **argv
, *command
;
474 classHint
= XAllocClassHint();
475 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
476 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
478 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
482 leaders
[0] = wwin
->client_leader
;
483 leaders
[1] = wwin
->group_id
;
486 command
= GetCommandForWindow(wwin
->client_win
);
488 wfree(command
); /* command already set. nothing to do. */
490 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
493 for (i
= 0; i
< 2; i
++) {
496 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
497 classHint
->res_name
= wwin
->wm_instance
;
498 classHint
->res_class
= wwin
->wm_class
;
499 XSetClassHint(dpy
, window
, classHint
);
501 hints
= XGetWMHints(dpy
, window
);
504 } else if (clientHints
) {
505 /* set window group leader to self */
506 clientHints
->window_group
= window
;
507 clientHints
->flags
|= WindowGroupHint
;
508 XSetWMHints(dpy
, window
, clientHints
);
512 command
= GetCommandForWindow(window
);
514 wfree(command
); /* command already set. nothing to do. */
516 XSetCommand(dpy
, window
, argv
, argc
);
519 /* Make sure we get notification when this window is destroyed */
520 if (XGetWindowAttributes(dpy
, window
, &attr
))
521 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
532 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
534 XClassHint
*classHint
;
540 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
542 classHint
= XAllocClassHint();
543 classHint
->res_name
= instance
;
544 classHint
->res_class
= class;
545 XSetClassHint(dpy
, leader
, classHint
);
548 /* inherit these from the original leader if available */
549 hints
= XGetWMHints(dpy
, win
);
551 hints
= XAllocWMHints();
554 /* set window group leader to self */
555 hints
->window_group
= leader
;
556 hints
->flags
|= WindowGroupHint
;
557 XSetWMHints(dpy
, leader
, hints
);
560 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
561 XSetCommand(dpy
, leader
, argv
, argc
);
562 XFreeStringList(argv
);
568 static int matchIdentifier(const void *item
, const void *cdata
)
570 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
574 *----------------------------------------------------------------
576 * reparents the window and allocates a descriptor for it.
577 * Window manager hints and other hints are fetched to configure
578 * the window decoration attributes and others. User preferences
579 * for the window are used if available, to configure window
580 * decorations and some behaviour.
581 * If in startup, windows that are override redirect,
582 * unmapped and never were managed and are Withdrawn are not
586 * the new window descriptor
589 * The window is reparented and appropriate notification
590 * is done to the client. Input mask for the window is setup.
591 * The window descriptor is also associated with various window
592 * contexts and inserted in the head of the window list.
593 * Event handler contexts are associated for some objects
594 * (buttons, titlebar and resizebar)
596 *----------------------------------------------------------------
598 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
602 unsigned width
, height
;
603 XWindowAttributes wattribs
;
604 XSetWindowAttributes attribs
;
605 WWindowState
*win_state
;
606 WWindow
*transientOwner
= NULL
;
612 Bool withdraw
= False
;
619 /* make sure the window is still there */
620 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
625 /* if it's an override-redirect, ignore it */
626 if (wattribs
.override_redirect
) {
631 wm_state
= PropGetWindowState(window
);
633 /* if it's startup and the window is unmapped, don't manage it */
634 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
639 wwin
= wWindowCreate();
641 title
= wNETWMGetWindowName(window
);
643 wwin
->flags
.net_has_title
= 1;
644 else if (!wFetchName(dpy
, window
, &title
))
647 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
650 if (w_global
.xext
.shape
.supported
) {
655 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
656 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
657 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
658 wwin
->flags
.shaped
= b_shaped
;
662 /* Get hints and other information in properties */
663 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
665 /* setup descriptor */
666 wwin
->client_win
= window
;
667 wwin
->screen_ptr
= scr
;
668 wwin
->old_border_width
= wattribs
.border_width
;
669 wwin
->event_mask
= CLIENT_EVENTS
;
670 attribs
.event_mask
= CLIENT_EVENTS
;
671 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
672 attribs
.save_under
= False
;
674 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
675 XSetWindowBorderWidth(dpy
, window
, 0);
677 /* get hints from GNUstep app */
678 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
679 wwin
->flags
.is_gnustep
= 1;
681 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
682 wwin
->wm_gnustep_attr
= NULL
;
684 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
685 wwin
->flags
.is_dockapp
= 1;
689 wwin
->client_leader
= PropGetClientLeader(window
);
690 if (wwin
->client_leader
!= None
)
691 wwin
->main_window
= wwin
->client_leader
;
693 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
695 if (wwin
->wm_hints
) {
696 if (wwin
->wm_hints
->flags
& StateHint
) {
697 if (wwin
->wm_hints
->initial_state
== IconicState
) {
698 wwin
->flags
.miniaturized
= 1;
699 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
700 wwin
->flags
.is_dockapp
= 1;
705 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
706 wwin
->group_id
= wwin
->wm_hints
->window_group
;
707 /* window_group has priority over CLIENT_LEADER */
708 wwin
->main_window
= wwin
->group_id
;
710 wwin
->group_id
= None
;
713 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
714 wwin
->flags
.urgent
= 1;
715 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
718 wwin
->group_id
= None
;
721 PropGetProtocols(window
, &wwin
->protocols
);
723 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
724 wwin
->transient_for
= None
;
726 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
727 wwin
->transient_for
= scr
->root_win
;
729 transientOwner
= wWindowFor(wwin
->transient_for
);
730 if (transientOwner
&& transientOwner
->main_window
!= None
)
731 wwin
->main_window
= transientOwner
->main_window
;
735 /* guess the focus mode */
736 wwin
->focus_mode
= getFocusMode(wwin
);
738 /* get geometry stuff */
739 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
741 /* get colormap windows */
742 GetColormapWindows(wwin
);
745 * Setup the decoration/window attributes and
748 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
750 /* Make broken apps behave as a nice app. */
751 if (WFLAGP(wwin
, emulate_appicon
))
752 wwin
->main_window
= wwin
->client_win
;
754 fixLeaderProperties(wwin
);
756 wwin
->orig_main_window
= wwin
->main_window
;
758 if (wwin
->flags
.is_gnustep
)
759 wwin
->client_flags
.shared_appicon
= 0;
761 if (wwin
->main_window
) {
762 XTextProperty text_prop
;
764 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, w_global
.atom
.wmaker
.menu
))
765 wwin
->client_flags
.shared_appicon
= 0;
768 if (wwin
->flags
.is_dockapp
)
769 wwin
->client_flags
.shared_appicon
= 0;
771 if (wwin
->main_window
) {
772 WApplication
*app
= wApplicationOf(wwin
->main_window
);
773 if (app
&& app
->app_icon
)
774 wwin
->client_flags
.shared_appicon
= 0;
777 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
778 char *buffer
, *instance
, *class;
779 WFakeGroupLeader
*fPtr
;
782 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
784 /* // only enter here if PropGetWMClass() succeeds */
785 PropGetWMClass(wwin
->main_window
, &class, &instance
);
786 buffer
= StrConcatDot(instance
, class);
788 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
789 if (index
!= WANotFound
) {
790 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
791 if (fPtr
->retainCount
== 0)
792 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
796 if (fPtr
->origLeader
== None
) {
797 if (ADEQUATE(wwin
->main_window
)) {
799 fPtr
->origLeader
= wwin
->main_window
;
802 wwin
->fake_group
= fPtr
;
803 wwin
->main_window
= fPtr
->leader
;
806 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
808 fPtr
->identifier
= buffer
;
809 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
810 fPtr
->origLeader
= None
;
811 fPtr
->retainCount
= 1;
813 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
815 if (ADEQUATE(wwin
->main_window
)) {
817 fPtr
->origLeader
= wwin
->main_window
;
819 wwin
->fake_group
= fPtr
;
820 wwin
->main_window
= fPtr
->leader
;
832 * Setup the initial state of the window
834 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
835 wwin
->flags
.miniaturized
= 1;
837 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
838 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
840 wNETWMCheckInitialClientState(wwin
);
842 /* apply previous state if it exists and we're in startup */
843 if (scr
->flags
.startup
&& wm_state
>= 0) {
844 if (wm_state
== IconicState
)
845 wwin
->flags
.miniaturized
= 1;
846 else if (wm_state
== WithdrawnState
)
850 /* if there is a saved state (from file), restore it */
852 if (wwin
->main_window
!= None
)
853 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
855 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
857 if (win_state
&& !withdraw
) {
858 if (win_state
->state
->hidden
> 0)
859 wwin
->flags
.hidden
= win_state
->state
->hidden
;
861 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
862 wwin
->flags
.shaded
= win_state
->state
->shaded
;
864 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
865 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
867 if (!IS_OMNIPRESENT(wwin
)) {
868 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
870 if (w
< 0 || w
>= scr
->workspace_count
) {
871 workspace
= win_state
->state
->workspace
;
872 if (workspace
>= scr
->workspace_count
)
873 workspace
= scr
->current_workspace
;
878 workspace
= scr
->current_workspace
;
882 /* if we're restarting, restore saved state (from hints).
883 * This will overwrite previous */
887 if (getSavedState(window
, &wstate
)) {
888 wwin
->flags
.shaded
= wstate
->shaded
;
889 wwin
->flags
.hidden
= wstate
->hidden
;
890 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
891 wwin
->flags
.maximized
= wstate
->maximized
;
892 if (wwin
->flags
.maximized
) {
893 wwin
->old_geometry
.x
= wstate
->x
;
894 wwin
->old_geometry
.y
= wstate
->y
;
895 wwin
->old_geometry
.width
= wstate
->w
;
896 wwin
->old_geometry
.height
= wstate
->h
;
899 workspace
= wstate
->workspace
;
904 /* restore window shortcut */
905 if (wstate
!= NULL
|| win_state
!= NULL
) {
908 if (win_state
!= NULL
)
909 mask
= win_state
->state
->window_shortcuts
;
911 if (wstate
!= NULL
&& mask
== 0)
912 mask
= wstate
->window_shortcuts
;
917 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
918 if (mask
& (1 << i
)) {
919 if (!scr
->shortcutWindows
[i
])
920 scr
->shortcutWindows
[i
] = WMCreateArray(4);
922 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
932 /* don't let transients start miniaturized if their owners are not */
933 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
934 wwin
->flags
.miniaturized
= 0;
936 wwin
->wm_hints
->initial_state
= NormalState
;
939 /* set workspace on which the window starts */
940 if (workspace
>= 0) {
941 if (workspace
> scr
->workspace_count
- 1)
942 workspace
= workspace
% scr
->workspace_count
;
946 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
948 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
951 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
952 workspace
= transientOwner
->frame
->workspace
;
954 workspace
= scr
->current_workspace
;
958 /* setup window geometry */
959 if (win_state
&& win_state
->state
->w
> 0) {
960 width
= win_state
->state
->w
;
961 height
= win_state
->state
->h
;
964 wWindowConstrainSize(wwin
, &width
, &height
);
966 /* do not ask for window placement if the window is
967 * transient, during startup, or if the window wants
968 * to start iconic. If geometry was saved, restore it. */
970 Bool dontBring
= False
;
972 if (win_state
&& win_state
->state
->w
> 0) {
973 x
= win_state
->state
->x
;
974 y
= win_state
->state
->y
;
975 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
976 && !scr
->flags
.startup
977 && !wwin
->flags
.miniaturized
978 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
980 if (transientOwner
&& transientOwner
->flags
.mapped
) {
981 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
985 x
= transientOwner
->frame_x
+
986 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
987 y
= transientOwner
->frame_y
+
988 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
990 /* limit transient windows to be inside their parent's head */
991 rect
.pos
.x
= transientOwner
->frame_x
;
992 rect
.pos
.y
= transientOwner
->frame_y
;
993 rect
.size
.width
= transientOwner
->frame
->core
->width
;
994 rect
.size
.height
= transientOwner
->frame
->core
->height
;
996 head
= wGetHeadForRect(scr
, rect
);
997 rect
= wGetRectForHead(scr
, head
);
1001 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1002 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1006 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1007 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1010 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1013 if (wPreferences
.window_placement
== WPM_MANUAL
)
1016 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1021 /* Make spash screens come out in the center of a head
1022 * trouble is that most splashies never get here
1023 * they are managed trough atoms but god knows where.
1024 * Dan, do you know ? -peter
1026 * Most of them are not managed, they have set
1027 * OverrideRedirect, which means we can't do anything about
1030 /* xinerama checks for: across head and dead space */
1033 rect
.size
.width
= width
;
1034 rect
.size
.height
= height
;
1036 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1038 if (flags
& XFLAG_DEAD
)
1041 if (flags
& XFLAG_MULTIPLE
)
1045 switch (reposition
) {
1047 head
= wGetHeadForPointerLocation(scr
);
1048 rect
= wGetRectForHead(scr
, head
);
1050 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1051 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1055 rect
= wGetRectForHead(scr
, head
);
1059 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1060 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1064 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1065 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1074 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1075 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1078 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1080 if (wwin
->flags
.urgent
) {
1081 if (!IS_OMNIPRESENT(wwin
))
1082 wwin
->flags
.omnipresent
^= 1;
1085 /* Create frame, borders and do reparenting */
1086 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1087 #ifdef XKB_BUTTON_HINT
1088 if (wPreferences
.modelock
)
1089 foo
|= WFF_LANGUAGE_BUTTON
;
1091 if (HAS_TITLEBAR(wwin
))
1092 foo
|= WFF_TITLEBAR
;
1094 if (HAS_RESIZEBAR(wwin
))
1095 foo
|= WFF_RESIZEBAR
;
1097 if (HAS_BORDER(wwin
))
1100 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1101 x
, y
, width
, height
,
1102 &wPreferences
.window_title_clearance
,
1103 &wPreferences
.window_title_min_height
,
1104 &wPreferences
.window_title_max_height
,
1106 scr
->window_title_texture
,
1107 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1108 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1110 wwin
->frame
->flags
.is_client_window_frame
= 1;
1111 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1113 wNETWMCheckInitialFrameState(wwin
);
1115 /* setup button images */
1116 wWindowUpdateButtonImages(wwin
);
1118 /* hide unused buttons */
1120 if (WFLAGP(wwin
, no_close_button
))
1121 foo
|= WFF_RIGHT_BUTTON
;
1123 if (WFLAGP(wwin
, no_miniaturize_button
))
1124 foo
|= WFF_LEFT_BUTTON
;
1126 #ifdef XKB_BUTTON_HINT
1127 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1128 foo
|= WFF_LANGUAGE_BUTTON
;
1131 wFrameWindowHideButton(wwin
->frame
, foo
);
1133 wwin
->frame
->child
= wwin
;
1134 wwin
->frame
->workspace
= workspace
;
1135 wwin
->frame
->on_click_left
= windowIconifyClick
;
1137 #ifdef XKB_BUTTON_HINT
1138 if (wPreferences
.modelock
)
1139 wwin
->frame
->on_click_language
= windowLanguageClick
;
1142 wwin
->frame
->on_click_right
= windowCloseClick
;
1143 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1144 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1145 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1146 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1148 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1149 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1150 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1155 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1157 /* if gravity is to the south, account for the border sizes */
1159 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1163 * wWindowConfigure() will init the client window's size
1164 * (wwin->client.{width,height}) and all other geometry
1165 * related variables (frame_x,frame_y) */
1166 wWindowConfigure(wwin
, x
, y
, width
, height
);
1168 /* to make sure the window receives it's new position after reparenting */
1169 wWindowSynthConfigureNotify(wwin
);
1171 /* Setup descriptors and save window to internal lists */
1172 if (wwin
->main_window
!= None
) {
1176 /* Leader windows do not necessary set themselves as leaders.
1177 * If this is the case, point the leader of this window to
1179 leader
= wWindowFor(wwin
->main_window
);
1180 if (leader
&& leader
->main_window
== None
)
1181 leader
->main_window
= leader
->client_win
;
1183 app
= wApplicationCreate(wwin
);
1185 app
->last_workspace
= workspace
;
1187 /* Do application specific stuff, like setting application
1188 * wide attributes. */
1190 if (wwin
->flags
.hidden
) {
1191 /* if the window was set to hidden because it was hidden
1192 * in a previous incarnation and that state was restored */
1193 app
->flags
.hidden
= 1;
1194 } else if (app
->flags
.hidden
) {
1195 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1196 wwin
->flags
.hidden
= 1;
1198 wUnhideApplication(app
, False
, False
);
1206 /* setup the frame descriptor */
1207 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1208 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1209 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1211 /* don't let windows go away if we die */
1212 XAddToSaveSet(dpy
, window
);
1214 XLowerWindow(dpy
, window
);
1216 /* if window is in this workspace and should be mapped, then map it */
1217 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1218 && !wwin
->flags
.hidden
&& !withdraw
) {
1220 /* The following "if" is to avoid crashing of clients that expect
1221 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1222 * after the return from this function. */
1223 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1224 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1226 wClientSetState(wwin
, NormalState
, None
);
1228 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1229 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1231 * The brain damaged idiotic non-click to focus modes will
1232 * have trouble with this because:
1234 * 1. window is created and mapped by the client
1235 * 2. window is mapped by wmaker in small size
1236 * 3. window is animated to grow to normal size
1237 * 4. this function returns to normal event loop
1238 * 5. eventually, the EnterNotify event that would trigger
1239 * the window focusing (if the mouse is over that window)
1240 * will be processed by wmaker.
1241 * But since this event will be rather delayed
1242 * (step 3 has a large delay) the time when the event occurred
1243 * and when it is processed, the client that owns that window
1244 * will reject the XSetInputFocus() for it.
1246 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1247 DoWindowBirth(wwin
);
1252 /* setup stacking descriptor */
1254 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1256 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1258 if (!scr
->focused_window
) {
1259 /* first window on the list */
1262 scr
->focused_window
= wwin
;
1266 /* add window at beginning of focus window list */
1267 tmp
= scr
->focused_window
;
1276 /* raise is set to true if we un-hid the app when this window was born.
1277 * we raise, else old windows of this app will be above this new one. */
1279 wRaiseFrame(wwin
->frame
->core
);
1281 /* Update name must come after WApplication stuff is done */
1282 wWindowUpdateName(wwin
, title
);
1288 /* Final preparations before window is ready to go */
1289 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1291 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1292 if (((transientOwner
&& transientOwner
->flags
.focused
)
1293 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1295 /* only auto_focus if on same screen as mouse
1296 * (and same head for xinerama mode)
1297 * TODO: make it an option */
1299 /*TODO add checking the head of the window, is it available? */
1300 short same_screen
= 0, same_head
= 1;
1306 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1307 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1310 if (same_screen
== 1 && same_head
== 1)
1311 wSetFocusTo(scr
, wwin
);
1314 wWindowResetMouseGrabs(wwin
);
1316 if (!WFLAGP(wwin
, no_bind_keys
))
1317 wWindowSetKeyGrabs(wwin
);
1319 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1320 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1322 /* Setup Notification Observers */
1323 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1325 /* Cleanup temporary stuff */
1327 wWindowDeleteSavedState(win_state
);
1329 /* If the window must be withdrawed, then do it now.
1330 * Must do some optimization, 'though */
1332 wwin
->flags
.mapped
= 0;
1333 wClientSetState(wwin
, WithdrawnState
, None
);
1334 wUnmanageWindow(wwin
, True
, False
);
1341 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1342 const char *title
, int x
, int y
, int width
, int height
)
1347 wwin
= wWindowCreate();
1349 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1351 wwin
->flags
.internal_window
= 1;
1353 wwin
->client_flags
.omnipresent
= 1;
1354 wwin
->client_flags
.no_shadeable
= 1;
1355 wwin
->client_flags
.no_resizable
= 1;
1356 wwin
->client_flags
.no_miniaturizable
= 1;
1358 wwin
->focus_mode
= WFM_PASSIVE
;
1359 wwin
->client_win
= window
;
1360 wwin
->screen_ptr
= scr
;
1361 wwin
->transient_for
= owner
;
1364 wwin
->client
.width
= width
;
1365 wwin
->client
.height
= height
;
1366 wwin
->frame_x
= wwin
->client
.x
;
1367 wwin
->frame_y
= wwin
->client
.y
;
1369 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1370 foo
|= WFF_TITLEBAR
;
1371 #ifdef XKB_BUTTON_HINT
1372 foo
|= WFF_LANGUAGE_BUTTON
;
1375 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1376 wwin
->frame_x
, wwin
->frame_y
,
1378 &wPreferences
.window_title_clearance
,
1379 &wPreferences
.window_title_min_height
,
1380 &wPreferences
.window_title_max_height
,
1382 scr
->window_title_texture
,
1383 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1384 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1386 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
1388 wwin
->frame
->flags
.is_client_window_frame
= 1;
1389 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1391 wFrameWindowChangeTitle(wwin
->frame
, title
);
1393 /* setup button images */
1394 wWindowUpdateButtonImages(wwin
);
1397 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1399 wwin
->frame
->child
= wwin
;
1400 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1402 #ifdef XKB_BUTTON_HINT
1403 if (wPreferences
.modelock
)
1404 wwin
->frame
->on_click_language
= windowLanguageClick
;
1407 wwin
->frame
->on_click_right
= windowCloseClick
;
1408 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1409 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1410 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1411 wwin
->client
.y
+= wwin
->frame
->top_width
;
1413 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1414 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1416 /* setup the frame descriptor */
1417 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1418 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1419 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1421 XLowerWindow(dpy
, window
);
1422 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1424 /* setup stacking descriptor */
1425 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1427 tmp
= wWindowFor(wwin
->transient_for
);
1429 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1431 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1434 if (!scr
->focused_window
) {
1435 /* first window on the list */
1438 scr
->focused_window
= wwin
;
1442 /* add window at beginning of focus window list */
1443 tmp
= scr
->focused_window
;
1451 if (wwin
->flags
.is_gnustep
== 0)
1452 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1454 /* if (wPreferences.auto_focus) */
1455 wSetFocusTo(scr
, wwin
);
1456 wWindowResetMouseGrabs(wwin
);
1457 wWindowSetKeyGrabs(wwin
);
1463 *----------------------------------------------------------------------
1465 * Removes the frame window from a window and destroys all data
1466 * related to it. The window will be reparented back to the root window
1467 * if restore is True.
1470 * Everything related to the window is destroyed and the window
1471 * is removed from the window lists. Focus is set to the previous on the
1473 *----------------------------------------------------------------------
1475 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1477 WCoreWindow
*frame
= wwin
->frame
->core
;
1478 WWindow
*owner
= NULL
;
1479 WWindow
*newFocusedWindow
= NULL
;
1481 WScreen
*scr
= wwin
->screen_ptr
;
1483 /* First close attribute editor window if open */
1484 if (wwin
->flags
.inspector_open
)
1485 wCloseInspectorForWindow(wwin
);
1487 /* Close window menu if it's open for this window */
1488 if (wwin
->flags
.menu_open_for_me
)
1489 CloseWindowMenu(scr
);
1491 /* Don't restore focus to this window after a window exits
1492 * fullscreen mode */
1493 if (scr
->bfs_focused_window
== wwin
)
1494 scr
->bfs_focused_window
= NULL
;
1497 if (!wwin
->flags
.internal_window
)
1498 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1500 /* If this is a leader window, we still need to listen for
1501 * DestroyNotify and PropertyNotify. */
1502 if (wApplicationOf(wwin
->client_win
))
1503 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1505 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1507 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1508 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1511 XUnmapWindow(dpy
, frame
->window
);
1513 XUnmapWindow(dpy
, wwin
->client_win
);
1515 /* deselect window */
1516 wSelectWindow(wwin
, False
);
1518 /* remove all pending events on window */
1519 /* I think this only matters for autoraise */
1520 if (wPreferences
.raise_delay
)
1521 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1525 /* reparent the window back to the root */
1527 wClientRestore(wwin
);
1529 if (wwin
->transient_for
!= scr
->root_win
) {
1530 owner
= wWindowFor(wwin
->transient_for
);
1532 if (!owner
->flags
.semi_focused
)
1535 owner
->flags
.semi_focused
= 0;
1539 wasFocused
= wwin
->flags
.focused
;
1541 /* remove from window focus list */
1542 if (!wwin
->prev
&& !wwin
->next
) {
1543 /* was the only window */
1544 scr
->focused_window
= NULL
;
1545 newFocusedWindow
= NULL
;
1550 wwin
->prev
->next
= wwin
->next
;
1553 wwin
->next
->prev
= wwin
->prev
;
1555 scr
->focused_window
= wwin
->prev
;
1556 scr
->focused_window
->next
= NULL
;
1559 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1561 /* if in click to focus mode and the window
1562 * was a transient, focus the owner window
1565 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1566 tmp
= wWindowFor(wwin
->transient_for
);
1567 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1571 /* otherwise, focus the next one in the focus list */
1573 tmp
= scr
->focused_window
;
1574 while (tmp
) { /* look for one in the window list first */
1575 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1576 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1580 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1581 tmp
= scr
->focused_window
;
1583 if (!WFLAGP(tmp
, no_focusable
)
1584 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1591 newFocusedWindow
= tmp
;
1593 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1598 /* This is to let the root window get the keyboard input
1599 * if Sloppy focus mode and no other window get focus.
1600 * This way keybindings will not freeze.
1603 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1604 tmp
= wWindowFor(win
);
1607 newFocusedWindow
= tmp
;
1609 newFocusedWindow
= NULL
;
1613 if (!wwin
->flags
.internal_window
)
1614 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1616 if (newFocusedWindow
!= owner
&& owner
) {
1617 if (wwin
->flags
.is_gnustep
== 0)
1618 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1620 wSetFocusTo(scr
, newFocusedWindow
);
1623 /* Close menu and unhighlight */
1624 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1625 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1626 if (oapp
&& oapp
!= napp
) {
1627 wAppMenuUnmap(oapp
->menu
);
1628 if (wPreferences
.highlight_active_app
)
1629 wApplicationDeactivate(oapp
);
1632 wNETCleanupFrameExtents(wwin
);
1634 wWindowDestroy(wwin
);
1638 void wWindowMap(WWindow
*wwin
)
1640 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1641 if (!wwin
->flags
.shaded
) {
1642 /* window will be remapped when getting MapNotify */
1643 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1644 XMapWindow(dpy
, wwin
->client_win
);
1645 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1647 wwin
->flags
.mapped
= 1;
1651 void wWindowUnmap(WWindow
*wwin
)
1653 wwin
->flags
.mapped
= 0;
1655 /* prevent window withdrawal when getting UnmapNotify */
1656 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1657 XUnmapWindow(dpy
, wwin
->client_win
);
1658 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1660 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1663 void wWindowSingleFocus(WWindow
*wwin
)
1671 scr
= wwin
->screen_ptr
;
1672 wMakeWindowVisible(wwin
);
1677 /* bring window back to visible area */
1678 move
= wScreenBringInside(scr
, &x
, &y
, wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1681 wWindowConfigure(wwin
, x
, y
, wwin
->client
.width
, wwin
->client
.height
);
1685 void wWindowFocusPrev(WWindow
*wwin
, Bool inSameWorkspace
)
1689 if (!wwin
|| !wwin
->prev
)
1696 if (inSameWorkspace
)
1697 while (tmp
&& (tmp
->frame
->workspace
!= wwin
->frame
->workspace
))
1700 wWindowSingleFocus(tmp
);
1703 void wWindowFocusNext(WWindow
*wwin
, Bool inSameWorkspace
)
1707 if (!wwin
|| !wwin
->prev
)
1711 if (inSameWorkspace
)
1712 while (tmp
&& (tmp
->frame
->workspace
!= wwin
->frame
->workspace
))
1715 wWindowSingleFocus(tmp
);
1718 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1723 #ifdef KEEP_XKB_LOCK_STATUS
1724 if (wPreferences
.modelock
)
1725 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1726 #endif /* KEEP_XKB_LOCK_STATUS */
1728 wwin
->flags
.semi_focused
= 0;
1730 if (wwin
->flags
.is_gnustep
== 0)
1731 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1733 wwin
->flags
.focused
= 1;
1735 wWindowResetMouseGrabs(wwin
);
1737 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1739 if (owin
== wwin
|| !owin
)
1742 nowner
= wWindowFor(wwin
->transient_for
);
1744 /* new window is a transient for the old window */
1745 if (nowner
== owin
) {
1746 owin
->flags
.semi_focused
= 1;
1747 wWindowUnfocus(nowner
);
1751 oowner
= wWindowFor(owin
->transient_for
);
1753 /* new window is owner of old window */
1754 if (wwin
== oowner
) {
1755 wWindowUnfocus(owin
);
1760 wWindowUnfocus(owin
);
1764 /* new window has same owner of old window */
1765 if (oowner
== nowner
) {
1766 /* prevent unfocusing of owner */
1767 oowner
->flags
.semi_focused
= 0;
1768 wWindowUnfocus(owin
);
1769 oowner
->flags
.semi_focused
= 1;
1774 /* nowner != NULL && oowner != nowner */
1775 nowner
->flags
.semi_focused
= 1;
1776 wWindowUnfocus(nowner
);
1777 wWindowUnfocus(owin
);
1780 void wWindowUnfocus(WWindow
*wwin
)
1782 CloseWindowMenu(wwin
->screen_ptr
);
1784 if (wwin
->flags
.is_gnustep
== 0)
1785 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1787 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1789 owner
= wWindowFor(wwin
->transient_for
);
1790 if (owner
&& owner
->flags
.semi_focused
) {
1791 owner
->flags
.semi_focused
= 0;
1792 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1793 wWindowUnfocus(owner
);
1794 wFrameWindowPaint(owner
->frame
);
1798 wwin
->flags
.focused
= 0;
1799 wWindowResetMouseGrabs(wwin
);
1800 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1803 void wWindowUpdateName(WWindow
*wwin
, const char *newTitle
)
1811 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1815 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1816 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1820 *----------------------------------------------------------------------
1822 * wWindowConstrainSize--
1823 * Constrains size for the client window, taking the maximal size,
1824 * window resize increments and other size hints into account.
1827 * The closest size to what was given that the client window can
1830 *----------------------------------------------------------------------
1832 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1834 int width
= (int)*nwidth
;
1835 int height
= (int)*nheight
;
1838 int minW
= 1, minH
= 1;
1839 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1840 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1841 int minAX
= -1, minAY
= -1;
1842 int maxAX
= -1, maxAY
= -1;
1846 if (wwin
->normal_hints
) {
1847 winc
= wwin
->normal_hints
->width_inc
;
1848 hinc
= wwin
->normal_hints
->height_inc
;
1849 minW
= wwin
->normal_hints
->min_width
;
1850 minH
= wwin
->normal_hints
->min_height
;
1851 maxW
= wwin
->normal_hints
->max_width
;
1852 maxH
= wwin
->normal_hints
->max_height
;
1853 if (wwin
->normal_hints
->flags
& PAspect
) {
1854 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1855 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1856 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1857 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1860 baseW
= wwin
->normal_hints
->base_width
;
1861 baseH
= wwin
->normal_hints
->base_height
;
1874 /* aspect ratio code borrowed from olwm */
1876 /* adjust max aspect ratio */
1877 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1878 if (maxAX
> maxAY
) {
1879 height
= (width
* maxAY
) / maxAX
;
1880 if (height
> maxH
) {
1882 width
= (height
* maxAX
) / maxAY
;
1885 width
= (height
* maxAX
) / maxAY
;
1888 height
= (width
* maxAY
) / maxAX
;
1893 /* adjust min aspect ratio */
1894 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1895 if (minAX
> minAY
) {
1896 height
= (width
* minAY
) / minAX
;
1897 if (height
< minH
) {
1899 width
= (height
* minAX
) / minAY
;
1902 width
= (height
* minAX
) / minAY
;
1905 height
= (width
* minAY
) / minAX
;
1912 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1914 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1917 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1919 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1921 /* broken stupid apps may cause preposterous values for these.. */
1928 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1929 unsigned int *width
, unsigned int *height
)
1931 int baseW
= 0, baseH
= 0;
1932 int winc
= 1, hinc
= 1;
1934 if (wwin
->normal_hints
) {
1935 baseW
= wwin
->normal_hints
->base_width
;
1936 baseH
= wwin
->normal_hints
->base_height
;
1938 winc
= wwin
->normal_hints
->width_inc
;
1939 hinc
= wwin
->normal_hints
->height_inc
;
1943 *width
= maxW
- (maxW
- baseW
) % winc
;
1946 *height
= maxH
- (maxH
- baseH
) % hinc
;
1949 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1951 WScreen
*scr
= wwin
->screen_ptr
;
1955 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1958 if (workspace
!= scr
->current_workspace
) {
1959 /* Sent to other workspace. Unmap window */
1960 if ((wwin
->flags
.mapped
1961 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1962 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1964 wapp
= wApplicationOf(wwin
->main_window
);
1966 wapp
->last_workspace
= workspace
;
1968 if (wwin
->flags
.miniaturized
) {
1970 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1971 wwin
->icon
->mapped
= 0;
1975 wSetFocusTo(scr
, NULL
);
1979 /* brought to current workspace. Map window */
1980 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1982 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1983 wwin
->icon
->mapped
= 1;
1985 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1989 if (!IS_OMNIPRESENT(wwin
)) {
1990 int oldWorkspace
= wwin
->frame
->workspace
;
1991 wwin
->frame
->workspace
= workspace
;
1992 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1999 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
2001 WScreen
*scr
= wwin
->screen_ptr
;
2002 int w
= scr
->current_workspace
+ amount
;
2006 wWindowChangeWorkspace(wwin
, w
);
2007 } else if (wPreferences
.ws_cycle
) {
2008 wWindowChangeWorkspace(wwin
, scr
->workspace_count
+ w
);
2010 } else if (amount
> 0) {
2011 if (w
< scr
->workspace_count
) {
2012 wWindowChangeWorkspace(wwin
, w
);
2013 } else if (wPreferences
.ws_advance
) {
2014 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
2015 wWorkspaceMake(scr
, workspace
);
2016 wWindowChangeWorkspace(wwin
, workspace
);
2017 } else if (wPreferences
.ws_cycle
) {
2018 wWindowChangeWorkspace(wwin
, w
% scr
->workspace_count
);
2023 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2027 sevent
.type
= ConfigureNotify
;
2028 sevent
.xconfigure
.display
= dpy
;
2029 sevent
.xconfigure
.event
= wwin
->client_win
;
2030 sevent
.xconfigure
.window
= wwin
->client_win
;
2032 sevent
.xconfigure
.x
= wwin
->client
.x
;
2033 sevent
.xconfigure
.y
= wwin
->client
.y
;
2034 sevent
.xconfigure
.width
= wwin
->client
.width
;
2035 sevent
.xconfigure
.height
= wwin
->client
.height
;
2037 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2038 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2039 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2041 sevent
.xconfigure
.above
= None
;
2043 sevent
.xconfigure
.override_redirect
= False
;
2044 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2049 *----------------------------------------------------------------------
2050 * wWindowConfigure()
2052 * req_x, req_y: new requested positions for the frame
2053 * req_width, req_height: new requested sizes for the client
2055 * Configures the frame, decorations and client window to the specified
2056 * geometry, whose validity is not checked -- wWindowConstrainSize()
2057 * must be used for that.
2058 * The size parameters are for the client window, but the position is
2060 * The client window receives a ConfigureNotify event, according
2061 * to what ICCCM says.
2067 * Window size and position are changed and client window receives
2068 * a ConfigureNotify event.
2069 *----------------------------------------------------------------------
2071 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2073 int synth_notify
= False
;
2076 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2078 * if the window is being moved but not resized then
2079 * send a synthetic ConfigureNotify
2081 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
2082 synth_notify
= True
;
2084 if (WFLAGP(wwin
, dont_move_off
))
2085 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2088 if (req_width
< MIN_WINDOW_SIZE
)
2089 req_width
= MIN_WINDOW_SIZE
;
2090 if (req_height
< MIN_WINDOW_SIZE
)
2091 req_height
= MIN_WINDOW_SIZE
;
2093 /* If growing, resize inner part before frame,
2094 * if shrinking, resize frame before.
2095 * This will prevent the frame (that can have a different color)
2096 * to be exposed, causing flicker */
2097 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2098 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2100 if (wwin
->flags
.shaded
) {
2101 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2102 wwin
->old_geometry
.height
= req_height
;
2106 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2108 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2111 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2112 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2114 wwin
->client
.x
= req_x
;
2115 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2116 wwin
->client
.width
= req_width
;
2117 wwin
->client
.height
= req_height
;
2119 wwin
->client
.x
= req_x
;
2120 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2122 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2124 wwin
->frame_x
= req_x
;
2125 wwin
->frame_y
= req_y
;
2126 if (HAS_BORDER(wwin
)) {
2127 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2128 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2131 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
&& resize
)
2132 wWindowSetShape(wwin
);
2136 wWindowSynthConfigureNotify(wwin
);
2138 wNETFrameExtents(wwin
);
2143 /* req_x, req_y: new position of the frame */
2144 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2146 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2147 int synth_notify
= False
;
2149 /* Send a synthetic ConfigureNotify event for every window movement. */
2150 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2151 synth_notify
= True
;
2153 /* A single synthetic ConfigureNotify event is sent at the end of
2154 * a completed (opaque) movement in moveres.c */
2157 if (WFLAGP(wwin
, dont_move_off
))
2158 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2159 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2161 wwin
->client
.x
= req_x
;
2162 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2163 if (HAS_BORDER(wwin
)) {
2164 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2165 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2168 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2170 wwin
->frame_x
= req_x
;
2171 wwin
->frame_y
= req_y
;
2173 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2175 wWindowSynthConfigureNotify(wwin
);
2179 void wWindowUpdateButtonImages(WWindow
*wwin
)
2181 WScreen
*scr
= wwin
->screen_ptr
;
2182 Pixmap pixmap
, mask
;
2183 WFrameWindow
*fwin
= wwin
->frame
;
2185 if (!HAS_TITLEBAR(wwin
))
2188 /* miniaturize button */
2189 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2190 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2191 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2193 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2194 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2198 if (fwin
->lbutton_image
2199 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2200 wPixmapDestroy(fwin
->lbutton_image
);
2201 fwin
->lbutton_image
= NULL
;
2204 if (!fwin
->lbutton_image
) {
2205 fwin
->lbutton_image
= wPixmapCreate(pixmap
, mask
);
2206 fwin
->lbutton_image
->client_owned
= 1;
2207 fwin
->lbutton_image
->client_owned_mask
= 1;
2210 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2211 wPixmapDestroy(fwin
->lbutton_image
);
2213 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2216 #ifdef XKB_BUTTON_HINT
2217 if (!WFLAGP(wwin
, no_language_button
)) {
2218 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2219 wPixmapDestroy(fwin
->languagebutton_image
);
2221 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2227 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2228 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2230 if (!WFLAGP(wwin
, no_close_button
)) {
2231 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2232 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2234 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2235 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2239 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2240 || fwin
->rbutton_image
->mask
!= mask
)) {
2241 wPixmapDestroy(fwin
->rbutton_image
);
2242 fwin
->rbutton_image
= NULL
;
2245 if (!fwin
->rbutton_image
) {
2246 fwin
->rbutton_image
= wPixmapCreate(pixmap
, mask
);
2247 fwin
->rbutton_image
->client_owned
= 1;
2248 fwin
->rbutton_image
->client_owned_mask
= 1;
2251 } else if (WFLAGP(wwin
, kill_close
)) {
2252 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2253 wPixmapDestroy(fwin
->rbutton_image
);
2255 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2257 } else if (MGFLAGP(wwin
, broken_close
)) {
2258 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2259 wPixmapDestroy(fwin
->rbutton_image
);
2261 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2264 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2265 wPixmapDestroy(fwin
->rbutton_image
);
2267 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2271 /* force buttons to be redrawn */
2272 fwin
->flags
.need_texture_change
= 1;
2273 wFrameWindowPaint(fwin
);
2277 *---------------------------------------------------------------------------
2278 * wWindowConfigureBorders--
2279 * Update window border configuration according to attribute flags.
2281 *---------------------------------------------------------------------------
2283 void wWindowConfigureBorders(WWindow
*wwin
)
2289 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2291 #ifdef XKB_BUTTON_HINT
2292 if (wPreferences
.modelock
)
2293 flags
|= WFF_LANGUAGE_BUTTON
;
2296 if (HAS_TITLEBAR(wwin
))
2297 flags
|= WFF_TITLEBAR
;
2298 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2299 flags
|= WFF_RESIZEBAR
;
2300 if (HAS_BORDER(wwin
))
2301 flags
|= WFF_BORDER
;
2302 if (wwin
->flags
.shaded
)
2303 flags
|= WFF_IS_SHADED
;
2304 if (wwin
->flags
.selected
)
2305 flags
|= WFF_SELECTED
;
2307 oldh
= wwin
->frame
->top_width
;
2308 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2309 if (oldh
!= wwin
->frame
->top_width
) {
2310 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2312 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2313 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2317 if (!WFLAGP(wwin
, no_miniaturize_button
)
2318 && wwin
->frame
->flags
.hide_left_button
)
2319 flags
|= WFF_LEFT_BUTTON
;
2321 #ifdef XKB_BUTTON_HINT
2322 if (!WFLAGP(wwin
, no_language_button
)
2323 && wwin
->frame
->flags
.hide_language_button
)
2324 flags
|= WFF_LANGUAGE_BUTTON
;
2327 if (!WFLAGP(wwin
, no_close_button
)
2328 && wwin
->frame
->flags
.hide_right_button
)
2329 flags
|= WFF_RIGHT_BUTTON
;
2332 wWindowUpdateButtonImages(wwin
);
2333 wFrameWindowShowButton(wwin
->frame
, flags
);
2337 if (WFLAGP(wwin
, no_miniaturize_button
)
2338 && !wwin
->frame
->flags
.hide_left_button
)
2339 flags
|= WFF_LEFT_BUTTON
;
2341 #ifdef XKB_BUTTON_HINT
2342 if (WFLAGP(wwin
, no_language_button
)
2343 && !wwin
->frame
->flags
.hide_language_button
)
2344 flags
|= WFF_LANGUAGE_BUTTON
;
2347 if (WFLAGP(wwin
, no_close_button
)
2348 && !wwin
->frame
->flags
.hide_right_button
)
2349 flags
|= WFF_RIGHT_BUTTON
;
2352 wFrameWindowHideButton(wwin
->frame
, flags
);
2355 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
)
2356 wWindowSetShape(wwin
);
2361 void wWindowSaveState(WWindow
*wwin
)
2366 memset(data
, 0, sizeof(long) * 10);
2367 data
[0] = wwin
->frame
->workspace
;
2368 data
[1] = wwin
->flags
.miniaturized
;
2369 data
[2] = wwin
->flags
.shaded
;
2370 data
[3] = wwin
->flags
.hidden
;
2371 data
[4] = wwin
->flags
.maximized
;
2372 if (wwin
->flags
.maximized
== 0) {
2373 data
[5] = wwin
->frame_x
;
2374 data
[6] = wwin
->frame_y
;
2375 data
[7] = wwin
->frame
->core
->width
;
2376 data
[8] = wwin
->frame
->core
->height
;
2378 data
[5] = wwin
->old_geometry
.x
;
2379 data
[6] = wwin
->old_geometry
.y
;
2380 data
[7] = wwin
->old_geometry
.width
;
2381 data
[8] = wwin
->old_geometry
.height
;
2384 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2385 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2386 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2390 XChangeProperty(dpy
, wwin
->client_win
, w_global
.atom
.wmaker
.state
,
2391 w_global
.atom
.wmaker
.state
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2394 static int getSavedState(Window window
, WSavedState
** state
)
2398 unsigned long nitems_ret
;
2399 unsigned long bytes_after_ret
;
2402 if (XGetWindowProperty(dpy
, window
, w_global
.atom
.wmaker
.state
, 0, 10,
2403 True
, w_global
.atom
.wmaker
.state
,
2404 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2405 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2408 if (type_ret
!= w_global
.atom
.wmaker
.state
) {
2413 *state
= wmalloc(sizeof(WSavedState
));
2415 (*state
)->workspace
= data
[0];
2416 (*state
)->miniaturized
= data
[1];
2417 (*state
)->shaded
= data
[2];
2418 (*state
)->hidden
= data
[3];
2419 (*state
)->maximized
= data
[4];
2420 (*state
)->x
= data
[5];
2421 (*state
)->y
= data
[6];
2422 (*state
)->w
= data
[7];
2423 (*state
)->h
= data
[8];
2424 (*state
)->window_shortcuts
= data
[9];
2432 void wWindowClearShape(WWindow
* wwin
)
2434 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2435 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2439 void wWindowSetShape(WWindow
* wwin
)
2443 #ifdef OPTIMIZE_SHAPE
2448 /* only shape is the client's */
2449 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2452 /* Get array of rectangles describing the shape mask */
2453 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2457 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2463 /* insert our decoration rectangles in the rect list */
2464 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2467 if (HAS_TITLEBAR(wwin
)) {
2469 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2470 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2471 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2474 if (HAS_RESIZEBAR(wwin
)) {
2476 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2477 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2478 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2482 /* shape our frame window */
2483 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2484 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2490 #endif /* OPTIMIZE_SHAPE */
2492 if (HAS_TITLEBAR(wwin
)) {
2495 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2496 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2499 if (HAS_RESIZEBAR(wwin
)) {
2501 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2502 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2503 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2507 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2508 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2510 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2511 0, wwin
->frame
->top_width
, wwin
->client_win
,
2512 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2515 #endif /* USE_XSHAPE */
2517 /* ====================================================================== */
2519 static FocusMode
getFocusMode(WWindow
* wwin
)
2523 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2524 if (wwin
->wm_hints
->input
== True
) {
2525 if (wwin
->protocols
.TAKE_FOCUS
)
2526 mode
= WFM_LOCALLY_ACTIVE
;
2530 if (wwin
->protocols
.TAKE_FOCUS
)
2531 mode
= WFM_GLOBALLY_ACTIVE
;
2533 mode
= WFM_NO_INPUT
;
2541 void wWindowSetKeyGrabs(WWindow
* wwin
)
2546 for (i
= 0; i
< WKBD_LAST
; i
++) {
2547 key
= &wKeyBindings
[i
];
2549 if (key
->keycode
== 0)
2551 if (key
->modifier
!= AnyModifier
) {
2552 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2553 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2555 /* Also grab all modifier combinations possible that include,
2556 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2557 * work even if the NumLock/ScrollLock key is on.
2559 wHackedGrabKey(key
->keycode
, key
->modifier
,
2560 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2563 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2564 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2567 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2570 void wWindowResetMouseGrabs(WWindow
* wwin
)
2572 /* Mouse grabs can't be done on the client window because of
2573 * ICCCM and because clients that try to do the same will crash.
2575 * But there is a problem which makes tbar buttons of unfocused
2576 * windows not usable as the click goes to the frame window instead
2577 * of the button itself. Must figure a way to fix that.
2580 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2582 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2583 /* grabs for Meta+drag */
2584 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2585 True
, ButtonPressMask
| ButtonReleaseMask
,
2586 GrabModeSync
, GrabModeAsync
, None
, None
);
2588 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2589 * but we only grab it for Button4 and Button 5 since a lot of apps
2590 * use CTRL+Button1-3 for app related functionality
2592 if (wPreferences
.resize_increment
> 0) {
2593 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2594 True
, ButtonPressMask
| ButtonReleaseMask
,
2595 GrabModeSync
, GrabModeAsync
, None
, None
);
2596 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2597 True
, ButtonPressMask
| ButtonReleaseMask
,
2598 GrabModeSync
, GrabModeAsync
, None
, None
);
2600 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2601 True
, ButtonPressMask
| ButtonReleaseMask
,
2602 GrabModeSync
, GrabModeAsync
, None
, None
);
2603 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2604 True
, ButtonPressMask
| ButtonReleaseMask
,
2605 GrabModeSync
, GrabModeAsync
, None
, None
);
2609 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2610 && !wwin
->flags
.is_gnustep
) {
2611 /* the passive grabs to focus the window */
2612 /* if (wPreferences.focus_mode == WKF_CLICK) */
2613 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2614 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2619 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2621 if (attr
->flags
& GSExtraFlagsAttr
) {
2622 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2623 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2624 wWindowUpdateButtonImages(wwin
);
2629 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2630 const char *command
, pid_t pid
, WSavedState
* state
)
2632 WWindowState
*wstate
;
2634 wstate
= malloc(sizeof(WWindowState
));
2638 memset(wstate
, 0, sizeof(WWindowState
));
2641 wstate
->instance
= wstrdup(instance
);
2643 wstate
->class = wstrdup(class);
2645 wstate
->command
= wstrdup(command
);
2646 wstate
->state
= state
;
2648 wstate
->next
= windowState
;
2649 windowState
= wstate
;
2654 static inline int is_same(const char *x
, const char *y
)
2656 if ((x
== NULL
) && (y
== NULL
))
2659 if ((x
== NULL
) || (y
== NULL
))
2662 if (strcmp(x
, y
) == 0)
2668 WMagicNumber
wWindowGetSavedState(Window win
)
2670 char *instance
, *class, *command
= NULL
;
2671 WWindowState
*wstate
= windowState
;
2676 command
= GetCommandForWindow(win
);
2680 if (PropGetWMClass(win
, &class, &instance
)) {
2682 if (is_same(instance
, wstate
->instance
) &&
2683 is_same(class, wstate
->class) &&
2684 is_same(command
, wstate
->command
)) {
2687 wstate
= wstate
->next
;
2703 void wWindowDeleteSavedState(WMagicNumber id
)
2705 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2707 if (!wstate
|| !windowState
)
2711 if (tmp
== wstate
) {
2712 windowState
= wstate
->next
;
2713 release_wwindowstate(wstate
);
2716 if (tmp
->next
== wstate
) {
2717 tmp
->next
= wstate
->next
;
2718 release_wwindowstate(wstate
);
2726 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2728 WWindowState
*tmp
, *wstate
;
2734 if (tmp
->pid
== pid
) {
2735 wstate
= windowState
;
2736 windowState
= tmp
->next
;
2738 release_wwindowstate(wstate
);
2741 if (tmp
->next
->pid
== pid
) {
2743 tmp
->next
= wstate
->next
;
2744 release_wwindowstate(wstate
);
2752 static void release_wwindowstate(WWindowState
*wstate
)
2754 if (wstate
->instance
)
2755 wfree(wstate
->instance
);
2758 wfree(wstate
->class);
2760 if (wstate
->command
)
2761 wfree(wstate
->command
);
2763 wfree(wstate
->state
);
2767 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2769 if (wwin
->flags
.omnipresent
== flag
)
2772 wwin
->flags
.omnipresent
= flag
;
2773 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2776 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2778 WWindow
*wwin
= data
;
2780 /* Parameter not used, but tell the compiler that it is ok */
2783 #ifndef NUMLOCK_HACK
2784 if ((event
->xbutton
.state
& ValidModMask
)
2785 != (event
->xbutton
.state
& ~LockMask
)) {
2786 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2787 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2791 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2793 CloseWindowMenu(wwin
->screen_ptr
);
2795 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2796 && !WFLAGP(wwin
, no_focusable
)) {
2797 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2800 if (event
->xbutton
.button
== Button1
)
2801 wRaiseFrame(wwin
->frame
->core
);
2803 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2804 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2805 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2806 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2811 if (event
->xbutton
.state
& MOD_MASK
) {
2812 /* move the window */
2813 wMouseMoveWindow(wwin
, event
);
2814 XUngrabPointer(dpy
, CurrentTime
);
2816 wMouseResizeWindow(wwin
, event
);
2817 XUngrabPointer(dpy
, CurrentTime
);
2821 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2823 WWindow
*wwin
= data
;
2825 /* Parameter not used, but tell the compiler that it is ok */
2828 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2830 if (event
->xbutton
.button
== Button1
) {
2831 if (event
->xbutton
.state
== 0) {
2832 if (!WFLAGP(wwin
, no_shadeable
)) {
2834 if (wwin
->flags
.shaded
)
2835 wUnshadeWindow(wwin
);
2842 if (event
->xbutton
.state
& ControlMask
)
2843 dir
|= MAX_VERTICAL
;
2845 if (event
->xbutton
.state
& ShiftMask
) {
2846 dir
|= MAX_HORIZONTAL
;
2847 if (!(event
->xbutton
.state
& ControlMask
))
2848 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2851 /* maximize window */
2852 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2853 int ndir
= dir
^ wwin
->flags
.maximized
;
2856 wMaximizeWindow(wwin
, ndir
);
2858 wUnmaximizeWindow(wwin
);
2861 } else if (event
->xbutton
.button
== Button3
) {
2862 if (event
->xbutton
.state
& MOD_MASK
)
2863 wHideOtherApplications(wwin
);
2864 } else if (event
->xbutton
.button
== Button2
) {
2865 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2866 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2868 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2869 wUnshadeWindow(wwin
);
2873 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2875 WWindow
*wwin
= desc
->parent
;
2876 unsigned int new_width
, w_scale
;
2877 unsigned int new_height
, h_scale
;
2878 unsigned int resize_width_increment
= 0;
2879 unsigned int resize_height_increment
= 0;
2881 if (wwin
->normal_hints
) {
2882 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2883 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2884 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2885 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2887 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2888 resize_width_increment
= wPreferences
.resize_increment
;
2889 resize_height_increment
= wPreferences
.resize_increment
;
2892 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2894 CloseWindowMenu(wwin
->screen_ptr
);
2896 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2897 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2899 if (event
->xbutton
.button
== Button1
)
2900 wRaiseFrame(wwin
->frame
->core
);
2902 if (event
->xbutton
.state
& ControlMask
) {
2903 if (event
->xbutton
.button
== Button4
) {
2904 new_width
= wwin
->client
.width
- resize_width_increment
;
2905 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2906 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2908 if (event
->xbutton
.button
== Button5
) {
2909 new_width
= wwin
->client
.width
+ resize_width_increment
;
2910 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2911 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2915 if (event
->xbutton
.state
& MOD_MASK
) {
2916 /* move the window */
2917 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2918 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2919 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2922 if (event
->xbutton
.button
== Button3
) {
2923 wMouseResizeWindow(wwin
, event
);
2924 } else if (event
->xbutton
.button
== Button4
) {
2925 new_height
= wwin
->client
.height
- resize_height_increment
;
2926 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2927 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2928 } else if (event
->xbutton
.button
== Button5
) {
2929 new_height
= wwin
->client
.height
+ resize_height_increment
;
2930 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2931 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2932 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2933 wMouseMoveWindow(wwin
, event
);
2935 XUngrabPointer(dpy
, CurrentTime
);
2939 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2941 WWindow
*wwin
= (WWindow
*) data
;
2943 /* Parameter not used, but tell the compiler that it is ok */
2946 #ifndef NUMLOCK_HACK
2947 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2948 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2949 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2951 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2953 CloseWindowMenu(wwin
->screen_ptr
);
2955 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2956 && !WFLAGP(wwin
, no_focusable
))
2957 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2959 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2961 if (event
->xbutton
.button
== Button1
) {
2962 if (event
->xbutton
.state
& MOD_MASK
)
2963 wLowerFrame(wwin
->frame
->core
);
2965 wRaiseFrame(wwin
->frame
->core
);
2967 if ((event
->xbutton
.state
& ShiftMask
)
2968 && !(event
->xbutton
.state
& ControlMask
)) {
2969 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2972 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2973 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2974 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2975 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2979 /* move the window */
2980 wMouseMoveWindow(wwin
, event
);
2982 XUngrabPointer(dpy
, CurrentTime
);
2983 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2984 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2985 WObjDescriptor
*desc
;
2987 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2988 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2989 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2990 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2994 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2996 /* allow drag select */
2997 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2998 event
->xany
.send_event
= True
;
2999 (*desc
->handle_mousedown
) (desc
, event
);
3001 XUngrabPointer(dpy
, CurrentTime
);
3005 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3007 WWindow
*wwin
= data
;
3009 /* Parameter not used, but tell the compiler that it is ok */
3012 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
3014 CloseWindowMenu(wwin
->screen_ptr
);
3016 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3019 /* if control-click, kill the client */
3020 if (event
->xbutton
.state
& ControlMask
) {
3023 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
3024 /* send delete message */
3025 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
3026 w_global
.timestamp
.last_event
);
3031 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3033 WWindow
*wwin
= data
;
3035 /* Parameter not used, but tell the compiler that it is ok */
3038 CloseWindowMenu(wwin
->screen_ptr
);
3040 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3043 /* send delete message */
3044 if (wwin
->protocols
.DELETE_WINDOW
)
3045 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
3046 w_global
.timestamp
.last_event
);
3051 #ifdef XKB_BUTTON_HINT
3052 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3054 WWindow
*wwin
= data
;
3055 WFrameWindow
*fwin
= wwin
->frame
;
3056 WScreen
*scr
= fwin
->screen_ptr
;
3059 /* Parameter not used, but tell the compiler that it is ok */
3062 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3064 tl
= wwin
->frame
->languagemode
;
3065 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3066 wwin
->frame
->last_languagemode
= tl
;
3067 wSetFocusTo(scr
, wwin
);
3068 wwin
->frame
->languagebutton_image
=
3069 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3070 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3071 if (event
->xbutton
.button
== Button3
)
3073 wRaiseFrame(fwin
->core
);
3077 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3079 WWindow
*wwin
= data
;
3081 /* Parameter not used, but tell the compiler that it is ok */
3084 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
3086 CloseWindowMenu(wwin
->screen_ptr
);
3088 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3091 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3092 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
3093 w_global
.timestamp
.last_event
);
3096 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3098 wapp
= wApplicationOf(wwin
->main_window
);
3099 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3100 wHideApplication(wapp
);
3101 } else if (event
->xbutton
.state
== 0) {
3102 wIconifyWindow(wwin
);