1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
29 #ifdef KEEP_XKB_LOCK_STATUS
30 #include <X11/XKBlib.h>
31 #endif /* KEEP_XKB_LOCK_STATUS */
38 /* For getting mouse wheel mappings from WINGs */
39 #include <WINGs/WINGsP.h>
41 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
57 #include "workspace.h"
61 #include "superfluous.h"
69 #define MOD_MASK wPreferences.modifier_mask
71 /****** Global Variables ******/
72 extern WShortKey wKeyBindings
[WKBD_LAST
];
75 extern Bool wShapeSupported
;
79 extern XContext wWinContext
;
82 extern Atom _XA_WM_DELETE_WINDOW
;
83 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
84 extern Atom _XA_WINDOWMAKER_STATE
;
85 extern WPreferences wPreferences
;
86 extern Time LastTimestamp
;
88 /***** Local Stuff *****/
89 static WWindowState
*windowState
= NULL
;
90 static FocusMode
getFocusMode(WWindow
*wwin
);
91 static int getSavedState(Window window
, WSavedState
**state
);
92 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
94 /* frame window (during window grabs) */
95 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
98 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
99 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
104 #ifdef XKB_BUTTON_HINT
105 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
109 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
110 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
112 static void remove_wwindowstate(WWindowState
*wstate
);
114 /****** Notification Observers ******/
116 static void appearanceObserver(void *self
, WMNotification
* notif
)
118 WWindow
*wwin
= (WWindow
*) self
;
119 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
121 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
124 if (flags
& WFontSettings
) {
125 wWindowConfigureBorders(wwin
);
126 if (wwin
->flags
.shaded
) {
127 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
128 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
129 wWindowSynthConfigureNotify(wwin
);
132 if (flags
& WTextureSettings
)
133 wwin
->frame
->flags
.need_texture_remake
= 1;
135 if (flags
& (WTextureSettings
| WColorSettings
)) {
136 if (wwin
->frame
->titlebar
)
137 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
139 wFrameWindowPaint(wwin
->frame
);
144 WWindow
*wWindowFor(Window window
)
146 WObjDescriptor
*desc
;
151 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
154 if (desc
->parent_type
== WCLASS_WINDOW
)
156 else if (desc
->parent_type
== WCLASS_FRAME
) {
157 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
158 if (frame
->flags
.is_client_window_frame
)
165 WWindow
*wWindowCreate(void)
169 wwin
= wmalloc(sizeof(WWindow
));
172 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
173 wwin
->client_descriptor
.parent
= wwin
;
174 wwin
->client_descriptor
.self
= wwin
;
175 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
180 void wWindowDestroy(WWindow
*wwin
)
184 if (wwin
->screen_ptr
->cmap_window
== wwin
)
185 wwin
->screen_ptr
->cmap_window
= NULL
;
187 WMRemoveNotificationObserver(wwin
);
189 wwin
->flags
.destroyed
= 1;
191 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
192 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
195 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
197 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
198 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
199 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
203 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
204 wwin
->fake_group
->retainCount
--;
205 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
206 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
207 wwin
->fake_group
->leader
= None
;
208 wwin
->fake_group
->origLeader
= None
;
213 if (wwin
->normal_hints
)
214 XFree(wwin
->normal_hints
);
217 XFree(wwin
->wm_hints
);
219 if (wwin
->wm_instance
)
220 XFree(wwin
->wm_instance
);
223 XFree(wwin
->wm_class
);
225 if (wwin
->wm_gnustep_attr
)
226 wfree(wwin
->wm_gnustep_attr
);
228 if (wwin
->cmap_windows
)
229 XFree(wwin
->cmap_windows
);
231 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
234 wFrameWindowDestroy(wwin
->frame
);
237 RemoveFromStackList(wwin
->icon
->core
);
238 wIconDestroy(wwin
->icon
);
239 if (wPreferences
.auto_arrange_icons
)
240 wArrangeIcons(wwin
->screen_ptr
, True
);
242 if (wwin
->net_icon_image
)
243 RReleaseImage(wwin
->net_icon_image
);
248 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
250 if (gs_hints
->flags
& GSWindowStyleAttr
) {
251 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
252 wwin
->client_flags
.no_border
= 1;
253 wwin
->client_flags
.no_titlebar
= 1;
254 wwin
->client_flags
.no_closable
= 1;
255 wwin
->client_flags
.no_miniaturizable
= 1;
256 wwin
->client_flags
.no_resizable
= 1;
257 wwin
->client_flags
.no_close_button
= 1;
258 wwin
->client_flags
.no_miniaturize_button
= 1;
259 wwin
->client_flags
.no_resizebar
= 1;
261 wwin
->client_flags
.no_close_button
=
262 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
264 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
266 wwin
->client_flags
.no_miniaturize_button
=
267 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
269 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
271 wwin
->client_flags
.no_resizebar
=
272 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
274 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
276 /* these attributes supposedly imply in the existence
278 if (gs_hints
->window_style
& (WMResizableWindowMask
|
279 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
280 wwin
->client_flags
.no_titlebar
= 0;
282 wwin
->client_flags
.no_titlebar
=
283 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
288 /* setup the defaults */
289 wwin
->client_flags
.no_border
= 0;
290 wwin
->client_flags
.no_titlebar
= 0;
291 wwin
->client_flags
.no_closable
= 0;
292 wwin
->client_flags
.no_miniaturizable
= 0;
293 wwin
->client_flags
.no_resizable
= 0;
294 wwin
->client_flags
.no_close_button
= 0;
295 wwin
->client_flags
.no_miniaturize_button
= 0;
296 wwin
->client_flags
.no_resizebar
= 0;
298 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
299 wwin
->client_flags
.no_appicon
= 1;
302 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
304 WScreen
*scr
= wwin
->screen_ptr
;
306 /* sets global default stuff */
307 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
309 * Decoration setting is done in this precedence (lower to higher)
310 * - use global default in the resource database
311 * - guess some settings
312 * - use GNUstep/external window attributes
313 * - set hints specified for the app in the resource DB
316 WSETUFLAG(wwin
, broken_close
, 0);
318 if (wwin
->protocols
.DELETE_WINDOW
)
319 WSETUFLAG(wwin
, kill_close
, 0);
321 WSETUFLAG(wwin
, kill_close
, 1);
323 /* transients can't be iconified or maximized */
324 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
325 WSETUFLAG(wwin
, no_miniaturizable
, 1);
326 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
329 /* if the window can't be resized, remove the resizebar */
330 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
331 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
332 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
333 WSETUFLAG(wwin
, no_resizable
, 1);
334 WSETUFLAG(wwin
, no_resizebar
, 1);
337 /* set GNUstep window attributes */
338 if (wwin
->wm_gnustep_attr
) {
339 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
341 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
343 *level
= wwin
->wm_gnustep_attr
->window_level
;
345 * INT_MIN is the only illegal window level.
347 if (*level
== INT_MIN
)
348 *level
= INT_MIN
+ 1;
351 *level
= WMNormalLevel
;
354 int tmp_workspace
= -1;
355 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
361 wMWMCheckClientHints(wwin
);
362 #endif /* MWM_HINTS */
365 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
367 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
368 * have INT_MIN that means that no window level was requested. -Dan
370 if (tmp_level
== INT_MIN
) {
371 if (WFLAGP(wwin
, floating
))
372 *level
= WMFloatingLevel
;
373 else if (WFLAGP(wwin
, sunken
))
374 *level
= WMSunkenLevel
;
376 *level
= WMNormalLevel
;
381 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
382 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
383 if (transientOwner
) {
384 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
385 if (ownerLevel
> *level
)
390 if (tmp_workspace
>= 0)
391 *workspace
= tmp_workspace
% scr
->workspace_count
;
395 * Set attributes specified only for that window/class.
396 * This might do duplicate work with the 1st wDefaultFillAttributes().
398 wDefaultFillAttributes(wwin
->wm_instance
, wwin
->wm_class
, &wwin
->user_flags
,
399 &wwin
->defined_user_flags
, False
);
401 * Sanity checks for attributes that depend on other attributes
403 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
404 wwin
->user_flags
.emulate_appicon
= 0;
406 if (wwin
->main_window
!= None
) {
407 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
408 if (wapp
&& !wapp
->flags
.emulated
)
409 wwin
->user_flags
.emulate_appicon
= 0;
412 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
413 wwin
->user_flags
.emulate_appicon
= 0;
415 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
416 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
417 wwin
->user_flags
.sunken
= 0;
419 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
421 /* windows that have takefocus=False shouldn't take focus at all */
422 if (wwin
->focus_mode
== WFM_NO_INPUT
)
423 wwin
->client_flags
.no_focusable
= 1;
426 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
430 w1
= wwin
->frame
->core
->width
;
431 h1
= wwin
->frame
->core
->height
;
432 w2
= obscured
->frame
->core
->width
;
433 h2
= obscured
->frame
->core
->height
;
435 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
436 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
439 if (wwin
->frame_x
+ w1
< obscured
->frame_x
440 || wwin
->frame_y
+ h1
< obscured
->frame_y
441 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
447 static void fixLeaderProperties(WWindow
*wwin
)
449 XClassHint
*classHint
;
450 XWMHints
*hints
, *clientHints
;
451 XWindowAttributes attr
;
452 Window leaders
[2], window
;
453 char **argv
, *command
;
457 classHint
= XAllocClassHint();
458 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
459 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
461 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
465 leaders
[0] = wwin
->client_leader
;
466 leaders
[1] = wwin
->group_id
;
469 command
= GetCommandForWindow(wwin
->client_win
);
471 wfree(command
); /* command already set. nothing to do. */
473 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
476 for (i
= 0; i
< 2; i
++) {
479 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
480 classHint
->res_name
= wwin
->wm_instance
;
481 classHint
->res_class
= wwin
->wm_class
;
482 XSetClassHint(dpy
, window
, classHint
);
484 hints
= XGetWMHints(dpy
, window
);
487 } else if (clientHints
) {
488 /* set window group leader to self */
489 clientHints
->window_group
= window
;
490 clientHints
->flags
|= WindowGroupHint
;
491 XSetWMHints(dpy
, window
, clientHints
);
495 command
= GetCommandForWindow(window
);
497 wfree(command
); /* command already set. nothing to do. */
499 XSetCommand(dpy
, window
, argv
, argc
);
502 /* Make sure we get notification when this window is destroyed */
503 if (XGetWindowAttributes(dpy
, window
, &attr
))
504 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
515 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
517 XClassHint
*classHint
;
523 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
525 classHint
= XAllocClassHint();
526 classHint
->res_name
= instance
;
527 classHint
->res_class
= class;
528 XSetClassHint(dpy
, leader
, classHint
);
531 /* inherit these from the original leader if available */
532 hints
= XGetWMHints(dpy
, win
);
534 hints
= XAllocWMHints();
537 /* set window group leader to self */
538 hints
->window_group
= leader
;
539 hints
->flags
|= WindowGroupHint
;
540 XSetWMHints(dpy
, leader
, hints
);
543 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
544 XSetCommand(dpy
, leader
, argv
, argc
);
545 XFreeStringList(argv
);
551 static int matchIdentifier(const void *item
, const void *cdata
)
553 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
557 *----------------------------------------------------------------
559 * reparents the window and allocates a descriptor for it.
560 * Window manager hints and other hints are fetched to configure
561 * the window decoration attributes and others. User preferences
562 * for the window are used if available, to configure window
563 * decorations and some behaviour.
564 * If in startup, windows that are override redirect,
565 * unmapped and never were managed and are Withdrawn are not
569 * the new window descriptor
572 * The window is reparented and appropriate notification
573 * is done to the client. Input mask for the window is setup.
574 * The window descriptor is also associated with various window
575 * contexts and inserted in the head of the window list.
576 * Event handler contexts are associated for some objects
577 * (buttons, titlebar and resizebar)
579 *----------------------------------------------------------------
581 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
585 unsigned width
, height
;
586 XWindowAttributes wattribs
;
587 XSetWindowAttributes attribs
;
588 WWindowState
*win_state
;
589 WWindow
*transientOwner
= NULL
;
595 Bool withdraw
= False
;
601 /* make sure the window is still there */
602 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
607 /* if it's an override-redirect, ignore it */
608 if (wattribs
.override_redirect
) {
613 wm_state
= PropGetWindowState(window
);
615 /* if it's startup and the window is unmapped, don't manage it */
616 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
621 wwin
= wWindowCreate();
623 title
= wNETWMGetWindowName(window
);
625 wwin
->flags
.net_has_title
= 1;
626 if (!title
&& !wFetchName(dpy
, window
, &title
))
629 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
632 if (wShapeSupported
) {
637 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
638 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
639 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
640 wwin
->flags
.shaped
= b_shaped
;
645 * 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
) {
682 if (wwin
->wm_hints
->initial_state
== IconicState
) {
683 wwin
->flags
.miniaturized
= 1;
684 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
685 wwin
->flags
.is_dockapp
= 1;
690 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
691 wwin
->group_id
= wwin
->wm_hints
->window_group
;
692 /* window_group has priority over CLIENT_LEADER */
693 wwin
->main_window
= wwin
->group_id
;
695 wwin
->group_id
= None
;
698 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
699 wwin
->flags
.urgent
= 1;
700 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
703 wwin
->group_id
= None
;
706 PropGetProtocols(window
, &wwin
->protocols
);
708 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
709 wwin
->transient_for
= None
;
711 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
712 wwin
->transient_for
= scr
->root_win
;
714 transientOwner
= wWindowFor(wwin
->transient_for
);
715 if (transientOwner
&& transientOwner
->main_window
!= None
)
716 wwin
->main_window
= transientOwner
->main_window
;
720 /* guess the focus mode */
721 wwin
->focus_mode
= getFocusMode(wwin
);
723 /* get geometry stuff */
724 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
726 /* get colormap windows */
727 GetColormapWindows(wwin
);
730 * Setup the decoration/window attributes and
733 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
735 /* Make broken apps behave as a nice app. */
736 if (WFLAGP(wwin
, emulate_appicon
))
737 wwin
->main_window
= wwin
->client_win
;
739 fixLeaderProperties(wwin
);
741 wwin
->orig_main_window
= wwin
->main_window
;
743 if (wwin
->flags
.is_gnustep
)
744 WSETUFLAG(wwin
, shared_appicon
, 0);
746 if (wwin
->main_window
) {
747 extern Atom _XA_WINDOWMAKER_MENU
;
748 XTextProperty text_prop
;
750 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
))
751 WSETUFLAG(wwin
, shared_appicon
, 0);
754 if (wwin
->flags
.is_dockapp
)
755 WSETUFLAG(wwin
, shared_appicon
, 0);
757 if (wwin
->main_window
) {
758 WApplication
*app
= wApplicationOf(wwin
->main_window
);
759 if (app
&& app
->app_icon
)
760 WSETUFLAG(wwin
, shared_appicon
, 0);
763 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
764 char *buffer
, *instance
, *class;
765 WFakeGroupLeader
*fPtr
;
768 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
770 /* // only enter here if PropGetWMClass() succeds */
771 PropGetWMClass(wwin
->main_window
, &class, &instance
);
772 buffer
= StrConcatDot(instance
, class);
774 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
775 if (index
!= WANotFound
) {
776 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
777 if (fPtr
->retainCount
== 0)
778 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
782 if (fPtr
->origLeader
== None
) {
783 if (ADEQUATE(wwin
->main_window
)) {
785 fPtr
->origLeader
= wwin
->main_window
;
788 wwin
->fake_group
= fPtr
;
789 /*wwin->group_id = fPtr->leader; */
790 wwin
->main_window
= fPtr
->leader
;
793 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
795 fPtr
->identifier
= buffer
;
796 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
797 fPtr
->origLeader
= None
;
798 fPtr
->retainCount
= 1;
800 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
802 if (ADEQUATE(wwin
->main_window
)) {
804 fPtr
->origLeader
= wwin
->main_window
;
806 wwin
->fake_group
= fPtr
;
807 /*wwin->group_id = fPtr->leader; */
808 wwin
->main_window
= fPtr
->leader
;
818 * Setup the initial state of the window
820 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
821 wwin
->flags
.miniaturized
= 1;
823 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
824 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
826 wNETWMCheckInitialClientState(wwin
);
828 /* apply previous state if it exists and we're in startup */
829 if (scr
->flags
.startup
&& wm_state
>= 0) {
830 if (wm_state
== IconicState
) {
831 wwin
->flags
.miniaturized
= 1;
832 } else if (wm_state
== WithdrawnState
) {
837 /* if there is a saved state (from file), restore it */
839 if (wwin
->main_window
!= None
)
840 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
842 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
844 if (win_state
&& !withdraw
) {
845 if (win_state
->state
->hidden
> 0)
846 wwin
->flags
.hidden
= win_state
->state
->hidden
;
848 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
849 wwin
->flags
.shaded
= win_state
->state
->shaded
;
851 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
852 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
854 if (!IS_OMNIPRESENT(wwin
)) {
855 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
857 if (w
< 0 || w
>= scr
->workspace_count
) {
858 workspace
= win_state
->state
->workspace
;
859 if (workspace
>= scr
->workspace_count
)
860 workspace
= scr
->current_workspace
;
865 workspace
= scr
->current_workspace
;
869 /* if we're restarting, restore saved state (from hints).
870 * This will overwrite previous */
874 if (getSavedState(window
, &wstate
)) {
875 wwin
->flags
.shaded
= wstate
->shaded
;
876 wwin
->flags
.hidden
= wstate
->hidden
;
877 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
878 wwin
->flags
.maximized
= wstate
->maximized
;
879 if (wwin
->flags
.maximized
) {
880 wwin
->old_geometry
.x
= wstate
->x
;
881 wwin
->old_geometry
.y
= wstate
->y
;
882 wwin
->old_geometry
.width
= wstate
->w
;
883 wwin
->old_geometry
.height
= wstate
->h
;
886 workspace
= wstate
->workspace
;
891 /* restore window shortcut */
892 if (wstate
!= NULL
|| win_state
!= NULL
) {
895 if (win_state
!= NULL
)
896 mask
= win_state
->state
->window_shortcuts
;
898 if (wstate
!= NULL
&& mask
== 0)
899 mask
= wstate
->window_shortcuts
;
904 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
905 if (mask
& (1 << i
)) {
906 if (!scr
->shortcutWindows
[i
])
907 scr
->shortcutWindows
[i
] = WMCreateArray(4);
909 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
918 /* don't let transients start miniaturized if their owners are not */
919 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
920 wwin
->flags
.miniaturized
= 0;
922 wwin
->wm_hints
->initial_state
= NormalState
;
925 /* set workspace on which the window starts */
926 if (workspace
>= 0) {
927 if (workspace
> scr
->workspace_count
- 1)
928 workspace
= workspace
% scr
->workspace_count
;
932 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
934 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
937 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
938 workspace
= transientOwner
->frame
->workspace
;
940 workspace
= scr
->current_workspace
;
944 /* setup window geometry */
945 if (win_state
&& win_state
->state
->w
> 0) {
946 width
= win_state
->state
->w
;
947 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
;
978 * limit transient windows to be inside their parent's head
980 rect
.pos
.x
= transientOwner
->frame_x
;
981 rect
.pos
.y
= transientOwner
->frame_y
;
982 rect
.size
.width
= transientOwner
->frame
->core
->width
;
983 rect
.size
.height
= transientOwner
->frame
->core
->height
;
985 head
= wGetHeadForRect(scr
, rect
);
986 rect
= wGetRectForHead(scr
, head
);
990 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
991 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
995 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
996 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
999 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1001 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1004 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1010 * Make spash screens come out in the center of a head
1011 * trouble is that most splashies never get here
1012 * they are managed trough atoms but god knows where.
1013 * Dan, do you know ? -peter
1015 * Most of them are not managed, they have set
1016 * OverrideRedirect, which means we can't do anything about
1021 * xinerama checks for: across head and dead space
1025 rect
.size
.width
= width
;
1026 rect
.size
.height
= height
;
1028 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1030 if (flags
& XFLAG_DEAD
)
1033 if (flags
& XFLAG_MULTIPLE
)
1037 switch (reposition
) {
1039 head
= wGetHeadForPointerLocation(scr
);
1040 rect
= wGetRectForHead(scr
, head
);
1042 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1043 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1047 rect
= wGetRectForHead(scr
, head
);
1051 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1052 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1056 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1057 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1066 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1067 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1070 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1072 if (wwin
->flags
.urgent
) {
1073 if (!IS_OMNIPRESENT(wwin
))
1074 wwin
->flags
.omnipresent
^= 1;
1078 * Create frame, borders and do reparenting
1080 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1081 #ifdef XKB_BUTTON_HINT
1082 if (wPreferences
.modelock
)
1083 foo
|= WFF_LANGUAGE_BUTTON
;
1085 if (HAS_TITLEBAR(wwin
))
1086 foo
|= WFF_TITLEBAR
;
1087 if (HAS_RESIZEBAR(wwin
))
1088 foo
|= WFF_RESIZEBAR
;
1089 if (HAS_BORDER(wwin
))
1092 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1093 x
, y
, width
, height
,
1094 &wPreferences
.window_title_clearance
,
1095 &wPreferences
.window_title_min_height
,
1096 &wPreferences
.window_title_max_height
,
1098 scr
->window_title_texture
,
1099 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1100 wattribs
.depth
, wattribs
.visual
, wattribs
.colormap
);
1102 wwin
->frame
->flags
.is_client_window_frame
= 1;
1103 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1105 /* setup button images */
1106 wWindowUpdateButtonImages(wwin
);
1108 /* hide unused buttons */
1110 if (WFLAGP(wwin
, no_close_button
))
1111 foo
|= WFF_RIGHT_BUTTON
;
1112 if (WFLAGP(wwin
, no_miniaturize_button
))
1113 foo
|= WFF_LEFT_BUTTON
;
1114 #ifdef XKB_BUTTON_HINT
1115 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1116 foo
|= WFF_LANGUAGE_BUTTON
;
1119 wFrameWindowHideButton(wwin
->frame
, foo
);
1121 wwin
->frame
->child
= wwin
;
1122 wwin
->frame
->workspace
= workspace
;
1123 wwin
->frame
->on_click_left
= windowIconifyClick
;
1125 #ifdef XKB_BUTTON_HINT
1126 if (wPreferences
.modelock
)
1127 wwin
->frame
->on_click_language
= windowLanguageClick
;
1130 wwin
->frame
->on_click_right
= windowCloseClick
;
1131 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1132 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1133 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1134 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1136 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1137 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1138 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1143 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1145 /* if gravity is to the south, account for the border sizes */
1147 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1151 * wWindowConfigure() will init the client window's size
1152 * (wwin->client.{width,height}) and all other geometry
1153 * related variables (frame_x,frame_y)
1155 wWindowConfigure(wwin
, x
, y
, width
, height
);
1157 /* to make sure the window receives it's new position after reparenting */
1158 wWindowSynthConfigureNotify(wwin
);
1161 * Setup descriptors and save window to internal
1164 if (wwin
->main_window
!= None
) {
1168 /* Leader windows do not necessary set themselves as leaders.
1169 * If this is the case, point the leader of this window to
1171 leader
= wWindowFor(wwin
->main_window
);
1172 if (leader
&& leader
->main_window
== None
)
1173 leader
->main_window
= leader
->client_win
;
1175 app
= wApplicationCreate(wwin
);
1177 app
->last_workspace
= workspace
;
1180 * Do application specific stuff, like setting application
1184 if (wwin
->flags
.hidden
) {
1185 /* if the window was set to hidden because it was hidden
1186 * in a previous incarnation and that state was restored */
1187 app
->flags
.hidden
= 1;
1188 } else if (app
->flags
.hidden
) {
1189 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1190 wwin
->flags
.hidden
= 1;
1192 wUnhideApplication(app
, False
, False
);
1200 /* setup the frame descriptor */
1201 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1202 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1203 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1205 /* don't let windows go away if we die */
1206 XAddToSaveSet(dpy
, window
);
1208 XLowerWindow(dpy
, window
);
1210 /* if window is in this workspace and should be mapped, then map it */
1211 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1212 && !wwin
->flags
.hidden
&& !withdraw
) {
1214 /* The following "if" is to avoid crashing of clients that expect
1215 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1216 * after the return from this function.
1218 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1219 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1221 wClientSetState(wwin
, NormalState
, None
);
1223 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1224 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1226 * The brain damaged idiotic non-click to focus modes will
1227 * have trouble with this because:
1229 * 1. window is created and mapped by the client
1230 * 2. window is mapped by wmaker in small size
1231 * 3. window is animated to grow to normal size
1232 * 4. this function returns to normal event loop
1233 * 5. eventually, the EnterNotify event that would trigger
1234 * the window focusing (if the mouse is over that window)
1235 * will be processed by wmaker.
1236 * But since this event will be rather delayed
1237 * (step 3 has a large delay) the time when the event ocurred
1238 * and when it is processed, the client that owns that window
1239 * will reject the XSetInputFocus() for it.
1241 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1242 DoWindowBirth(wwin
);
1247 /* setup stacking descriptor */
1249 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1251 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1253 if (!scr
->focused_window
) {
1254 /* first window on the list */
1257 scr
->focused_window
= wwin
;
1261 /* add window at beginning of focus window list */
1262 tmp
= scr
->focused_window
;
1270 /* raise is set to true if we un-hid the app when this window was born.
1271 * we raise, else old windows of this app will be above this new one. */
1273 wRaiseFrame(wwin
->frame
->core
);
1275 /* Update name must come after WApplication stuff is done */
1276 wWindowUpdateName(wwin
, title
);
1283 * Final preparations before window is ready to go
1285 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1287 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1288 if (((transientOwner
&& transientOwner
->flags
.focused
)
1289 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1291 /* only auto_focus if on same screen as mouse
1292 * (and same head for xinerama mode)
1293 * TODO: make it an option */
1295 /*TODO add checking the head of the window, is it available? */
1296 short same_screen
= 0, same_head
= 1;
1302 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1303 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1306 if (same_screen
== 1 && same_head
== 1)
1307 wSetFocusTo(scr
, wwin
);
1310 wWindowResetMouseGrabs(wwin
);
1312 if (!WFLAGP(wwin
, no_bind_keys
))
1313 wWindowSetKeyGrabs(wwin
);
1315 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1316 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1318 /* Setup Notification Observers */
1319 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1321 /* Cleanup temporary stuff */
1323 wWindowDeleteSavedState(win_state
);
1325 /* If the window must be withdrawed, then do it now.
1326 * Must do some optimization, 'though */
1328 wwin
->flags
.mapped
= 0;
1329 wClientSetState(wwin
, WithdrawnState
, None
);
1330 wUnmanageWindow(wwin
, True
, False
);
1337 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1338 char *title
, int x
, int y
, int width
, int height
)
1343 wwin
= wWindowCreate();
1345 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1347 wwin
->flags
.internal_window
= 1;
1349 WSETUFLAG(wwin
, omnipresent
, 1);
1350 WSETUFLAG(wwin
, no_shadeable
, 1);
1351 WSETUFLAG(wwin
, no_resizable
, 1);
1352 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1354 wwin
->focus_mode
= WFM_PASSIVE
;
1355 wwin
->client_win
= window
;
1356 wwin
->screen_ptr
= scr
;
1357 wwin
->transient_for
= owner
;
1360 wwin
->client
.width
= width
;
1361 wwin
->client
.height
= height
;
1362 wwin
->frame_x
= wwin
->client
.x
;
1363 wwin
->frame_y
= wwin
->client
.y
;
1365 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1366 foo
|= WFF_TITLEBAR
;
1367 #ifdef XKB_BUTTON_HINT
1368 foo
|= WFF_LANGUAGE_BUTTON
;
1371 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1372 wwin
->frame_x
, wwin
->frame_y
,
1374 &wPreferences
.window_title_clearance
,
1375 &wPreferences
.window_title_min_height
,
1376 &wPreferences
.window_title_max_height
,
1378 scr
->window_title_texture
,
1379 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
,
1380 scr
->w_depth
, scr
->w_visual
, scr
->w_colormap
);
1382 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1384 wwin
->frame
->flags
.is_client_window_frame
= 1;
1385 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1387 wFrameWindowChangeTitle(wwin
->frame
, title
);
1389 /* setup button images */
1390 wWindowUpdateButtonImages(wwin
);
1393 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1395 wwin
->frame
->child
= wwin
;
1396 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1398 #ifdef XKB_BUTTON_HINT
1399 if (wPreferences
.modelock
)
1400 wwin
->frame
->on_click_language
= windowLanguageClick
;
1403 wwin
->frame
->on_click_right
= windowCloseClick
;
1404 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1405 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1406 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1407 wwin
->client
.y
+= wwin
->frame
->top_width
;
1409 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1410 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1412 /* setup the frame descriptor */
1413 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1414 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1415 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1417 XLowerWindow(dpy
, window
);
1418 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1420 /* setup stacking descriptor */
1421 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1423 tmp
= wWindowFor(wwin
->transient_for
);
1425 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1427 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1430 if (!scr
->focused_window
) {
1431 /* first window on the list */
1434 scr
->focused_window
= wwin
;
1438 /* add window at beginning of focus window list */
1439 tmp
= scr
->focused_window
;
1447 if (wwin
->flags
.is_gnustep
== 0)
1448 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1450 /* if (wPreferences.auto_focus) */
1451 wSetFocusTo(scr
, wwin
);
1452 wWindowResetMouseGrabs(wwin
);
1453 wWindowSetKeyGrabs(wwin
);
1459 *----------------------------------------------------------------------
1461 * Removes the frame window from a window and destroys all data
1462 * related to it. The window will be reparented back to the root window
1463 * if restore is True.
1466 * Everything related to the window is destroyed and the window
1467 * is removed from the window lists. Focus is set to the previous on the
1469 *----------------------------------------------------------------------
1471 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1473 WCoreWindow
*frame
= wwin
->frame
->core
;
1474 WWindow
*owner
= NULL
;
1475 WWindow
*newFocusedWindow
= NULL
;
1477 WScreen
*scr
= wwin
->screen_ptr
;
1479 /* First close attribute editor window if open */
1480 if (wwin
->flags
.inspector_open
)
1481 wCloseInspectorForWindow(wwin
);
1483 /* Close window menu if it's open for this window */
1484 if (wwin
->flags
.menu_open_for_me
)
1485 CloseWindowMenu(scr
);
1488 if (!wwin
->flags
.internal_window
)
1489 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1491 /* If this is a leader window, we still need to listen for
1492 * DestroyNotify and PropertyNotify. */
1493 if (wApplicationOf(wwin
->client_win
))
1494 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1496 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1498 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1499 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1502 XUnmapWindow(dpy
, frame
->window
);
1504 XUnmapWindow(dpy
, wwin
->client_win
);
1506 /* deselect window */
1507 wSelectWindow(wwin
, False
);
1509 /* remove all pending events on window */
1510 /* I think this only matters for autoraise */
1511 if (wPreferences
.raise_delay
)
1512 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1516 /* reparent the window back to the root */
1518 wClientRestore(wwin
);
1520 if (wwin
->transient_for
!= scr
->root_win
) {
1521 owner
= wWindowFor(wwin
->transient_for
);
1523 if (!owner
->flags
.semi_focused
)
1526 owner
->flags
.semi_focused
= 0;
1530 wasFocused
= wwin
->flags
.focused
;
1532 /* remove from window focus list */
1533 if (!wwin
->prev
&& !wwin
->next
) {
1534 /* was the only window */
1535 scr
->focused_window
= NULL
;
1536 newFocusedWindow
= NULL
;
1541 wwin
->prev
->next
= wwin
->next
;
1544 wwin
->next
->prev
= wwin
->prev
;
1546 scr
->focused_window
= wwin
->prev
;
1547 scr
->focused_window
->next
= NULL
;
1550 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1552 /* if in click to focus mode and the window
1553 * was a transient, focus the owner window
1556 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1557 tmp
= wWindowFor(wwin
->transient_for
);
1558 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1562 /* otherwise, focus the next one in the focus list */
1564 tmp
= scr
->focused_window
;
1565 while (tmp
) { /* look for one in the window list first */
1566 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1567 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1571 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1572 tmp
= scr
->focused_window
;
1574 if (!WFLAGP(tmp
, no_focusable
)
1575 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1582 newFocusedWindow
= tmp
;
1584 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1589 /* This is to let the root window get the keyboard input
1590 * if Sloppy focus mode and no other window get focus.
1591 * This way keybindings will not freeze.
1594 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1595 tmp
= wWindowFor(win
);
1598 newFocusedWindow
= tmp
;
1600 newFocusedWindow
= NULL
;
1604 if (!wwin
->flags
.internal_window
)
1605 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1607 if (newFocusedWindow
!= owner
&& owner
) {
1608 if (wwin
->flags
.is_gnustep
== 0)
1609 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1611 wSetFocusTo(scr
, newFocusedWindow
);
1614 /* Close menu and unhighlight */
1615 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1616 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1617 if (oapp
&& oapp
!= napp
) {
1618 wAppMenuUnmap(oapp
->menu
);
1619 wApplicationDeactivate(oapp
);
1622 wNETCleanupFrameExtents(wwin
);
1624 wWindowDestroy(wwin
);
1628 void wWindowMap(WWindow
*wwin
)
1630 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1631 if (!wwin
->flags
.shaded
) {
1632 /* window will be remapped when getting MapNotify */
1633 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1634 XMapWindow(dpy
, wwin
->client_win
);
1635 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1637 wwin
->flags
.mapped
= 1;
1641 void wWindowUnmap(WWindow
*wwin
)
1643 wwin
->flags
.mapped
= 0;
1645 /* prevent window withdrawal when getting UnmapNotify */
1646 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1647 XUnmapWindow(dpy
, wwin
->client_win
);
1648 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1650 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1653 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1658 #ifdef KEEP_XKB_LOCK_STATUS
1659 if (wPreferences
.modelock
)
1660 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1661 #endif /* KEEP_XKB_LOCK_STATUS */
1663 wwin
->flags
.semi_focused
= 0;
1665 if (wwin
->flags
.is_gnustep
== 0)
1666 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1668 wwin
->flags
.focused
= 1;
1670 wWindowResetMouseGrabs(wwin
);
1672 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1674 if (owin
== wwin
|| !owin
)
1677 nowner
= wWindowFor(wwin
->transient_for
);
1679 /* new window is a transient for the old window */
1680 if (nowner
== owin
) {
1681 owin
->flags
.semi_focused
= 1;
1682 wWindowUnfocus(nowner
);
1686 oowner
= wWindowFor(owin
->transient_for
);
1688 /* new window is owner of old window */
1689 if (wwin
== oowner
) {
1690 wWindowUnfocus(owin
);
1695 wWindowUnfocus(owin
);
1699 /* new window has same owner of old window */
1700 if (oowner
== nowner
) {
1701 /* prevent unfocusing of owner */
1702 oowner
->flags
.semi_focused
= 0;
1703 wWindowUnfocus(owin
);
1704 oowner
->flags
.semi_focused
= 1;
1709 /* nowner != NULL && oowner != nowner */
1710 nowner
->flags
.semi_focused
= 1;
1711 wWindowUnfocus(nowner
);
1712 wWindowUnfocus(owin
);
1715 void wWindowUnfocus(WWindow
*wwin
)
1717 CloseWindowMenu(wwin
->screen_ptr
);
1719 if (wwin
->flags
.is_gnustep
== 0)
1720 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1722 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1724 owner
= wWindowFor(wwin
->transient_for
);
1725 if (owner
&& owner
->flags
.semi_focused
) {
1726 owner
->flags
.semi_focused
= 0;
1727 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1728 wWindowUnfocus(owner
);
1729 wFrameWindowPaint(owner
->frame
);
1733 wwin
->flags
.focused
= 0;
1734 wWindowResetMouseGrabs(wwin
);
1735 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1738 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1746 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1750 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1751 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1755 *----------------------------------------------------------------------
1757 * wWindowConstrainSize--
1758 * Constrains size for the client window, taking the maximal size,
1759 * window resize increments and other size hints into account.
1762 * The closest size to what was given that the client window can
1765 *----------------------------------------------------------------------
1767 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1769 int width
= (int)*nwidth
;
1770 int height
= (int)*nheight
;
1773 int minW
= 1, minH
= 1;
1774 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1775 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1776 int minAX
= -1, minAY
= -1;
1777 int maxAX
= -1, maxAY
= -1;
1781 if (wwin
->normal_hints
) {
1782 winc
= wwin
->normal_hints
->width_inc
;
1783 hinc
= wwin
->normal_hints
->height_inc
;
1784 minW
= wwin
->normal_hints
->min_width
;
1785 minH
= wwin
->normal_hints
->min_height
;
1786 maxW
= wwin
->normal_hints
->max_width
;
1787 maxH
= wwin
->normal_hints
->max_height
;
1788 if (wwin
->normal_hints
->flags
& PAspect
) {
1789 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1790 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1791 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1792 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1795 baseW
= wwin
->normal_hints
->base_width
;
1796 baseH
= wwin
->normal_hints
->base_height
;
1809 /* aspect ratio code borrowed from olwm */
1811 /* adjust max aspect ratio */
1812 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1813 if (maxAX
> maxAY
) {
1814 height
= (width
* maxAY
) / maxAX
;
1815 if (height
> maxH
) {
1817 width
= (height
* maxAX
) / maxAY
;
1820 width
= (height
* maxAX
) / maxAY
;
1823 height
= (width
* maxAY
) / maxAX
;
1828 /* adjust min aspect ratio */
1829 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1830 if (minAX
> minAY
) {
1831 height
= (width
* minAY
) / minAX
;
1832 if (height
< minH
) {
1834 width
= (height
* minAX
) / minAY
;
1837 width
= (height
* minAX
) / minAY
;
1840 height
= (width
* minAY
) / minAX
;
1847 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1849 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1852 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1854 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1856 /* broken stupid apps may cause preposterous values for these.. */
1863 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1864 unsigned int *width
, unsigned int *height
)
1866 int baseW
= 0, baseH
= 0;
1867 int winc
= 1, hinc
= 1;
1869 if (wwin
->normal_hints
) {
1870 baseW
= wwin
->normal_hints
->base_width
;
1871 baseH
= wwin
->normal_hints
->base_height
;
1873 winc
= wwin
->normal_hints
->width_inc
;
1874 hinc
= wwin
->normal_hints
->height_inc
;
1878 *width
= maxW
- (maxW
- baseW
) % winc
;
1881 *height
= maxH
- (maxH
- baseH
) % hinc
;
1884 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1886 WScreen
*scr
= wwin
->screen_ptr
;
1890 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1893 if (workspace
!= scr
->current_workspace
) {
1894 /* Sent to other workspace. Unmap window */
1895 if ((wwin
->flags
.mapped
1896 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1897 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1899 wapp
= wApplicationOf(wwin
->main_window
);
1901 wapp
->last_workspace
= workspace
;
1903 if (wwin
->flags
.miniaturized
) {
1905 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1906 wwin
->icon
->mapped
= 0;
1910 wSetFocusTo(scr
, NULL
);
1914 /* brought to current workspace. Map window */
1915 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1917 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1918 wwin
->icon
->mapped
= 1;
1920 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1924 if (!IS_OMNIPRESENT(wwin
)) {
1925 int oldWorkspace
= wwin
->frame
->workspace
;
1926 wwin
->frame
->workspace
= workspace
;
1927 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1934 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1938 sevent
.type
= ConfigureNotify
;
1939 sevent
.xconfigure
.display
= dpy
;
1940 sevent
.xconfigure
.event
= wwin
->client_win
;
1941 sevent
.xconfigure
.window
= wwin
->client_win
;
1943 sevent
.xconfigure
.x
= wwin
->client
.x
;
1944 sevent
.xconfigure
.y
= wwin
->client
.y
;
1945 sevent
.xconfigure
.width
= wwin
->client
.width
;
1946 sevent
.xconfigure
.height
= wwin
->client
.height
;
1948 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1949 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1950 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1952 sevent
.xconfigure
.above
= None
;
1954 sevent
.xconfigure
.override_redirect
= False
;
1955 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1960 *----------------------------------------------------------------------
1961 * wWindowConfigure()
1963 * req_x, req_y: new requested positions for the frame
1964 * req_width, req_height: new requested sizes for the client
1966 * Configures the frame, decorations and client window to the specified
1967 * geometry, whose validity is not checked -- wWindowConstrainSize()
1968 * must be used for that.
1969 * The size parameters are for the client window, but the position is
1971 * The client window receives a ConfigureNotify event, according
1972 * to what ICCCM says.
1978 * Window size and position are changed and client window receives
1979 * a ConfigureNotify event.
1980 *----------------------------------------------------------------------
1982 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1984 int synth_notify
= False
;
1987 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1989 * if the window is being moved but not resized then
1990 * send a synthetic ConfigureNotify
1992 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
1993 synth_notify
= True
;
1995 if (WFLAGP(wwin
, dont_move_off
))
1996 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
1999 if (req_width
< MIN_WINDOW_SIZE
)
2000 req_width
= MIN_WINDOW_SIZE
;
2001 if (req_height
< MIN_WINDOW_SIZE
)
2002 req_height
= MIN_WINDOW_SIZE
;
2004 /* If growing, resize inner part before frame,
2005 * if shrinking, resize frame before.
2006 * This will prevent the frame (that can have a different color)
2007 * to be exposed, causing flicker */
2008 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2009 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2011 if (wwin
->flags
.shaded
) {
2012 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2013 wwin
->old_geometry
.height
= req_height
;
2017 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2019 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
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 wwin
->client
.x
= req_x
;
2026 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2027 wwin
->client
.width
= req_width
;
2028 wwin
->client
.height
= req_height
;
2030 wwin
->client
.x
= req_x
;
2031 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2033 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2035 wwin
->frame_x
= req_x
;
2036 wwin
->frame_y
= req_y
;
2037 if (HAS_BORDER(wwin
)) {
2038 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2039 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2042 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2043 wWindowSetShape(wwin
);
2047 wWindowSynthConfigureNotify(wwin
);
2049 wNETFrameExtents(wwin
);
2054 /* req_x, req_y: new position of the frame */
2055 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2057 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2058 int synth_notify
= False
;
2060 /* Send a synthetic ConfigureNotify event for every window movement. */
2061 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2062 synth_notify
= True
;
2064 /* A single synthetic ConfigureNotify event is sent at the end of
2065 * a completed (opaque) movement in moveres.c */
2068 if (WFLAGP(wwin
, dont_move_off
))
2069 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2070 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2072 wwin
->client
.x
= req_x
;
2073 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2074 if (HAS_BORDER(wwin
)) {
2075 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2076 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2079 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2081 wwin
->frame_x
= req_x
;
2082 wwin
->frame_y
= req_y
;
2084 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2086 wWindowSynthConfigureNotify(wwin
);
2090 void wWindowUpdateButtonImages(WWindow
*wwin
)
2092 WScreen
*scr
= wwin
->screen_ptr
;
2093 Pixmap pixmap
, mask
;
2094 WFrameWindow
*fwin
= wwin
->frame
;
2096 if (!HAS_TITLEBAR(wwin
))
2099 /* miniaturize button */
2100 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2101 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2102 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2104 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2105 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2109 if (fwin
->lbutton_image
2110 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2111 wPixmapDestroy(fwin
->lbutton_image
);
2112 fwin
->lbutton_image
= NULL
;
2115 if (!fwin
->lbutton_image
) {
2116 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2117 fwin
->lbutton_image
->client_owned
= 1;
2118 fwin
->lbutton_image
->client_owned_mask
= 1;
2121 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2122 wPixmapDestroy(fwin
->lbutton_image
);
2124 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2127 #ifdef XKB_BUTTON_HINT
2128 if (!WFLAGP(wwin
, no_language_button
)) {
2129 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2130 wPixmapDestroy(fwin
->languagebutton_image
);
2132 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2138 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2139 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2141 if (!WFLAGP(wwin
, no_close_button
)) {
2142 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2143 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2145 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2146 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2150 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2151 || fwin
->rbutton_image
->mask
!= mask
)) {
2152 wPixmapDestroy(fwin
->rbutton_image
);
2153 fwin
->rbutton_image
= NULL
;
2156 if (!fwin
->rbutton_image
) {
2157 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2158 fwin
->rbutton_image
->client_owned
= 1;
2159 fwin
->rbutton_image
->client_owned_mask
= 1;
2162 } else if (WFLAGP(wwin
, kill_close
)) {
2163 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2164 wPixmapDestroy(fwin
->rbutton_image
);
2166 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2168 } else if (MGFLAGP(wwin
, broken_close
)) {
2169 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2170 wPixmapDestroy(fwin
->rbutton_image
);
2172 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2175 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2176 wPixmapDestroy(fwin
->rbutton_image
);
2178 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2182 /* force buttons to be redrawn */
2183 fwin
->flags
.need_texture_change
= 1;
2184 wFrameWindowPaint(fwin
);
2188 *---------------------------------------------------------------------------
2189 * wWindowConfigureBorders--
2190 * Update window border configuration according to attribute flags.
2192 *---------------------------------------------------------------------------
2194 void wWindowConfigureBorders(WWindow
*wwin
)
2200 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2202 #ifdef XKB_BUTTON_HINT
2203 if (wPreferences
.modelock
)
2204 flags
|= WFF_LANGUAGE_BUTTON
;
2207 if (HAS_TITLEBAR(wwin
))
2208 flags
|= WFF_TITLEBAR
;
2209 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2210 flags
|= WFF_RESIZEBAR
;
2211 if (HAS_BORDER(wwin
))
2212 flags
|= WFF_BORDER
;
2213 if (wwin
->flags
.shaded
)
2214 flags
|= WFF_IS_SHADED
;
2216 oldh
= wwin
->frame
->top_width
;
2217 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2218 if (oldh
!= wwin
->frame
->top_width
) {
2219 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2221 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2222 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2226 if (!WFLAGP(wwin
, no_miniaturize_button
)
2227 && wwin
->frame
->flags
.hide_left_button
)
2228 flags
|= WFF_LEFT_BUTTON
;
2230 #ifdef XKB_BUTTON_HINT
2231 if (!WFLAGP(wwin
, no_language_button
)
2232 && wwin
->frame
->flags
.hide_language_button
)
2233 flags
|= WFF_LANGUAGE_BUTTON
;
2236 if (!WFLAGP(wwin
, no_close_button
)
2237 && wwin
->frame
->flags
.hide_right_button
)
2238 flags
|= WFF_RIGHT_BUTTON
;
2241 wWindowUpdateButtonImages(wwin
);
2242 wFrameWindowShowButton(wwin
->frame
, flags
);
2246 if (WFLAGP(wwin
, no_miniaturize_button
)
2247 && !wwin
->frame
->flags
.hide_left_button
)
2248 flags
|= WFF_LEFT_BUTTON
;
2250 #ifdef XKB_BUTTON_HINT
2251 if (WFLAGP(wwin
, no_language_button
)
2252 && !wwin
->frame
->flags
.hide_language_button
)
2253 flags
|= WFF_LANGUAGE_BUTTON
;
2256 if (WFLAGP(wwin
, no_close_button
)
2257 && !wwin
->frame
->flags
.hide_right_button
)
2258 flags
|= WFF_RIGHT_BUTTON
;
2261 wFrameWindowHideButton(wwin
->frame
, flags
);
2264 if (wShapeSupported
&& wwin
->flags
.shaped
)
2265 wWindowSetShape(wwin
);
2270 void wWindowSaveState(WWindow
* wwin
)
2275 memset(data
, 0, sizeof(long) * 10);
2276 data
[0] = wwin
->frame
->workspace
;
2277 data
[1] = wwin
->flags
.miniaturized
;
2278 data
[2] = wwin
->flags
.shaded
;
2279 data
[3] = wwin
->flags
.hidden
;
2280 data
[4] = wwin
->flags
.maximized
;
2281 if (wwin
->flags
.maximized
== 0) {
2282 data
[5] = wwin
->frame_x
;
2283 data
[6] = wwin
->frame_y
;
2284 data
[7] = wwin
->frame
->core
->width
;
2285 data
[8] = wwin
->frame
->core
->height
;
2287 data
[5] = wwin
->old_geometry
.x
;
2288 data
[6] = wwin
->old_geometry
.y
;
2289 data
[7] = wwin
->old_geometry
.width
;
2290 data
[8] = wwin
->old_geometry
.height
;
2293 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2294 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2295 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2298 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2299 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2302 static int getSavedState(Window window
, WSavedState
** state
)
2306 unsigned long nitems_ret
;
2307 unsigned long bytes_after_ret
;
2310 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2311 True
, _XA_WINDOWMAKER_STATE
,
2312 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2313 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2316 *state
= wmalloc(sizeof(WSavedState
));
2318 (*state
)->workspace
= data
[0];
2319 (*state
)->miniaturized
= data
[1];
2320 (*state
)->shaded
= data
[2];
2321 (*state
)->hidden
= data
[3];
2322 (*state
)->maximized
= data
[4];
2323 (*state
)->x
= data
[5];
2324 (*state
)->y
= data
[6];
2325 (*state
)->w
= data
[7];
2326 (*state
)->h
= data
[8];
2327 (*state
)->window_shortcuts
= data
[9];
2331 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2338 void wWindowClearShape(WWindow
* wwin
)
2340 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2341 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2345 void wWindowSetShape(WWindow
* wwin
)
2349 #ifdef OPTIMIZE_SHAPE
2354 /* only shape is the client's */
2355 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2358 /* Get array of rectangles describing the shape mask */
2359 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2363 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2369 /* insert our decoration rectangles in the rect list */
2370 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2373 if (HAS_TITLEBAR(wwin
)) {
2375 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2376 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2377 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2380 if (HAS_RESIZEBAR(wwin
)) {
2382 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2383 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2384 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2388 /* shape our frame window */
2389 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2390 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2396 #endif /* OPTIMIZE_SHAPE */
2398 if (HAS_TITLEBAR(wwin
)) {
2401 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2402 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2405 if (HAS_RESIZEBAR(wwin
)) {
2407 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2408 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2409 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2413 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2414 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2416 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2417 0, wwin
->frame
->top_width
, wwin
->client_win
,
2418 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2423 /* ====================================================================== */
2425 static FocusMode
getFocusMode(WWindow
* wwin
)
2429 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2430 if (wwin
->wm_hints
->input
== True
) {
2431 if (wwin
->protocols
.TAKE_FOCUS
)
2432 mode
= WFM_LOCALLY_ACTIVE
;
2436 if (wwin
->protocols
.TAKE_FOCUS
)
2437 mode
= WFM_GLOBALLY_ACTIVE
;
2439 mode
= WFM_NO_INPUT
;
2447 void wWindowSetKeyGrabs(WWindow
* wwin
)
2452 for (i
= 0; i
< WKBD_LAST
; i
++) {
2453 key
= &wKeyBindings
[i
];
2455 if (key
->keycode
== 0)
2457 if (key
->modifier
!= AnyModifier
) {
2458 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2459 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2461 /* Also grab all modifier combinations possible that include,
2462 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2463 * work even if the NumLock/ScrollLock key is on.
2465 wHackedGrabKey(key
->keycode
, key
->modifier
,
2466 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2469 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2470 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2473 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2476 void wWindowResetMouseGrabs(WWindow
* wwin
)
2478 /* Mouse grabs can't be done on the client window because of
2479 * ICCCM and because clients that try to do the same will crash.
2481 * But there is a problem wich makes tbar buttons of unfocused
2482 * windows not usable as the click goes to the frame window instead
2483 * of the button itself. Must figure a way to fix that.
2486 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2488 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2489 /* grabs for Meta+drag */
2490 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2491 True
, ButtonPressMask
| ButtonReleaseMask
,
2492 GrabModeSync
, GrabModeAsync
, None
, None
);
2494 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2495 * but we only grab it for Button4 and Button 5 since a lot of apps
2496 * use CTRL+Button1-3 for app related functionality
2498 if (wPreferences
.resize_increment
> 0) {
2499 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2500 True
, ButtonPressMask
| ButtonReleaseMask
,
2501 GrabModeSync
, GrabModeAsync
, None
, None
);
2502 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2503 True
, ButtonPressMask
| ButtonReleaseMask
,
2504 GrabModeSync
, GrabModeAsync
, None
, None
);
2506 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2507 True
, ButtonPressMask
| ButtonReleaseMask
,
2508 GrabModeSync
, GrabModeAsync
, None
, None
);
2509 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2510 True
, ButtonPressMask
| ButtonReleaseMask
,
2511 GrabModeSync
, GrabModeAsync
, None
, None
);
2515 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2516 && !wwin
->flags
.is_gnustep
) {
2517 /* the passive grabs to focus the window */
2518 /* if (wPreferences.focus_mode == WKF_CLICK) */
2519 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2520 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2525 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2527 if (attr
->flags
& GSExtraFlagsAttr
) {
2528 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2529 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2530 wWindowUpdateButtonImages(wwin
);
2535 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2537 WWindowState
*wstate
;
2539 wstate
= malloc(sizeof(WWindowState
));
2543 memset(wstate
, 0, sizeof(WWindowState
));
2546 wstate
->instance
= wstrdup(instance
);
2548 wstate
->class = wstrdup(class);
2550 wstate
->command
= wstrdup(command
);
2551 wstate
->state
= state
;
2553 wstate
->next
= windowState
;
2554 windowState
= wstate
;
2559 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2561 WMagicNumber
wWindowGetSavedState(Window win
)
2563 char *instance
, *class, *command
= NULL
;
2564 WWindowState
*wstate
= windowState
;
2569 command
= GetCommandForWindow(win
);
2573 if (PropGetWMClass(win
, &class, &instance
)) {
2575 if (SAME(instance
, wstate
->instance
) &&
2576 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2579 wstate
= wstate
->next
;
2595 void wWindowDeleteSavedState(WMagicNumber id
)
2597 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2599 if (!wstate
|| !windowState
)
2603 if (tmp
== wstate
) {
2604 windowState
= wstate
->next
;
2605 remove_wwindowstate(wstate
);
2608 if (tmp
->next
== wstate
) {
2609 tmp
->next
= wstate
->next
;
2610 remove_wwindowstate(wstate
);
2618 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2620 WWindowState
*tmp
, *wstate
;
2626 if (tmp
->pid
== pid
) {
2627 wstate
= windowState
;
2628 windowState
= tmp
->next
;
2630 remove_wwindowstate(wstate
);
2633 if (tmp
->next
->pid
== pid
) {
2635 tmp
->next
= wstate
->next
;
2636 remove_wwindowstate(wstate
);
2644 static void remove_wwindowstate(WWindowState
*wstate
)
2646 if (wstate
->instance
)
2647 wfree(wstate
->instance
);
2650 wfree(wstate
->class);
2652 if (wstate
->command
)
2653 wfree(wstate
->command
);
2655 wfree(wstate
->state
);
2659 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2661 if (wwin
->flags
.omnipresent
== flag
)
2664 wwin
->flags
.omnipresent
= flag
;
2665 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2668 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2670 WWindow
*wwin
= data
;
2672 #ifndef NUMLOCK_HACK
2673 if ((event
->xbutton
.state
& ValidModMask
)
2674 != (event
->xbutton
.state
& ~LockMask
)) {
2675 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2676 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2680 event
->xbutton
.state
&= ValidModMask
;
2682 CloseWindowMenu(wwin
->screen_ptr
);
2684 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2685 && !WFLAGP(wwin
, no_focusable
)) {
2686 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2689 if (event
->xbutton
.button
== Button1
)
2690 wRaiseFrame(wwin
->frame
->core
);
2692 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2693 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2694 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2695 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2700 if (event
->xbutton
.state
& MOD_MASK
) {
2701 /* move the window */
2702 wMouseMoveWindow(wwin
, event
);
2703 XUngrabPointer(dpy
, CurrentTime
);
2705 wMouseResizeWindow(wwin
, event
);
2706 XUngrabPointer(dpy
, CurrentTime
);
2710 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2712 WWindow
*wwin
= data
;
2714 event
->xbutton
.state
&= ValidModMask
;
2716 if (event
->xbutton
.button
== Button1
) {
2717 if (event
->xbutton
.state
== 0) {
2718 if (!WFLAGP(wwin
, no_shadeable
)) {
2720 if (wwin
->flags
.shaded
)
2721 wUnshadeWindow(wwin
);
2728 if (event
->xbutton
.state
& ControlMask
)
2729 dir
|= MAX_VERTICAL
;
2731 if (event
->xbutton
.state
& ShiftMask
) {
2732 dir
|= MAX_HORIZONTAL
;
2733 if (!(event
->xbutton
.state
& ControlMask
))
2734 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2737 /* maximize window */
2738 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2739 int ndir
= dir
^ wwin
->flags
.maximized
;
2742 wMaximizeWindow(wwin
, ndir
);
2744 wUnmaximizeWindow(wwin
);
2747 } else if (event
->xbutton
.button
== Button3
) {
2748 if (event
->xbutton
.state
& MOD_MASK
)
2749 wHideOtherApplications(wwin
);
2750 } else if (event
->xbutton
.button
== Button2
) {
2751 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2752 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2754 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2755 wUnshadeWindow(wwin
);
2759 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2761 WWindow
*wwin
= desc
->parent
;
2762 unsigned int new_width
, w_scale
;
2763 unsigned int new_height
, h_scale
;
2764 unsigned int resize_width_increment
= 0;
2765 unsigned int resize_height_increment
= 0;
2767 if (wwin
->normal_hints
) {
2768 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2769 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2770 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2771 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2773 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2774 resize_width_increment
= wPreferences
.resize_increment
;
2775 resize_height_increment
= wPreferences
.resize_increment
;
2778 event
->xbutton
.state
&= ValidModMask
;
2780 CloseWindowMenu(wwin
->screen_ptr
);
2782 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2783 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2785 if (event
->xbutton
.button
== Button1
)
2786 wRaiseFrame(wwin
->frame
->core
);
2788 if (event
->xbutton
.state
& ControlMask
) {
2789 if (event
->xbutton
.button
== Button4
) {
2790 new_width
= wwin
->client
.width
- resize_width_increment
;
2791 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2792 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2794 if (event
->xbutton
.button
== Button5
) {
2795 new_width
= wwin
->client
.width
+ resize_width_increment
;
2796 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2797 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2801 if (event
->xbutton
.state
& MOD_MASK
) {
2802 /* move the window */
2803 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2804 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2805 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2808 if (event
->xbutton
.button
== Button3
) {
2809 wMouseResizeWindow(wwin
, event
);
2810 } else if (event
->xbutton
.button
== Button4
) {
2811 new_height
= wwin
->client
.height
- resize_height_increment
;
2812 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2813 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2814 } else if (event
->xbutton
.button
== Button5
) {
2815 new_height
= wwin
->client
.height
+ resize_height_increment
;
2816 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2817 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2818 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2819 wMouseMoveWindow(wwin
, event
);
2821 XUngrabPointer(dpy
, CurrentTime
);
2825 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2827 WWindow
*wwin
= (WWindow
*) data
;
2829 #ifndef NUMLOCK_HACK
2830 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2831 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2832 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2834 event
->xbutton
.state
&= ValidModMask
;
2836 CloseWindowMenu(wwin
->screen_ptr
);
2838 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2839 && !WFLAGP(wwin
, no_focusable
))
2840 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2842 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2844 if (event
->xbutton
.button
== Button1
) {
2845 if (event
->xbutton
.state
& MOD_MASK
)
2846 wLowerFrame(wwin
->frame
->core
);
2848 wRaiseFrame(wwin
->frame
->core
);
2850 if ((event
->xbutton
.state
& ShiftMask
)
2851 && !(event
->xbutton
.state
& ControlMask
)) {
2852 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2855 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2856 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2857 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2858 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2862 /* move the window */
2863 wMouseMoveWindow(wwin
, event
);
2865 XUngrabPointer(dpy
, CurrentTime
);
2866 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2867 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2868 WObjDescriptor
*desc
;
2870 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2871 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2872 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2873 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2877 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2879 /* allow drag select */
2880 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2881 event
->xany
.send_event
= True
;
2882 (*desc
->handle_mousedown
) (desc
, event
);
2884 XUngrabPointer(dpy
, CurrentTime
);
2888 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2890 WWindow
*wwin
= data
;
2892 event
->xbutton
.state
&= ValidModMask
;
2894 CloseWindowMenu(wwin
->screen_ptr
);
2896 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2899 /* if control-click, kill the client */
2900 if (event
->xbutton
.state
& ControlMask
) {
2903 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2904 /* send delete message */
2905 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2910 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2912 WWindow
*wwin
= data
;
2914 CloseWindowMenu(wwin
->screen_ptr
);
2916 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2919 /* send delete message */
2920 if (wwin
->protocols
.DELETE_WINDOW
)
2921 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2926 #ifdef XKB_BUTTON_HINT
2927 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2929 WWindow
*wwin
= data
;
2930 WFrameWindow
*fwin
= wwin
->frame
;
2931 WScreen
*scr
= fwin
->screen_ptr
;
2934 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2936 tl
= wwin
->frame
->languagemode
;
2937 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2938 wwin
->frame
->last_languagemode
= tl
;
2939 wSetFocusTo(scr
, wwin
);
2940 wwin
->frame
->languagebutton_image
=
2941 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2942 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2943 if (event
->xbutton
.button
== Button3
)
2945 wRaiseFrame(fwin
->core
);
2949 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2951 WWindow
*wwin
= data
;
2953 event
->xbutton
.state
&= ValidModMask
;
2955 CloseWindowMenu(wwin
->screen_ptr
);
2957 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2960 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2961 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
2964 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2966 wapp
= wApplicationOf(wwin
->main_window
);
2967 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2968 wHideApplication(wapp
);
2969 } else if (event
->xbutton
.state
== 0) {
2970 wIconifyWindow(wwin
);