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);
126 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
127 wWindowSynthConfigureNotify(wwin
);
130 if (flags
& WTextureSettings
)
131 wwin
->frame
->flags
.need_texture_remake
= 1;
133 if (flags
& (WTextureSettings
| WColorSettings
)) {
134 if (wwin
->frame
->titlebar
)
135 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
137 wFrameWindowPaint(wwin
->frame
);
142 WWindow
*wWindowFor(Window window
)
144 WObjDescriptor
*desc
;
149 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
152 if (desc
->parent_type
== WCLASS_WINDOW
)
154 else if (desc
->parent_type
== WCLASS_FRAME
) {
155 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
156 if (frame
->flags
.is_client_window_frame
)
163 WWindow
*wWindowCreate(void)
167 wwin
= wmalloc(sizeof(WWindow
));
170 memset(wwin
, 0, sizeof(WWindow
));
172 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
173 wwin
->client_descriptor
.parent
= wwin
;
174 wwin
->client_descriptor
.self
= wwin
;
175 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
180 void wWindowDestroy(WWindow
*wwin
)
184 if (wwin
->screen_ptr
->cmap_window
== wwin
)
185 wwin
->screen_ptr
->cmap_window
= NULL
;
187 WMRemoveNotificationObserver(wwin
);
189 wwin
->flags
.destroyed
= 1;
191 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
192 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
195 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
197 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
198 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
199 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
203 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
204 wwin
->fake_group
->retainCount
--;
205 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
206 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
207 wwin
->fake_group
->leader
= None
;
208 wwin
->fake_group
->origLeader
= None
;
213 if (wwin
->normal_hints
)
214 XFree(wwin
->normal_hints
);
217 XFree(wwin
->wm_hints
);
219 if (wwin
->wm_instance
)
220 XFree(wwin
->wm_instance
);
223 XFree(wwin
->wm_class
);
225 if (wwin
->wm_gnustep_attr
)
226 wfree(wwin
->wm_gnustep_attr
);
228 if (wwin
->cmap_windows
)
229 XFree(wwin
->cmap_windows
);
231 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
234 wFrameWindowDestroy(wwin
->frame
);
237 RemoveFromStackList(wwin
->icon
->core
);
238 wIconDestroy(wwin
->icon
);
239 if (wPreferences
.auto_arrange_icons
)
240 wArrangeIcons(wwin
->screen_ptr
, True
);
242 if (wwin
->net_icon_image
)
243 RReleaseImage(wwin
->net_icon_image
);
248 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
250 if (gs_hints
->flags
& GSWindowStyleAttr
) {
251 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
252 wwin
->client_flags
.no_border
= 1;
253 wwin
->client_flags
.no_titlebar
= 1;
254 wwin
->client_flags
.no_closable
= 1;
255 wwin
->client_flags
.no_miniaturizable
= 1;
256 wwin
->client_flags
.no_resizable
= 1;
257 wwin
->client_flags
.no_close_button
= 1;
258 wwin
->client_flags
.no_miniaturize_button
= 1;
259 wwin
->client_flags
.no_resizebar
= 1;
261 wwin
->client_flags
.no_close_button
=
262 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
264 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
266 wwin
->client_flags
.no_miniaturize_button
=
267 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
269 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
271 wwin
->client_flags
.no_resizebar
=
272 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
274 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
276 /* these attributes supposedly imply in the existence
278 if (gs_hints
->window_style
& (WMResizableWindowMask
|
279 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
280 wwin
->client_flags
.no_titlebar
= 0;
282 wwin
->client_flags
.no_titlebar
=
283 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
288 /* setup the defaults */
289 wwin
->client_flags
.no_border
= 0;
290 wwin
->client_flags
.no_titlebar
= 0;
291 wwin
->client_flags
.no_closable
= 0;
292 wwin
->client_flags
.no_miniaturizable
= 0;
293 wwin
->client_flags
.no_resizable
= 0;
294 wwin
->client_flags
.no_close_button
= 0;
295 wwin
->client_flags
.no_miniaturize_button
= 0;
296 wwin
->client_flags
.no_resizebar
= 0;
298 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
299 wwin
->client_flags
.no_appicon
= 1;
302 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
304 WScreen
*scr
= wwin
->screen_ptr
;
306 /* sets global default stuff */
307 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
309 * Decoration setting is done in this precedence (lower to higher)
310 * - use global default in the resource database
311 * - guess some settings
312 * - use GNUstep/external window attributes
313 * - set hints specified for the app in the resource DB
316 WSETUFLAG(wwin
, broken_close
, 0);
318 if (wwin
->protocols
.DELETE_WINDOW
)
319 WSETUFLAG(wwin
, kill_close
, 0);
321 WSETUFLAG(wwin
, kill_close
, 1);
323 /* transients can't be iconified or maximized */
324 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
325 WSETUFLAG(wwin
, no_miniaturizable
, 1);
326 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
329 /* if the window can't be resized, remove the resizebar */
330 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
331 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
332 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
333 WSETUFLAG(wwin
, no_resizable
, 1);
334 WSETUFLAG(wwin
, no_resizebar
, 1);
337 /* set GNUstep window attributes */
338 if (wwin
->wm_gnustep_attr
) {
339 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
341 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
343 *level
= wwin
->wm_gnustep_attr
->window_level
;
345 * INT_MIN is the only illegal window level.
347 if (*level
== INT_MIN
)
348 *level
= INT_MIN
+ 1;
351 *level
= WMNormalLevel
;
354 int tmp_workspace
= -1;
355 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
361 wMWMCheckClientHints(wwin
);
362 #endif /* MWM_HINTS */
365 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
367 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
368 * have INT_MIN that means that no window level was requested. -Dan
370 if (tmp_level
== INT_MIN
) {
371 if (WFLAGP(wwin
, floating
))
372 *level
= WMFloatingLevel
;
373 else if (WFLAGP(wwin
, sunken
))
374 *level
= WMSunkenLevel
;
376 *level
= WMNormalLevel
;
381 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
382 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
383 if (transientOwner
) {
384 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
385 if (ownerLevel
> *level
)
390 if (tmp_workspace
>= 0)
391 *workspace
= tmp_workspace
% scr
->workspace_count
;
395 * Set attributes specified only for that window/class.
396 * This might do duplicate work with the 1st wDefaultFillAttributes().
398 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
399 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
401 * Sanity checks for attributes that depend on other attributes
403 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
404 wwin
->user_flags
.emulate_appicon
= 0;
406 if (wwin
->main_window
!= None
) {
407 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
408 if (wapp
&& !wapp
->flags
.emulated
)
409 wwin
->user_flags
.emulate_appicon
= 0;
412 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
413 wwin
->user_flags
.emulate_appicon
= 0;
415 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
416 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
417 wwin
->user_flags
.sunken
= 0;
419 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
421 /* windows that have takefocus=False shouldn't take focus at all */
422 if (wwin
->focus_mode
== WFM_NO_INPUT
)
423 wwin
->client_flags
.no_focusable
= 1;
426 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
428 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
430 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
432 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
438 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
442 w1
= wwin
->frame
->core
->width
;
443 h1
= wwin
->frame
->core
->height
;
444 w2
= obscured
->frame
->core
->width
;
445 h2
= obscured
->frame
->core
->height
;
447 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
448 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
451 if (wwin
->frame_x
+ w1
< obscured
->frame_x
452 || wwin
->frame_y
+ h1
< obscured
->frame_y
453 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
459 static void fixLeaderProperties(WWindow
*wwin
)
461 XClassHint
*classHint
;
462 XWMHints
*hints
, *clientHints
;
463 XWindowAttributes attr
;
464 Window leaders
[2], window
;
465 char **argv
, *command
;
469 classHint
= XAllocClassHint();
470 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
471 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
473 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
477 leaders
[0] = wwin
->client_leader
;
478 leaders
[1] = wwin
->group_id
;
481 command
= GetCommandForWindow(wwin
->client_win
);
483 wfree(command
); /* command already set. nothing to do. */
485 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
488 for (i
= 0; i
< 2; i
++) {
491 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
492 classHint
->res_name
= wwin
->wm_instance
;
493 classHint
->res_class
= wwin
->wm_class
;
494 XSetClassHint(dpy
, window
, classHint
);
496 hints
= XGetWMHints(dpy
, window
);
499 } else if (clientHints
) {
500 /* set window group leader to self */
501 clientHints
->window_group
= window
;
502 clientHints
->flags
|= WindowGroupHint
;
503 XSetWMHints(dpy
, window
, clientHints
);
507 command
= GetCommandForWindow(window
);
509 wfree(command
); /* command already set. nothing to do. */
511 XSetCommand(dpy
, window
, argv
, argc
);
514 /* Make sure we get notification when this window is destroyed */
515 if (XGetWindowAttributes(dpy
, window
, &attr
))
516 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
527 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
529 XClassHint
*classHint
;
535 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
537 classHint
= XAllocClassHint();
538 classHint
->res_name
= instance
;
539 classHint
->res_class
= class;
540 XSetClassHint(dpy
, leader
, classHint
);
543 /* inherit these from the original leader if available */
544 hints
= XGetWMHints(dpy
, win
);
546 hints
= XAllocWMHints();
549 /* set window group leader to self */
550 hints
->window_group
= leader
;
551 hints
->flags
|= WindowGroupHint
;
552 XSetWMHints(dpy
, leader
, hints
);
555 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
556 XSetCommand(dpy
, leader
, argv
, argc
);
557 XFreeStringList(argv
);
563 static int matchIdentifier(const void *item
, const void *cdata
)
565 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
569 *----------------------------------------------------------------
571 * reparents the window and allocates a descriptor for it.
572 * Window manager hints and other hints are fetched to configure
573 * the window decoration attributes and others. User preferences
574 * for the window are used if available, to configure window
575 * decorations and some behaviour.
576 * If in startup, windows that are override redirect,
577 * unmapped and never were managed and are Withdrawn are not
581 * the new window descriptor
584 * The window is reparented and appropriate notification
585 * is done to the client. Input mask for the window is setup.
586 * The window descriptor is also associated with various window
587 * contexts and inserted in the head of the window list.
588 * Event handler contexts are associated for some objects
589 * (buttons, titlebar and resizebar)
591 *----------------------------------------------------------------
593 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
597 unsigned width
, height
;
598 XWindowAttributes wattribs
;
599 XSetWindowAttributes attribs
;
600 WWindowState
*win_state
;
601 WWindow
*transientOwner
= NULL
;
607 Bool withdraw
= False
;
613 /* make sure the window is still there */
614 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
619 /* if it's an override-redirect, ignore it */
620 if (wattribs
.override_redirect
) {
625 wm_state
= PropGetWindowState(window
);
627 /* if it's startup and the window is unmapped, don't manage it */
628 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
633 wwin
= wWindowCreate();
635 title
= wNETWMGetWindowName(window
);
637 wwin
->flags
.net_has_title
= 1;
638 if (!title
&& !wFetchName(dpy
, window
, &title
))
641 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
644 if (wShapeSupported
) {
649 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
650 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
651 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
652 wwin
->flags
.shaped
= b_shaped
;
657 * Get hints and other information in properties
659 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
661 /* setup descriptor */
662 wwin
->client_win
= window
;
663 wwin
->screen_ptr
= scr
;
664 wwin
->old_border_width
= wattribs
.border_width
;
665 wwin
->event_mask
= CLIENT_EVENTS
;
666 attribs
.event_mask
= CLIENT_EVENTS
;
667 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
668 attribs
.save_under
= False
;
670 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
671 XSetWindowBorderWidth(dpy
, window
, 0);
673 /* get hints from GNUstep app */
674 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
675 wwin
->flags
.is_gnustep
= 1;
677 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
678 wwin
->wm_gnustep_attr
= NULL
;
680 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
681 wwin
->flags
.is_dockapp
= 1;
685 wwin
->client_leader
= PropGetClientLeader(window
);
686 if (wwin
->client_leader
!= None
)
687 wwin
->main_window
= wwin
->client_leader
;
689 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
691 if (wwin
->wm_hints
) {
692 if (wwin
->wm_hints
->flags
& StateHint
) {
694 if (wwin
->wm_hints
->initial_state
== IconicState
) {
695 wwin
->flags
.miniaturized
= 1;
696 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
697 wwin
->flags
.is_dockapp
= 1;
702 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
703 wwin
->group_id
= wwin
->wm_hints
->window_group
;
704 /* window_group has priority over CLIENT_LEADER */
705 wwin
->main_window
= wwin
->group_id
;
707 wwin
->group_id
= None
;
710 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
711 wwin
->flags
.urgent
= 1;
712 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
715 wwin
->group_id
= None
;
718 PropGetProtocols(window
, &wwin
->protocols
);
720 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
721 wwin
->transient_for
= None
;
723 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
724 wwin
->transient_for
= scr
->root_win
;
726 transientOwner
= wWindowFor(wwin
->transient_for
);
727 if (transientOwner
&& transientOwner
->main_window
!= None
)
728 wwin
->main_window
= transientOwner
->main_window
;
732 /* guess the focus mode */
733 wwin
->focus_mode
= getFocusMode(wwin
);
735 /* get geometry stuff */
736 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
738 /* get colormap windows */
739 GetColormapWindows(wwin
);
742 * Setup the decoration/window attributes and
745 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
747 /* Make broken apps behave as a nice app. */
748 if (WFLAGP(wwin
, emulate_appicon
))
749 wwin
->main_window
= wwin
->client_win
;
751 fixLeaderProperties(wwin
);
753 wwin
->orig_main_window
= wwin
->main_window
;
755 if (wwin
->flags
.is_gnustep
)
756 WSETUFLAG(wwin
, shared_appicon
, 0);
758 if (wwin
->main_window
) {
759 extern Atom _XA_WINDOWMAKER_MENU
;
760 XTextProperty text_prop
;
762 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
))
763 WSETUFLAG(wwin
, shared_appicon
, 0);
766 if (wwin
->flags
.is_dockapp
)
767 WSETUFLAG(wwin
, shared_appicon
, 0);
769 if (wwin
->main_window
) {
770 WApplication
*app
= wApplicationOf(wwin
->main_window
);
771 if (app
&& app
->app_icon
)
772 WSETUFLAG(wwin
, shared_appicon
, 0);
775 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
776 char *buffer
, *instance
, *class;
777 WFakeGroupLeader
*fPtr
;
780 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
782 /* // only enter here if PropGetWMClass() succeds */
783 PropGetWMClass(wwin
->main_window
, &class, &instance
);
784 buffer
= StrConcatDot(instance
, class);
786 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
787 if (index
!= WANotFound
) {
788 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
789 if (fPtr
->retainCount
== 0)
790 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
794 if (fPtr
->origLeader
== None
) {
795 if (ADEQUATE(wwin
->main_window
)) {
797 fPtr
->origLeader
= wwin
->main_window
;
800 wwin
->fake_group
= fPtr
;
801 /*wwin->group_id = fPtr->leader; */
802 wwin
->main_window
= fPtr
->leader
;
805 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
807 fPtr
->identifier
= buffer
;
808 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
809 fPtr
->origLeader
= None
;
810 fPtr
->retainCount
= 1;
812 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
814 if (ADEQUATE(wwin
->main_window
)) {
816 fPtr
->origLeader
= wwin
->main_window
;
818 wwin
->fake_group
= fPtr
;
819 /*wwin->group_id = fPtr->leader; */
820 wwin
->main_window
= fPtr
->leader
;
830 * Setup the initial state of the window
832 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
833 wwin
->flags
.miniaturized
= 1;
835 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
836 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
838 wNETWMCheckInitialClientState(wwin
);
840 /* apply previous state if it exists and we're in startup */
841 if (scr
->flags
.startup
&& wm_state
>= 0) {
842 if (wm_state
== IconicState
) {
843 wwin
->flags
.miniaturized
= 1;
844 } else if (wm_state
== WithdrawnState
) {
849 /* if there is a saved state (from file), restore it */
851 if (wwin
->main_window
!= None
)
852 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
854 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
856 if (win_state
&& !withdraw
) {
857 if (win_state
->state
->hidden
> 0)
858 wwin
->flags
.hidden
= win_state
->state
->hidden
;
860 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
861 wwin
->flags
.shaded
= win_state
->state
->shaded
;
863 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
864 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
866 if (!IS_OMNIPRESENT(wwin
)) {
867 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
869 if (w
< 0 || w
>= scr
->workspace_count
) {
870 workspace
= win_state
->state
->workspace
;
871 if (workspace
>= scr
->workspace_count
)
872 workspace
= scr
->current_workspace
;
877 workspace
= scr
->current_workspace
;
881 /* if we're restarting, restore saved state (from hints).
882 * This will overwrite previous */
886 if (getSavedState(window
, &wstate
)) {
887 wwin
->flags
.shaded
= wstate
->shaded
;
888 wwin
->flags
.hidden
= wstate
->hidden
;
889 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
890 wwin
->flags
.maximized
= wstate
->maximized
;
891 if (wwin
->flags
.maximized
) {
892 wwin
->old_geometry
.x
= wstate
->x
;
893 wwin
->old_geometry
.y
= wstate
->y
;
894 wwin
->old_geometry
.width
= wstate
->w
;
895 wwin
->old_geometry
.height
= wstate
->h
;
898 workspace
= wstate
->workspace
;
903 /* restore window shortcut */
904 if (wstate
!= NULL
|| win_state
!= NULL
) {
907 if (win_state
!= NULL
)
908 mask
= win_state
->state
->window_shortcuts
;
910 if (wstate
!= NULL
&& mask
== 0)
911 mask
= wstate
->window_shortcuts
;
916 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
917 if (mask
& (1 << i
)) {
918 if (!scr
->shortcutWindows
[i
])
919 scr
->shortcutWindows
[i
] = WMCreateArray(4);
921 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
930 /* don't let transients start miniaturized if their owners are not */
931 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
932 wwin
->flags
.miniaturized
= 0;
934 wwin
->wm_hints
->initial_state
= NormalState
;
937 /* set workspace on which the window starts */
938 if (workspace
>= 0) {
939 if (workspace
> scr
->workspace_count
- 1)
940 workspace
= workspace
% scr
->workspace_count
;
944 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
946 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
949 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
950 workspace
= transientOwner
->frame
->workspace
;
952 workspace
= scr
->current_workspace
;
956 /* setup window geometry */
957 if (win_state
&& win_state
->state
->w
> 0) {
958 width
= win_state
->state
->w
;
959 height
= win_state
->state
->h
;
961 wWindowConstrainSize(wwin
, &width
, &height
);
963 /* do not ask for window placement if the window is
964 * transient, during startup, if the initial workspace is another one
965 * or if the window wants to start iconic.
966 * If geometry was saved, restore it. */
968 Bool dontBring
= False
;
970 if (win_state
&& win_state
->state
->w
> 0) {
971 x
= win_state
->state
->x
;
972 y
= win_state
->state
->y
;
973 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
974 && !scr
->flags
.startup
975 && workspace
== scr
->current_workspace
976 && !wwin
->flags
.miniaturized
977 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
979 if (transientOwner
&& transientOwner
->flags
.mapped
) {
980 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
984 x
= transientOwner
->frame_x
+
985 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
986 y
= transientOwner
->frame_y
+
987 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
990 * limit transient windows to be inside their parent's head
992 rect
.pos
.x
= transientOwner
->frame_x
;
993 rect
.pos
.y
= transientOwner
->frame_y
;
994 rect
.size
.width
= transientOwner
->frame
->core
->width
;
995 rect
.size
.height
= transientOwner
->frame
->core
->height
;
997 head
= wGetHeadForRect(scr
, rect
);
998 rect
= wGetRectForHead(scr
, head
);
1002 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1003 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1007 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1008 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1011 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1013 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1016 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1022 * Make spash screens come out in the center of a head
1023 * trouble is that most splashies never get here
1024 * they are managed trough atoms but god knows where.
1025 * Dan, do you know ? -peter
1027 * Most of them are not managed, they have set
1028 * OverrideRedirect, which means we can't do anything about
1033 * xinerama checks for: across head and dead space
1037 rect
.size
.width
= width
;
1038 rect
.size
.height
= height
;
1040 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1042 if (flags
& XFLAG_DEAD
)
1045 if (flags
& XFLAG_MULTIPLE
)
1049 switch (reposition
) {
1051 head
= wGetHeadForPointerLocation(scr
);
1052 rect
= wGetRectForHead(scr
, head
);
1054 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1055 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1059 rect
= wGetRectForHead(scr
, head
);
1063 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1064 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1068 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1069 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1078 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1079 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1082 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1084 if (wwin
->flags
.urgent
) {
1085 if (!IS_OMNIPRESENT(wwin
))
1086 wwin
->flags
.omnipresent
^= 1;
1090 * Create frame, borders and do reparenting
1092 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1093 #ifdef XKB_BUTTON_HINT
1094 if (wPreferences
.modelock
)
1095 foo
|= WFF_LANGUAGE_BUTTON
;
1097 if (HAS_TITLEBAR(wwin
))
1098 foo
|= WFF_TITLEBAR
;
1099 if (HAS_RESIZEBAR(wwin
))
1100 foo
|= WFF_RESIZEBAR
;
1101 if (HAS_BORDER(wwin
))
1104 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1105 x
, y
, width
, height
,
1106 &wPreferences
.window_title_clearance
,
1107 &wPreferences
.window_title_min_height
,
1108 &wPreferences
.window_title_max_height
,
1110 scr
->window_title_texture
,
1111 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1113 wwin
->frame
->flags
.is_client_window_frame
= 1;
1114 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1116 /* setup button images */
1117 wWindowUpdateButtonImages(wwin
);
1119 /* hide unused buttons */
1121 if (WFLAGP(wwin
, no_close_button
))
1122 foo
|= WFF_RIGHT_BUTTON
;
1123 if (WFLAGP(wwin
, no_miniaturize_button
))
1124 foo
|= WFF_LEFT_BUTTON
;
1125 #ifdef XKB_BUTTON_HINT
1126 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1127 foo
|= WFF_LANGUAGE_BUTTON
;
1130 wFrameWindowHideButton(wwin
->frame
, foo
);
1132 wwin
->frame
->child
= wwin
;
1133 wwin
->frame
->workspace
= workspace
;
1134 wwin
->frame
->on_click_left
= windowIconifyClick
;
1136 #ifdef XKB_BUTTON_HINT
1137 if (wPreferences
.modelock
)
1138 wwin
->frame
->on_click_language
= windowLanguageClick
;
1141 wwin
->frame
->on_click_right
= windowCloseClick
;
1142 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1143 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1144 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1145 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1147 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1148 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1149 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1154 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1156 /* if gravity is to the south, account for the border sizes */
1158 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1162 * wWindowConfigure() will init the client window's size
1163 * (wwin->client.{width,height}) and all other geometry
1164 * related variables (frame_x,frame_y)
1166 wWindowConfigure(wwin
, x
, y
, width
, height
);
1168 /* to make sure the window receives it's new position after reparenting */
1169 wWindowSynthConfigureNotify(wwin
);
1172 * Setup descriptors and save window to internal
1175 if (wwin
->main_window
!= None
) {
1179 /* Leader windows do not necessary set themselves as leaders.
1180 * If this is the case, point the leader of this window to
1182 leader
= wWindowFor(wwin
->main_window
);
1183 if (leader
&& leader
->main_window
== None
)
1184 leader
->main_window
= leader
->client_win
;
1186 app
= wApplicationCreate(wwin
);
1188 app
->last_workspace
= workspace
;
1191 * Do application specific stuff, like setting application
1195 if (wwin
->flags
.hidden
) {
1196 /* if the window was set to hidden because it was hidden
1197 * in a previous incarnation and that state was restored */
1198 app
->flags
.hidden
= 1;
1199 } else if (app
->flags
.hidden
) {
1200 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1201 wwin
->flags
.hidden
= 1;
1203 wUnhideApplication(app
, False
, False
);
1211 /* setup the frame descriptor */
1212 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1213 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1214 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1216 /* don't let windows go away if we die */
1217 XAddToSaveSet(dpy
, window
);
1219 XLowerWindow(dpy
, window
);
1221 /* if window is in this workspace and should be mapped, then map it */
1222 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1223 && !wwin
->flags
.hidden
&& !withdraw
) {
1225 /* The following "if" is to avoid crashing of clients that expect
1226 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1227 * after the return from this function.
1229 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1230 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1232 wClientSetState(wwin
, NormalState
, None
);
1234 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1235 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1237 * The brain damaged idiotic non-click to focus modes will
1238 * have trouble with this because:
1240 * 1. window is created and mapped by the client
1241 * 2. window is mapped by wmaker in small size
1242 * 3. window is animated to grow to normal size
1243 * 4. this function returns to normal event loop
1244 * 5. eventually, the EnterNotify event that would trigger
1245 * the window focusing (if the mouse is over that window)
1246 * will be processed by wmaker.
1247 * But since this event will be rather delayed
1248 * (step 3 has a large delay) the time when the event ocurred
1249 * and when it is processed, the client that owns that window
1250 * will reject the XSetInputFocus() for it.
1252 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1253 DoWindowBirth(wwin
);
1258 /* setup stacking descriptor */
1260 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1262 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1264 if (!scr
->focused_window
) {
1265 /* first window on the list */
1268 scr
->focused_window
= wwin
;
1272 /* add window at beginning of focus window list */
1273 tmp
= scr
->focused_window
;
1281 /* raise is set to true if we un-hid the app when this window was born.
1282 * we raise, else old windows of this app will be above this new one. */
1284 wRaiseFrame(wwin
->frame
->core
);
1286 /* Update name must come after WApplication stuff is done */
1287 wWindowUpdateName(wwin
, title
);
1294 * Final preparations before window is ready to go
1296 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1298 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1299 if (((transientOwner
&& transientOwner
->flags
.focused
)
1300 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1302 /* only auto_focus if on same screen as mouse
1303 * (and same head for xinerama mode)
1304 * TODO: make it an option */
1306 /*TODO add checking the head of the window, is it available? */
1307 short same_screen
= 0, same_head
= 1;
1313 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1314 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1317 if (same_screen
== 1 && same_head
== 1)
1318 wSetFocusTo(scr
, wwin
);
1321 wWindowResetMouseGrabs(wwin
);
1323 if (!WFLAGP(wwin
, no_bind_keys
))
1324 wWindowSetKeyGrabs(wwin
);
1326 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1327 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1329 /* Setup Notification Observers */
1330 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1332 /* Cleanup temporary stuff */
1334 wWindowDeleteSavedState(win_state
);
1336 /* If the window must be withdrawed, then do it now.
1337 * Must do some optimization, 'though */
1339 wwin
->flags
.mapped
= 0;
1340 wClientSetState(wwin
, WithdrawnState
, None
);
1341 wUnmanageWindow(wwin
, True
, False
);
1348 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1349 char *title
, int x
, int y
, int width
, int height
)
1354 wwin
= wWindowCreate();
1356 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1358 wwin
->flags
.internal_window
= 1;
1360 WSETUFLAG(wwin
, omnipresent
, 1);
1361 WSETUFLAG(wwin
, no_shadeable
, 1);
1362 WSETUFLAG(wwin
, no_resizable
, 1);
1363 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1365 wwin
->focus_mode
= WFM_PASSIVE
;
1366 wwin
->client_win
= window
;
1367 wwin
->screen_ptr
= scr
;
1368 wwin
->transient_for
= owner
;
1371 wwin
->client
.width
= width
;
1372 wwin
->client
.height
= height
;
1373 wwin
->frame_x
= wwin
->client
.x
;
1374 wwin
->frame_y
= wwin
->client
.y
;
1376 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1377 foo
|= WFF_TITLEBAR
;
1378 #ifdef XKB_BUTTON_HINT
1379 foo
|= WFF_LANGUAGE_BUTTON
;
1382 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1383 wwin
->frame_x
, wwin
->frame_y
,
1385 &wPreferences
.window_title_clearance
,
1386 &wPreferences
.window_title_min_height
,
1387 &wPreferences
.window_title_max_height
,
1389 scr
->window_title_texture
,
1390 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1392 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1394 wwin
->frame
->flags
.is_client_window_frame
= 1;
1395 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1397 wFrameWindowChangeTitle(wwin
->frame
, title
);
1399 /* setup button images */
1400 wWindowUpdateButtonImages(wwin
);
1403 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1405 wwin
->frame
->child
= wwin
;
1406 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1408 #ifdef XKB_BUTTON_HINT
1409 if (wPreferences
.modelock
)
1410 wwin
->frame
->on_click_language
= windowLanguageClick
;
1413 wwin
->frame
->on_click_right
= windowCloseClick
;
1414 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1415 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1416 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1417 wwin
->client
.y
+= wwin
->frame
->top_width
;
1419 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1420 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1422 /* setup the frame descriptor */
1423 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1424 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1425 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1427 XLowerWindow(dpy
, window
);
1428 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1430 /* setup stacking descriptor */
1431 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1433 tmp
= wWindowFor(wwin
->transient_for
);
1435 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1437 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1440 if (!scr
->focused_window
) {
1441 /* first window on the list */
1444 scr
->focused_window
= wwin
;
1448 /* add window at beginning of focus window list */
1449 tmp
= scr
->focused_window
;
1457 if (wwin
->flags
.is_gnustep
== 0)
1458 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1460 /* if (wPreferences.auto_focus) */
1461 wSetFocusTo(scr
, wwin
);
1462 wWindowResetMouseGrabs(wwin
);
1463 wWindowSetKeyGrabs(wwin
);
1469 *----------------------------------------------------------------------
1471 * Removes the frame window from a window and destroys all data
1472 * related to it. The window will be reparented back to the root window
1473 * if restore is True.
1476 * Everything related to the window is destroyed and the window
1477 * is removed from the window lists. Focus is set to the previous on the
1479 *----------------------------------------------------------------------
1481 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1483 WCoreWindow
*frame
= wwin
->frame
->core
;
1484 WWindow
*owner
= NULL
;
1485 WWindow
*newFocusedWindow
= NULL
;
1487 WScreen
*scr
= wwin
->screen_ptr
;
1489 /* First close attribute editor window if open */
1490 if (wwin
->flags
.inspector_open
)
1491 wCloseInspectorForWindow(wwin
);
1493 /* Close window menu if it's open for this window */
1494 if (wwin
->flags
.menu_open_for_me
)
1495 CloseWindowMenu(scr
);
1498 if (!wwin
->flags
.internal_window
)
1499 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1501 /* If this is a leader window, we still need to listen for
1502 * DestroyNotify and PropertyNotify. */
1503 if (wApplicationOf(wwin
->client_win
))
1504 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1506 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1508 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1509 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1512 XUnmapWindow(dpy
, frame
->window
);
1514 XUnmapWindow(dpy
, wwin
->client_win
);
1516 /* deselect window */
1517 wSelectWindow(wwin
, False
);
1519 /* remove all pending events on window */
1520 /* I think this only matters for autoraise */
1521 if (wPreferences
.raise_delay
)
1522 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1526 /* reparent the window back to the root */
1528 wClientRestore(wwin
);
1530 if (wwin
->transient_for
!= scr
->root_win
) {
1531 owner
= wWindowFor(wwin
->transient_for
);
1533 if (!owner
->flags
.semi_focused
)
1536 owner
->flags
.semi_focused
= 0;
1540 wasFocused
= wwin
->flags
.focused
;
1542 /* remove from window focus list */
1543 if (!wwin
->prev
&& !wwin
->next
) {
1544 /* was the only window */
1545 scr
->focused_window
= NULL
;
1546 newFocusedWindow
= NULL
;
1551 wwin
->prev
->next
= wwin
->next
;
1554 wwin
->next
->prev
= wwin
->prev
;
1556 scr
->focused_window
= wwin
->prev
;
1557 scr
->focused_window
->next
= NULL
;
1560 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1562 /* if in click to focus mode and the window
1563 * was a transient, focus the owner window
1566 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1567 tmp
= wWindowFor(wwin
->transient_for
);
1568 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1572 /* otherwise, focus the next one in the focus list */
1574 tmp
= scr
->focused_window
;
1575 while (tmp
) { /* look for one in the window list first */
1576 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1577 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1581 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1582 tmp
= scr
->focused_window
;
1584 if (!WFLAGP(tmp
, no_focusable
)
1585 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1592 newFocusedWindow
= tmp
;
1594 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1599 /* This is to let the root window get the keyboard input
1600 * if Sloppy focus mode and no other window get focus.
1601 * This way keybindings will not freeze.
1604 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1605 tmp
= wWindowFor(win
);
1608 newFocusedWindow
= tmp
;
1610 newFocusedWindow
= NULL
;
1614 if (!wwin
->flags
.internal_window
)
1615 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1617 if (newFocusedWindow
!= owner
&& owner
) {
1618 if (wwin
->flags
.is_gnustep
== 0)
1619 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1621 wSetFocusTo(scr
, newFocusedWindow
);
1624 /* Close menu and unhighlight */
1625 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1626 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1627 if (oapp
&& oapp
!= napp
) {
1628 wAppMenuUnmap(oapp
->menu
);
1629 wApplicationDeactivate(oapp
);
1632 wWindowDestroy(wwin
);
1636 void wWindowMap(WWindow
*wwin
)
1638 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1639 if (!wwin
->flags
.shaded
) {
1640 /* window will be remapped when getting MapNotify */
1641 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1642 XMapWindow(dpy
, wwin
->client_win
);
1643 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1645 wwin
->flags
.mapped
= 1;
1649 void wWindowUnmap(WWindow
*wwin
)
1651 wwin
->flags
.mapped
= 0;
1653 /* prevent window withdrawal when getting UnmapNotify */
1654 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1655 XUnmapWindow(dpy
, wwin
->client_win
);
1656 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1658 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1661 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1666 #ifdef KEEP_XKB_LOCK_STATUS
1667 if (wPreferences
.modelock
)
1668 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1669 #endif /* KEEP_XKB_LOCK_STATUS */
1671 wwin
->flags
.semi_focused
= 0;
1673 if (wwin
->flags
.is_gnustep
== 0)
1674 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1676 wwin
->flags
.focused
= 1;
1678 wWindowResetMouseGrabs(wwin
);
1680 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1682 if (owin
== wwin
|| !owin
)
1685 nowner
= wWindowFor(wwin
->transient_for
);
1687 /* new window is a transient for the old window */
1688 if (nowner
== owin
) {
1689 owin
->flags
.semi_focused
= 1;
1690 wWindowUnfocus(nowner
);
1694 oowner
= wWindowFor(owin
->transient_for
);
1696 /* new window is owner of old window */
1697 if (wwin
== oowner
) {
1698 wWindowUnfocus(owin
);
1703 wWindowUnfocus(owin
);
1707 /* new window has same owner of old window */
1708 if (oowner
== nowner
) {
1709 /* prevent unfocusing of owner */
1710 oowner
->flags
.semi_focused
= 0;
1711 wWindowUnfocus(owin
);
1712 oowner
->flags
.semi_focused
= 1;
1717 /* nowner != NULL && oowner != nowner */
1718 nowner
->flags
.semi_focused
= 1;
1719 wWindowUnfocus(nowner
);
1720 wWindowUnfocus(owin
);
1723 void wWindowUnfocus(WWindow
*wwin
)
1725 CloseWindowMenu(wwin
->screen_ptr
);
1727 if (wwin
->flags
.is_gnustep
== 0)
1728 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1730 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1732 owner
= wWindowFor(wwin
->transient_for
);
1733 if (owner
&& owner
->flags
.semi_focused
) {
1734 owner
->flags
.semi_focused
= 0;
1735 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1736 wWindowUnfocus(owner
);
1737 wFrameWindowPaint(owner
->frame
);
1741 wwin
->flags
.focused
= 0;
1742 wWindowResetMouseGrabs(wwin
);
1743 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1746 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1753 wwin
->flags
.wm_name_changed
= 1;
1756 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1760 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1761 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1765 *----------------------------------------------------------------------
1767 * wWindowConstrainSize--
1768 * Constrains size for the client window, taking the maximal size,
1769 * window resize increments and other size hints into account.
1772 * The closest size to what was given that the client window can
1775 *----------------------------------------------------------------------
1777 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1779 int width
= (int)*nwidth
;
1780 int height
= (int)*nheight
;
1783 int minW
= 1, minH
= 1;
1784 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1785 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1786 int minAX
= -1, minAY
= -1;
1787 int maxAX
= -1, maxAY
= -1;
1791 if (wwin
->normal_hints
) {
1792 winc
= wwin
->normal_hints
->width_inc
;
1793 hinc
= wwin
->normal_hints
->height_inc
;
1794 minW
= wwin
->normal_hints
->min_width
;
1795 minH
= wwin
->normal_hints
->min_height
;
1796 maxW
= wwin
->normal_hints
->max_width
;
1797 maxH
= wwin
->normal_hints
->max_height
;
1798 if (wwin
->normal_hints
->flags
& PAspect
) {
1799 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1800 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1801 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1802 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1805 baseW
= wwin
->normal_hints
->base_width
;
1806 baseH
= wwin
->normal_hints
->base_height
;
1819 /* aspect ratio code borrowed from olwm */
1821 /* adjust max aspect ratio */
1822 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1823 if (maxAX
> maxAY
) {
1824 height
= (width
* maxAY
) / maxAX
;
1825 if (height
> maxH
) {
1827 width
= (height
* maxAX
) / maxAY
;
1830 width
= (height
* maxAX
) / maxAY
;
1833 height
= (width
* maxAY
) / maxAX
;
1838 /* adjust min aspect ratio */
1839 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1840 if (minAX
> minAY
) {
1841 height
= (width
* minAY
) / minAX
;
1842 if (height
< minH
) {
1844 width
= (height
* minAX
) / minAY
;
1847 width
= (height
* minAX
) / minAY
;
1850 height
= (width
* minAY
) / minAX
;
1857 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1859 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1862 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1864 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1866 /* broken stupid apps may cause preposterous values for these.. */
1873 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1874 unsigned int *width
, unsigned int *height
)
1876 int baseW
= 0, baseH
= 0;
1877 int winc
= 1, hinc
= 1;
1879 if (wwin
->normal_hints
) {
1880 baseW
= wwin
->normal_hints
->base_width
;
1881 baseH
= wwin
->normal_hints
->base_height
;
1883 winc
= wwin
->normal_hints
->width_inc
;
1884 hinc
= wwin
->normal_hints
->height_inc
;
1888 *width
= maxW
- (maxW
- baseW
) % winc
;
1891 *height
= maxH
- (maxH
- baseH
) % hinc
;
1894 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1896 WScreen
*scr
= wwin
->screen_ptr
;
1900 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1903 if (workspace
!= scr
->current_workspace
) {
1904 /* Sent to other workspace. Unmap window */
1905 if ((wwin
->flags
.mapped
1906 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1907 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1909 wapp
= wApplicationOf(wwin
->main_window
);
1911 wapp
->last_workspace
= workspace
;
1913 if (wwin
->flags
.miniaturized
) {
1915 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1916 wwin
->icon
->mapped
= 0;
1920 wSetFocusTo(scr
, NULL
);
1924 /* brought to current workspace. Map window */
1925 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1927 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1928 wwin
->icon
->mapped
= 1;
1930 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1934 if (!IS_OMNIPRESENT(wwin
)) {
1935 int oldWorkspace
= wwin
->frame
->workspace
;
1936 wwin
->frame
->workspace
= workspace
;
1937 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1944 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1948 sevent
.type
= ConfigureNotify
;
1949 sevent
.xconfigure
.display
= dpy
;
1950 sevent
.xconfigure
.event
= wwin
->client_win
;
1951 sevent
.xconfigure
.window
= wwin
->client_win
;
1953 sevent
.xconfigure
.x
= wwin
->client
.x
;
1954 sevent
.xconfigure
.y
= wwin
->client
.y
;
1955 sevent
.xconfigure
.width
= wwin
->client
.width
;
1956 sevent
.xconfigure
.height
= wwin
->client
.height
;
1958 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1959 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1960 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1962 sevent
.xconfigure
.above
= None
;
1964 sevent
.xconfigure
.override_redirect
= False
;
1965 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1970 *----------------------------------------------------------------------
1971 * wWindowConfigure()
1973 * req_x, req_y: new requested positions for the frame
1974 * req_width, req_height: new requested sizes for the client
1976 * Configures the frame, decorations and client window to the specified
1977 * geometry, whose validity is not checked -- wWindowConstrainSize()
1978 * must be used for that.
1979 * The size parameters are for the client window, but the position is
1981 * The client window receives a ConfigureNotify event, according
1982 * to what ICCCM says.
1988 * Window size and position are changed and client window receives
1989 * a ConfigureNotify event.
1990 *----------------------------------------------------------------------
1992 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1994 int synth_notify
= False
;
1997 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1999 * if the window is being moved but not resized then
2000 * send a synthetic ConfigureNotify
2002 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
2003 synth_notify
= True
;
2005 if (WFLAGP(wwin
, dont_move_off
))
2006 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2009 if (req_width
< MIN_WINDOW_SIZE
)
2010 req_width
= MIN_WINDOW_SIZE
;
2011 if (req_height
< MIN_WINDOW_SIZE
)
2012 req_height
= MIN_WINDOW_SIZE
;
2014 /* If growing, resize inner part before frame,
2015 * if shrinking, resize frame before.
2016 * This will prevent the frame (that can have a different color)
2017 * to be exposed, causing flicker */
2018 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2019 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2021 if (wwin
->flags
.shaded
) {
2022 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2023 wwin
->old_geometry
.height
= req_height
;
2027 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2029 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2032 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2033 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2035 wwin
->client
.x
= req_x
;
2036 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2037 wwin
->client
.width
= req_width
;
2038 wwin
->client
.height
= req_height
;
2040 wwin
->client
.x
= req_x
;
2041 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2043 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2045 wwin
->frame_x
= req_x
;
2046 wwin
->frame_y
= req_y
;
2047 if (HAS_BORDER(wwin
)) {
2048 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2049 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2052 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2053 wWindowSetShape(wwin
);
2057 wWindowSynthConfigureNotify(wwin
);
2061 /* req_x, req_y: new position of the frame */
2062 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2064 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2065 int synth_notify
= False
;
2067 /* Send a synthetic ConfigureNotify event for every window movement. */
2068 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2069 synth_notify
= True
;
2071 /* A single synthetic ConfigureNotify event is sent at the end of
2072 * a completed (opaque) movement in moveres.c */
2075 if (WFLAGP(wwin
, dont_move_off
))
2076 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2077 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2079 wwin
->client
.x
= req_x
;
2080 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2081 if (HAS_BORDER(wwin
)) {
2082 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2083 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2086 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2088 wwin
->frame_x
= req_x
;
2089 wwin
->frame_y
= req_y
;
2091 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2093 wWindowSynthConfigureNotify(wwin
);
2097 void wWindowUpdateButtonImages(WWindow
*wwin
)
2099 WScreen
*scr
= wwin
->screen_ptr
;
2100 Pixmap pixmap
, mask
;
2101 WFrameWindow
*fwin
= wwin
->frame
;
2103 if (!HAS_TITLEBAR(wwin
))
2106 /* miniaturize button */
2107 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2108 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2109 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2111 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2112 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2116 if (fwin
->lbutton_image
2117 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2118 wPixmapDestroy(fwin
->lbutton_image
);
2119 fwin
->lbutton_image
= NULL
;
2122 if (!fwin
->lbutton_image
) {
2123 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2124 fwin
->lbutton_image
->client_owned
= 1;
2125 fwin
->lbutton_image
->client_owned_mask
= 1;
2128 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2129 wPixmapDestroy(fwin
->lbutton_image
);
2131 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2134 #ifdef XKB_BUTTON_HINT
2135 if (!WFLAGP(wwin
, no_language_button
)) {
2136 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2137 wPixmapDestroy(fwin
->languagebutton_image
);
2139 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2145 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2146 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2148 if (!WFLAGP(wwin
, no_close_button
)) {
2149 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2150 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2152 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2153 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2157 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2158 || fwin
->rbutton_image
->mask
!= mask
)) {
2159 wPixmapDestroy(fwin
->rbutton_image
);
2160 fwin
->rbutton_image
= NULL
;
2163 if (!fwin
->rbutton_image
) {
2164 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2165 fwin
->rbutton_image
->client_owned
= 1;
2166 fwin
->rbutton_image
->client_owned_mask
= 1;
2169 } else if (WFLAGP(wwin
, kill_close
)) {
2170 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2171 wPixmapDestroy(fwin
->rbutton_image
);
2173 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2175 } else if (MGFLAGP(wwin
, broken_close
)) {
2176 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2177 wPixmapDestroy(fwin
->rbutton_image
);
2179 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2182 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2183 wPixmapDestroy(fwin
->rbutton_image
);
2185 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2189 /* force buttons to be redrawn */
2190 fwin
->flags
.need_texture_change
= 1;
2191 wFrameWindowPaint(fwin
);
2195 *---------------------------------------------------------------------------
2196 * wWindowConfigureBorders--
2197 * Update window border configuration according to attribute flags.
2199 *---------------------------------------------------------------------------
2201 void wWindowConfigureBorders(WWindow
*wwin
)
2207 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2209 #ifdef XKB_BUTTON_HINT
2210 if (wPreferences
.modelock
)
2211 flags
|= WFF_LANGUAGE_BUTTON
;
2214 if (HAS_TITLEBAR(wwin
))
2215 flags
|= WFF_TITLEBAR
;
2216 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2217 flags
|= WFF_RESIZEBAR
;
2218 if (HAS_BORDER(wwin
))
2219 flags
|= WFF_BORDER
;
2220 if (wwin
->flags
.shaded
)
2221 flags
|= WFF_IS_SHADED
;
2223 oldh
= wwin
->frame
->top_width
;
2224 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2225 if (oldh
!= wwin
->frame
->top_width
) {
2226 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2228 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2229 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2233 if (!WFLAGP(wwin
, no_miniaturize_button
)
2234 && wwin
->frame
->flags
.hide_left_button
)
2235 flags
|= WFF_LEFT_BUTTON
;
2237 #ifdef XKB_BUTTON_HINT
2238 if (!WFLAGP(wwin
, no_language_button
)
2239 && wwin
->frame
->flags
.hide_language_button
)
2240 flags
|= WFF_LANGUAGE_BUTTON
;
2243 if (!WFLAGP(wwin
, no_close_button
)
2244 && wwin
->frame
->flags
.hide_right_button
)
2245 flags
|= WFF_RIGHT_BUTTON
;
2248 wWindowUpdateButtonImages(wwin
);
2249 wFrameWindowShowButton(wwin
->frame
, flags
);
2253 if (WFLAGP(wwin
, no_miniaturize_button
)
2254 && !wwin
->frame
->flags
.hide_left_button
)
2255 flags
|= WFF_LEFT_BUTTON
;
2257 #ifdef XKB_BUTTON_HINT
2258 if (WFLAGP(wwin
, no_language_button
)
2259 && !wwin
->frame
->flags
.hide_language_button
)
2260 flags
|= WFF_LANGUAGE_BUTTON
;
2263 if (WFLAGP(wwin
, no_close_button
)
2264 && !wwin
->frame
->flags
.hide_right_button
)
2265 flags
|= WFF_RIGHT_BUTTON
;
2268 wFrameWindowHideButton(wwin
->frame
, flags
);
2271 if (wShapeSupported
&& wwin
->flags
.shaped
)
2272 wWindowSetShape(wwin
);
2277 void wWindowSaveState(WWindow
* wwin
)
2282 memset(data
, 0, sizeof(long) * 10);
2283 data
[0] = wwin
->frame
->workspace
;
2284 data
[1] = wwin
->flags
.miniaturized
;
2285 data
[2] = wwin
->flags
.shaded
;
2286 data
[3] = wwin
->flags
.hidden
;
2287 data
[4] = wwin
->flags
.maximized
;
2288 if (wwin
->flags
.maximized
== 0) {
2289 data
[5] = wwin
->frame_x
;
2290 data
[6] = wwin
->frame_y
;
2291 data
[7] = wwin
->frame
->core
->width
;
2292 data
[8] = wwin
->frame
->core
->height
;
2294 data
[5] = wwin
->old_geometry
.x
;
2295 data
[6] = wwin
->old_geometry
.y
;
2296 data
[7] = wwin
->old_geometry
.width
;
2297 data
[8] = wwin
->old_geometry
.height
;
2300 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2301 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2302 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2305 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2306 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2309 static int getSavedState(Window window
, WSavedState
** state
)
2313 unsigned long nitems_ret
;
2314 unsigned long bytes_after_ret
;
2317 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2318 True
, _XA_WINDOWMAKER_STATE
,
2319 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2320 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2323 *state
= wmalloc(sizeof(WSavedState
));
2325 (*state
)->workspace
= data
[0];
2326 (*state
)->miniaturized
= data
[1];
2327 (*state
)->shaded
= data
[2];
2328 (*state
)->hidden
= data
[3];
2329 (*state
)->maximized
= data
[4];
2330 (*state
)->x
= data
[5];
2331 (*state
)->y
= data
[6];
2332 (*state
)->w
= data
[7];
2333 (*state
)->h
= data
[8];
2334 (*state
)->window_shortcuts
= data
[9];
2338 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2345 void wWindowClearShape(WWindow
* wwin
)
2347 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2348 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2352 void wWindowSetShape(WWindow
* wwin
)
2356 #ifdef OPTIMIZE_SHAPE
2361 /* only shape is the client's */
2362 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2365 /* Get array of rectangles describing the shape mask */
2366 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2370 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2376 /* insert our decoration rectangles in the rect list */
2377 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2380 if (HAS_TITLEBAR(wwin
)) {
2382 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2383 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2384 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2387 if (HAS_RESIZEBAR(wwin
)) {
2389 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2390 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2391 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2395 /* shape our frame window */
2396 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2397 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2403 #endif /* OPTIMIZE_SHAPE */
2405 if (HAS_TITLEBAR(wwin
)) {
2408 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2409 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2412 if (HAS_RESIZEBAR(wwin
)) {
2414 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2415 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2416 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2420 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2421 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2423 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2424 0, wwin
->frame
->top_width
, wwin
->client_win
,
2425 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2430 /* ====================================================================== */
2432 static FocusMode
getFocusMode(WWindow
* wwin
)
2436 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2437 if (wwin
->wm_hints
->input
== True
) {
2438 if (wwin
->protocols
.TAKE_FOCUS
)
2439 mode
= WFM_LOCALLY_ACTIVE
;
2443 if (wwin
->protocols
.TAKE_FOCUS
)
2444 mode
= WFM_GLOBALLY_ACTIVE
;
2446 mode
= WFM_NO_INPUT
;
2454 void wWindowSetKeyGrabs(WWindow
* wwin
)
2459 for (i
= 0; i
< WKBD_LAST
; i
++) {
2460 key
= &wKeyBindings
[i
];
2462 if (key
->keycode
== 0)
2464 if (key
->modifier
!= AnyModifier
) {
2465 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2466 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2468 /* Also grab all modifier combinations possible that include,
2469 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2470 * work even if the NumLock/ScrollLock key is on.
2472 wHackedGrabKey(key
->keycode
, key
->modifier
,
2473 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2476 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2477 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2480 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2483 void wWindowResetMouseGrabs(WWindow
* wwin
)
2485 /* Mouse grabs can't be done on the client window because of
2486 * ICCCM and because clients that try to do the same will crash.
2488 * But there is a problem wich makes tbar buttons of unfocused
2489 * windows not usable as the click goes to the frame window instead
2490 * of the button itself. Must figure a way to fix that.
2493 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2495 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2496 /* grabs for Meta+drag */
2497 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2498 True
, ButtonPressMask
| ButtonReleaseMask
,
2499 GrabModeSync
, GrabModeAsync
, None
, None
);
2501 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2502 * but we only grab it for Button4 and Button 5 since a lot of apps
2503 * use CTRL+Button1-3 for app related functionality
2505 if (wPreferences
.resize_increment
> 0) {
2506 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2507 True
, ButtonPressMask
| ButtonReleaseMask
,
2508 GrabModeSync
, GrabModeAsync
, None
, None
);
2509 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2510 True
, ButtonPressMask
| ButtonReleaseMask
,
2511 GrabModeSync
, GrabModeAsync
, None
, None
);
2513 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2514 True
, ButtonPressMask
| ButtonReleaseMask
,
2515 GrabModeSync
, GrabModeAsync
, None
, None
);
2516 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2517 True
, ButtonPressMask
| ButtonReleaseMask
,
2518 GrabModeSync
, GrabModeAsync
, None
, None
);
2522 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2523 && !wwin
->flags
.is_gnustep
) {
2524 /* the passive grabs to focus the window */
2525 /* if (wPreferences.focus_mode == WKF_CLICK) */
2526 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2527 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2532 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2534 if (attr
->flags
& GSExtraFlagsAttr
) {
2535 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2536 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2537 wWindowUpdateButtonImages(wwin
);
2542 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2544 WWindowState
*wstate
;
2546 wstate
= malloc(sizeof(WWindowState
));
2550 memset(wstate
, 0, sizeof(WWindowState
));
2553 wstate
->instance
= wstrdup(instance
);
2555 wstate
->class = wstrdup(class);
2557 wstate
->command
= wstrdup(command
);
2558 wstate
->state
= state
;
2560 wstate
->next
= windowState
;
2561 windowState
= wstate
;
2566 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2568 WMagicNumber
wWindowGetSavedState(Window win
)
2570 char *instance
, *class, *command
= NULL
;
2571 WWindowState
*wstate
= windowState
;
2576 command
= GetCommandForWindow(win
);
2580 if (PropGetWMClass(win
, &class, &instance
)) {
2582 if (SAME(instance
, wstate
->instance
) &&
2583 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2586 wstate
= wstate
->next
;
2602 void wWindowDeleteSavedState(WMagicNumber id
)
2604 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2606 if (!wstate
|| !windowState
)
2610 if (tmp
== wstate
) {
2611 windowState
= wstate
->next
;
2612 if (wstate
->instance
)
2613 wfree(wstate
->instance
);
2615 wfree(wstate
->class);
2616 if (wstate
->command
)
2617 wfree(wstate
->command
);
2618 wfree(wstate
->state
);
2622 if (tmp
->next
== wstate
) {
2623 tmp
->next
= wstate
->next
;
2624 if (wstate
->instance
)
2625 wfree(wstate
->instance
);
2627 wfree(wstate
->class);
2628 if (wstate
->command
)
2629 wfree(wstate
->command
);
2630 wfree(wstate
->state
);
2639 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2641 WWindowState
*tmp
, *wstate
;
2647 if (tmp
->pid
== pid
) {
2648 wstate
= windowState
;
2649 windowState
= tmp
->next
;
2650 if (wstate
->instance
)
2651 wfree(wstate
->instance
);
2653 wfree(wstate
->class);
2654 if (wstate
->command
)
2655 wfree(wstate
->command
);
2656 wfree(wstate
->state
);
2660 if (tmp
->next
->pid
== pid
) {
2662 tmp
->next
= wstate
->next
;
2663 if (wstate
->instance
)
2664 wfree(wstate
->instance
);
2666 wfree(wstate
->class);
2667 if (wstate
->command
)
2668 wfree(wstate
->command
);
2669 wfree(wstate
->state
);
2678 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2680 if (wwin
->flags
.omnipresent
== flag
)
2683 wwin
->flags
.omnipresent
= flag
;
2684 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2687 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2689 WWindow
*wwin
= data
;
2691 #ifndef NUMLOCK_HACK
2692 if ((event
->xbutton
.state
& ValidModMask
)
2693 != (event
->xbutton
.state
& ~LockMask
)) {
2694 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2695 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2699 event
->xbutton
.state
&= ValidModMask
;
2701 CloseWindowMenu(wwin
->screen_ptr
);
2703 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2704 && !WFLAGP(wwin
, no_focusable
)) {
2705 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2708 if (event
->xbutton
.button
== Button1
)
2709 wRaiseFrame(wwin
->frame
->core
);
2711 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2712 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2713 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2714 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2719 if (event
->xbutton
.state
& MOD_MASK
) {
2720 /* move the window */
2721 wMouseMoveWindow(wwin
, event
);
2722 XUngrabPointer(dpy
, CurrentTime
);
2724 wMouseResizeWindow(wwin
, event
);
2725 XUngrabPointer(dpy
, CurrentTime
);
2729 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2731 WWindow
*wwin
= data
;
2733 event
->xbutton
.state
&= ValidModMask
;
2735 if (event
->xbutton
.button
== Button1
) {
2736 if (event
->xbutton
.state
== 0) {
2737 if (!WFLAGP(wwin
, no_shadeable
)) {
2739 if (wwin
->flags
.shaded
)
2740 wUnshadeWindow(wwin
);
2747 if (event
->xbutton
.state
& ControlMask
)
2748 dir
|= MAX_VERTICAL
;
2750 if (event
->xbutton
.state
& ShiftMask
) {
2751 dir
|= MAX_HORIZONTAL
;
2752 if (!(event
->xbutton
.state
& ControlMask
))
2753 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2756 /* maximize window */
2757 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2758 int ndir
= dir
^ wwin
->flags
.maximized
;
2761 wMaximizeWindow(wwin
, ndir
);
2763 wUnmaximizeWindow(wwin
);
2766 } else if (event
->xbutton
.button
== Button3
) {
2767 if (event
->xbutton
.state
& MOD_MASK
)
2768 wHideOtherApplications(wwin
);
2769 } else if (event
->xbutton
.button
== Button2
) {
2770 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2771 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2773 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2774 wUnshadeWindow(wwin
);
2778 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2780 WWindow
*wwin
= desc
->parent
;
2781 unsigned int new_width
, w_scale
;
2782 unsigned int new_height
, h_scale
;
2783 unsigned int resize_width_increment
= 0;
2784 unsigned int resize_height_increment
= 0;
2786 if (wwin
->normal_hints
) {
2787 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2788 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2789 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2790 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2792 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2793 resize_width_increment
= wPreferences
.resize_increment
;
2794 resize_height_increment
= wPreferences
.resize_increment
;
2797 event
->xbutton
.state
&= ValidModMask
;
2799 CloseWindowMenu(wwin
->screen_ptr
);
2801 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2802 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2804 if (event
->xbutton
.button
== Button1
)
2805 wRaiseFrame(wwin
->frame
->core
);
2807 if (event
->xbutton
.state
& ControlMask
) {
2808 if (event
->xbutton
.button
== Button4
) {
2809 new_width
= wwin
->client
.width
- resize_width_increment
;
2810 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2811 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2813 if (event
->xbutton
.button
== Button5
) {
2814 new_width
= wwin
->client
.width
+ resize_width_increment
;
2815 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2816 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2820 if (event
->xbutton
.state
& MOD_MASK
) {
2821 /* move the window */
2822 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2823 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2824 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2827 if (event
->xbutton
.button
== Button3
) {
2828 wMouseResizeWindow(wwin
, event
);
2829 } else if (event
->xbutton
.button
== Button4
) {
2830 new_height
= wwin
->client
.height
- resize_height_increment
;
2831 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2832 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2833 } else if (event
->xbutton
.button
== Button5
) {
2834 new_height
= wwin
->client
.height
+ resize_height_increment
;
2835 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2836 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2837 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2838 wMouseMoveWindow(wwin
, event
);
2840 XUngrabPointer(dpy
, CurrentTime
);
2844 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2846 WWindow
*wwin
= (WWindow
*) data
;
2848 #ifndef NUMLOCK_HACK
2849 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2850 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2851 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2853 event
->xbutton
.state
&= ValidModMask
;
2855 CloseWindowMenu(wwin
->screen_ptr
);
2857 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2858 && !WFLAGP(wwin
, no_focusable
))
2859 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2861 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2863 if (event
->xbutton
.button
== Button1
) {
2864 if (event
->xbutton
.state
& MOD_MASK
)
2865 wLowerFrame(wwin
->frame
->core
);
2867 wRaiseFrame(wwin
->frame
->core
);
2869 if ((event
->xbutton
.state
& ShiftMask
)
2870 && !(event
->xbutton
.state
& ControlMask
)) {
2871 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2874 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2875 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2876 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2877 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2881 /* move the window */
2882 wMouseMoveWindow(wwin
, event
);
2884 XUngrabPointer(dpy
, CurrentTime
);
2885 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2886 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2887 WObjDescriptor
*desc
;
2889 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2890 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2891 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2892 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2896 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2898 /* allow drag select */
2899 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2900 event
->xany
.send_event
= True
;
2901 (*desc
->handle_mousedown
) (desc
, event
);
2903 XUngrabPointer(dpy
, CurrentTime
);
2907 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2909 WWindow
*wwin
= data
;
2911 event
->xbutton
.state
&= ValidModMask
;
2913 CloseWindowMenu(wwin
->screen_ptr
);
2915 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2918 /* if control-click, kill the client */
2919 if (event
->xbutton
.state
& ControlMask
) {
2922 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2923 /* send delete message */
2924 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2929 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2931 WWindow
*wwin
= data
;
2933 CloseWindowMenu(wwin
->screen_ptr
);
2935 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2938 /* send delete message */
2939 if (wwin
->protocols
.DELETE_WINDOW
)
2940 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2945 #ifdef XKB_BUTTON_HINT
2946 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2948 WWindow
*wwin
= data
;
2949 WFrameWindow
*fwin
= wwin
->frame
;
2950 WScreen
*scr
= fwin
->screen_ptr
;
2953 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2955 tl
= wwin
->frame
->languagemode
;
2956 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2957 wwin
->frame
->last_languagemode
= tl
;
2958 wSetFocusTo(scr
, wwin
);
2959 wwin
->frame
->languagebutton_image
=
2960 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2961 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2962 if (event
->xbutton
.button
== Button3
)
2964 wRaiseFrame(fwin
->core
);
2968 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2970 WWindow
*wwin
= data
;
2972 event
->xbutton
.state
&= ValidModMask
;
2974 CloseWindowMenu(wwin
->screen_ptr
);
2976 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2979 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2980 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
2983 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2985 wapp
= wApplicationOf(wwin
->main_window
);
2986 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2987 wHideApplication(wapp
);
2988 } else if (event
->xbutton
.state
== 0) {
2989 wIconifyWindow(wwin
);