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 */
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"
64 #define MOD_MASK wPreferences.modifier_mask
66 /****** Global Variables ******/
67 extern WShortKey wKeyBindings
[WKBD_LAST
];
70 extern Bool wShapeSupported
;
74 extern XContext wWinContext
;
77 extern Cursor wCursor
[WCUR_LAST
];
80 extern Atom _XA_WM_DELETE_WINDOW
;
81 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
82 extern Atom _XA_WINDOWMAKER_STATE
;
84 extern WPreferences wPreferences
;
85 extern Time LastTimestamp
;
88 extern void DoWindowBirth(WWindow
*wwin
);
90 /***** Local Stuff *****/
91 static WWindowState
*windowState
= NULL
;
93 static FocusMode
getFocusMode(WWindow
*wwin
);
94 static int getSavedState(Window window
, WSavedState
**state
);
95 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
97 /* frame window (during window grabs) */
98 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
101 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
102 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
105 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
107 #ifdef XKB_BUTTON_HINT
108 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
111 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
112 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
113 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
115 /****** Notification Observers ******/
117 static void appearanceObserver(void *self
, WMNotification
* notif
)
119 WWindow
*wwin
= (WWindow
*) self
;
120 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
122 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
125 if (flags
& WFontSettings
) {
126 wWindowConfigureBorders(wwin
);
127 if (wwin
->flags
.shaded
) {
128 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
130 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
131 wWindowSynthConfigureNotify(wwin
);
134 if (flags
& WTextureSettings
) {
135 wwin
->frame
->flags
.need_texture_remake
= 1;
137 if (flags
& (WTextureSettings
| WColorSettings
)) {
138 if (wwin
->frame
->titlebar
)
139 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
141 wFrameWindowPaint(wwin
->frame
);
146 WWindow
*wWindowFor(Window window
)
148 WObjDescriptor
*desc
;
153 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
156 if (desc
->parent_type
== WCLASS_WINDOW
)
158 else if (desc
->parent_type
== WCLASS_FRAME
) {
159 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
160 if (frame
->flags
.is_client_window_frame
)
167 WWindow
*wWindowCreate()
171 wwin
= wmalloc(sizeof(WWindow
));
174 memset(wwin
, 0, sizeof(WWindow
));
176 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
177 wwin
->client_descriptor
.parent
= wwin
;
178 wwin
->client_descriptor
.self
= wwin
;
179 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
184 void wWindowDestroy(WWindow
*wwin
)
188 if (wwin
->screen_ptr
->cmap_window
== wwin
)
189 wwin
->screen_ptr
->cmap_window
= NULL
;
191 WMRemoveNotificationObserver(wwin
);
193 wwin
->flags
.destroyed
= 1;
195 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
196 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
199 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
201 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
202 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
203 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
207 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
208 wwin
->fake_group
->retainCount
--;
209 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
210 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
211 wwin
->fake_group
->leader
= None
;
212 wwin
->fake_group
->origLeader
= None
;
217 if (wwin
->normal_hints
)
218 XFree(wwin
->normal_hints
);
221 XFree(wwin
->wm_hints
);
223 if (wwin
->wm_instance
)
224 XFree(wwin
->wm_instance
);
227 XFree(wwin
->wm_class
);
229 if (wwin
->wm_gnustep_attr
)
230 wfree(wwin
->wm_gnustep_attr
);
232 if (wwin
->cmap_windows
)
233 XFree(wwin
->cmap_windows
);
235 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
238 wFrameWindowDestroy(wwin
->frame
);
241 RemoveFromStackList(wwin
->icon
->core
);
242 wIconDestroy(wwin
->icon
);
243 if (wPreferences
.auto_arrange_icons
)
244 wArrangeIcons(wwin
->screen_ptr
, True
);
246 if (wwin
->net_icon_image
)
247 RReleaseImage(wwin
->net_icon_image
);
252 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
254 if (gs_hints
->flags
& GSWindowStyleAttr
) {
255 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
256 wwin
->client_flags
.no_border
= 1;
257 wwin
->client_flags
.no_titlebar
= 1;
258 wwin
->client_flags
.no_closable
= 1;
259 wwin
->client_flags
.no_miniaturizable
= 1;
260 wwin
->client_flags
.no_resizable
= 1;
261 wwin
->client_flags
.no_close_button
= 1;
262 wwin
->client_flags
.no_miniaturize_button
= 1;
263 wwin
->client_flags
.no_resizebar
= 1;
265 wwin
->client_flags
.no_close_button
=
266 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
268 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
270 wwin
->client_flags
.no_miniaturize_button
=
271 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
273 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
275 wwin
->client_flags
.no_resizebar
=
276 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
278 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
280 /* these attributes supposedly imply in the existence
282 if (gs_hints
->window_style
& (WMResizableWindowMask
|
283 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
284 wwin
->client_flags
.no_titlebar
= 0;
286 wwin
->client_flags
.no_titlebar
=
287 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
292 /* setup the defaults */
293 wwin
->client_flags
.no_border
= 0;
294 wwin
->client_flags
.no_titlebar
= 0;
295 wwin
->client_flags
.no_closable
= 0;
296 wwin
->client_flags
.no_miniaturizable
= 0;
297 wwin
->client_flags
.no_resizable
= 0;
298 wwin
->client_flags
.no_close_button
= 0;
299 wwin
->client_flags
.no_miniaturize_button
= 0;
300 wwin
->client_flags
.no_resizebar
= 0;
302 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
303 wwin
->client_flags
.no_appicon
= 1;
306 void wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
, WWindowAttributes
*mask
)
308 if (wflags
->no_appicon
&& mask
->no_appicon
)
309 wflags
->emulate_appicon
= 0;
311 if (wwin
->main_window
!= None
) {
312 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
313 if (wapp
&& !wapp
->flags
.emulated
)
314 wflags
->emulate_appicon
= 0;
317 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
318 wflags
->emulate_appicon
= 0;
320 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
324 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
326 WScreen
*scr
= wwin
->screen_ptr
;
328 /* sets global default stuff */
329 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
331 * Decoration setting is done in this precedence (lower to higher)
332 * - use global default in the resource database
333 * - guess some settings
334 * - use GNUstep/external window attributes
335 * - set hints specified for the app in the resource DB
338 WSETUFLAG(wwin
, broken_close
, 0);
340 if (wwin
->protocols
.DELETE_WINDOW
)
341 WSETUFLAG(wwin
, kill_close
, 0);
343 WSETUFLAG(wwin
, kill_close
, 1);
345 /* transients can't be iconified or maximized */
346 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
347 WSETUFLAG(wwin
, no_miniaturizable
, 1);
348 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
351 /* if the window can't be resized, remove the resizebar */
352 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
353 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
354 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
355 WSETUFLAG(wwin
, no_resizable
, 1);
356 WSETUFLAG(wwin
, no_resizebar
, 1);
359 /* set GNUstep window attributes */
360 if (wwin
->wm_gnustep_attr
) {
361 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
363 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
365 *level
= wwin
->wm_gnustep_attr
->window_level
;
367 * INT_MIN is the only illegal window level.
369 if (*level
== INT_MIN
)
370 *level
= INT_MIN
+ 1;
373 *level
= WMNormalLevel
;
376 int tmp_workspace
= -1;
377 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
383 wMWMCheckClientHints(wwin
);
384 #endif /* MWM_HINTS */
387 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
389 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
390 * have INT_MIN that means that no window level was requested. -Dan
392 if (tmp_level
== INT_MIN
) {
393 if (WFLAGP(wwin
, floating
))
394 *level
= WMFloatingLevel
;
395 else if (WFLAGP(wwin
, sunken
))
396 *level
= WMSunkenLevel
;
398 *level
= WMNormalLevel
;
403 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
404 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
405 if (transientOwner
) {
406 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
407 if (ownerLevel
> *level
)
412 if (tmp_workspace
>= 0)
413 *workspace
= tmp_workspace
% scr
->workspace_count
;
417 * Set attributes specified only for that window/class.
418 * This might do duplicate work with the 1st wDefaultFillAttributes().
420 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
421 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
423 * Sanity checks for attributes that depend on other attributes
425 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
426 wwin
->user_flags
.emulate_appicon
= 0;
428 if (wwin
->main_window
!= None
) {
429 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
430 if (wapp
&& !wapp
->flags
.emulated
)
431 wwin
->user_flags
.emulate_appicon
= 0;
434 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
435 wwin
->user_flags
.emulate_appicon
= 0;
437 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
438 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
439 wwin
->user_flags
.sunken
= 0;
441 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
443 /* windows that have takefocus=False shouldn't take focus at all */
444 if (wwin
->focus_mode
== WFM_NO_INPUT
)
445 wwin
->client_flags
.no_focusable
= 1;
448 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
450 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
452 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
454 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
460 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
464 w1
= wwin
->frame
->core
->width
;
465 h1
= wwin
->frame
->core
->height
;
466 w2
= obscured
->frame
->core
->width
;
467 h2
= obscured
->frame
->core
->height
;
469 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
470 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
473 if (wwin
->frame_x
+ w1
< obscured
->frame_x
474 || wwin
->frame_y
+ h1
< obscured
->frame_y
475 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
481 static void fixLeaderProperties(WWindow
*wwin
)
483 XClassHint
*classHint
;
484 XWMHints
*hints
, *clientHints
;
485 Window leaders
[2], window
;
486 char **argv
, *command
;
490 classHint
= XAllocClassHint();
491 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
492 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
494 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
498 leaders
[0] = wwin
->client_leader
;
499 leaders
[1] = wwin
->group_id
;
502 command
= GetCommandForWindow(wwin
->client_win
);
504 /* command already set. nothing to do. */
507 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
511 for (i
= 0; i
< 2; i
++) {
514 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
515 classHint
->res_name
= wwin
->wm_instance
;
516 classHint
->res_class
= wwin
->wm_class
;
517 XSetClassHint(dpy
, window
, classHint
);
519 hints
= XGetWMHints(dpy
, window
);
522 } else if (clientHints
) {
523 /* set window group leader to self */
524 clientHints
->window_group
= window
;
525 clientHints
->flags
|= WindowGroupHint
;
526 XSetWMHints(dpy
, window
, clientHints
);
530 command
= GetCommandForWindow(window
);
532 /* command already set. nothing to do. */
535 XSetCommand(dpy
, window
, argv
, argc
);
548 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
550 XClassHint
*classHint
;
556 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
558 classHint
= XAllocClassHint();
559 classHint
->res_name
= instance
;
560 classHint
->res_class
= class;
561 XSetClassHint(dpy
, leader
, classHint
);
564 /* inherit these from the original leader if available */
565 hints
= XGetWMHints(dpy
, win
);
567 hints
= XAllocWMHints();
570 /* set window group leader to self */
571 hints
->window_group
= leader
;
572 hints
->flags
|= WindowGroupHint
;
573 XSetWMHints(dpy
, leader
, hints
);
576 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
577 XSetCommand(dpy
, leader
, argv
, argc
);
578 XFreeStringList(argv
);
584 static int matchIdentifier(void *item
, void *cdata
)
586 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
590 *----------------------------------------------------------------
592 * reparents the window and allocates a descriptor for it.
593 * Window manager hints and other hints are fetched to configure
594 * the window decoration attributes and others. User preferences
595 * for the window are used if available, to configure window
596 * decorations and some behaviour.
597 * If in startup, windows that are override redirect,
598 * unmapped and never were managed and are Withdrawn are not
602 * the new window descriptor
605 * The window is reparented and appropriate notification
606 * is done to the client. Input mask for the window is setup.
607 * The window descriptor is also associated with various window
608 * contexts and inserted in the head of the window list.
609 * Event handler contexts are associated for some objects
610 * (buttons, titlebar and resizebar)
612 *----------------------------------------------------------------
614 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
618 unsigned width
, height
;
619 XWindowAttributes wattribs
;
620 XSetWindowAttributes attribs
;
621 WWindowState
*win_state
;
622 WWindow
*transientOwner
= NULL
;
628 Bool withdraw
= False
;
632 /* XGrabServer(dpy); */
634 /* make sure the window is still there */
635 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
640 /* if it's an override-redirect, ignore it */
641 if (wattribs
.override_redirect
) {
646 wm_state
= PropGetWindowState(window
);
648 /* if it's startup and the window is unmapped, don't manage it */
649 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
654 wwin
= wWindowCreate();
656 title
= wNETWMGetWindowName(window
);
658 wwin
->flags
.net_has_title
= 1;
659 if (!title
&& !wFetchName(dpy
, window
, &title
))
662 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
665 printf("managing window %x\n", (unsigned)window
);
669 if (wShapeSupported
) {
674 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
675 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
676 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
677 wwin
->flags
.shaped
= b_shaped
;
682 * Get hints and other information in properties
684 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
686 /* setup descriptor */
687 wwin
->client_win
= window
;
688 wwin
->screen_ptr
= scr
;
689 wwin
->old_border_width
= wattribs
.border_width
;
690 wwin
->event_mask
= CLIENT_EVENTS
;
691 attribs
.event_mask
= CLIENT_EVENTS
;
692 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
693 attribs
.save_under
= False
;
695 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
696 XSetWindowBorderWidth(dpy
, window
, 0);
698 /* get hints from GNUstep app */
699 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
700 wwin
->flags
.is_gnustep
= 1;
702 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
703 wwin
->wm_gnustep_attr
= NULL
;
706 wwin
->client_leader
= PropGetClientLeader(window
);
707 if (wwin
->client_leader
!= None
)
708 wwin
->main_window
= wwin
->client_leader
;
710 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
712 if (wwin
->wm_hints
) {
713 if (wwin
->wm_hints
->flags
& StateHint
) {
715 if (wwin
->wm_hints
->initial_state
== IconicState
) {
717 wwin
->flags
.miniaturized
= 1;
719 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
725 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
726 wwin
->group_id
= wwin
->wm_hints
->window_group
;
727 /* window_group has priority over CLIENT_LEADER */
728 wwin
->main_window
= wwin
->group_id
;
730 wwin
->group_id
= None
;
733 if (wwin
->wm_hints
->flags
& UrgencyHint
)
734 wwin
->flags
.urgent
= 1;
736 wwin
->group_id
= None
;
739 PropGetProtocols(window
, &wwin
->protocols
);
741 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
742 wwin
->transient_for
= None
;
744 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
745 wwin
->transient_for
= scr
->root_win
;
747 transientOwner
= wWindowFor(wwin
->transient_for
);
748 if (transientOwner
&& transientOwner
->main_window
!= None
)
749 wwin
->main_window
= transientOwner
->main_window
;
753 /* guess the focus mode */
754 wwin
->focus_mode
= getFocusMode(wwin
);
756 /* get geometry stuff */
757 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
759 /* get colormap windows */
760 GetColormapWindows(wwin
);
763 * Setup the decoration/window attributes and
766 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
768 /* Make broken apps behave as a nice app. */
769 if (WFLAGP(wwin
, emulate_appicon
))
770 wwin
->main_window
= wwin
->client_win
;
772 fixLeaderProperties(wwin
);
774 wwin
->orig_main_window
= wwin
->main_window
;
776 if (wwin
->flags
.is_gnustep
)
777 WSETUFLAG(wwin
, shared_appicon
, 0);
779 if (wwin
->main_window
) {
780 extern Atom _XA_WINDOWMAKER_MENU
;
781 XTextProperty text_prop
;
783 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
784 WSETUFLAG(wwin
, shared_appicon
, 0);
788 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
789 char *buffer
, *instance
, *class;
790 WFakeGroupLeader
*fPtr
;
793 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
795 /* // only enter here if PropGetWMClass() succeds */
796 PropGetWMClass(wwin
->main_window
, &class, &instance
);
797 buffer
= StrConcatDot(instance
, class);
799 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
800 if (index
!= WANotFound
) {
801 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
802 if (fPtr
->retainCount
== 0) {
803 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
808 if (fPtr
->origLeader
== None
) {
810 if (ADEQUATE(wwin
->group_id
)) {
812 fPtr
->origLeader
= wwin
->group_id
;
813 } else if (ADEQUATE(wwin
->client_leader
)) {
815 fPtr
->origLeader
= wwin
->client_leader
;
816 } else if (ADEQUATE(wwin
->main_window
)) {
818 fPtr
->origLeader
= wwin
->main_window
;
821 if (ADEQUATE(wwin
->main_window
)) {
823 fPtr
->origLeader
= wwin
->main_window
;
827 wwin
->fake_group
= fPtr
;
828 /*wwin->group_id = fPtr->leader; */
829 wwin
->main_window
= fPtr
->leader
;
832 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
834 fPtr
->identifier
= buffer
;
835 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
836 fPtr
->origLeader
= None
;
837 fPtr
->retainCount
= 1;
839 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
842 if (ADEQUATE(wwin
->group_id
)) {
844 fPtr
->origLeader
= wwin
->group_id
;
845 } else if (ADEQUATE(wwin
->client_leader
)) {
847 fPtr
->origLeader
= wwin
->client_leader
;
848 } else if (ADEQUATE(wwin
->main_window
)) {
850 fPtr
->origLeader
= wwin
->main_window
;
853 if (ADEQUATE(wwin
->main_window
)) {
855 fPtr
->origLeader
= wwin
->main_window
;
858 wwin
->fake_group
= fPtr
;
859 /*wwin->group_id = fPtr->leader; */
860 wwin
->main_window
= fPtr
->leader
;
872 * Setup the initial state of the window
874 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
875 wwin
->flags
.miniaturized
= 1;
877 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
878 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
880 wNETWMCheckInitialClientState(wwin
);
882 /* apply previous state if it exists and we're in startup */
883 if (scr
->flags
.startup
&& wm_state
>= 0) {
885 if (wm_state
== IconicState
) {
887 wwin
->flags
.miniaturized
= 1;
889 } else if (wm_state
== WithdrawnState
) {
895 /* if there is a saved state (from file), restore it */
897 if (wwin
->main_window
!= None
)
898 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
900 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
902 if (win_state
&& !withdraw
) {
903 if (win_state
->state
->hidden
> 0)
904 wwin
->flags
.hidden
= win_state
->state
->hidden
;
906 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
907 wwin
->flags
.shaded
= win_state
->state
->shaded
;
909 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
910 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
913 if (!IS_OMNIPRESENT(wwin
)) {
914 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
916 if (w
< 0 || w
>= scr
->workspace_count
) {
917 workspace
= win_state
->state
->workspace
;
918 if (workspace
>= scr
->workspace_count
)
919 workspace
= scr
->current_workspace
;
924 workspace
= scr
->current_workspace
;
928 /* if we're restarting, restore saved state (from hints).
929 * This will overwrite previous */
933 if (getSavedState(window
, &wstate
)) {
934 wwin
->flags
.shaded
= wstate
->shaded
;
935 wwin
->flags
.hidden
= wstate
->hidden
;
936 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
937 wwin
->flags
.maximized
= wstate
->maximized
;
938 if (wwin
->flags
.maximized
) {
939 wwin
->old_geometry
.x
= wstate
->x
;
940 wwin
->old_geometry
.y
= wstate
->y
;
941 wwin
->old_geometry
.width
= wstate
->w
;
942 wwin
->old_geometry
.height
= wstate
->h
;
945 workspace
= wstate
->workspace
;
950 /* restore window shortcut */
951 if (wstate
!= NULL
|| win_state
!= NULL
) {
954 if (win_state
!= NULL
)
955 mask
= win_state
->state
->window_shortcuts
;
957 if (wstate
!= NULL
&& mask
== 0)
958 mask
= wstate
->window_shortcuts
;
963 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
964 if (mask
& (1 << i
)) {
965 if (!scr
->shortcutWindows
[i
])
966 scr
->shortcutWindows
[i
] = WMCreateArray(4);
968 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
977 /* don't let transients start miniaturized if their owners are not */
978 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
979 wwin
->flags
.miniaturized
= 0;
981 wwin
->wm_hints
->initial_state
= NormalState
;
984 /* set workspace on which the window starts */
985 if (workspace
>= 0) {
986 if (workspace
> scr
->workspace_count
- 1) {
987 workspace
= workspace
% scr
->workspace_count
;
992 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
994 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
999 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1001 workspace
= transientOwner
->frame
->workspace
;
1005 workspace
= scr
->current_workspace
;
1010 /* setup window geometry */
1011 if (win_state
&& win_state
->state
->w
> 0) {
1012 width
= win_state
->state
->w
;
1013 height
= win_state
->state
->h
;
1015 wWindowConstrainSize(wwin
, &width
, &height
);
1017 /* do not ask for window placement if the window is
1018 * transient, during startup, if the initial workspace is another one
1019 * or if the window wants to start iconic.
1020 * If geometry was saved, restore it. */
1022 Bool dontBring
= False
;
1024 if (win_state
&& win_state
->state
->w
> 0) {
1025 x
= win_state
->state
->x
;
1026 y
= win_state
->state
->y
;
1027 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
1028 && !scr
->flags
.startup
1029 && workspace
== scr
->current_workspace
1030 && !wwin
->flags
.miniaturized
1031 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
1033 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1034 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
1038 x
= transientOwner
->frame_x
+
1039 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
1040 y
= transientOwner
->frame_y
+
1041 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
1044 * limit transient windows to be inside their parent's head
1046 rect
.pos
.x
= transientOwner
->frame_x
;
1047 rect
.pos
.y
= transientOwner
->frame_y
;
1048 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1049 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1051 head
= wGetHeadForRect(scr
, rect
);
1052 rect
= wGetRectForHead(scr
, head
);
1056 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1057 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1061 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1062 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1065 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1067 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1070 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1076 * Make spash screens come out in the center of a head
1077 * trouble is that most splashies never get here
1078 * they are managed trough atoms but god knows where.
1079 * Dan, do you know ? -peter
1081 * Most of them are not managed, they have set
1082 * OverrideRedirect, which means we can't do anything about
1086 printf("xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
) / 2);
1087 printf("xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
) / 2);
1089 if ((unsigned)(x
+ (width
- scr
->scr_width
) / 2 + 10) < 20 &&
1090 (unsigned)(y
+ (height
- scr
->scr_height
) / 2 + 10) < 20) {
1098 * xinerama checks for: across head and dead space
1102 rect
.size
.width
= width
;
1103 rect
.size
.height
= height
;
1105 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1107 if (flags
& XFLAG_DEAD
)
1110 if (flags
& XFLAG_MULTIPLE
)
1114 switch (reposition
) {
1116 head
= wGetHeadForPointerLocation(scr
);
1117 rect
= wGetRectForHead(scr
, head
);
1119 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1120 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1124 rect
= wGetRectForHead(scr
, head
);
1128 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1129 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1133 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1134 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1143 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1144 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1147 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1149 if (wwin
->flags
.urgent
) {
1150 if (!IS_OMNIPRESENT(wwin
))
1151 wwin
->flags
.omnipresent
^= 1;
1155 * Create frame, borders and do reparenting
1157 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1158 #ifdef XKB_BUTTON_HINT
1159 if (wPreferences
.modelock
)
1160 foo
|= WFF_LANGUAGE_BUTTON
;
1162 if (HAS_TITLEBAR(wwin
))
1163 foo
|= WFF_TITLEBAR
;
1164 if (HAS_RESIZEBAR(wwin
))
1165 foo
|= WFF_RESIZEBAR
;
1166 if (HAS_BORDER(wwin
))
1169 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1170 x
, y
, width
, height
,
1171 &wPreferences
.window_title_clearance
, foo
,
1172 scr
->window_title_texture
,
1173 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1175 wwin
->frame
->flags
.is_client_window_frame
= 1;
1176 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1178 /* setup button images */
1179 wWindowUpdateButtonImages(wwin
);
1181 /* hide unused buttons */
1183 if (WFLAGP(wwin
, no_close_button
))
1184 foo
|= WFF_RIGHT_BUTTON
;
1185 if (WFLAGP(wwin
, no_miniaturize_button
))
1186 foo
|= WFF_LEFT_BUTTON
;
1187 #ifdef XKB_BUTTON_HINT
1188 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1189 foo
|= WFF_LANGUAGE_BUTTON
;
1192 wFrameWindowHideButton(wwin
->frame
, foo
);
1194 wwin
->frame
->child
= wwin
;
1195 wwin
->frame
->workspace
= workspace
;
1196 wwin
->frame
->on_click_left
= windowIconifyClick
;
1198 #ifdef XKB_BUTTON_HINT
1199 if (wPreferences
.modelock
)
1200 wwin
->frame
->on_click_language
= windowLanguageClick
;
1203 wwin
->frame
->on_click_right
= windowCloseClick
;
1204 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1205 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1206 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1207 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1209 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1210 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1211 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1216 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1218 /* if gravity is to the south, account for the border sizes */
1220 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1224 * wWindowConfigure() will init the client window's size
1225 * (wwin->client.{width,height}) and all other geometry
1226 * related variables (frame_x,frame_y)
1228 wWindowConfigure(wwin
, x
, y
, width
, height
);
1230 /* to make sure the window receives it's new position after reparenting */
1231 wWindowSynthConfigureNotify(wwin
);
1234 * Setup descriptors and save window to internal
1237 if (wwin
->main_window
!= None
) {
1241 /* Leader windows do not necessary set themselves as leaders.
1242 * If this is the case, point the leader of this window to
1244 leader
= wWindowFor(wwin
->main_window
);
1245 if (leader
&& leader
->main_window
== None
) {
1246 leader
->main_window
= leader
->client_win
;
1248 app
= wApplicationCreate(wwin
);
1250 app
->last_workspace
= workspace
;
1253 * Do application specific stuff, like setting application
1257 if (wwin
->flags
.hidden
) {
1258 /* if the window was set to hidden because it was hidden
1259 * in a previous incarnation and that state was restored */
1260 app
->flags
.hidden
= 1;
1261 } else if (app
->flags
.hidden
) {
1262 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1263 wwin
->flags
.hidden
= 1;
1265 wUnhideApplication(app
, False
, False
);
1272 /* setup the frame descriptor */
1273 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1274 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1275 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1277 /* don't let windows go away if we die */
1278 XAddToSaveSet(dpy
, window
);
1280 XLowerWindow(dpy
, window
);
1282 /* if window is in this workspace and should be mapped, then map it */
1283 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1284 && !wwin
->flags
.hidden
&& !withdraw
) {
1286 /* The following "if" is to avoid crashing of clients that expect
1287 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1288 * after the return from this function.
1290 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1291 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1293 wClientSetState(wwin
, NormalState
, None
);
1297 /* if not auto focus, then map the window under the currently
1299 #define _WIDTH(w) (w)->frame->core->width
1300 #define _HEIGHT(w) (w)->frame->core->height
1301 if (!wPreferences
.auto_focus
&& scr
->focused_window
1302 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1304 (_WIDTH(scr
->focused_window
) * 5) / 3
1306 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1307 && WINDOW_LEVEL(scr
->focused_window
) ==
1309 || wwin
->flags
.maximized
)) {
1310 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1317 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1318 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1320 * The brain damaged idiotic non-click to focus modes will
1321 * have trouble with this because:
1323 * 1. window is created and mapped by the client
1324 * 2. window is mapped by wmaker in small size
1325 * 3. window is animated to grow to normal size
1326 * 4. this function returns to normal event loop
1327 * 5. eventually, the EnterNotify event that would trigger
1328 * the window focusing (if the mouse is over that window)
1329 * will be processed by wmaker.
1330 * But since this event will be rather delayed
1331 * (step 3 has a large delay) the time when the event ocurred
1332 * and when it is processed, the client that owns that window
1333 * will reject the XSetInputFocus() for it.
1335 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1336 DoWindowBirth(wwin
);
1342 /* setup stacking descriptor */
1343 if (transientOwner
) {
1344 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1346 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1349 if (!scr
->focused_window
) {
1350 /* first window on the list */
1353 scr
->focused_window
= wwin
;
1357 /* add window at beginning of focus window list */
1358 tmp
= scr
->focused_window
;
1366 /* raise is set to true if we un-hid the app when this window was born.
1367 * we raise, else old windows of this app will be above this new one. */
1369 wRaiseFrame(wwin
->frame
->core
);
1372 /* Update name must come after WApplication stuff is done */
1373 wWindowUpdateName(wwin
, title
);
1380 * Final preparations before window is ready to go
1382 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1384 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1385 if (((transientOwner
&& transientOwner
->flags
.focused
)
1386 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1387 wSetFocusTo(scr
, wwin
);
1389 wWindowResetMouseGrabs(wwin
);
1391 if (!WFLAGP(wwin
, no_bind_keys
))
1392 wWindowSetKeyGrabs(wwin
);
1394 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1395 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1397 /* Setup Notification Observers */
1398 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1400 /* Cleanup temporary stuff */
1402 wWindowDeleteSavedState(win_state
);
1404 /* If the window must be withdrawed, then do it now.
1405 * Must do some optimization, 'though */
1407 wwin
->flags
.mapped
= 0;
1408 wClientSetState(wwin
, WithdrawnState
, None
);
1409 wUnmanageWindow(wwin
, True
, False
);
1416 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1417 char *title
, int x
, int y
, int width
, int height
)
1422 wwin
= wWindowCreate();
1424 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1426 wwin
->flags
.internal_window
= 1;
1428 WSETUFLAG(wwin
, omnipresent
, 1);
1429 WSETUFLAG(wwin
, no_shadeable
, 1);
1430 WSETUFLAG(wwin
, no_resizable
, 1);
1431 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1433 wwin
->focus_mode
= WFM_PASSIVE
;
1434 wwin
->client_win
= window
;
1435 wwin
->screen_ptr
= scr
;
1436 wwin
->transient_for
= owner
;
1439 wwin
->client
.width
= width
;
1440 wwin
->client
.height
= height
;
1441 wwin
->frame_x
= wwin
->client
.x
;
1442 wwin
->frame_y
= wwin
->client
.y
;
1444 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1445 foo
|= WFF_TITLEBAR
;
1446 #ifdef XKB_BUTTON_HINT
1447 foo
|= WFF_LANGUAGE_BUTTON
;
1450 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1451 wwin
->frame_x
, wwin
->frame_y
,
1453 &wPreferences
.window_title_clearance
, foo
,
1454 scr
->window_title_texture
,
1455 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1457 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1459 wwin
->frame
->flags
.is_client_window_frame
= 1;
1460 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1462 wFrameWindowChangeTitle(wwin
->frame
, title
);
1464 /* setup button images */
1465 wWindowUpdateButtonImages(wwin
);
1468 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1470 wwin
->frame
->child
= wwin
;
1471 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1473 #ifdef XKB_BUTTON_HINT
1474 if (wPreferences
.modelock
)
1475 wwin
->frame
->on_click_language
= windowLanguageClick
;
1478 wwin
->frame
->on_click_right
= windowCloseClick
;
1479 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1480 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1481 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1482 wwin
->client
.y
+= wwin
->frame
->top_width
;
1484 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1485 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1487 /* setup the frame descriptor */
1488 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1489 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1490 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1492 XLowerWindow(dpy
, window
);
1493 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1495 /* setup stacking descriptor */
1496 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1498 tmp
= wWindowFor(wwin
->transient_for
);
1500 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1502 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1505 if (!scr
->focused_window
) {
1506 /* first window on the list */
1509 scr
->focused_window
= wwin
;
1513 /* add window at beginning of focus window list */
1514 tmp
= scr
->focused_window
;
1522 if (wwin
->flags
.is_gnustep
== 0)
1523 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1525 /* if (wPreferences.auto_focus) */
1526 wSetFocusTo(scr
, wwin
);
1527 wWindowResetMouseGrabs(wwin
);
1528 wWindowSetKeyGrabs(wwin
);
1534 *----------------------------------------------------------------------
1536 * Removes the frame window from a window and destroys all data
1537 * related to it. The window will be reparented back to the root window
1538 * if restore is True.
1541 * Everything related to the window is destroyed and the window
1542 * is removed from the window lists. Focus is set to the previous on the
1544 *----------------------------------------------------------------------
1546 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1548 WCoreWindow
*frame
= wwin
->frame
->core
;
1549 WWindow
*owner
= NULL
;
1550 WWindow
*newFocusedWindow
= NULL
;
1552 WScreen
*scr
= wwin
->screen_ptr
;
1554 /* First close attribute editor window if open */
1555 if (wwin
->flags
.inspector_open
) {
1556 wCloseInspectorForWindow(wwin
);
1559 /* Close window menu if it's open for this window */
1560 if (wwin
->flags
.menu_open_for_me
) {
1561 CloseWindowMenu(scr
);
1565 if (!wwin
->flags
.internal_window
)
1566 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1568 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1570 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1571 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1574 XUnmapWindow(dpy
, frame
->window
);
1576 XUnmapWindow(dpy
, wwin
->client_win
);
1578 /* deselect window */
1579 wSelectWindow(wwin
, False
);
1581 /* remove all pending events on window */
1582 /* I think this only matters for autoraise */
1583 if (wPreferences
.raise_delay
)
1584 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1588 /* reparent the window back to the root */
1590 wClientRestore(wwin
);
1592 if (wwin
->transient_for
!= scr
->root_win
) {
1593 owner
= wWindowFor(wwin
->transient_for
);
1595 if (!owner
->flags
.semi_focused
) {
1598 owner
->flags
.semi_focused
= 0;
1603 wasFocused
= wwin
->flags
.focused
;
1605 /* remove from window focus list */
1606 if (!wwin
->prev
&& !wwin
->next
) {
1607 /* was the only window */
1608 scr
->focused_window
= NULL
;
1609 newFocusedWindow
= NULL
;
1614 wwin
->prev
->next
= wwin
->next
;
1616 wwin
->next
->prev
= wwin
->prev
;
1618 scr
->focused_window
= wwin
->prev
;
1619 scr
->focused_window
->next
= NULL
;
1622 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1624 /* if in click to focus mode and the window
1625 * was a transient, focus the owner window
1628 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1629 tmp
= wWindowFor(wwin
->transient_for
);
1630 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1634 /* otherwise, focus the next one in the focus list */
1636 tmp
= scr
->focused_window
;
1637 while (tmp
) { /* look for one in the window list first */
1638 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1639 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1643 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1644 tmp
= scr
->focused_window
;
1646 if (!WFLAGP(tmp
, no_focusable
)
1647 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1654 newFocusedWindow
= tmp
;
1656 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1661 /* This is to let the root window get the keyboard input
1662 * if Sloppy focus mode and no other window get focus.
1663 * This way keybindings will not freeze.
1666 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1667 tmp
= wWindowFor(win
);
1670 newFocusedWindow
= tmp
;
1672 newFocusedWindow
= NULL
;
1676 if (!wwin
->flags
.internal_window
)
1677 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1679 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
, (unsigned)frame
->window
);
1683 if (newFocusedWindow
!= owner
&& owner
) {
1684 if (wwin
->flags
.is_gnustep
== 0)
1685 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1687 wSetFocusTo(scr
, newFocusedWindow
);
1689 wWindowDestroy(wwin
);
1693 void wWindowMap(WWindow
*wwin
)
1695 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1696 if (!wwin
->flags
.shaded
) {
1697 /* window will be remapped when getting MapNotify */
1698 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1699 XMapWindow(dpy
, wwin
->client_win
);
1700 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1702 wwin
->flags
.mapped
= 1;
1706 void wWindowUnmap(WWindow
*wwin
)
1708 wwin
->flags
.mapped
= 0;
1710 /* prevent window withdrawal when getting UnmapNotify */
1711 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1712 XUnmapWindow(dpy
, wwin
->client_win
);
1713 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1715 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1718 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1723 #ifdef KEEP_XKB_LOCK_STATUS
1724 if (wPreferences
.modelock
) {
1725 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1727 #endif /* KEEP_XKB_LOCK_STATUS */
1729 wwin
->flags
.semi_focused
= 0;
1731 if (wwin
->flags
.is_gnustep
== 0)
1732 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1734 wwin
->flags
.focused
= 1;
1736 wWindowResetMouseGrabs(wwin
);
1738 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1740 if (owin
== wwin
|| !owin
)
1743 nowner
= wWindowFor(wwin
->transient_for
);
1745 /* new window is a transient for the old window */
1746 if (nowner
== owin
) {
1747 owin
->flags
.semi_focused
= 1;
1748 wWindowUnfocus(nowner
);
1752 oowner
= wWindowFor(owin
->transient_for
);
1754 /* new window is owner of old window */
1755 if (wwin
== oowner
) {
1756 wWindowUnfocus(owin
);
1761 wWindowUnfocus(owin
);
1765 /* new window has same owner of old window */
1766 if (oowner
== nowner
) {
1767 /* prevent unfocusing of owner */
1768 oowner
->flags
.semi_focused
= 0;
1769 wWindowUnfocus(owin
);
1770 oowner
->flags
.semi_focused
= 1;
1775 /* nowner != NULL && oowner != nowner */
1776 nowner
->flags
.semi_focused
= 1;
1777 wWindowUnfocus(nowner
);
1778 wWindowUnfocus(owin
);
1781 void wWindowUnfocus(WWindow
*wwin
)
1783 CloseWindowMenu(wwin
->screen_ptr
);
1785 if (wwin
->flags
.is_gnustep
== 0)
1786 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1788 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1790 owner
= wWindowFor(wwin
->transient_for
);
1791 if (owner
&& owner
->flags
.semi_focused
) {
1792 owner
->flags
.semi_focused
= 0;
1793 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1794 wWindowUnfocus(owner
);
1795 wFrameWindowPaint(owner
->frame
);
1799 wwin
->flags
.focused
= 0;
1800 wWindowResetMouseGrabs(wwin
);
1801 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1804 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1811 wwin
->flags
.wm_name_changed
= 1;
1814 /* the hint was removed */
1815 title
= DEF_WINDOW_TITLE
;
1820 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1821 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1826 *----------------------------------------------------------------------
1828 * wWindowConstrainSize--
1829 * Constrains size for the client window, taking the maximal size,
1830 * window resize increments and other size hints into account.
1833 * The closest size to what was given that the client window can
1836 *----------------------------------------------------------------------
1838 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1840 int width
= (int)*nwidth
;
1841 int height
= (int)*nheight
;
1844 int minW
= 1, minH
= 1;
1845 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1846 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1847 int minAX
= -1, minAY
= -1;
1848 int maxAX
= -1, maxAY
= -1;
1852 if (wwin
->normal_hints
) {
1853 winc
= wwin
->normal_hints
->width_inc
;
1854 hinc
= wwin
->normal_hints
->height_inc
;
1855 minW
= wwin
->normal_hints
->min_width
;
1856 minH
= wwin
->normal_hints
->min_height
;
1857 maxW
= wwin
->normal_hints
->max_width
;
1858 maxH
= wwin
->normal_hints
->max_height
;
1859 if (wwin
->normal_hints
->flags
& PAspect
) {
1860 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1861 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1862 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1863 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1866 baseW
= wwin
->normal_hints
->base_width
;
1867 baseH
= wwin
->normal_hints
->base_height
;
1880 /* aspect ratio code borrowed from olwm */
1882 /* adjust max aspect ratio */
1883 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1884 if (maxAX
> maxAY
) {
1885 height
= (width
* maxAY
) / maxAX
;
1886 if (height
> maxH
) {
1888 width
= (height
* maxAX
) / maxAY
;
1891 width
= (height
* maxAX
) / maxAY
;
1894 height
= (width
* maxAY
) / maxAX
;
1899 /* adjust min aspect ratio */
1900 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1901 if (minAX
> minAY
) {
1902 height
= (width
* minAY
) / minAX
;
1903 if (height
< minH
) {
1905 width
= (height
* minAX
) / minAY
;
1908 width
= (height
* minAX
) / minAY
;
1911 height
= (width
* minAY
) / minAX
;
1918 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1920 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1923 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1925 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1927 /* broken stupid apps may cause preposterous values for these.. */
1934 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1935 unsigned int *width
, unsigned int *height
)
1937 int baseW
= 0, baseH
= 0;
1938 int winc
= 1, hinc
= 1;
1940 if (wwin
->normal_hints
) {
1941 baseW
= wwin
->normal_hints
->base_width
;
1942 baseH
= wwin
->normal_hints
->base_height
;
1944 winc
= wwin
->normal_hints
->width_inc
;
1945 hinc
= wwin
->normal_hints
->height_inc
;
1949 *width
= maxW
- (maxW
- baseW
) % winc
;
1952 *height
= maxH
- (maxH
- baseH
) % hinc
;
1955 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1957 WScreen
*scr
= wwin
->screen_ptr
;
1961 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1964 if (workspace
!= scr
->current_workspace
) {
1965 /* Sent to other workspace. Unmap window */
1966 if ((wwin
->flags
.mapped
1967 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1968 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1970 wapp
= wApplicationOf(wwin
->main_window
);
1972 wapp
->last_workspace
= workspace
;
1974 if (wwin
->flags
.miniaturized
) {
1976 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1977 wwin
->icon
->mapped
= 0;
1981 wSetFocusTo(scr
, NULL
);
1985 /* brought to current workspace. Map window */
1986 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1988 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1989 wwin
->icon
->mapped
= 1;
1991 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1995 if (!IS_OMNIPRESENT(wwin
)) {
1996 int oldWorkspace
= wwin
->frame
->workspace
;
1998 wwin
->frame
->workspace
= workspace
;
2000 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
2007 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2011 sevent
.type
= ConfigureNotify
;
2012 sevent
.xconfigure
.display
= dpy
;
2013 sevent
.xconfigure
.event
= wwin
->client_win
;
2014 sevent
.xconfigure
.window
= wwin
->client_win
;
2016 sevent
.xconfigure
.x
= wwin
->client
.x
;
2017 sevent
.xconfigure
.y
= wwin
->client
.y
;
2018 sevent
.xconfigure
.width
= wwin
->client
.width
;
2019 sevent
.xconfigure
.height
= wwin
->client
.height
;
2021 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2022 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2023 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2025 sevent
.xconfigure
.above
= None
;
2027 sevent
.xconfigure
.override_redirect
= False
;
2028 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2033 *----------------------------------------------------------------------
2034 * wWindowConfigure()
2036 * req_x, req_y: new requested positions for the frame
2037 * req_width, req_height: new requested sizes for the client
2039 * Configures the frame, decorations and client window to the specified
2040 * geometry, whose validity is not checked -- wWindowConstrainSize()
2041 * must be used for that.
2042 * The size parameters are for the client window, but the position is
2044 * The client window receives a ConfigureNotify event, according
2045 * to what ICCCM says.
2051 * Window size and position are changed and client window receives
2052 * a ConfigureNotify event.
2053 *----------------------------------------------------------------------
2055 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2057 int synth_notify
= False
;
2060 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2062 * if the window is being moved but not resized then
2063 * send a synthetic ConfigureNotify
2065 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2066 synth_notify
= True
;
2069 if (WFLAGP(wwin
, dont_move_off
))
2070 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2072 if (req_width
< MIN_WINDOW_SIZE
)
2073 req_width
= MIN_WINDOW_SIZE
;
2074 if (req_height
< MIN_WINDOW_SIZE
)
2075 req_height
= MIN_WINDOW_SIZE
;
2077 /* If growing, resize inner part before frame,
2078 * if shrinking, resize frame before.
2079 * This will prevent the frame (that can have a different color)
2080 * to be exposed, causing flicker */
2081 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2082 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2084 if (wwin
->flags
.shaded
) {
2085 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2086 wwin
->old_geometry
.height
= req_height
;
2090 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2092 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2095 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2096 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2098 wwin
->client
.x
= req_x
;
2099 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2100 wwin
->client
.width
= req_width
;
2101 wwin
->client
.height
= req_height
;
2103 wwin
->client
.x
= req_x
;
2104 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2106 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2108 wwin
->frame_x
= req_x
;
2109 wwin
->frame_y
= req_y
;
2110 if (HAS_BORDER(wwin
)) {
2111 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2112 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2115 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2116 wWindowSetShape(wwin
);
2121 wWindowSynthConfigureNotify(wwin
);
2125 /* req_x, req_y: new position of the frame */
2126 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2128 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2129 int synth_notify
= False
;
2131 /* Send a synthetic ConfigureNotify event for every window movement. */
2132 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2133 synth_notify
= True
;
2136 /* A single synthetic ConfigureNotify event is sent at the end of
2137 * a completed (opaque) movement in moveres.c */
2140 if (WFLAGP(wwin
, dont_move_off
))
2141 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2142 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2144 wwin
->client
.x
= req_x
;
2145 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2146 if (HAS_BORDER(wwin
)) {
2147 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2148 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2151 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2153 wwin
->frame_x
= req_x
;
2154 wwin
->frame_y
= req_y
;
2156 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2158 wWindowSynthConfigureNotify(wwin
);
2162 void wWindowUpdateButtonImages(WWindow
*wwin
)
2164 WScreen
*scr
= wwin
->screen_ptr
;
2165 Pixmap pixmap
, mask
;
2166 WFrameWindow
*fwin
= wwin
->frame
;
2168 if (!HAS_TITLEBAR(wwin
))
2171 /* miniaturize button */
2172 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2173 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2174 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2176 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2177 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2182 if (fwin
->lbutton_image
2183 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2184 wPixmapDestroy(fwin
->lbutton_image
);
2185 fwin
->lbutton_image
= NULL
;
2188 if (!fwin
->lbutton_image
) {
2189 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2190 fwin
->lbutton_image
->client_owned
= 1;
2191 fwin
->lbutton_image
->client_owned_mask
= 1;
2194 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2195 wPixmapDestroy(fwin
->lbutton_image
);
2197 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2200 #ifdef XKB_BUTTON_HINT
2201 if (!WFLAGP(wwin
, no_language_button
)) {
2202 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2203 wPixmapDestroy(fwin
->languagebutton_image
);
2205 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2211 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2212 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2214 if (!WFLAGP(wwin
, no_close_button
)) {
2215 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2216 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2218 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2219 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2223 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2224 || fwin
->rbutton_image
->mask
!= mask
)) {
2225 wPixmapDestroy(fwin
->rbutton_image
);
2226 fwin
->rbutton_image
= NULL
;
2229 if (!fwin
->rbutton_image
) {
2230 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2231 fwin
->rbutton_image
->client_owned
= 1;
2232 fwin
->rbutton_image
->client_owned_mask
= 1;
2235 } else if (WFLAGP(wwin
, kill_close
)) {
2237 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2238 wPixmapDestroy(fwin
->rbutton_image
);
2240 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2242 } else if (MGFLAGP(wwin
, broken_close
)) {
2244 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2245 wPixmapDestroy(fwin
->rbutton_image
);
2247 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2251 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2252 wPixmapDestroy(fwin
->rbutton_image
);
2254 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2258 /* force buttons to be redrawn */
2259 fwin
->flags
.need_texture_change
= 1;
2260 wFrameWindowPaint(fwin
);
2264 *---------------------------------------------------------------------------
2265 * wWindowConfigureBorders--
2266 * Update window border configuration according to attribute flags.
2268 *---------------------------------------------------------------------------
2270 void wWindowConfigureBorders(WWindow
*wwin
)
2276 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2278 #ifdef XKB_BUTTON_HINT
2279 flags
|= WFF_LANGUAGE_BUTTON
;
2282 if (HAS_TITLEBAR(wwin
))
2283 flags
|= WFF_TITLEBAR
;
2284 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2285 flags
|= WFF_RESIZEBAR
;
2286 if (HAS_BORDER(wwin
))
2287 flags
|= WFF_BORDER
;
2288 if (wwin
->flags
.shaded
)
2289 flags
|= WFF_IS_SHADED
;
2291 oldh
= wwin
->frame
->top_width
;
2292 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2293 if (oldh
!= wwin
->frame
->top_width
) {
2294 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2296 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2297 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2301 if (!WFLAGP(wwin
, no_miniaturize_button
)
2302 && wwin
->frame
->flags
.hide_left_button
)
2303 flags
|= WFF_LEFT_BUTTON
;
2305 #ifdef XKB_BUTTON_HINT
2306 if (!WFLAGP(wwin
, no_language_button
)
2307 && wwin
->frame
->flags
.hide_language_button
) {
2308 flags
|= WFF_LANGUAGE_BUTTON
;
2312 if (!WFLAGP(wwin
, no_close_button
)
2313 && wwin
->frame
->flags
.hide_right_button
)
2314 flags
|= WFF_RIGHT_BUTTON
;
2317 wWindowUpdateButtonImages(wwin
);
2318 wFrameWindowShowButton(wwin
->frame
, flags
);
2322 if (WFLAGP(wwin
, no_miniaturize_button
)
2323 && !wwin
->frame
->flags
.hide_left_button
)
2324 flags
|= WFF_LEFT_BUTTON
;
2326 #ifdef XKB_BUTTON_HINT
2327 if (WFLAGP(wwin
, no_language_button
)
2328 && !wwin
->frame
->flags
.hide_language_button
)
2329 flags
|= WFF_LANGUAGE_BUTTON
;
2332 if (WFLAGP(wwin
, no_close_button
)
2333 && !wwin
->frame
->flags
.hide_right_button
)
2334 flags
|= WFF_RIGHT_BUTTON
;
2337 wFrameWindowHideButton(wwin
->frame
, flags
);
2340 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2341 wWindowSetShape(wwin
);
2347 void wWindowSaveState(WWindow
* wwin
)
2352 memset(data
, 0, sizeof(CARD32
) * 10);
2353 data
[0] = wwin
->frame
->workspace
;
2354 data
[1] = wwin
->flags
.miniaturized
;
2355 data
[2] = wwin
->flags
.shaded
;
2356 data
[3] = wwin
->flags
.hidden
;
2357 data
[4] = wwin
->flags
.maximized
;
2358 if (wwin
->flags
.maximized
== 0) {
2359 data
[5] = wwin
->frame_x
;
2360 data
[6] = wwin
->frame_y
;
2361 data
[7] = wwin
->frame
->core
->width
;
2362 data
[8] = wwin
->frame
->core
->height
;
2364 data
[5] = wwin
->old_geometry
.x
;
2365 data
[6] = wwin
->old_geometry
.y
;
2366 data
[7] = wwin
->old_geometry
.width
;
2367 data
[8] = wwin
->old_geometry
.height
;
2370 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2371 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2372 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2375 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2376 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2379 static int getSavedState(Window window
, WSavedState
** state
)
2383 unsigned long nitems_ret
;
2384 unsigned long bytes_after_ret
;
2387 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2388 True
, _XA_WINDOWMAKER_STATE
,
2389 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2390 (unsigned char **)&data
) != Success
|| !data
)
2393 *state
= wmalloc(sizeof(WSavedState
));
2395 (*state
)->workspace
= data
[0];
2396 (*state
)->miniaturized
= data
[1];
2397 (*state
)->shaded
= data
[2];
2398 (*state
)->hidden
= data
[3];
2399 (*state
)->maximized
= data
[4];
2400 (*state
)->x
= data
[5];
2401 (*state
)->y
= data
[6];
2402 (*state
)->w
= data
[7];
2403 (*state
)->h
= data
[8];
2404 (*state
)->window_shortcuts
= data
[9];
2408 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2415 void wWindowClearShape(WWindow
* wwin
)
2417 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2418 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2422 void wWindowSetShape(WWindow
* wwin
)
2426 #ifdef OPTIMIZE_SHAPE
2431 /* only shape is the client's */
2432 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2436 /* Get array of rectangles describing the shape mask */
2437 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2442 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2448 /* insert our decoration rectangles in the rect list */
2449 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2452 if (HAS_TITLEBAR(wwin
)) {
2454 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2455 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2456 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2459 if (HAS_RESIZEBAR(wwin
)) {
2461 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2462 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2463 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2467 /* shape our frame window */
2468 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2469 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2475 #endif /* OPTIMIZE_SHAPE */
2477 if (HAS_TITLEBAR(wwin
)) {
2480 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2481 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2484 if (HAS_RESIZEBAR(wwin
)) {
2486 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2487 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2488 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2492 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2493 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2495 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2496 0, wwin
->frame
->top_width
, wwin
->client_win
,
2497 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2502 /* ====================================================================== */
2504 static FocusMode
getFocusMode(WWindow
* wwin
)
2508 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2509 if (wwin
->wm_hints
->input
== True
) {
2510 if (wwin
->protocols
.TAKE_FOCUS
)
2511 mode
= WFM_LOCALLY_ACTIVE
;
2515 if (wwin
->protocols
.TAKE_FOCUS
)
2516 mode
= WFM_GLOBALLY_ACTIVE
;
2518 mode
= WFM_NO_INPUT
;
2526 void wWindowSetKeyGrabs(WWindow
* wwin
)
2531 for (i
= 0; i
< WKBD_LAST
; i
++) {
2532 key
= &wKeyBindings
[i
];
2534 if (key
->keycode
== 0)
2536 if (key
->modifier
!= AnyModifier
) {
2537 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2538 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2540 /* Also grab all modifier combinations possible that include,
2541 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2542 * work even if the NumLock/ScrollLock key is on.
2544 wHackedGrabKey(key
->keycode
, key
->modifier
,
2545 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2548 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2549 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2552 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2555 void wWindowResetMouseGrabs(WWindow
* wwin
)
2557 /* Mouse grabs can't be done on the client window because of
2558 * ICCCM and because clients that try to do the same will crash.
2560 * But there is a problem wich makes tbar buttons of unfocused
2561 * windows not usable as the click goes to the frame window instead
2562 * of the button itself. Must figure a way to fix that.
2565 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2567 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2568 /* grabs for Meta+drag */
2569 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2570 True
, ButtonPressMask
| ButtonReleaseMask
,
2571 GrabModeSync
, GrabModeAsync
, None
, None
);
2574 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2575 && !wwin
->flags
.is_gnustep
) {
2576 /* the passive grabs to focus the window */
2577 /* if (wPreferences.focus_mode == WKF_CLICK) */
2578 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2579 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2584 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2586 if (attr
->flags
& GSExtraFlagsAttr
) {
2587 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2588 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2589 wWindowUpdateButtonImages(wwin
);
2594 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2596 WWindowState
*wstate
;
2598 wstate
= malloc(sizeof(WWindowState
));
2602 memset(wstate
, 0, sizeof(WWindowState
));
2605 wstate
->instance
= wstrdup(instance
);
2607 wstate
->class = wstrdup(class);
2609 wstate
->command
= wstrdup(command
);
2610 wstate
->state
= state
;
2612 wstate
->next
= windowState
;
2613 windowState
= wstate
;
2616 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2622 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2624 WMagicNumber
wWindowGetSavedState(Window win
)
2626 char *instance
, *class, *command
= NULL
;
2627 WWindowState
*wstate
= windowState
;
2632 command
= GetCommandForWindow(win
);
2636 if (PropGetWMClass(win
, &class, &instance
)) {
2638 if (SAME(instance
, wstate
->instance
) &&
2639 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2642 wstate
= wstate
->next
;
2649 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2662 void wWindowDeleteSavedState(WMagicNumber id
)
2664 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2666 if (!wstate
|| !windowState
)
2670 if (tmp
== wstate
) {
2671 windowState
= wstate
->next
;
2673 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2674 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2676 if (wstate
->instance
)
2677 wfree(wstate
->instance
);
2679 wfree(wstate
->class);
2680 if (wstate
->command
)
2681 wfree(wstate
->command
);
2682 wfree(wstate
->state
);
2686 if (tmp
->next
== wstate
) {
2687 tmp
->next
= wstate
->next
;
2689 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2690 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2692 if (wstate
->instance
)
2693 wfree(wstate
->instance
);
2695 wfree(wstate
->class);
2696 if (wstate
->command
)
2697 wfree(wstate
->command
);
2698 wfree(wstate
->state
);
2707 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2709 WWindowState
*tmp
, *wstate
;
2715 if (tmp
->pid
== pid
) {
2716 wstate
= windowState
;
2717 windowState
= tmp
->next
;
2719 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2720 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2722 if (wstate
->instance
)
2723 wfree(wstate
->instance
);
2725 wfree(wstate
->class);
2726 if (wstate
->command
)
2727 wfree(wstate
->command
);
2728 wfree(wstate
->state
);
2732 if (tmp
->next
->pid
== pid
) {
2734 tmp
->next
= wstate
->next
;
2736 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2737 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2739 if (wstate
->instance
)
2740 wfree(wstate
->instance
);
2742 wfree(wstate
->class);
2743 if (wstate
->command
)
2744 wfree(wstate
->command
);
2745 wfree(wstate
->state
);
2754 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2756 if (wwin
->flags
.omnipresent
== flag
)
2759 wwin
->flags
.omnipresent
= flag
;
2760 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2763 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2765 WWindow
*wwin
= data
;
2767 #ifndef NUMLOCK_HACK
2768 if ((event
->xbutton
.state
& ValidModMask
)
2769 != (event
->xbutton
.state
& ~LockMask
)) {
2770 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2771 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2775 event
->xbutton
.state
&= ValidModMask
;
2777 CloseWindowMenu(wwin
->screen_ptr
);
2779 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2780 && !WFLAGP(wwin
, no_focusable
)) {
2781 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2784 if (event
->xbutton
.button
== Button1
)
2785 wRaiseFrame(wwin
->frame
->core
);
2787 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2788 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2789 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2790 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2792 wwarning("pointer grab failed for window move");
2798 if (event
->xbutton
.state
& MOD_MASK
) {
2799 /* move the window */
2800 wMouseMoveWindow(wwin
, event
);
2801 XUngrabPointer(dpy
, CurrentTime
);
2803 wMouseResizeWindow(wwin
, event
);
2804 XUngrabPointer(dpy
, CurrentTime
);
2808 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2810 WWindow
*wwin
= data
;
2812 event
->xbutton
.state
&= ValidModMask
;
2814 if (event
->xbutton
.button
== Button1
) {
2815 if (event
->xbutton
.state
== 0) {
2816 if (!WFLAGP(wwin
, no_shadeable
)) {
2818 if (wwin
->flags
.shaded
)
2819 wUnshadeWindow(wwin
);
2826 if (event
->xbutton
.state
& ControlMask
)
2827 dir
|= MAX_VERTICAL
;
2829 if (event
->xbutton
.state
& ShiftMask
) {
2830 dir
|= MAX_HORIZONTAL
;
2831 if (!(event
->xbutton
.state
& ControlMask
))
2832 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2835 /* maximize window */
2836 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2837 int ndir
= dir
^ wwin
->flags
.maximized
;
2840 wMaximizeWindow(wwin
, ndir
);
2842 wUnmaximizeWindow(wwin
);
2845 } else if (event
->xbutton
.button
== Button3
) {
2846 if (event
->xbutton
.state
& MOD_MASK
) {
2847 wHideOtherApplications(wwin
);
2849 } else if (event
->xbutton
.button
== Button2
) {
2850 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2851 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2853 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2854 wUnshadeWindow(wwin
);
2858 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2860 WWindow
*wwin
= desc
->parent
;
2861 unsigned int new_width
;
2862 unsigned int new_height
;
2863 unsigned int resize_width_increment
= 0;
2864 unsigned int resize_height_increment
= 0;
2866 if (wwin
->normal_hints
) {
2867 resize_width_increment
= wwin
->normal_hints
->width_inc
;
2868 resize_height_increment
= wwin
->normal_hints
->height_inc
;
2870 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2871 resize_width_increment
= wPreferences
.resize_increment
;
2872 resize_height_increment
= wPreferences
.resize_increment
;
2875 event
->xbutton
.state
&= ValidModMask
;
2877 CloseWindowMenu(wwin
->screen_ptr
);
2879 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2880 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2882 if (event
->xbutton
.button
== Button1
)
2883 wRaiseFrame(wwin
->frame
->core
);
2885 if (event
->xbutton
.state
& MOD_MASK
) {
2886 /* move the window */
2887 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2888 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2889 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2891 wwarning("pointer grab failed for window move");
2895 if (event
->xbutton
.button
== Button3
) {
2896 wMouseResizeWindow(wwin
, event
);
2897 } else if (event
->xbutton
.button
== Button4
) {
2898 new_width
= wwin
->client
.width
- resize_width_increment
;
2899 new_height
= wwin
->client
.height
- resize_height_increment
;
2900 wWindowConstrainSize(wwin
, &new_width
,&new_height
);
2901 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, new_height
);
2902 } else if (event
->xbutton
.button
== Button5
) {
2903 new_width
= wwin
->client
.width
+ resize_width_increment
;
2904 new_height
= wwin
->client
.height
+ resize_height_increment
;
2905 wWindowConstrainSize(wwin
, &new_width
,&new_height
);
2906 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, new_height
);
2907 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2908 wMouseMoveWindow(wwin
, event
);
2910 XUngrabPointer(dpy
, CurrentTime
);
2914 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2916 WWindow
*wwin
= (WWindow
*) data
;
2918 #ifndef NUMLOCK_HACK
2919 if ((event
->xbutton
.state
& ValidModMask
)
2920 != (event
->xbutton
.state
& ~LockMask
)) {
2921 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2922 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2925 event
->xbutton
.state
&= ValidModMask
;
2927 CloseWindowMenu(wwin
->screen_ptr
);
2929 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2930 && !WFLAGP(wwin
, no_focusable
)) {
2931 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2934 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2936 if (event
->xbutton
.button
== Button1
) {
2937 if (event
->xbutton
.state
& MOD_MASK
) {
2938 wLowerFrame(wwin
->frame
->core
);
2940 wRaiseFrame(wwin
->frame
->core
);
2943 if ((event
->xbutton
.state
& ShiftMask
)
2944 && !(event
->xbutton
.state
& ControlMask
)) {
2945 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2948 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2949 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2950 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2951 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2953 wwarning("pointer grab failed for window move");
2958 /* move the window */
2959 wMouseMoveWindow(wwin
, event
);
2961 XUngrabPointer(dpy
, CurrentTime
);
2962 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2963 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2964 WObjDescriptor
*desc
;
2966 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2967 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2968 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2969 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2971 wwarning("pointer grab failed for window move");
2976 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2978 /* allow drag select */
2979 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2980 event
->xany
.send_event
= True
;
2981 (*desc
->handle_mousedown
) (desc
, event
);
2983 XUngrabPointer(dpy
, CurrentTime
);
2987 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2989 WWindow
*wwin
= data
;
2991 event
->xbutton
.state
&= ValidModMask
;
2993 CloseWindowMenu(wwin
->screen_ptr
);
2995 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2998 /* if control-click, kill the client */
2999 if (event
->xbutton
.state
& ControlMask
) {
3002 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
3003 /* send delete message */
3004 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3009 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3011 WWindow
*wwin
= data
;
3013 CloseWindowMenu(wwin
->screen_ptr
);
3015 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3018 /* send delete message */
3019 if (wwin
->protocols
.DELETE_WINDOW
) {
3020 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3026 #ifdef XKB_BUTTON_HINT
3027 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3029 WWindow
*wwin
= data
;
3030 WFrameWindow
*fwin
= wwin
->frame
;
3031 WScreen
*scr
= fwin
->screen_ptr
;
3032 XkbStateRec staterec
;
3035 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3037 tl
= wwin
->frame
->languagemode
;
3038 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3039 wwin
->frame
->last_languagemode
= tl
;
3040 wSetFocusTo(scr
, wwin
);
3041 wwin
->frame
->languagebutton_image
=
3042 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3043 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3044 if (event
->xbutton
.button
== Button3
)
3046 wRaiseFrame(fwin
->core
);
3050 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3052 WWindow
*wwin
= data
;
3054 event
->xbutton
.state
&= ValidModMask
;
3056 CloseWindowMenu(wwin
->screen_ptr
);
3058 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3061 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3062 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3065 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3067 wapp
= wApplicationOf(wwin
->main_window
);
3068 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3069 wHideApplication(wapp
);
3070 } else if (event
->xbutton
.state
== 0) {
3071 wIconifyWindow(wwin
);