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"
56 #include "workspace.h"
66 #define MOD_MASK wPreferences.modifier_mask
68 /****** Global Variables ******/
69 extern WShortKey wKeyBindings
[WKBD_LAST
];
72 extern Bool wShapeSupported
;
76 extern XContext wWinContext
;
79 extern Atom _XA_WM_DELETE_WINDOW
;
80 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
81 extern Atom _XA_WINDOWMAKER_STATE
;
82 extern WPreferences wPreferences
;
83 extern Time LastTimestamp
;
86 extern void DoWindowBirth(WWindow
*wwin
);
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);
127 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
128 wWindowSynthConfigureNotify(wwin
);
131 if (flags
& WTextureSettings
) {
132 wwin
->frame
->flags
.need_texture_remake
= 1;
134 if (flags
& (WTextureSettings
| WColorSettings
)) {
135 if (wwin
->frame
->titlebar
)
136 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
138 wFrameWindowPaint(wwin
->frame
);
143 WWindow
*wWindowFor(Window window
)
145 WObjDescriptor
*desc
;
150 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
153 if (desc
->parent_type
== WCLASS_WINDOW
)
155 else if (desc
->parent_type
== WCLASS_FRAME
) {
156 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
157 if (frame
->flags
.is_client_window_frame
)
164 WWindow
*wWindowCreate(void)
168 wwin
= wmalloc(sizeof(WWindow
));
171 memset(wwin
, 0, sizeof(WWindow
));
173 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
174 wwin
->client_descriptor
.parent
= wwin
;
175 wwin
->client_descriptor
.self
= wwin
;
176 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
181 void wWindowDestroy(WWindow
*wwin
)
185 if (wwin
->screen_ptr
->cmap_window
== wwin
)
186 wwin
->screen_ptr
->cmap_window
= NULL
;
188 WMRemoveNotificationObserver(wwin
);
190 wwin
->flags
.destroyed
= 1;
192 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
193 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
196 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
198 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
199 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
200 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
204 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
205 wwin
->fake_group
->retainCount
--;
206 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
207 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
208 wwin
->fake_group
->leader
= None
;
209 wwin
->fake_group
->origLeader
= None
;
214 if (wwin
->normal_hints
)
215 XFree(wwin
->normal_hints
);
218 XFree(wwin
->wm_hints
);
220 if (wwin
->wm_instance
)
221 XFree(wwin
->wm_instance
);
224 XFree(wwin
->wm_class
);
226 if (wwin
->wm_gnustep_attr
)
227 wfree(wwin
->wm_gnustep_attr
);
229 if (wwin
->cmap_windows
)
230 XFree(wwin
->cmap_windows
);
232 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
235 wFrameWindowDestroy(wwin
->frame
);
238 RemoveFromStackList(wwin
->icon
->core
);
239 wIconDestroy(wwin
->icon
);
240 if (wPreferences
.auto_arrange_icons
)
241 wArrangeIcons(wwin
->screen_ptr
, True
);
243 if (wwin
->net_icon_image
)
244 RReleaseImage(wwin
->net_icon_image
);
249 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
251 if (gs_hints
->flags
& GSWindowStyleAttr
) {
252 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
253 wwin
->client_flags
.no_border
= 1;
254 wwin
->client_flags
.no_titlebar
= 1;
255 wwin
->client_flags
.no_closable
= 1;
256 wwin
->client_flags
.no_miniaturizable
= 1;
257 wwin
->client_flags
.no_resizable
= 1;
258 wwin
->client_flags
.no_close_button
= 1;
259 wwin
->client_flags
.no_miniaturize_button
= 1;
260 wwin
->client_flags
.no_resizebar
= 1;
262 wwin
->client_flags
.no_close_button
=
263 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
265 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
267 wwin
->client_flags
.no_miniaturize_button
=
268 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
270 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
272 wwin
->client_flags
.no_resizebar
=
273 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
275 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
277 /* these attributes supposedly imply in the existence
279 if (gs_hints
->window_style
& (WMResizableWindowMask
|
280 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
281 wwin
->client_flags
.no_titlebar
= 0;
283 wwin
->client_flags
.no_titlebar
=
284 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
289 /* setup the defaults */
290 wwin
->client_flags
.no_border
= 0;
291 wwin
->client_flags
.no_titlebar
= 0;
292 wwin
->client_flags
.no_closable
= 0;
293 wwin
->client_flags
.no_miniaturizable
= 0;
294 wwin
->client_flags
.no_resizable
= 0;
295 wwin
->client_flags
.no_close_button
= 0;
296 wwin
->client_flags
.no_miniaturize_button
= 0;
297 wwin
->client_flags
.no_resizebar
= 0;
299 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
300 wwin
->client_flags
.no_appicon
= 1;
303 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
305 WScreen
*scr
= wwin
->screen_ptr
;
307 /* sets global default stuff */
308 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
310 * Decoration setting is done in this precedence (lower to higher)
311 * - use global default in the resource database
312 * - guess some settings
313 * - use GNUstep/external window attributes
314 * - set hints specified for the app in the resource DB
317 WSETUFLAG(wwin
, broken_close
, 0);
319 if (wwin
->protocols
.DELETE_WINDOW
)
320 WSETUFLAG(wwin
, kill_close
, 0);
322 WSETUFLAG(wwin
, kill_close
, 1);
324 /* transients can't be iconified or maximized */
325 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
326 WSETUFLAG(wwin
, no_miniaturizable
, 1);
327 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
330 /* if the window can't be resized, remove the resizebar */
331 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
332 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
333 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
334 WSETUFLAG(wwin
, no_resizable
, 1);
335 WSETUFLAG(wwin
, no_resizebar
, 1);
338 /* set GNUstep window attributes */
339 if (wwin
->wm_gnustep_attr
) {
340 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
342 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
344 *level
= wwin
->wm_gnustep_attr
->window_level
;
346 * INT_MIN is the only illegal window level.
348 if (*level
== INT_MIN
)
349 *level
= INT_MIN
+ 1;
352 *level
= WMNormalLevel
;
355 int tmp_workspace
= -1;
356 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
362 wMWMCheckClientHints(wwin
);
363 #endif /* MWM_HINTS */
366 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
368 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
369 * have INT_MIN that means that no window level was requested. -Dan
371 if (tmp_level
== INT_MIN
) {
372 if (WFLAGP(wwin
, floating
))
373 *level
= WMFloatingLevel
;
374 else if (WFLAGP(wwin
, sunken
))
375 *level
= WMSunkenLevel
;
377 *level
= WMNormalLevel
;
382 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
383 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
384 if (transientOwner
) {
385 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
386 if (ownerLevel
> *level
)
391 if (tmp_workspace
>= 0)
392 *workspace
= tmp_workspace
% scr
->workspace_count
;
396 * Set attributes specified only for that window/class.
397 * This might do duplicate work with the 1st wDefaultFillAttributes().
399 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
400 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
402 * Sanity checks for attributes that depend on other attributes
404 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
405 wwin
->user_flags
.emulate_appicon
= 0;
407 if (wwin
->main_window
!= None
) {
408 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
409 if (wapp
&& !wapp
->flags
.emulated
)
410 wwin
->user_flags
.emulate_appicon
= 0;
413 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
414 wwin
->user_flags
.emulate_appicon
= 0;
416 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
417 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
418 wwin
->user_flags
.sunken
= 0;
420 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
422 /* windows that have takefocus=False shouldn't take focus at all */
423 if (wwin
->focus_mode
== WFM_NO_INPUT
)
424 wwin
->client_flags
.no_focusable
= 1;
427 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
429 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
431 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
433 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
439 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
443 w1
= wwin
->frame
->core
->width
;
444 h1
= wwin
->frame
->core
->height
;
445 w2
= obscured
->frame
->core
->width
;
446 h2
= obscured
->frame
->core
->height
;
448 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
449 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
452 if (wwin
->frame_x
+ w1
< obscured
->frame_x
453 || wwin
->frame_y
+ h1
< obscured
->frame_y
454 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
460 static void fixLeaderProperties(WWindow
*wwin
)
462 XClassHint
*classHint
;
463 XWMHints
*hints
, *clientHints
;
464 XWindowAttributes attr
;
465 Window leaders
[2], window
;
466 char **argv
, *command
;
470 classHint
= XAllocClassHint();
471 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
472 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
474 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
478 leaders
[0] = wwin
->client_leader
;
479 leaders
[1] = wwin
->group_id
;
482 command
= GetCommandForWindow(wwin
->client_win
);
484 /* command already set. nothing to do. */
487 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
491 for (i
= 0; i
< 2; i
++) {
494 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
495 classHint
->res_name
= wwin
->wm_instance
;
496 classHint
->res_class
= wwin
->wm_class
;
497 XSetClassHint(dpy
, window
, classHint
);
499 hints
= XGetWMHints(dpy
, window
);
502 } else if (clientHints
) {
503 /* set window group leader to self */
504 clientHints
->window_group
= window
;
505 clientHints
->flags
|= WindowGroupHint
;
506 XSetWMHints(dpy
, window
, clientHints
);
510 command
= GetCommandForWindow(window
);
512 /* command already set. nothing to do. */
515 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
;
618 /* make sure the window is still there */
619 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
624 /* if it's an override-redirect, ignore it */
625 if (wattribs
.override_redirect
) {
630 wm_state
= PropGetWindowState(window
);
632 /* if it's startup and the window is unmapped, don't manage it */
633 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
638 wwin
= wWindowCreate();
640 title
= wNETWMGetWindowName(window
);
642 wwin
->flags
.net_has_title
= 1;
643 if (!title
&& !wFetchName(dpy
, window
, &title
))
646 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
649 if (wShapeSupported
) {
654 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
655 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
656 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
657 wwin
->flags
.shaped
= b_shaped
;
662 * Get hints and other information in properties
664 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
666 /* setup descriptor */
667 wwin
->client_win
= window
;
668 wwin
->screen_ptr
= scr
;
669 wwin
->old_border_width
= wattribs
.border_width
;
670 wwin
->event_mask
= CLIENT_EVENTS
;
671 attribs
.event_mask
= CLIENT_EVENTS
;
672 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
673 attribs
.save_under
= False
;
675 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
676 XSetWindowBorderWidth(dpy
, window
, 0);
678 /* get hints from GNUstep app */
679 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0) {
680 wwin
->flags
.is_gnustep
= 1;
682 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
683 wwin
->wm_gnustep_attr
= NULL
;
686 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
687 wwin
->flags
.is_dockapp
= 1;
691 wwin
->client_leader
= PropGetClientLeader(window
);
692 if (wwin
->client_leader
!= None
)
693 wwin
->main_window
= wwin
->client_leader
;
695 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
697 if (wwin
->wm_hints
) {
698 if (wwin
->wm_hints
->flags
& StateHint
) {
700 if (wwin
->wm_hints
->initial_state
== IconicState
) {
702 wwin
->flags
.miniaturized
= 1;
704 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
706 wwin
->flags
.is_dockapp
= 1;
711 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
712 wwin
->group_id
= wwin
->wm_hints
->window_group
;
713 /* window_group has priority over CLIENT_LEADER */
714 wwin
->main_window
= wwin
->group_id
;
716 wwin
->group_id
= None
;
719 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
720 wwin
->flags
.urgent
= 1;
721 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
724 wwin
->group_id
= None
;
727 PropGetProtocols(window
, &wwin
->protocols
);
729 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
730 wwin
->transient_for
= None
;
732 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
733 wwin
->transient_for
= scr
->root_win
;
735 transientOwner
= wWindowFor(wwin
->transient_for
);
736 if (transientOwner
&& transientOwner
->main_window
!= None
)
737 wwin
->main_window
= transientOwner
->main_window
;
741 /* guess the focus mode */
742 wwin
->focus_mode
= getFocusMode(wwin
);
744 /* get geometry stuff */
745 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
747 /* get colormap windows */
748 GetColormapWindows(wwin
);
751 * Setup the decoration/window attributes and
754 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
756 /* Make broken apps behave as a nice app. */
757 if (WFLAGP(wwin
, emulate_appicon
))
758 wwin
->main_window
= wwin
->client_win
;
760 fixLeaderProperties(wwin
);
762 wwin
->orig_main_window
= wwin
->main_window
;
764 if (wwin
->flags
.is_gnustep
)
765 WSETUFLAG(wwin
, shared_appicon
, 0);
767 if (wwin
->main_window
) {
768 extern Atom _XA_WINDOWMAKER_MENU
;
769 XTextProperty text_prop
;
771 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
772 WSETUFLAG(wwin
, shared_appicon
, 0);
776 if (wwin
->flags
.is_dockapp
)
777 WSETUFLAG(wwin
, shared_appicon
, 0);
779 if (wwin
->main_window
) {
780 WApplication
*app
= wApplicationOf(wwin
->main_window
);
781 if (app
&& app
->app_icon
)
782 WSETUFLAG(wwin
, shared_appicon
, 0);
785 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
786 char *buffer
, *instance
, *class;
787 WFakeGroupLeader
*fPtr
;
790 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
792 /* // only enter here if PropGetWMClass() succeds */
793 PropGetWMClass(wwin
->main_window
, &class, &instance
);
794 buffer
= StrConcatDot(instance
, class);
796 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
797 if (index
!= WANotFound
) {
798 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
799 if (fPtr
->retainCount
== 0) {
800 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
804 if (fPtr
->origLeader
== None
) {
805 if (ADEQUATE(wwin
->main_window
)) {
807 fPtr
->origLeader
= wwin
->main_window
;
810 wwin
->fake_group
= fPtr
;
811 /*wwin->group_id = fPtr->leader; */
812 wwin
->main_window
= fPtr
->leader
;
815 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
817 fPtr
->identifier
= buffer
;
818 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
819 fPtr
->origLeader
= None
;
820 fPtr
->retainCount
= 1;
822 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
824 if (ADEQUATE(wwin
->main_window
)) {
826 fPtr
->origLeader
= wwin
->main_window
;
828 wwin
->fake_group
= fPtr
;
829 /*wwin->group_id = fPtr->leader; */
830 wwin
->main_window
= fPtr
->leader
;
840 * Setup the initial state of the window
842 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
843 wwin
->flags
.miniaturized
= 1;
845 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
846 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
848 wNETWMCheckInitialClientState(wwin
);
850 /* apply previous state if it exists and we're in startup */
851 if (scr
->flags
.startup
&& wm_state
>= 0) {
853 if (wm_state
== IconicState
) {
855 wwin
->flags
.miniaturized
= 1;
857 } else if (wm_state
== WithdrawnState
) {
863 /* if there is a saved state (from file), restore it */
865 if (wwin
->main_window
!= None
)
866 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
868 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
870 if (win_state
&& !withdraw
) {
871 if (win_state
->state
->hidden
> 0)
872 wwin
->flags
.hidden
= win_state
->state
->hidden
;
874 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
875 wwin
->flags
.shaded
= win_state
->state
->shaded
;
877 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
878 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
881 if (!IS_OMNIPRESENT(wwin
)) {
882 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
884 if (w
< 0 || w
>= scr
->workspace_count
) {
885 workspace
= win_state
->state
->workspace
;
886 if (workspace
>= scr
->workspace_count
)
887 workspace
= scr
->current_workspace
;
892 workspace
= scr
->current_workspace
;
896 /* if we're restarting, restore saved state (from hints).
897 * This will overwrite previous */
901 if (getSavedState(window
, &wstate
)) {
902 wwin
->flags
.shaded
= wstate
->shaded
;
903 wwin
->flags
.hidden
= wstate
->hidden
;
904 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
905 wwin
->flags
.maximized
= wstate
->maximized
;
906 if (wwin
->flags
.maximized
) {
907 wwin
->old_geometry
.x
= wstate
->x
;
908 wwin
->old_geometry
.y
= wstate
->y
;
909 wwin
->old_geometry
.width
= wstate
->w
;
910 wwin
->old_geometry
.height
= wstate
->h
;
913 workspace
= wstate
->workspace
;
918 /* restore window shortcut */
919 if (wstate
!= NULL
|| win_state
!= NULL
) {
922 if (win_state
!= NULL
)
923 mask
= win_state
->state
->window_shortcuts
;
925 if (wstate
!= NULL
&& mask
== 0)
926 mask
= wstate
->window_shortcuts
;
931 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
932 if (mask
& (1 << i
)) {
933 if (!scr
->shortcutWindows
[i
])
934 scr
->shortcutWindows
[i
] = WMCreateArray(4);
936 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
945 /* don't let transients start miniaturized if their owners are not */
946 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
947 wwin
->flags
.miniaturized
= 0;
949 wwin
->wm_hints
->initial_state
= NormalState
;
952 /* set workspace on which the window starts */
953 if (workspace
>= 0) {
954 if (workspace
> scr
->workspace_count
- 1) {
955 workspace
= workspace
% scr
->workspace_count
;
960 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
962 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
967 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
969 workspace
= transientOwner
->frame
->workspace
;
973 workspace
= scr
->current_workspace
;
978 /* setup window geometry */
979 if (win_state
&& win_state
->state
->w
> 0) {
980 width
= win_state
->state
->w
;
981 height
= win_state
->state
->h
;
983 wWindowConstrainSize(wwin
, &width
, &height
);
985 /* do not ask for window placement if the window is
986 * transient, during startup, if the initial workspace is another one
987 * or if the window wants to start iconic.
988 * If geometry was saved, restore it. */
990 Bool dontBring
= False
;
992 if (win_state
&& win_state
->state
->w
> 0) {
993 x
= win_state
->state
->x
;
994 y
= win_state
->state
->y
;
995 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
996 && !scr
->flags
.startup
997 && workspace
== scr
->current_workspace
998 && !wwin
->flags
.miniaturized
999 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
1001 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1002 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
1006 x
= transientOwner
->frame_x
+
1007 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
1008 y
= transientOwner
->frame_y
+
1009 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
1012 * limit transient windows to be inside their parent's head
1014 rect
.pos
.x
= transientOwner
->frame_x
;
1015 rect
.pos
.y
= transientOwner
->frame_y
;
1016 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1017 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1019 head
= wGetHeadForRect(scr
, rect
);
1020 rect
= wGetRectForHead(scr
, head
);
1024 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1025 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1029 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1030 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1033 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1035 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1038 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1044 * Make spash screens come out in the center of a head
1045 * trouble is that most splashies never get here
1046 * they are managed trough atoms but god knows where.
1047 * Dan, do you know ? -peter
1049 * Most of them are not managed, they have set
1050 * OverrideRedirect, which means we can't do anything about
1055 * xinerama checks for: across head and dead space
1059 rect
.size
.width
= width
;
1060 rect
.size
.height
= height
;
1062 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1064 if (flags
& XFLAG_DEAD
)
1067 if (flags
& XFLAG_MULTIPLE
)
1071 switch (reposition
) {
1073 head
= wGetHeadForPointerLocation(scr
);
1074 rect
= wGetRectForHead(scr
, head
);
1076 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1077 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1081 rect
= wGetRectForHead(scr
, head
);
1085 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1086 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1090 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1091 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1100 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1101 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1104 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1106 if (wwin
->flags
.urgent
) {
1107 if (!IS_OMNIPRESENT(wwin
))
1108 wwin
->flags
.omnipresent
^= 1;
1112 * Create frame, borders and do reparenting
1114 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1115 #ifdef XKB_BUTTON_HINT
1116 if (wPreferences
.modelock
)
1117 foo
|= WFF_LANGUAGE_BUTTON
;
1119 if (HAS_TITLEBAR(wwin
))
1120 foo
|= WFF_TITLEBAR
;
1121 if (HAS_RESIZEBAR(wwin
))
1122 foo
|= WFF_RESIZEBAR
;
1123 if (HAS_BORDER(wwin
))
1126 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1127 x
, y
, width
, height
,
1128 &wPreferences
.window_title_clearance
, foo
,
1129 scr
->window_title_texture
,
1130 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1132 wwin
->frame
->flags
.is_client_window_frame
= 1;
1133 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1135 /* setup button images */
1136 wWindowUpdateButtonImages(wwin
);
1138 /* hide unused buttons */
1140 if (WFLAGP(wwin
, no_close_button
))
1141 foo
|= WFF_RIGHT_BUTTON
;
1142 if (WFLAGP(wwin
, no_miniaturize_button
))
1143 foo
|= WFF_LEFT_BUTTON
;
1144 #ifdef XKB_BUTTON_HINT
1145 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1146 foo
|= WFF_LANGUAGE_BUTTON
;
1149 wFrameWindowHideButton(wwin
->frame
, foo
);
1151 wwin
->frame
->child
= wwin
;
1152 wwin
->frame
->workspace
= workspace
;
1153 wwin
->frame
->on_click_left
= windowIconifyClick
;
1155 #ifdef XKB_BUTTON_HINT
1156 if (wPreferences
.modelock
)
1157 wwin
->frame
->on_click_language
= windowLanguageClick
;
1160 wwin
->frame
->on_click_right
= windowCloseClick
;
1161 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1162 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1163 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1164 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1166 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1167 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1168 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1173 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1175 /* if gravity is to the south, account for the border sizes */
1177 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1181 * wWindowConfigure() will init the client window's size
1182 * (wwin->client.{width,height}) and all other geometry
1183 * related variables (frame_x,frame_y)
1185 wWindowConfigure(wwin
, x
, y
, width
, height
);
1187 /* to make sure the window receives it's new position after reparenting */
1188 wWindowSynthConfigureNotify(wwin
);
1191 * Setup descriptors and save window to internal
1194 if (wwin
->main_window
!= None
) {
1198 /* Leader windows do not necessary set themselves as leaders.
1199 * If this is the case, point the leader of this window to
1201 leader
= wWindowFor(wwin
->main_window
);
1202 if (leader
&& leader
->main_window
== None
) {
1203 leader
->main_window
= leader
->client_win
;
1205 app
= wApplicationCreate(wwin
);
1207 app
->last_workspace
= workspace
;
1210 * Do application specific stuff, like setting application
1214 if (wwin
->flags
.hidden
) {
1215 /* if the window was set to hidden because it was hidden
1216 * in a previous incarnation and that state was restored */
1217 app
->flags
.hidden
= 1;
1218 } else if (app
->flags
.hidden
) {
1219 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1220 wwin
->flags
.hidden
= 1;
1222 wUnhideApplication(app
, False
, False
);
1230 /* setup the frame descriptor */
1231 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1232 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1233 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1235 /* don't let windows go away if we die */
1236 XAddToSaveSet(dpy
, window
);
1238 XLowerWindow(dpy
, window
);
1240 /* if window is in this workspace and should be mapped, then map it */
1241 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1242 && !wwin
->flags
.hidden
&& !withdraw
) {
1244 /* The following "if" is to avoid crashing of clients that expect
1245 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1246 * after the return from this function.
1248 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1249 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1251 wClientSetState(wwin
, NormalState
, None
);
1255 /* if not auto focus, then map the window under the currently
1257 #define _WIDTH(w) (w)->frame->core->width
1258 #define _HEIGHT(w) (w)->frame->core->height
1259 if (!wPreferences
.auto_focus
&& scr
->focused_window
1260 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1262 (_WIDTH(scr
->focused_window
) * 5) / 3
1264 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1265 && WINDOW_LEVEL(scr
->focused_window
) ==
1267 || wwin
->flags
.maximized
)) {
1268 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1275 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1276 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1278 * The brain damaged idiotic non-click to focus modes will
1279 * have trouble with this because:
1281 * 1. window is created and mapped by the client
1282 * 2. window is mapped by wmaker in small size
1283 * 3. window is animated to grow to normal size
1284 * 4. this function returns to normal event loop
1285 * 5. eventually, the EnterNotify event that would trigger
1286 * the window focusing (if the mouse is over that window)
1287 * will be processed by wmaker.
1288 * But since this event will be rather delayed
1289 * (step 3 has a large delay) the time when the event ocurred
1290 * and when it is processed, the client that owns that window
1291 * will reject the XSetInputFocus() for it.
1293 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1294 DoWindowBirth(wwin
);
1300 /* setup stacking descriptor */
1301 if (transientOwner
) {
1302 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1304 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1307 if (!scr
->focused_window
) {
1308 /* first window on the list */
1311 scr
->focused_window
= wwin
;
1315 /* add window at beginning of focus window list */
1316 tmp
= scr
->focused_window
;
1324 /* raise is set to true if we un-hid the app when this window was born.
1325 * we raise, else old windows of this app will be above this new one. */
1327 wRaiseFrame(wwin
->frame
->core
);
1330 /* Update name must come after WApplication stuff is done */
1331 wWindowUpdateName(wwin
, title
);
1338 * Final preparations before window is ready to go
1340 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1342 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1343 if (((transientOwner
&& transientOwner
->flags
.focused
)
1344 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1346 /* only auto_focus if on same screen as mouse
1347 * (and same head for xinerama mode)
1348 * TODO: make it an option */
1350 /*TODO add checking the head of the window, is it available? */
1351 short same_screen
= 0, same_head
= 1;
1357 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1358 &foo
, &foo
, &foo
, &foo
, &bar
) != False
) {
1362 if (same_screen
== 1 && same_head
== 1) {
1363 wSetFocusTo(scr
, wwin
);
1367 wWindowResetMouseGrabs(wwin
);
1369 if (!WFLAGP(wwin
, no_bind_keys
))
1370 wWindowSetKeyGrabs(wwin
);
1372 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1373 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1375 /* Setup Notification Observers */
1376 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1378 /* Cleanup temporary stuff */
1380 wWindowDeleteSavedState(win_state
);
1382 /* If the window must be withdrawed, then do it now.
1383 * Must do some optimization, 'though */
1385 wwin
->flags
.mapped
= 0;
1386 wClientSetState(wwin
, WithdrawnState
, None
);
1387 wUnmanageWindow(wwin
, True
, False
);
1394 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1395 char *title
, int x
, int y
, int width
, int height
)
1400 wwin
= wWindowCreate();
1402 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1404 wwin
->flags
.internal_window
= 1;
1406 WSETUFLAG(wwin
, omnipresent
, 1);
1407 WSETUFLAG(wwin
, no_shadeable
, 1);
1408 WSETUFLAG(wwin
, no_resizable
, 1);
1409 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1411 wwin
->focus_mode
= WFM_PASSIVE
;
1412 wwin
->client_win
= window
;
1413 wwin
->screen_ptr
= scr
;
1414 wwin
->transient_for
= owner
;
1417 wwin
->client
.width
= width
;
1418 wwin
->client
.height
= height
;
1419 wwin
->frame_x
= wwin
->client
.x
;
1420 wwin
->frame_y
= wwin
->client
.y
;
1422 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1423 foo
|= WFF_TITLEBAR
;
1424 #ifdef XKB_BUTTON_HINT
1425 foo
|= WFF_LANGUAGE_BUTTON
;
1428 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1429 wwin
->frame_x
, wwin
->frame_y
,
1431 &wPreferences
.window_title_clearance
, foo
,
1432 scr
->window_title_texture
,
1433 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1435 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1437 wwin
->frame
->flags
.is_client_window_frame
= 1;
1438 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1440 wFrameWindowChangeTitle(wwin
->frame
, title
);
1442 /* setup button images */
1443 wWindowUpdateButtonImages(wwin
);
1446 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1448 wwin
->frame
->child
= wwin
;
1449 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1451 #ifdef XKB_BUTTON_HINT
1452 if (wPreferences
.modelock
)
1453 wwin
->frame
->on_click_language
= windowLanguageClick
;
1456 wwin
->frame
->on_click_right
= windowCloseClick
;
1457 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1458 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1459 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1460 wwin
->client
.y
+= wwin
->frame
->top_width
;
1462 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1463 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1465 /* setup the frame descriptor */
1466 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1467 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1468 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1470 XLowerWindow(dpy
, window
);
1471 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1473 /* setup stacking descriptor */
1474 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1476 tmp
= wWindowFor(wwin
->transient_for
);
1478 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1480 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1483 if (!scr
->focused_window
) {
1484 /* first window on the list */
1487 scr
->focused_window
= wwin
;
1491 /* add window at beginning of focus window list */
1492 tmp
= scr
->focused_window
;
1500 if (wwin
->flags
.is_gnustep
== 0)
1501 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1503 /* if (wPreferences.auto_focus) */
1504 wSetFocusTo(scr
, wwin
);
1505 wWindowResetMouseGrabs(wwin
);
1506 wWindowSetKeyGrabs(wwin
);
1512 *----------------------------------------------------------------------
1514 * Removes the frame window from a window and destroys all data
1515 * related to it. The window will be reparented back to the root window
1516 * if restore is True.
1519 * Everything related to the window is destroyed and the window
1520 * is removed from the window lists. Focus is set to the previous on the
1522 *----------------------------------------------------------------------
1524 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1526 WCoreWindow
*frame
= wwin
->frame
->core
;
1527 WWindow
*owner
= NULL
;
1528 WWindow
*newFocusedWindow
= NULL
;
1530 WScreen
*scr
= wwin
->screen_ptr
;
1532 /* First close attribute editor window if open */
1533 if (wwin
->flags
.inspector_open
) {
1534 wCloseInspectorForWindow(wwin
);
1537 /* Close window menu if it's open for this window */
1538 if (wwin
->flags
.menu_open_for_me
) {
1539 CloseWindowMenu(scr
);
1543 if (!wwin
->flags
.internal_window
)
1544 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1546 /* If this is a leader window, we still need to listen for
1547 * DestroyNotify and PropertyNotify. */
1548 if (wApplicationOf(wwin
->client_win
)) {
1549 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1551 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1554 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1555 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1558 XUnmapWindow(dpy
, frame
->window
);
1560 XUnmapWindow(dpy
, wwin
->client_win
);
1562 /* deselect window */
1563 wSelectWindow(wwin
, False
);
1565 /* remove all pending events on window */
1566 /* I think this only matters for autoraise */
1567 if (wPreferences
.raise_delay
)
1568 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1572 /* reparent the window back to the root */
1574 wClientRestore(wwin
);
1576 if (wwin
->transient_for
!= scr
->root_win
) {
1577 owner
= wWindowFor(wwin
->transient_for
);
1579 if (!owner
->flags
.semi_focused
) {
1582 owner
->flags
.semi_focused
= 0;
1587 wasFocused
= wwin
->flags
.focused
;
1589 /* remove from window focus list */
1590 if (!wwin
->prev
&& !wwin
->next
) {
1591 /* was the only window */
1592 scr
->focused_window
= NULL
;
1593 newFocusedWindow
= NULL
;
1598 wwin
->prev
->next
= wwin
->next
;
1600 wwin
->next
->prev
= wwin
->prev
;
1602 scr
->focused_window
= wwin
->prev
;
1603 scr
->focused_window
->next
= NULL
;
1606 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1608 /* if in click to focus mode and the window
1609 * was a transient, focus the owner window
1612 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1613 tmp
= wWindowFor(wwin
->transient_for
);
1614 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1618 /* otherwise, focus the next one in the focus list */
1620 tmp
= scr
->focused_window
;
1621 while (tmp
) { /* look for one in the window list first */
1622 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1623 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1627 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1628 tmp
= scr
->focused_window
;
1630 if (!WFLAGP(tmp
, no_focusable
)
1631 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1638 newFocusedWindow
= tmp
;
1640 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1645 /* This is to let the root window get the keyboard input
1646 * if Sloppy focus mode and no other window get focus.
1647 * This way keybindings will not freeze.
1650 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1651 tmp
= wWindowFor(win
);
1654 newFocusedWindow
= tmp
;
1656 newFocusedWindow
= NULL
;
1660 if (!wwin
->flags
.internal_window
)
1661 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1663 if (newFocusedWindow
!= owner
&& owner
) {
1664 if (wwin
->flags
.is_gnustep
== 0)
1665 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1667 wSetFocusTo(scr
, newFocusedWindow
);
1670 /* Close menu and unhighlight */
1671 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1672 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1673 if (oapp
&& oapp
!= napp
) {
1674 wAppMenuUnmap(oapp
->menu
);
1675 wApplicationDeactivate(oapp
);
1678 wWindowDestroy(wwin
);
1682 void wWindowMap(WWindow
*wwin
)
1684 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1685 if (!wwin
->flags
.shaded
) {
1686 /* window will be remapped when getting MapNotify */
1687 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1688 XMapWindow(dpy
, wwin
->client_win
);
1689 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1691 wwin
->flags
.mapped
= 1;
1695 void wWindowUnmap(WWindow
*wwin
)
1697 wwin
->flags
.mapped
= 0;
1699 /* prevent window withdrawal when getting UnmapNotify */
1700 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1701 XUnmapWindow(dpy
, wwin
->client_win
);
1702 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1704 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1707 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1712 #ifdef KEEP_XKB_LOCK_STATUS
1713 if (wPreferences
.modelock
) {
1714 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1716 #endif /* KEEP_XKB_LOCK_STATUS */
1718 wwin
->flags
.semi_focused
= 0;
1720 if (wwin
->flags
.is_gnustep
== 0)
1721 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1723 wwin
->flags
.focused
= 1;
1725 wWindowResetMouseGrabs(wwin
);
1727 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1729 if (owin
== wwin
|| !owin
)
1732 nowner
= wWindowFor(wwin
->transient_for
);
1734 /* new window is a transient for the old window */
1735 if (nowner
== owin
) {
1736 owin
->flags
.semi_focused
= 1;
1737 wWindowUnfocus(nowner
);
1741 oowner
= wWindowFor(owin
->transient_for
);
1743 /* new window is owner of old window */
1744 if (wwin
== oowner
) {
1745 wWindowUnfocus(owin
);
1750 wWindowUnfocus(owin
);
1754 /* new window has same owner of old window */
1755 if (oowner
== nowner
) {
1756 /* prevent unfocusing of owner */
1757 oowner
->flags
.semi_focused
= 0;
1758 wWindowUnfocus(owin
);
1759 oowner
->flags
.semi_focused
= 1;
1764 /* nowner != NULL && oowner != nowner */
1765 nowner
->flags
.semi_focused
= 1;
1766 wWindowUnfocus(nowner
);
1767 wWindowUnfocus(owin
);
1770 void wWindowUnfocus(WWindow
*wwin
)
1772 CloseWindowMenu(wwin
->screen_ptr
);
1774 if (wwin
->flags
.is_gnustep
== 0)
1775 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1777 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1779 owner
= wWindowFor(wwin
->transient_for
);
1780 if (owner
&& owner
->flags
.semi_focused
) {
1781 owner
->flags
.semi_focused
= 0;
1782 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1783 wWindowUnfocus(owner
);
1784 wFrameWindowPaint(owner
->frame
);
1788 wwin
->flags
.focused
= 0;
1789 wWindowResetMouseGrabs(wwin
);
1790 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1793 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1800 wwin
->flags
.wm_name_changed
= 1;
1803 /* the hint was removed */
1804 title
= DEF_WINDOW_TITLE
;
1809 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1810 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1815 *----------------------------------------------------------------------
1817 * wWindowConstrainSize--
1818 * Constrains size for the client window, taking the maximal size,
1819 * window resize increments and other size hints into account.
1822 * The closest size to what was given that the client window can
1825 *----------------------------------------------------------------------
1827 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1829 int width
= (int)*nwidth
;
1830 int height
= (int)*nheight
;
1833 int minW
= 1, minH
= 1;
1834 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1835 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1836 int minAX
= -1, minAY
= -1;
1837 int maxAX
= -1, maxAY
= -1;
1841 if (wwin
->normal_hints
) {
1842 winc
= wwin
->normal_hints
->width_inc
;
1843 hinc
= wwin
->normal_hints
->height_inc
;
1844 minW
= wwin
->normal_hints
->min_width
;
1845 minH
= wwin
->normal_hints
->min_height
;
1846 maxW
= wwin
->normal_hints
->max_width
;
1847 maxH
= wwin
->normal_hints
->max_height
;
1848 if (wwin
->normal_hints
->flags
& PAspect
) {
1849 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1850 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1851 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1852 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1855 baseW
= wwin
->normal_hints
->base_width
;
1856 baseH
= wwin
->normal_hints
->base_height
;
1869 /* aspect ratio code borrowed from olwm */
1871 /* adjust max aspect ratio */
1872 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1873 if (maxAX
> maxAY
) {
1874 height
= (width
* maxAY
) / maxAX
;
1875 if (height
> maxH
) {
1877 width
= (height
* maxAX
) / maxAY
;
1880 width
= (height
* maxAX
) / maxAY
;
1883 height
= (width
* maxAY
) / maxAX
;
1888 /* adjust min aspect ratio */
1889 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1890 if (minAX
> minAY
) {
1891 height
= (width
* minAY
) / minAX
;
1892 if (height
< minH
) {
1894 width
= (height
* minAX
) / minAY
;
1897 width
= (height
* minAX
) / minAY
;
1900 height
= (width
* minAY
) / minAX
;
1907 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1909 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1912 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1914 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1916 /* broken stupid apps may cause preposterous values for these.. */
1923 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1924 unsigned int *width
, unsigned int *height
)
1926 int baseW
= 0, baseH
= 0;
1927 int winc
= 1, hinc
= 1;
1929 if (wwin
->normal_hints
) {
1930 baseW
= wwin
->normal_hints
->base_width
;
1931 baseH
= wwin
->normal_hints
->base_height
;
1933 winc
= wwin
->normal_hints
->width_inc
;
1934 hinc
= wwin
->normal_hints
->height_inc
;
1938 *width
= maxW
- (maxW
- baseW
) % winc
;
1941 *height
= maxH
- (maxH
- baseH
) % hinc
;
1944 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1946 WScreen
*scr
= wwin
->screen_ptr
;
1950 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1953 if (workspace
!= scr
->current_workspace
) {
1954 /* Sent to other workspace. Unmap window */
1955 if ((wwin
->flags
.mapped
1956 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1957 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1959 wapp
= wApplicationOf(wwin
->main_window
);
1961 wapp
->last_workspace
= workspace
;
1963 if (wwin
->flags
.miniaturized
) {
1965 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1966 wwin
->icon
->mapped
= 0;
1970 wSetFocusTo(scr
, NULL
);
1974 /* brought to current workspace. Map window */
1975 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1977 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1978 wwin
->icon
->mapped
= 1;
1980 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1984 if (!IS_OMNIPRESENT(wwin
)) {
1985 int oldWorkspace
= wwin
->frame
->workspace
;
1987 wwin
->frame
->workspace
= workspace
;
1989 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1996 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2000 sevent
.type
= ConfigureNotify
;
2001 sevent
.xconfigure
.display
= dpy
;
2002 sevent
.xconfigure
.event
= wwin
->client_win
;
2003 sevent
.xconfigure
.window
= wwin
->client_win
;
2005 sevent
.xconfigure
.x
= wwin
->client
.x
;
2006 sevent
.xconfigure
.y
= wwin
->client
.y
;
2007 sevent
.xconfigure
.width
= wwin
->client
.width
;
2008 sevent
.xconfigure
.height
= wwin
->client
.height
;
2010 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2011 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2012 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2014 sevent
.xconfigure
.above
= None
;
2016 sevent
.xconfigure
.override_redirect
= False
;
2017 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2022 *----------------------------------------------------------------------
2023 * wWindowConfigure()
2025 * req_x, req_y: new requested positions for the frame
2026 * req_width, req_height: new requested sizes for the client
2028 * Configures the frame, decorations and client window to the specified
2029 * geometry, whose validity is not checked -- wWindowConstrainSize()
2030 * must be used for that.
2031 * The size parameters are for the client window, but the position is
2033 * The client window receives a ConfigureNotify event, according
2034 * to what ICCCM says.
2040 * Window size and position are changed and client window receives
2041 * a ConfigureNotify event.
2042 *----------------------------------------------------------------------
2044 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2046 int synth_notify
= False
;
2049 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2051 * if the window is being moved but not resized then
2052 * send a synthetic ConfigureNotify
2054 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2055 synth_notify
= True
;
2058 if (WFLAGP(wwin
, dont_move_off
))
2059 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2061 if (req_width
< MIN_WINDOW_SIZE
)
2062 req_width
= MIN_WINDOW_SIZE
;
2063 if (req_height
< MIN_WINDOW_SIZE
)
2064 req_height
= MIN_WINDOW_SIZE
;
2066 /* If growing, resize inner part before frame,
2067 * if shrinking, resize frame before.
2068 * This will prevent the frame (that can have a different color)
2069 * to be exposed, causing flicker */
2070 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2071 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2073 if (wwin
->flags
.shaded
) {
2074 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2075 wwin
->old_geometry
.height
= req_height
;
2079 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2081 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2084 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2085 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2087 wwin
->client
.x
= req_x
;
2088 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2089 wwin
->client
.width
= req_width
;
2090 wwin
->client
.height
= req_height
;
2092 wwin
->client
.x
= req_x
;
2093 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2095 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2097 wwin
->frame_x
= req_x
;
2098 wwin
->frame_y
= req_y
;
2099 if (HAS_BORDER(wwin
)) {
2100 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2101 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2104 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2105 wWindowSetShape(wwin
);
2110 wWindowSynthConfigureNotify(wwin
);
2114 /* req_x, req_y: new position of the frame */
2115 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2117 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2118 int synth_notify
= False
;
2120 /* Send a synthetic ConfigureNotify event for every window movement. */
2121 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2122 synth_notify
= True
;
2125 /* A single synthetic ConfigureNotify event is sent at the end of
2126 * a completed (opaque) movement in moveres.c */
2129 if (WFLAGP(wwin
, dont_move_off
))
2130 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2131 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2133 wwin
->client
.x
= req_x
;
2134 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2135 if (HAS_BORDER(wwin
)) {
2136 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2137 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2140 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2142 wwin
->frame_x
= req_x
;
2143 wwin
->frame_y
= req_y
;
2145 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2147 wWindowSynthConfigureNotify(wwin
);
2151 void wWindowUpdateButtonImages(WWindow
*wwin
)
2153 WScreen
*scr
= wwin
->screen_ptr
;
2154 Pixmap pixmap
, mask
;
2155 WFrameWindow
*fwin
= wwin
->frame
;
2157 if (!HAS_TITLEBAR(wwin
))
2160 /* miniaturize button */
2161 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2162 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2163 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2165 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2166 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2171 if (fwin
->lbutton_image
2172 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2173 wPixmapDestroy(fwin
->lbutton_image
);
2174 fwin
->lbutton_image
= NULL
;
2177 if (!fwin
->lbutton_image
) {
2178 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2179 fwin
->lbutton_image
->client_owned
= 1;
2180 fwin
->lbutton_image
->client_owned_mask
= 1;
2183 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2184 wPixmapDestroy(fwin
->lbutton_image
);
2186 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2189 #ifdef XKB_BUTTON_HINT
2190 if (!WFLAGP(wwin
, no_language_button
)) {
2191 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2192 wPixmapDestroy(fwin
->languagebutton_image
);
2194 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2200 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2201 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2203 if (!WFLAGP(wwin
, no_close_button
)) {
2204 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2205 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2207 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2208 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2212 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2213 || fwin
->rbutton_image
->mask
!= mask
)) {
2214 wPixmapDestroy(fwin
->rbutton_image
);
2215 fwin
->rbutton_image
= NULL
;
2218 if (!fwin
->rbutton_image
) {
2219 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2220 fwin
->rbutton_image
->client_owned
= 1;
2221 fwin
->rbutton_image
->client_owned_mask
= 1;
2224 } else if (WFLAGP(wwin
, kill_close
)) {
2226 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2227 wPixmapDestroy(fwin
->rbutton_image
);
2229 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2231 } else if (MGFLAGP(wwin
, broken_close
)) {
2233 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2234 wPixmapDestroy(fwin
->rbutton_image
);
2236 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2240 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2241 wPixmapDestroy(fwin
->rbutton_image
);
2243 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2247 /* force buttons to be redrawn */
2248 fwin
->flags
.need_texture_change
= 1;
2249 wFrameWindowPaint(fwin
);
2253 *---------------------------------------------------------------------------
2254 * wWindowConfigureBorders--
2255 * Update window border configuration according to attribute flags.
2257 *---------------------------------------------------------------------------
2259 void wWindowConfigureBorders(WWindow
*wwin
)
2265 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2267 #ifdef XKB_BUTTON_HINT
2268 if (wPreferences
.modelock
)
2269 flags
|= WFF_LANGUAGE_BUTTON
;
2272 if (HAS_TITLEBAR(wwin
))
2273 flags
|= WFF_TITLEBAR
;
2274 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2275 flags
|= WFF_RESIZEBAR
;
2276 if (HAS_BORDER(wwin
))
2277 flags
|= WFF_BORDER
;
2278 if (wwin
->flags
.shaded
)
2279 flags
|= WFF_IS_SHADED
;
2281 oldh
= wwin
->frame
->top_width
;
2282 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2283 if (oldh
!= wwin
->frame
->top_width
) {
2284 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2286 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2287 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2291 if (!WFLAGP(wwin
, no_miniaturize_button
)
2292 && wwin
->frame
->flags
.hide_left_button
)
2293 flags
|= WFF_LEFT_BUTTON
;
2295 #ifdef XKB_BUTTON_HINT
2296 if (!WFLAGP(wwin
, no_language_button
)
2297 && wwin
->frame
->flags
.hide_language_button
) {
2298 flags
|= WFF_LANGUAGE_BUTTON
;
2302 if (!WFLAGP(wwin
, no_close_button
)
2303 && wwin
->frame
->flags
.hide_right_button
)
2304 flags
|= WFF_RIGHT_BUTTON
;
2307 wWindowUpdateButtonImages(wwin
);
2308 wFrameWindowShowButton(wwin
->frame
, flags
);
2312 if (WFLAGP(wwin
, no_miniaturize_button
)
2313 && !wwin
->frame
->flags
.hide_left_button
)
2314 flags
|= WFF_LEFT_BUTTON
;
2316 #ifdef XKB_BUTTON_HINT
2317 if (WFLAGP(wwin
, no_language_button
)
2318 && !wwin
->frame
->flags
.hide_language_button
)
2319 flags
|= WFF_LANGUAGE_BUTTON
;
2322 if (WFLAGP(wwin
, no_close_button
)
2323 && !wwin
->frame
->flags
.hide_right_button
)
2324 flags
|= WFF_RIGHT_BUTTON
;
2327 wFrameWindowHideButton(wwin
->frame
, flags
);
2330 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2331 wWindowSetShape(wwin
);
2337 void wWindowSaveState(WWindow
* wwin
)
2342 memset(data
, 0, sizeof(long) * 10);
2343 data
[0] = wwin
->frame
->workspace
;
2344 data
[1] = wwin
->flags
.miniaturized
;
2345 data
[2] = wwin
->flags
.shaded
;
2346 data
[3] = wwin
->flags
.hidden
;
2347 data
[4] = wwin
->flags
.maximized
;
2348 if (wwin
->flags
.maximized
== 0) {
2349 data
[5] = wwin
->frame_x
;
2350 data
[6] = wwin
->frame_y
;
2351 data
[7] = wwin
->frame
->core
->width
;
2352 data
[8] = wwin
->frame
->core
->height
;
2354 data
[5] = wwin
->old_geometry
.x
;
2355 data
[6] = wwin
->old_geometry
.y
;
2356 data
[7] = wwin
->old_geometry
.width
;
2357 data
[8] = wwin
->old_geometry
.height
;
2360 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2361 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2362 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2365 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2366 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2369 static int getSavedState(Window window
, WSavedState
** state
)
2373 unsigned long nitems_ret
;
2374 unsigned long bytes_after_ret
;
2377 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2378 True
, _XA_WINDOWMAKER_STATE
,
2379 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2380 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2383 *state
= wmalloc(sizeof(WSavedState
));
2385 (*state
)->workspace
= data
[0];
2386 (*state
)->miniaturized
= data
[1];
2387 (*state
)->shaded
= data
[2];
2388 (*state
)->hidden
= data
[3];
2389 (*state
)->maximized
= data
[4];
2390 (*state
)->x
= data
[5];
2391 (*state
)->y
= data
[6];
2392 (*state
)->w
= data
[7];
2393 (*state
)->h
= data
[8];
2394 (*state
)->window_shortcuts
= data
[9];
2398 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2405 void wWindowClearShape(WWindow
* wwin
)
2407 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2408 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2412 void wWindowSetShape(WWindow
* wwin
)
2416 #ifdef OPTIMIZE_SHAPE
2421 /* only shape is the client's */
2422 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2426 /* Get array of rectangles describing the shape mask */
2427 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2432 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2438 /* insert our decoration rectangles in the rect list */
2439 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2442 if (HAS_TITLEBAR(wwin
)) {
2444 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2445 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2446 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2449 if (HAS_RESIZEBAR(wwin
)) {
2451 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2452 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2453 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2457 /* shape our frame window */
2458 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2459 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2465 #endif /* OPTIMIZE_SHAPE */
2467 if (HAS_TITLEBAR(wwin
)) {
2470 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2471 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2474 if (HAS_RESIZEBAR(wwin
)) {
2476 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2477 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2478 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2482 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2483 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2485 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2486 0, wwin
->frame
->top_width
, wwin
->client_win
,
2487 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2492 /* ====================================================================== */
2494 static FocusMode
getFocusMode(WWindow
* wwin
)
2498 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2499 if (wwin
->wm_hints
->input
== True
) {
2500 if (wwin
->protocols
.TAKE_FOCUS
)
2501 mode
= WFM_LOCALLY_ACTIVE
;
2505 if (wwin
->protocols
.TAKE_FOCUS
)
2506 mode
= WFM_GLOBALLY_ACTIVE
;
2508 mode
= WFM_NO_INPUT
;
2516 void wWindowSetKeyGrabs(WWindow
* wwin
)
2521 for (i
= 0; i
< WKBD_LAST
; i
++) {
2522 key
= &wKeyBindings
[i
];
2524 if (key
->keycode
== 0)
2526 if (key
->modifier
!= AnyModifier
) {
2527 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2528 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2530 /* Also grab all modifier combinations possible that include,
2531 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2532 * work even if the NumLock/ScrollLock key is on.
2534 wHackedGrabKey(key
->keycode
, key
->modifier
,
2535 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2538 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2539 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2542 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2545 void wWindowResetMouseGrabs(WWindow
* wwin
)
2547 /* Mouse grabs can't be done on the client window because of
2548 * ICCCM and because clients that try to do the same will crash.
2550 * But there is a problem wich makes tbar buttons of unfocused
2551 * windows not usable as the click goes to the frame window instead
2552 * of the button itself. Must figure a way to fix that.
2555 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2557 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2558 /* grabs for Meta+drag */
2559 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2560 True
, ButtonPressMask
| ButtonReleaseMask
,
2561 GrabModeSync
, GrabModeAsync
, None
, None
);
2563 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2564 * but we only grab it for Button4 and Button 5 since a lot of apps
2565 * use CTRL+Button1-3 for app related functionality
2567 if (wPreferences
.resize_increment
> 0) {
2568 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2569 True
, ButtonPressMask
| ButtonReleaseMask
,
2570 GrabModeSync
, GrabModeAsync
, None
, None
);
2571 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2572 True
, ButtonPressMask
| ButtonReleaseMask
,
2573 GrabModeSync
, GrabModeAsync
, None
, None
);
2575 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2576 True
, ButtonPressMask
| ButtonReleaseMask
,
2577 GrabModeSync
, GrabModeAsync
, None
, None
);
2578 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2579 True
, ButtonPressMask
| ButtonReleaseMask
,
2580 GrabModeSync
, GrabModeAsync
, None
, None
);
2584 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2585 && !wwin
->flags
.is_gnustep
) {
2586 /* the passive grabs to focus the window */
2587 /* if (wPreferences.focus_mode == WKF_CLICK) */
2588 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2589 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2594 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2596 if (attr
->flags
& GSExtraFlagsAttr
) {
2597 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2598 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2599 wWindowUpdateButtonImages(wwin
);
2604 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2606 WWindowState
*wstate
;
2608 wstate
= malloc(sizeof(WWindowState
));
2612 memset(wstate
, 0, sizeof(WWindowState
));
2615 wstate
->instance
= wstrdup(instance
);
2617 wstate
->class = wstrdup(class);
2619 wstate
->command
= wstrdup(command
);
2620 wstate
->state
= state
;
2622 wstate
->next
= windowState
;
2623 windowState
= wstate
;
2628 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2630 WMagicNumber
wWindowGetSavedState(Window win
)
2632 char *instance
, *class, *command
= NULL
;
2633 WWindowState
*wstate
= windowState
;
2638 command
= GetCommandForWindow(win
);
2642 if (PropGetWMClass(win
, &class, &instance
)) {
2644 if (SAME(instance
, wstate
->instance
) &&
2645 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2648 wstate
= wstate
->next
;
2664 void wWindowDeleteSavedState(WMagicNumber id
)
2666 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2668 if (!wstate
|| !windowState
)
2672 if (tmp
== wstate
) {
2673 windowState
= wstate
->next
;
2674 if (wstate
->instance
)
2675 wfree(wstate
->instance
);
2677 wfree(wstate
->class);
2678 if (wstate
->command
)
2679 wfree(wstate
->command
);
2680 wfree(wstate
->state
);
2684 if (tmp
->next
== wstate
) {
2685 tmp
->next
= wstate
->next
;
2686 if (wstate
->instance
)
2687 wfree(wstate
->instance
);
2689 wfree(wstate
->class);
2690 if (wstate
->command
)
2691 wfree(wstate
->command
);
2692 wfree(wstate
->state
);
2701 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2703 WWindowState
*tmp
, *wstate
;
2709 if (tmp
->pid
== pid
) {
2710 wstate
= windowState
;
2711 windowState
= tmp
->next
;
2712 if (wstate
->instance
)
2713 wfree(wstate
->instance
);
2715 wfree(wstate
->class);
2716 if (wstate
->command
)
2717 wfree(wstate
->command
);
2718 wfree(wstate
->state
);
2722 if (tmp
->next
->pid
== pid
) {
2724 tmp
->next
= wstate
->next
;
2725 if (wstate
->instance
)
2726 wfree(wstate
->instance
);
2728 wfree(wstate
->class);
2729 if (wstate
->command
)
2730 wfree(wstate
->command
);
2731 wfree(wstate
->state
);
2740 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2742 if (wwin
->flags
.omnipresent
== flag
)
2745 wwin
->flags
.omnipresent
= flag
;
2746 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2749 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2751 WWindow
*wwin
= data
;
2753 #ifndef NUMLOCK_HACK
2754 if ((event
->xbutton
.state
& ValidModMask
)
2755 != (event
->xbutton
.state
& ~LockMask
)) {
2756 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2757 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2761 event
->xbutton
.state
&= ValidModMask
;
2763 CloseWindowMenu(wwin
->screen_ptr
);
2765 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2766 && !WFLAGP(wwin
, no_focusable
)) {
2767 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2770 if (event
->xbutton
.button
== Button1
)
2771 wRaiseFrame(wwin
->frame
->core
);
2773 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2774 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2775 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2776 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2781 if (event
->xbutton
.state
& MOD_MASK
) {
2782 /* move the window */
2783 wMouseMoveWindow(wwin
, event
);
2784 XUngrabPointer(dpy
, CurrentTime
);
2786 wMouseResizeWindow(wwin
, event
);
2787 XUngrabPointer(dpy
, CurrentTime
);
2791 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2793 WWindow
*wwin
= data
;
2795 event
->xbutton
.state
&= ValidModMask
;
2797 if (event
->xbutton
.button
== Button1
) {
2798 if (event
->xbutton
.state
== 0) {
2799 if (!WFLAGP(wwin
, no_shadeable
)) {
2801 if (wwin
->flags
.shaded
)
2802 wUnshadeWindow(wwin
);
2809 if (event
->xbutton
.state
& ControlMask
)
2810 dir
|= MAX_VERTICAL
;
2812 if (event
->xbutton
.state
& ShiftMask
) {
2813 dir
|= MAX_HORIZONTAL
;
2814 if (!(event
->xbutton
.state
& ControlMask
))
2815 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2818 /* maximize window */
2819 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2820 int ndir
= dir
^ wwin
->flags
.maximized
;
2823 wMaximizeWindow(wwin
, ndir
);
2825 wUnmaximizeWindow(wwin
);
2828 } else if (event
->xbutton
.button
== Button3
) {
2829 if (event
->xbutton
.state
& MOD_MASK
) {
2830 wHideOtherApplications(wwin
);
2832 } else if (event
->xbutton
.button
== Button2
) {
2833 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2834 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2836 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2837 wUnshadeWindow(wwin
);
2841 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2843 WWindow
*wwin
= desc
->parent
;
2844 unsigned int new_width
, w_scale
;
2845 unsigned int new_height
, h_scale
;
2846 unsigned int resize_width_increment
= 0;
2847 unsigned int resize_height_increment
= 0;
2849 if (wwin
->normal_hints
) {
2850 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2851 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2852 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2853 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2855 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2856 resize_width_increment
= wPreferences
.resize_increment
;
2857 resize_height_increment
= wPreferences
.resize_increment
;
2860 event
->xbutton
.state
&= ValidModMask
;
2862 CloseWindowMenu(wwin
->screen_ptr
);
2864 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2865 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2867 if (event
->xbutton
.button
== Button1
)
2868 wRaiseFrame(wwin
->frame
->core
);
2870 if (event
->xbutton
.state
& ControlMask
) {
2871 if (event
->xbutton
.button
== Button4
) {
2872 new_width
= wwin
->client
.width
- resize_width_increment
;
2873 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2874 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2876 if (event
->xbutton
.button
== Button5
) {
2877 new_width
= wwin
->client
.width
+ resize_width_increment
;
2878 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2879 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2883 if (event
->xbutton
.state
& MOD_MASK
) {
2884 /* move the window */
2885 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2886 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2887 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2890 if (event
->xbutton
.button
== Button3
) {
2891 wMouseResizeWindow(wwin
, event
);
2892 } else if (event
->xbutton
.button
== Button4
) {
2893 new_height
= wwin
->client
.height
- resize_height_increment
;
2894 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2895 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2896 } else if (event
->xbutton
.button
== Button5
) {
2897 new_height
= wwin
->client
.height
+ resize_height_increment
;
2898 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2899 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2900 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2901 wMouseMoveWindow(wwin
, event
);
2903 XUngrabPointer(dpy
, CurrentTime
);
2907 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2909 WWindow
*wwin
= (WWindow
*) data
;
2911 #ifndef NUMLOCK_HACK
2912 if ((event
->xbutton
.state
& ValidModMask
)
2913 != (event
->xbutton
.state
& ~LockMask
)) {
2914 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2915 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2918 event
->xbutton
.state
&= ValidModMask
;
2920 CloseWindowMenu(wwin
->screen_ptr
);
2922 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2923 && !WFLAGP(wwin
, no_focusable
)) {
2924 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2927 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2929 if (event
->xbutton
.button
== Button1
) {
2930 if (event
->xbutton
.state
& MOD_MASK
) {
2931 wLowerFrame(wwin
->frame
->core
);
2933 wRaiseFrame(wwin
->frame
->core
);
2936 if ((event
->xbutton
.state
& ShiftMask
)
2937 && !(event
->xbutton
.state
& ControlMask
)) {
2938 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2941 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2942 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2943 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2944 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2948 /* move the window */
2949 wMouseMoveWindow(wwin
, event
);
2951 XUngrabPointer(dpy
, CurrentTime
);
2952 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2953 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2954 WObjDescriptor
*desc
;
2956 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2957 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2958 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2959 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2963 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2965 /* allow drag select */
2966 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2967 event
->xany
.send_event
= True
;
2968 (*desc
->handle_mousedown
) (desc
, event
);
2970 XUngrabPointer(dpy
, CurrentTime
);
2974 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2976 WWindow
*wwin
= data
;
2978 event
->xbutton
.state
&= ValidModMask
;
2980 CloseWindowMenu(wwin
->screen_ptr
);
2982 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2985 /* if control-click, kill the client */
2986 if (event
->xbutton
.state
& ControlMask
) {
2989 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2990 /* send delete message */
2991 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2996 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2998 WWindow
*wwin
= data
;
3000 CloseWindowMenu(wwin
->screen_ptr
);
3002 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3005 /* send delete message */
3006 if (wwin
->protocols
.DELETE_WINDOW
) {
3007 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3013 #ifdef XKB_BUTTON_HINT
3014 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3016 WWindow
*wwin
= data
;
3017 WFrameWindow
*fwin
= wwin
->frame
;
3018 WScreen
*scr
= fwin
->screen_ptr
;
3021 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3023 tl
= wwin
->frame
->languagemode
;
3024 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3025 wwin
->frame
->last_languagemode
= tl
;
3026 wSetFocusTo(scr
, wwin
);
3027 wwin
->frame
->languagebutton_image
=
3028 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3029 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3030 if (event
->xbutton
.button
== Button3
)
3032 wRaiseFrame(fwin
->core
);
3036 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3038 WWindow
*wwin
= data
;
3040 event
->xbutton
.state
&= ValidModMask
;
3042 CloseWindowMenu(wwin
->screen_ptr
);
3044 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3047 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3048 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3051 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3053 wapp
= wApplicationOf(wwin
->main_window
);
3054 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3055 wHideApplication(wapp
);
3056 } else if (event
->xbutton
.state
== 0) {
3057 wIconifyWindow(wwin
);