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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
39 /* For getting mouse wheel mappings from WINGs */
40 #include <WINGs/WINGsP.h>
42 #include "WindowMaker.h"
48 #include "winspector.h"
50 #include "properties.h"
57 #include "workspace.h"
65 #define MOD_MASK wPreferences.modifier_mask
67 /****** Global Variables ******/
68 extern WShortKey wKeyBindings
[WKBD_LAST
];
71 extern Bool wShapeSupported
;
75 extern XContext wWinContext
;
78 extern Atom _XA_WM_DELETE_WINDOW
;
79 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
80 extern Atom _XA_WINDOWMAKER_STATE
;
81 extern WPreferences wPreferences
;
82 extern Time LastTimestamp
;
85 extern void DoWindowBirth(WWindow
*wwin
);
87 /***** Local Stuff *****/
88 static WWindowState
*windowState
= NULL
;
89 static FocusMode
getFocusMode(WWindow
*wwin
);
90 static int getSavedState(Window window
, WSavedState
**state
);
91 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
93 /* frame window (during window grabs) */
94 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
97 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
98 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
101 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
103 #ifdef XKB_BUTTON_HINT
104 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
107 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
109 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
111 /****** Notification Observers ******/
113 static void appearanceObserver(void *self
, WMNotification
* notif
)
115 WWindow
*wwin
= (WWindow
*) self
;
116 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
118 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
121 if (flags
& WFontSettings
) {
122 wWindowConfigureBorders(wwin
);
123 if (wwin
->flags
.shaded
) {
124 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 Window leaders
[2], window
;
464 char **argv
, *command
;
468 classHint
= XAllocClassHint();
469 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
470 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
472 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
476 leaders
[0] = wwin
->client_leader
;
477 leaders
[1] = wwin
->group_id
;
480 command
= GetCommandForWindow(wwin
->client_win
);
482 /* command already set. nothing to do. */
485 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
489 for (i
= 0; i
< 2; i
++) {
492 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
493 classHint
->res_name
= wwin
->wm_instance
;
494 classHint
->res_class
= wwin
->wm_class
;
495 XSetClassHint(dpy
, window
, classHint
);
497 hints
= XGetWMHints(dpy
, window
);
500 } else if (clientHints
) {
501 /* set window group leader to self */
502 clientHints
->window_group
= window
;
503 clientHints
->flags
|= WindowGroupHint
;
504 XSetWMHints(dpy
, window
, clientHints
);
508 command
= GetCommandForWindow(window
);
510 /* command already set. nothing to do. */
513 XSetCommand(dpy
, window
, argv
, argc
);
526 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
528 XClassHint
*classHint
;
534 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
536 classHint
= XAllocClassHint();
537 classHint
->res_name
= instance
;
538 classHint
->res_class
= class;
539 XSetClassHint(dpy
, leader
, classHint
);
542 /* inherit these from the original leader if available */
543 hints
= XGetWMHints(dpy
, win
);
545 hints
= XAllocWMHints();
548 /* set window group leader to self */
549 hints
->window_group
= leader
;
550 hints
->flags
|= WindowGroupHint
;
551 XSetWMHints(dpy
, leader
, hints
);
554 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
555 XSetCommand(dpy
, leader
, argv
, argc
);
556 XFreeStringList(argv
);
562 static int matchIdentifier(const void *item
, const void *cdata
)
564 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
568 *----------------------------------------------------------------
570 * reparents the window and allocates a descriptor for it.
571 * Window manager hints and other hints are fetched to configure
572 * the window decoration attributes and others. User preferences
573 * for the window are used if available, to configure window
574 * decorations and some behaviour.
575 * If in startup, windows that are override redirect,
576 * unmapped and never were managed and are Withdrawn are not
580 * the new window descriptor
583 * The window is reparented and appropriate notification
584 * is done to the client. Input mask for the window is setup.
585 * The window descriptor is also associated with various window
586 * contexts and inserted in the head of the window list.
587 * Event handler contexts are associated for some objects
588 * (buttons, titlebar and resizebar)
590 *----------------------------------------------------------------
592 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
596 unsigned width
, height
;
597 XWindowAttributes wattribs
;
598 XSetWindowAttributes attribs
;
599 WWindowState
*win_state
;
600 WWindow
*transientOwner
= NULL
;
606 Bool withdraw
= False
;
612 /* make sure the window is still there */
613 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
618 /* if it's an override-redirect, ignore it */
619 if (wattribs
.override_redirect
) {
624 wm_state
= PropGetWindowState(window
);
626 /* if it's startup and the window is unmapped, don't manage it */
627 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
632 wwin
= wWindowCreate();
634 title
= wNETWMGetWindowName(window
);
636 wwin
->flags
.net_has_title
= 1;
637 if (!title
&& !wFetchName(dpy
, window
, &title
))
640 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
643 if (wShapeSupported
) {
648 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
649 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
650 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
651 wwin
->flags
.shaped
= b_shaped
;
656 * Get hints and other information in properties
658 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
660 /* setup descriptor */
661 wwin
->client_win
= window
;
662 wwin
->screen_ptr
= scr
;
663 wwin
->old_border_width
= wattribs
.border_width
;
664 wwin
->event_mask
= CLIENT_EVENTS
;
665 attribs
.event_mask
= CLIENT_EVENTS
;
666 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
667 attribs
.save_under
= False
;
669 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
670 XSetWindowBorderWidth(dpy
, window
, 0);
672 /* get hints from GNUstep app */
673 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0) {
674 wwin
->flags
.is_gnustep
= 1;
676 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
677 wwin
->wm_gnustep_attr
= NULL
;
680 wwin
->client_leader
= PropGetClientLeader(window
);
681 if (wwin
->client_leader
!= None
)
682 wwin
->main_window
= wwin
->client_leader
;
684 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
686 if (wwin
->wm_hints
) {
687 if (wwin
->wm_hints
->flags
& StateHint
) {
689 if (wwin
->wm_hints
->initial_state
== IconicState
) {
691 wwin
->flags
.miniaturized
= 1;
693 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
699 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
700 wwin
->group_id
= wwin
->wm_hints
->window_group
;
701 /* window_group has priority over CLIENT_LEADER */
702 wwin
->main_window
= wwin
->group_id
;
704 wwin
->group_id
= None
;
707 if (wwin
->wm_hints
->flags
& UrgencyHint
)
708 wwin
->flags
.urgent
= 1;
710 wwin
->group_id
= None
;
713 PropGetProtocols(window
, &wwin
->protocols
);
715 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
716 wwin
->transient_for
= None
;
718 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
719 wwin
->transient_for
= scr
->root_win
;
721 transientOwner
= wWindowFor(wwin
->transient_for
);
722 if (transientOwner
&& transientOwner
->main_window
!= None
)
723 wwin
->main_window
= transientOwner
->main_window
;
727 /* guess the focus mode */
728 wwin
->focus_mode
= getFocusMode(wwin
);
730 /* get geometry stuff */
731 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
733 /* get colormap windows */
734 GetColormapWindows(wwin
);
737 * Setup the decoration/window attributes and
740 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
742 /* Make broken apps behave as a nice app. */
743 if (WFLAGP(wwin
, emulate_appicon
))
744 wwin
->main_window
= wwin
->client_win
;
746 fixLeaderProperties(wwin
);
748 wwin
->orig_main_window
= wwin
->main_window
;
750 if (wwin
->flags
.is_gnustep
)
751 WSETUFLAG(wwin
, shared_appicon
, 0);
753 if (wwin
->main_window
) {
754 extern Atom _XA_WINDOWMAKER_MENU
;
755 XTextProperty text_prop
;
757 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
758 WSETUFLAG(wwin
, shared_appicon
, 0);
762 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
763 char *buffer
, *instance
, *class;
764 WFakeGroupLeader
*fPtr
;
767 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
769 /* // only enter here if PropGetWMClass() succeds */
770 PropGetWMClass(wwin
->main_window
, &class, &instance
);
771 buffer
= StrConcatDot(instance
, class);
773 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
774 if (index
!= WANotFound
) {
775 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
776 if (fPtr
->retainCount
== 0) {
777 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
781 if (fPtr
->origLeader
== None
) {
782 if (ADEQUATE(wwin
->main_window
)) {
784 fPtr
->origLeader
= wwin
->main_window
;
787 wwin
->fake_group
= fPtr
;
788 /*wwin->group_id = fPtr->leader; */
789 wwin
->main_window
= fPtr
->leader
;
792 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
794 fPtr
->identifier
= buffer
;
795 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
796 fPtr
->origLeader
= None
;
797 fPtr
->retainCount
= 1;
799 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
801 if (ADEQUATE(wwin
->main_window
)) {
803 fPtr
->origLeader
= wwin
->main_window
;
805 wwin
->fake_group
= fPtr
;
806 /*wwin->group_id = fPtr->leader; */
807 wwin
->main_window
= fPtr
->leader
;
817 * Setup the initial state of the window
819 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
820 wwin
->flags
.miniaturized
= 1;
822 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
823 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
825 wNETWMCheckInitialClientState(wwin
);
827 /* apply previous state if it exists and we're in startup */
828 if (scr
->flags
.startup
&& wm_state
>= 0) {
830 if (wm_state
== IconicState
) {
832 wwin
->flags
.miniaturized
= 1;
834 } else if (wm_state
== WithdrawnState
) {
840 /* if there is a saved state (from file), restore it */
842 if (wwin
->main_window
!= None
)
843 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
845 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
847 if (win_state
&& !withdraw
) {
848 if (win_state
->state
->hidden
> 0)
849 wwin
->flags
.hidden
= win_state
->state
->hidden
;
851 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
852 wwin
->flags
.shaded
= win_state
->state
->shaded
;
854 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
855 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
858 if (!IS_OMNIPRESENT(wwin
)) {
859 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
861 if (w
< 0 || w
>= scr
->workspace_count
) {
862 workspace
= win_state
->state
->workspace
;
863 if (workspace
>= scr
->workspace_count
)
864 workspace
= scr
->current_workspace
;
869 workspace
= scr
->current_workspace
;
873 /* if we're restarting, restore saved state (from hints).
874 * This will overwrite previous */
878 if (getSavedState(window
, &wstate
)) {
879 wwin
->flags
.shaded
= wstate
->shaded
;
880 wwin
->flags
.hidden
= wstate
->hidden
;
881 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
882 wwin
->flags
.maximized
= wstate
->maximized
;
883 if (wwin
->flags
.maximized
) {
884 wwin
->old_geometry
.x
= wstate
->x
;
885 wwin
->old_geometry
.y
= wstate
->y
;
886 wwin
->old_geometry
.width
= wstate
->w
;
887 wwin
->old_geometry
.height
= wstate
->h
;
890 workspace
= wstate
->workspace
;
895 /* restore window shortcut */
896 if (wstate
!= NULL
|| win_state
!= NULL
) {
899 if (win_state
!= NULL
)
900 mask
= win_state
->state
->window_shortcuts
;
902 if (wstate
!= NULL
&& mask
== 0)
903 mask
= wstate
->window_shortcuts
;
908 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
909 if (mask
& (1 << i
)) {
910 if (!scr
->shortcutWindows
[i
])
911 scr
->shortcutWindows
[i
] = WMCreateArray(4);
913 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
922 /* don't let transients start miniaturized if their owners are not */
923 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
924 wwin
->flags
.miniaturized
= 0;
926 wwin
->wm_hints
->initial_state
= NormalState
;
929 /* set workspace on which the window starts */
930 if (workspace
>= 0) {
931 if (workspace
> scr
->workspace_count
- 1) {
932 workspace
= workspace
% scr
->workspace_count
;
937 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
939 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
944 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
946 workspace
= transientOwner
->frame
->workspace
;
950 workspace
= scr
->current_workspace
;
955 /* setup window geometry */
956 if (win_state
&& win_state
->state
->w
> 0) {
957 width
= win_state
->state
->w
;
958 height
= win_state
->state
->h
;
960 wWindowConstrainSize(wwin
, &width
, &height
);
962 /* do not ask for window placement if the window is
963 * transient, during startup, if the initial workspace is another one
964 * or if the window wants to start iconic.
965 * If geometry was saved, restore it. */
967 Bool dontBring
= False
;
969 if (win_state
&& win_state
->state
->w
> 0) {
970 x
= win_state
->state
->x
;
971 y
= win_state
->state
->y
;
972 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
973 && !scr
->flags
.startup
974 && workspace
== scr
->current_workspace
975 && !wwin
->flags
.miniaturized
976 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
978 if (transientOwner
&& transientOwner
->flags
.mapped
) {
979 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
983 x
= transientOwner
->frame_x
+
984 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
985 y
= transientOwner
->frame_y
+
986 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
989 * limit transient windows to be inside their parent's head
991 rect
.pos
.x
= transientOwner
->frame_x
;
992 rect
.pos
.y
= transientOwner
->frame_y
;
993 rect
.size
.width
= transientOwner
->frame
->core
->width
;
994 rect
.size
.height
= transientOwner
->frame
->core
->height
;
996 head
= wGetHeadForRect(scr
, rect
);
997 rect
= wGetRectForHead(scr
, head
);
1001 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1002 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1006 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1007 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1010 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1012 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1015 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1021 * Make spash screens come out in the center of a head
1022 * trouble is that most splashies never get here
1023 * they are managed trough atoms but god knows where.
1024 * Dan, do you know ? -peter
1026 * Most of them are not managed, they have set
1027 * OverrideRedirect, which means we can't do anything about
1032 * xinerama checks for: across head and dead space
1036 rect
.size
.width
= width
;
1037 rect
.size
.height
= height
;
1039 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1041 if (flags
& XFLAG_DEAD
)
1044 if (flags
& XFLAG_MULTIPLE
)
1048 switch (reposition
) {
1050 head
= wGetHeadForPointerLocation(scr
);
1051 rect
= wGetRectForHead(scr
, head
);
1053 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1054 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1058 rect
= wGetRectForHead(scr
, head
);
1062 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1063 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1067 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1068 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1077 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1078 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1081 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1083 if (wwin
->flags
.urgent
) {
1084 if (!IS_OMNIPRESENT(wwin
))
1085 wwin
->flags
.omnipresent
^= 1;
1089 * Create frame, borders and do reparenting
1091 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1092 #ifdef XKB_BUTTON_HINT
1093 if (wPreferences
.modelock
)
1094 foo
|= WFF_LANGUAGE_BUTTON
;
1096 if (HAS_TITLEBAR(wwin
))
1097 foo
|= WFF_TITLEBAR
;
1098 if (HAS_RESIZEBAR(wwin
))
1099 foo
|= WFF_RESIZEBAR
;
1100 if (HAS_BORDER(wwin
))
1103 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1104 x
, y
, width
, height
,
1105 &wPreferences
.window_title_clearance
, foo
,
1106 scr
->window_title_texture
,
1107 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1109 wwin
->frame
->flags
.is_client_window_frame
= 1;
1110 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1112 /* setup button images */
1113 wWindowUpdateButtonImages(wwin
);
1115 /* hide unused buttons */
1117 if (WFLAGP(wwin
, no_close_button
))
1118 foo
|= WFF_RIGHT_BUTTON
;
1119 if (WFLAGP(wwin
, no_miniaturize_button
))
1120 foo
|= WFF_LEFT_BUTTON
;
1121 #ifdef XKB_BUTTON_HINT
1122 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1123 foo
|= WFF_LANGUAGE_BUTTON
;
1126 wFrameWindowHideButton(wwin
->frame
, foo
);
1128 wwin
->frame
->child
= wwin
;
1129 wwin
->frame
->workspace
= workspace
;
1130 wwin
->frame
->on_click_left
= windowIconifyClick
;
1132 #ifdef XKB_BUTTON_HINT
1133 if (wPreferences
.modelock
)
1134 wwin
->frame
->on_click_language
= windowLanguageClick
;
1137 wwin
->frame
->on_click_right
= windowCloseClick
;
1138 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1139 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1140 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1141 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1143 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1144 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1145 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1150 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1152 /* if gravity is to the south, account for the border sizes */
1154 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1158 * wWindowConfigure() will init the client window's size
1159 * (wwin->client.{width,height}) and all other geometry
1160 * related variables (frame_x,frame_y)
1162 wWindowConfigure(wwin
, x
, y
, width
, height
);
1164 /* to make sure the window receives it's new position after reparenting */
1165 wWindowSynthConfigureNotify(wwin
);
1168 * Setup descriptors and save window to internal
1171 if (wwin
->main_window
!= None
) {
1175 /* Leader windows do not necessary set themselves as leaders.
1176 * If this is the case, point the leader of this window to
1178 leader
= wWindowFor(wwin
->main_window
);
1179 if (leader
&& leader
->main_window
== None
) {
1180 leader
->main_window
= leader
->client_win
;
1182 app
= wApplicationCreate(wwin
);
1184 app
->last_workspace
= workspace
;
1187 * Do application specific stuff, like setting application
1191 if (wwin
->flags
.hidden
) {
1192 /* if the window was set to hidden because it was hidden
1193 * in a previous incarnation and that state was restored */
1194 app
->flags
.hidden
= 1;
1195 } else if (app
->flags
.hidden
) {
1196 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1197 wwin
->flags
.hidden
= 1;
1199 wUnhideApplication(app
, False
, False
);
1206 /* setup the frame descriptor */
1207 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1208 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1209 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1211 /* don't let windows go away if we die */
1212 XAddToSaveSet(dpy
, window
);
1214 XLowerWindow(dpy
, window
);
1216 /* if window is in this workspace and should be mapped, then map it */
1217 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1218 && !wwin
->flags
.hidden
&& !withdraw
) {
1220 /* The following "if" is to avoid crashing of clients that expect
1221 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1222 * after the return from this function.
1224 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1225 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1227 wClientSetState(wwin
, NormalState
, None
);
1231 /* if not auto focus, then map the window under the currently
1233 #define _WIDTH(w) (w)->frame->core->width
1234 #define _HEIGHT(w) (w)->frame->core->height
1235 if (!wPreferences
.auto_focus
&& scr
->focused_window
1236 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1238 (_WIDTH(scr
->focused_window
) * 5) / 3
1240 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1241 && WINDOW_LEVEL(scr
->focused_window
) ==
1243 || wwin
->flags
.maximized
)) {
1244 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1251 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1252 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1254 * The brain damaged idiotic non-click to focus modes will
1255 * have trouble with this because:
1257 * 1. window is created and mapped by the client
1258 * 2. window is mapped by wmaker in small size
1259 * 3. window is animated to grow to normal size
1260 * 4. this function returns to normal event loop
1261 * 5. eventually, the EnterNotify event that would trigger
1262 * the window focusing (if the mouse is over that window)
1263 * will be processed by wmaker.
1264 * But since this event will be rather delayed
1265 * (step 3 has a large delay) the time when the event ocurred
1266 * and when it is processed, the client that owns that window
1267 * will reject the XSetInputFocus() for it.
1269 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1270 DoWindowBirth(wwin
);
1276 /* setup stacking descriptor */
1277 if (transientOwner
) {
1278 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1280 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1283 if (!scr
->focused_window
) {
1284 /* first window on the list */
1287 scr
->focused_window
= wwin
;
1291 /* add window at beginning of focus window list */
1292 tmp
= scr
->focused_window
;
1300 /* raise is set to true if we un-hid the app when this window was born.
1301 * we raise, else old windows of this app will be above this new one. */
1303 wRaiseFrame(wwin
->frame
->core
);
1306 /* Update name must come after WApplication stuff is done */
1307 wWindowUpdateName(wwin
, title
);
1314 * Final preparations before window is ready to go
1316 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1318 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1319 if (((transientOwner
&& transientOwner
->flags
.focused
)
1320 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1322 /* only auto_focus if on same screen as mouse
1323 * (and same head for xinerama mode)
1324 * TODO: make it an option */
1326 /*TODO add checking the head of the window, is it available? */
1327 short same_screen
= 0, same_head
= 1;
1333 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1334 &foo
, &foo
, &foo
, &foo
, &bar
) != False
) {
1338 if (same_screen
== 1 && same_head
== 1) {
1339 wSetFocusTo(scr
, wwin
);
1343 wWindowResetMouseGrabs(wwin
);
1345 if (!WFLAGP(wwin
, no_bind_keys
))
1346 wWindowSetKeyGrabs(wwin
);
1348 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1349 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1351 /* Setup Notification Observers */
1352 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1354 /* Cleanup temporary stuff */
1356 wWindowDeleteSavedState(win_state
);
1358 /* If the window must be withdrawed, then do it now.
1359 * Must do some optimization, 'though */
1361 wwin
->flags
.mapped
= 0;
1362 wClientSetState(wwin
, WithdrawnState
, None
);
1363 wUnmanageWindow(wwin
, True
, False
);
1370 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1371 char *title
, int x
, int y
, int width
, int height
)
1376 wwin
= wWindowCreate();
1378 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1380 wwin
->flags
.internal_window
= 1;
1382 WSETUFLAG(wwin
, omnipresent
, 1);
1383 WSETUFLAG(wwin
, no_shadeable
, 1);
1384 WSETUFLAG(wwin
, no_resizable
, 1);
1385 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1387 wwin
->focus_mode
= WFM_PASSIVE
;
1388 wwin
->client_win
= window
;
1389 wwin
->screen_ptr
= scr
;
1390 wwin
->transient_for
= owner
;
1393 wwin
->client
.width
= width
;
1394 wwin
->client
.height
= height
;
1395 wwin
->frame_x
= wwin
->client
.x
;
1396 wwin
->frame_y
= wwin
->client
.y
;
1398 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1399 foo
|= WFF_TITLEBAR
;
1400 #ifdef XKB_BUTTON_HINT
1401 foo
|= WFF_LANGUAGE_BUTTON
;
1404 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1405 wwin
->frame_x
, wwin
->frame_y
,
1407 &wPreferences
.window_title_clearance
, foo
,
1408 scr
->window_title_texture
,
1409 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1411 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1413 wwin
->frame
->flags
.is_client_window_frame
= 1;
1414 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1416 wFrameWindowChangeTitle(wwin
->frame
, title
);
1418 /* setup button images */
1419 wWindowUpdateButtonImages(wwin
);
1422 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1424 wwin
->frame
->child
= wwin
;
1425 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1427 #ifdef XKB_BUTTON_HINT
1428 if (wPreferences
.modelock
)
1429 wwin
->frame
->on_click_language
= windowLanguageClick
;
1432 wwin
->frame
->on_click_right
= windowCloseClick
;
1433 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1434 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1435 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1436 wwin
->client
.y
+= wwin
->frame
->top_width
;
1438 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1439 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1441 /* setup the frame descriptor */
1442 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1443 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1444 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1446 XLowerWindow(dpy
, window
);
1447 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1449 /* setup stacking descriptor */
1450 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1452 tmp
= wWindowFor(wwin
->transient_for
);
1454 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1456 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1459 if (!scr
->focused_window
) {
1460 /* first window on the list */
1463 scr
->focused_window
= wwin
;
1467 /* add window at beginning of focus window list */
1468 tmp
= scr
->focused_window
;
1476 if (wwin
->flags
.is_gnustep
== 0)
1477 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1479 /* if (wPreferences.auto_focus) */
1480 wSetFocusTo(scr
, wwin
);
1481 wWindowResetMouseGrabs(wwin
);
1482 wWindowSetKeyGrabs(wwin
);
1488 *----------------------------------------------------------------------
1490 * Removes the frame window from a window and destroys all data
1491 * related to it. The window will be reparented back to the root window
1492 * if restore is True.
1495 * Everything related to the window is destroyed and the window
1496 * is removed from the window lists. Focus is set to the previous on the
1498 *----------------------------------------------------------------------
1500 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1502 WCoreWindow
*frame
= wwin
->frame
->core
;
1503 WWindow
*owner
= NULL
;
1504 WWindow
*newFocusedWindow
= NULL
;
1506 WScreen
*scr
= wwin
->screen_ptr
;
1508 /* First close attribute editor window if open */
1509 if (wwin
->flags
.inspector_open
) {
1510 wCloseInspectorForWindow(wwin
);
1513 /* Close window menu if it's open for this window */
1514 if (wwin
->flags
.menu_open_for_me
) {
1515 CloseWindowMenu(scr
);
1519 if (!wwin
->flags
.internal_window
)
1520 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1522 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1524 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1525 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1528 XUnmapWindow(dpy
, frame
->window
);
1530 XUnmapWindow(dpy
, wwin
->client_win
);
1532 /* deselect window */
1533 wSelectWindow(wwin
, False
);
1535 /* remove all pending events on window */
1536 /* I think this only matters for autoraise */
1537 if (wPreferences
.raise_delay
)
1538 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1542 /* reparent the window back to the root */
1544 wClientRestore(wwin
);
1546 if (wwin
->transient_for
!= scr
->root_win
) {
1547 owner
= wWindowFor(wwin
->transient_for
);
1549 if (!owner
->flags
.semi_focused
) {
1552 owner
->flags
.semi_focused
= 0;
1557 wasFocused
= wwin
->flags
.focused
;
1559 /* remove from window focus list */
1560 if (!wwin
->prev
&& !wwin
->next
) {
1561 /* was the only window */
1562 scr
->focused_window
= NULL
;
1563 newFocusedWindow
= NULL
;
1568 wwin
->prev
->next
= wwin
->next
;
1570 wwin
->next
->prev
= wwin
->prev
;
1572 scr
->focused_window
= wwin
->prev
;
1573 scr
->focused_window
->next
= NULL
;
1576 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1578 /* if in click to focus mode and the window
1579 * was a transient, focus the owner window
1582 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1583 tmp
= wWindowFor(wwin
->transient_for
);
1584 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1588 /* otherwise, focus the next one in the focus list */
1590 tmp
= scr
->focused_window
;
1591 while (tmp
) { /* look for one in the window list first */
1592 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1593 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1597 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1598 tmp
= scr
->focused_window
;
1600 if (!WFLAGP(tmp
, no_focusable
)
1601 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1608 newFocusedWindow
= tmp
;
1610 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1615 /* This is to let the root window get the keyboard input
1616 * if Sloppy focus mode and no other window get focus.
1617 * This way keybindings will not freeze.
1620 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1621 tmp
= wWindowFor(win
);
1624 newFocusedWindow
= tmp
;
1626 newFocusedWindow
= NULL
;
1630 if (!wwin
->flags
.internal_window
)
1631 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1633 if (newFocusedWindow
!= owner
&& owner
) {
1634 if (wwin
->flags
.is_gnustep
== 0)
1635 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1637 wSetFocusTo(scr
, newFocusedWindow
);
1639 wWindowDestroy(wwin
);
1643 void wWindowMap(WWindow
*wwin
)
1645 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1646 if (!wwin
->flags
.shaded
) {
1647 /* window will be remapped when getting MapNotify */
1648 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1649 XMapWindow(dpy
, wwin
->client_win
);
1650 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1652 wwin
->flags
.mapped
= 1;
1656 void wWindowUnmap(WWindow
*wwin
)
1658 wwin
->flags
.mapped
= 0;
1660 /* prevent window withdrawal when getting UnmapNotify */
1661 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1662 XUnmapWindow(dpy
, wwin
->client_win
);
1663 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1665 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1668 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1673 #ifdef KEEP_XKB_LOCK_STATUS
1674 if (wPreferences
.modelock
) {
1675 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1677 #endif /* KEEP_XKB_LOCK_STATUS */
1679 wwin
->flags
.semi_focused
= 0;
1681 if (wwin
->flags
.is_gnustep
== 0)
1682 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1684 wwin
->flags
.focused
= 1;
1686 wWindowResetMouseGrabs(wwin
);
1688 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1690 if (owin
== wwin
|| !owin
)
1693 nowner
= wWindowFor(wwin
->transient_for
);
1695 /* new window is a transient for the old window */
1696 if (nowner
== owin
) {
1697 owin
->flags
.semi_focused
= 1;
1698 wWindowUnfocus(nowner
);
1702 oowner
= wWindowFor(owin
->transient_for
);
1704 /* new window is owner of old window */
1705 if (wwin
== oowner
) {
1706 wWindowUnfocus(owin
);
1711 wWindowUnfocus(owin
);
1715 /* new window has same owner of old window */
1716 if (oowner
== nowner
) {
1717 /* prevent unfocusing of owner */
1718 oowner
->flags
.semi_focused
= 0;
1719 wWindowUnfocus(owin
);
1720 oowner
->flags
.semi_focused
= 1;
1725 /* nowner != NULL && oowner != nowner */
1726 nowner
->flags
.semi_focused
= 1;
1727 wWindowUnfocus(nowner
);
1728 wWindowUnfocus(owin
);
1731 void wWindowUnfocus(WWindow
*wwin
)
1733 CloseWindowMenu(wwin
->screen_ptr
);
1735 if (wwin
->flags
.is_gnustep
== 0)
1736 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1738 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1740 owner
= wWindowFor(wwin
->transient_for
);
1741 if (owner
&& owner
->flags
.semi_focused
) {
1742 owner
->flags
.semi_focused
= 0;
1743 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1744 wWindowUnfocus(owner
);
1745 wFrameWindowPaint(owner
->frame
);
1749 wwin
->flags
.focused
= 0;
1750 wWindowResetMouseGrabs(wwin
);
1751 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1754 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1761 wwin
->flags
.wm_name_changed
= 1;
1764 /* the hint was removed */
1765 title
= DEF_WINDOW_TITLE
;
1770 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1771 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1776 *----------------------------------------------------------------------
1778 * wWindowConstrainSize--
1779 * Constrains size for the client window, taking the maximal size,
1780 * window resize increments and other size hints into account.
1783 * The closest size to what was given that the client window can
1786 *----------------------------------------------------------------------
1788 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1790 int width
= (int)*nwidth
;
1791 int height
= (int)*nheight
;
1794 int minW
= 1, minH
= 1;
1795 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1796 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1797 int minAX
= -1, minAY
= -1;
1798 int maxAX
= -1, maxAY
= -1;
1802 if (wwin
->normal_hints
) {
1803 winc
= wwin
->normal_hints
->width_inc
;
1804 hinc
= wwin
->normal_hints
->height_inc
;
1805 minW
= wwin
->normal_hints
->min_width
;
1806 minH
= wwin
->normal_hints
->min_height
;
1807 maxW
= wwin
->normal_hints
->max_width
;
1808 maxH
= wwin
->normal_hints
->max_height
;
1809 if (wwin
->normal_hints
->flags
& PAspect
) {
1810 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1811 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1812 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1813 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1816 baseW
= wwin
->normal_hints
->base_width
;
1817 baseH
= wwin
->normal_hints
->base_height
;
1830 /* aspect ratio code borrowed from olwm */
1832 /* adjust max aspect ratio */
1833 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1834 if (maxAX
> maxAY
) {
1835 height
= (width
* maxAY
) / maxAX
;
1836 if (height
> maxH
) {
1838 width
= (height
* maxAX
) / maxAY
;
1841 width
= (height
* maxAX
) / maxAY
;
1844 height
= (width
* maxAY
) / maxAX
;
1849 /* adjust min aspect ratio */
1850 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1851 if (minAX
> minAY
) {
1852 height
= (width
* minAY
) / minAX
;
1853 if (height
< minH
) {
1855 width
= (height
* minAX
) / minAY
;
1858 width
= (height
* minAX
) / minAY
;
1861 height
= (width
* minAY
) / minAX
;
1868 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1870 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1873 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1875 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1877 /* broken stupid apps may cause preposterous values for these.. */
1884 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1885 unsigned int *width
, unsigned int *height
)
1887 int baseW
= 0, baseH
= 0;
1888 int winc
= 1, hinc
= 1;
1890 if (wwin
->normal_hints
) {
1891 baseW
= wwin
->normal_hints
->base_width
;
1892 baseH
= wwin
->normal_hints
->base_height
;
1894 winc
= wwin
->normal_hints
->width_inc
;
1895 hinc
= wwin
->normal_hints
->height_inc
;
1899 *width
= maxW
- (maxW
- baseW
) % winc
;
1902 *height
= maxH
- (maxH
- baseH
) % hinc
;
1905 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1907 WScreen
*scr
= wwin
->screen_ptr
;
1911 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1914 if (workspace
!= scr
->current_workspace
) {
1915 /* Sent to other workspace. Unmap window */
1916 if ((wwin
->flags
.mapped
1917 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1918 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1920 wapp
= wApplicationOf(wwin
->main_window
);
1922 wapp
->last_workspace
= workspace
;
1924 if (wwin
->flags
.miniaturized
) {
1926 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1927 wwin
->icon
->mapped
= 0;
1931 wSetFocusTo(scr
, NULL
);
1935 /* brought to current workspace. Map window */
1936 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1938 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1939 wwin
->icon
->mapped
= 1;
1941 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1945 if (!IS_OMNIPRESENT(wwin
)) {
1946 int oldWorkspace
= wwin
->frame
->workspace
;
1948 wwin
->frame
->workspace
= workspace
;
1950 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1957 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1961 sevent
.type
= ConfigureNotify
;
1962 sevent
.xconfigure
.display
= dpy
;
1963 sevent
.xconfigure
.event
= wwin
->client_win
;
1964 sevent
.xconfigure
.window
= wwin
->client_win
;
1966 sevent
.xconfigure
.x
= wwin
->client
.x
;
1967 sevent
.xconfigure
.y
= wwin
->client
.y
;
1968 sevent
.xconfigure
.width
= wwin
->client
.width
;
1969 sevent
.xconfigure
.height
= wwin
->client
.height
;
1971 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1972 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1973 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1975 sevent
.xconfigure
.above
= None
;
1977 sevent
.xconfigure
.override_redirect
= False
;
1978 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1983 *----------------------------------------------------------------------
1984 * wWindowConfigure()
1986 * req_x, req_y: new requested positions for the frame
1987 * req_width, req_height: new requested sizes for the client
1989 * Configures the frame, decorations and client window to the specified
1990 * geometry, whose validity is not checked -- wWindowConstrainSize()
1991 * must be used for that.
1992 * The size parameters are for the client window, but the position is
1994 * The client window receives a ConfigureNotify event, according
1995 * to what ICCCM says.
2001 * Window size and position are changed and client window receives
2002 * a ConfigureNotify event.
2003 *----------------------------------------------------------------------
2005 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2007 int synth_notify
= False
;
2010 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2012 * if the window is being moved but not resized then
2013 * send a synthetic ConfigureNotify
2015 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2016 synth_notify
= True
;
2019 if (WFLAGP(wwin
, dont_move_off
))
2020 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2022 if (req_width
< MIN_WINDOW_SIZE
)
2023 req_width
= MIN_WINDOW_SIZE
;
2024 if (req_height
< MIN_WINDOW_SIZE
)
2025 req_height
= MIN_WINDOW_SIZE
;
2027 /* If growing, resize inner part before frame,
2028 * if shrinking, resize frame before.
2029 * This will prevent the frame (that can have a different color)
2030 * to be exposed, causing flicker */
2031 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2032 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2034 if (wwin
->flags
.shaded
) {
2035 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2036 wwin
->old_geometry
.height
= req_height
;
2040 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2042 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2045 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2046 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2048 wwin
->client
.x
= req_x
;
2049 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2050 wwin
->client
.width
= req_width
;
2051 wwin
->client
.height
= req_height
;
2053 wwin
->client
.x
= req_x
;
2054 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2056 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2058 wwin
->frame_x
= req_x
;
2059 wwin
->frame_y
= req_y
;
2060 if (HAS_BORDER(wwin
)) {
2061 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2062 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2065 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2066 wWindowSetShape(wwin
);
2071 wWindowSynthConfigureNotify(wwin
);
2075 /* req_x, req_y: new position of the frame */
2076 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2078 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2079 int synth_notify
= False
;
2081 /* Send a synthetic ConfigureNotify event for every window movement. */
2082 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2083 synth_notify
= True
;
2086 /* A single synthetic ConfigureNotify event is sent at the end of
2087 * a completed (opaque) movement in moveres.c */
2090 if (WFLAGP(wwin
, dont_move_off
))
2091 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2092 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2094 wwin
->client
.x
= req_x
;
2095 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2096 if (HAS_BORDER(wwin
)) {
2097 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2098 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2101 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2103 wwin
->frame_x
= req_x
;
2104 wwin
->frame_y
= req_y
;
2106 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2108 wWindowSynthConfigureNotify(wwin
);
2112 void wWindowUpdateButtonImages(WWindow
*wwin
)
2114 WScreen
*scr
= wwin
->screen_ptr
;
2115 Pixmap pixmap
, mask
;
2116 WFrameWindow
*fwin
= wwin
->frame
;
2118 if (!HAS_TITLEBAR(wwin
))
2121 /* miniaturize button */
2122 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2123 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2124 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2126 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2127 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2132 if (fwin
->lbutton_image
2133 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2134 wPixmapDestroy(fwin
->lbutton_image
);
2135 fwin
->lbutton_image
= NULL
;
2138 if (!fwin
->lbutton_image
) {
2139 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2140 fwin
->lbutton_image
->client_owned
= 1;
2141 fwin
->lbutton_image
->client_owned_mask
= 1;
2144 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2145 wPixmapDestroy(fwin
->lbutton_image
);
2147 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2150 #ifdef XKB_BUTTON_HINT
2151 if (!WFLAGP(wwin
, no_language_button
)) {
2152 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2153 wPixmapDestroy(fwin
->languagebutton_image
);
2155 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2161 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2162 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2164 if (!WFLAGP(wwin
, no_close_button
)) {
2165 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2166 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2168 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2169 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2173 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2174 || fwin
->rbutton_image
->mask
!= mask
)) {
2175 wPixmapDestroy(fwin
->rbutton_image
);
2176 fwin
->rbutton_image
= NULL
;
2179 if (!fwin
->rbutton_image
) {
2180 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2181 fwin
->rbutton_image
->client_owned
= 1;
2182 fwin
->rbutton_image
->client_owned_mask
= 1;
2185 } else if (WFLAGP(wwin
, kill_close
)) {
2187 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2188 wPixmapDestroy(fwin
->rbutton_image
);
2190 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2192 } else if (MGFLAGP(wwin
, broken_close
)) {
2194 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2195 wPixmapDestroy(fwin
->rbutton_image
);
2197 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2201 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2202 wPixmapDestroy(fwin
->rbutton_image
);
2204 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2208 /* force buttons to be redrawn */
2209 fwin
->flags
.need_texture_change
= 1;
2210 wFrameWindowPaint(fwin
);
2214 *---------------------------------------------------------------------------
2215 * wWindowConfigureBorders--
2216 * Update window border configuration according to attribute flags.
2218 *---------------------------------------------------------------------------
2220 void wWindowConfigureBorders(WWindow
*wwin
)
2226 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2228 #ifdef XKB_BUTTON_HINT
2229 if (wPreferences
.modelock
)
2230 flags
|= WFF_LANGUAGE_BUTTON
;
2233 if (HAS_TITLEBAR(wwin
))
2234 flags
|= WFF_TITLEBAR
;
2235 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2236 flags
|= WFF_RESIZEBAR
;
2237 if (HAS_BORDER(wwin
))
2238 flags
|= WFF_BORDER
;
2239 if (wwin
->flags
.shaded
)
2240 flags
|= WFF_IS_SHADED
;
2242 oldh
= wwin
->frame
->top_width
;
2243 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2244 if (oldh
!= wwin
->frame
->top_width
) {
2245 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2247 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2248 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2252 if (!WFLAGP(wwin
, no_miniaturize_button
)
2253 && wwin
->frame
->flags
.hide_left_button
)
2254 flags
|= WFF_LEFT_BUTTON
;
2256 #ifdef XKB_BUTTON_HINT
2257 if (!WFLAGP(wwin
, no_language_button
)
2258 && wwin
->frame
->flags
.hide_language_button
) {
2259 flags
|= WFF_LANGUAGE_BUTTON
;
2263 if (!WFLAGP(wwin
, no_close_button
)
2264 && wwin
->frame
->flags
.hide_right_button
)
2265 flags
|= WFF_RIGHT_BUTTON
;
2268 wWindowUpdateButtonImages(wwin
);
2269 wFrameWindowShowButton(wwin
->frame
, flags
);
2273 if (WFLAGP(wwin
, no_miniaturize_button
)
2274 && !wwin
->frame
->flags
.hide_left_button
)
2275 flags
|= WFF_LEFT_BUTTON
;
2277 #ifdef XKB_BUTTON_HINT
2278 if (WFLAGP(wwin
, no_language_button
)
2279 && !wwin
->frame
->flags
.hide_language_button
)
2280 flags
|= WFF_LANGUAGE_BUTTON
;
2283 if (WFLAGP(wwin
, no_close_button
)
2284 && !wwin
->frame
->flags
.hide_right_button
)
2285 flags
|= WFF_RIGHT_BUTTON
;
2288 wFrameWindowHideButton(wwin
->frame
, flags
);
2291 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2292 wWindowSetShape(wwin
);
2298 void wWindowSaveState(WWindow
* wwin
)
2303 memset(data
, 0, sizeof(long) * 10);
2304 data
[0] = wwin
->frame
->workspace
;
2305 data
[1] = wwin
->flags
.miniaturized
;
2306 data
[2] = wwin
->flags
.shaded
;
2307 data
[3] = wwin
->flags
.hidden
;
2308 data
[4] = wwin
->flags
.maximized
;
2309 if (wwin
->flags
.maximized
== 0) {
2310 data
[5] = wwin
->frame_x
;
2311 data
[6] = wwin
->frame_y
;
2312 data
[7] = wwin
->frame
->core
->width
;
2313 data
[8] = wwin
->frame
->core
->height
;
2315 data
[5] = wwin
->old_geometry
.x
;
2316 data
[6] = wwin
->old_geometry
.y
;
2317 data
[7] = wwin
->old_geometry
.width
;
2318 data
[8] = wwin
->old_geometry
.height
;
2321 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2322 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2323 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2326 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2327 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2330 static int getSavedState(Window window
, WSavedState
** state
)
2334 unsigned long nitems_ret
;
2335 unsigned long bytes_after_ret
;
2338 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2339 True
, _XA_WINDOWMAKER_STATE
,
2340 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2341 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2344 *state
= wmalloc(sizeof(WSavedState
));
2346 (*state
)->workspace
= data
[0];
2347 (*state
)->miniaturized
= data
[1];
2348 (*state
)->shaded
= data
[2];
2349 (*state
)->hidden
= data
[3];
2350 (*state
)->maximized
= data
[4];
2351 (*state
)->x
= data
[5];
2352 (*state
)->y
= data
[6];
2353 (*state
)->w
= data
[7];
2354 (*state
)->h
= data
[8];
2355 (*state
)->window_shortcuts
= data
[9];
2359 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2366 void wWindowClearShape(WWindow
* wwin
)
2368 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2369 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2373 void wWindowSetShape(WWindow
* wwin
)
2377 #ifdef OPTIMIZE_SHAPE
2382 /* only shape is the client's */
2383 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2387 /* Get array of rectangles describing the shape mask */
2388 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2393 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2399 /* insert our decoration rectangles in the rect list */
2400 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2403 if (HAS_TITLEBAR(wwin
)) {
2405 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2406 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2407 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2410 if (HAS_RESIZEBAR(wwin
)) {
2412 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2413 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2414 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2418 /* shape our frame window */
2419 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2420 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2426 #endif /* OPTIMIZE_SHAPE */
2428 if (HAS_TITLEBAR(wwin
)) {
2431 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2432 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2435 if (HAS_RESIZEBAR(wwin
)) {
2437 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2438 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2439 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2443 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2444 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2446 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2447 0, wwin
->frame
->top_width
, wwin
->client_win
,
2448 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2453 /* ====================================================================== */
2455 static FocusMode
getFocusMode(WWindow
* wwin
)
2459 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2460 if (wwin
->wm_hints
->input
== True
) {
2461 if (wwin
->protocols
.TAKE_FOCUS
)
2462 mode
= WFM_LOCALLY_ACTIVE
;
2466 if (wwin
->protocols
.TAKE_FOCUS
)
2467 mode
= WFM_GLOBALLY_ACTIVE
;
2469 mode
= WFM_NO_INPUT
;
2477 void wWindowSetKeyGrabs(WWindow
* wwin
)
2482 for (i
= 0; i
< WKBD_LAST
; i
++) {
2483 key
= &wKeyBindings
[i
];
2485 if (key
->keycode
== 0)
2487 if (key
->modifier
!= AnyModifier
) {
2488 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2489 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2491 /* Also grab all modifier combinations possible that include,
2492 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2493 * work even if the NumLock/ScrollLock key is on.
2495 wHackedGrabKey(key
->keycode
, key
->modifier
,
2496 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2499 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2500 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2503 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2506 void wWindowResetMouseGrabs(WWindow
* wwin
)
2508 /* Mouse grabs can't be done on the client window because of
2509 * ICCCM and because clients that try to do the same will crash.
2511 * But there is a problem wich makes tbar buttons of unfocused
2512 * windows not usable as the click goes to the frame window instead
2513 * of the button itself. Must figure a way to fix that.
2516 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2518 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2519 /* grabs for Meta+drag */
2520 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2521 True
, ButtonPressMask
| ButtonReleaseMask
,
2522 GrabModeSync
, GrabModeAsync
, None
, None
);
2524 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2525 * but we only grab it for Button4 and Button 5 since a lot of apps
2526 * use CTRL+Button1-3 for app related functionality
2528 if (wPreferences
.resize_increment
> 0) {
2529 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2530 True
, ButtonPressMask
| ButtonReleaseMask
,
2531 GrabModeSync
, GrabModeAsync
, None
, None
);
2532 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2533 True
, ButtonPressMask
| ButtonReleaseMask
,
2534 GrabModeSync
, GrabModeAsync
, None
, None
);
2536 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2537 True
, ButtonPressMask
| ButtonReleaseMask
,
2538 GrabModeSync
, GrabModeAsync
, None
, None
);
2539 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2540 True
, ButtonPressMask
| ButtonReleaseMask
,
2541 GrabModeSync
, GrabModeAsync
, None
, None
);
2545 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2546 && !wwin
->flags
.is_gnustep
) {
2547 /* the passive grabs to focus the window */
2548 /* if (wPreferences.focus_mode == WKF_CLICK) */
2549 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2550 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2555 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2557 if (attr
->flags
& GSExtraFlagsAttr
) {
2558 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2559 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2560 wWindowUpdateButtonImages(wwin
);
2565 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2567 WWindowState
*wstate
;
2569 wstate
= malloc(sizeof(WWindowState
));
2573 memset(wstate
, 0, sizeof(WWindowState
));
2576 wstate
->instance
= wstrdup(instance
);
2578 wstate
->class = wstrdup(class);
2580 wstate
->command
= wstrdup(command
);
2581 wstate
->state
= state
;
2583 wstate
->next
= windowState
;
2584 windowState
= wstate
;
2589 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2591 WMagicNumber
wWindowGetSavedState(Window win
)
2593 char *instance
, *class, *command
= NULL
;
2594 WWindowState
*wstate
= windowState
;
2599 command
= GetCommandForWindow(win
);
2603 if (PropGetWMClass(win
, &class, &instance
)) {
2605 if (SAME(instance
, wstate
->instance
) &&
2606 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2609 wstate
= wstate
->next
;
2625 void wWindowDeleteSavedState(WMagicNumber id
)
2627 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2629 if (!wstate
|| !windowState
)
2633 if (tmp
== wstate
) {
2634 windowState
= wstate
->next
;
2635 if (wstate
->instance
)
2636 wfree(wstate
->instance
);
2638 wfree(wstate
->class);
2639 if (wstate
->command
)
2640 wfree(wstate
->command
);
2641 wfree(wstate
->state
);
2645 if (tmp
->next
== wstate
) {
2646 tmp
->next
= wstate
->next
;
2647 if (wstate
->instance
)
2648 wfree(wstate
->instance
);
2650 wfree(wstate
->class);
2651 if (wstate
->command
)
2652 wfree(wstate
->command
);
2653 wfree(wstate
->state
);
2662 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2664 WWindowState
*tmp
, *wstate
;
2670 if (tmp
->pid
== pid
) {
2671 wstate
= windowState
;
2672 windowState
= tmp
->next
;
2673 if (wstate
->instance
)
2674 wfree(wstate
->instance
);
2676 wfree(wstate
->class);
2677 if (wstate
->command
)
2678 wfree(wstate
->command
);
2679 wfree(wstate
->state
);
2683 if (tmp
->next
->pid
== pid
) {
2685 tmp
->next
= wstate
->next
;
2686 if (wstate
->instance
)
2687 wfree(wstate
->instance
);
2689 wfree(wstate
->class);
2690 if (wstate
->command
)
2691 wfree(wstate
->command
);
2692 wfree(wstate
->state
);
2701 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2703 if (wwin
->flags
.omnipresent
== flag
)
2706 wwin
->flags
.omnipresent
= flag
;
2707 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2710 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2712 WWindow
*wwin
= data
;
2714 #ifndef NUMLOCK_HACK
2715 if ((event
->xbutton
.state
& ValidModMask
)
2716 != (event
->xbutton
.state
& ~LockMask
)) {
2717 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2718 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2722 event
->xbutton
.state
&= ValidModMask
;
2724 CloseWindowMenu(wwin
->screen_ptr
);
2726 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2727 && !WFLAGP(wwin
, no_focusable
)) {
2728 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2731 if (event
->xbutton
.button
== Button1
)
2732 wRaiseFrame(wwin
->frame
->core
);
2734 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2735 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2736 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2737 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2742 if (event
->xbutton
.state
& MOD_MASK
) {
2743 /* move the window */
2744 wMouseMoveWindow(wwin
, event
);
2745 XUngrabPointer(dpy
, CurrentTime
);
2747 wMouseResizeWindow(wwin
, event
);
2748 XUngrabPointer(dpy
, CurrentTime
);
2752 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2754 WWindow
*wwin
= data
;
2756 event
->xbutton
.state
&= ValidModMask
;
2758 if (event
->xbutton
.button
== Button1
) {
2759 if (event
->xbutton
.state
== 0) {
2760 if (!WFLAGP(wwin
, no_shadeable
)) {
2762 if (wwin
->flags
.shaded
)
2763 wUnshadeWindow(wwin
);
2770 if (event
->xbutton
.state
& ControlMask
)
2771 dir
|= MAX_VERTICAL
;
2773 if (event
->xbutton
.state
& ShiftMask
) {
2774 dir
|= MAX_HORIZONTAL
;
2775 if (!(event
->xbutton
.state
& ControlMask
))
2776 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2779 /* maximize window */
2780 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2781 int ndir
= dir
^ wwin
->flags
.maximized
;
2784 wMaximizeWindow(wwin
, ndir
);
2786 wUnmaximizeWindow(wwin
);
2789 } else if (event
->xbutton
.button
== Button3
) {
2790 if (event
->xbutton
.state
& MOD_MASK
) {
2791 wHideOtherApplications(wwin
);
2793 } else if (event
->xbutton
.button
== Button2
) {
2794 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2795 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2797 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2798 wUnshadeWindow(wwin
);
2802 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2804 WWindow
*wwin
= desc
->parent
;
2805 unsigned int new_width
, w_scale
;
2806 unsigned int new_height
, h_scale
;
2807 unsigned int resize_width_increment
= 0;
2808 unsigned int resize_height_increment
= 0;
2810 if (wwin
->normal_hints
) {
2811 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2812 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2813 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2814 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2816 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2817 resize_width_increment
= wPreferences
.resize_increment
;
2818 resize_height_increment
= wPreferences
.resize_increment
;
2821 event
->xbutton
.state
&= ValidModMask
;
2823 CloseWindowMenu(wwin
->screen_ptr
);
2825 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2826 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2828 if (event
->xbutton
.button
== Button1
)
2829 wRaiseFrame(wwin
->frame
->core
);
2831 if (event
->xbutton
.state
& ControlMask
) {
2832 if (event
->xbutton
.button
== Button4
) {
2833 new_width
= wwin
->client
.width
- resize_width_increment
;
2834 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2835 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2837 if (event
->xbutton
.button
== Button5
) {
2838 new_width
= wwin
->client
.width
+ resize_width_increment
;
2839 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2840 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2844 if (event
->xbutton
.state
& MOD_MASK
) {
2845 /* move the window */
2846 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2847 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2848 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2851 if (event
->xbutton
.button
== Button3
) {
2852 wMouseResizeWindow(wwin
, event
);
2853 } else if (event
->xbutton
.button
== Button4
) {
2854 new_height
= wwin
->client
.height
- resize_height_increment
;
2855 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2856 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2857 } else if (event
->xbutton
.button
== Button5
) {
2858 new_height
= wwin
->client
.height
+ resize_height_increment
;
2859 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2860 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2861 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2862 wMouseMoveWindow(wwin
, event
);
2864 XUngrabPointer(dpy
, CurrentTime
);
2868 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2870 WWindow
*wwin
= (WWindow
*) data
;
2872 #ifndef NUMLOCK_HACK
2873 if ((event
->xbutton
.state
& ValidModMask
)
2874 != (event
->xbutton
.state
& ~LockMask
)) {
2875 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2876 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2879 event
->xbutton
.state
&= ValidModMask
;
2881 CloseWindowMenu(wwin
->screen_ptr
);
2883 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2884 && !WFLAGP(wwin
, no_focusable
)) {
2885 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2888 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2890 if (event
->xbutton
.button
== Button1
) {
2891 if (event
->xbutton
.state
& MOD_MASK
) {
2892 wLowerFrame(wwin
->frame
->core
);
2894 wRaiseFrame(wwin
->frame
->core
);
2897 if ((event
->xbutton
.state
& ShiftMask
)
2898 && !(event
->xbutton
.state
& ControlMask
)) {
2899 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2902 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2903 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2904 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2905 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2909 /* move the window */
2910 wMouseMoveWindow(wwin
, event
);
2912 XUngrabPointer(dpy
, CurrentTime
);
2913 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2914 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2915 WObjDescriptor
*desc
;
2917 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2918 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2919 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2920 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2924 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2926 /* allow drag select */
2927 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2928 event
->xany
.send_event
= True
;
2929 (*desc
->handle_mousedown
) (desc
, event
);
2931 XUngrabPointer(dpy
, CurrentTime
);
2935 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2937 WWindow
*wwin
= data
;
2939 event
->xbutton
.state
&= ValidModMask
;
2941 CloseWindowMenu(wwin
->screen_ptr
);
2943 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2946 /* if control-click, kill the client */
2947 if (event
->xbutton
.state
& ControlMask
) {
2950 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2951 /* send delete message */
2952 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2957 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2959 WWindow
*wwin
= data
;
2961 CloseWindowMenu(wwin
->screen_ptr
);
2963 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2966 /* send delete message */
2967 if (wwin
->protocols
.DELETE_WINDOW
) {
2968 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2974 #ifdef XKB_BUTTON_HINT
2975 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2977 WWindow
*wwin
= data
;
2978 WFrameWindow
*fwin
= wwin
->frame
;
2979 WScreen
*scr
= fwin
->screen_ptr
;
2982 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2984 tl
= wwin
->frame
->languagemode
;
2985 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2986 wwin
->frame
->last_languagemode
= tl
;
2987 wSetFocusTo(scr
, wwin
);
2988 wwin
->frame
->languagebutton_image
=
2989 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2990 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2991 if (event
->xbutton
.button
== Button3
)
2993 wRaiseFrame(fwin
->core
);
2997 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2999 WWindow
*wwin
= data
;
3001 event
->xbutton
.state
&= ValidModMask
;
3003 CloseWindowMenu(wwin
->screen_ptr
);
3005 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3008 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3009 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3012 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3014 wapp
= wApplicationOf(wwin
->main_window
);
3015 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3016 wHideApplication(wapp
);
3017 } else if (event
->xbutton
.state
== 0) {
3018 wIconifyWindow(wwin
);