1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
29 #ifdef KEEP_XKB_LOCK_STATUS
30 #include <X11/XKBlib.h>
31 #endif /* KEEP_XKB_LOCK_STATUS */
38 /* For getting mouse wheel mappings from WINGs */
39 #include <WINGs/WINGs.h>
41 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
56 #include "workspace.h"
60 #include "superfluous.h"
62 #include "placement.h"
73 #define MOD_MASK wPreferences.modifier_mask
75 /****** Global Variables ******/
76 extern WShortKey wKeyBindings
[WKBD_LAST
];
79 extern Bool wShapeSupported
;
83 extern XContext wWinContext
;
86 extern Atom _XA_WM_DELETE_WINDOW
;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
88 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern WPreferences wPreferences
;
90 extern Time LastTimestamp
;
92 /***** Local Stuff *****/
93 static WWindowState
*windowState
= NULL
;
94 static FocusMode
getFocusMode(WWindow
*wwin
);
95 static int getSavedState(Window window
, WSavedState
**state
);
96 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
98 /* frame window (during window grabs) */
99 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
102 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
103 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
106 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 #ifdef XKB_BUTTON_HINT
109 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
112 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
113 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
114 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
116 static void release_wwindowstate(WWindowState
*wstate
);
118 /****** Notification Observers ******/
120 static void appearanceObserver(void *self
, WMNotification
* notif
)
122 WWindow
*wwin
= (WWindow
*) self
;
123 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
125 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
128 if (flags
& WFontSettings
) {
129 wWindowConfigureBorders(wwin
);
130 if (wwin
->flags
.shaded
) {
131 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
132 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
133 wWindowSynthConfigureNotify(wwin
);
136 if (flags
& WTextureSettings
)
137 wwin
->frame
->flags
.need_texture_remake
= 1;
139 if (flags
& (WTextureSettings
| WColorSettings
)) {
140 if (wwin
->frame
->titlebar
)
141 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
143 wFrameWindowPaint(wwin
->frame
);
148 /* Return the WWindow associated with a given (Xlib) Window. */
149 WWindow
*wWindowFor(Window window
)
151 WObjDescriptor
*desc
;
156 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
159 if (desc
->parent_type
== WCLASS_WINDOW
)
161 else if (desc
->parent_type
== WCLASS_FRAME
) {
162 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
163 if (frame
->flags
.is_client_window_frame
)
170 WWindow
*wWindowCreate(void)
174 wwin
= wmalloc(sizeof(WWindow
));
177 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
178 wwin
->client_descriptor
.parent
= wwin
;
179 wwin
->client_descriptor
.self
= wwin
;
180 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
185 void wWindowDestroy(WWindow
*wwin
)
189 if (wwin
->screen_ptr
->cmap_window
== wwin
)
190 wwin
->screen_ptr
->cmap_window
= NULL
;
192 WMRemoveNotificationObserver(wwin
);
194 wwin
->flags
.destroyed
= 1;
196 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
197 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
200 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
202 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
203 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
204 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
208 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
209 wwin
->fake_group
->retainCount
--;
210 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
211 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
212 wwin
->fake_group
->leader
= None
;
213 wwin
->fake_group
->origLeader
= None
;
218 if (wwin
->normal_hints
)
219 XFree(wwin
->normal_hints
);
222 XFree(wwin
->wm_hints
);
224 if (wwin
->wm_instance
)
225 XFree(wwin
->wm_instance
);
228 XFree(wwin
->wm_class
);
230 if (wwin
->wm_gnustep_attr
)
231 wfree(wwin
->wm_gnustep_attr
);
233 if (wwin
->cmap_windows
)
234 XFree(wwin
->cmap_windows
);
236 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
239 wFrameWindowDestroy(wwin
->frame
);
242 RemoveFromStackList(wwin
->icon
->core
);
243 wIconDestroy(wwin
->icon
);
244 if (wPreferences
.auto_arrange_icons
)
245 wArrangeIcons(wwin
->screen_ptr
, True
);
247 if (wwin
->net_icon_image
)
248 RReleaseImage(wwin
->net_icon_image
);
253 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
255 if (gs_hints
->flags
& GSWindowStyleAttr
) {
256 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
257 wwin
->client_flags
.no_border
= 1;
258 wwin
->client_flags
.no_titlebar
= 1;
259 wwin
->client_flags
.no_closable
= 1;
260 wwin
->client_flags
.no_miniaturizable
= 1;
261 wwin
->client_flags
.no_resizable
= 1;
262 wwin
->client_flags
.no_close_button
= 1;
263 wwin
->client_flags
.no_miniaturize_button
= 1;
264 wwin
->client_flags
.no_resizebar
= 1;
266 wwin
->client_flags
.no_close_button
=
267 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
269 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
271 wwin
->client_flags
.no_miniaturize_button
=
272 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
274 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
276 wwin
->client_flags
.no_resizebar
=
277 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
279 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
281 /* these attributes supposedly imply in the existence
283 if (gs_hints
->window_style
& (WMResizableWindowMask
|
284 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
285 wwin
->client_flags
.no_titlebar
= 0;
287 wwin
->client_flags
.no_titlebar
=
288 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
293 /* setup the defaults */
294 wwin
->client_flags
.no_border
= 0;
295 wwin
->client_flags
.no_titlebar
= 0;
296 wwin
->client_flags
.no_closable
= 0;
297 wwin
->client_flags
.no_miniaturizable
= 0;
298 wwin
->client_flags
.no_resizable
= 0;
299 wwin
->client_flags
.no_close_button
= 0;
300 wwin
->client_flags
.no_miniaturize_button
= 0;
301 wwin
->client_flags
.no_resizebar
= 0;
303 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
304 wwin
->client_flags
.no_appicon
= 1;
307 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
309 WScreen
*scr
= wwin
->screen_ptr
;
311 /* sets global default stuff */
312 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
314 * Decoration setting is done in this precedence (lower to higher)
315 * - use global default in the resource database
316 * - guess some settings
317 * - use GNUstep/external window attributes
318 * - set hints specified for the app in the resource DB
321 WSETUFLAG(wwin
, broken_close
, 0);
323 if (wwin
->protocols
.DELETE_WINDOW
)
324 WSETUFLAG(wwin
, kill_close
, 0);
326 WSETUFLAG(wwin
, kill_close
, 1);
328 /* transients can't be iconified or maximized */
329 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
330 WSETUFLAG(wwin
, no_miniaturizable
, 1);
331 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
334 /* if the window can't be resized, remove the resizebar */
335 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
336 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
337 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
338 WSETUFLAG(wwin
, no_resizable
, 1);
339 WSETUFLAG(wwin
, no_resizebar
, 1);
342 /* set GNUstep window attributes */
343 if (wwin
->wm_gnustep_attr
) {
344 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
346 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
348 *level
= wwin
->wm_gnustep_attr
->window_level
;
350 * INT_MIN is the only illegal window level.
352 if (*level
== INT_MIN
)
353 *level
= INT_MIN
+ 1;
356 *level
= WMNormalLevel
;
359 int tmp_workspace
= -1;
360 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
363 wMWMCheckClientHints(wwin
);
364 #endif /* MWM_HINTS */
366 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
368 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
369 * have INT_MIN that means that no window level was requested. -Dan
371 if (tmp_level
== INT_MIN
) {
372 if (WFLAGP(wwin
, floating
))
373 *level
= WMFloatingLevel
;
374 else if (WFLAGP(wwin
, sunken
))
375 *level
= WMSunkenLevel
;
377 *level
= WMNormalLevel
;
382 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
383 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
384 if (transientOwner
) {
385 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
386 if (ownerLevel
> *level
)
391 if (tmp_workspace
>= 0)
392 *workspace
= tmp_workspace
% scr
->workspace_count
;
396 * Set attributes specified only for that window/class.
397 * This might do duplicate work with the 1st wDefaultFillAttributes().
399 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
400 &wwin
->defined_user_flags
, False
);
402 * Sanity checks for attributes that depend on other attributes
404 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
405 wwin
->user_flags
.emulate_appicon
= 0;
407 if (wwin
->main_window
!= None
) {
408 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
409 if (wapp
&& !wapp
->flags
.emulated
)
410 wwin
->user_flags
.emulate_appicon
= 0;
413 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
414 wwin
->user_flags
.emulate_appicon
= 0;
416 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
417 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
418 wwin
->user_flags
.sunken
= 0;
420 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
422 /* windows that have takefocus=False shouldn't take focus at all */
423 if (wwin
->focus_mode
== WFM_NO_INPUT
)
424 wwin
->client_flags
.no_focusable
= 1;
427 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
431 w1
= wwin
->frame
->core
->width
;
432 h1
= wwin
->frame
->core
->height
;
433 w2
= obscured
->frame
->core
->width
;
434 h2
= obscured
->frame
->core
->height
;
436 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
437 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
440 if (wwin
->frame_x
+ w1
< obscured
->frame_x
441 || wwin
->frame_y
+ h1
< obscured
->frame_y
442 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
448 static void fixLeaderProperties(WWindow
*wwin
)
450 XClassHint
*classHint
;
451 XWMHints
*hints
, *clientHints
;
452 XWindowAttributes attr
;
453 Window leaders
[2], window
;
454 char **argv
, *command
;
458 classHint
= XAllocClassHint();
459 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
460 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
462 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
466 leaders
[0] = wwin
->client_leader
;
467 leaders
[1] = wwin
->group_id
;
470 command
= GetCommandForWindow(wwin
->client_win
);
472 wfree(command
); /* command already set. nothing to do. */
474 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
477 for (i
= 0; i
< 2; i
++) {
480 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
481 classHint
->res_name
= wwin
->wm_instance
;
482 classHint
->res_class
= wwin
->wm_class
;
483 XSetClassHint(dpy
, window
, classHint
);
485 hints
= XGetWMHints(dpy
, window
);
488 } else if (clientHints
) {
489 /* set window group leader to self */
490 clientHints
->window_group
= window
;
491 clientHints
->flags
|= WindowGroupHint
;
492 XSetWMHints(dpy
, window
, clientHints
);
496 command
= GetCommandForWindow(window
);
498 wfree(command
); /* command already set. nothing to do. */
500 XSetCommand(dpy
, window
, argv
, argc
);
503 /* Make sure we get notification when this window is destroyed */
504 if (XGetWindowAttributes(dpy
, window
, &attr
))
505 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
516 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
518 XClassHint
*classHint
;
524 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
526 classHint
= XAllocClassHint();
527 classHint
->res_name
= instance
;
528 classHint
->res_class
= class;
529 XSetClassHint(dpy
, leader
, classHint
);
532 /* inherit these from the original leader if available */
533 hints
= XGetWMHints(dpy
, win
);
535 hints
= XAllocWMHints();
538 /* set window group leader to self */
539 hints
->window_group
= leader
;
540 hints
->flags
|= WindowGroupHint
;
541 XSetWMHints(dpy
, leader
, hints
);
544 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
545 XSetCommand(dpy
, leader
, argv
, argc
);
546 XFreeStringList(argv
);
552 static int matchIdentifier(const void *item
, const void *cdata
)
554 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
558 *----------------------------------------------------------------
560 * reparents the window and allocates a descriptor for it.
561 * Window manager hints and other hints are fetched to configure
562 * the window decoration attributes and others. User preferences
563 * for the window are used if available, to configure window
564 * decorations and some behaviour.
565 * If in startup, windows that are override redirect,
566 * unmapped and never were managed and are Withdrawn are not
570 * the new window descriptor
573 * The window is reparented and appropriate notification
574 * is done to the client. Input mask for the window is setup.
575 * The window descriptor is also associated with various window
576 * contexts and inserted in the head of the window list.
577 * Event handler contexts are associated for some objects
578 * (buttons, titlebar and resizebar)
580 *----------------------------------------------------------------
582 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
586 unsigned width
, height
;
587 XWindowAttributes wattribs
;
588 XSetWindowAttributes attribs
;
589 WWindowState
*win_state
;
590 WWindow
*transientOwner
= NULL
;
596 Bool withdraw
= False
;
603 /* make sure the window is still there */
604 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
609 /* if it's an override-redirect, ignore it */
610 if (wattribs
.override_redirect
) {
615 wm_state
= PropGetWindowState(window
);
617 /* if it's startup and the window is unmapped, don't manage it */
618 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
623 wwin
= wWindowCreate();
625 title
= wNETWMGetWindowName(window
);
627 wwin
->flags
.net_has_title
= 1;
628 else if (!wFetchName(dpy
, window
, &title
))
631 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
634 if (wShapeSupported
) {
639 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
640 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
641 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
642 wwin
->flags
.shaped
= b_shaped
;
646 /* Get hints and other information in properties */
647 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
649 /* setup descriptor */
650 wwin
->client_win
= window
;
651 wwin
->screen_ptr
= scr
;
652 wwin
->old_border_width
= wattribs
.border_width
;
653 wwin
->event_mask
= CLIENT_EVENTS
;
654 attribs
.event_mask
= CLIENT_EVENTS
;
655 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
656 attribs
.save_under
= False
;
658 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
659 XSetWindowBorderWidth(dpy
, window
, 0);
661 /* get hints from GNUstep app */
662 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
663 wwin
->flags
.is_gnustep
= 1;
665 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
666 wwin
->wm_gnustep_attr
= NULL
;
668 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
669 wwin
->flags
.is_dockapp
= 1;
673 wwin
->client_leader
= PropGetClientLeader(window
);
674 if (wwin
->client_leader
!= None
)
675 wwin
->main_window
= wwin
->client_leader
;
677 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
679 if (wwin
->wm_hints
) {
680 if (wwin
->wm_hints
->flags
& StateHint
) {
681 if (wwin
->wm_hints
->initial_state
== IconicState
) {
682 wwin
->flags
.miniaturized
= 1;
683 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
684 wwin
->flags
.is_dockapp
= 1;
689 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
690 wwin
->group_id
= wwin
->wm_hints
->window_group
;
691 /* window_group has priority over CLIENT_LEADER */
692 wwin
->main_window
= wwin
->group_id
;
694 wwin
->group_id
= None
;
697 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
698 wwin
->flags
.urgent
= 1;
699 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
702 wwin
->group_id
= None
;
705 PropGetProtocols(window
, &wwin
->protocols
);
707 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
708 wwin
->transient_for
= None
;
710 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
711 wwin
->transient_for
= scr
->root_win
;
713 transientOwner
= wWindowFor(wwin
->transient_for
);
714 if (transientOwner
&& transientOwner
->main_window
!= None
)
715 wwin
->main_window
= transientOwner
->main_window
;
719 /* guess the focus mode */
720 wwin
->focus_mode
= getFocusMode(wwin
);
722 /* get geometry stuff */
723 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
725 /* get colormap windows */
726 GetColormapWindows(wwin
);
729 * Setup the decoration/window attributes and
732 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
734 /* Make broken apps behave as a nice app. */
735 if (WFLAGP(wwin
, emulate_appicon
))
736 wwin
->main_window
= wwin
->client_win
;
738 fixLeaderProperties(wwin
);
740 wwin
->orig_main_window
= wwin
->main_window
;
742 if (wwin
->flags
.is_gnustep
)
743 WSETUFLAG(wwin
, shared_appicon
, 0);
745 if (wwin
->main_window
) {
746 extern Atom _XA_WINDOWMAKER_MENU
;
747 XTextProperty text_prop
;
749 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
))
750 WSETUFLAG(wwin
, shared_appicon
, 0);
753 if (wwin
->flags
.is_dockapp
)
754 WSETUFLAG(wwin
, shared_appicon
, 0);
756 if (wwin
->main_window
) {
757 WApplication
*app
= wApplicationOf(wwin
->main_window
);
758 if (app
&& app
->app_icon
)
759 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
->main_window
= fPtr
->leader
;
791 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
793 fPtr
->identifier
= buffer
;
794 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
795 fPtr
->origLeader
= None
;
796 fPtr
->retainCount
= 1;
798 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
800 if (ADEQUATE(wwin
->main_window
)) {
802 fPtr
->origLeader
= wwin
->main_window
;
804 wwin
->fake_group
= fPtr
;
805 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) {
829 if (wm_state
== IconicState
)
830 wwin
->flags
.miniaturized
= 1;
831 else if (wm_state
== WithdrawnState
)
835 /* if there is a saved state (from file), restore it */
837 if (wwin
->main_window
!= None
)
838 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
840 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
842 if (win_state
&& !withdraw
) {
843 if (win_state
->state
->hidden
> 0)
844 wwin
->flags
.hidden
= win_state
->state
->hidden
;
846 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
847 wwin
->flags
.shaded
= win_state
->state
->shaded
;
849 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
850 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
852 if (!IS_OMNIPRESENT(wwin
)) {
853 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
855 if (w
< 0 || w
>= scr
->workspace_count
) {
856 workspace
= win_state
->state
->workspace
;
857 if (workspace
>= scr
->workspace_count
)
858 workspace
= scr
->current_workspace
;
863 workspace
= scr
->current_workspace
;
867 /* if we're restarting, restore saved state (from hints).
868 * This will overwrite previous */
872 if (getSavedState(window
, &wstate
)) {
873 wwin
->flags
.shaded
= wstate
->shaded
;
874 wwin
->flags
.hidden
= wstate
->hidden
;
875 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
876 wwin
->flags
.maximized
= wstate
->maximized
;
877 if (wwin
->flags
.maximized
) {
878 wwin
->old_geometry
.x
= wstate
->x
;
879 wwin
->old_geometry
.y
= wstate
->y
;
880 wwin
->old_geometry
.width
= wstate
->w
;
881 wwin
->old_geometry
.height
= wstate
->h
;
884 workspace
= wstate
->workspace
;
889 /* restore window shortcut */
890 if (wstate
!= NULL
|| win_state
!= NULL
) {
893 if (win_state
!= NULL
)
894 mask
= win_state
->state
->window_shortcuts
;
896 if (wstate
!= NULL
&& mask
== 0)
897 mask
= wstate
->window_shortcuts
;
902 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
903 if (mask
& (1 << i
)) {
904 if (!scr
->shortcutWindows
[i
])
905 scr
->shortcutWindows
[i
] = WMCreateArray(4);
907 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
917 /* don't let transients start miniaturized if their owners are not */
918 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
919 wwin
->flags
.miniaturized
= 0;
921 wwin
->wm_hints
->initial_state
= NormalState
;
924 /* set workspace on which the window starts */
925 if (workspace
>= 0) {
926 if (workspace
> scr
->workspace_count
- 1)
927 workspace
= workspace
% scr
->workspace_count
;
931 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
933 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
936 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
937 workspace
= transientOwner
->frame
->workspace
;
939 workspace
= scr
->current_workspace
;
943 /* setup window geometry */
944 if (win_state
&& win_state
->state
->w
> 0) {
945 width
= win_state
->state
->w
;
946 height
= win_state
->state
->h
;
949 wWindowConstrainSize(wwin
, &width
, &height
);
951 /* do not ask for window placement if the window is
952 * transient, during startup, if the initial workspace is another one
953 * or if the window wants to start iconic.
954 * If geometry was saved, restore it. */
956 Bool dontBring
= False
;
958 if (win_state
&& win_state
->state
->w
> 0) {
959 x
= win_state
->state
->x
;
960 y
= win_state
->state
->y
;
961 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
962 && !scr
->flags
.startup
963 && workspace
== scr
->current_workspace
964 && !wwin
->flags
.miniaturized
965 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
967 if (transientOwner
&& transientOwner
->flags
.mapped
) {
968 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
972 x
= transientOwner
->frame_x
+
973 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
974 y
= transientOwner
->frame_y
+
975 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
977 /* limit transient windows to be inside their parent's head */
978 rect
.pos
.x
= transientOwner
->frame_x
;
979 rect
.pos
.y
= transientOwner
->frame_y
;
980 rect
.size
.width
= transientOwner
->frame
->core
->width
;
981 rect
.size
.height
= transientOwner
->frame
->core
->height
;
983 head
= wGetHeadForRect(scr
, rect
);
984 rect
= wGetRectForHead(scr
, head
);
988 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
989 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
993 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
994 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
997 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1000 if (wPreferences
.window_placement
== WPM_MANUAL
)
1003 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1008 /* Make spash screens come out in the center of a head
1009 * trouble is that most splashies never get here
1010 * they are managed trough atoms but god knows where.
1011 * Dan, do you know ? -peter
1013 * Most of them are not managed, they have set
1014 * OverrideRedirect, which means we can't do anything about
1017 /* xinerama checks for: across head and dead space */
1020 rect
.size
.width
= width
;
1021 rect
.size
.height
= height
;
1023 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1025 if (flags
& XFLAG_DEAD
)
1028 if (flags
& XFLAG_MULTIPLE
)
1032 switch (reposition
) {
1034 head
= wGetHeadForPointerLocation(scr
);
1035 rect
= wGetRectForHead(scr
, head
);
1037 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1038 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1042 rect
= wGetRectForHead(scr
, head
);
1046 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1047 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1051 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1052 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1061 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1062 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1065 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1067 if (wwin
->flags
.urgent
) {
1068 if (!IS_OMNIPRESENT(wwin
))
1069 wwin
->flags
.omnipresent
^= 1;
1072 /* Create frame, borders and do reparenting */
1073 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1074 #ifdef XKB_BUTTON_HINT
1075 if (wPreferences
.modelock
)
1076 foo
|= WFF_LANGUAGE_BUTTON
;
1078 if (HAS_TITLEBAR(wwin
))
1079 foo
|= WFF_TITLEBAR
;
1081 if (HAS_RESIZEBAR(wwin
))
1082 foo
|= WFF_RESIZEBAR
;
1084 if (HAS_BORDER(wwin
))
1087 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1088 x
, y
, width
, height
,
1089 &wPreferences
.window_title_clearance
,
1090 &wPreferences
.window_title_min_height
,
1091 &wPreferences
.window_title_max_height
,
1093 scr
->window_title_texture
,
1094 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1095 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1097 wwin
->frame
->flags
.is_client_window_frame
= 1;
1098 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1100 /* setup button images */
1101 wWindowUpdateButtonImages(wwin
);
1103 /* hide unused buttons */
1105 if (WFLAGP(wwin
, no_close_button
))
1106 foo
|= WFF_RIGHT_BUTTON
;
1108 if (WFLAGP(wwin
, no_miniaturize_button
))
1109 foo
|= WFF_LEFT_BUTTON
;
1111 #ifdef XKB_BUTTON_HINT
1112 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1113 foo
|= WFF_LANGUAGE_BUTTON
;
1116 wFrameWindowHideButton(wwin
->frame
, foo
);
1118 wwin
->frame
->child
= wwin
;
1119 wwin
->frame
->workspace
= workspace
;
1120 wwin
->frame
->on_click_left
= windowIconifyClick
;
1122 #ifdef XKB_BUTTON_HINT
1123 if (wPreferences
.modelock
)
1124 wwin
->frame
->on_click_language
= windowLanguageClick
;
1127 wwin
->frame
->on_click_right
= windowCloseClick
;
1128 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1129 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1130 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1131 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1133 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1134 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1135 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1140 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1142 /* if gravity is to the south, account for the border sizes */
1144 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1148 * wWindowConfigure() will init the client window's size
1149 * (wwin->client.{width,height}) and all other geometry
1150 * related variables (frame_x,frame_y) */
1151 wWindowConfigure(wwin
, x
, y
, width
, height
);
1153 /* to make sure the window receives it's new position after reparenting */
1154 wWindowSynthConfigureNotify(wwin
);
1156 /* Setup descriptors and save window to internal lists */
1157 if (wwin
->main_window
!= None
) {
1161 /* Leader windows do not necessary set themselves as leaders.
1162 * If this is the case, point the leader of this window to
1164 leader
= wWindowFor(wwin
->main_window
);
1165 if (leader
&& leader
->main_window
== None
)
1166 leader
->main_window
= leader
->client_win
;
1168 app
= wApplicationCreate(wwin
);
1170 app
->last_workspace
= workspace
;
1172 /* Do application specific stuff, like setting application
1173 * wide attributes. */
1175 if (wwin
->flags
.hidden
) {
1176 /* if the window was set to hidden because it was hidden
1177 * in a previous incarnation and that state was restored */
1178 app
->flags
.hidden
= 1;
1179 } else if (app
->flags
.hidden
) {
1180 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1181 wwin
->flags
.hidden
= 1;
1183 wUnhideApplication(app
, False
, False
);
1191 /* setup the frame descriptor */
1192 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1193 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1194 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1196 /* don't let windows go away if we die */
1197 XAddToSaveSet(dpy
, window
);
1199 XLowerWindow(dpy
, window
);
1201 /* if window is in this workspace and should be mapped, then map it */
1202 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1203 && !wwin
->flags
.hidden
&& !withdraw
) {
1205 /* The following "if" is to avoid crashing of clients that expect
1206 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1207 * after the return from this function. */
1208 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1209 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1211 wClientSetState(wwin
, NormalState
, None
);
1213 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1214 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1216 * The brain damaged idiotic non-click to focus modes will
1217 * have trouble with this because:
1219 * 1. window is created and mapped by the client
1220 * 2. window is mapped by wmaker in small size
1221 * 3. window is animated to grow to normal size
1222 * 4. this function returns to normal event loop
1223 * 5. eventually, the EnterNotify event that would trigger
1224 * the window focusing (if the mouse is over that window)
1225 * will be processed by wmaker.
1226 * But since this event will be rather delayed
1227 * (step 3 has a large delay) the time when the event ocurred
1228 * and when it is processed, the client that owns that window
1229 * will reject the XSetInputFocus() for it.
1231 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1232 DoWindowBirth(wwin
);
1237 /* setup stacking descriptor */
1239 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1241 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1243 if (!scr
->focused_window
) {
1244 /* first window on the list */
1247 scr
->focused_window
= wwin
;
1251 /* add window at beginning of focus window list */
1252 tmp
= scr
->focused_window
;
1261 /* raise is set to true if we un-hid the app when this window was born.
1262 * we raise, else old windows of this app will be above this new one. */
1264 wRaiseFrame(wwin
->frame
->core
);
1266 /* Update name must come after WApplication stuff is done */
1267 wWindowUpdateName(wwin
, title
);
1273 /* Final preparations before window is ready to go */
1274 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1276 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1277 if (((transientOwner
&& transientOwner
->flags
.focused
)
1278 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1280 /* only auto_focus if on same screen as mouse
1281 * (and same head for xinerama mode)
1282 * TODO: make it an option */
1284 /*TODO add checking the head of the window, is it available? */
1285 short same_screen
= 0, same_head
= 1;
1291 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1292 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1295 if (same_screen
== 1 && same_head
== 1)
1296 wSetFocusTo(scr
, wwin
);
1299 wWindowResetMouseGrabs(wwin
);
1301 if (!WFLAGP(wwin
, no_bind_keys
))
1302 wWindowSetKeyGrabs(wwin
);
1304 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1305 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1307 /* Setup Notification Observers */
1308 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1310 /* Cleanup temporary stuff */
1312 wWindowDeleteSavedState(win_state
);
1314 /* If the window must be withdrawed, then do it now.
1315 * Must do some optimization, 'though */
1317 wwin
->flags
.mapped
= 0;
1318 wClientSetState(wwin
, WithdrawnState
, None
);
1319 wUnmanageWindow(wwin
, True
, False
);
1326 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1327 const char *title
, int x
, int y
, int width
, int height
)
1332 wwin
= wWindowCreate();
1334 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1336 wwin
->flags
.internal_window
= 1;
1338 WSETUFLAG(wwin
, omnipresent
, 1);
1339 WSETUFLAG(wwin
, no_shadeable
, 1);
1340 WSETUFLAG(wwin
, no_resizable
, 1);
1341 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1343 wwin
->focus_mode
= WFM_PASSIVE
;
1344 wwin
->client_win
= window
;
1345 wwin
->screen_ptr
= scr
;
1346 wwin
->transient_for
= owner
;
1349 wwin
->client
.width
= width
;
1350 wwin
->client
.height
= height
;
1351 wwin
->frame_x
= wwin
->client
.x
;
1352 wwin
->frame_y
= wwin
->client
.y
;
1354 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1355 foo
|= WFF_TITLEBAR
;
1356 #ifdef XKB_BUTTON_HINT
1357 foo
|= WFF_LANGUAGE_BUTTON
;
1360 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1361 wwin
->frame_x
, wwin
->frame_y
,
1363 &wPreferences
.window_title_clearance
,
1364 &wPreferences
.window_title_min_height
,
1365 &wPreferences
.window_title_max_height
,
1367 scr
->window_title_texture
,
1368 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1369 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1371 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1373 wwin
->frame
->flags
.is_client_window_frame
= 1;
1374 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1376 wFrameWindowChangeTitle(wwin
->frame
, title
);
1378 /* setup button images */
1379 wWindowUpdateButtonImages(wwin
);
1382 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1384 wwin
->frame
->child
= wwin
;
1385 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1387 #ifdef XKB_BUTTON_HINT
1388 if (wPreferences
.modelock
)
1389 wwin
->frame
->on_click_language
= windowLanguageClick
;
1392 wwin
->frame
->on_click_right
= windowCloseClick
;
1393 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1394 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1395 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1396 wwin
->client
.y
+= wwin
->frame
->top_width
;
1398 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1399 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1401 /* setup the frame descriptor */
1402 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1403 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1404 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1406 XLowerWindow(dpy
, window
);
1407 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1409 /* setup stacking descriptor */
1410 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1412 tmp
= wWindowFor(wwin
->transient_for
);
1414 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1416 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1419 if (!scr
->focused_window
) {
1420 /* first window on the list */
1423 scr
->focused_window
= wwin
;
1427 /* add window at beginning of focus window list */
1428 tmp
= scr
->focused_window
;
1436 if (wwin
->flags
.is_gnustep
== 0)
1437 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1439 /* if (wPreferences.auto_focus) */
1440 wSetFocusTo(scr
, wwin
);
1441 wWindowResetMouseGrabs(wwin
);
1442 wWindowSetKeyGrabs(wwin
);
1448 *----------------------------------------------------------------------
1450 * Removes the frame window from a window and destroys all data
1451 * related to it. The window will be reparented back to the root window
1452 * if restore is True.
1455 * Everything related to the window is destroyed and the window
1456 * is removed from the window lists. Focus is set to the previous on the
1458 *----------------------------------------------------------------------
1460 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1462 WCoreWindow
*frame
= wwin
->frame
->core
;
1463 WWindow
*owner
= NULL
;
1464 WWindow
*newFocusedWindow
= NULL
;
1466 WScreen
*scr
= wwin
->screen_ptr
;
1468 /* First close attribute editor window if open */
1469 if (wwin
->flags
.inspector_open
)
1470 wCloseInspectorForWindow(wwin
);
1472 /* Close window menu if it's open for this window */
1473 if (wwin
->flags
.menu_open_for_me
)
1474 CloseWindowMenu(scr
);
1477 if (!wwin
->flags
.internal_window
)
1478 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1480 /* If this is a leader window, we still need to listen for
1481 * DestroyNotify and PropertyNotify. */
1482 if (wApplicationOf(wwin
->client_win
))
1483 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1485 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1487 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1488 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1491 XUnmapWindow(dpy
, frame
->window
);
1493 XUnmapWindow(dpy
, wwin
->client_win
);
1495 /* deselect window */
1496 wSelectWindow(wwin
, False
);
1498 /* remove all pending events on window */
1499 /* I think this only matters for autoraise */
1500 if (wPreferences
.raise_delay
)
1501 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1505 /* reparent the window back to the root */
1507 wClientRestore(wwin
);
1509 if (wwin
->transient_for
!= scr
->root_win
) {
1510 owner
= wWindowFor(wwin
->transient_for
);
1512 if (!owner
->flags
.semi_focused
)
1515 owner
->flags
.semi_focused
= 0;
1519 wasFocused
= wwin
->flags
.focused
;
1521 /* remove from window focus list */
1522 if (!wwin
->prev
&& !wwin
->next
) {
1523 /* was the only window */
1524 scr
->focused_window
= NULL
;
1525 newFocusedWindow
= NULL
;
1530 wwin
->prev
->next
= wwin
->next
;
1533 wwin
->next
->prev
= wwin
->prev
;
1535 scr
->focused_window
= wwin
->prev
;
1536 scr
->focused_window
->next
= NULL
;
1539 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1541 /* if in click to focus mode and the window
1542 * was a transient, focus the owner window
1545 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1546 tmp
= wWindowFor(wwin
->transient_for
);
1547 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1551 /* otherwise, focus the next one in the focus list */
1553 tmp
= scr
->focused_window
;
1554 while (tmp
) { /* look for one in the window list first */
1555 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1556 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1560 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1561 tmp
= scr
->focused_window
;
1563 if (!WFLAGP(tmp
, no_focusable
)
1564 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1571 newFocusedWindow
= tmp
;
1573 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1578 /* This is to let the root window get the keyboard input
1579 * if Sloppy focus mode and no other window get focus.
1580 * This way keybindings will not freeze.
1583 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1584 tmp
= wWindowFor(win
);
1587 newFocusedWindow
= tmp
;
1589 newFocusedWindow
= NULL
;
1593 if (!wwin
->flags
.internal_window
)
1594 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1596 if (newFocusedWindow
!= owner
&& owner
) {
1597 if (wwin
->flags
.is_gnustep
== 0)
1598 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1600 wSetFocusTo(scr
, newFocusedWindow
);
1603 /* Close menu and unhighlight */
1604 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1605 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1606 if (oapp
&& oapp
!= napp
) {
1607 wAppMenuUnmap(oapp
->menu
);
1608 if (wPreferences
.highlight_active_app
)
1609 wApplicationDeactivate(oapp
);
1612 wNETCleanupFrameExtents(wwin
);
1614 wWindowDestroy(wwin
);
1618 void wWindowMap(WWindow
*wwin
)
1620 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1621 if (!wwin
->flags
.shaded
) {
1622 /* window will be remapped when getting MapNotify */
1623 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1624 XMapWindow(dpy
, wwin
->client_win
);
1625 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1627 wwin
->flags
.mapped
= 1;
1631 void wWindowUnmap(WWindow
*wwin
)
1633 wwin
->flags
.mapped
= 0;
1635 /* prevent window withdrawal when getting UnmapNotify */
1636 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1637 XUnmapWindow(dpy
, wwin
->client_win
);
1638 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1640 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1643 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1648 #ifdef KEEP_XKB_LOCK_STATUS
1649 if (wPreferences
.modelock
)
1650 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1651 #endif /* KEEP_XKB_LOCK_STATUS */
1653 wwin
->flags
.semi_focused
= 0;
1655 if (wwin
->flags
.is_gnustep
== 0)
1656 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1658 wwin
->flags
.focused
= 1;
1660 wWindowResetMouseGrabs(wwin
);
1662 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1664 if (owin
== wwin
|| !owin
)
1667 nowner
= wWindowFor(wwin
->transient_for
);
1669 /* new window is a transient for the old window */
1670 if (nowner
== owin
) {
1671 owin
->flags
.semi_focused
= 1;
1672 wWindowUnfocus(nowner
);
1676 oowner
= wWindowFor(owin
->transient_for
);
1678 /* new window is owner of old window */
1679 if (wwin
== oowner
) {
1680 wWindowUnfocus(owin
);
1685 wWindowUnfocus(owin
);
1689 /* new window has same owner of old window */
1690 if (oowner
== nowner
) {
1691 /* prevent unfocusing of owner */
1692 oowner
->flags
.semi_focused
= 0;
1693 wWindowUnfocus(owin
);
1694 oowner
->flags
.semi_focused
= 1;
1699 /* nowner != NULL && oowner != nowner */
1700 nowner
->flags
.semi_focused
= 1;
1701 wWindowUnfocus(nowner
);
1702 wWindowUnfocus(owin
);
1705 void wWindowUnfocus(WWindow
*wwin
)
1707 CloseWindowMenu(wwin
->screen_ptr
);
1709 if (wwin
->flags
.is_gnustep
== 0)
1710 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1712 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1714 owner
= wWindowFor(wwin
->transient_for
);
1715 if (owner
&& owner
->flags
.semi_focused
) {
1716 owner
->flags
.semi_focused
= 0;
1717 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1718 wWindowUnfocus(owner
);
1719 wFrameWindowPaint(owner
->frame
);
1723 wwin
->flags
.focused
= 0;
1724 wWindowResetMouseGrabs(wwin
);
1725 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1728 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1736 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1740 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1741 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1745 *----------------------------------------------------------------------
1747 * wWindowConstrainSize--
1748 * Constrains size for the client window, taking the maximal size,
1749 * window resize increments and other size hints into account.
1752 * The closest size to what was given that the client window can
1755 *----------------------------------------------------------------------
1757 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1759 int width
= (int)*nwidth
;
1760 int height
= (int)*nheight
;
1763 int minW
= 1, minH
= 1;
1764 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1765 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1766 int minAX
= -1, minAY
= -1;
1767 int maxAX
= -1, maxAY
= -1;
1771 if (wwin
->normal_hints
) {
1772 winc
= wwin
->normal_hints
->width_inc
;
1773 hinc
= wwin
->normal_hints
->height_inc
;
1774 minW
= wwin
->normal_hints
->min_width
;
1775 minH
= wwin
->normal_hints
->min_height
;
1776 maxW
= wwin
->normal_hints
->max_width
;
1777 maxH
= wwin
->normal_hints
->max_height
;
1778 if (wwin
->normal_hints
->flags
& PAspect
) {
1779 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1780 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1781 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1782 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1785 baseW
= wwin
->normal_hints
->base_width
;
1786 baseH
= wwin
->normal_hints
->base_height
;
1799 /* aspect ratio code borrowed from olwm */
1801 /* adjust max aspect ratio */
1802 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1803 if (maxAX
> maxAY
) {
1804 height
= (width
* maxAY
) / maxAX
;
1805 if (height
> maxH
) {
1807 width
= (height
* maxAX
) / maxAY
;
1810 width
= (height
* maxAX
) / maxAY
;
1813 height
= (width
* maxAY
) / maxAX
;
1818 /* adjust min aspect ratio */
1819 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1820 if (minAX
> minAY
) {
1821 height
= (width
* minAY
) / minAX
;
1822 if (height
< minH
) {
1824 width
= (height
* minAX
) / minAY
;
1827 width
= (height
* minAX
) / minAY
;
1830 height
= (width
* minAY
) / minAX
;
1837 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1839 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1842 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1844 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1846 /* broken stupid apps may cause preposterous values for these.. */
1853 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1854 unsigned int *width
, unsigned int *height
)
1856 int baseW
= 0, baseH
= 0;
1857 int winc
= 1, hinc
= 1;
1859 if (wwin
->normal_hints
) {
1860 baseW
= wwin
->normal_hints
->base_width
;
1861 baseH
= wwin
->normal_hints
->base_height
;
1863 winc
= wwin
->normal_hints
->width_inc
;
1864 hinc
= wwin
->normal_hints
->height_inc
;
1868 *width
= maxW
- (maxW
- baseW
) % winc
;
1871 *height
= maxH
- (maxH
- baseH
) % hinc
;
1874 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1876 WScreen
*scr
= wwin
->screen_ptr
;
1880 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1883 if (workspace
!= scr
->current_workspace
) {
1884 /* Sent to other workspace. Unmap window */
1885 if ((wwin
->flags
.mapped
1886 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1887 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1889 wapp
= wApplicationOf(wwin
->main_window
);
1891 wapp
->last_workspace
= workspace
;
1893 if (wwin
->flags
.miniaturized
) {
1895 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1896 wwin
->icon
->mapped
= 0;
1900 wSetFocusTo(scr
, NULL
);
1904 /* brought to current workspace. Map window */
1905 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1907 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1908 wwin
->icon
->mapped
= 1;
1910 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1914 if (!IS_OMNIPRESENT(wwin
)) {
1915 int oldWorkspace
= wwin
->frame
->workspace
;
1916 wwin
->frame
->workspace
= workspace
;
1917 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1924 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
1926 WScreen
*scr
= wwin
->screen_ptr
;
1927 int w
= scr
->current_workspace
+ amount
;
1931 wWindowChangeWorkspace(wwin
, w
);
1932 } else if (wPreferences
.ws_cycle
) {
1933 wWindowChangeWorkspace(wwin
, scr
->workspace_count
+ w
);
1935 } else if (amount
> 0) {
1936 if (w
< scr
->workspace_count
) {
1937 wWindowChangeWorkspace(wwin
, w
);
1938 } else if (wPreferences
.ws_advance
) {
1939 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
1940 wWorkspaceMake(scr
, workspace
);
1941 wWindowChangeWorkspace(wwin
, workspace
);
1942 } else if (wPreferences
.ws_cycle
) {
1943 wWindowChangeWorkspace(wwin
, w
% scr
->workspace_count
);
1948 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1952 sevent
.type
= ConfigureNotify
;
1953 sevent
.xconfigure
.display
= dpy
;
1954 sevent
.xconfigure
.event
= wwin
->client_win
;
1955 sevent
.xconfigure
.window
= wwin
->client_win
;
1957 sevent
.xconfigure
.x
= wwin
->client
.x
;
1958 sevent
.xconfigure
.y
= wwin
->client
.y
;
1959 sevent
.xconfigure
.width
= wwin
->client
.width
;
1960 sevent
.xconfigure
.height
= wwin
->client
.height
;
1962 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1963 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1964 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1966 sevent
.xconfigure
.above
= None
;
1968 sevent
.xconfigure
.override_redirect
= False
;
1969 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1974 *----------------------------------------------------------------------
1975 * wWindowConfigure()
1977 * req_x, req_y: new requested positions for the frame
1978 * req_width, req_height: new requested sizes for the client
1980 * Configures the frame, decorations and client window to the specified
1981 * geometry, whose validity is not checked -- wWindowConstrainSize()
1982 * must be used for that.
1983 * The size parameters are for the client window, but the position is
1985 * The client window receives a ConfigureNotify event, according
1986 * to what ICCCM says.
1992 * Window size and position are changed and client window receives
1993 * a ConfigureNotify event.
1994 *----------------------------------------------------------------------
1996 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1998 int synth_notify
= False
;
2001 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2003 * if the window is being moved but not resized then
2004 * send a synthetic ConfigureNotify
2006 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
2007 synth_notify
= True
;
2009 if (WFLAGP(wwin
, dont_move_off
))
2010 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2013 if (req_width
< MIN_WINDOW_SIZE
)
2014 req_width
= MIN_WINDOW_SIZE
;
2015 if (req_height
< MIN_WINDOW_SIZE
)
2016 req_height
= MIN_WINDOW_SIZE
;
2018 /* If growing, resize inner part before frame,
2019 * if shrinking, resize frame before.
2020 * This will prevent the frame (that can have a different color)
2021 * to be exposed, causing flicker */
2022 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2023 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2025 if (wwin
->flags
.shaded
) {
2026 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2027 wwin
->old_geometry
.height
= req_height
;
2031 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2033 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2036 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2037 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2039 wwin
->client
.x
= req_x
;
2040 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2041 wwin
->client
.width
= req_width
;
2042 wwin
->client
.height
= req_height
;
2044 wwin
->client
.x
= req_x
;
2045 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2047 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2049 wwin
->frame_x
= req_x
;
2050 wwin
->frame_y
= req_y
;
2051 if (HAS_BORDER(wwin
)) {
2052 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2053 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2056 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2057 wWindowSetShape(wwin
);
2061 wWindowSynthConfigureNotify(wwin
);
2063 wNETFrameExtents(wwin
);
2068 /* req_x, req_y: new position of the frame */
2069 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2071 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2072 int synth_notify
= False
;
2074 /* Send a synthetic ConfigureNotify event for every window movement. */
2075 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2076 synth_notify
= True
;
2078 /* A single synthetic ConfigureNotify event is sent at the end of
2079 * a completed (opaque) movement in moveres.c */
2082 if (WFLAGP(wwin
, dont_move_off
))
2083 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2084 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2086 wwin
->client
.x
= req_x
;
2087 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2088 if (HAS_BORDER(wwin
)) {
2089 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2090 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2093 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2095 wwin
->frame_x
= req_x
;
2096 wwin
->frame_y
= req_y
;
2098 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2100 wWindowSynthConfigureNotify(wwin
);
2104 void wWindowUpdateButtonImages(WWindow
*wwin
)
2106 WScreen
*scr
= wwin
->screen_ptr
;
2107 Pixmap pixmap
, mask
;
2108 WFrameWindow
*fwin
= wwin
->frame
;
2110 if (!HAS_TITLEBAR(wwin
))
2113 /* miniaturize button */
2114 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2115 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2116 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2118 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2119 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2123 if (fwin
->lbutton_image
2124 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2125 wPixmapDestroy(fwin
->lbutton_image
);
2126 fwin
->lbutton_image
= NULL
;
2129 if (!fwin
->lbutton_image
) {
2130 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2131 fwin
->lbutton_image
->client_owned
= 1;
2132 fwin
->lbutton_image
->client_owned_mask
= 1;
2135 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2136 wPixmapDestroy(fwin
->lbutton_image
);
2138 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2141 #ifdef XKB_BUTTON_HINT
2142 if (!WFLAGP(wwin
, no_language_button
)) {
2143 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2144 wPixmapDestroy(fwin
->languagebutton_image
);
2146 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2152 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2153 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2155 if (!WFLAGP(wwin
, no_close_button
)) {
2156 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2157 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2159 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2160 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2164 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2165 || fwin
->rbutton_image
->mask
!= mask
)) {
2166 wPixmapDestroy(fwin
->rbutton_image
);
2167 fwin
->rbutton_image
= NULL
;
2170 if (!fwin
->rbutton_image
) {
2171 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2172 fwin
->rbutton_image
->client_owned
= 1;
2173 fwin
->rbutton_image
->client_owned_mask
= 1;
2176 } else if (WFLAGP(wwin
, kill_close
)) {
2177 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2178 wPixmapDestroy(fwin
->rbutton_image
);
2180 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2182 } else if (MGFLAGP(wwin
, broken_close
)) {
2183 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2184 wPixmapDestroy(fwin
->rbutton_image
);
2186 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2189 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2190 wPixmapDestroy(fwin
->rbutton_image
);
2192 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2196 /* force buttons to be redrawn */
2197 fwin
->flags
.need_texture_change
= 1;
2198 wFrameWindowPaint(fwin
);
2202 *---------------------------------------------------------------------------
2203 * wWindowConfigureBorders--
2204 * Update window border configuration according to attribute flags.
2206 *---------------------------------------------------------------------------
2208 void wWindowConfigureBorders(WWindow
*wwin
)
2214 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2216 #ifdef XKB_BUTTON_HINT
2217 if (wPreferences
.modelock
)
2218 flags
|= WFF_LANGUAGE_BUTTON
;
2221 if (HAS_TITLEBAR(wwin
))
2222 flags
|= WFF_TITLEBAR
;
2223 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2224 flags
|= WFF_RESIZEBAR
;
2225 if (HAS_BORDER(wwin
))
2226 flags
|= WFF_BORDER
;
2227 if (wwin
->flags
.shaded
)
2228 flags
|= WFF_IS_SHADED
;
2229 if (wwin
->flags
.selected
)
2230 flags
|= WFF_SELECTED
;
2232 oldh
= wwin
->frame
->top_width
;
2233 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2234 if (oldh
!= wwin
->frame
->top_width
) {
2235 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2237 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2238 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2242 if (!WFLAGP(wwin
, no_miniaturize_button
)
2243 && wwin
->frame
->flags
.hide_left_button
)
2244 flags
|= WFF_LEFT_BUTTON
;
2246 #ifdef XKB_BUTTON_HINT
2247 if (!WFLAGP(wwin
, no_language_button
)
2248 && wwin
->frame
->flags
.hide_language_button
)
2249 flags
|= WFF_LANGUAGE_BUTTON
;
2252 if (!WFLAGP(wwin
, no_close_button
)
2253 && wwin
->frame
->flags
.hide_right_button
)
2254 flags
|= WFF_RIGHT_BUTTON
;
2257 wWindowUpdateButtonImages(wwin
);
2258 wFrameWindowShowButton(wwin
->frame
, flags
);
2262 if (WFLAGP(wwin
, no_miniaturize_button
)
2263 && !wwin
->frame
->flags
.hide_left_button
)
2264 flags
|= WFF_LEFT_BUTTON
;
2266 #ifdef XKB_BUTTON_HINT
2267 if (WFLAGP(wwin
, no_language_button
)
2268 && !wwin
->frame
->flags
.hide_language_button
)
2269 flags
|= WFF_LANGUAGE_BUTTON
;
2272 if (WFLAGP(wwin
, no_close_button
)
2273 && !wwin
->frame
->flags
.hide_right_button
)
2274 flags
|= WFF_RIGHT_BUTTON
;
2277 wFrameWindowHideButton(wwin
->frame
, flags
);
2280 if (wShapeSupported
&& wwin
->flags
.shaped
)
2281 wWindowSetShape(wwin
);
2286 void wWindowSaveState(WWindow
* wwin
)
2291 memset(data
, 0, sizeof(long) * 10);
2292 data
[0] = wwin
->frame
->workspace
;
2293 data
[1] = wwin
->flags
.miniaturized
;
2294 data
[2] = wwin
->flags
.shaded
;
2295 data
[3] = wwin
->flags
.hidden
;
2296 data
[4] = wwin
->flags
.maximized
;
2297 if (wwin
->flags
.maximized
== 0) {
2298 data
[5] = wwin
->frame_x
;
2299 data
[6] = wwin
->frame_y
;
2300 data
[7] = wwin
->frame
->core
->width
;
2301 data
[8] = wwin
->frame
->core
->height
;
2303 data
[5] = wwin
->old_geometry
.x
;
2304 data
[6] = wwin
->old_geometry
.y
;
2305 data
[7] = wwin
->old_geometry
.width
;
2306 data
[8] = wwin
->old_geometry
.height
;
2309 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2310 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2311 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2314 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2315 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2318 static int getSavedState(Window window
, WSavedState
** state
)
2322 unsigned long nitems_ret
;
2323 unsigned long bytes_after_ret
;
2326 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2327 True
, _XA_WINDOWMAKER_STATE
,
2328 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2329 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2332 *state
= wmalloc(sizeof(WSavedState
));
2334 (*state
)->workspace
= data
[0];
2335 (*state
)->miniaturized
= data
[1];
2336 (*state
)->shaded
= data
[2];
2337 (*state
)->hidden
= data
[3];
2338 (*state
)->maximized
= data
[4];
2339 (*state
)->x
= data
[5];
2340 (*state
)->y
= data
[6];
2341 (*state
)->w
= data
[7];
2342 (*state
)->h
= data
[8];
2343 (*state
)->window_shortcuts
= data
[9];
2347 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2354 void wWindowClearShape(WWindow
* wwin
)
2356 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2357 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2361 void wWindowSetShape(WWindow
* wwin
)
2365 #ifdef OPTIMIZE_SHAPE
2370 /* only shape is the client's */
2371 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2374 /* Get array of rectangles describing the shape mask */
2375 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2379 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2385 /* insert our decoration rectangles in the rect list */
2386 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2389 if (HAS_TITLEBAR(wwin
)) {
2391 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2392 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2393 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2396 if (HAS_RESIZEBAR(wwin
)) {
2398 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2399 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2400 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2404 /* shape our frame window */
2405 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2406 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2412 #endif /* OPTIMIZE_SHAPE */
2414 if (HAS_TITLEBAR(wwin
)) {
2417 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2418 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2421 if (HAS_RESIZEBAR(wwin
)) {
2423 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2424 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2425 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2429 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2430 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2432 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2433 0, wwin
->frame
->top_width
, wwin
->client_win
,
2434 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2439 /* ====================================================================== */
2441 static FocusMode
getFocusMode(WWindow
* wwin
)
2445 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2446 if (wwin
->wm_hints
->input
== True
) {
2447 if (wwin
->protocols
.TAKE_FOCUS
)
2448 mode
= WFM_LOCALLY_ACTIVE
;
2452 if (wwin
->protocols
.TAKE_FOCUS
)
2453 mode
= WFM_GLOBALLY_ACTIVE
;
2455 mode
= WFM_NO_INPUT
;
2463 void wWindowSetKeyGrabs(WWindow
* wwin
)
2468 for (i
= 0; i
< WKBD_LAST
; i
++) {
2469 key
= &wKeyBindings
[i
];
2471 if (key
->keycode
== 0)
2473 if (key
->modifier
!= AnyModifier
) {
2474 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2475 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2477 /* Also grab all modifier combinations possible that include,
2478 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2479 * work even if the NumLock/ScrollLock key is on.
2481 wHackedGrabKey(key
->keycode
, key
->modifier
,
2482 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2485 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2486 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2489 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2492 void wWindowResetMouseGrabs(WWindow
* wwin
)
2494 /* Mouse grabs can't be done on the client window because of
2495 * ICCCM and because clients that try to do the same will crash.
2497 * But there is a problem wich makes tbar buttons of unfocused
2498 * windows not usable as the click goes to the frame window instead
2499 * of the button itself. Must figure a way to fix that.
2502 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2504 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2505 /* grabs for Meta+drag */
2506 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2507 True
, ButtonPressMask
| ButtonReleaseMask
,
2508 GrabModeSync
, GrabModeAsync
, None
, None
);
2510 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2511 * but we only grab it for Button4 and Button 5 since a lot of apps
2512 * use CTRL+Button1-3 for app related functionality
2514 if (wPreferences
.resize_increment
> 0) {
2515 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2516 True
, ButtonPressMask
| ButtonReleaseMask
,
2517 GrabModeSync
, GrabModeAsync
, None
, None
);
2518 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2519 True
, ButtonPressMask
| ButtonReleaseMask
,
2520 GrabModeSync
, GrabModeAsync
, None
, None
);
2522 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2523 True
, ButtonPressMask
| ButtonReleaseMask
,
2524 GrabModeSync
, GrabModeAsync
, None
, None
);
2525 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2526 True
, ButtonPressMask
| ButtonReleaseMask
,
2527 GrabModeSync
, GrabModeAsync
, None
, None
);
2531 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2532 && !wwin
->flags
.is_gnustep
) {
2533 /* the passive grabs to focus the window */
2534 /* if (wPreferences.focus_mode == WKF_CLICK) */
2535 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2536 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2541 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2543 if (attr
->flags
& GSExtraFlagsAttr
) {
2544 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2545 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2546 wWindowUpdateButtonImages(wwin
);
2551 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2552 const char *command
, pid_t pid
, WSavedState
* state
)
2554 WWindowState
*wstate
;
2556 wstate
= malloc(sizeof(WWindowState
));
2560 memset(wstate
, 0, sizeof(WWindowState
));
2563 wstate
->instance
= wstrdup(instance
);
2565 wstate
->class = wstrdup(class);
2567 wstate
->command
= wstrdup(command
);
2568 wstate
->state
= state
;
2570 wstate
->next
= windowState
;
2571 windowState
= wstate
;
2576 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2578 WMagicNumber
wWindowGetSavedState(Window win
)
2580 char *instance
, *class, *command
= NULL
;
2581 WWindowState
*wstate
= windowState
;
2586 command
= GetCommandForWindow(win
);
2590 if (PropGetWMClass(win
, &class, &instance
)) {
2592 if (SAME(instance
, wstate
->instance
) &&
2593 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2596 wstate
= wstate
->next
;
2612 void wWindowDeleteSavedState(WMagicNumber id
)
2614 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2616 if (!wstate
|| !windowState
)
2620 if (tmp
== wstate
) {
2621 windowState
= wstate
->next
;
2622 release_wwindowstate(wstate
);
2625 if (tmp
->next
== wstate
) {
2626 tmp
->next
= wstate
->next
;
2627 release_wwindowstate(wstate
);
2635 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2637 WWindowState
*tmp
, *wstate
;
2643 if (tmp
->pid
== pid
) {
2644 wstate
= windowState
;
2645 windowState
= tmp
->next
;
2647 release_wwindowstate(wstate
);
2650 if (tmp
->next
->pid
== pid
) {
2652 tmp
->next
= wstate
->next
;
2653 release_wwindowstate(wstate
);
2661 static void release_wwindowstate(WWindowState
*wstate
)
2663 if (wstate
->instance
)
2664 wfree(wstate
->instance
);
2667 wfree(wstate
->class);
2669 if (wstate
->command
)
2670 wfree(wstate
->command
);
2672 wfree(wstate
->state
);
2676 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2678 if (wwin
->flags
.omnipresent
== flag
)
2681 wwin
->flags
.omnipresent
= flag
;
2682 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2685 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2687 WWindow
*wwin
= data
;
2689 #ifndef NUMLOCK_HACK
2690 if ((event
->xbutton
.state
& ValidModMask
)
2691 != (event
->xbutton
.state
& ~LockMask
)) {
2692 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2693 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2697 event
->xbutton
.state
&= ValidModMask
;
2699 CloseWindowMenu(wwin
->screen_ptr
);
2701 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2702 && !WFLAGP(wwin
, no_focusable
)) {
2703 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2706 if (event
->xbutton
.button
== Button1
)
2707 wRaiseFrame(wwin
->frame
->core
);
2709 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2710 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2711 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2712 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2717 if (event
->xbutton
.state
& MOD_MASK
) {
2718 /* move the window */
2719 wMouseMoveWindow(wwin
, event
);
2720 XUngrabPointer(dpy
, CurrentTime
);
2722 wMouseResizeWindow(wwin
, event
);
2723 XUngrabPointer(dpy
, CurrentTime
);
2727 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2729 WWindow
*wwin
= data
;
2731 event
->xbutton
.state
&= ValidModMask
;
2733 if (event
->xbutton
.button
== Button1
) {
2734 if (event
->xbutton
.state
== 0) {
2735 if (!WFLAGP(wwin
, no_shadeable
)) {
2737 if (wwin
->flags
.shaded
)
2738 wUnshadeWindow(wwin
);
2745 if (event
->xbutton
.state
& ControlMask
)
2746 dir
|= MAX_VERTICAL
;
2748 if (event
->xbutton
.state
& ShiftMask
) {
2749 dir
|= MAX_HORIZONTAL
;
2750 if (!(event
->xbutton
.state
& ControlMask
))
2751 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2754 /* maximize window */
2755 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2756 int ndir
= dir
^ wwin
->flags
.maximized
;
2759 wMaximizeWindow(wwin
, ndir
);
2761 wUnmaximizeWindow(wwin
);
2764 } else if (event
->xbutton
.button
== Button3
) {
2765 if (event
->xbutton
.state
& MOD_MASK
)
2766 wHideOtherApplications(wwin
);
2767 } else if (event
->xbutton
.button
== Button2
) {
2768 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2769 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2771 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2772 wUnshadeWindow(wwin
);
2776 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2778 WWindow
*wwin
= desc
->parent
;
2779 unsigned int new_width
, w_scale
;
2780 unsigned int new_height
, h_scale
;
2781 unsigned int resize_width_increment
= 0;
2782 unsigned int resize_height_increment
= 0;
2784 if (wwin
->normal_hints
) {
2785 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2786 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2787 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2788 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2790 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2791 resize_width_increment
= wPreferences
.resize_increment
;
2792 resize_height_increment
= wPreferences
.resize_increment
;
2795 event
->xbutton
.state
&= ValidModMask
;
2797 CloseWindowMenu(wwin
->screen_ptr
);
2799 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2800 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2802 if (event
->xbutton
.button
== Button1
)
2803 wRaiseFrame(wwin
->frame
->core
);
2805 if (event
->xbutton
.state
& ControlMask
) {
2806 if (event
->xbutton
.button
== Button4
) {
2807 new_width
= wwin
->client
.width
- resize_width_increment
;
2808 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2809 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2811 if (event
->xbutton
.button
== Button5
) {
2812 new_width
= wwin
->client
.width
+ resize_width_increment
;
2813 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2814 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2818 if (event
->xbutton
.state
& MOD_MASK
) {
2819 /* move the window */
2820 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2821 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2822 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2825 if (event
->xbutton
.button
== Button3
) {
2826 wMouseResizeWindow(wwin
, event
);
2827 } else if (event
->xbutton
.button
== Button4
) {
2828 new_height
= wwin
->client
.height
- resize_height_increment
;
2829 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2830 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2831 } else if (event
->xbutton
.button
== Button5
) {
2832 new_height
= wwin
->client
.height
+ resize_height_increment
;
2833 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2834 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2835 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2836 wMouseMoveWindow(wwin
, event
);
2838 XUngrabPointer(dpy
, CurrentTime
);
2842 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2844 WWindow
*wwin
= (WWindow
*) data
;
2846 #ifndef NUMLOCK_HACK
2847 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2848 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2849 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2851 event
->xbutton
.state
&= ValidModMask
;
2853 CloseWindowMenu(wwin
->screen_ptr
);
2855 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2856 && !WFLAGP(wwin
, no_focusable
))
2857 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2859 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2861 if (event
->xbutton
.button
== Button1
) {
2862 if (event
->xbutton
.state
& MOD_MASK
)
2863 wLowerFrame(wwin
->frame
->core
);
2865 wRaiseFrame(wwin
->frame
->core
);
2867 if ((event
->xbutton
.state
& ShiftMask
)
2868 && !(event
->xbutton
.state
& ControlMask
)) {
2869 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2872 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2873 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2874 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2875 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2879 /* move the window */
2880 wMouseMoveWindow(wwin
, event
);
2882 XUngrabPointer(dpy
, CurrentTime
);
2883 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2884 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2885 WObjDescriptor
*desc
;
2887 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2888 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2889 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2890 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2894 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2896 /* allow drag select */
2897 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2898 event
->xany
.send_event
= True
;
2899 (*desc
->handle_mousedown
) (desc
, event
);
2901 XUngrabPointer(dpy
, CurrentTime
);
2905 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2907 WWindow
*wwin
= data
;
2909 event
->xbutton
.state
&= ValidModMask
;
2911 CloseWindowMenu(wwin
->screen_ptr
);
2913 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2916 /* if control-click, kill the client */
2917 if (event
->xbutton
.state
& ControlMask
) {
2920 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2921 /* send delete message */
2922 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2927 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2929 WWindow
*wwin
= data
;
2931 CloseWindowMenu(wwin
->screen_ptr
);
2933 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2936 /* send delete message */
2937 if (wwin
->protocols
.DELETE_WINDOW
)
2938 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2943 #ifdef XKB_BUTTON_HINT
2944 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2946 WWindow
*wwin
= data
;
2947 WFrameWindow
*fwin
= wwin
->frame
;
2948 WScreen
*scr
= fwin
->screen_ptr
;
2951 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2953 tl
= wwin
->frame
->languagemode
;
2954 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2955 wwin
->frame
->last_languagemode
= tl
;
2956 wSetFocusTo(scr
, wwin
);
2957 wwin
->frame
->languagebutton_image
=
2958 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2959 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2960 if (event
->xbutton
.button
== Button3
)
2962 wRaiseFrame(fwin
->core
);
2966 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2968 WWindow
*wwin
= data
;
2970 event
->xbutton
.state
&= ValidModMask
;
2972 CloseWindowMenu(wwin
->screen_ptr
);
2974 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2977 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2978 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
2981 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2983 wapp
= wApplicationOf(wwin
->main_window
);
2984 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2985 wHideApplication(wapp
);
2986 } else if (event
->xbutton
.state
== 0) {
2987 wIconifyWindow(wwin
);