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
,
1129 &wPreferences
.window_title_min_height
,
1130 &wPreferences
.window_title_max_height
,
1132 scr
->window_title_texture
,
1133 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1135 wwin
->frame
->flags
.is_client_window_frame
= 1;
1136 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1138 /* setup button images */
1139 wWindowUpdateButtonImages(wwin
);
1141 /* hide unused buttons */
1143 if (WFLAGP(wwin
, no_close_button
))
1144 foo
|= WFF_RIGHT_BUTTON
;
1145 if (WFLAGP(wwin
, no_miniaturize_button
))
1146 foo
|= WFF_LEFT_BUTTON
;
1147 #ifdef XKB_BUTTON_HINT
1148 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1149 foo
|= WFF_LANGUAGE_BUTTON
;
1152 wFrameWindowHideButton(wwin
->frame
, foo
);
1154 wwin
->frame
->child
= wwin
;
1155 wwin
->frame
->workspace
= workspace
;
1156 wwin
->frame
->on_click_left
= windowIconifyClick
;
1158 #ifdef XKB_BUTTON_HINT
1159 if (wPreferences
.modelock
)
1160 wwin
->frame
->on_click_language
= windowLanguageClick
;
1163 wwin
->frame
->on_click_right
= windowCloseClick
;
1164 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1165 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1166 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1167 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1169 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1170 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1171 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1176 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1178 /* if gravity is to the south, account for the border sizes */
1180 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1184 * wWindowConfigure() will init the client window's size
1185 * (wwin->client.{width,height}) and all other geometry
1186 * related variables (frame_x,frame_y)
1188 wWindowConfigure(wwin
, x
, y
, width
, height
);
1190 /* to make sure the window receives it's new position after reparenting */
1191 wWindowSynthConfigureNotify(wwin
);
1194 * Setup descriptors and save window to internal
1197 if (wwin
->main_window
!= None
) {
1201 /* Leader windows do not necessary set themselves as leaders.
1202 * If this is the case, point the leader of this window to
1204 leader
= wWindowFor(wwin
->main_window
);
1205 if (leader
&& leader
->main_window
== None
) {
1206 leader
->main_window
= leader
->client_win
;
1208 app
= wApplicationCreate(wwin
);
1210 app
->last_workspace
= workspace
;
1213 * Do application specific stuff, like setting application
1217 if (wwin
->flags
.hidden
) {
1218 /* if the window was set to hidden because it was hidden
1219 * in a previous incarnation and that state was restored */
1220 app
->flags
.hidden
= 1;
1221 } else if (app
->flags
.hidden
) {
1222 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1223 wwin
->flags
.hidden
= 1;
1225 wUnhideApplication(app
, False
, False
);
1233 /* setup the frame descriptor */
1234 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1235 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1236 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1238 /* don't let windows go away if we die */
1239 XAddToSaveSet(dpy
, window
);
1241 XLowerWindow(dpy
, window
);
1243 /* if window is in this workspace and should be mapped, then map it */
1244 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1245 && !wwin
->flags
.hidden
&& !withdraw
) {
1247 /* The following "if" is to avoid crashing of clients that expect
1248 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1249 * after the return from this function.
1251 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1252 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1254 wClientSetState(wwin
, NormalState
, None
);
1258 /* if not auto focus, then map the window under the currently
1260 #define _WIDTH(w) (w)->frame->core->width
1261 #define _HEIGHT(w) (w)->frame->core->height
1262 if (!wPreferences
.auto_focus
&& scr
->focused_window
1263 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1265 (_WIDTH(scr
->focused_window
) * 5) / 3
1267 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1268 && WINDOW_LEVEL(scr
->focused_window
) ==
1270 || wwin
->flags
.maximized
)) {
1271 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1278 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1279 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1281 * The brain damaged idiotic non-click to focus modes will
1282 * have trouble with this because:
1284 * 1. window is created and mapped by the client
1285 * 2. window is mapped by wmaker in small size
1286 * 3. window is animated to grow to normal size
1287 * 4. this function returns to normal event loop
1288 * 5. eventually, the EnterNotify event that would trigger
1289 * the window focusing (if the mouse is over that window)
1290 * will be processed by wmaker.
1291 * But since this event will be rather delayed
1292 * (step 3 has a large delay) the time when the event ocurred
1293 * and when it is processed, the client that owns that window
1294 * will reject the XSetInputFocus() for it.
1296 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1297 DoWindowBirth(wwin
);
1303 /* setup stacking descriptor */
1304 if (transientOwner
) {
1305 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1307 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1310 if (!scr
->focused_window
) {
1311 /* first window on the list */
1314 scr
->focused_window
= wwin
;
1318 /* add window at beginning of focus window list */
1319 tmp
= scr
->focused_window
;
1327 /* raise is set to true if we un-hid the app when this window was born.
1328 * we raise, else old windows of this app will be above this new one. */
1330 wRaiseFrame(wwin
->frame
->core
);
1333 /* Update name must come after WApplication stuff is done */
1334 wWindowUpdateName(wwin
, title
);
1341 * Final preparations before window is ready to go
1343 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1345 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1346 if (((transientOwner
&& transientOwner
->flags
.focused
)
1347 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1349 /* only auto_focus if on same screen as mouse
1350 * (and same head for xinerama mode)
1351 * TODO: make it an option */
1353 /*TODO add checking the head of the window, is it available? */
1354 short same_screen
= 0, same_head
= 1;
1360 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1361 &foo
, &foo
, &foo
, &foo
, &bar
) != False
) {
1365 if (same_screen
== 1 && same_head
== 1) {
1366 wSetFocusTo(scr
, wwin
);
1370 wWindowResetMouseGrabs(wwin
);
1372 if (!WFLAGP(wwin
, no_bind_keys
))
1373 wWindowSetKeyGrabs(wwin
);
1375 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1376 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1378 /* Setup Notification Observers */
1379 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1381 /* Cleanup temporary stuff */
1383 wWindowDeleteSavedState(win_state
);
1385 /* If the window must be withdrawed, then do it now.
1386 * Must do some optimization, 'though */
1388 wwin
->flags
.mapped
= 0;
1389 wClientSetState(wwin
, WithdrawnState
, None
);
1390 wUnmanageWindow(wwin
, True
, False
);
1397 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1398 char *title
, int x
, int y
, int width
, int height
)
1403 wwin
= wWindowCreate();
1405 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1407 wwin
->flags
.internal_window
= 1;
1409 WSETUFLAG(wwin
, omnipresent
, 1);
1410 WSETUFLAG(wwin
, no_shadeable
, 1);
1411 WSETUFLAG(wwin
, no_resizable
, 1);
1412 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1414 wwin
->focus_mode
= WFM_PASSIVE
;
1415 wwin
->client_win
= window
;
1416 wwin
->screen_ptr
= scr
;
1417 wwin
->transient_for
= owner
;
1420 wwin
->client
.width
= width
;
1421 wwin
->client
.height
= height
;
1422 wwin
->frame_x
= wwin
->client
.x
;
1423 wwin
->frame_y
= wwin
->client
.y
;
1425 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1426 foo
|= WFF_TITLEBAR
;
1427 #ifdef XKB_BUTTON_HINT
1428 foo
|= WFF_LANGUAGE_BUTTON
;
1431 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1432 wwin
->frame_x
, wwin
->frame_y
,
1434 &wPreferences
.window_title_clearance
,
1435 &wPreferences
.window_title_min_height
,
1436 &wPreferences
.window_title_max_height
,
1438 scr
->window_title_texture
,
1439 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1441 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1443 wwin
->frame
->flags
.is_client_window_frame
= 1;
1444 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1446 wFrameWindowChangeTitle(wwin
->frame
, title
);
1448 /* setup button images */
1449 wWindowUpdateButtonImages(wwin
);
1452 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1454 wwin
->frame
->child
= wwin
;
1455 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1457 #ifdef XKB_BUTTON_HINT
1458 if (wPreferences
.modelock
)
1459 wwin
->frame
->on_click_language
= windowLanguageClick
;
1462 wwin
->frame
->on_click_right
= windowCloseClick
;
1463 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1464 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1465 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1466 wwin
->client
.y
+= wwin
->frame
->top_width
;
1468 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1469 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1471 /* setup the frame descriptor */
1472 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1473 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1474 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1476 XLowerWindow(dpy
, window
);
1477 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1479 /* setup stacking descriptor */
1480 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1482 tmp
= wWindowFor(wwin
->transient_for
);
1484 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1486 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1489 if (!scr
->focused_window
) {
1490 /* first window on the list */
1493 scr
->focused_window
= wwin
;
1497 /* add window at beginning of focus window list */
1498 tmp
= scr
->focused_window
;
1506 if (wwin
->flags
.is_gnustep
== 0)
1507 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1509 /* if (wPreferences.auto_focus) */
1510 wSetFocusTo(scr
, wwin
);
1511 wWindowResetMouseGrabs(wwin
);
1512 wWindowSetKeyGrabs(wwin
);
1518 *----------------------------------------------------------------------
1520 * Removes the frame window from a window and destroys all data
1521 * related to it. The window will be reparented back to the root window
1522 * if restore is True.
1525 * Everything related to the window is destroyed and the window
1526 * is removed from the window lists. Focus is set to the previous on the
1528 *----------------------------------------------------------------------
1530 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1532 WCoreWindow
*frame
= wwin
->frame
->core
;
1533 WWindow
*owner
= NULL
;
1534 WWindow
*newFocusedWindow
= NULL
;
1536 WScreen
*scr
= wwin
->screen_ptr
;
1538 /* First close attribute editor window if open */
1539 if (wwin
->flags
.inspector_open
) {
1540 wCloseInspectorForWindow(wwin
);
1543 /* Close window menu if it's open for this window */
1544 if (wwin
->flags
.menu_open_for_me
) {
1545 CloseWindowMenu(scr
);
1549 if (!wwin
->flags
.internal_window
)
1550 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1552 /* If this is a leader window, we still need to listen for
1553 * DestroyNotify and PropertyNotify. */
1554 if (wApplicationOf(wwin
->client_win
)) {
1555 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1557 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1560 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1561 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1564 XUnmapWindow(dpy
, frame
->window
);
1566 XUnmapWindow(dpy
, wwin
->client_win
);
1568 /* deselect window */
1569 wSelectWindow(wwin
, False
);
1571 /* remove all pending events on window */
1572 /* I think this only matters for autoraise */
1573 if (wPreferences
.raise_delay
)
1574 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1578 /* reparent the window back to the root */
1580 wClientRestore(wwin
);
1582 if (wwin
->transient_for
!= scr
->root_win
) {
1583 owner
= wWindowFor(wwin
->transient_for
);
1585 if (!owner
->flags
.semi_focused
) {
1588 owner
->flags
.semi_focused
= 0;
1593 wasFocused
= wwin
->flags
.focused
;
1595 /* remove from window focus list */
1596 if (!wwin
->prev
&& !wwin
->next
) {
1597 /* was the only window */
1598 scr
->focused_window
= NULL
;
1599 newFocusedWindow
= NULL
;
1604 wwin
->prev
->next
= wwin
->next
;
1606 wwin
->next
->prev
= wwin
->prev
;
1608 scr
->focused_window
= wwin
->prev
;
1609 scr
->focused_window
->next
= NULL
;
1612 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1614 /* if in click to focus mode and the window
1615 * was a transient, focus the owner window
1618 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1619 tmp
= wWindowFor(wwin
->transient_for
);
1620 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1624 /* otherwise, focus the next one in the focus list */
1626 tmp
= scr
->focused_window
;
1627 while (tmp
) { /* look for one in the window list first */
1628 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1629 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1633 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1634 tmp
= scr
->focused_window
;
1636 if (!WFLAGP(tmp
, no_focusable
)
1637 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1644 newFocusedWindow
= tmp
;
1646 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1651 /* This is to let the root window get the keyboard input
1652 * if Sloppy focus mode and no other window get focus.
1653 * This way keybindings will not freeze.
1656 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1657 tmp
= wWindowFor(win
);
1660 newFocusedWindow
= tmp
;
1662 newFocusedWindow
= NULL
;
1666 if (!wwin
->flags
.internal_window
)
1667 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1669 if (newFocusedWindow
!= owner
&& owner
) {
1670 if (wwin
->flags
.is_gnustep
== 0)
1671 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1673 wSetFocusTo(scr
, newFocusedWindow
);
1676 /* Close menu and unhighlight */
1677 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1678 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1679 if (oapp
&& oapp
!= napp
) {
1680 wAppMenuUnmap(oapp
->menu
);
1681 wApplicationDeactivate(oapp
);
1684 wWindowDestroy(wwin
);
1688 void wWindowMap(WWindow
*wwin
)
1690 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1691 if (!wwin
->flags
.shaded
) {
1692 /* window will be remapped when getting MapNotify */
1693 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1694 XMapWindow(dpy
, wwin
->client_win
);
1695 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1697 wwin
->flags
.mapped
= 1;
1701 void wWindowUnmap(WWindow
*wwin
)
1703 wwin
->flags
.mapped
= 0;
1705 /* prevent window withdrawal when getting UnmapNotify */
1706 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1707 XUnmapWindow(dpy
, wwin
->client_win
);
1708 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1710 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1713 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1718 #ifdef KEEP_XKB_LOCK_STATUS
1719 if (wPreferences
.modelock
) {
1720 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1722 #endif /* KEEP_XKB_LOCK_STATUS */
1724 wwin
->flags
.semi_focused
= 0;
1726 if (wwin
->flags
.is_gnustep
== 0)
1727 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1729 wwin
->flags
.focused
= 1;
1731 wWindowResetMouseGrabs(wwin
);
1733 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1735 if (owin
== wwin
|| !owin
)
1738 nowner
= wWindowFor(wwin
->transient_for
);
1740 /* new window is a transient for the old window */
1741 if (nowner
== owin
) {
1742 owin
->flags
.semi_focused
= 1;
1743 wWindowUnfocus(nowner
);
1747 oowner
= wWindowFor(owin
->transient_for
);
1749 /* new window is owner of old window */
1750 if (wwin
== oowner
) {
1751 wWindowUnfocus(owin
);
1756 wWindowUnfocus(owin
);
1760 /* new window has same owner of old window */
1761 if (oowner
== nowner
) {
1762 /* prevent unfocusing of owner */
1763 oowner
->flags
.semi_focused
= 0;
1764 wWindowUnfocus(owin
);
1765 oowner
->flags
.semi_focused
= 1;
1770 /* nowner != NULL && oowner != nowner */
1771 nowner
->flags
.semi_focused
= 1;
1772 wWindowUnfocus(nowner
);
1773 wWindowUnfocus(owin
);
1776 void wWindowUnfocus(WWindow
*wwin
)
1778 CloseWindowMenu(wwin
->screen_ptr
);
1780 if (wwin
->flags
.is_gnustep
== 0)
1781 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1783 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1785 owner
= wWindowFor(wwin
->transient_for
);
1786 if (owner
&& owner
->flags
.semi_focused
) {
1787 owner
->flags
.semi_focused
= 0;
1788 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1789 wWindowUnfocus(owner
);
1790 wFrameWindowPaint(owner
->frame
);
1794 wwin
->flags
.focused
= 0;
1795 wWindowResetMouseGrabs(wwin
);
1796 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1799 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1806 wwin
->flags
.wm_name_changed
= 1;
1809 /* the hint was removed */
1810 title
= DEF_WINDOW_TITLE
;
1815 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1816 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1821 *----------------------------------------------------------------------
1823 * wWindowConstrainSize--
1824 * Constrains size for the client window, taking the maximal size,
1825 * window resize increments and other size hints into account.
1828 * The closest size to what was given that the client window can
1831 *----------------------------------------------------------------------
1833 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1835 int width
= (int)*nwidth
;
1836 int height
= (int)*nheight
;
1839 int minW
= 1, minH
= 1;
1840 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1841 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1842 int minAX
= -1, minAY
= -1;
1843 int maxAX
= -1, maxAY
= -1;
1847 if (wwin
->normal_hints
) {
1848 winc
= wwin
->normal_hints
->width_inc
;
1849 hinc
= wwin
->normal_hints
->height_inc
;
1850 minW
= wwin
->normal_hints
->min_width
;
1851 minH
= wwin
->normal_hints
->min_height
;
1852 maxW
= wwin
->normal_hints
->max_width
;
1853 maxH
= wwin
->normal_hints
->max_height
;
1854 if (wwin
->normal_hints
->flags
& PAspect
) {
1855 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1856 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1857 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1858 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1861 baseW
= wwin
->normal_hints
->base_width
;
1862 baseH
= wwin
->normal_hints
->base_height
;
1875 /* aspect ratio code borrowed from olwm */
1877 /* adjust max aspect ratio */
1878 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1879 if (maxAX
> maxAY
) {
1880 height
= (width
* maxAY
) / maxAX
;
1881 if (height
> maxH
) {
1883 width
= (height
* maxAX
) / maxAY
;
1886 width
= (height
* maxAX
) / maxAY
;
1889 height
= (width
* maxAY
) / maxAX
;
1894 /* adjust min aspect ratio */
1895 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1896 if (minAX
> minAY
) {
1897 height
= (width
* minAY
) / minAX
;
1898 if (height
< minH
) {
1900 width
= (height
* minAX
) / minAY
;
1903 width
= (height
* minAX
) / minAY
;
1906 height
= (width
* minAY
) / minAX
;
1913 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1915 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1918 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1920 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1922 /* broken stupid apps may cause preposterous values for these.. */
1929 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1930 unsigned int *width
, unsigned int *height
)
1932 int baseW
= 0, baseH
= 0;
1933 int winc
= 1, hinc
= 1;
1935 if (wwin
->normal_hints
) {
1936 baseW
= wwin
->normal_hints
->base_width
;
1937 baseH
= wwin
->normal_hints
->base_height
;
1939 winc
= wwin
->normal_hints
->width_inc
;
1940 hinc
= wwin
->normal_hints
->height_inc
;
1944 *width
= maxW
- (maxW
- baseW
) % winc
;
1947 *height
= maxH
- (maxH
- baseH
) % hinc
;
1950 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1952 WScreen
*scr
= wwin
->screen_ptr
;
1956 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1959 if (workspace
!= scr
->current_workspace
) {
1960 /* Sent to other workspace. Unmap window */
1961 if ((wwin
->flags
.mapped
1962 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1963 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1965 wapp
= wApplicationOf(wwin
->main_window
);
1967 wapp
->last_workspace
= workspace
;
1969 if (wwin
->flags
.miniaturized
) {
1971 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1972 wwin
->icon
->mapped
= 0;
1976 wSetFocusTo(scr
, NULL
);
1980 /* brought to current workspace. Map window */
1981 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1983 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1984 wwin
->icon
->mapped
= 1;
1986 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1990 if (!IS_OMNIPRESENT(wwin
)) {
1991 int oldWorkspace
= wwin
->frame
->workspace
;
1993 wwin
->frame
->workspace
= workspace
;
1995 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
2002 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2006 sevent
.type
= ConfigureNotify
;
2007 sevent
.xconfigure
.display
= dpy
;
2008 sevent
.xconfigure
.event
= wwin
->client_win
;
2009 sevent
.xconfigure
.window
= wwin
->client_win
;
2011 sevent
.xconfigure
.x
= wwin
->client
.x
;
2012 sevent
.xconfigure
.y
= wwin
->client
.y
;
2013 sevent
.xconfigure
.width
= wwin
->client
.width
;
2014 sevent
.xconfigure
.height
= wwin
->client
.height
;
2016 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2017 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2018 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2020 sevent
.xconfigure
.above
= None
;
2022 sevent
.xconfigure
.override_redirect
= False
;
2023 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2028 *----------------------------------------------------------------------
2029 * wWindowConfigure()
2031 * req_x, req_y: new requested positions for the frame
2032 * req_width, req_height: new requested sizes for the client
2034 * Configures the frame, decorations and client window to the specified
2035 * geometry, whose validity is not checked -- wWindowConstrainSize()
2036 * must be used for that.
2037 * The size parameters are for the client window, but the position is
2039 * The client window receives a ConfigureNotify event, according
2040 * to what ICCCM says.
2046 * Window size and position are changed and client window receives
2047 * a ConfigureNotify event.
2048 *----------------------------------------------------------------------
2050 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2052 int synth_notify
= False
;
2055 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2057 * if the window is being moved but not resized then
2058 * send a synthetic ConfigureNotify
2060 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2061 synth_notify
= True
;
2064 if (WFLAGP(wwin
, dont_move_off
))
2065 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2067 if (req_width
< MIN_WINDOW_SIZE
)
2068 req_width
= MIN_WINDOW_SIZE
;
2069 if (req_height
< MIN_WINDOW_SIZE
)
2070 req_height
= MIN_WINDOW_SIZE
;
2072 /* If growing, resize inner part before frame,
2073 * if shrinking, resize frame before.
2074 * This will prevent the frame (that can have a different color)
2075 * to be exposed, causing flicker */
2076 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2077 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2079 if (wwin
->flags
.shaded
) {
2080 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2081 wwin
->old_geometry
.height
= req_height
;
2085 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2087 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2090 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2091 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2093 wwin
->client
.x
= req_x
;
2094 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2095 wwin
->client
.width
= req_width
;
2096 wwin
->client
.height
= req_height
;
2098 wwin
->client
.x
= req_x
;
2099 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2101 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2103 wwin
->frame_x
= req_x
;
2104 wwin
->frame_y
= req_y
;
2105 if (HAS_BORDER(wwin
)) {
2106 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2107 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2110 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2111 wWindowSetShape(wwin
);
2116 wWindowSynthConfigureNotify(wwin
);
2120 /* req_x, req_y: new position of the frame */
2121 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2123 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2124 int synth_notify
= False
;
2126 /* Send a synthetic ConfigureNotify event for every window movement. */
2127 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2128 synth_notify
= True
;
2131 /* A single synthetic ConfigureNotify event is sent at the end of
2132 * a completed (opaque) movement in moveres.c */
2135 if (WFLAGP(wwin
, dont_move_off
))
2136 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2137 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2139 wwin
->client
.x
= req_x
;
2140 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2141 if (HAS_BORDER(wwin
)) {
2142 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2143 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2146 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2148 wwin
->frame_x
= req_x
;
2149 wwin
->frame_y
= req_y
;
2151 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2153 wWindowSynthConfigureNotify(wwin
);
2157 void wWindowUpdateButtonImages(WWindow
*wwin
)
2159 WScreen
*scr
= wwin
->screen_ptr
;
2160 Pixmap pixmap
, mask
;
2161 WFrameWindow
*fwin
= wwin
->frame
;
2163 if (!HAS_TITLEBAR(wwin
))
2166 /* miniaturize button */
2167 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2168 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2169 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2171 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2172 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2177 if (fwin
->lbutton_image
2178 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2179 wPixmapDestroy(fwin
->lbutton_image
);
2180 fwin
->lbutton_image
= NULL
;
2183 if (!fwin
->lbutton_image
) {
2184 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2185 fwin
->lbutton_image
->client_owned
= 1;
2186 fwin
->lbutton_image
->client_owned_mask
= 1;
2189 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2190 wPixmapDestroy(fwin
->lbutton_image
);
2192 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2195 #ifdef XKB_BUTTON_HINT
2196 if (!WFLAGP(wwin
, no_language_button
)) {
2197 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2198 wPixmapDestroy(fwin
->languagebutton_image
);
2200 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2206 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2207 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2209 if (!WFLAGP(wwin
, no_close_button
)) {
2210 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2211 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2213 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2214 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2218 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2219 || fwin
->rbutton_image
->mask
!= mask
)) {
2220 wPixmapDestroy(fwin
->rbutton_image
);
2221 fwin
->rbutton_image
= NULL
;
2224 if (!fwin
->rbutton_image
) {
2225 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2226 fwin
->rbutton_image
->client_owned
= 1;
2227 fwin
->rbutton_image
->client_owned_mask
= 1;
2230 } else if (WFLAGP(wwin
, kill_close
)) {
2232 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2233 wPixmapDestroy(fwin
->rbutton_image
);
2235 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2237 } else if (MGFLAGP(wwin
, broken_close
)) {
2239 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2240 wPixmapDestroy(fwin
->rbutton_image
);
2242 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2246 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2247 wPixmapDestroy(fwin
->rbutton_image
);
2249 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2253 /* force buttons to be redrawn */
2254 fwin
->flags
.need_texture_change
= 1;
2255 wFrameWindowPaint(fwin
);
2259 *---------------------------------------------------------------------------
2260 * wWindowConfigureBorders--
2261 * Update window border configuration according to attribute flags.
2263 *---------------------------------------------------------------------------
2265 void wWindowConfigureBorders(WWindow
*wwin
)
2271 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2273 #ifdef XKB_BUTTON_HINT
2274 if (wPreferences
.modelock
)
2275 flags
|= WFF_LANGUAGE_BUTTON
;
2278 if (HAS_TITLEBAR(wwin
))
2279 flags
|= WFF_TITLEBAR
;
2280 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2281 flags
|= WFF_RESIZEBAR
;
2282 if (HAS_BORDER(wwin
))
2283 flags
|= WFF_BORDER
;
2284 if (wwin
->flags
.shaded
)
2285 flags
|= WFF_IS_SHADED
;
2287 oldh
= wwin
->frame
->top_width
;
2288 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2289 if (oldh
!= wwin
->frame
->top_width
) {
2290 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2292 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2293 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2297 if (!WFLAGP(wwin
, no_miniaturize_button
)
2298 && wwin
->frame
->flags
.hide_left_button
)
2299 flags
|= WFF_LEFT_BUTTON
;
2301 #ifdef XKB_BUTTON_HINT
2302 if (!WFLAGP(wwin
, no_language_button
)
2303 && wwin
->frame
->flags
.hide_language_button
) {
2304 flags
|= WFF_LANGUAGE_BUTTON
;
2308 if (!WFLAGP(wwin
, no_close_button
)
2309 && wwin
->frame
->flags
.hide_right_button
)
2310 flags
|= WFF_RIGHT_BUTTON
;
2313 wWindowUpdateButtonImages(wwin
);
2314 wFrameWindowShowButton(wwin
->frame
, flags
);
2318 if (WFLAGP(wwin
, no_miniaturize_button
)
2319 && !wwin
->frame
->flags
.hide_left_button
)
2320 flags
|= WFF_LEFT_BUTTON
;
2322 #ifdef XKB_BUTTON_HINT
2323 if (WFLAGP(wwin
, no_language_button
)
2324 && !wwin
->frame
->flags
.hide_language_button
)
2325 flags
|= WFF_LANGUAGE_BUTTON
;
2328 if (WFLAGP(wwin
, no_close_button
)
2329 && !wwin
->frame
->flags
.hide_right_button
)
2330 flags
|= WFF_RIGHT_BUTTON
;
2333 wFrameWindowHideButton(wwin
->frame
, flags
);
2336 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2337 wWindowSetShape(wwin
);
2343 void wWindowSaveState(WWindow
* wwin
)
2348 memset(data
, 0, sizeof(long) * 10);
2349 data
[0] = wwin
->frame
->workspace
;
2350 data
[1] = wwin
->flags
.miniaturized
;
2351 data
[2] = wwin
->flags
.shaded
;
2352 data
[3] = wwin
->flags
.hidden
;
2353 data
[4] = wwin
->flags
.maximized
;
2354 if (wwin
->flags
.maximized
== 0) {
2355 data
[5] = wwin
->frame_x
;
2356 data
[6] = wwin
->frame_y
;
2357 data
[7] = wwin
->frame
->core
->width
;
2358 data
[8] = wwin
->frame
->core
->height
;
2360 data
[5] = wwin
->old_geometry
.x
;
2361 data
[6] = wwin
->old_geometry
.y
;
2362 data
[7] = wwin
->old_geometry
.width
;
2363 data
[8] = wwin
->old_geometry
.height
;
2366 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2367 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2368 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2371 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2372 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2375 static int getSavedState(Window window
, WSavedState
** state
)
2379 unsigned long nitems_ret
;
2380 unsigned long bytes_after_ret
;
2383 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2384 True
, _XA_WINDOWMAKER_STATE
,
2385 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2386 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2389 *state
= wmalloc(sizeof(WSavedState
));
2391 (*state
)->workspace
= data
[0];
2392 (*state
)->miniaturized
= data
[1];
2393 (*state
)->shaded
= data
[2];
2394 (*state
)->hidden
= data
[3];
2395 (*state
)->maximized
= data
[4];
2396 (*state
)->x
= data
[5];
2397 (*state
)->y
= data
[6];
2398 (*state
)->w
= data
[7];
2399 (*state
)->h
= data
[8];
2400 (*state
)->window_shortcuts
= data
[9];
2404 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2411 void wWindowClearShape(WWindow
* wwin
)
2413 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2414 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2418 void wWindowSetShape(WWindow
* wwin
)
2422 #ifdef OPTIMIZE_SHAPE
2427 /* only shape is the client's */
2428 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2432 /* Get array of rectangles describing the shape mask */
2433 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2438 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2444 /* insert our decoration rectangles in the rect list */
2445 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2448 if (HAS_TITLEBAR(wwin
)) {
2450 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2451 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2452 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2455 if (HAS_RESIZEBAR(wwin
)) {
2457 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2458 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2459 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2463 /* shape our frame window */
2464 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2465 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2471 #endif /* OPTIMIZE_SHAPE */
2473 if (HAS_TITLEBAR(wwin
)) {
2476 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2477 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2480 if (HAS_RESIZEBAR(wwin
)) {
2482 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2483 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2484 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2488 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2489 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2491 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2492 0, wwin
->frame
->top_width
, wwin
->client_win
,
2493 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2498 /* ====================================================================== */
2500 static FocusMode
getFocusMode(WWindow
* wwin
)
2504 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2505 if (wwin
->wm_hints
->input
== True
) {
2506 if (wwin
->protocols
.TAKE_FOCUS
)
2507 mode
= WFM_LOCALLY_ACTIVE
;
2511 if (wwin
->protocols
.TAKE_FOCUS
)
2512 mode
= WFM_GLOBALLY_ACTIVE
;
2514 mode
= WFM_NO_INPUT
;
2522 void wWindowSetKeyGrabs(WWindow
* wwin
)
2527 for (i
= 0; i
< WKBD_LAST
; i
++) {
2528 key
= &wKeyBindings
[i
];
2530 if (key
->keycode
== 0)
2532 if (key
->modifier
!= AnyModifier
) {
2533 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2534 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2536 /* Also grab all modifier combinations possible that include,
2537 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2538 * work even if the NumLock/ScrollLock key is on.
2540 wHackedGrabKey(key
->keycode
, key
->modifier
,
2541 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2544 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2545 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2548 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2551 void wWindowResetMouseGrabs(WWindow
* wwin
)
2553 /* Mouse grabs can't be done on the client window because of
2554 * ICCCM and because clients that try to do the same will crash.
2556 * But there is a problem wich makes tbar buttons of unfocused
2557 * windows not usable as the click goes to the frame window instead
2558 * of the button itself. Must figure a way to fix that.
2561 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2563 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2564 /* grabs for Meta+drag */
2565 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2566 True
, ButtonPressMask
| ButtonReleaseMask
,
2567 GrabModeSync
, GrabModeAsync
, None
, None
);
2569 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2570 * but we only grab it for Button4 and Button 5 since a lot of apps
2571 * use CTRL+Button1-3 for app related functionality
2573 if (wPreferences
.resize_increment
> 0) {
2574 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2575 True
, ButtonPressMask
| ButtonReleaseMask
,
2576 GrabModeSync
, GrabModeAsync
, None
, None
);
2577 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2578 True
, ButtonPressMask
| ButtonReleaseMask
,
2579 GrabModeSync
, GrabModeAsync
, None
, None
);
2581 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2582 True
, ButtonPressMask
| ButtonReleaseMask
,
2583 GrabModeSync
, GrabModeAsync
, None
, None
);
2584 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2585 True
, ButtonPressMask
| ButtonReleaseMask
,
2586 GrabModeSync
, GrabModeAsync
, None
, None
);
2590 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2591 && !wwin
->flags
.is_gnustep
) {
2592 /* the passive grabs to focus the window */
2593 /* if (wPreferences.focus_mode == WKF_CLICK) */
2594 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2595 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2600 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2602 if (attr
->flags
& GSExtraFlagsAttr
) {
2603 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2604 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2605 wWindowUpdateButtonImages(wwin
);
2610 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2612 WWindowState
*wstate
;
2614 wstate
= malloc(sizeof(WWindowState
));
2618 memset(wstate
, 0, sizeof(WWindowState
));
2621 wstate
->instance
= wstrdup(instance
);
2623 wstate
->class = wstrdup(class);
2625 wstate
->command
= wstrdup(command
);
2626 wstate
->state
= state
;
2628 wstate
->next
= windowState
;
2629 windowState
= wstate
;
2634 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2636 WMagicNumber
wWindowGetSavedState(Window win
)
2638 char *instance
, *class, *command
= NULL
;
2639 WWindowState
*wstate
= windowState
;
2644 command
= GetCommandForWindow(win
);
2648 if (PropGetWMClass(win
, &class, &instance
)) {
2650 if (SAME(instance
, wstate
->instance
) &&
2651 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2654 wstate
= wstate
->next
;
2670 void wWindowDeleteSavedState(WMagicNumber id
)
2672 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2674 if (!wstate
|| !windowState
)
2678 if (tmp
== wstate
) {
2679 windowState
= wstate
->next
;
2680 if (wstate
->instance
)
2681 wfree(wstate
->instance
);
2683 wfree(wstate
->class);
2684 if (wstate
->command
)
2685 wfree(wstate
->command
);
2686 wfree(wstate
->state
);
2690 if (tmp
->next
== wstate
) {
2691 tmp
->next
= wstate
->next
;
2692 if (wstate
->instance
)
2693 wfree(wstate
->instance
);
2695 wfree(wstate
->class);
2696 if (wstate
->command
)
2697 wfree(wstate
->command
);
2698 wfree(wstate
->state
);
2707 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2709 WWindowState
*tmp
, *wstate
;
2715 if (tmp
->pid
== pid
) {
2716 wstate
= windowState
;
2717 windowState
= tmp
->next
;
2718 if (wstate
->instance
)
2719 wfree(wstate
->instance
);
2721 wfree(wstate
->class);
2722 if (wstate
->command
)
2723 wfree(wstate
->command
);
2724 wfree(wstate
->state
);
2728 if (tmp
->next
->pid
== pid
) {
2730 tmp
->next
= wstate
->next
;
2731 if (wstate
->instance
)
2732 wfree(wstate
->instance
);
2734 wfree(wstate
->class);
2735 if (wstate
->command
)
2736 wfree(wstate
->command
);
2737 wfree(wstate
->state
);
2746 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2748 if (wwin
->flags
.omnipresent
== flag
)
2751 wwin
->flags
.omnipresent
= flag
;
2752 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2755 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2757 WWindow
*wwin
= data
;
2759 #ifndef NUMLOCK_HACK
2760 if ((event
->xbutton
.state
& ValidModMask
)
2761 != (event
->xbutton
.state
& ~LockMask
)) {
2762 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2763 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2767 event
->xbutton
.state
&= ValidModMask
;
2769 CloseWindowMenu(wwin
->screen_ptr
);
2771 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2772 && !WFLAGP(wwin
, no_focusable
)) {
2773 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2776 if (event
->xbutton
.button
== Button1
)
2777 wRaiseFrame(wwin
->frame
->core
);
2779 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2780 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2781 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2782 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2787 if (event
->xbutton
.state
& MOD_MASK
) {
2788 /* move the window */
2789 wMouseMoveWindow(wwin
, event
);
2790 XUngrabPointer(dpy
, CurrentTime
);
2792 wMouseResizeWindow(wwin
, event
);
2793 XUngrabPointer(dpy
, CurrentTime
);
2797 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2799 WWindow
*wwin
= data
;
2801 event
->xbutton
.state
&= ValidModMask
;
2803 if (event
->xbutton
.button
== Button1
) {
2804 if (event
->xbutton
.state
== 0) {
2805 if (!WFLAGP(wwin
, no_shadeable
)) {
2807 if (wwin
->flags
.shaded
)
2808 wUnshadeWindow(wwin
);
2815 if (event
->xbutton
.state
& ControlMask
)
2816 dir
|= MAX_VERTICAL
;
2818 if (event
->xbutton
.state
& ShiftMask
) {
2819 dir
|= MAX_HORIZONTAL
;
2820 if (!(event
->xbutton
.state
& ControlMask
))
2821 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2824 /* maximize window */
2825 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2826 int ndir
= dir
^ wwin
->flags
.maximized
;
2829 wMaximizeWindow(wwin
, ndir
);
2831 wUnmaximizeWindow(wwin
);
2834 } else if (event
->xbutton
.button
== Button3
) {
2835 if (event
->xbutton
.state
& MOD_MASK
) {
2836 wHideOtherApplications(wwin
);
2838 } else if (event
->xbutton
.button
== Button2
) {
2839 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2840 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2842 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2843 wUnshadeWindow(wwin
);
2847 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2849 WWindow
*wwin
= desc
->parent
;
2850 unsigned int new_width
, w_scale
;
2851 unsigned int new_height
, h_scale
;
2852 unsigned int resize_width_increment
= 0;
2853 unsigned int resize_height_increment
= 0;
2855 if (wwin
->normal_hints
) {
2856 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2857 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2858 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2859 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2861 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2862 resize_width_increment
= wPreferences
.resize_increment
;
2863 resize_height_increment
= wPreferences
.resize_increment
;
2866 event
->xbutton
.state
&= ValidModMask
;
2868 CloseWindowMenu(wwin
->screen_ptr
);
2870 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2871 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2873 if (event
->xbutton
.button
== Button1
)
2874 wRaiseFrame(wwin
->frame
->core
);
2876 if (event
->xbutton
.state
& ControlMask
) {
2877 if (event
->xbutton
.button
== Button4
) {
2878 new_width
= wwin
->client
.width
- resize_width_increment
;
2879 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2880 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2882 if (event
->xbutton
.button
== Button5
) {
2883 new_width
= wwin
->client
.width
+ resize_width_increment
;
2884 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2885 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2889 if (event
->xbutton
.state
& MOD_MASK
) {
2890 /* move the window */
2891 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2892 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2893 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2896 if (event
->xbutton
.button
== Button3
) {
2897 wMouseResizeWindow(wwin
, event
);
2898 } else if (event
->xbutton
.button
== Button4
) {
2899 new_height
= wwin
->client
.height
- resize_height_increment
;
2900 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2901 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2902 } else if (event
->xbutton
.button
== Button5
) {
2903 new_height
= wwin
->client
.height
+ resize_height_increment
;
2904 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2905 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2906 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2907 wMouseMoveWindow(wwin
, event
);
2909 XUngrabPointer(dpy
, CurrentTime
);
2913 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2915 WWindow
*wwin
= (WWindow
*) data
;
2917 #ifndef NUMLOCK_HACK
2918 if ((event
->xbutton
.state
& ValidModMask
)
2919 != (event
->xbutton
.state
& ~LockMask
)) {
2920 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2921 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2924 event
->xbutton
.state
&= ValidModMask
;
2926 CloseWindowMenu(wwin
->screen_ptr
);
2928 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2929 && !WFLAGP(wwin
, no_focusable
)) {
2930 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2933 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2935 if (event
->xbutton
.button
== Button1
) {
2936 if (event
->xbutton
.state
& MOD_MASK
) {
2937 wLowerFrame(wwin
->frame
->core
);
2939 wRaiseFrame(wwin
->frame
->core
);
2942 if ((event
->xbutton
.state
& ShiftMask
)
2943 && !(event
->xbutton
.state
& ControlMask
)) {
2944 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2947 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2948 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2949 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2950 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2954 /* move the window */
2955 wMouseMoveWindow(wwin
, event
);
2957 XUngrabPointer(dpy
, CurrentTime
);
2958 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2959 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2960 WObjDescriptor
*desc
;
2962 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2963 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2964 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2965 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2969 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2971 /* allow drag select */
2972 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2973 event
->xany
.send_event
= True
;
2974 (*desc
->handle_mousedown
) (desc
, event
);
2976 XUngrabPointer(dpy
, CurrentTime
);
2980 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2982 WWindow
*wwin
= data
;
2984 event
->xbutton
.state
&= ValidModMask
;
2986 CloseWindowMenu(wwin
->screen_ptr
);
2988 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2991 /* if control-click, kill the client */
2992 if (event
->xbutton
.state
& ControlMask
) {
2995 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2996 /* send delete message */
2997 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3002 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3004 WWindow
*wwin
= data
;
3006 CloseWindowMenu(wwin
->screen_ptr
);
3008 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3011 /* send delete message */
3012 if (wwin
->protocols
.DELETE_WINDOW
) {
3013 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3019 #ifdef XKB_BUTTON_HINT
3020 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3022 WWindow
*wwin
= data
;
3023 WFrameWindow
*fwin
= wwin
->frame
;
3024 WScreen
*scr
= fwin
->screen_ptr
;
3027 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3029 tl
= wwin
->frame
->languagemode
;
3030 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3031 wwin
->frame
->last_languagemode
= tl
;
3032 wSetFocusTo(scr
, wwin
);
3033 wwin
->frame
->languagebutton_image
=
3034 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3035 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3036 if (event
->xbutton
.button
== Button3
)
3038 wRaiseFrame(fwin
->core
);
3042 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3044 WWindow
*wwin
= data
;
3046 event
->xbutton
.state
&= ValidModMask
;
3048 CloseWindowMenu(wwin
->screen_ptr
);
3050 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3053 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3054 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3057 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3059 wapp
= wApplicationOf(wwin
->main_window
);
3060 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3061 wHideApplication(wapp
);
3062 } else if (event
->xbutton
.state
== 0) {
3063 wIconifyWindow(wwin
);