1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
29 #ifdef KEEP_XKB_LOCK_STATUS
30 #include <X11/XKBlib.h>
31 #endif /* KEEP_XKB_LOCK_STATUS */
38 /* For getting mouse wheel mappings from WINGs */
39 #include <WINGs/WINGsP.h>
41 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
56 #include "workspace.h"
60 #include "superfluous.h"
67 #define MOD_MASK wPreferences.modifier_mask
69 /****** Global Variables ******/
70 extern WShortKey wKeyBindings
[WKBD_LAST
];
73 extern Bool wShapeSupported
;
77 extern XContext wWinContext
;
80 extern Atom _XA_WM_DELETE_WINDOW
;
81 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
82 extern Atom _XA_WINDOWMAKER_STATE
;
83 extern WPreferences wPreferences
;
84 extern Time LastTimestamp
;
86 /***** Local Stuff *****/
87 static WWindowState
*windowState
= NULL
;
88 static FocusMode
getFocusMode(WWindow
*wwin
);
89 static int getSavedState(Window window
, WSavedState
**state
);
90 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
92 /* frame window (during window grabs) */
93 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
96 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
97 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
100 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 #ifdef XKB_BUTTON_HINT
103 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
106 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
107 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
110 /****** Notification Observers ******/
112 static void appearanceObserver(void *self
, WMNotification
* notif
)
114 WWindow
*wwin
= (WWindow
*) self
;
115 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
117 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
120 if (flags
& WFontSettings
) {
121 wWindowConfigureBorders(wwin
);
122 if (wwin
->flags
.shaded
) {
123 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
124 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
125 wWindowSynthConfigureNotify(wwin
);
128 if (flags
& WTextureSettings
)
129 wwin
->frame
->flags
.need_texture_remake
= 1;
131 if (flags
& (WTextureSettings
| WColorSettings
)) {
132 if (wwin
->frame
->titlebar
)
133 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
135 wFrameWindowPaint(wwin
->frame
);
140 WWindow
*wWindowFor(Window window
)
142 WObjDescriptor
*desc
;
147 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
150 if (desc
->parent_type
== WCLASS_WINDOW
)
152 else if (desc
->parent_type
== WCLASS_FRAME
) {
153 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
154 if (frame
->flags
.is_client_window_frame
)
161 WWindow
*wWindowCreate(void)
165 wwin
= wmalloc(sizeof(WWindow
));
168 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
169 wwin
->client_descriptor
.parent
= wwin
;
170 wwin
->client_descriptor
.self
= wwin
;
171 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
176 void wWindowDestroy(WWindow
*wwin
)
180 if (wwin
->screen_ptr
->cmap_window
== wwin
)
181 wwin
->screen_ptr
->cmap_window
= NULL
;
183 WMRemoveNotificationObserver(wwin
);
185 wwin
->flags
.destroyed
= 1;
187 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
188 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
191 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
193 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
194 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
195 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
199 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
200 wwin
->fake_group
->retainCount
--;
201 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
202 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
203 wwin
->fake_group
->leader
= None
;
204 wwin
->fake_group
->origLeader
= None
;
209 if (wwin
->normal_hints
)
210 XFree(wwin
->normal_hints
);
213 XFree(wwin
->wm_hints
);
215 if (wwin
->wm_instance
)
216 XFree(wwin
->wm_instance
);
219 XFree(wwin
->wm_class
);
221 if (wwin
->wm_gnustep_attr
)
222 wfree(wwin
->wm_gnustep_attr
);
224 if (wwin
->cmap_windows
)
225 XFree(wwin
->cmap_windows
);
227 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
230 wFrameWindowDestroy(wwin
->frame
);
233 RemoveFromStackList(wwin
->icon
->core
);
234 wIconDestroy(wwin
->icon
);
235 if (wPreferences
.auto_arrange_icons
)
236 wArrangeIcons(wwin
->screen_ptr
, True
);
238 if (wwin
->net_icon_image
)
239 RReleaseImage(wwin
->net_icon_image
);
244 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
246 if (gs_hints
->flags
& GSWindowStyleAttr
) {
247 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
248 wwin
->client_flags
.no_border
= 1;
249 wwin
->client_flags
.no_titlebar
= 1;
250 wwin
->client_flags
.no_closable
= 1;
251 wwin
->client_flags
.no_miniaturizable
= 1;
252 wwin
->client_flags
.no_resizable
= 1;
253 wwin
->client_flags
.no_close_button
= 1;
254 wwin
->client_flags
.no_miniaturize_button
= 1;
255 wwin
->client_flags
.no_resizebar
= 1;
257 wwin
->client_flags
.no_close_button
=
258 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
260 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
262 wwin
->client_flags
.no_miniaturize_button
=
263 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
265 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
267 wwin
->client_flags
.no_resizebar
=
268 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
270 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
272 /* these attributes supposedly imply in the existence
274 if (gs_hints
->window_style
& (WMResizableWindowMask
|
275 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
276 wwin
->client_flags
.no_titlebar
= 0;
278 wwin
->client_flags
.no_titlebar
=
279 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
284 /* setup the defaults */
285 wwin
->client_flags
.no_border
= 0;
286 wwin
->client_flags
.no_titlebar
= 0;
287 wwin
->client_flags
.no_closable
= 0;
288 wwin
->client_flags
.no_miniaturizable
= 0;
289 wwin
->client_flags
.no_resizable
= 0;
290 wwin
->client_flags
.no_close_button
= 0;
291 wwin
->client_flags
.no_miniaturize_button
= 0;
292 wwin
->client_flags
.no_resizebar
= 0;
294 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
295 wwin
->client_flags
.no_appicon
= 1;
298 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
300 WScreen
*scr
= wwin
->screen_ptr
;
302 /* sets global default stuff */
303 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
305 * Decoration setting is done in this precedence (lower to higher)
306 * - use global default in the resource database
307 * - guess some settings
308 * - use GNUstep/external window attributes
309 * - set hints specified for the app in the resource DB
312 WSETUFLAG(wwin
, broken_close
, 0);
314 if (wwin
->protocols
.DELETE_WINDOW
)
315 WSETUFLAG(wwin
, kill_close
, 0);
317 WSETUFLAG(wwin
, kill_close
, 1);
319 /* transients can't be iconified or maximized */
320 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
321 WSETUFLAG(wwin
, no_miniaturizable
, 1);
322 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
325 /* if the window can't be resized, remove the resizebar */
326 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
327 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
328 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
329 WSETUFLAG(wwin
, no_resizable
, 1);
330 WSETUFLAG(wwin
, no_resizebar
, 1);
333 /* set GNUstep window attributes */
334 if (wwin
->wm_gnustep_attr
) {
335 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
337 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
339 *level
= wwin
->wm_gnustep_attr
->window_level
;
341 * INT_MIN is the only illegal window level.
343 if (*level
== INT_MIN
)
344 *level
= INT_MIN
+ 1;
347 *level
= WMNormalLevel
;
350 int tmp_workspace
= -1;
351 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
357 wMWMCheckClientHints(wwin
);
358 #endif /* MWM_HINTS */
361 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
363 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
364 * have INT_MIN that means that no window level was requested. -Dan
366 if (tmp_level
== INT_MIN
) {
367 if (WFLAGP(wwin
, floating
))
368 *level
= WMFloatingLevel
;
369 else if (WFLAGP(wwin
, sunken
))
370 *level
= WMSunkenLevel
;
372 *level
= WMNormalLevel
;
377 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
378 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
379 if (transientOwner
) {
380 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
381 if (ownerLevel
> *level
)
386 if (tmp_workspace
>= 0)
387 *workspace
= tmp_workspace
% scr
->workspace_count
;
391 * Set attributes specified only for that window/class.
392 * This might do duplicate work with the 1st wDefaultFillAttributes().
394 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
395 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
397 * Sanity checks for attributes that depend on other attributes
399 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
400 wwin
->user_flags
.emulate_appicon
= 0;
402 if (wwin
->main_window
!= None
) {
403 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
404 if (wapp
&& !wapp
->flags
.emulated
)
405 wwin
->user_flags
.emulate_appicon
= 0;
408 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
409 wwin
->user_flags
.emulate_appicon
= 0;
411 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
412 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
413 wwin
->user_flags
.sunken
= 0;
415 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
417 /* windows that have takefocus=False shouldn't take focus at all */
418 if (wwin
->focus_mode
== WFM_NO_INPUT
)
419 wwin
->client_flags
.no_focusable
= 1;
422 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
424 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
426 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
428 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
434 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
438 w1
= wwin
->frame
->core
->width
;
439 h1
= wwin
->frame
->core
->height
;
440 w2
= obscured
->frame
->core
->width
;
441 h2
= obscured
->frame
->core
->height
;
443 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
444 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
447 if (wwin
->frame_x
+ w1
< obscured
->frame_x
448 || wwin
->frame_y
+ h1
< obscured
->frame_y
449 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
455 static void fixLeaderProperties(WWindow
*wwin
)
457 XClassHint
*classHint
;
458 XWMHints
*hints
, *clientHints
;
459 XWindowAttributes attr
;
460 Window leaders
[2], window
;
461 char **argv
, *command
;
465 classHint
= XAllocClassHint();
466 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
467 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
469 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
473 leaders
[0] = wwin
->client_leader
;
474 leaders
[1] = wwin
->group_id
;
477 command
= GetCommandForWindow(wwin
->client_win
);
479 wfree(command
); /* command already set. nothing to do. */
481 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
484 for (i
= 0; i
< 2; i
++) {
487 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
488 classHint
->res_name
= wwin
->wm_instance
;
489 classHint
->res_class
= wwin
->wm_class
;
490 XSetClassHint(dpy
, window
, classHint
);
492 hints
= XGetWMHints(dpy
, window
);
495 } else if (clientHints
) {
496 /* set window group leader to self */
497 clientHints
->window_group
= window
;
498 clientHints
->flags
|= WindowGroupHint
;
499 XSetWMHints(dpy
, window
, clientHints
);
503 command
= GetCommandForWindow(window
);
505 wfree(command
); /* command already set. nothing to do. */
507 XSetCommand(dpy
, window
, argv
, argc
);
510 /* Make sure we get notification when this window is destroyed */
511 if (XGetWindowAttributes(dpy
, window
, &attr
))
512 XSelectInput(dpy
, window
, attr
.your_event_mask
| StructureNotifyMask
| PropertyChangeMask
);
523 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
525 XClassHint
*classHint
;
531 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
533 classHint
= XAllocClassHint();
534 classHint
->res_name
= instance
;
535 classHint
->res_class
= class;
536 XSetClassHint(dpy
, leader
, classHint
);
539 /* inherit these from the original leader if available */
540 hints
= XGetWMHints(dpy
, win
);
542 hints
= XAllocWMHints();
545 /* set window group leader to self */
546 hints
->window_group
= leader
;
547 hints
->flags
|= WindowGroupHint
;
548 XSetWMHints(dpy
, leader
, hints
);
551 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
552 XSetCommand(dpy
, leader
, argv
, argc
);
553 XFreeStringList(argv
);
559 static int matchIdentifier(const void *item
, const void *cdata
)
561 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
565 *----------------------------------------------------------------
567 * reparents the window and allocates a descriptor for it.
568 * Window manager hints and other hints are fetched to configure
569 * the window decoration attributes and others. User preferences
570 * for the window are used if available, to configure window
571 * decorations and some behaviour.
572 * If in startup, windows that are override redirect,
573 * unmapped and never were managed and are Withdrawn are not
577 * the new window descriptor
580 * The window is reparented and appropriate notification
581 * is done to the client. Input mask for the window is setup.
582 * The window descriptor is also associated with various window
583 * contexts and inserted in the head of the window list.
584 * Event handler contexts are associated for some objects
585 * (buttons, titlebar and resizebar)
587 *----------------------------------------------------------------
589 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
593 unsigned width
, height
;
594 XWindowAttributes wattribs
;
595 XSetWindowAttributes attribs
;
596 WWindowState
*win_state
;
597 WWindow
*transientOwner
= NULL
;
603 Bool withdraw
= False
;
609 /* make sure the window is still there */
610 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
615 /* if it's an override-redirect, ignore it */
616 if (wattribs
.override_redirect
) {
621 wm_state
= PropGetWindowState(window
);
623 /* if it's startup and the window is unmapped, don't manage it */
624 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
629 wwin
= wWindowCreate();
631 title
= wNETWMGetWindowName(window
);
633 wwin
->flags
.net_has_title
= 1;
634 if (!title
&& !wFetchName(dpy
, window
, &title
))
637 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
640 if (wShapeSupported
) {
645 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
646 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
647 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
648 wwin
->flags
.shaped
= b_shaped
;
653 * Get hints and other information in properties
655 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
657 /* setup descriptor */
658 wwin
->client_win
= window
;
659 wwin
->screen_ptr
= scr
;
660 wwin
->old_border_width
= wattribs
.border_width
;
661 wwin
->event_mask
= CLIENT_EVENTS
;
662 attribs
.event_mask
= CLIENT_EVENTS
;
663 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
664 attribs
.save_under
= False
;
666 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
667 XSetWindowBorderWidth(dpy
, window
, 0);
669 /* get hints from GNUstep app */
670 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0)
671 wwin
->flags
.is_gnustep
= 1;
673 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
))
674 wwin
->wm_gnustep_attr
= NULL
;
676 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
677 wwin
->flags
.is_dockapp
= 1;
681 wwin
->client_leader
= PropGetClientLeader(window
);
682 if (wwin
->client_leader
!= None
)
683 wwin
->main_window
= wwin
->client_leader
;
685 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
687 if (wwin
->wm_hints
) {
688 if (wwin
->wm_hints
->flags
& StateHint
) {
690 if (wwin
->wm_hints
->initial_state
== IconicState
) {
691 wwin
->flags
.miniaturized
= 1;
692 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
693 wwin
->flags
.is_dockapp
= 1;
698 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
699 wwin
->group_id
= wwin
->wm_hints
->window_group
;
700 /* window_group has priority over CLIENT_LEADER */
701 wwin
->main_window
= wwin
->group_id
;
703 wwin
->group_id
= None
;
706 if (wwin
->wm_hints
->flags
& UrgencyHint
) {
707 wwin
->flags
.urgent
= 1;
708 wAppBounceWhileUrgent(wApplicationOf(wwin
->main_window
));
711 wwin
->group_id
= None
;
714 PropGetProtocols(window
, &wwin
->protocols
);
716 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
717 wwin
->transient_for
= None
;
719 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
720 wwin
->transient_for
= scr
->root_win
;
722 transientOwner
= wWindowFor(wwin
->transient_for
);
723 if (transientOwner
&& transientOwner
->main_window
!= None
)
724 wwin
->main_window
= transientOwner
->main_window
;
728 /* guess the focus mode */
729 wwin
->focus_mode
= getFocusMode(wwin
);
731 /* get geometry stuff */
732 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
734 /* get colormap windows */
735 GetColormapWindows(wwin
);
738 * Setup the decoration/window attributes and
741 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
743 /* Make broken apps behave as a nice app. */
744 if (WFLAGP(wwin
, emulate_appicon
))
745 wwin
->main_window
= wwin
->client_win
;
747 fixLeaderProperties(wwin
);
749 wwin
->orig_main_window
= wwin
->main_window
;
751 if (wwin
->flags
.is_gnustep
)
752 WSETUFLAG(wwin
, shared_appicon
, 0);
754 if (wwin
->main_window
) {
755 extern Atom _XA_WINDOWMAKER_MENU
;
756 XTextProperty text_prop
;
758 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
))
759 WSETUFLAG(wwin
, shared_appicon
, 0);
762 if (wwin
->flags
.is_dockapp
)
763 WSETUFLAG(wwin
, shared_appicon
, 0);
765 if (wwin
->main_window
) {
766 WApplication
*app
= wApplicationOf(wwin
->main_window
);
767 if (app
&& app
->app_icon
)
768 WSETUFLAG(wwin
, shared_appicon
, 0);
771 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
772 char *buffer
, *instance
, *class;
773 WFakeGroupLeader
*fPtr
;
776 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
778 /* // only enter here if PropGetWMClass() succeds */
779 PropGetWMClass(wwin
->main_window
, &class, &instance
);
780 buffer
= StrConcatDot(instance
, class);
782 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
783 if (index
!= WANotFound
) {
784 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
785 if (fPtr
->retainCount
== 0)
786 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
790 if (fPtr
->origLeader
== None
) {
791 if (ADEQUATE(wwin
->main_window
)) {
793 fPtr
->origLeader
= wwin
->main_window
;
796 wwin
->fake_group
= fPtr
;
797 /*wwin->group_id = fPtr->leader; */
798 wwin
->main_window
= fPtr
->leader
;
801 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
803 fPtr
->identifier
= buffer
;
804 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
805 fPtr
->origLeader
= None
;
806 fPtr
->retainCount
= 1;
808 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
810 if (ADEQUATE(wwin
->main_window
)) {
812 fPtr
->origLeader
= wwin
->main_window
;
814 wwin
->fake_group
= fPtr
;
815 /*wwin->group_id = fPtr->leader; */
816 wwin
->main_window
= fPtr
->leader
;
826 * Setup the initial state of the window
828 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
829 wwin
->flags
.miniaturized
= 1;
831 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
832 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
834 wNETWMCheckInitialClientState(wwin
);
836 /* apply previous state if it exists and we're in startup */
837 if (scr
->flags
.startup
&& wm_state
>= 0) {
838 if (wm_state
== IconicState
) {
839 wwin
->flags
.miniaturized
= 1;
840 } else if (wm_state
== WithdrawnState
) {
845 /* if there is a saved state (from file), restore it */
847 if (wwin
->main_window
!= None
)
848 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
850 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
852 if (win_state
&& !withdraw
) {
853 if (win_state
->state
->hidden
> 0)
854 wwin
->flags
.hidden
= win_state
->state
->hidden
;
856 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
857 wwin
->flags
.shaded
= win_state
->state
->shaded
;
859 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
))
860 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
862 if (!IS_OMNIPRESENT(wwin
)) {
863 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
865 if (w
< 0 || w
>= scr
->workspace_count
) {
866 workspace
= win_state
->state
->workspace
;
867 if (workspace
>= scr
->workspace_count
)
868 workspace
= scr
->current_workspace
;
873 workspace
= scr
->current_workspace
;
877 /* if we're restarting, restore saved state (from hints).
878 * This will overwrite previous */
882 if (getSavedState(window
, &wstate
)) {
883 wwin
->flags
.shaded
= wstate
->shaded
;
884 wwin
->flags
.hidden
= wstate
->hidden
;
885 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
886 wwin
->flags
.maximized
= wstate
->maximized
;
887 if (wwin
->flags
.maximized
) {
888 wwin
->old_geometry
.x
= wstate
->x
;
889 wwin
->old_geometry
.y
= wstate
->y
;
890 wwin
->old_geometry
.width
= wstate
->w
;
891 wwin
->old_geometry
.height
= wstate
->h
;
894 workspace
= wstate
->workspace
;
899 /* restore window shortcut */
900 if (wstate
!= NULL
|| win_state
!= NULL
) {
903 if (win_state
!= NULL
)
904 mask
= win_state
->state
->window_shortcuts
;
906 if (wstate
!= NULL
&& mask
== 0)
907 mask
= wstate
->window_shortcuts
;
912 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
913 if (mask
& (1 << i
)) {
914 if (!scr
->shortcutWindows
[i
])
915 scr
->shortcutWindows
[i
] = WMCreateArray(4);
917 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
926 /* don't let transients start miniaturized if their owners are not */
927 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
928 wwin
->flags
.miniaturized
= 0;
930 wwin
->wm_hints
->initial_state
= NormalState
;
933 /* set workspace on which the window starts */
934 if (workspace
>= 0) {
935 if (workspace
> scr
->workspace_count
- 1)
936 workspace
= workspace
% scr
->workspace_count
;
940 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
942 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
945 if (wPreferences
.open_transients_with_parent
&& transientOwner
)
946 workspace
= transientOwner
->frame
->workspace
;
948 workspace
= scr
->current_workspace
;
952 /* setup window geometry */
953 if (win_state
&& win_state
->state
->w
> 0) {
954 width
= win_state
->state
->w
;
955 height
= win_state
->state
->h
;
957 wWindowConstrainSize(wwin
, &width
, &height
);
959 /* do not ask for window placement if the window is
960 * transient, during startup, if the initial workspace is another one
961 * or if the window wants to start iconic.
962 * If geometry was saved, restore it. */
964 Bool dontBring
= False
;
966 if (win_state
&& win_state
->state
->w
> 0) {
967 x
= win_state
->state
->x
;
968 y
= win_state
->state
->y
;
969 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
970 && !scr
->flags
.startup
971 && workspace
== scr
->current_workspace
972 && !wwin
->flags
.miniaturized
973 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
975 if (transientOwner
&& transientOwner
->flags
.mapped
) {
976 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
980 x
= transientOwner
->frame_x
+
981 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
982 y
= transientOwner
->frame_y
+
983 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
986 * limit transient windows to be inside their parent's head
988 rect
.pos
.x
= transientOwner
->frame_x
;
989 rect
.pos
.y
= transientOwner
->frame_y
;
990 rect
.size
.width
= transientOwner
->frame
->core
->width
;
991 rect
.size
.height
= transientOwner
->frame
->core
->height
;
993 head
= wGetHeadForRect(scr
, rect
);
994 rect
= wGetRectForHead(scr
, head
);
998 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
999 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1003 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1004 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1007 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1009 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1012 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1018 * Make spash screens come out in the center of a head
1019 * trouble is that most splashies never get here
1020 * they are managed trough atoms but god knows where.
1021 * Dan, do you know ? -peter
1023 * Most of them are not managed, they have set
1024 * OverrideRedirect, which means we can't do anything about
1029 * xinerama checks for: across head and dead space
1033 rect
.size
.width
= width
;
1034 rect
.size
.height
= height
;
1036 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1038 if (flags
& XFLAG_DEAD
)
1041 if (flags
& XFLAG_MULTIPLE
)
1045 switch (reposition
) {
1047 head
= wGetHeadForPointerLocation(scr
);
1048 rect
= wGetRectForHead(scr
, head
);
1050 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1051 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1055 rect
= wGetRectForHead(scr
, head
);
1059 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1060 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1064 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1065 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1074 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1075 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1078 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1080 if (wwin
->flags
.urgent
) {
1081 if (!IS_OMNIPRESENT(wwin
))
1082 wwin
->flags
.omnipresent
^= 1;
1086 * Create frame, borders and do reparenting
1088 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1089 #ifdef XKB_BUTTON_HINT
1090 if (wPreferences
.modelock
)
1091 foo
|= WFF_LANGUAGE_BUTTON
;
1093 if (HAS_TITLEBAR(wwin
))
1094 foo
|= WFF_TITLEBAR
;
1095 if (HAS_RESIZEBAR(wwin
))
1096 foo
|= WFF_RESIZEBAR
;
1097 if (HAS_BORDER(wwin
))
1100 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1101 x
, y
, width
, height
,
1102 &wPreferences
.window_title_clearance
,
1103 &wPreferences
.window_title_min_height
,
1104 &wPreferences
.window_title_max_height
,
1106 scr
->window_title_texture
,
1107 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1109 wwin
->frame
->flags
.is_client_window_frame
= 1;
1110 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1112 /* setup button images */
1113 wWindowUpdateButtonImages(wwin
);
1115 /* hide unused buttons */
1117 if (WFLAGP(wwin
, no_close_button
))
1118 foo
|= WFF_RIGHT_BUTTON
;
1119 if (WFLAGP(wwin
, no_miniaturize_button
))
1120 foo
|= WFF_LEFT_BUTTON
;
1121 #ifdef XKB_BUTTON_HINT
1122 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1123 foo
|= WFF_LANGUAGE_BUTTON
;
1126 wFrameWindowHideButton(wwin
->frame
, foo
);
1128 wwin
->frame
->child
= wwin
;
1129 wwin
->frame
->workspace
= workspace
;
1130 wwin
->frame
->on_click_left
= windowIconifyClick
;
1132 #ifdef XKB_BUTTON_HINT
1133 if (wPreferences
.modelock
)
1134 wwin
->frame
->on_click_language
= windowLanguageClick
;
1137 wwin
->frame
->on_click_right
= windowCloseClick
;
1138 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1139 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1140 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1141 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1143 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1144 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1145 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1150 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1152 /* if gravity is to the south, account for the border sizes */
1154 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1158 * wWindowConfigure() will init the client window's size
1159 * (wwin->client.{width,height}) and all other geometry
1160 * related variables (frame_x,frame_y)
1162 wWindowConfigure(wwin
, x
, y
, width
, height
);
1164 /* to make sure the window receives it's new position after reparenting */
1165 wWindowSynthConfigureNotify(wwin
);
1168 * Setup descriptors and save window to internal
1171 if (wwin
->main_window
!= None
) {
1175 /* Leader windows do not necessary set themselves as leaders.
1176 * If this is the case, point the leader of this window to
1178 leader
= wWindowFor(wwin
->main_window
);
1179 if (leader
&& leader
->main_window
== None
)
1180 leader
->main_window
= leader
->client_win
;
1182 app
= wApplicationCreate(wwin
);
1184 app
->last_workspace
= workspace
;
1187 * Do application specific stuff, like setting application
1191 if (wwin
->flags
.hidden
) {
1192 /* if the window was set to hidden because it was hidden
1193 * in a previous incarnation and that state was restored */
1194 app
->flags
.hidden
= 1;
1195 } else if (app
->flags
.hidden
) {
1196 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1197 wwin
->flags
.hidden
= 1;
1199 wUnhideApplication(app
, False
, False
);
1207 /* setup the frame descriptor */
1208 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1209 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1210 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1212 /* don't let windows go away if we die */
1213 XAddToSaveSet(dpy
, window
);
1215 XLowerWindow(dpy
, window
);
1217 /* if window is in this workspace and should be mapped, then map it */
1218 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1219 && !wwin
->flags
.hidden
&& !withdraw
) {
1221 /* The following "if" is to avoid crashing of clients that expect
1222 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1223 * after the return from this function.
1225 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
))
1226 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1228 wClientSetState(wwin
, NormalState
, None
);
1230 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
&& !scr
->flags
.startup
&&
1231 (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
) &&
1233 * The brain damaged idiotic non-click to focus modes will
1234 * have trouble with this because:
1236 * 1. window is created and mapped by the client
1237 * 2. window is mapped by wmaker in small size
1238 * 3. window is animated to grow to normal size
1239 * 4. this function returns to normal event loop
1240 * 5. eventually, the EnterNotify event that would trigger
1241 * the window focusing (if the mouse is over that window)
1242 * will be processed by wmaker.
1243 * But since this event will be rather delayed
1244 * (step 3 has a large delay) the time when the event ocurred
1245 * and when it is processed, the client that owns that window
1246 * will reject the XSetInputFocus() for it.
1248 (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
))
1249 DoWindowBirth(wwin
);
1254 /* setup stacking descriptor */
1256 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1258 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1260 if (!scr
->focused_window
) {
1261 /* first window on the list */
1264 scr
->focused_window
= wwin
;
1268 /* add window at beginning of focus window list */
1269 tmp
= scr
->focused_window
;
1277 /* raise is set to true if we un-hid the app when this window was born.
1278 * we raise, else old windows of this app will be above this new one. */
1280 wRaiseFrame(wwin
->frame
->core
);
1282 /* Update name must come after WApplication stuff is done */
1283 wWindowUpdateName(wwin
, title
);
1290 * Final preparations before window is ready to go
1292 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1294 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1295 if (((transientOwner
&& transientOwner
->flags
.focused
)
1296 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1298 /* only auto_focus if on same screen as mouse
1299 * (and same head for xinerama mode)
1300 * TODO: make it an option */
1302 /*TODO add checking the head of the window, is it available? */
1303 short same_screen
= 0, same_head
= 1;
1309 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1310 &foo
, &foo
, &foo
, &foo
, &bar
) != False
)
1313 if (same_screen
== 1 && same_head
== 1)
1314 wSetFocusTo(scr
, wwin
);
1317 wWindowResetMouseGrabs(wwin
);
1319 if (!WFLAGP(wwin
, no_bind_keys
))
1320 wWindowSetKeyGrabs(wwin
);
1322 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1323 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1325 /* Setup Notification Observers */
1326 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1328 /* Cleanup temporary stuff */
1330 wWindowDeleteSavedState(win_state
);
1332 /* If the window must be withdrawed, then do it now.
1333 * Must do some optimization, 'though */
1335 wwin
->flags
.mapped
= 0;
1336 wClientSetState(wwin
, WithdrawnState
, None
);
1337 wUnmanageWindow(wwin
, True
, False
);
1344 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1345 char *title
, int x
, int y
, int width
, int height
)
1350 wwin
= wWindowCreate();
1352 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1354 wwin
->flags
.internal_window
= 1;
1356 WSETUFLAG(wwin
, omnipresent
, 1);
1357 WSETUFLAG(wwin
, no_shadeable
, 1);
1358 WSETUFLAG(wwin
, no_resizable
, 1);
1359 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1361 wwin
->focus_mode
= WFM_PASSIVE
;
1362 wwin
->client_win
= window
;
1363 wwin
->screen_ptr
= scr
;
1364 wwin
->transient_for
= owner
;
1367 wwin
->client
.width
= width
;
1368 wwin
->client
.height
= height
;
1369 wwin
->frame_x
= wwin
->client
.x
;
1370 wwin
->frame_y
= wwin
->client
.y
;
1372 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1373 foo
|= WFF_TITLEBAR
;
1374 #ifdef XKB_BUTTON_HINT
1375 foo
|= WFF_LANGUAGE_BUTTON
;
1378 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1379 wwin
->frame_x
, wwin
->frame_y
,
1381 &wPreferences
.window_title_clearance
,
1382 &wPreferences
.window_title_min_height
,
1383 &wPreferences
.window_title_max_height
,
1385 scr
->window_title_texture
,
1386 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1388 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1390 wwin
->frame
->flags
.is_client_window_frame
= 1;
1391 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1393 wFrameWindowChangeTitle(wwin
->frame
, title
);
1395 /* setup button images */
1396 wWindowUpdateButtonImages(wwin
);
1399 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1401 wwin
->frame
->child
= wwin
;
1402 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1404 #ifdef XKB_BUTTON_HINT
1405 if (wPreferences
.modelock
)
1406 wwin
->frame
->on_click_language
= windowLanguageClick
;
1409 wwin
->frame
->on_click_right
= windowCloseClick
;
1410 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1411 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1412 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1413 wwin
->client
.y
+= wwin
->frame
->top_width
;
1415 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1416 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1418 /* setup the frame descriptor */
1419 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1420 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1421 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1423 XLowerWindow(dpy
, window
);
1424 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1426 /* setup stacking descriptor */
1427 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1429 tmp
= wWindowFor(wwin
->transient_for
);
1431 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1433 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1436 if (!scr
->focused_window
) {
1437 /* first window on the list */
1440 scr
->focused_window
= wwin
;
1444 /* add window at beginning of focus window list */
1445 tmp
= scr
->focused_window
;
1453 if (wwin
->flags
.is_gnustep
== 0)
1454 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1456 /* if (wPreferences.auto_focus) */
1457 wSetFocusTo(scr
, wwin
);
1458 wWindowResetMouseGrabs(wwin
);
1459 wWindowSetKeyGrabs(wwin
);
1465 *----------------------------------------------------------------------
1467 * Removes the frame window from a window and destroys all data
1468 * related to it. The window will be reparented back to the root window
1469 * if restore is True.
1472 * Everything related to the window is destroyed and the window
1473 * is removed from the window lists. Focus is set to the previous on the
1475 *----------------------------------------------------------------------
1477 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1479 WCoreWindow
*frame
= wwin
->frame
->core
;
1480 WWindow
*owner
= NULL
;
1481 WWindow
*newFocusedWindow
= NULL
;
1483 WScreen
*scr
= wwin
->screen_ptr
;
1485 /* First close attribute editor window if open */
1486 if (wwin
->flags
.inspector_open
)
1487 wCloseInspectorForWindow(wwin
);
1489 /* Close window menu if it's open for this window */
1490 if (wwin
->flags
.menu_open_for_me
)
1491 CloseWindowMenu(scr
);
1494 if (!wwin
->flags
.internal_window
)
1495 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1497 /* If this is a leader window, we still need to listen for
1498 * DestroyNotify and PropertyNotify. */
1499 if (wApplicationOf(wwin
->client_win
))
1500 XSelectInput(dpy
, wwin
->client_win
, StructureNotifyMask
| PropertyChangeMask
);
1502 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1504 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1505 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1508 XUnmapWindow(dpy
, frame
->window
);
1510 XUnmapWindow(dpy
, wwin
->client_win
);
1512 /* deselect window */
1513 wSelectWindow(wwin
, False
);
1515 /* remove all pending events on window */
1516 /* I think this only matters for autoraise */
1517 if (wPreferences
.raise_delay
)
1518 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1522 /* reparent the window back to the root */
1524 wClientRestore(wwin
);
1526 if (wwin
->transient_for
!= scr
->root_win
) {
1527 owner
= wWindowFor(wwin
->transient_for
);
1529 if (!owner
->flags
.semi_focused
)
1532 owner
->flags
.semi_focused
= 0;
1536 wasFocused
= wwin
->flags
.focused
;
1538 /* remove from window focus list */
1539 if (!wwin
->prev
&& !wwin
->next
) {
1540 /* was the only window */
1541 scr
->focused_window
= NULL
;
1542 newFocusedWindow
= NULL
;
1547 wwin
->prev
->next
= wwin
->next
;
1550 wwin
->next
->prev
= wwin
->prev
;
1552 scr
->focused_window
= wwin
->prev
;
1553 scr
->focused_window
->next
= NULL
;
1556 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1558 /* if in click to focus mode and the window
1559 * was a transient, focus the owner window
1562 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1563 tmp
= wWindowFor(wwin
->transient_for
);
1564 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1568 /* otherwise, focus the next one in the focus list */
1570 tmp
= scr
->focused_window
;
1571 while (tmp
) { /* look for one in the window list first */
1572 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1573 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1577 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1578 tmp
= scr
->focused_window
;
1580 if (!WFLAGP(tmp
, no_focusable
)
1581 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1588 newFocusedWindow
= tmp
;
1590 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1595 /* This is to let the root window get the keyboard input
1596 * if Sloppy focus mode and no other window get focus.
1597 * This way keybindings will not freeze.
1600 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1601 tmp
= wWindowFor(win
);
1604 newFocusedWindow
= tmp
;
1606 newFocusedWindow
= NULL
;
1610 if (!wwin
->flags
.internal_window
)
1611 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1613 if (newFocusedWindow
!= owner
&& owner
) {
1614 if (wwin
->flags
.is_gnustep
== 0)
1615 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1617 wSetFocusTo(scr
, newFocusedWindow
);
1620 /* Close menu and unhighlight */
1621 WApplication
*oapp
= wApplicationOf(wwin
->main_window
);
1622 WApplication
*napp
= scr
->focused_window
? wApplicationOf(scr
->focused_window
->main_window
) : NULL
;
1623 if (oapp
&& oapp
!= napp
) {
1624 wAppMenuUnmap(oapp
->menu
);
1625 wApplicationDeactivate(oapp
);
1628 wWindowDestroy(wwin
);
1632 void wWindowMap(WWindow
*wwin
)
1634 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1635 if (!wwin
->flags
.shaded
) {
1636 /* window will be remapped when getting MapNotify */
1637 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1638 XMapWindow(dpy
, wwin
->client_win
);
1639 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1641 wwin
->flags
.mapped
= 1;
1645 void wWindowUnmap(WWindow
*wwin
)
1647 wwin
->flags
.mapped
= 0;
1649 /* prevent window withdrawal when getting UnmapNotify */
1650 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1651 XUnmapWindow(dpy
, wwin
->client_win
);
1652 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1654 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1657 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1662 #ifdef KEEP_XKB_LOCK_STATUS
1663 if (wPreferences
.modelock
)
1664 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1665 #endif /* KEEP_XKB_LOCK_STATUS */
1667 wwin
->flags
.semi_focused
= 0;
1669 if (wwin
->flags
.is_gnustep
== 0)
1670 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1672 wwin
->flags
.focused
= 1;
1674 wWindowResetMouseGrabs(wwin
);
1676 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1678 if (owin
== wwin
|| !owin
)
1681 nowner
= wWindowFor(wwin
->transient_for
);
1683 /* new window is a transient for the old window */
1684 if (nowner
== owin
) {
1685 owin
->flags
.semi_focused
= 1;
1686 wWindowUnfocus(nowner
);
1690 oowner
= wWindowFor(owin
->transient_for
);
1692 /* new window is owner of old window */
1693 if (wwin
== oowner
) {
1694 wWindowUnfocus(owin
);
1699 wWindowUnfocus(owin
);
1703 /* new window has same owner of old window */
1704 if (oowner
== nowner
) {
1705 /* prevent unfocusing of owner */
1706 oowner
->flags
.semi_focused
= 0;
1707 wWindowUnfocus(owin
);
1708 oowner
->flags
.semi_focused
= 1;
1713 /* nowner != NULL && oowner != nowner */
1714 nowner
->flags
.semi_focused
= 1;
1715 wWindowUnfocus(nowner
);
1716 wWindowUnfocus(owin
);
1719 void wWindowUnfocus(WWindow
*wwin
)
1721 CloseWindowMenu(wwin
->screen_ptr
);
1723 if (wwin
->flags
.is_gnustep
== 0)
1724 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1726 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1728 owner
= wWindowFor(wwin
->transient_for
);
1729 if (owner
&& owner
->flags
.semi_focused
) {
1730 owner
->flags
.semi_focused
= 0;
1731 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1732 wWindowUnfocus(owner
);
1733 wFrameWindowPaint(owner
->frame
);
1737 wwin
->flags
.focused
= 0;
1738 wWindowResetMouseGrabs(wwin
);
1739 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1742 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1749 wwin
->flags
.wm_name_changed
= 1;
1752 title
= DEF_WINDOW_TITLE
; /* the hint was removed */
1756 if (wFrameWindowChangeTitle(wwin
->frame
, title
))
1757 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1761 *----------------------------------------------------------------------
1763 * wWindowConstrainSize--
1764 * Constrains size for the client window, taking the maximal size,
1765 * window resize increments and other size hints into account.
1768 * The closest size to what was given that the client window can
1771 *----------------------------------------------------------------------
1773 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1775 int width
= (int)*nwidth
;
1776 int height
= (int)*nheight
;
1779 int minW
= 1, minH
= 1;
1780 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1781 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1782 int minAX
= -1, minAY
= -1;
1783 int maxAX
= -1, maxAY
= -1;
1787 if (wwin
->normal_hints
) {
1788 winc
= wwin
->normal_hints
->width_inc
;
1789 hinc
= wwin
->normal_hints
->height_inc
;
1790 minW
= wwin
->normal_hints
->min_width
;
1791 minH
= wwin
->normal_hints
->min_height
;
1792 maxW
= wwin
->normal_hints
->max_width
;
1793 maxH
= wwin
->normal_hints
->max_height
;
1794 if (wwin
->normal_hints
->flags
& PAspect
) {
1795 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1796 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1797 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1798 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1801 baseW
= wwin
->normal_hints
->base_width
;
1802 baseH
= wwin
->normal_hints
->base_height
;
1815 /* aspect ratio code borrowed from olwm */
1817 /* adjust max aspect ratio */
1818 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1819 if (maxAX
> maxAY
) {
1820 height
= (width
* maxAY
) / maxAX
;
1821 if (height
> maxH
) {
1823 width
= (height
* maxAX
) / maxAY
;
1826 width
= (height
* maxAX
) / maxAY
;
1829 height
= (width
* maxAY
) / maxAX
;
1834 /* adjust min aspect ratio */
1835 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1836 if (minAX
> minAY
) {
1837 height
= (width
* minAY
) / minAX
;
1838 if (height
< minH
) {
1840 width
= (height
* minAX
) / minAY
;
1843 width
= (height
* minAX
) / minAY
;
1846 height
= (width
* minAY
) / minAX
;
1853 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1855 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1858 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1860 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1862 /* broken stupid apps may cause preposterous values for these.. */
1869 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1870 unsigned int *width
, unsigned int *height
)
1872 int baseW
= 0, baseH
= 0;
1873 int winc
= 1, hinc
= 1;
1875 if (wwin
->normal_hints
) {
1876 baseW
= wwin
->normal_hints
->base_width
;
1877 baseH
= wwin
->normal_hints
->base_height
;
1879 winc
= wwin
->normal_hints
->width_inc
;
1880 hinc
= wwin
->normal_hints
->height_inc
;
1884 *width
= maxW
- (maxW
- baseW
) % winc
;
1887 *height
= maxH
- (maxH
- baseH
) % hinc
;
1890 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1892 WScreen
*scr
= wwin
->screen_ptr
;
1896 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1899 if (workspace
!= scr
->current_workspace
) {
1900 /* Sent to other workspace. Unmap window */
1901 if ((wwin
->flags
.mapped
1902 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1903 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1905 wapp
= wApplicationOf(wwin
->main_window
);
1907 wapp
->last_workspace
= workspace
;
1909 if (wwin
->flags
.miniaturized
) {
1911 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1912 wwin
->icon
->mapped
= 0;
1916 wSetFocusTo(scr
, NULL
);
1920 /* brought to current workspace. Map window */
1921 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1923 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1924 wwin
->icon
->mapped
= 1;
1926 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1930 if (!IS_OMNIPRESENT(wwin
)) {
1931 int oldWorkspace
= wwin
->frame
->workspace
;
1932 wwin
->frame
->workspace
= workspace
;
1933 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1940 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1944 sevent
.type
= ConfigureNotify
;
1945 sevent
.xconfigure
.display
= dpy
;
1946 sevent
.xconfigure
.event
= wwin
->client_win
;
1947 sevent
.xconfigure
.window
= wwin
->client_win
;
1949 sevent
.xconfigure
.x
= wwin
->client
.x
;
1950 sevent
.xconfigure
.y
= wwin
->client
.y
;
1951 sevent
.xconfigure
.width
= wwin
->client
.width
;
1952 sevent
.xconfigure
.height
= wwin
->client
.height
;
1954 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1955 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1956 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1958 sevent
.xconfigure
.above
= None
;
1960 sevent
.xconfigure
.override_redirect
= False
;
1961 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1966 *----------------------------------------------------------------------
1967 * wWindowConfigure()
1969 * req_x, req_y: new requested positions for the frame
1970 * req_width, req_height: new requested sizes for the client
1972 * Configures the frame, decorations and client window to the specified
1973 * geometry, whose validity is not checked -- wWindowConstrainSize()
1974 * must be used for that.
1975 * The size parameters are for the client window, but the position is
1977 * The client window receives a ConfigureNotify event, according
1978 * to what ICCCM says.
1984 * Window size and position are changed and client window receives
1985 * a ConfigureNotify event.
1986 *----------------------------------------------------------------------
1988 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
1990 int synth_notify
= False
;
1993 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
1995 * if the window is being moved but not resized then
1996 * send a synthetic ConfigureNotify
1998 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
)
1999 synth_notify
= True
;
2001 if (WFLAGP(wwin
, dont_move_off
))
2002 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2005 if (req_width
< MIN_WINDOW_SIZE
)
2006 req_width
= MIN_WINDOW_SIZE
;
2007 if (req_height
< MIN_WINDOW_SIZE
)
2008 req_height
= MIN_WINDOW_SIZE
;
2010 /* If growing, resize inner part before frame,
2011 * if shrinking, resize frame before.
2012 * This will prevent the frame (that can have a different color)
2013 * to be exposed, causing flicker */
2014 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2015 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2017 if (wwin
->flags
.shaded
) {
2018 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2019 wwin
->old_geometry
.height
= req_height
;
2023 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2025 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2028 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2029 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2031 wwin
->client
.x
= req_x
;
2032 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2033 wwin
->client
.width
= req_width
;
2034 wwin
->client
.height
= req_height
;
2036 wwin
->client
.x
= req_x
;
2037 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2039 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2041 wwin
->frame_x
= req_x
;
2042 wwin
->frame_y
= req_y
;
2043 if (HAS_BORDER(wwin
)) {
2044 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2045 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2048 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
)
2049 wWindowSetShape(wwin
);
2053 wWindowSynthConfigureNotify(wwin
);
2057 /* req_x, req_y: new position of the frame */
2058 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2060 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2061 int synth_notify
= False
;
2063 /* Send a synthetic ConfigureNotify event for every window movement. */
2064 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
))
2065 synth_notify
= True
;
2067 /* A single synthetic ConfigureNotify event is sent at the end of
2068 * a completed (opaque) movement in moveres.c */
2071 if (WFLAGP(wwin
, dont_move_off
))
2072 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2073 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2075 wwin
->client
.x
= req_x
;
2076 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2077 if (HAS_BORDER(wwin
)) {
2078 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2079 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2082 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2084 wwin
->frame_x
= req_x
;
2085 wwin
->frame_y
= req_y
;
2087 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2089 wWindowSynthConfigureNotify(wwin
);
2093 void wWindowUpdateButtonImages(WWindow
*wwin
)
2095 WScreen
*scr
= wwin
->screen_ptr
;
2096 Pixmap pixmap
, mask
;
2097 WFrameWindow
*fwin
= wwin
->frame
;
2099 if (!HAS_TITLEBAR(wwin
))
2102 /* miniaturize button */
2103 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2104 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2105 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2107 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
)
2108 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2112 if (fwin
->lbutton_image
2113 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2114 wPixmapDestroy(fwin
->lbutton_image
);
2115 fwin
->lbutton_image
= NULL
;
2118 if (!fwin
->lbutton_image
) {
2119 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2120 fwin
->lbutton_image
->client_owned
= 1;
2121 fwin
->lbutton_image
->client_owned_mask
= 1;
2124 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
)
2125 wPixmapDestroy(fwin
->lbutton_image
);
2127 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2130 #ifdef XKB_BUTTON_HINT
2131 if (!WFLAGP(wwin
, no_language_button
)) {
2132 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
)
2133 wPixmapDestroy(fwin
->languagebutton_image
);
2135 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2141 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2142 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2144 if (!WFLAGP(wwin
, no_close_button
)) {
2145 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2146 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2148 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2149 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2153 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2154 || fwin
->rbutton_image
->mask
!= mask
)) {
2155 wPixmapDestroy(fwin
->rbutton_image
);
2156 fwin
->rbutton_image
= NULL
;
2159 if (!fwin
->rbutton_image
) {
2160 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2161 fwin
->rbutton_image
->client_owned
= 1;
2162 fwin
->rbutton_image
->client_owned_mask
= 1;
2165 } else if (WFLAGP(wwin
, kill_close
)) {
2166 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2167 wPixmapDestroy(fwin
->rbutton_image
);
2169 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2171 } else if (MGFLAGP(wwin
, broken_close
)) {
2172 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2173 wPixmapDestroy(fwin
->rbutton_image
);
2175 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2178 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2179 wPixmapDestroy(fwin
->rbutton_image
);
2181 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2185 /* force buttons to be redrawn */
2186 fwin
->flags
.need_texture_change
= 1;
2187 wFrameWindowPaint(fwin
);
2191 *---------------------------------------------------------------------------
2192 * wWindowConfigureBorders--
2193 * Update window border configuration according to attribute flags.
2195 *---------------------------------------------------------------------------
2197 void wWindowConfigureBorders(WWindow
*wwin
)
2203 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2205 #ifdef XKB_BUTTON_HINT
2206 if (wPreferences
.modelock
)
2207 flags
|= WFF_LANGUAGE_BUTTON
;
2210 if (HAS_TITLEBAR(wwin
))
2211 flags
|= WFF_TITLEBAR
;
2212 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2213 flags
|= WFF_RESIZEBAR
;
2214 if (HAS_BORDER(wwin
))
2215 flags
|= WFF_BORDER
;
2216 if (wwin
->flags
.shaded
)
2217 flags
|= WFF_IS_SHADED
;
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 (wShapeSupported
&& 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 (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2298 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2301 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2302 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2305 static int getSavedState(Window window
, WSavedState
** state
)
2309 unsigned long nitems_ret
;
2310 unsigned long bytes_after_ret
;
2313 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2314 True
, _XA_WINDOWMAKER_STATE
,
2315 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2316 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2319 *state
= wmalloc(sizeof(WSavedState
));
2321 (*state
)->workspace
= data
[0];
2322 (*state
)->miniaturized
= data
[1];
2323 (*state
)->shaded
= data
[2];
2324 (*state
)->hidden
= data
[3];
2325 (*state
)->maximized
= data
[4];
2326 (*state
)->x
= data
[5];
2327 (*state
)->y
= data
[6];
2328 (*state
)->w
= data
[7];
2329 (*state
)->h
= data
[8];
2330 (*state
)->window_shortcuts
= data
[9];
2334 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2341 void wWindowClearShape(WWindow
* wwin
)
2343 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2344 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2348 void wWindowSetShape(WWindow
* wwin
)
2352 #ifdef OPTIMIZE_SHAPE
2357 /* only shape is the client's */
2358 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
))
2361 /* Get array of rectangles describing the shape mask */
2362 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2366 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2372 /* insert our decoration rectangles in the rect list */
2373 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2376 if (HAS_TITLEBAR(wwin
)) {
2378 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2379 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2380 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2383 if (HAS_RESIZEBAR(wwin
)) {
2385 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2386 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2387 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2391 /* shape our frame window */
2392 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2393 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2399 #endif /* OPTIMIZE_SHAPE */
2401 if (HAS_TITLEBAR(wwin
)) {
2404 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2405 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2408 if (HAS_RESIZEBAR(wwin
)) {
2410 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2411 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2412 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2416 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2417 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2419 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2420 0, wwin
->frame
->top_width
, wwin
->client_win
,
2421 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2426 /* ====================================================================== */
2428 static FocusMode
getFocusMode(WWindow
* wwin
)
2432 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2433 if (wwin
->wm_hints
->input
== True
) {
2434 if (wwin
->protocols
.TAKE_FOCUS
)
2435 mode
= WFM_LOCALLY_ACTIVE
;
2439 if (wwin
->protocols
.TAKE_FOCUS
)
2440 mode
= WFM_GLOBALLY_ACTIVE
;
2442 mode
= WFM_NO_INPUT
;
2450 void wWindowSetKeyGrabs(WWindow
* wwin
)
2455 for (i
= 0; i
< WKBD_LAST
; i
++) {
2456 key
= &wKeyBindings
[i
];
2458 if (key
->keycode
== 0)
2460 if (key
->modifier
!= AnyModifier
) {
2461 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2462 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2464 /* Also grab all modifier combinations possible that include,
2465 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2466 * work even if the NumLock/ScrollLock key is on.
2468 wHackedGrabKey(key
->keycode
, key
->modifier
,
2469 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2472 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2473 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2476 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2479 void wWindowResetMouseGrabs(WWindow
* wwin
)
2481 /* Mouse grabs can't be done on the client window because of
2482 * ICCCM and because clients that try to do the same will crash.
2484 * But there is a problem wich makes tbar buttons of unfocused
2485 * windows not usable as the click goes to the frame window instead
2486 * of the button itself. Must figure a way to fix that.
2489 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2491 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2492 /* grabs for Meta+drag */
2493 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2494 True
, ButtonPressMask
| ButtonReleaseMask
,
2495 GrabModeSync
, GrabModeAsync
, None
, None
);
2497 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2498 * but we only grab it for Button4 and Button 5 since a lot of apps
2499 * use CTRL+Button1-3 for app related functionality
2501 if (wPreferences
.resize_increment
> 0) {
2502 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2503 True
, ButtonPressMask
| ButtonReleaseMask
,
2504 GrabModeSync
, GrabModeAsync
, None
, None
);
2505 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2506 True
, ButtonPressMask
| ButtonReleaseMask
,
2507 GrabModeSync
, GrabModeAsync
, None
, None
);
2509 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2510 True
, ButtonPressMask
| ButtonReleaseMask
,
2511 GrabModeSync
, GrabModeAsync
, None
, None
);
2512 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2513 True
, ButtonPressMask
| ButtonReleaseMask
,
2514 GrabModeSync
, GrabModeAsync
, None
, None
);
2518 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2519 && !wwin
->flags
.is_gnustep
) {
2520 /* the passive grabs to focus the window */
2521 /* if (wPreferences.focus_mode == WKF_CLICK) */
2522 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2523 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2528 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2530 if (attr
->flags
& GSExtraFlagsAttr
) {
2531 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2532 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2533 wWindowUpdateButtonImages(wwin
);
2538 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2540 WWindowState
*wstate
;
2542 wstate
= malloc(sizeof(WWindowState
));
2546 memset(wstate
, 0, sizeof(WWindowState
));
2549 wstate
->instance
= wstrdup(instance
);
2551 wstate
->class = wstrdup(class);
2553 wstate
->command
= wstrdup(command
);
2554 wstate
->state
= state
;
2556 wstate
->next
= windowState
;
2557 windowState
= wstate
;
2562 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2564 WMagicNumber
wWindowGetSavedState(Window win
)
2566 char *instance
, *class, *command
= NULL
;
2567 WWindowState
*wstate
= windowState
;
2572 command
= GetCommandForWindow(win
);
2576 if (PropGetWMClass(win
, &class, &instance
)) {
2578 if (SAME(instance
, wstate
->instance
) &&
2579 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2582 wstate
= wstate
->next
;
2598 void wWindowDeleteSavedState(WMagicNumber id
)
2600 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2602 if (!wstate
|| !windowState
)
2606 if (tmp
== wstate
) {
2607 windowState
= wstate
->next
;
2608 if (wstate
->instance
)
2609 wfree(wstate
->instance
);
2611 wfree(wstate
->class);
2612 if (wstate
->command
)
2613 wfree(wstate
->command
);
2614 wfree(wstate
->state
);
2618 if (tmp
->next
== wstate
) {
2619 tmp
->next
= wstate
->next
;
2620 if (wstate
->instance
)
2621 wfree(wstate
->instance
);
2623 wfree(wstate
->class);
2624 if (wstate
->command
)
2625 wfree(wstate
->command
);
2626 wfree(wstate
->state
);
2635 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2637 WWindowState
*tmp
, *wstate
;
2643 if (tmp
->pid
== pid
) {
2644 wstate
= windowState
;
2645 windowState
= tmp
->next
;
2646 if (wstate
->instance
)
2647 wfree(wstate
->instance
);
2649 wfree(wstate
->class);
2650 if (wstate
->command
)
2651 wfree(wstate
->command
);
2652 wfree(wstate
->state
);
2656 if (tmp
->next
->pid
== pid
) {
2658 tmp
->next
= wstate
->next
;
2659 if (wstate
->instance
)
2660 wfree(wstate
->instance
);
2662 wfree(wstate
->class);
2663 if (wstate
->command
)
2664 wfree(wstate
->command
);
2665 wfree(wstate
->state
);
2674 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2676 if (wwin
->flags
.omnipresent
== flag
)
2679 wwin
->flags
.omnipresent
= flag
;
2680 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2683 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2685 WWindow
*wwin
= data
;
2687 #ifndef NUMLOCK_HACK
2688 if ((event
->xbutton
.state
& ValidModMask
)
2689 != (event
->xbutton
.state
& ~LockMask
)) {
2690 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2691 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2695 event
->xbutton
.state
&= ValidModMask
;
2697 CloseWindowMenu(wwin
->screen_ptr
);
2699 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2700 && !WFLAGP(wwin
, no_focusable
)) {
2701 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2704 if (event
->xbutton
.button
== Button1
)
2705 wRaiseFrame(wwin
->frame
->core
);
2707 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2708 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2709 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2710 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2715 if (event
->xbutton
.state
& MOD_MASK
) {
2716 /* move the window */
2717 wMouseMoveWindow(wwin
, event
);
2718 XUngrabPointer(dpy
, CurrentTime
);
2720 wMouseResizeWindow(wwin
, event
);
2721 XUngrabPointer(dpy
, CurrentTime
);
2725 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2727 WWindow
*wwin
= data
;
2729 event
->xbutton
.state
&= ValidModMask
;
2731 if (event
->xbutton
.button
== Button1
) {
2732 if (event
->xbutton
.state
== 0) {
2733 if (!WFLAGP(wwin
, no_shadeable
)) {
2735 if (wwin
->flags
.shaded
)
2736 wUnshadeWindow(wwin
);
2743 if (event
->xbutton
.state
& ControlMask
)
2744 dir
|= MAX_VERTICAL
;
2746 if (event
->xbutton
.state
& ShiftMask
) {
2747 dir
|= MAX_HORIZONTAL
;
2748 if (!(event
->xbutton
.state
& ControlMask
))
2749 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2752 /* maximize window */
2753 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2754 int ndir
= dir
^ wwin
->flags
.maximized
;
2757 wMaximizeWindow(wwin
, ndir
);
2759 wUnmaximizeWindow(wwin
);
2762 } else if (event
->xbutton
.button
== Button3
) {
2763 if (event
->xbutton
.state
& MOD_MASK
)
2764 wHideOtherApplications(wwin
);
2765 } else if (event
->xbutton
.button
== Button2
) {
2766 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2767 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2769 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2770 wUnshadeWindow(wwin
);
2774 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2776 WWindow
*wwin
= desc
->parent
;
2777 unsigned int new_width
, w_scale
;
2778 unsigned int new_height
, h_scale
;
2779 unsigned int resize_width_increment
= 0;
2780 unsigned int resize_height_increment
= 0;
2782 if (wwin
->normal_hints
) {
2783 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2784 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2785 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2786 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2788 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2789 resize_width_increment
= wPreferences
.resize_increment
;
2790 resize_height_increment
= wPreferences
.resize_increment
;
2793 event
->xbutton
.state
&= ValidModMask
;
2795 CloseWindowMenu(wwin
->screen_ptr
);
2797 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2798 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2800 if (event
->xbutton
.button
== Button1
)
2801 wRaiseFrame(wwin
->frame
->core
);
2803 if (event
->xbutton
.state
& ControlMask
) {
2804 if (event
->xbutton
.button
== Button4
) {
2805 new_width
= wwin
->client
.width
- resize_width_increment
;
2806 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2807 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2809 if (event
->xbutton
.button
== Button5
) {
2810 new_width
= wwin
->client
.width
+ resize_width_increment
;
2811 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2812 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2816 if (event
->xbutton
.state
& MOD_MASK
) {
2817 /* move the window */
2818 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2819 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2820 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2823 if (event
->xbutton
.button
== Button3
) {
2824 wMouseResizeWindow(wwin
, event
);
2825 } else if (event
->xbutton
.button
== Button4
) {
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
== Button5
) {
2830 new_height
= wwin
->client
.height
+ resize_height_increment
;
2831 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2832 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2833 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2834 wMouseMoveWindow(wwin
, event
);
2836 XUngrabPointer(dpy
, CurrentTime
);
2840 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2842 WWindow
*wwin
= (WWindow
*) data
;
2844 #ifndef NUMLOCK_HACK
2845 if ((event
->xbutton
.state
& ValidModMask
) != (event
->xbutton
.state
& ~LockMask
))
2846 wwarning(_("The NumLock, ScrollLock or similar key seems to be turned on. "
2847 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2849 event
->xbutton
.state
&= ValidModMask
;
2851 CloseWindowMenu(wwin
->screen_ptr
);
2853 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2854 && !WFLAGP(wwin
, no_focusable
))
2855 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2857 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2859 if (event
->xbutton
.button
== Button1
) {
2860 if (event
->xbutton
.state
& MOD_MASK
)
2861 wLowerFrame(wwin
->frame
->core
);
2863 wRaiseFrame(wwin
->frame
->core
);
2865 if ((event
->xbutton
.state
& ShiftMask
)
2866 && !(event
->xbutton
.state
& ControlMask
)) {
2867 wSelectWindow(wwin
, !wwin
->flags
.selected
);
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 /* move the window */
2878 wMouseMoveWindow(wwin
, event
);
2880 XUngrabPointer(dpy
, CurrentTime
);
2881 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2882 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2883 WObjDescriptor
*desc
;
2885 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2886 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2887 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2888 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2892 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2894 /* allow drag select */
2895 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2896 event
->xany
.send_event
= True
;
2897 (*desc
->handle_mousedown
) (desc
, event
);
2899 XUngrabPointer(dpy
, CurrentTime
);
2903 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2905 WWindow
*wwin
= data
;
2907 event
->xbutton
.state
&= ValidModMask
;
2909 CloseWindowMenu(wwin
->screen_ptr
);
2911 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2914 /* if control-click, kill the client */
2915 if (event
->xbutton
.state
& ControlMask
) {
2918 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2919 /* send delete message */
2920 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2925 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2927 WWindow
*wwin
= data
;
2929 CloseWindowMenu(wwin
->screen_ptr
);
2931 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2934 /* send delete message */
2935 if (wwin
->protocols
.DELETE_WINDOW
)
2936 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2941 #ifdef XKB_BUTTON_HINT
2942 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2944 WWindow
*wwin
= data
;
2945 WFrameWindow
*fwin
= wwin
->frame
;
2946 WScreen
*scr
= fwin
->screen_ptr
;
2949 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2951 tl
= wwin
->frame
->languagemode
;
2952 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2953 wwin
->frame
->last_languagemode
= tl
;
2954 wSetFocusTo(scr
, wwin
);
2955 wwin
->frame
->languagebutton_image
=
2956 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
2957 wFrameWindowUpdateLanguageButton(wwin
->frame
);
2958 if (event
->xbutton
.button
== Button3
)
2960 wRaiseFrame(fwin
->core
);
2964 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2966 WWindow
*wwin
= data
;
2968 event
->xbutton
.state
&= ValidModMask
;
2970 CloseWindowMenu(wwin
->screen_ptr
);
2972 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2975 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
2976 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
2979 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
2981 wapp
= wApplicationOf(wwin
->main_window
);
2982 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
2983 wHideApplication(wapp
);
2984 } else if (event
->xbutton
.state
== 0) {
2985 wIconifyWindow(wwin
);