1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
39 /* For getting mouse wheel mappings from WINGs */
40 #include <WINGs/WINGsP.h>
42 #include "WindowMaker.h"
48 #include "winspector.h"
50 #include "properties.h"
57 #include "workspace.h"
65 #define MOD_MASK wPreferences.modifier_mask
67 /****** Global Variables ******/
68 extern WShortKey wKeyBindings
[WKBD_LAST
];
71 extern Bool wShapeSupported
;
75 extern XContext wWinContext
;
78 extern Cursor wCursor
[WCUR_LAST
];
81 extern Atom _XA_WM_DELETE_WINDOW
;
82 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
83 extern Atom _XA_WINDOWMAKER_STATE
;
85 extern WPreferences wPreferences
;
86 extern Time LastTimestamp
;
89 extern void DoWindowBirth(WWindow
*wwin
);
91 /***** Local Stuff *****/
92 static WWindowState
*windowState
= NULL
;
94 static FocusMode
getFocusMode(WWindow
*wwin
);
95 static int getSavedState(Window window
, WSavedState
**state
);
96 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
98 /* frame window (during window grabs) */
99 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
102 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
103 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
106 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 #ifdef XKB_BUTTON_HINT
109 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
112 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
113 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
114 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
116 /****** Notification Observers ******/
118 static void appearanceObserver(void *self
, WMNotification
* notif
)
120 WWindow
*wwin
= (WWindow
*) self
;
121 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
123 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
126 if (flags
& WFontSettings
) {
127 wWindowConfigureBorders(wwin
);
128 if (wwin
->flags
.shaded
) {
129 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
131 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
132 wWindowSynthConfigureNotify(wwin
);
135 if (flags
& WTextureSettings
) {
136 wwin
->frame
->flags
.need_texture_remake
= 1;
138 if (flags
& (WTextureSettings
| WColorSettings
)) {
139 if (wwin
->frame
->titlebar
)
140 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
142 wFrameWindowPaint(wwin
->frame
);
147 WWindow
*wWindowFor(Window window
)
149 WObjDescriptor
*desc
;
154 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
157 if (desc
->parent_type
== WCLASS_WINDOW
)
159 else if (desc
->parent_type
== WCLASS_FRAME
) {
160 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
161 if (frame
->flags
.is_client_window_frame
)
168 WWindow
*wWindowCreate()
172 wwin
= wmalloc(sizeof(WWindow
));
175 memset(wwin
, 0, sizeof(WWindow
));
177 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
178 wwin
->client_descriptor
.parent
= wwin
;
179 wwin
->client_descriptor
.self
= wwin
;
180 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
185 void wWindowDestroy(WWindow
*wwin
)
189 if (wwin
->screen_ptr
->cmap_window
== wwin
)
190 wwin
->screen_ptr
->cmap_window
= NULL
;
192 WMRemoveNotificationObserver(wwin
);
194 wwin
->flags
.destroyed
= 1;
196 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
197 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
200 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
202 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
203 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
204 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
208 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
209 wwin
->fake_group
->retainCount
--;
210 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
211 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
212 wwin
->fake_group
->leader
= None
;
213 wwin
->fake_group
->origLeader
= None
;
218 if (wwin
->normal_hints
)
219 XFree(wwin
->normal_hints
);
222 XFree(wwin
->wm_hints
);
224 if (wwin
->wm_instance
)
225 XFree(wwin
->wm_instance
);
228 XFree(wwin
->wm_class
);
230 if (wwin
->wm_gnustep_attr
)
231 wfree(wwin
->wm_gnustep_attr
);
233 if (wwin
->cmap_windows
)
234 XFree(wwin
->cmap_windows
);
236 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
239 wFrameWindowDestroy(wwin
->frame
);
242 RemoveFromStackList(wwin
->icon
->core
);
243 wIconDestroy(wwin
->icon
);
244 if (wPreferences
.auto_arrange_icons
)
245 wArrangeIcons(wwin
->screen_ptr
, True
);
247 if (wwin
->net_icon_image
)
248 RReleaseImage(wwin
->net_icon_image
);
253 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
255 if (gs_hints
->flags
& GSWindowStyleAttr
) {
256 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
257 wwin
->client_flags
.no_border
= 1;
258 wwin
->client_flags
.no_titlebar
= 1;
259 wwin
->client_flags
.no_closable
= 1;
260 wwin
->client_flags
.no_miniaturizable
= 1;
261 wwin
->client_flags
.no_resizable
= 1;
262 wwin
->client_flags
.no_close_button
= 1;
263 wwin
->client_flags
.no_miniaturize_button
= 1;
264 wwin
->client_flags
.no_resizebar
= 1;
266 wwin
->client_flags
.no_close_button
=
267 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
269 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
271 wwin
->client_flags
.no_miniaturize_button
=
272 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
274 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
276 wwin
->client_flags
.no_resizebar
=
277 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
279 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
281 /* these attributes supposedly imply in the existence
283 if (gs_hints
->window_style
& (WMResizableWindowMask
|
284 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
285 wwin
->client_flags
.no_titlebar
= 0;
287 wwin
->client_flags
.no_titlebar
=
288 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
293 /* setup the defaults */
294 wwin
->client_flags
.no_border
= 0;
295 wwin
->client_flags
.no_titlebar
= 0;
296 wwin
->client_flags
.no_closable
= 0;
297 wwin
->client_flags
.no_miniaturizable
= 0;
298 wwin
->client_flags
.no_resizable
= 0;
299 wwin
->client_flags
.no_close_button
= 0;
300 wwin
->client_flags
.no_miniaturize_button
= 0;
301 wwin
->client_flags
.no_resizebar
= 0;
303 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
304 wwin
->client_flags
.no_appicon
= 1;
307 void wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
, WWindowAttributes
*mask
)
309 if (wflags
->no_appicon
&& mask
->no_appicon
)
310 wflags
->emulate_appicon
= 0;
312 if (wwin
->main_window
!= None
) {
313 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
314 if (wapp
&& !wapp
->flags
.emulated
)
315 wflags
->emulate_appicon
= 0;
318 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
319 wflags
->emulate_appicon
= 0;
321 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
325 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
327 WScreen
*scr
= wwin
->screen_ptr
;
329 /* sets global default stuff */
330 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
332 * Decoration setting is done in this precedence (lower to higher)
333 * - use global default in the resource database
334 * - guess some settings
335 * - use GNUstep/external window attributes
336 * - set hints specified for the app in the resource DB
339 WSETUFLAG(wwin
, broken_close
, 0);
341 if (wwin
->protocols
.DELETE_WINDOW
)
342 WSETUFLAG(wwin
, kill_close
, 0);
344 WSETUFLAG(wwin
, kill_close
, 1);
346 /* transients can't be iconified or maximized */
347 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
348 WSETUFLAG(wwin
, no_miniaturizable
, 1);
349 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
352 /* if the window can't be resized, remove the resizebar */
353 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
354 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
355 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
356 WSETUFLAG(wwin
, no_resizable
, 1);
357 WSETUFLAG(wwin
, no_resizebar
, 1);
360 /* set GNUstep window attributes */
361 if (wwin
->wm_gnustep_attr
) {
362 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
364 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
366 *level
= wwin
->wm_gnustep_attr
->window_level
;
368 * INT_MIN is the only illegal window level.
370 if (*level
== INT_MIN
)
371 *level
= INT_MIN
+ 1;
374 *level
= WMNormalLevel
;
377 int tmp_workspace
= -1;
378 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
384 wMWMCheckClientHints(wwin
);
385 #endif /* MWM_HINTS */
388 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
390 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
391 * have INT_MIN that means that no window level was requested. -Dan
393 if (tmp_level
== INT_MIN
) {
394 if (WFLAGP(wwin
, floating
))
395 *level
= WMFloatingLevel
;
396 else if (WFLAGP(wwin
, sunken
))
397 *level
= WMSunkenLevel
;
399 *level
= WMNormalLevel
;
404 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
405 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
406 if (transientOwner
) {
407 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
408 if (ownerLevel
> *level
)
413 if (tmp_workspace
>= 0)
414 *workspace
= tmp_workspace
% scr
->workspace_count
;
418 * Set attributes specified only for that window/class.
419 * This might do duplicate work with the 1st wDefaultFillAttributes().
421 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
422 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
424 * Sanity checks for attributes that depend on other attributes
426 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
427 wwin
->user_flags
.emulate_appicon
= 0;
429 if (wwin
->main_window
!= None
) {
430 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
431 if (wapp
&& !wapp
->flags
.emulated
)
432 wwin
->user_flags
.emulate_appicon
= 0;
435 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
436 wwin
->user_flags
.emulate_appicon
= 0;
438 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
439 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
440 wwin
->user_flags
.sunken
= 0;
442 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
444 /* windows that have takefocus=False shouldn't take focus at all */
445 if (wwin
->focus_mode
== WFM_NO_INPUT
)
446 wwin
->client_flags
.no_focusable
= 1;
449 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
451 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
453 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
455 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
461 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
465 w1
= wwin
->frame
->core
->width
;
466 h1
= wwin
->frame
->core
->height
;
467 w2
= obscured
->frame
->core
->width
;
468 h2
= obscured
->frame
->core
->height
;
470 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
471 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
474 if (wwin
->frame_x
+ w1
< obscured
->frame_x
475 || wwin
->frame_y
+ h1
< obscured
->frame_y
476 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
482 static void fixLeaderProperties(WWindow
*wwin
)
484 XClassHint
*classHint
;
485 XWMHints
*hints
, *clientHints
;
486 Window leaders
[2], window
;
487 char **argv
, *command
;
491 classHint
= XAllocClassHint();
492 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
493 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
495 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
499 leaders
[0] = wwin
->client_leader
;
500 leaders
[1] = wwin
->group_id
;
503 command
= GetCommandForWindow(wwin
->client_win
);
505 /* command already set. nothing to do. */
508 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
512 for (i
= 0; i
< 2; i
++) {
515 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
516 classHint
->res_name
= wwin
->wm_instance
;
517 classHint
->res_class
= wwin
->wm_class
;
518 XSetClassHint(dpy
, window
, classHint
);
520 hints
= XGetWMHints(dpy
, window
);
523 } else if (clientHints
) {
524 /* set window group leader to self */
525 clientHints
->window_group
= window
;
526 clientHints
->flags
|= WindowGroupHint
;
527 XSetWMHints(dpy
, window
, clientHints
);
531 command
= GetCommandForWindow(window
);
533 /* command already set. nothing to do. */
536 XSetCommand(dpy
, window
, argv
, argc
);
549 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
551 XClassHint
*classHint
;
557 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
559 classHint
= XAllocClassHint();
560 classHint
->res_name
= instance
;
561 classHint
->res_class
= class;
562 XSetClassHint(dpy
, leader
, classHint
);
565 /* inherit these from the original leader if available */
566 hints
= XGetWMHints(dpy
, win
);
568 hints
= XAllocWMHints();
571 /* set window group leader to self */
572 hints
->window_group
= leader
;
573 hints
->flags
|= WindowGroupHint
;
574 XSetWMHints(dpy
, leader
, hints
);
577 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
578 XSetCommand(dpy
, leader
, argv
, argc
);
579 XFreeStringList(argv
);
585 static int matchIdentifier(void *item
, void *cdata
)
587 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
591 *----------------------------------------------------------------
593 * reparents the window and allocates a descriptor for it.
594 * Window manager hints and other hints are fetched to configure
595 * the window decoration attributes and others. User preferences
596 * for the window are used if available, to configure window
597 * decorations and some behaviour.
598 * If in startup, windows that are override redirect,
599 * unmapped and never were managed and are Withdrawn are not
603 * the new window descriptor
606 * The window is reparented and appropriate notification
607 * is done to the client. Input mask for the window is setup.
608 * The window descriptor is also associated with various window
609 * contexts and inserted in the head of the window list.
610 * Event handler contexts are associated for some objects
611 * (buttons, titlebar and resizebar)
613 *----------------------------------------------------------------
615 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
619 unsigned width
, height
;
620 XWindowAttributes wattribs
;
621 XSetWindowAttributes attribs
;
622 WWindowState
*win_state
;
623 WWindow
*transientOwner
= NULL
;
629 Bool withdraw
= False
;
633 /* XGrabServer(dpy); */
635 /* make sure the window is still there */
636 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
641 /* if it's an override-redirect, ignore it */
642 if (wattribs
.override_redirect
) {
647 wm_state
= PropGetWindowState(window
);
649 /* if it's startup and the window is unmapped, don't manage it */
650 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
655 wwin
= wWindowCreate();
657 title
= wNETWMGetWindowName(window
);
659 wwin
->flags
.net_has_title
= 1;
660 if (!title
&& !wFetchName(dpy
, window
, &title
))
663 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
666 printf("managing window %x\n", (unsigned)window
);
670 if (wShapeSupported
) {
675 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
676 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
677 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
678 wwin
->flags
.shaped
= b_shaped
;
683 * Get hints and other information in properties
685 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
687 /* setup descriptor */
688 wwin
->client_win
= window
;
689 wwin
->screen_ptr
= scr
;
690 wwin
->old_border_width
= wattribs
.border_width
;
691 wwin
->event_mask
= CLIENT_EVENTS
;
692 attribs
.event_mask
= CLIENT_EVENTS
;
693 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
694 attribs
.save_under
= False
;
696 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
697 XSetWindowBorderWidth(dpy
, window
, 0);
699 /* get hints from GNUstep app */
700 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
701 wwin
->flags
.is_gnustep
= 1;
703 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
704 wwin
->wm_gnustep_attr
= NULL
;
707 wwin
->client_leader
= PropGetClientLeader(window
);
708 if (wwin
->client_leader
!= None
)
709 wwin
->main_window
= wwin
->client_leader
;
711 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
713 if (wwin
->wm_hints
) {
714 if (wwin
->wm_hints
->flags
& StateHint
) {
716 if (wwin
->wm_hints
->initial_state
== IconicState
) {
718 wwin
->flags
.miniaturized
= 1;
720 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
726 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
727 wwin
->group_id
= wwin
->wm_hints
->window_group
;
728 /* window_group has priority over CLIENT_LEADER */
729 wwin
->main_window
= wwin
->group_id
;
731 wwin
->group_id
= None
;
734 if (wwin
->wm_hints
->flags
& UrgencyHint
)
735 wwin
->flags
.urgent
= 1;
737 wwin
->group_id
= None
;
740 PropGetProtocols(window
, &wwin
->protocols
);
742 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
743 wwin
->transient_for
= None
;
745 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
746 wwin
->transient_for
= scr
->root_win
;
748 transientOwner
= wWindowFor(wwin
->transient_for
);
749 if (transientOwner
&& transientOwner
->main_window
!= None
)
750 wwin
->main_window
= transientOwner
->main_window
;
754 /* guess the focus mode */
755 wwin
->focus_mode
= getFocusMode(wwin
);
757 /* get geometry stuff */
758 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
760 /* get colormap windows */
761 GetColormapWindows(wwin
);
764 * Setup the decoration/window attributes and
767 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
769 /* Make broken apps behave as a nice app. */
770 if (WFLAGP(wwin
, emulate_appicon
))
771 wwin
->main_window
= wwin
->client_win
;
773 fixLeaderProperties(wwin
);
775 wwin
->orig_main_window
= wwin
->main_window
;
777 if (wwin
->flags
.is_gnustep
)
778 WSETUFLAG(wwin
, shared_appicon
, 0);
780 if (wwin
->main_window
) {
781 extern Atom _XA_WINDOWMAKER_MENU
;
782 XTextProperty text_prop
;
784 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
785 WSETUFLAG(wwin
, shared_appicon
, 0);
789 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
790 char *buffer
, *instance
, *class;
791 WFakeGroupLeader
*fPtr
;
794 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
796 /* // only enter here if PropGetWMClass() succeds */
797 PropGetWMClass(wwin
->main_window
, &class, &instance
);
798 buffer
= StrConcatDot(instance
, class);
800 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
801 if (index
!= WANotFound
) {
802 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
803 if (fPtr
->retainCount
== 0) {
804 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
809 if (fPtr
->origLeader
== None
) {
811 if (ADEQUATE(wwin
->group_id
)) {
813 fPtr
->origLeader
= wwin
->group_id
;
814 } else if (ADEQUATE(wwin
->client_leader
)) {
816 fPtr
->origLeader
= wwin
->client_leader
;
817 } else if (ADEQUATE(wwin
->main_window
)) {
819 fPtr
->origLeader
= wwin
->main_window
;
822 if (ADEQUATE(wwin
->main_window
)) {
824 fPtr
->origLeader
= wwin
->main_window
;
828 wwin
->fake_group
= fPtr
;
829 /*wwin->group_id = fPtr->leader; */
830 wwin
->main_window
= fPtr
->leader
;
833 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
835 fPtr
->identifier
= buffer
;
836 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
837 fPtr
->origLeader
= None
;
838 fPtr
->retainCount
= 1;
840 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
843 if (ADEQUATE(wwin
->group_id
)) {
845 fPtr
->origLeader
= wwin
->group_id
;
846 } else if (ADEQUATE(wwin
->client_leader
)) {
848 fPtr
->origLeader
= wwin
->client_leader
;
849 } else if (ADEQUATE(wwin
->main_window
)) {
851 fPtr
->origLeader
= wwin
->main_window
;
854 if (ADEQUATE(wwin
->main_window
)) {
856 fPtr
->origLeader
= wwin
->main_window
;
859 wwin
->fake_group
= fPtr
;
860 /*wwin->group_id = fPtr->leader; */
861 wwin
->main_window
= fPtr
->leader
;
873 * Setup the initial state of the window
875 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
876 wwin
->flags
.miniaturized
= 1;
878 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
879 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
881 wNETWMCheckInitialClientState(wwin
);
883 /* apply previous state if it exists and we're in startup */
884 if (scr
->flags
.startup
&& wm_state
>= 0) {
886 if (wm_state
== IconicState
) {
888 wwin
->flags
.miniaturized
= 1;
890 } else if (wm_state
== WithdrawnState
) {
896 /* if there is a saved state (from file), restore it */
898 if (wwin
->main_window
!= None
)
899 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
901 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
903 if (win_state
&& !withdraw
) {
904 if (win_state
->state
->hidden
> 0)
905 wwin
->flags
.hidden
= win_state
->state
->hidden
;
907 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
908 wwin
->flags
.shaded
= win_state
->state
->shaded
;
910 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
911 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
914 if (!IS_OMNIPRESENT(wwin
)) {
915 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
917 if (w
< 0 || w
>= scr
->workspace_count
) {
918 workspace
= win_state
->state
->workspace
;
919 if (workspace
>= scr
->workspace_count
)
920 workspace
= scr
->current_workspace
;
925 workspace
= scr
->current_workspace
;
929 /* if we're restarting, restore saved state (from hints).
930 * This will overwrite previous */
934 if (getSavedState(window
, &wstate
)) {
935 wwin
->flags
.shaded
= wstate
->shaded
;
936 wwin
->flags
.hidden
= wstate
->hidden
;
937 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
938 wwin
->flags
.maximized
= wstate
->maximized
;
939 if (wwin
->flags
.maximized
) {
940 wwin
->old_geometry
.x
= wstate
->x
;
941 wwin
->old_geometry
.y
= wstate
->y
;
942 wwin
->old_geometry
.width
= wstate
->w
;
943 wwin
->old_geometry
.height
= wstate
->h
;
946 workspace
= wstate
->workspace
;
951 /* restore window shortcut */
952 if (wstate
!= NULL
|| win_state
!= NULL
) {
955 if (win_state
!= NULL
)
956 mask
= win_state
->state
->window_shortcuts
;
958 if (wstate
!= NULL
&& mask
== 0)
959 mask
= wstate
->window_shortcuts
;
964 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
965 if (mask
& (1 << i
)) {
966 if (!scr
->shortcutWindows
[i
])
967 scr
->shortcutWindows
[i
] = WMCreateArray(4);
969 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
978 /* don't let transients start miniaturized if their owners are not */
979 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
980 wwin
->flags
.miniaturized
= 0;
982 wwin
->wm_hints
->initial_state
= NormalState
;
985 /* set workspace on which the window starts */
986 if (workspace
>= 0) {
987 if (workspace
> scr
->workspace_count
- 1) {
988 workspace
= workspace
% scr
->workspace_count
;
993 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
995 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1000 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1002 workspace
= transientOwner
->frame
->workspace
;
1006 workspace
= scr
->current_workspace
;
1011 /* setup window geometry */
1012 if (win_state
&& win_state
->state
->w
> 0) {
1013 width
= win_state
->state
->w
;
1014 height
= win_state
->state
->h
;
1016 wWindowConstrainSize(wwin
, &width
, &height
);
1018 /* do not ask for window placement if the window is
1019 * transient, during startup, if the initial workspace is another one
1020 * or if the window wants to start iconic.
1021 * If geometry was saved, restore it. */
1023 Bool dontBring
= False
;
1025 if (win_state
&& win_state
->state
->w
> 0) {
1026 x
= win_state
->state
->x
;
1027 y
= win_state
->state
->y
;
1028 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
1029 && !scr
->flags
.startup
1030 && workspace
== scr
->current_workspace
1031 && !wwin
->flags
.miniaturized
1032 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
1034 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1035 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
1039 x
= transientOwner
->frame_x
+
1040 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
1041 y
= transientOwner
->frame_y
+
1042 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
1045 * limit transient windows to be inside their parent's head
1047 rect
.pos
.x
= transientOwner
->frame_x
;
1048 rect
.pos
.y
= transientOwner
->frame_y
;
1049 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1050 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1052 head
= wGetHeadForRect(scr
, rect
);
1053 rect
= wGetRectForHead(scr
, head
);
1057 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1058 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1062 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1063 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1066 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1068 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1071 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1077 * Make spash screens come out in the center of a head
1078 * trouble is that most splashies never get here
1079 * they are managed trough atoms but god knows where.
1080 * Dan, do you know ? -peter
1082 * Most of them are not managed, they have set
1083 * OverrideRedirect, which means we can't do anything about
1087 printf("xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
) / 2);
1088 printf("xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
) / 2);
1090 if ((unsigned)(x
+ (width
- scr
->scr_width
) / 2 + 10) < 20 &&
1091 (unsigned)(y
+ (height
- scr
->scr_height
) / 2 + 10) < 20) {
1099 * xinerama checks for: across head and dead space
1103 rect
.size
.width
= width
;
1104 rect
.size
.height
= height
;
1106 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1108 if (flags
& XFLAG_DEAD
)
1111 if (flags
& XFLAG_MULTIPLE
)
1115 switch (reposition
) {
1117 head
= wGetHeadForPointerLocation(scr
);
1118 rect
= wGetRectForHead(scr
, head
);
1120 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1121 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1125 rect
= wGetRectForHead(scr
, head
);
1129 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1130 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1134 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1135 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1144 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1145 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1148 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1150 if (wwin
->flags
.urgent
) {
1151 if (!IS_OMNIPRESENT(wwin
))
1152 wwin
->flags
.omnipresent
^= 1;
1156 * Create frame, borders and do reparenting
1158 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1159 #ifdef XKB_BUTTON_HINT
1160 if (wPreferences
.modelock
)
1161 foo
|= WFF_LANGUAGE_BUTTON
;
1163 if (HAS_TITLEBAR(wwin
))
1164 foo
|= WFF_TITLEBAR
;
1165 if (HAS_RESIZEBAR(wwin
))
1166 foo
|= WFF_RESIZEBAR
;
1167 if (HAS_BORDER(wwin
))
1170 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1171 x
, y
, width
, height
,
1172 &wPreferences
.window_title_clearance
, foo
,
1173 scr
->window_title_texture
,
1174 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1176 wwin
->frame
->flags
.is_client_window_frame
= 1;
1177 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1179 /* setup button images */
1180 wWindowUpdateButtonImages(wwin
);
1182 /* hide unused buttons */
1184 if (WFLAGP(wwin
, no_close_button
))
1185 foo
|= WFF_RIGHT_BUTTON
;
1186 if (WFLAGP(wwin
, no_miniaturize_button
))
1187 foo
|= WFF_LEFT_BUTTON
;
1188 #ifdef XKB_BUTTON_HINT
1189 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1190 foo
|= WFF_LANGUAGE_BUTTON
;
1193 wFrameWindowHideButton(wwin
->frame
, foo
);
1195 wwin
->frame
->child
= wwin
;
1196 wwin
->frame
->workspace
= workspace
;
1197 wwin
->frame
->on_click_left
= windowIconifyClick
;
1199 #ifdef XKB_BUTTON_HINT
1200 if (wPreferences
.modelock
)
1201 wwin
->frame
->on_click_language
= windowLanguageClick
;
1204 wwin
->frame
->on_click_right
= windowCloseClick
;
1205 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1206 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1207 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1208 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1210 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1211 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1212 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1217 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1219 /* if gravity is to the south, account for the border sizes */
1221 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1225 * wWindowConfigure() will init the client window's size
1226 * (wwin->client.{width,height}) and all other geometry
1227 * related variables (frame_x,frame_y)
1229 wWindowConfigure(wwin
, x
, y
, width
, height
);
1231 /* to make sure the window receives it's new position after reparenting */
1232 wWindowSynthConfigureNotify(wwin
);
1235 * Setup descriptors and save window to internal
1238 if (wwin
->main_window
!= None
) {
1242 /* Leader windows do not necessary set themselves as leaders.
1243 * If this is the case, point the leader of this window to
1245 leader
= wWindowFor(wwin
->main_window
);
1246 if (leader
&& leader
->main_window
== None
) {
1247 leader
->main_window
= leader
->client_win
;
1249 app
= wApplicationCreate(wwin
);
1251 app
->last_workspace
= workspace
;
1254 * Do application specific stuff, like setting application
1258 if (wwin
->flags
.hidden
) {
1259 /* if the window was set to hidden because it was hidden
1260 * in a previous incarnation and that state was restored */
1261 app
->flags
.hidden
= 1;
1262 } else if (app
->flags
.hidden
) {
1263 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1264 wwin
->flags
.hidden
= 1;
1266 wUnhideApplication(app
, False
, False
);
1273 /* setup the frame descriptor */
1274 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1275 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1276 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1278 /* don't let windows go away if we die */
1279 XAddToSaveSet(dpy
, window
);
1281 XLowerWindow(dpy
, window
);
1283 /* if window is in this workspace and should be mapped, then map it */
1284 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1285 && !wwin
->flags
.hidden
&& !withdraw
) {
1287 /* The following "if" is to avoid crashing of clients that expect
1288 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1289 * after the return from this function.
1291 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1292 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1294 wClientSetState(wwin
, NormalState
, None
);
1298 /* if not auto focus, then map the window under the currently
1300 #define _WIDTH(w) (w)->frame->core->width
1301 #define _HEIGHT(w) (w)->frame->core->height
1302 if (!wPreferences
.auto_focus
&& scr
->focused_window
1303 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1305 (_WIDTH(scr
->focused_window
) * 5) / 3
1307 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1308 && WINDOW_LEVEL(scr
->focused_window
) ==
1310 || wwin
->flags
.maximized
)) {
1311 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1318 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1319 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1321 * The brain damaged idiotic non-click to focus modes will
1322 * have trouble with this because:
1324 * 1. window is created and mapped by the client
1325 * 2. window is mapped by wmaker in small size
1326 * 3. window is animated to grow to normal size
1327 * 4. this function returns to normal event loop
1328 * 5. eventually, the EnterNotify event that would trigger
1329 * the window focusing (if the mouse is over that window)
1330 * will be processed by wmaker.
1331 * But since this event will be rather delayed
1332 * (step 3 has a large delay) the time when the event ocurred
1333 * and when it is processed, the client that owns that window
1334 * will reject the XSetInputFocus() for it.
1336 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1337 DoWindowBirth(wwin
);
1343 /* setup stacking descriptor */
1344 if (transientOwner
) {
1345 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1347 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1350 if (!scr
->focused_window
) {
1351 /* first window on the list */
1354 scr
->focused_window
= wwin
;
1358 /* add window at beginning of focus window list */
1359 tmp
= scr
->focused_window
;
1367 /* raise is set to true if we un-hid the app when this window was born.
1368 * we raise, else old windows of this app will be above this new one. */
1370 wRaiseFrame(wwin
->frame
->core
);
1373 /* Update name must come after WApplication stuff is done */
1374 wWindowUpdateName(wwin
, title
);
1381 * Final preparations before window is ready to go
1383 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1385 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1386 if (((transientOwner
&& transientOwner
->flags
.focused
)
1387 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1388 wSetFocusTo(scr
, wwin
);
1390 wWindowResetMouseGrabs(wwin
);
1392 if (!WFLAGP(wwin
, no_bind_keys
))
1393 wWindowSetKeyGrabs(wwin
);
1395 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1396 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1398 /* Setup Notification Observers */
1399 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1401 /* Cleanup temporary stuff */
1403 wWindowDeleteSavedState(win_state
);
1405 /* If the window must be withdrawed, then do it now.
1406 * Must do some optimization, 'though */
1408 wwin
->flags
.mapped
= 0;
1409 wClientSetState(wwin
, WithdrawnState
, None
);
1410 wUnmanageWindow(wwin
, True
, False
);
1417 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1418 char *title
, int x
, int y
, int width
, int height
)
1423 wwin
= wWindowCreate();
1425 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1427 wwin
->flags
.internal_window
= 1;
1429 WSETUFLAG(wwin
, omnipresent
, 1);
1430 WSETUFLAG(wwin
, no_shadeable
, 1);
1431 WSETUFLAG(wwin
, no_resizable
, 1);
1432 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1434 wwin
->focus_mode
= WFM_PASSIVE
;
1435 wwin
->client_win
= window
;
1436 wwin
->screen_ptr
= scr
;
1437 wwin
->transient_for
= owner
;
1440 wwin
->client
.width
= width
;
1441 wwin
->client
.height
= height
;
1442 wwin
->frame_x
= wwin
->client
.x
;
1443 wwin
->frame_y
= wwin
->client
.y
;
1445 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1446 foo
|= WFF_TITLEBAR
;
1447 #ifdef XKB_BUTTON_HINT
1448 foo
|= WFF_LANGUAGE_BUTTON
;
1451 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1452 wwin
->frame_x
, wwin
->frame_y
,
1454 &wPreferences
.window_title_clearance
, foo
,
1455 scr
->window_title_texture
,
1456 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1458 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1460 wwin
->frame
->flags
.is_client_window_frame
= 1;
1461 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1463 wFrameWindowChangeTitle(wwin
->frame
, title
);
1465 /* setup button images */
1466 wWindowUpdateButtonImages(wwin
);
1469 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1471 wwin
->frame
->child
= wwin
;
1472 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1474 #ifdef XKB_BUTTON_HINT
1475 if (wPreferences
.modelock
)
1476 wwin
->frame
->on_click_language
= windowLanguageClick
;
1479 wwin
->frame
->on_click_right
= windowCloseClick
;
1480 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1481 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1482 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1483 wwin
->client
.y
+= wwin
->frame
->top_width
;
1485 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1486 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1488 /* setup the frame descriptor */
1489 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1490 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1491 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1493 XLowerWindow(dpy
, window
);
1494 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1496 /* setup stacking descriptor */
1497 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1499 tmp
= wWindowFor(wwin
->transient_for
);
1501 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1503 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1506 if (!scr
->focused_window
) {
1507 /* first window on the list */
1510 scr
->focused_window
= wwin
;
1514 /* add window at beginning of focus window list */
1515 tmp
= scr
->focused_window
;
1523 if (wwin
->flags
.is_gnustep
== 0)
1524 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1526 /* if (wPreferences.auto_focus) */
1527 wSetFocusTo(scr
, wwin
);
1528 wWindowResetMouseGrabs(wwin
);
1529 wWindowSetKeyGrabs(wwin
);
1535 *----------------------------------------------------------------------
1537 * Removes the frame window from a window and destroys all data
1538 * related to it. The window will be reparented back to the root window
1539 * if restore is True.
1542 * Everything related to the window is destroyed and the window
1543 * is removed from the window lists. Focus is set to the previous on the
1545 *----------------------------------------------------------------------
1547 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1549 WCoreWindow
*frame
= wwin
->frame
->core
;
1550 WWindow
*owner
= NULL
;
1551 WWindow
*newFocusedWindow
= NULL
;
1553 WScreen
*scr
= wwin
->screen_ptr
;
1555 /* First close attribute editor window if open */
1556 if (wwin
->flags
.inspector_open
) {
1557 wCloseInspectorForWindow(wwin
);
1560 /* Close window menu if it's open for this window */
1561 if (wwin
->flags
.menu_open_for_me
) {
1562 CloseWindowMenu(scr
);
1566 if (!wwin
->flags
.internal_window
)
1567 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1569 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1571 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1572 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1575 XUnmapWindow(dpy
, frame
->window
);
1577 XUnmapWindow(dpy
, wwin
->client_win
);
1579 /* deselect window */
1580 wSelectWindow(wwin
, False
);
1582 /* remove all pending events on window */
1583 /* I think this only matters for autoraise */
1584 if (wPreferences
.raise_delay
)
1585 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1589 /* reparent the window back to the root */
1591 wClientRestore(wwin
);
1593 if (wwin
->transient_for
!= scr
->root_win
) {
1594 owner
= wWindowFor(wwin
->transient_for
);
1596 if (!owner
->flags
.semi_focused
) {
1599 owner
->flags
.semi_focused
= 0;
1604 wasFocused
= wwin
->flags
.focused
;
1606 /* remove from window focus list */
1607 if (!wwin
->prev
&& !wwin
->next
) {
1608 /* was the only window */
1609 scr
->focused_window
= NULL
;
1610 newFocusedWindow
= NULL
;
1615 wwin
->prev
->next
= wwin
->next
;
1617 wwin
->next
->prev
= wwin
->prev
;
1619 scr
->focused_window
= wwin
->prev
;
1620 scr
->focused_window
->next
= NULL
;
1623 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1625 /* if in click to focus mode and the window
1626 * was a transient, focus the owner window
1629 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1630 tmp
= wWindowFor(wwin
->transient_for
);
1631 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1635 /* otherwise, focus the next one in the focus list */
1637 tmp
= scr
->focused_window
;
1638 while (tmp
) { /* look for one in the window list first */
1639 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1640 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1644 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1645 tmp
= scr
->focused_window
;
1647 if (!WFLAGP(tmp
, no_focusable
)
1648 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1655 newFocusedWindow
= tmp
;
1657 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1662 /* This is to let the root window get the keyboard input
1663 * if Sloppy focus mode and no other window get focus.
1664 * This way keybindings will not freeze.
1667 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1668 tmp
= wWindowFor(win
);
1671 newFocusedWindow
= tmp
;
1673 newFocusedWindow
= NULL
;
1677 if (!wwin
->flags
.internal_window
)
1678 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1680 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
, (unsigned)frame
->window
);
1684 if (newFocusedWindow
!= owner
&& owner
) {
1685 if (wwin
->flags
.is_gnustep
== 0)
1686 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1688 wSetFocusTo(scr
, newFocusedWindow
);
1690 wWindowDestroy(wwin
);
1694 void wWindowMap(WWindow
*wwin
)
1696 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1697 if (!wwin
->flags
.shaded
) {
1698 /* window will be remapped when getting MapNotify */
1699 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1700 XMapWindow(dpy
, wwin
->client_win
);
1701 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1703 wwin
->flags
.mapped
= 1;
1707 void wWindowUnmap(WWindow
*wwin
)
1709 wwin
->flags
.mapped
= 0;
1711 /* prevent window withdrawal when getting UnmapNotify */
1712 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1713 XUnmapWindow(dpy
, wwin
->client_win
);
1714 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1716 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1719 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1724 #ifdef KEEP_XKB_LOCK_STATUS
1725 if (wPreferences
.modelock
) {
1726 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1728 #endif /* KEEP_XKB_LOCK_STATUS */
1730 wwin
->flags
.semi_focused
= 0;
1732 if (wwin
->flags
.is_gnustep
== 0)
1733 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1735 wwin
->flags
.focused
= 1;
1737 wWindowResetMouseGrabs(wwin
);
1739 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1741 if (owin
== wwin
|| !owin
)
1744 nowner
= wWindowFor(wwin
->transient_for
);
1746 /* new window is a transient for the old window */
1747 if (nowner
== owin
) {
1748 owin
->flags
.semi_focused
= 1;
1749 wWindowUnfocus(nowner
);
1753 oowner
= wWindowFor(owin
->transient_for
);
1755 /* new window is owner of old window */
1756 if (wwin
== oowner
) {
1757 wWindowUnfocus(owin
);
1762 wWindowUnfocus(owin
);
1766 /* new window has same owner of old window */
1767 if (oowner
== nowner
) {
1768 /* prevent unfocusing of owner */
1769 oowner
->flags
.semi_focused
= 0;
1770 wWindowUnfocus(owin
);
1771 oowner
->flags
.semi_focused
= 1;
1776 /* nowner != NULL && oowner != nowner */
1777 nowner
->flags
.semi_focused
= 1;
1778 wWindowUnfocus(nowner
);
1779 wWindowUnfocus(owin
);
1782 void wWindowUnfocus(WWindow
*wwin
)
1784 CloseWindowMenu(wwin
->screen_ptr
);
1786 if (wwin
->flags
.is_gnustep
== 0)
1787 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1789 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1791 owner
= wWindowFor(wwin
->transient_for
);
1792 if (owner
&& owner
->flags
.semi_focused
) {
1793 owner
->flags
.semi_focused
= 0;
1794 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1795 wWindowUnfocus(owner
);
1796 wFrameWindowPaint(owner
->frame
);
1800 wwin
->flags
.focused
= 0;
1801 wWindowResetMouseGrabs(wwin
);
1802 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1805 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1812 wwin
->flags
.wm_name_changed
= 1;
1815 /* the hint was removed */
1816 title
= DEF_WINDOW_TITLE
;
1821 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1822 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1827 *----------------------------------------------------------------------
1829 * wWindowConstrainSize--
1830 * Constrains size for the client window, taking the maximal size,
1831 * window resize increments and other size hints into account.
1834 * The closest size to what was given that the client window can
1837 *----------------------------------------------------------------------
1839 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1841 int width
= (int)*nwidth
;
1842 int height
= (int)*nheight
;
1845 int minW
= 1, minH
= 1;
1846 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1847 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1848 int minAX
= -1, minAY
= -1;
1849 int maxAX
= -1, maxAY
= -1;
1853 if (wwin
->normal_hints
) {
1854 winc
= wwin
->normal_hints
->width_inc
;
1855 hinc
= wwin
->normal_hints
->height_inc
;
1856 minW
= wwin
->normal_hints
->min_width
;
1857 minH
= wwin
->normal_hints
->min_height
;
1858 maxW
= wwin
->normal_hints
->max_width
;
1859 maxH
= wwin
->normal_hints
->max_height
;
1860 if (wwin
->normal_hints
->flags
& PAspect
) {
1861 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1862 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1863 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1864 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1867 baseW
= wwin
->normal_hints
->base_width
;
1868 baseH
= wwin
->normal_hints
->base_height
;
1881 /* aspect ratio code borrowed from olwm */
1883 /* adjust max aspect ratio */
1884 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1885 if (maxAX
> maxAY
) {
1886 height
= (width
* maxAY
) / maxAX
;
1887 if (height
> maxH
) {
1889 width
= (height
* maxAX
) / maxAY
;
1892 width
= (height
* maxAX
) / maxAY
;
1895 height
= (width
* maxAY
) / maxAX
;
1900 /* adjust min aspect ratio */
1901 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1902 if (minAX
> minAY
) {
1903 height
= (width
* minAY
) / minAX
;
1904 if (height
< minH
) {
1906 width
= (height
* minAX
) / minAY
;
1909 width
= (height
* minAX
) / minAY
;
1912 height
= (width
* minAY
) / minAX
;
1919 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1921 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1924 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1926 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1928 /* broken stupid apps may cause preposterous values for these.. */
1935 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1936 unsigned int *width
, unsigned int *height
)
1938 int baseW
= 0, baseH
= 0;
1939 int winc
= 1, hinc
= 1;
1941 if (wwin
->normal_hints
) {
1942 baseW
= wwin
->normal_hints
->base_width
;
1943 baseH
= wwin
->normal_hints
->base_height
;
1945 winc
= wwin
->normal_hints
->width_inc
;
1946 hinc
= wwin
->normal_hints
->height_inc
;
1950 *width
= maxW
- (maxW
- baseW
) % winc
;
1953 *height
= maxH
- (maxH
- baseH
) % hinc
;
1956 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1958 WScreen
*scr
= wwin
->screen_ptr
;
1962 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1965 if (workspace
!= scr
->current_workspace
) {
1966 /* Sent to other workspace. Unmap window */
1967 if ((wwin
->flags
.mapped
1968 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1969 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1971 wapp
= wApplicationOf(wwin
->main_window
);
1973 wapp
->last_workspace
= workspace
;
1975 if (wwin
->flags
.miniaturized
) {
1977 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1978 wwin
->icon
->mapped
= 0;
1982 wSetFocusTo(scr
, NULL
);
1986 /* brought to current workspace. Map window */
1987 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1989 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1990 wwin
->icon
->mapped
= 1;
1992 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1996 if (!IS_OMNIPRESENT(wwin
)) {
1997 int oldWorkspace
= wwin
->frame
->workspace
;
1999 wwin
->frame
->workspace
= workspace
;
2001 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
2008 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2012 sevent
.type
= ConfigureNotify
;
2013 sevent
.xconfigure
.display
= dpy
;
2014 sevent
.xconfigure
.event
= wwin
->client_win
;
2015 sevent
.xconfigure
.window
= wwin
->client_win
;
2017 sevent
.xconfigure
.x
= wwin
->client
.x
;
2018 sevent
.xconfigure
.y
= wwin
->client
.y
;
2019 sevent
.xconfigure
.width
= wwin
->client
.width
;
2020 sevent
.xconfigure
.height
= wwin
->client
.height
;
2022 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2023 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2024 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2026 sevent
.xconfigure
.above
= None
;
2028 sevent
.xconfigure
.override_redirect
= False
;
2029 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2034 *----------------------------------------------------------------------
2035 * wWindowConfigure()
2037 * req_x, req_y: new requested positions for the frame
2038 * req_width, req_height: new requested sizes for the client
2040 * Configures the frame, decorations and client window to the specified
2041 * geometry, whose validity is not checked -- wWindowConstrainSize()
2042 * must be used for that.
2043 * The size parameters are for the client window, but the position is
2045 * The client window receives a ConfigureNotify event, according
2046 * to what ICCCM says.
2052 * Window size and position are changed and client window receives
2053 * a ConfigureNotify event.
2054 *----------------------------------------------------------------------
2056 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2058 int synth_notify
= False
;
2061 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2063 * if the window is being moved but not resized then
2064 * send a synthetic ConfigureNotify
2066 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2067 synth_notify
= True
;
2070 if (WFLAGP(wwin
, dont_move_off
))
2071 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2073 if (req_width
< MIN_WINDOW_SIZE
)
2074 req_width
= MIN_WINDOW_SIZE
;
2075 if (req_height
< MIN_WINDOW_SIZE
)
2076 req_height
= MIN_WINDOW_SIZE
;
2078 /* If growing, resize inner part before frame,
2079 * if shrinking, resize frame before.
2080 * This will prevent the frame (that can have a different color)
2081 * to be exposed, causing flicker */
2082 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2083 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2085 if (wwin
->flags
.shaded
) {
2086 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2087 wwin
->old_geometry
.height
= req_height
;
2091 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2093 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2096 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2097 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2099 wwin
->client
.x
= req_x
;
2100 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2101 wwin
->client
.width
= req_width
;
2102 wwin
->client
.height
= req_height
;
2104 wwin
->client
.x
= req_x
;
2105 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2107 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2109 wwin
->frame_x
= req_x
;
2110 wwin
->frame_y
= req_y
;
2111 if (HAS_BORDER(wwin
)) {
2112 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2113 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2116 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2117 wWindowSetShape(wwin
);
2122 wWindowSynthConfigureNotify(wwin
);
2126 /* req_x, req_y: new position of the frame */
2127 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2129 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2130 int synth_notify
= False
;
2132 /* Send a synthetic ConfigureNotify event for every window movement. */
2133 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2134 synth_notify
= True
;
2137 /* A single synthetic ConfigureNotify event is sent at the end of
2138 * a completed (opaque) movement in moveres.c */
2141 if (WFLAGP(wwin
, dont_move_off
))
2142 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2143 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2145 wwin
->client
.x
= req_x
;
2146 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2147 if (HAS_BORDER(wwin
)) {
2148 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2149 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2152 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2154 wwin
->frame_x
= req_x
;
2155 wwin
->frame_y
= req_y
;
2157 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2159 wWindowSynthConfigureNotify(wwin
);
2163 void wWindowUpdateButtonImages(WWindow
*wwin
)
2165 WScreen
*scr
= wwin
->screen_ptr
;
2166 Pixmap pixmap
, mask
;
2167 WFrameWindow
*fwin
= wwin
->frame
;
2169 if (!HAS_TITLEBAR(wwin
))
2172 /* miniaturize button */
2173 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2174 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2175 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2177 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2178 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2183 if (fwin
->lbutton_image
2184 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2185 wPixmapDestroy(fwin
->lbutton_image
);
2186 fwin
->lbutton_image
= NULL
;
2189 if (!fwin
->lbutton_image
) {
2190 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2191 fwin
->lbutton_image
->client_owned
= 1;
2192 fwin
->lbutton_image
->client_owned_mask
= 1;
2195 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2196 wPixmapDestroy(fwin
->lbutton_image
);
2198 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2201 #ifdef XKB_BUTTON_HINT
2202 if (!WFLAGP(wwin
, no_language_button
)) {
2203 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2204 wPixmapDestroy(fwin
->languagebutton_image
);
2206 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2212 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2213 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2215 if (!WFLAGP(wwin
, no_close_button
)) {
2216 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2217 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2219 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2220 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2224 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2225 || fwin
->rbutton_image
->mask
!= mask
)) {
2226 wPixmapDestroy(fwin
->rbutton_image
);
2227 fwin
->rbutton_image
= NULL
;
2230 if (!fwin
->rbutton_image
) {
2231 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2232 fwin
->rbutton_image
->client_owned
= 1;
2233 fwin
->rbutton_image
->client_owned_mask
= 1;
2236 } else if (WFLAGP(wwin
, kill_close
)) {
2238 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2239 wPixmapDestroy(fwin
->rbutton_image
);
2241 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2243 } else if (MGFLAGP(wwin
, broken_close
)) {
2245 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2246 wPixmapDestroy(fwin
->rbutton_image
);
2248 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2252 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2253 wPixmapDestroy(fwin
->rbutton_image
);
2255 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2259 /* force buttons to be redrawn */
2260 fwin
->flags
.need_texture_change
= 1;
2261 wFrameWindowPaint(fwin
);
2265 *---------------------------------------------------------------------------
2266 * wWindowConfigureBorders--
2267 * Update window border configuration according to attribute flags.
2269 *---------------------------------------------------------------------------
2271 void wWindowConfigureBorders(WWindow
*wwin
)
2277 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2279 #ifdef XKB_BUTTON_HINT
2280 flags
|= WFF_LANGUAGE_BUTTON
;
2283 if (HAS_TITLEBAR(wwin
))
2284 flags
|= WFF_TITLEBAR
;
2285 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2286 flags
|= WFF_RESIZEBAR
;
2287 if (HAS_BORDER(wwin
))
2288 flags
|= WFF_BORDER
;
2289 if (wwin
->flags
.shaded
)
2290 flags
|= WFF_IS_SHADED
;
2292 oldh
= wwin
->frame
->top_width
;
2293 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2294 if (oldh
!= wwin
->frame
->top_width
) {
2295 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2297 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2298 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2302 if (!WFLAGP(wwin
, no_miniaturize_button
)
2303 && wwin
->frame
->flags
.hide_left_button
)
2304 flags
|= WFF_LEFT_BUTTON
;
2306 #ifdef XKB_BUTTON_HINT
2307 if (!WFLAGP(wwin
, no_language_button
)
2308 && wwin
->frame
->flags
.hide_language_button
) {
2309 flags
|= WFF_LANGUAGE_BUTTON
;
2313 if (!WFLAGP(wwin
, no_close_button
)
2314 && wwin
->frame
->flags
.hide_right_button
)
2315 flags
|= WFF_RIGHT_BUTTON
;
2318 wWindowUpdateButtonImages(wwin
);
2319 wFrameWindowShowButton(wwin
->frame
, flags
);
2323 if (WFLAGP(wwin
, no_miniaturize_button
)
2324 && !wwin
->frame
->flags
.hide_left_button
)
2325 flags
|= WFF_LEFT_BUTTON
;
2327 #ifdef XKB_BUTTON_HINT
2328 if (WFLAGP(wwin
, no_language_button
)
2329 && !wwin
->frame
->flags
.hide_language_button
)
2330 flags
|= WFF_LANGUAGE_BUTTON
;
2333 if (WFLAGP(wwin
, no_close_button
)
2334 && !wwin
->frame
->flags
.hide_right_button
)
2335 flags
|= WFF_RIGHT_BUTTON
;
2338 wFrameWindowHideButton(wwin
->frame
, flags
);
2341 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2342 wWindowSetShape(wwin
);
2348 void wWindowSaveState(WWindow
* wwin
)
2353 memset(data
, 0, sizeof(CARD32
) * 10);
2354 data
[0] = wwin
->frame
->workspace
;
2355 data
[1] = wwin
->flags
.miniaturized
;
2356 data
[2] = wwin
->flags
.shaded
;
2357 data
[3] = wwin
->flags
.hidden
;
2358 data
[4] = wwin
->flags
.maximized
;
2359 if (wwin
->flags
.maximized
== 0) {
2360 data
[5] = wwin
->frame_x
;
2361 data
[6] = wwin
->frame_y
;
2362 data
[7] = wwin
->frame
->core
->width
;
2363 data
[8] = wwin
->frame
->core
->height
;
2365 data
[5] = wwin
->old_geometry
.x
;
2366 data
[6] = wwin
->old_geometry
.y
;
2367 data
[7] = wwin
->old_geometry
.width
;
2368 data
[8] = wwin
->old_geometry
.height
;
2371 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2372 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2373 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2376 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2377 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2380 static int getSavedState(Window window
, WSavedState
** state
)
2384 unsigned long nitems_ret
;
2385 unsigned long bytes_after_ret
;
2388 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2389 True
, _XA_WINDOWMAKER_STATE
,
2390 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2391 (unsigned char **)&data
) != Success
|| !data
)
2394 *state
= wmalloc(sizeof(WSavedState
));
2396 (*state
)->workspace
= data
[0];
2397 (*state
)->miniaturized
= data
[1];
2398 (*state
)->shaded
= data
[2];
2399 (*state
)->hidden
= data
[3];
2400 (*state
)->maximized
= data
[4];
2401 (*state
)->x
= data
[5];
2402 (*state
)->y
= data
[6];
2403 (*state
)->w
= data
[7];
2404 (*state
)->h
= data
[8];
2405 (*state
)->window_shortcuts
= data
[9];
2409 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2416 void wWindowClearShape(WWindow
* wwin
)
2418 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2419 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2423 void wWindowSetShape(WWindow
* wwin
)
2427 #ifdef OPTIMIZE_SHAPE
2432 /* only shape is the client's */
2433 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2437 /* Get array of rectangles describing the shape mask */
2438 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2443 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2449 /* insert our decoration rectangles in the rect list */
2450 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2453 if (HAS_TITLEBAR(wwin
)) {
2455 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2456 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2457 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2460 if (HAS_RESIZEBAR(wwin
)) {
2462 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2463 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2464 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2468 /* shape our frame window */
2469 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2470 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2476 #endif /* OPTIMIZE_SHAPE */
2478 if (HAS_TITLEBAR(wwin
)) {
2481 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2482 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2485 if (HAS_RESIZEBAR(wwin
)) {
2487 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2488 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2489 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2493 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2494 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2496 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2497 0, wwin
->frame
->top_width
, wwin
->client_win
,
2498 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2503 /* ====================================================================== */
2505 static FocusMode
getFocusMode(WWindow
* wwin
)
2509 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2510 if (wwin
->wm_hints
->input
== True
) {
2511 if (wwin
->protocols
.TAKE_FOCUS
)
2512 mode
= WFM_LOCALLY_ACTIVE
;
2516 if (wwin
->protocols
.TAKE_FOCUS
)
2517 mode
= WFM_GLOBALLY_ACTIVE
;
2519 mode
= WFM_NO_INPUT
;
2527 void wWindowSetKeyGrabs(WWindow
* wwin
)
2532 for (i
= 0; i
< WKBD_LAST
; i
++) {
2533 key
= &wKeyBindings
[i
];
2535 if (key
->keycode
== 0)
2537 if (key
->modifier
!= AnyModifier
) {
2538 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2539 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2541 /* Also grab all modifier combinations possible that include,
2542 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2543 * work even if the NumLock/ScrollLock key is on.
2545 wHackedGrabKey(key
->keycode
, key
->modifier
,
2546 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2549 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2550 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2553 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2556 void wWindowResetMouseGrabs(WWindow
* wwin
)
2558 /* Mouse grabs can't be done on the client window because of
2559 * ICCCM and because clients that try to do the same will crash.
2561 * But there is a problem wich makes tbar buttons of unfocused
2562 * windows not usable as the click goes to the frame window instead
2563 * of the button itself. Must figure a way to fix that.
2566 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2568 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2569 /* grabs for Meta+drag */
2570 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2571 True
, ButtonPressMask
| ButtonReleaseMask
,
2572 GrabModeSync
, GrabModeAsync
, None
, None
);
2575 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2576 && !wwin
->flags
.is_gnustep
) {
2577 /* the passive grabs to focus the window */
2578 /* if (wPreferences.focus_mode == WKF_CLICK) */
2579 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2580 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2585 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2587 if (attr
->flags
& GSExtraFlagsAttr
) {
2588 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2589 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2590 wWindowUpdateButtonImages(wwin
);
2595 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2597 WWindowState
*wstate
;
2599 wstate
= malloc(sizeof(WWindowState
));
2603 memset(wstate
, 0, sizeof(WWindowState
));
2606 wstate
->instance
= wstrdup(instance
);
2608 wstate
->class = wstrdup(class);
2610 wstate
->command
= wstrdup(command
);
2611 wstate
->state
= state
;
2613 wstate
->next
= windowState
;
2614 windowState
= wstate
;
2617 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2623 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2625 WMagicNumber
wWindowGetSavedState(Window win
)
2627 char *instance
, *class, *command
= NULL
;
2628 WWindowState
*wstate
= windowState
;
2633 command
= GetCommandForWindow(win
);
2637 if (PropGetWMClass(win
, &class, &instance
)) {
2639 if (SAME(instance
, wstate
->instance
) &&
2640 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2643 wstate
= wstate
->next
;
2650 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2663 void wWindowDeleteSavedState(WMagicNumber id
)
2665 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2667 if (!wstate
|| !windowState
)
2671 if (tmp
== wstate
) {
2672 windowState
= wstate
->next
;
2674 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2675 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2677 if (wstate
->instance
)
2678 wfree(wstate
->instance
);
2680 wfree(wstate
->class);
2681 if (wstate
->command
)
2682 wfree(wstate
->command
);
2683 wfree(wstate
->state
);
2687 if (tmp
->next
== wstate
) {
2688 tmp
->next
= wstate
->next
;
2690 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2691 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2693 if (wstate
->instance
)
2694 wfree(wstate
->instance
);
2696 wfree(wstate
->class);
2697 if (wstate
->command
)
2698 wfree(wstate
->command
);
2699 wfree(wstate
->state
);
2708 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2710 WWindowState
*tmp
, *wstate
;
2716 if (tmp
->pid
== pid
) {
2717 wstate
= windowState
;
2718 windowState
= tmp
->next
;
2720 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2721 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2723 if (wstate
->instance
)
2724 wfree(wstate
->instance
);
2726 wfree(wstate
->class);
2727 if (wstate
->command
)
2728 wfree(wstate
->command
);
2729 wfree(wstate
->state
);
2733 if (tmp
->next
->pid
== pid
) {
2735 tmp
->next
= wstate
->next
;
2737 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2738 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2740 if (wstate
->instance
)
2741 wfree(wstate
->instance
);
2743 wfree(wstate
->class);
2744 if (wstate
->command
)
2745 wfree(wstate
->command
);
2746 wfree(wstate
->state
);
2755 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2757 if (wwin
->flags
.omnipresent
== flag
)
2760 wwin
->flags
.omnipresent
= flag
;
2761 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2764 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2766 WWindow
*wwin
= data
;
2768 #ifndef NUMLOCK_HACK
2769 if ((event
->xbutton
.state
& ValidModMask
)
2770 != (event
->xbutton
.state
& ~LockMask
)) {
2771 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2772 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2776 event
->xbutton
.state
&= ValidModMask
;
2778 CloseWindowMenu(wwin
->screen_ptr
);
2780 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2781 && !WFLAGP(wwin
, no_focusable
)) {
2782 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2785 if (event
->xbutton
.button
== Button1
)
2786 wRaiseFrame(wwin
->frame
->core
);
2788 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2789 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2790 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2791 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2793 wwarning("pointer grab failed for window move");
2799 if (event
->xbutton
.state
& MOD_MASK
) {
2800 /* move the window */
2801 wMouseMoveWindow(wwin
, event
);
2802 XUngrabPointer(dpy
, CurrentTime
);
2804 wMouseResizeWindow(wwin
, event
);
2805 XUngrabPointer(dpy
, CurrentTime
);
2809 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2811 WWindow
*wwin
= data
;
2813 event
->xbutton
.state
&= ValidModMask
;
2815 if (event
->xbutton
.button
== Button1
) {
2816 if (event
->xbutton
.state
== 0) {
2817 if (!WFLAGP(wwin
, no_shadeable
)) {
2819 if (wwin
->flags
.shaded
)
2820 wUnshadeWindow(wwin
);
2827 if (event
->xbutton
.state
& ControlMask
)
2828 dir
|= MAX_VERTICAL
;
2830 if (event
->xbutton
.state
& ShiftMask
) {
2831 dir
|= MAX_HORIZONTAL
;
2832 if (!(event
->xbutton
.state
& ControlMask
))
2833 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2836 /* maximize window */
2837 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2838 int ndir
= dir
^ wwin
->flags
.maximized
;
2841 wMaximizeWindow(wwin
, ndir
);
2843 wUnmaximizeWindow(wwin
);
2846 } else if (event
->xbutton
.button
== Button3
) {
2847 if (event
->xbutton
.state
& MOD_MASK
) {
2848 wHideOtherApplications(wwin
);
2850 } else if (event
->xbutton
.button
== Button2
) {
2851 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2852 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2854 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2855 wUnshadeWindow(wwin
);
2859 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2861 WWindow
*wwin
= desc
->parent
;
2862 unsigned int new_width
, w_scale
;
2863 unsigned int new_height
, h_scale
;
2864 unsigned int resize_width_increment
= 0;
2865 unsigned int resize_height_increment
= 0;
2867 if (wwin
->normal_hints
) {
2868 w_scale
= ceil(wPreferences
.resize_increment
/ wwin
->normal_hints
->width_inc
);
2869 h_scale
= ceil(wPreferences
.resize_increment
/ wwin
->normal_hints
->height_inc
);
2870 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2871 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2873 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2874 resize_width_increment
= wPreferences
.resize_increment
;
2875 resize_height_increment
= wPreferences
.resize_increment
;
2878 event
->xbutton
.state
&= ValidModMask
;
2880 CloseWindowMenu(wwin
->screen_ptr
);
2882 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2883 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2885 if (event
->xbutton
.button
== Button1
)
2886 wRaiseFrame(wwin
->frame
->core
);
2888 if (event
->xbutton
.state
& MOD_MASK
) {
2889 /* move the window */
2890 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2891 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2892 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2894 wwarning("pointer grab failed for window move");
2898 if (event
->xbutton
.button
== Button3
) {
2899 wMouseResizeWindow(wwin
, event
);
2900 } else if (event
->xbutton
.button
== Button4
) {
2901 new_width
= wwin
->client
.width
- resize_width_increment
;
2902 new_height
= wwin
->client
.height
- resize_height_increment
;
2903 wWindowConstrainSize(wwin
, &new_width
,&new_height
);
2904 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, new_height
);
2905 } else if (event
->xbutton
.button
== Button5
) {
2906 new_width
= wwin
->client
.width
+ resize_width_increment
;
2907 new_height
= wwin
->client
.height
+ resize_height_increment
;
2908 wWindowConstrainSize(wwin
, &new_width
,&new_height
);
2909 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, new_height
);
2910 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2911 wMouseMoveWindow(wwin
, event
);
2913 XUngrabPointer(dpy
, CurrentTime
);
2917 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2919 WWindow
*wwin
= (WWindow
*) data
;
2921 #ifndef NUMLOCK_HACK
2922 if ((event
->xbutton
.state
& ValidModMask
)
2923 != (event
->xbutton
.state
& ~LockMask
)) {
2924 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2925 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2928 event
->xbutton
.state
&= ValidModMask
;
2930 CloseWindowMenu(wwin
->screen_ptr
);
2932 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2933 && !WFLAGP(wwin
, no_focusable
)) {
2934 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2937 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2939 if (event
->xbutton
.button
== Button1
) {
2940 if (event
->xbutton
.state
& MOD_MASK
) {
2941 wLowerFrame(wwin
->frame
->core
);
2943 wRaiseFrame(wwin
->frame
->core
);
2946 if ((event
->xbutton
.state
& ShiftMask
)
2947 && !(event
->xbutton
.state
& ControlMask
)) {
2948 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2951 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2952 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2953 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2954 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2956 wwarning("pointer grab failed for window move");
2961 /* move the window */
2962 wMouseMoveWindow(wwin
, event
);
2964 XUngrabPointer(dpy
, CurrentTime
);
2965 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2966 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2967 WObjDescriptor
*desc
;
2969 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2970 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2971 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2972 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2974 wwarning("pointer grab failed for window move");
2979 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2981 /* allow drag select */
2982 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2983 event
->xany
.send_event
= True
;
2984 (*desc
->handle_mousedown
) (desc
, event
);
2986 XUngrabPointer(dpy
, CurrentTime
);
2990 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2992 WWindow
*wwin
= data
;
2994 event
->xbutton
.state
&= ValidModMask
;
2996 CloseWindowMenu(wwin
->screen_ptr
);
2998 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3001 /* if control-click, kill the client */
3002 if (event
->xbutton
.state
& ControlMask
) {
3005 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
3006 /* send delete message */
3007 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3012 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3014 WWindow
*wwin
= data
;
3016 CloseWindowMenu(wwin
->screen_ptr
);
3018 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3021 /* send delete message */
3022 if (wwin
->protocols
.DELETE_WINDOW
) {
3023 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3029 #ifdef XKB_BUTTON_HINT
3030 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3032 WWindow
*wwin
= data
;
3033 WFrameWindow
*fwin
= wwin
->frame
;
3034 WScreen
*scr
= fwin
->screen_ptr
;
3035 XkbStateRec staterec
;
3038 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3040 tl
= wwin
->frame
->languagemode
;
3041 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3042 wwin
->frame
->last_languagemode
= tl
;
3043 wSetFocusTo(scr
, wwin
);
3044 wwin
->frame
->languagebutton_image
=
3045 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3046 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3047 if (event
->xbutton
.button
== Button3
)
3049 wRaiseFrame(fwin
->core
);
3053 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3055 WWindow
*wwin
= data
;
3057 event
->xbutton
.state
&= ValidModMask
;
3059 CloseWindowMenu(wwin
->screen_ptr
);
3061 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3064 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3065 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3068 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3070 wapp
= wApplicationOf(wwin
->main_window
);
3071 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3072 wHideApplication(wapp
);
3073 } else if (event
->xbutton
.state
== 0) {
3074 wIconifyWindow(wwin
);