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
76 /***** Local Stuff *****/
77 static WWindowState
*windowState
= NULL
;
78 static FocusMode
getFocusMode(WWindow
*wwin
);
79 static int getSavedState(Window window
, WSavedState
**state
);
80 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
82 /* frame window (during window grabs) */
83 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
86 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
87 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
90 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
92 #ifdef XKB_BUTTON_HINT
93 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
96 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
97 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
98 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
100 static void release_wwindowstate(WWindowState
*wstate
);
102 /****** Notification Observers ******/
104 static void appearanceObserver(void *self
, WMNotification
* notif
)
106 WWindow
*wwin
= (WWindow
*) self
;
107 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
109 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
112 if (flags
& WFontSettings
) {
113 wWindowConfigureBorders(wwin
);
114 if (wwin
->flags
.shaded
) {
115 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
116 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
117 wWindowSynthConfigureNotify(wwin
);
120 if (flags
& WTextureSettings
)
121 wwin
->frame
->flags
.need_texture_remake
= 1;
123 if (flags
& (WTextureSettings
| WColorSettings
)) {
124 if (wwin
->frame
->titlebar
)
125 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
127 wFrameWindowPaint(wwin
->frame
);
132 /* Return the WWindow associated with a given (Xlib) Window. */
133 WWindow
*wWindowFor(Window window
)
135 WObjDescriptor
*desc
;
140 if (XFindContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
*) & desc
) == XCNOENT
)
143 if (desc
->parent_type
== WCLASS_WINDOW
)
145 else if (desc
->parent_type
== WCLASS_FRAME
) {
146 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
147 if (frame
->flags
.is_client_window_frame
)
154 WWindow
*wWindowCreate(void)
158 wwin
= wmalloc(sizeof(WWindow
));
161 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
162 wwin
->client_descriptor
.parent
= wwin
;
163 wwin
->client_descriptor
.self
= wwin
;
164 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
169 void wWindowDestroy(WWindow
*wwin
)
173 if (wwin
->screen_ptr
->cmap_window
== wwin
)
174 wwin
->screen_ptr
->cmap_window
= NULL
;
176 WMRemoveNotificationObserver(wwin
);
178 wwin
->flags
.destroyed
= 1;
180 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
181 if (!w_global
.shortcut
.windows
[i
])
184 WMRemoveFromArray(w_global
.shortcut
.windows
[i
], wwin
);
186 if (!WMGetArrayItemCount(w_global
.shortcut
.windows
[i
])) {
187 WMFreeArray(w_global
.shortcut
.windows
[i
]);
188 w_global
.shortcut
.windows
[i
] = NULL
;
192 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
193 wwin
->fake_group
->retainCount
--;
194 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
195 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
196 wwin
->fake_group
->leader
= None
;
197 wwin
->fake_group
->origLeader
= None
;
202 if (wwin
->normal_hints
)
203 XFree(wwin
->normal_hints
);
206 XFree(wwin
->wm_hints
);
208 if (wwin
->wm_instance
)
209 XFree(wwin
->wm_instance
);
212 XFree(wwin
->wm_class
);
214 if (wwin
->wm_gnustep_attr
)
215 wfree(wwin
->wm_gnustep_attr
);
217 if (wwin
->cmap_windows
)
218 XFree(wwin
->cmap_windows
);
220 XDeleteContext(dpy
, wwin
->client_win
, w_global
.context
.client_win
);
223 wFrameWindowDestroy(wwin
->frame
);
226 RemoveFromStackList(wwin
->icon
->core
);
227 wIconDestroy(wwin
->icon
);
228 if (wPreferences
.auto_arrange_icons
)
229 wArrangeIcons(wwin
->screen_ptr
, True
);
231 if (wwin
->net_icon_image
)
232 RReleaseImage(wwin
->net_icon_image
);
237 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
239 if (gs_hints
->flags
& GSWindowStyleAttr
) {
240 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
241 wwin
->client_flags
.no_border
= 1;
242 wwin
->client_flags
.no_titlebar
= 1;
243 wwin
->client_flags
.no_closable
= 1;
244 wwin
->client_flags
.no_miniaturizable
= 1;
245 wwin
->client_flags
.no_resizable
= 1;
246 wwin
->client_flags
.no_close_button
= 1;
247 wwin
->client_flags
.no_miniaturize_button
= 1;
248 wwin
->client_flags
.no_resizebar
= 1;
250 wwin
->client_flags
.no_close_button
=
251 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
253 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
255 wwin
->client_flags
.no_miniaturize_button
=
256 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
258 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
260 wwin
->client_flags
.no_resizebar
=
261 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
263 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
265 /* these attributes supposedly imply in the existence
267 if (gs_hints
->window_style
& (WMResizableWindowMask
|
268 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
269 wwin
->client_flags
.no_titlebar
= 0;
271 wwin
->client_flags
.no_titlebar
=
272 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
277 /* setup the defaults */
278 wwin
->client_flags
.no_border
= 0;
279 wwin
->client_flags
.no_titlebar
= 0;
280 wwin
->client_flags
.no_closable
= 0;
281 wwin
->client_flags
.no_miniaturizable
= 0;
282 wwin
->client_flags
.no_resizable
= 0;
283 wwin
->client_flags
.no_close_button
= 0;
284 wwin
->client_flags
.no_miniaturize_button
= 0;
285 wwin
->client_flags
.no_resizebar
= 0;
287 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
288 wwin
->client_flags
.no_appicon
= 1;
291 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
293 WScreen
*scr
= wwin
->screen_ptr
;
295 /* sets global default stuff */
296 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
298 * Decoration setting is done in this precedence (lower to higher)
299 * - use global default in the resource database
300 * - guess some settings
301 * - use GNUstep/external window attributes
302 * - set hints specified for the app in the resource DB
305 WSETUFLAG(wwin
, broken_close
, 0);
307 if (wwin
->protocols
.DELETE_WINDOW
)
308 WSETUFLAG(wwin
, kill_close
, 0);
310 WSETUFLAG(wwin
, kill_close
, 1);
312 /* transients can't be iconified or maximized */
313 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
314 WSETUFLAG(wwin
, no_miniaturizable
, 1);
315 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
318 /* if the window can't be resized, remove the resizebar */
319 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
320 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
321 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
322 WSETUFLAG(wwin
, no_resizable
, 1);
323 WSETUFLAG(wwin
, no_resizebar
, 1);
326 /* set GNUstep window attributes */
327 if (wwin
->wm_gnustep_attr
) {
328 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
330 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
332 *level
= wwin
->wm_gnustep_attr
->window_level
;
334 * INT_MIN is the only illegal window level.
336 if (*level
== INT_MIN
)
337 *level
= INT_MIN
+ 1;
340 *level
= WMNormalLevel
;
343 int tmp_workspace
= -1;
344 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
347 wMWMCheckClientHints(wwin
);
348 #endif /* MWM_HINTS */
350 wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
352 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
353 * have INT_MIN that means that no window level was requested. -Dan
355 if (tmp_level
== INT_MIN
) {
356 if (WFLAGP(wwin
, floating
))
357 *level
= WMFloatingLevel
;
358 else if (WFLAGP(wwin
, sunken
))
359 *level
= WMSunkenLevel
;
361 *level
= WMNormalLevel
;
366 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
367 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
368 if (transientOwner
) {
369 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
370 if (ownerLevel
> *level
)
375 if (tmp_workspace
>= 0)
376 *workspace
= tmp_workspace
% w_global
.workspace
.count
;
380 * Set attributes specified only for that window/class.
381 * This might do duplicate work with the 1st wDefaultFillAttributes().
383 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
384 &wwin
->defined_user_flags
, False
);
386 * Sanity checks for attributes that depend on other attributes
388 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
389 wwin
->user_flags
.emulate_appicon
= 0;
391 if (wwin
->main_window
!= None
) {
392 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
393 if (wapp
&& !wapp
->flags
.emulated
)
394 wwin
->user_flags
.emulate_appicon
= 0;
397 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
398 wwin
->user_flags
.emulate_appicon
= 0;
400 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
401 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
402 wwin
->user_flags
.sunken
= 0;
404 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
406 /* windows that have takefocus=False shouldn't take focus at all */
407 if (wwin
->focus_mode
== WFM_NO_INPUT
)
408 wwin
->client_flags
.no_focusable
= 1;
411 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
415 w1
= wwin
->frame
->core
->width
;
416 h1
= wwin
->frame
->core
->height
;
417 w2
= obscured
->frame
->core
->width
;
418 h2
= obscured
->frame
->core
->height
;
420 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
421 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
424 if (wwin
->frame_x
+ w1
< obscured
->frame_x
425 || wwin
->frame_y
+ h1
< obscured
->frame_y
426 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
432 static void fixLeaderProperties(WWindow
*wwin
)
434 XClassHint
*classHint
;
435 XWMHints
*hints
, *clientHints
;
436 XWindowAttributes attr
;
437 Window leaders
[2], window
;
438 char **argv
, *command
;
442 classHint
= XAllocClassHint();
443 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
444 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
446 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
450 leaders
[0] = wwin
->client_leader
;
451 leaders
[1] = wwin
->group_id
;
454 command
= GetCommandForWindow(wwin
->client_win
);
456 wfree(command
); /* command already set. nothing to do. */
458 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
461 for (i
= 0; i
< 2; i
++) {
464 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
465 classHint
->res_name
= wwin
->wm_instance
;
466 classHint
->res_class
= wwin
->wm_class
;
467 XSetClassHint(dpy
, window
, classHint
);
469 hints
= XGetWMHints(dpy
, window
);
472 } else if (clientHints
) {
473 /* set window group leader to self */
474 clientHints
->window_group
= window
;
475 clientHints
->flags
|= WindowGroupHint
;
476 XSetWMHints(dpy
, window
, clientHints
);
480 command
= GetCommandForWindow(window
);
482 wfree(command
); /* command already set. nothing to do. */
484 XSetCommand(dpy
, window
, argv
, argc
);
487 /* Make sure we get notification when this window is destroyed */
488 if (XGetWindowAttributes(dpy
, window
, &attr
))
489 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
500 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
502 XClassHint
*classHint
;
508 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
510 classHint
= XAllocClassHint();
511 classHint
->res_name
= instance
;
512 classHint
->res_class
= class;
513 XSetClassHint(dpy
, leader
, classHint
);
516 /* inherit these from the original leader if available */
517 hints
= XGetWMHints(dpy
, win
);
519 hints
= XAllocWMHints();
522 /* set window group leader to self */
523 hints
->window_group
= leader
;
524 hints
->flags
|= WindowGroupHint
;
525 XSetWMHints(dpy
, leader
, hints
);
528 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
529 XSetCommand(dpy
, leader
, argv
, argc
);
530 XFreeStringList(argv
);
536 static int matchIdentifier(const void *item
, const void *cdata
)
538 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
542 *----------------------------------------------------------------
544 * reparents the window and allocates a descriptor for it.
545 * Window manager hints and other hints are fetched to configure
546 * the window decoration attributes and others. User preferences
547 * for the window are used if available, to configure window
548 * decorations and some behaviour.
549 * If in startup, windows that are override redirect,
550 * unmapped and never were managed and are Withdrawn are not
554 * the new window descriptor
557 * The window is reparented and appropriate notification
558 * is done to the client. Input mask for the window is setup.
559 * The window descriptor is also associated with various window
560 * contexts and inserted in the head of the window list.
561 * Event handler contexts are associated for some objects
562 * (buttons, titlebar and resizebar)
564 *----------------------------------------------------------------
566 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
570 unsigned width
, height
;
571 XWindowAttributes wattribs
;
572 XSetWindowAttributes attribs
;
573 WWindowState
*win_state
;
574 WWindow
*transientOwner
= NULL
;
580 Bool withdraw
= False
;
587 /* make sure the window is still there */
588 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
593 /* if it's an override-redirect, ignore it */
594 if (wattribs
.override_redirect
) {
599 wm_state
= PropGetWindowState(window
);
601 /* if it's startup and the window is unmapped, don't manage it */
602 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
607 wwin
= wWindowCreate();
609 title
= wNETWMGetWindowName(window
);
611 wwin
->flags
.net_has_title
= 1;
612 else if (!wFetchName(dpy
, window
, &title
))
615 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
618 if (w_global
.xext
.shape
.supported
) {
623 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
624 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
625 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
626 wwin
->flags
.shaped
= b_shaped
;
630 /* Get hints and other information in properties */
631 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
633 /* setup descriptor */
634 wwin
->client_win
= window
;
635 wwin
->screen_ptr
= scr
;
636 wwin
->old_border_width
= wattribs
.border_width
;
637 wwin
->event_mask
= CLIENT_EVENTS
;
638 attribs
.event_mask
= CLIENT_EVENTS
;
639 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
640 attribs
.save_under
= False
;
642 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
643 XSetWindowBorderWidth(dpy
, window
, 0);
645 /* get hints from GNUstep app */
646 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
647 wwin
->flags
.is_gnustep
= 1;
649 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
650 wwin
->wm_gnustep_attr
= NULL
;
652 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
653 wwin
->flags
.is_dockapp
= 1;
657 wwin
->client_leader
= PropGetClientLeader(window
);
658 if (wwin
->client_leader
!= None
)
659 wwin
->main_window
= wwin
->client_leader
;
661 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
663 if (wwin
->wm_hints
) {
664 if (wwin
->wm_hints
->flags
& StateHint
) {
665 if (wwin
->wm_hints
->initial_state
== IconicState
) {
666 wwin
->flags
.miniaturized
= 1;
667 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
668 wwin
->flags
.is_dockapp
= 1;
673 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
674 wwin
->group_id
= wwin
->wm_hints
->window_group
;
675 /* window_group has priority over CLIENT_LEADER */
676 wwin
->main_window
= wwin
->group_id
;
678 wwin
->group_id
= None
;
681 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
682 wwin
->flags
.urgent
= 1;
683 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
686 wwin
->group_id
= None
;
689 PropGetProtocols(window
, &wwin
->protocols
);
691 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
692 wwin
->transient_for
= None
;
694 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
695 wwin
->transient_for
= scr
->root_win
;
697 transientOwner
= wWindowFor(wwin
->transient_for
);
698 if (transientOwner
&& transientOwner
->main_window
!= None
)
699 wwin
->main_window
= transientOwner
->main_window
;
703 /* guess the focus mode */
704 wwin
->focus_mode
= getFocusMode(wwin
);
706 /* get geometry stuff */
707 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
709 /* get colormap windows */
710 GetColormapWindows(wwin
);
713 * Setup the decoration/window attributes and
716 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
718 /* Make broken apps behave as a nice app. */
719 if (WFLAGP(wwin
, emulate_appicon
))
720 wwin
->main_window
= wwin
->client_win
;
722 fixLeaderProperties(wwin
);
724 wwin
->orig_main_window
= wwin
->main_window
;
726 if (wwin
->flags
.is_gnustep
)
727 WSETUFLAG(wwin
, shared_appicon
, 0);
729 if (wwin
->main_window
) {
730 XTextProperty text_prop
;
732 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, w_global
.atom
.wmaker
.menu
))
733 WSETUFLAG(wwin
, shared_appicon
, 0);
736 if (wwin
->flags
.is_dockapp
)
737 WSETUFLAG(wwin
, shared_appicon
, 0);
739 if (wwin
->main_window
) {
740 WApplication
*app
= wApplicationOf(wwin
->main_window
);
741 if (app
&& app
->app_icon
)
742 WSETUFLAG(wwin
, shared_appicon
, 0);
745 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
746 char *buffer
, *instance
, *class;
747 WFakeGroupLeader
*fPtr
;
750 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
752 /* // only enter here if PropGetWMClass() succeds */
753 PropGetWMClass(wwin
->main_window
, &class, &instance
);
754 buffer
= StrConcatDot(instance
, class);
756 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
757 if (index
!= WANotFound
) {
758 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
759 if (fPtr
->retainCount
== 0)
760 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
764 if (fPtr
->origLeader
== None
) {
765 if (ADEQUATE(wwin
->main_window
)) {
767 fPtr
->origLeader
= wwin
->main_window
;
770 wwin
->fake_group
= fPtr
;
771 wwin
->main_window
= fPtr
->leader
;
774 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
776 fPtr
->identifier
= buffer
;
777 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
778 fPtr
->origLeader
= None
;
779 fPtr
->retainCount
= 1;
781 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
783 if (ADEQUATE(wwin
->main_window
)) {
785 fPtr
->origLeader
= wwin
->main_window
;
787 wwin
->fake_group
= fPtr
;
788 wwin
->main_window
= fPtr
->leader
;
800 * Setup the initial state of the window
802 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
803 wwin
->flags
.miniaturized
= 1;
805 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
806 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
808 wNETWMCheckInitialClientState(wwin
);
810 /* apply previous state if it exists and we're in startup */
811 if (scr
->flags
.startup
&& wm_state
>= 0) {
812 if (wm_state
== IconicState
)
813 wwin
->flags
.miniaturized
= 1;
814 else if (wm_state
== WithdrawnState
)
818 /* if there is a saved state (from file), restore it */
820 if (wwin
->main_window
!= None
)
821 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
823 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
825 if (win_state
&& !withdraw
) {
826 if (win_state
->state
->hidden
> 0)
827 wwin
->flags
.hidden
= win_state
->state
->hidden
;
829 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
830 wwin
->flags
.shaded
= win_state
->state
->shaded
;
832 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
833 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
835 if (!IS_OMNIPRESENT(wwin
)) {
836 int w
= wDefaultGetStartWorkspace(wwin
->wm_instance
, wwin
->wm_class
);
837 if (w
< 0 || w
>= w_global
.workspace
.count
) {
838 workspace
= win_state
->state
->workspace
;
839 if (workspace
>= w_global
.workspace
.count
)
840 workspace
= w_global
.workspace
.current
;
845 workspace
= w_global
.workspace
.current
;
849 /* if we're restarting, restore saved state (from hints).
850 * This will overwrite previous */
854 if (getSavedState(window
, &wstate
)) {
855 wwin
->flags
.shaded
= wstate
->shaded
;
856 wwin
->flags
.hidden
= wstate
->hidden
;
857 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
858 wwin
->flags
.maximized
= wstate
->maximized
;
859 if (wwin
->flags
.maximized
) {
860 wwin
->old_geometry
.x
= wstate
->x
;
861 wwin
->old_geometry
.y
= wstate
->y
;
862 wwin
->old_geometry
.width
= wstate
->w
;
863 wwin
->old_geometry
.height
= wstate
->h
;
866 workspace
= wstate
->workspace
;
871 /* restore window shortcut */
872 if (wstate
!= NULL
|| win_state
!= NULL
) {
875 if (win_state
!= NULL
)
876 mask
= win_state
->state
->window_shortcuts
;
878 if (wstate
!= NULL
&& mask
== 0)
879 mask
= wstate
->window_shortcuts
;
884 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
885 if (mask
& (1 << i
)) {
886 if (!w_global
.shortcut
.windows
[i
])
887 w_global
.shortcut
.windows
[i
] = WMCreateArray(4);
889 WMAddToArray(w_global
.shortcut
.windows
[i
], wwin
);
899 /* don't let transients start miniaturized if their owners are not */
900 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
901 wwin
->flags
.miniaturized
= 0;
903 wwin
->wm_hints
->initial_state
= NormalState
;
906 /* set workspace on which the window starts */
907 if (workspace
>= 0) {
908 if (workspace
> w_global
.workspace
.count
- 1)
909 workspace
= workspace
% w_global
.workspace
.count
;
913 w
= wDefaultGetStartWorkspace(wwin
->wm_instance
, wwin
->wm_class
);
915 if (w
>= 0 && w
< w_global
.workspace
.count
&& !(IS_OMNIPRESENT(wwin
))) {
918 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
919 workspace
= transientOwner
->frame
->workspace
;
921 workspace
= w_global
.workspace
.current
;
925 /* setup window geometry */
926 if (win_state
&& win_state
->state
->w
> 0) {
927 width
= win_state
->state
->w
;
928 height
= win_state
->state
->h
;
931 wWindowConstrainSize(wwin
, &width
, &height
);
933 /* do not ask for window placement if the window is
934 * transient, during startup, if the initial workspace is another one
935 * or if the window wants to start iconic.
936 * If geometry was saved, restore it. */
938 Bool dontBring
= False
;
940 if (win_state
&& win_state
->state
->w
> 0) {
941 x
= win_state
->state
->x
;
942 y
= win_state
->state
->y
;
943 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
944 && !scr
->flags
.startup
945 && workspace
== w_global
.workspace
.current
946 && !wwin
->flags
.miniaturized
947 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
949 if (transientOwner
&& transientOwner
->flags
.mapped
) {
950 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
954 x
= transientOwner
->frame_x
+
955 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
956 y
= transientOwner
->frame_y
+
957 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
959 /* limit transient windows to be inside their parent's head */
960 rect
.pos
.x
= transientOwner
->frame_x
;
961 rect
.pos
.y
= transientOwner
->frame_y
;
962 rect
.size
.width
= transientOwner
->frame
->core
->width
;
963 rect
.size
.height
= transientOwner
->frame
->core
->height
;
965 head
= wGetHeadForRect(scr
, rect
);
966 rect
= wGetRectForHead(scr
, head
);
970 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
971 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
975 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
976 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
979 PlaceWindow(wwin
, &x
, &y
, width
, height
);
982 if (wPreferences
.window_placement
== WPM_MANUAL
)
985 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
990 /* Make spash screens come out in the center of a head
991 * trouble is that most splashies never get here
992 * they are managed trough atoms but god knows where.
993 * Dan, do you know ? -peter
995 * Most of them are not managed, they have set
996 * OverrideRedirect, which means we can't do anything about
999 /* xinerama checks for: across head and dead space */
1002 rect
.size
.width
= width
;
1003 rect
.size
.height
= height
;
1005 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1007 if (flags
& XFLAG_DEAD
)
1010 if (flags
& XFLAG_MULTIPLE
)
1014 switch (reposition
) {
1016 head
= wGetHeadForPointerLocation(scr
);
1017 rect
= wGetRectForHead(scr
, head
);
1019 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1020 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1024 rect
= wGetRectForHead(scr
, head
);
1028 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1029 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1033 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1034 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1043 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1044 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1047 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1049 if (wwin
->flags
.urgent
) {
1050 if (!IS_OMNIPRESENT(wwin
))
1051 wwin
->flags
.omnipresent
^= 1;
1054 /* Create frame, borders and do reparenting */
1055 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1056 #ifdef XKB_BUTTON_HINT
1057 if (wPreferences
.modelock
)
1058 foo
|= WFF_LANGUAGE_BUTTON
;
1060 if (HAS_TITLEBAR(wwin
))
1061 foo
|= WFF_TITLEBAR
;
1063 if (HAS_RESIZEBAR(wwin
))
1064 foo
|= WFF_RESIZEBAR
;
1066 if (HAS_BORDER(wwin
))
1069 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1070 x
, y
, width
, height
,
1071 &wPreferences
.window_title_clearance
,
1072 &wPreferences
.window_title_min_height
,
1073 &wPreferences
.window_title_max_height
,
1075 scr
->window_title_texture
,
1076 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1077 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1079 wwin
->frame
->flags
.is_client_window_frame
= 1;
1080 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1082 /* setup button images */
1083 wWindowUpdateButtonImages(wwin
);
1085 /* hide unused buttons */
1087 if (WFLAGP(wwin
, no_close_button
))
1088 foo
|= WFF_RIGHT_BUTTON
;
1090 if (WFLAGP(wwin
, no_miniaturize_button
))
1091 foo
|= WFF_LEFT_BUTTON
;
1093 #ifdef XKB_BUTTON_HINT
1094 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1095 foo
|= WFF_LANGUAGE_BUTTON
;
1098 wFrameWindowHideButton(wwin
->frame
, foo
);
1100 wwin
->frame
->child
= wwin
;
1101 wwin
->frame
->workspace
= workspace
;
1102 wwin
->frame
->on_click_left
= windowIconifyClick
;
1104 #ifdef XKB_BUTTON_HINT
1105 if (wPreferences
.modelock
)
1106 wwin
->frame
->on_click_language
= windowLanguageClick
;
1109 wwin
->frame
->on_click_right
= windowCloseClick
;
1110 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1111 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1112 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1113 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1115 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1116 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1117 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1122 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1124 /* if gravity is to the south, account for the border sizes */
1126 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1130 * wWindowConfigure() will init the client window's size
1131 * (wwin->client.{width,height}) and all other geometry
1132 * related variables (frame_x,frame_y) */
1133 wWindowConfigure(wwin
, x
, y
, width
, height
);
1135 /* to make sure the window receives it's new position after reparenting */
1136 wWindowSynthConfigureNotify(wwin
);
1138 /* Setup descriptors and save window to internal lists */
1139 if (wwin
->main_window
!= None
) {
1143 /* Leader windows do not necessary set themselves as leaders.
1144 * If this is the case, point the leader of this window to
1146 leader
= wWindowFor(wwin
->main_window
);
1147 if (leader
&& leader
->main_window
== None
)
1148 leader
->main_window
= leader
->client_win
;
1150 app
= wApplicationCreate(wwin
);
1152 app
->last_workspace
= workspace
;
1154 /* Do application specific stuff, like setting application
1155 * wide attributes. */
1157 if (wwin
->flags
.hidden
) {
1158 /* if the window was set to hidden because it was hidden
1159 * in a previous incarnation and that state was restored */
1160 app
->flags
.hidden
= 1;
1161 } else if (app
->flags
.hidden
) {
1162 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1163 wwin
->flags
.hidden
= 1;
1165 wUnhideApplication(app
, False
, False
);
1173 /* setup the frame descriptor */
1174 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1175 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1176 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1178 /* don't let windows go away if we die */
1179 XAddToSaveSet(dpy
, window
);
1181 XLowerWindow(dpy
, window
);
1183 /* if window is in this workspace and should be mapped, then map it */
1184 if (!wwin
->flags
.miniaturized
&& (workspace
== w_global
.workspace
.current
|| IS_OMNIPRESENT(wwin
))
1185 && !wwin
->flags
.hidden
&& !withdraw
) {
1187 /* The following "if" is to avoid crashing of clients that expect
1188 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1189 * after the return from this function. */
1190 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1191 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1193 wClientSetState(wwin
, NormalState
, None
);
1195 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1196 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1198 * The brain damaged idiotic non-click to focus modes will
1199 * have trouble with this because:
1201 * 1. window is created and mapped by the client
1202 * 2. window is mapped by wmaker in small size
1203 * 3. window is animated to grow to normal size
1204 * 4. this function returns to normal event loop
1205 * 5. eventually, the EnterNotify event that would trigger
1206 * the window focusing (if the mouse is over that window)
1207 * will be processed by wmaker.
1208 * But since this event will be rather delayed
1209 * (step 3 has a large delay) the time when the event ocurred
1210 * and when it is processed, the client that owns that window
1211 * will reject the XSetInputFocus() for it.
1213 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1214 DoWindowBirth(wwin
);
1219 /* setup stacking descriptor */
1221 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1223 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1225 if (!scr
->focused_window
) {
1226 /* first window on the list */
1229 scr
->focused_window
= wwin
;
1233 /* add window at beginning of focus window list */
1234 tmp
= scr
->focused_window
;
1243 /* raise is set to true if we un-hid the app when this window was born.
1244 * we raise, else old windows of this app will be above this new one. */
1246 wRaiseFrame(wwin
->frame
->core
);
1248 /* Update name must come after WApplication stuff is done */
1249 wWindowUpdateName(wwin
, title
);
1255 /* Final preparations before window is ready to go */
1256 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1258 if (!wwin
->flags
.miniaturized
&& workspace
== w_global
.workspace
.current
&& !wwin
->flags
.hidden
) {
1259 if (((transientOwner
&& transientOwner
->flags
.focused
)
1260 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1262 /* only auto_focus if on same screen as mouse
1263 * (and same head for xinerama mode)
1264 * TODO: make it an option */
1266 /*TODO add checking the head of the window, is it available? */
1267 short same_screen
= 0, same_head
= 1;
1273 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1274 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1277 if (same_screen
== 1 && same_head
== 1)
1278 wSetFocusTo(scr
, wwin
);
1281 wWindowResetMouseGrabs(wwin
);
1283 if (!WFLAGP(wwin
, no_bind_keys
))
1284 wWindowSetKeyGrabs(wwin
);
1286 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1287 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1289 /* Setup Notification Observers */
1290 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1292 /* Cleanup temporary stuff */
1294 wWindowDeleteSavedState(win_state
);
1296 /* If the window must be withdrawed, then do it now.
1297 * Must do some optimization, 'though */
1299 wwin
->flags
.mapped
= 0;
1300 wClientSetState(wwin
, WithdrawnState
, None
);
1301 wUnmanageWindow(wwin
, True
, False
);
1308 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1309 const char *title
, int x
, int y
, int width
, int height
)
1314 wwin
= wWindowCreate();
1316 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1318 wwin
->flags
.internal_window
= 1;
1320 WSETUFLAG(wwin
, omnipresent
, 1);
1321 WSETUFLAG(wwin
, no_shadeable
, 1);
1322 WSETUFLAG(wwin
, no_resizable
, 1);
1323 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1325 wwin
->focus_mode
= WFM_PASSIVE
;
1326 wwin
->client_win
= window
;
1327 wwin
->screen_ptr
= scr
;
1328 wwin
->transient_for
= owner
;
1331 wwin
->client
.width
= width
;
1332 wwin
->client
.height
= height
;
1333 wwin
->frame_x
= wwin
->client
.x
;
1334 wwin
->frame_y
= wwin
->client
.y
;
1336 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1337 foo
|= WFF_TITLEBAR
;
1338 #ifdef XKB_BUTTON_HINT
1339 foo
|= WFF_LANGUAGE_BUTTON
;
1342 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1343 wwin
->frame_x
, wwin
->frame_y
,
1345 &wPreferences
.window_title_clearance
,
1346 &wPreferences
.window_title_min_height
,
1347 &wPreferences
.window_title_max_height
,
1349 scr
->window_title_texture
,
1350 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1351 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1353 XSaveContext(dpy
, window
, w_global
.context
.client_win
, (XPointer
) & wwin
->client_descriptor
);
1355 wwin
->frame
->flags
.is_client_window_frame
= 1;
1356 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1358 wFrameWindowChangeTitle(wwin
->frame
, title
);
1360 /* setup button images */
1361 wWindowUpdateButtonImages(wwin
);
1364 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1366 wwin
->frame
->child
= wwin
;
1367 wwin
->frame
->workspace
= w_global
.workspace
.current
;
1369 #ifdef XKB_BUTTON_HINT
1370 if (wPreferences
.modelock
)
1371 wwin
->frame
->on_click_language
= windowLanguageClick
;
1374 wwin
->frame
->on_click_right
= windowCloseClick
;
1375 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1376 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1377 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1378 wwin
->client
.y
+= wwin
->frame
->top_width
;
1380 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1381 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1383 /* setup the frame descriptor */
1384 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1385 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1386 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1388 XLowerWindow(dpy
, window
);
1389 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1391 /* setup stacking descriptor */
1392 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1394 tmp
= wWindowFor(wwin
->transient_for
);
1396 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1398 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1401 if (!scr
->focused_window
) {
1402 /* first window on the list */
1405 scr
->focused_window
= wwin
;
1409 /* add window at beginning of focus window list */
1410 tmp
= scr
->focused_window
;
1418 if (wwin
->flags
.is_gnustep
== 0)
1419 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1421 /* if (wPreferences.auto_focus) */
1422 wSetFocusTo(scr
, wwin
);
1423 wWindowResetMouseGrabs(wwin
);
1424 wWindowSetKeyGrabs(wwin
);
1430 *----------------------------------------------------------------------
1432 * Removes the frame window from a window and destroys all data
1433 * related to it. The window will be reparented back to the root window
1434 * if restore is True.
1437 * Everything related to the window is destroyed and the window
1438 * is removed from the window lists. Focus is set to the previous on the
1440 *----------------------------------------------------------------------
1442 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1444 WCoreWindow
*frame
= wwin
->frame
->core
;
1445 WWindow
*owner
= NULL
;
1446 WWindow
*newFocusedWindow
= NULL
;
1448 WScreen
*scr
= wwin
->screen_ptr
;
1450 /* First close attribute editor window if open */
1451 if (wwin
->flags
.inspector_open
)
1452 wCloseInspectorForWindow(wwin
);
1454 /* Close window menu if it's open for this window */
1455 if (wwin
->flags
.menu_open_for_me
)
1456 CloseWindowMenu(scr
);
1458 /* Don't restore focus to this window after a window exits
1459 * fullscreen mode */
1460 if (scr
->bfs_focused_window
== wwin
)
1461 scr
->bfs_focused_window
= NULL
;
1464 if (!wwin
->flags
.internal_window
)
1465 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1467 /* If this is a leader window, we still need to listen for
1468 * DestroyNotify and PropertyNotify. */
1469 if (wApplicationOf(wwin
->client_win
))
1470 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1472 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1474 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1475 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1478 XUnmapWindow(dpy
, frame
->window
);
1480 XUnmapWindow(dpy
, wwin
->client_win
);
1482 /* deselect window */
1483 wSelectWindow(wwin
, False
);
1485 /* remove all pending events on window */
1486 /* I think this only matters for autoraise */
1487 if (wPreferences
.raise_delay
)
1488 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1492 /* reparent the window back to the root */
1494 wClientRestore(wwin
);
1496 if (wwin
->transient_for
!= scr
->root_win
) {
1497 owner
= wWindowFor(wwin
->transient_for
);
1499 if (!owner
->flags
.semi_focused
)
1502 owner
->flags
.semi_focused
= 0;
1506 wasFocused
= wwin
->flags
.focused
;
1508 /* remove from window focus list */
1509 if (!wwin
->prev
&& !wwin
->next
) {
1510 /* was the only window */
1511 scr
->focused_window
= NULL
;
1512 newFocusedWindow
= NULL
;
1517 wwin
->prev
->next
= wwin
->next
;
1520 wwin
->next
->prev
= wwin
->prev
;
1522 scr
->focused_window
= wwin
->prev
;
1523 scr
->focused_window
->next
= NULL
;
1526 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1528 /* if in click to focus mode and the window
1529 * was a transient, focus the owner window
1532 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1533 tmp
= wWindowFor(wwin
->transient_for
);
1534 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1538 /* otherwise, focus the next one in the focus list */
1540 tmp
= scr
->focused_window
;
1541 while (tmp
) { /* look for one in the window list first */
1542 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1543 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1547 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1548 tmp
= scr
->focused_window
;
1550 if (!WFLAGP(tmp
, no_focusable
)
1551 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1558 newFocusedWindow
= tmp
;
1560 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1565 /* This is to let the root window get the keyboard input
1566 * if Sloppy focus mode and no other window get focus.
1567 * This way keybindings will not freeze.
1570 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1571 tmp
= wWindowFor(win
);
1574 newFocusedWindow
= tmp
;
1576 newFocusedWindow
= NULL
;
1580 if (!wwin
->flags
.internal_window
)
1581 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1583 if (newFocusedWindow
!= owner
&& owner
) {
1584 if (wwin
->flags
.is_gnustep
== 0)
1585 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1587 wSetFocusTo(scr
, newFocusedWindow
);
1590 /* Close menu and unhighlight */
1591 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1592 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1593 if (oapp
&& oapp
!= napp
) {
1594 wAppMenuUnmap(oapp
->menu
);
1595 if (wPreferences
.highlight_active_app
)
1596 wApplicationDeactivate(oapp
);
1599 wNETCleanupFrameExtents(wwin
);
1601 wWindowDestroy(wwin
);
1605 void wWindowMap(WWindow
*wwin
)
1607 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1608 if (!wwin
->flags
.shaded
) {
1609 /* window will be remapped when getting MapNotify */
1610 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1611 XMapWindow(dpy
, wwin
->client_win
);
1612 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1614 wwin
->flags
.mapped
= 1;
1618 void wWindowUnmap(WWindow
*wwin
)
1620 wwin
->flags
.mapped
= 0;
1622 /* prevent window withdrawal when getting UnmapNotify */
1623 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1624 XUnmapWindow(dpy
, wwin
->client_win
);
1625 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1627 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1630 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1635 #ifdef KEEP_XKB_LOCK_STATUS
1636 if (wPreferences
.modelock
)
1637 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1638 #endif /* KEEP_XKB_LOCK_STATUS */
1640 wwin
->flags
.semi_focused
= 0;
1642 if (wwin
->flags
.is_gnustep
== 0)
1643 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1645 wwin
->flags
.focused
= 1;
1647 wWindowResetMouseGrabs(wwin
);
1649 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1651 if (owin
== wwin
|| !owin
)
1654 nowner
= wWindowFor(wwin
->transient_for
);
1656 /* new window is a transient for the old window */
1657 if (nowner
== owin
) {
1658 owin
->flags
.semi_focused
= 1;
1659 wWindowUnfocus(nowner
);
1663 oowner
= wWindowFor(owin
->transient_for
);
1665 /* new window is owner of old window */
1666 if (wwin
== oowner
) {
1667 wWindowUnfocus(owin
);
1672 wWindowUnfocus(owin
);
1676 /* new window has same owner of old window */
1677 if (oowner
== nowner
) {
1678 /* prevent unfocusing of owner */
1679 oowner
->flags
.semi_focused
= 0;
1680 wWindowUnfocus(owin
);
1681 oowner
->flags
.semi_focused
= 1;
1686 /* nowner != NULL && oowner != nowner */
1687 nowner
->flags
.semi_focused
= 1;
1688 wWindowUnfocus(nowner
);
1689 wWindowUnfocus(owin
);
1692 void wWindowUnfocus(WWindow
*wwin
)
1694 CloseWindowMenu(wwin
->screen_ptr
);
1696 if (wwin
->flags
.is_gnustep
== 0)
1697 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1699 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1701 owner
= wWindowFor(wwin
->transient_for
);
1702 if (owner
&& owner
->flags
.semi_focused
) {
1703 owner
->flags
.semi_focused
= 0;
1704 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1705 wWindowUnfocus(owner
);
1706 wFrameWindowPaint(owner
->frame
);
1710 wwin
->flags
.focused
= 0;
1711 wWindowResetMouseGrabs(wwin
);
1712 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1715 void wWindowUpdateName(WWindow
*wwin
, const char *newTitle
)
1723 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1727 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1728 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1732 *----------------------------------------------------------------------
1734 * wWindowConstrainSize--
1735 * Constrains size for the client window, taking the maximal size,
1736 * window resize increments and other size hints into account.
1739 * The closest size to what was given that the client window can
1742 *----------------------------------------------------------------------
1744 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1746 int width
= (int)*nwidth
;
1747 int height
= (int)*nheight
;
1750 int minW
= 1, minH
= 1;
1751 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1752 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1753 int minAX
= -1, minAY
= -1;
1754 int maxAX
= -1, maxAY
= -1;
1758 if (wwin
->normal_hints
) {
1759 winc
= wwin
->normal_hints
->width_inc
;
1760 hinc
= wwin
->normal_hints
->height_inc
;
1761 minW
= wwin
->normal_hints
->min_width
;
1762 minH
= wwin
->normal_hints
->min_height
;
1763 maxW
= wwin
->normal_hints
->max_width
;
1764 maxH
= wwin
->normal_hints
->max_height
;
1765 if (wwin
->normal_hints
->flags
& PAspect
) {
1766 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1767 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1768 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1769 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1772 baseW
= wwin
->normal_hints
->base_width
;
1773 baseH
= wwin
->normal_hints
->base_height
;
1786 /* aspect ratio code borrowed from olwm */
1788 /* adjust max aspect ratio */
1789 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1790 if (maxAX
> maxAY
) {
1791 height
= (width
* maxAY
) / maxAX
;
1792 if (height
> maxH
) {
1794 width
= (height
* maxAX
) / maxAY
;
1797 width
= (height
* maxAX
) / maxAY
;
1800 height
= (width
* maxAY
) / maxAX
;
1805 /* adjust min aspect ratio */
1806 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1807 if (minAX
> minAY
) {
1808 height
= (width
* minAY
) / minAX
;
1809 if (height
< minH
) {
1811 width
= (height
* minAX
) / minAY
;
1814 width
= (height
* minAX
) / minAY
;
1817 height
= (width
* minAY
) / minAX
;
1824 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1826 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1829 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1831 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1833 /* broken stupid apps may cause preposterous values for these.. */
1840 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1841 unsigned int *width
, unsigned int *height
)
1843 int baseW
= 0, baseH
= 0;
1844 int winc
= 1, hinc
= 1;
1846 if (wwin
->normal_hints
) {
1847 baseW
= wwin
->normal_hints
->base_width
;
1848 baseH
= wwin
->normal_hints
->base_height
;
1850 winc
= wwin
->normal_hints
->width_inc
;
1851 hinc
= wwin
->normal_hints
->height_inc
;
1855 *width
= maxW
- (maxW
- baseW
) % winc
;
1858 *height
= maxH
- (maxH
- baseH
) % hinc
;
1861 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1863 WScreen
*scr
= wwin
->screen_ptr
;
1867 if (workspace
>= w_global
.workspace
.count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1870 if (workspace
!= w_global
.workspace
.current
) {
1871 /* Sent to other workspace. Unmap window */
1872 if ((wwin
->flags
.mapped
1873 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1874 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1876 wapp
= wApplicationOf(wwin
->main_window
);
1878 wapp
->last_workspace
= workspace
;
1880 if (wwin
->flags
.miniaturized
) {
1882 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1883 wwin
->icon
->mapped
= 0;
1887 wSetFocusTo(scr
, NULL
);
1891 /* brought to current workspace. Map window */
1892 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1894 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1895 wwin
->icon
->mapped
= 1;
1897 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1901 if (!IS_OMNIPRESENT(wwin
)) {
1902 int oldWorkspace
= wwin
->frame
->workspace
;
1903 wwin
->frame
->workspace
= workspace
;
1904 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1911 void wWindowChangeWorkspaceRelative(WWindow
*wwin
, int amount
)
1913 WScreen
*scr
= wwin
->screen_ptr
;
1914 int w
= w_global
.workspace
.current
+ amount
;
1918 wWindowChangeWorkspace(wwin
, w
);
1919 } else if (wPreferences
.ws_cycle
) {
1920 wWindowChangeWorkspace(wwin
, w_global
.workspace
.count
+ w
);
1922 } else if (amount
> 0) {
1923 if (w
< w_global
.workspace
.count
) {
1924 wWindowChangeWorkspace(wwin
, w
);
1925 } else if (wPreferences
.ws_advance
) {
1926 int workspace
= WMIN(w
, MAX_WORKSPACES
- 1);
1927 wWorkspaceMake(scr
, workspace
);
1928 wWindowChangeWorkspace(wwin
, workspace
);
1929 } else if (wPreferences
.ws_cycle
) {
1930 wWindowChangeWorkspace(wwin
, w
% w_global
.workspace
.count
);
1935 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1939 sevent
.type
= ConfigureNotify
;
1940 sevent
.xconfigure
.display
= dpy
;
1941 sevent
.xconfigure
.event
= wwin
->client_win
;
1942 sevent
.xconfigure
.window
= wwin
->client_win
;
1944 sevent
.xconfigure
.x
= wwin
->client
.x
;
1945 sevent
.xconfigure
.y
= wwin
->client
.y
;
1946 sevent
.xconfigure
.width
= wwin
->client
.width
;
1947 sevent
.xconfigure
.height
= wwin
->client
.height
;
1949 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1950 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1951 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1953 sevent
.xconfigure
.above
= None
;
1955 sevent
.xconfigure
.override_redirect
= False
;
1956 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1961 *----------------------------------------------------------------------
1962 * wWindowConfigure()
1964 * req_x, req_y: new requested positions for the frame
1965 * req_width, req_height: new requested sizes for the client
1967 * Configures the frame, decorations and client window to the specified
1968 * geometry, whose validity is not checked -- wWindowConstrainSize()
1969 * must be used for that.
1970 * The size parameters are for the client window, but the position is
1972 * The client window receives a ConfigureNotify event, according
1973 * to what ICCCM says.
1979 * Window size and position are changed and client window receives
1980 * a ConfigureNotify event.
1981 *----------------------------------------------------------------------
1983 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1985 int synth_notify
= False
;
1988 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1990 * if the window is being moved but not resized then
1991 * send a synthetic ConfigureNotify
1993 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
1994 synth_notify
= True
;
1996 if (WFLAGP(wwin
, dont_move_off
))
1997 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2000 if (req_width
< MIN_WINDOW_SIZE
)
2001 req_width
= MIN_WINDOW_SIZE
;
2002 if (req_height
< MIN_WINDOW_SIZE
)
2003 req_height
= MIN_WINDOW_SIZE
;
2005 /* If growing, resize inner part before frame,
2006 * if shrinking, resize frame before.
2007 * This will prevent the frame (that can have a different color)
2008 * to be exposed, causing flicker */
2009 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2010 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2012 if (wwin
->flags
.shaded
) {
2013 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2014 wwin
->old_geometry
.height
= req_height
;
2018 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2020 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2023 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2024 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2026 wwin
->client
.x
= req_x
;
2027 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2028 wwin
->client
.width
= req_width
;
2029 wwin
->client
.height
= req_height
;
2031 wwin
->client
.x
= req_x
;
2032 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2034 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2036 wwin
->frame_x
= req_x
;
2037 wwin
->frame_y
= req_y
;
2038 if (HAS_BORDER(wwin
)) {
2039 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2040 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2043 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
&& resize
)
2044 wWindowSetShape(wwin
);
2048 wWindowSynthConfigureNotify(wwin
);
2050 wNETFrameExtents(wwin
);
2055 /* req_x, req_y: new position of the frame */
2056 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2058 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2059 int synth_notify
= False
;
2061 /* Send a synthetic ConfigureNotify event for every window movement. */
2062 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2063 synth_notify
= True
;
2065 /* A single synthetic ConfigureNotify event is sent at the end of
2066 * a completed (opaque) movement in moveres.c */
2069 if (WFLAGP(wwin
, dont_move_off
))
2070 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2071 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2073 wwin
->client
.x
= req_x
;
2074 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2075 if (HAS_BORDER(wwin
)) {
2076 wwin
->client
.x
+= wwin
->screen_ptr
->frame_border_width
;
2077 wwin
->client
.y
+= wwin
->screen_ptr
->frame_border_width
;
2080 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2082 wwin
->frame_x
= req_x
;
2083 wwin
->frame_y
= req_y
;
2085 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2087 wWindowSynthConfigureNotify(wwin
);
2091 void wWindowUpdateButtonImages(WWindow
*wwin
)
2093 WScreen
*scr
= wwin
->screen_ptr
;
2094 Pixmap pixmap
, mask
;
2095 WFrameWindow
*fwin
= wwin
->frame
;
2097 if (!HAS_TITLEBAR(wwin
))
2100 /* miniaturize button */
2101 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2102 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2103 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2105 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2106 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2110 if (fwin
->lbutton_image
2111 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2112 wPixmapDestroy(fwin
->lbutton_image
);
2113 fwin
->lbutton_image
= NULL
;
2116 if (!fwin
->lbutton_image
) {
2117 fwin
->lbutton_image
= wPixmapCreate(pixmap
, mask
);
2118 fwin
->lbutton_image
->client_owned
= 1;
2119 fwin
->lbutton_image
->client_owned_mask
= 1;
2122 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2123 wPixmapDestroy(fwin
->lbutton_image
);
2125 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2128 #ifdef XKB_BUTTON_HINT
2129 if (!WFLAGP(wwin
, no_language_button
)) {
2130 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2131 wPixmapDestroy(fwin
->languagebutton_image
);
2133 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2139 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2140 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2142 if (!WFLAGP(wwin
, no_close_button
)) {
2143 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2144 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2146 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2147 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2151 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2152 || fwin
->rbutton_image
->mask
!= mask
)) {
2153 wPixmapDestroy(fwin
->rbutton_image
);
2154 fwin
->rbutton_image
= NULL
;
2157 if (!fwin
->rbutton_image
) {
2158 fwin
->rbutton_image
= wPixmapCreate(pixmap
, mask
);
2159 fwin
->rbutton_image
->client_owned
= 1;
2160 fwin
->rbutton_image
->client_owned_mask
= 1;
2163 } else if (WFLAGP(wwin
, kill_close
)) {
2164 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2165 wPixmapDestroy(fwin
->rbutton_image
);
2167 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2169 } else if (MGFLAGP(wwin
, broken_close
)) {
2170 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2171 wPixmapDestroy(fwin
->rbutton_image
);
2173 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2176 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2177 wPixmapDestroy(fwin
->rbutton_image
);
2179 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2183 /* force buttons to be redrawn */
2184 fwin
->flags
.need_texture_change
= 1;
2185 wFrameWindowPaint(fwin
);
2189 *---------------------------------------------------------------------------
2190 * wWindowConfigureBorders--
2191 * Update window border configuration according to attribute flags.
2193 *---------------------------------------------------------------------------
2195 void wWindowConfigureBorders(WWindow
*wwin
)
2201 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2203 #ifdef XKB_BUTTON_HINT
2204 if (wPreferences
.modelock
)
2205 flags
|= WFF_LANGUAGE_BUTTON
;
2208 if (HAS_TITLEBAR(wwin
))
2209 flags
|= WFF_TITLEBAR
;
2210 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2211 flags
|= WFF_RESIZEBAR
;
2212 if (HAS_BORDER(wwin
))
2213 flags
|= WFF_BORDER
;
2214 if (wwin
->flags
.shaded
)
2215 flags
|= WFF_IS_SHADED
;
2216 if (wwin
->flags
.selected
)
2217 flags
|= WFF_SELECTED
;
2219 oldh
= wwin
->frame
->top_width
;
2220 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2221 if (oldh
!= wwin
->frame
->top_width
) {
2222 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2224 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2225 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2229 if (!WFLAGP(wwin
, no_miniaturize_button
)
2230 && wwin
->frame
->flags
.hide_left_button
)
2231 flags
|= WFF_LEFT_BUTTON
;
2233 #ifdef XKB_BUTTON_HINT
2234 if (!WFLAGP(wwin
, no_language_button
)
2235 && wwin
->frame
->flags
.hide_language_button
)
2236 flags
|= WFF_LANGUAGE_BUTTON
;
2239 if (!WFLAGP(wwin
, no_close_button
)
2240 && wwin
->frame
->flags
.hide_right_button
)
2241 flags
|= WFF_RIGHT_BUTTON
;
2244 wWindowUpdateButtonImages(wwin
);
2245 wFrameWindowShowButton(wwin
->frame
, flags
);
2249 if (WFLAGP(wwin
, no_miniaturize_button
)
2250 && !wwin
->frame
->flags
.hide_left_button
)
2251 flags
|= WFF_LEFT_BUTTON
;
2253 #ifdef XKB_BUTTON_HINT
2254 if (WFLAGP(wwin
, no_language_button
)
2255 && !wwin
->frame
->flags
.hide_language_button
)
2256 flags
|= WFF_LANGUAGE_BUTTON
;
2259 if (WFLAGP(wwin
, no_close_button
)
2260 && !wwin
->frame
->flags
.hide_right_button
)
2261 flags
|= WFF_RIGHT_BUTTON
;
2264 wFrameWindowHideButton(wwin
->frame
, flags
);
2267 if (w_global
.xext
.shape
.supported
&& wwin
->flags
.shaped
)
2268 wWindowSetShape(wwin
);
2273 void wWindowSaveState(WWindow
*wwin
)
2278 memset(data
, 0, sizeof(long) * 10);
2279 data
[0] = wwin
->frame
->workspace
;
2280 data
[1] = wwin
->flags
.miniaturized
;
2281 data
[2] = wwin
->flags
.shaded
;
2282 data
[3] = wwin
->flags
.hidden
;
2283 data
[4] = wwin
->flags
.maximized
;
2284 if (wwin
->flags
.maximized
== 0) {
2285 data
[5] = wwin
->frame_x
;
2286 data
[6] = wwin
->frame_y
;
2287 data
[7] = wwin
->frame
->core
->width
;
2288 data
[8] = wwin
->frame
->core
->height
;
2290 data
[5] = wwin
->old_geometry
.x
;
2291 data
[6] = wwin
->old_geometry
.y
;
2292 data
[7] = wwin
->old_geometry
.width
;
2293 data
[8] = wwin
->old_geometry
.height
;
2296 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2297 if (w_global
.shortcut
.windows
[i
] &&
2298 WMCountInArray(w_global
.shortcut
.windows
[i
], wwin
))
2302 XChangeProperty(dpy
, wwin
->client_win
, w_global
.atom
.wmaker
.state
,
2303 w_global
.atom
.wmaker
.state
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2306 static int getSavedState(Window window
, WSavedState
** state
)
2310 unsigned long nitems_ret
;
2311 unsigned long bytes_after_ret
;
2314 if (XGetWindowProperty(dpy
, window
, w_global
.atom
.wmaker
.state
, 0, 10,
2315 True
, w_global
.atom
.wmaker
.state
,
2316 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2317 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2320 *state
= wmalloc(sizeof(WSavedState
));
2322 (*state
)->workspace
= data
[0];
2323 (*state
)->miniaturized
= data
[1];
2324 (*state
)->shaded
= data
[2];
2325 (*state
)->hidden
= data
[3];
2326 (*state
)->maximized
= data
[4];
2327 (*state
)->x
= data
[5];
2328 (*state
)->y
= data
[6];
2329 (*state
)->w
= data
[7];
2330 (*state
)->h
= data
[8];
2331 (*state
)->window_shortcuts
= data
[9];
2335 if (*state
&& type_ret
== w_global
.atom
.wmaker
.state
)
2342 void wWindowClearShape(WWindow
* wwin
)
2344 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2345 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2349 void wWindowSetShape(WWindow
* wwin
)
2353 #ifdef OPTIMIZE_SHAPE
2358 /* only shape is the client's */
2359 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2362 /* Get array of rectangles describing the shape mask */
2363 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2367 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2373 /* insert our decoration rectangles in the rect list */
2374 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2377 if (HAS_TITLEBAR(wwin
)) {
2379 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2380 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2381 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2384 if (HAS_RESIZEBAR(wwin
)) {
2386 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2387 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2388 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2392 /* shape our frame window */
2393 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2394 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2400 #endif /* OPTIMIZE_SHAPE */
2402 if (HAS_TITLEBAR(wwin
)) {
2405 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2406 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2409 if (HAS_RESIZEBAR(wwin
)) {
2411 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2412 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2413 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2417 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2418 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2420 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2421 0, wwin
->frame
->top_width
, wwin
->client_win
,
2422 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2427 /* ====================================================================== */
2429 static FocusMode
getFocusMode(WWindow
* wwin
)
2433 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2434 if (wwin
->wm_hints
->input
== True
) {
2435 if (wwin
->protocols
.TAKE_FOCUS
)
2436 mode
= WFM_LOCALLY_ACTIVE
;
2440 if (wwin
->protocols
.TAKE_FOCUS
)
2441 mode
= WFM_GLOBALLY_ACTIVE
;
2443 mode
= WFM_NO_INPUT
;
2451 void wWindowSetKeyGrabs(WWindow
* wwin
)
2456 for (i
= 0; i
< WKBD_LAST
; i
++) {
2457 key
= &wKeyBindings
[i
];
2459 if (key
->keycode
== 0)
2461 if (key
->modifier
!= AnyModifier
) {
2462 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2463 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2465 /* Also grab all modifier combinations possible that include,
2466 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2467 * work even if the NumLock/ScrollLock key is on.
2469 wHackedGrabKey(key
->keycode
, key
->modifier
,
2470 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2473 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2474 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2477 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2480 void wWindowResetMouseGrabs(WWindow
* wwin
)
2482 /* Mouse grabs can't be done on the client window because of
2483 * ICCCM and because clients that try to do the same will crash.
2485 * But there is a problem wich makes tbar buttons of unfocused
2486 * windows not usable as the click goes to the frame window instead
2487 * of the button itself. Must figure a way to fix that.
2490 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2492 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2493 /* grabs for Meta+drag */
2494 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2495 True
, ButtonPressMask
| ButtonReleaseMask
,
2496 GrabModeSync
, GrabModeAsync
, None
, None
);
2498 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2499 * but we only grab it for Button4 and Button 5 since a lot of apps
2500 * use CTRL+Button1-3 for app related functionality
2502 if (wPreferences
.resize_increment
> 0) {
2503 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2504 True
, ButtonPressMask
| ButtonReleaseMask
,
2505 GrabModeSync
, GrabModeAsync
, None
, None
);
2506 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2507 True
, ButtonPressMask
| ButtonReleaseMask
,
2508 GrabModeSync
, GrabModeAsync
, None
, None
);
2510 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2511 True
, ButtonPressMask
| ButtonReleaseMask
,
2512 GrabModeSync
, GrabModeAsync
, None
, None
);
2513 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2514 True
, ButtonPressMask
| ButtonReleaseMask
,
2515 GrabModeSync
, GrabModeAsync
, None
, None
);
2519 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2520 && !wwin
->flags
.is_gnustep
) {
2521 /* the passive grabs to focus the window */
2522 /* if (wPreferences.focus_mode == WKF_CLICK) */
2523 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2524 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2529 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2531 if (attr
->flags
& GSExtraFlagsAttr
) {
2532 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2533 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2534 wWindowUpdateButtonImages(wwin
);
2539 WMagicNumber
wWindowAddSavedState(const char *instance
, const char *class,
2540 const char *command
, pid_t pid
, WSavedState
* state
)
2542 WWindowState
*wstate
;
2544 wstate
= malloc(sizeof(WWindowState
));
2548 memset(wstate
, 0, sizeof(WWindowState
));
2551 wstate
->instance
= wstrdup(instance
);
2553 wstate
->class = wstrdup(class);
2555 wstate
->command
= wstrdup(command
);
2556 wstate
->state
= state
;
2558 wstate
->next
= windowState
;
2559 windowState
= wstate
;
2564 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2566 WMagicNumber
wWindowGetSavedState(Window win
)
2568 char *instance
, *class, *command
= NULL
;
2569 WWindowState
*wstate
= windowState
;
2574 command
= GetCommandForWindow(win
);
2578 if (PropGetWMClass(win
, &class, &instance
)) {
2580 if (SAME(instance
, wstate
->instance
) &&
2581 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2584 wstate
= wstate
->next
;
2600 void wWindowDeleteSavedState(WMagicNumber id
)
2602 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2604 if (!wstate
|| !windowState
)
2608 if (tmp
== wstate
) {
2609 windowState
= wstate
->next
;
2610 release_wwindowstate(wstate
);
2613 if (tmp
->next
== wstate
) {
2614 tmp
->next
= wstate
->next
;
2615 release_wwindowstate(wstate
);
2623 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2625 WWindowState
*tmp
, *wstate
;
2631 if (tmp
->pid
== pid
) {
2632 wstate
= windowState
;
2633 windowState
= tmp
->next
;
2635 release_wwindowstate(wstate
);
2638 if (tmp
->next
->pid
== pid
) {
2640 tmp
->next
= wstate
->next
;
2641 release_wwindowstate(wstate
);
2649 static void release_wwindowstate(WWindowState
*wstate
)
2651 if (wstate
->instance
)
2652 wfree(wstate
->instance
);
2655 wfree(wstate
->class);
2657 if (wstate
->command
)
2658 wfree(wstate
->command
);
2660 wfree(wstate
->state
);
2664 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2666 if (wwin
->flags
.omnipresent
== flag
)
2669 wwin
->flags
.omnipresent
= flag
;
2670 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2673 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2675 WWindow
*wwin
= data
;
2677 /* Parameter not used, but tell the compiler that it is ok */
2680 #ifndef NUMLOCK_HACK
2681 if ((event
->xbutton
.state
& ValidModMask
)
2682 != (event
->xbutton
.state
& ~LockMask
)) {
2683 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2684 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2688 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2690 CloseWindowMenu(wwin
->screen_ptr
);
2692 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2693 && !WFLAGP(wwin
, no_focusable
)) {
2694 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2697 if (event
->xbutton
.button
== Button1
)
2698 wRaiseFrame(wwin
->frame
->core
);
2700 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2701 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2702 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2703 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2708 if (event
->xbutton
.state
& MOD_MASK
) {
2709 /* move the window */
2710 wMouseMoveWindow(wwin
, event
);
2711 XUngrabPointer(dpy
, CurrentTime
);
2713 wMouseResizeWindow(wwin
, event
);
2714 XUngrabPointer(dpy
, CurrentTime
);
2718 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2720 WWindow
*wwin
= data
;
2722 /* Parameter not used, but tell the compiler that it is ok */
2725 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2727 if (event
->xbutton
.button
== Button1
) {
2728 if (event
->xbutton
.state
== 0) {
2729 if (!WFLAGP(wwin
, no_shadeable
)) {
2731 if (wwin
->flags
.shaded
)
2732 wUnshadeWindow(wwin
);
2739 if (event
->xbutton
.state
& ControlMask
)
2740 dir
|= MAX_VERTICAL
;
2742 if (event
->xbutton
.state
& ShiftMask
) {
2743 dir
|= MAX_HORIZONTAL
;
2744 if (!(event
->xbutton
.state
& ControlMask
))
2745 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2748 /* maximize window */
2749 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2750 int ndir
= dir
^ wwin
->flags
.maximized
;
2753 wMaximizeWindow(wwin
, ndir
);
2755 wUnmaximizeWindow(wwin
);
2758 } else if (event
->xbutton
.button
== Button3
) {
2759 if (event
->xbutton
.state
& MOD_MASK
)
2760 wHideOtherApplications(wwin
);
2761 } else if (event
->xbutton
.button
== Button2
) {
2762 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2763 } else if (event
->xbutton
.button
== W_getconf_mouseWheelUp()) {
2765 } else if (event
->xbutton
.button
== W_getconf_mouseWheelDown()) {
2766 wUnshadeWindow(wwin
);
2770 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2772 WWindow
*wwin
= desc
->parent
;
2773 unsigned int new_width
, w_scale
;
2774 unsigned int new_height
, h_scale
;
2775 unsigned int resize_width_increment
= 0;
2776 unsigned int resize_height_increment
= 0;
2778 if (wwin
->normal_hints
) {
2779 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2780 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2781 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2782 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2784 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2785 resize_width_increment
= wPreferences
.resize_increment
;
2786 resize_height_increment
= wPreferences
.resize_increment
;
2789 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2791 CloseWindowMenu(wwin
->screen_ptr
);
2793 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2794 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2796 if (event
->xbutton
.button
== Button1
)
2797 wRaiseFrame(wwin
->frame
->core
);
2799 if (event
->xbutton
.state
& ControlMask
) {
2800 if (event
->xbutton
.button
== Button4
) {
2801 new_width
= wwin
->client
.width
- resize_width_increment
;
2802 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2803 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2805 if (event
->xbutton
.button
== Button5
) {
2806 new_width
= wwin
->client
.width
+ resize_width_increment
;
2807 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2808 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2812 if (event
->xbutton
.state
& MOD_MASK
) {
2813 /* move the window */
2814 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2815 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2816 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2819 if (event
->xbutton
.button
== Button3
) {
2820 wMouseResizeWindow(wwin
, event
);
2821 } else if (event
->xbutton
.button
== Button4
) {
2822 new_height
= wwin
->client
.height
- resize_height_increment
;
2823 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2824 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2825 } else if (event
->xbutton
.button
== Button5
) {
2826 new_height
= wwin
->client
.height
+ resize_height_increment
;
2827 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2828 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2829 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2830 wMouseMoveWindow(wwin
, event
);
2832 XUngrabPointer(dpy
, CurrentTime
);
2836 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2838 WWindow
*wwin
= (WWindow
*) data
;
2840 /* Parameter not used, but tell the compiler that it is ok */
2843 #ifndef NUMLOCK_HACK
2844 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2845 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2846 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2848 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2850 CloseWindowMenu(wwin
->screen_ptr
);
2852 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2853 && !WFLAGP(wwin
, no_focusable
))
2854 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2856 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2858 if (event
->xbutton
.button
== Button1
) {
2859 if (event
->xbutton
.state
& MOD_MASK
)
2860 wLowerFrame(wwin
->frame
->core
);
2862 wRaiseFrame(wwin
->frame
->core
);
2864 if ((event
->xbutton
.state
& ShiftMask
)
2865 && !(event
->xbutton
.state
& ControlMask
)) {
2866 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2869 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2870 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2871 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2872 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2876 /* move the window */
2877 wMouseMoveWindow(wwin
, event
);
2879 XUngrabPointer(dpy
, CurrentTime
);
2880 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2881 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2882 WObjDescriptor
*desc
;
2884 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2885 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2886 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2887 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2891 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2893 /* allow drag select */
2894 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2895 event
->xany
.send_event
= True
;
2896 (*desc
->handle_mousedown
) (desc
, event
);
2898 XUngrabPointer(dpy
, CurrentTime
);
2902 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2904 WWindow
*wwin
= data
;
2906 /* Parameter not used, but tell the compiler that it is ok */
2909 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
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
, w_global
.atom
.wm
.delete_window
,
2923 w_global
.timestamp
.last_event
);
2928 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2930 WWindow
*wwin
= data
;
2932 /* Parameter not used, but tell the compiler that it is ok */
2935 CloseWindowMenu(wwin
->screen_ptr
);
2937 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2940 /* send delete message */
2941 if (wwin
->protocols
.DELETE_WINDOW
)
2942 wClientSendProtocol(wwin
, w_global
.atom
.wm
.delete_window
,
2943 w_global
.timestamp
.last_event
);
2948 #ifdef XKB_BUTTON_HINT
2949 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2951 WWindow
*wwin
= data
;
2952 WFrameWindow
*fwin
= wwin
->frame
;
2953 WScreen
*scr
= fwin
->screen_ptr
;
2956 /* Parameter not used, but tell the compiler that it is ok */
2959 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2961 tl
= wwin
->frame
->languagemode
;
2962 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2963 wwin
->frame
->last_languagemode
= tl
;
2964 wSetFocusTo(scr
, wwin
);
2965 wwin
->frame
->languagebutton_image
=
2966 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2967 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2968 if (event
->xbutton
.button
== Button3
)
2970 wRaiseFrame(fwin
->core
);
2974 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2976 WWindow
*wwin
= data
;
2978 /* Parameter not used, but tell the compiler that it is ok */
2981 event
->xbutton
.state
&= w_global
.shortcut
.modifiers_mask
;
2983 CloseWindowMenu(wwin
->screen_ptr
);
2985 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2988 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2989 wClientSendProtocol(wwin
, w_global
.atom
.gnustep
.wm_miniaturize_window
,
2990 w_global
.timestamp
.last_event
);
2993 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2995 wapp
= wApplicationOf(wwin
->main_window
);
2996 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2997 wHideApplication(wapp
);
2998 } else if (event
->xbutton
.state
== 0) {
2999 wIconifyWindow(wwin
);