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 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
309 WScreen
*scr
= wwin
->screen_ptr
;
311 /* sets global default stuff */
312 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
314 * Decoration setting is done in this precedence (lower to higher)
315 * - use global default in the resource database
316 * - guess some settings
317 * - use GNUstep/external window attributes
318 * - set hints specified for the app in the resource DB
321 WSETUFLAG(wwin
, broken_close
, 0);
323 if (wwin
->protocols
.DELETE_WINDOW
)
324 WSETUFLAG(wwin
, kill_close
, 0);
326 WSETUFLAG(wwin
, kill_close
, 1);
328 /* transients can't be iconified or maximized */
329 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
330 WSETUFLAG(wwin
, no_miniaturizable
, 1);
331 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
334 /* if the window can't be resized, remove the resizebar */
335 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
336 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
337 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
338 WSETUFLAG(wwin
, no_resizable
, 1);
339 WSETUFLAG(wwin
, no_resizebar
, 1);
342 /* set GNUstep window attributes */
343 if (wwin
->wm_gnustep_attr
) {
344 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
346 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
348 *level
= wwin
->wm_gnustep_attr
->window_level
;
350 * INT_MIN is the only illegal window level.
352 if (*level
== INT_MIN
)
353 *level
= INT_MIN
+ 1;
356 *level
= WMNormalLevel
;
359 int tmp_workspace
= -1;
360 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
366 wMWMCheckClientHints(wwin
);
367 #endif /* MWM_HINTS */
370 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
372 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
373 * have INT_MIN that means that no window level was requested. -Dan
375 if (tmp_level
== INT_MIN
) {
376 if (WFLAGP(wwin
, floating
))
377 *level
= WMFloatingLevel
;
378 else if (WFLAGP(wwin
, sunken
))
379 *level
= WMSunkenLevel
;
381 *level
= WMNormalLevel
;
386 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
387 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
388 if (transientOwner
) {
389 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
390 if (ownerLevel
> *level
)
395 if (tmp_workspace
>= 0)
396 *workspace
= tmp_workspace
% scr
->workspace_count
;
400 * Set attributes specified only for that window/class.
401 * This might do duplicate work with the 1st wDefaultFillAttributes().
403 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
404 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
406 * Sanity checks for attributes that depend on other attributes
408 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
409 wwin
->user_flags
.emulate_appicon
= 0;
411 if (wwin
->main_window
!= None
) {
412 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
413 if (wapp
&& !wapp
->flags
.emulated
)
414 wwin
->user_flags
.emulate_appicon
= 0;
417 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
418 wwin
->user_flags
.emulate_appicon
= 0;
420 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
421 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
422 wwin
->user_flags
.sunken
= 0;
424 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
426 /* windows that have takefocus=False shouldn't take focus at all */
427 if (wwin
->focus_mode
== WFM_NO_INPUT
)
428 wwin
->client_flags
.no_focusable
= 1;
431 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
433 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
435 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
437 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
443 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
447 w1
= wwin
->frame
->core
->width
;
448 h1
= wwin
->frame
->core
->height
;
449 w2
= obscured
->frame
->core
->width
;
450 h2
= obscured
->frame
->core
->height
;
452 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
453 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
456 if (wwin
->frame_x
+ w1
< obscured
->frame_x
457 || wwin
->frame_y
+ h1
< obscured
->frame_y
458 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
464 static void fixLeaderProperties(WWindow
*wwin
)
466 XClassHint
*classHint
;
467 XWMHints
*hints
, *clientHints
;
468 Window leaders
[2], window
;
469 char **argv
, *command
;
473 classHint
= XAllocClassHint();
474 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
475 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
477 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
481 leaders
[0] = wwin
->client_leader
;
482 leaders
[1] = wwin
->group_id
;
485 command
= GetCommandForWindow(wwin
->client_win
);
487 /* command already set. nothing to do. */
490 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
494 for (i
= 0; i
< 2; i
++) {
497 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
498 classHint
->res_name
= wwin
->wm_instance
;
499 classHint
->res_class
= wwin
->wm_class
;
500 XSetClassHint(dpy
, window
, classHint
);
502 hints
= XGetWMHints(dpy
, window
);
505 } else if (clientHints
) {
506 /* set window group leader to self */
507 clientHints
->window_group
= window
;
508 clientHints
->flags
|= WindowGroupHint
;
509 XSetWMHints(dpy
, window
, clientHints
);
513 command
= GetCommandForWindow(window
);
515 /* command already set. nothing to do. */
518 XSetCommand(dpy
, window
, argv
, argc
);
531 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
533 XClassHint
*classHint
;
539 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
541 classHint
= XAllocClassHint();
542 classHint
->res_name
= instance
;
543 classHint
->res_class
= class;
544 XSetClassHint(dpy
, leader
, classHint
);
547 /* inherit these from the original leader if available */
548 hints
= XGetWMHints(dpy
, win
);
550 hints
= XAllocWMHints();
553 /* set window group leader to self */
554 hints
->window_group
= leader
;
555 hints
->flags
|= WindowGroupHint
;
556 XSetWMHints(dpy
, leader
, hints
);
559 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
560 XSetCommand(dpy
, leader
, argv
, argc
);
561 XFreeStringList(argv
);
567 static int matchIdentifier(void *item
, void *cdata
)
569 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
573 *----------------------------------------------------------------
575 * reparents the window and allocates a descriptor for it.
576 * Window manager hints and other hints are fetched to configure
577 * the window decoration attributes and others. User preferences
578 * for the window are used if available, to configure window
579 * decorations and some behaviour.
580 * If in startup, windows that are override redirect,
581 * unmapped and never were managed and are Withdrawn are not
585 * the new window descriptor
588 * The window is reparented and appropriate notification
589 * is done to the client. Input mask for the window is setup.
590 * The window descriptor is also associated with various window
591 * contexts and inserted in the head of the window list.
592 * Event handler contexts are associated for some objects
593 * (buttons, titlebar and resizebar)
595 *----------------------------------------------------------------
597 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
601 unsigned width
, height
;
602 XWindowAttributes wattribs
;
603 XSetWindowAttributes attribs
;
604 WWindowState
*win_state
;
605 WWindow
*transientOwner
= NULL
;
611 Bool withdraw
= False
;
615 /* XGrabServer(dpy); */
617 /* make sure the window is still there */
618 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
623 /* if it's an override-redirect, ignore it */
624 if (wattribs
.override_redirect
) {
629 wm_state
= PropGetWindowState(window
);
631 /* if it's startup and the window is unmapped, don't manage it */
632 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
637 wwin
= wWindowCreate();
639 title
= wNETWMGetWindowName(window
);
641 wwin
->flags
.net_has_title
= 1;
642 if (!title
&& !wFetchName(dpy
, window
, &title
))
645 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
648 printf("managing window %x\n", (unsigned)window
);
652 if (wShapeSupported
) {
657 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
658 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
659 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
660 wwin
->flags
.shaped
= b_shaped
;
665 * Get hints and other information in properties
667 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
669 /* setup descriptor */
670 wwin
->client_win
= window
;
671 wwin
->screen_ptr
= scr
;
672 wwin
->old_border_width
= wattribs
.border_width
;
673 wwin
->event_mask
= CLIENT_EVENTS
;
674 attribs
.event_mask
= CLIENT_EVENTS
;
675 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
676 attribs
.save_under
= False
;
678 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
679 XSetWindowBorderWidth(dpy
, window
, 0);
681 /* get hints from GNUstep app */
682 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
683 wwin
->flags
.is_gnustep
= 1;
685 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
686 wwin
->wm_gnustep_attr
= NULL
;
689 wwin
->client_leader
= PropGetClientLeader(window
);
690 if (wwin
->client_leader
!= None
)
691 wwin
->main_window
= wwin
->client_leader
;
693 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
695 if (wwin
->wm_hints
) {
696 if (wwin
->wm_hints
->flags
& StateHint
) {
698 if (wwin
->wm_hints
->initial_state
== IconicState
) {
700 wwin
->flags
.miniaturized
= 1;
702 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
708 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
709 wwin
->group_id
= wwin
->wm_hints
->window_group
;
710 /* window_group has priority over CLIENT_LEADER */
711 wwin
->main_window
= wwin
->group_id
;
713 wwin
->group_id
= None
;
716 if (wwin
->wm_hints
->flags
& UrgencyHint
)
717 wwin
->flags
.urgent
= 1;
719 wwin
->group_id
= None
;
722 PropGetProtocols(window
, &wwin
->protocols
);
724 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
725 wwin
->transient_for
= None
;
727 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
728 wwin
->transient_for
= scr
->root_win
;
730 transientOwner
= wWindowFor(wwin
->transient_for
);
731 if (transientOwner
&& transientOwner
->main_window
!= None
)
732 wwin
->main_window
= transientOwner
->main_window
;
736 /* guess the focus mode */
737 wwin
->focus_mode
= getFocusMode(wwin
);
739 /* get geometry stuff */
740 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
742 /* get colormap windows */
743 GetColormapWindows(wwin
);
746 * Setup the decoration/window attributes and
749 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
751 /* Make broken apps behave as a nice app. */
752 if (WFLAGP(wwin
, emulate_appicon
))
753 wwin
->main_window
= wwin
->client_win
;
755 fixLeaderProperties(wwin
);
757 wwin
->orig_main_window
= wwin
->main_window
;
759 if (wwin
->flags
.is_gnustep
)
760 WSETUFLAG(wwin
, shared_appicon
, 0);
762 if (wwin
->main_window
) {
763 extern Atom _XA_WINDOWMAKER_MENU
;
764 XTextProperty text_prop
;
766 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
767 WSETUFLAG(wwin
, shared_appicon
, 0);
771 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
772 char *buffer
, *instance
, *class;
773 WFakeGroupLeader
*fPtr
;
776 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
778 /* // only enter here if PropGetWMClass() succeds */
779 PropGetWMClass(wwin
->main_window
, &class, &instance
);
780 buffer
= StrConcatDot(instance
, class);
782 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
783 if (index
!= WANotFound
) {
784 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
785 if (fPtr
->retainCount
== 0) {
786 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
791 if (fPtr
->origLeader
== None
) {
793 if (ADEQUATE(wwin
->group_id
)) {
795 fPtr
->origLeader
= wwin
->group_id
;
796 } else if (ADEQUATE(wwin
->client_leader
)) {
798 fPtr
->origLeader
= wwin
->client_leader
;
799 } else if (ADEQUATE(wwin
->main_window
)) {
801 fPtr
->origLeader
= wwin
->main_window
;
804 if (ADEQUATE(wwin
->main_window
)) {
806 fPtr
->origLeader
= wwin
->main_window
;
810 wwin
->fake_group
= fPtr
;
811 /*wwin->group_id = fPtr->leader; */
812 wwin
->main_window
= fPtr
->leader
;
815 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
817 fPtr
->identifier
= buffer
;
818 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
819 fPtr
->origLeader
= None
;
820 fPtr
->retainCount
= 1;
822 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
825 if (ADEQUATE(wwin
->group_id
)) {
827 fPtr
->origLeader
= wwin
->group_id
;
828 } else if (ADEQUATE(wwin
->client_leader
)) {
830 fPtr
->origLeader
= wwin
->client_leader
;
831 } else if (ADEQUATE(wwin
->main_window
)) {
833 fPtr
->origLeader
= wwin
->main_window
;
836 if (ADEQUATE(wwin
->main_window
)) {
838 fPtr
->origLeader
= wwin
->main_window
;
841 wwin
->fake_group
= fPtr
;
842 /*wwin->group_id = fPtr->leader; */
843 wwin
->main_window
= fPtr
->leader
;
855 * Setup the initial state of the window
857 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
858 wwin
->flags
.miniaturized
= 1;
860 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
861 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
863 wNETWMCheckInitialClientState(wwin
);
865 /* apply previous state if it exists and we're in startup */
866 if (scr
->flags
.startup
&& wm_state
>= 0) {
868 if (wm_state
== IconicState
) {
870 wwin
->flags
.miniaturized
= 1;
872 } else if (wm_state
== WithdrawnState
) {
878 /* if there is a saved state (from file), restore it */
880 if (wwin
->main_window
!= None
)
881 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
883 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
885 if (win_state
&& !withdraw
) {
886 if (win_state
->state
->hidden
> 0)
887 wwin
->flags
.hidden
= win_state
->state
->hidden
;
889 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
890 wwin
->flags
.shaded
= win_state
->state
->shaded
;
892 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
893 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
896 if (!IS_OMNIPRESENT(wwin
)) {
897 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
899 if (w
< 0 || w
>= scr
->workspace_count
) {
900 workspace
= win_state
->state
->workspace
;
901 if (workspace
>= scr
->workspace_count
)
902 workspace
= scr
->current_workspace
;
907 workspace
= scr
->current_workspace
;
911 /* if we're restarting, restore saved state (from hints).
912 * This will overwrite previous */
916 if (getSavedState(window
, &wstate
)) {
917 wwin
->flags
.shaded
= wstate
->shaded
;
918 wwin
->flags
.hidden
= wstate
->hidden
;
919 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
920 wwin
->flags
.maximized
= wstate
->maximized
;
921 if (wwin
->flags
.maximized
) {
922 wwin
->old_geometry
.x
= wstate
->x
;
923 wwin
->old_geometry
.y
= wstate
->y
;
924 wwin
->old_geometry
.width
= wstate
->w
;
925 wwin
->old_geometry
.height
= wstate
->h
;
928 workspace
= wstate
->workspace
;
933 /* restore window shortcut */
934 if (wstate
!= NULL
|| win_state
!= NULL
) {
937 if (win_state
!= NULL
)
938 mask
= win_state
->state
->window_shortcuts
;
940 if (wstate
!= NULL
&& mask
== 0)
941 mask
= wstate
->window_shortcuts
;
946 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
947 if (mask
& (1 << i
)) {
948 if (!scr
->shortcutWindows
[i
])
949 scr
->shortcutWindows
[i
] = WMCreateArray(4);
951 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
960 /* don't let transients start miniaturized if their owners are not */
961 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
962 wwin
->flags
.miniaturized
= 0;
964 wwin
->wm_hints
->initial_state
= NormalState
;
967 /* set workspace on which the window starts */
968 if (workspace
>= 0) {
969 if (workspace
> scr
->workspace_count
- 1) {
970 workspace
= workspace
% scr
->workspace_count
;
975 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
977 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
982 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
984 workspace
= transientOwner
->frame
->workspace
;
988 workspace
= scr
->current_workspace
;
993 /* setup window geometry */
994 if (win_state
&& win_state
->state
->w
> 0) {
995 width
= win_state
->state
->w
;
996 height
= win_state
->state
->h
;
998 wWindowConstrainSize(wwin
, &width
, &height
);
1000 /* do not ask for window placement if the window is
1001 * transient, during startup, if the initial workspace is another one
1002 * or if the window wants to start iconic.
1003 * If geometry was saved, restore it. */
1005 Bool dontBring
= False
;
1007 if (win_state
&& win_state
->state
->w
> 0) {
1008 x
= win_state
->state
->x
;
1009 y
= win_state
->state
->y
;
1010 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
1011 && !scr
->flags
.startup
1012 && workspace
== scr
->current_workspace
1013 && !wwin
->flags
.miniaturized
1014 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
1016 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1017 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
1021 x
= transientOwner
->frame_x
+
1022 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
1023 y
= transientOwner
->frame_y
+
1024 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
1027 * limit transient windows to be inside their parent's head
1029 rect
.pos
.x
= transientOwner
->frame_x
;
1030 rect
.pos
.y
= transientOwner
->frame_y
;
1031 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1032 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1034 head
= wGetHeadForRect(scr
, rect
);
1035 rect
= wGetRectForHead(scr
, head
);
1039 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1040 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1044 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1045 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1048 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1050 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1053 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1059 * Make spash screens come out in the center of a head
1060 * trouble is that most splashies never get here
1061 * they are managed trough atoms but god knows where.
1062 * Dan, do you know ? -peter
1064 * Most of them are not managed, they have set
1065 * OverrideRedirect, which means we can't do anything about
1069 printf("xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
) / 2);
1070 printf("xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
) / 2);
1072 if ((unsigned)(x
+ (width
- scr
->scr_width
) / 2 + 10) < 20 &&
1073 (unsigned)(y
+ (height
- scr
->scr_height
) / 2 + 10) < 20) {
1081 * xinerama checks for: across head and dead space
1085 rect
.size
.width
= width
;
1086 rect
.size
.height
= height
;
1088 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1090 if (flags
& XFLAG_DEAD
)
1093 if (flags
& XFLAG_MULTIPLE
)
1097 switch (reposition
) {
1099 head
= wGetHeadForPointerLocation(scr
);
1100 rect
= wGetRectForHead(scr
, head
);
1102 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1103 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1107 rect
= wGetRectForHead(scr
, head
);
1111 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1112 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1116 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1117 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1126 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1127 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1130 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1132 if (wwin
->flags
.urgent
) {
1133 if (!IS_OMNIPRESENT(wwin
))
1134 wwin
->flags
.omnipresent
^= 1;
1138 * Create frame, borders and do reparenting
1140 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1141 #ifdef XKB_BUTTON_HINT
1142 if (wPreferences
.modelock
)
1143 foo
|= WFF_LANGUAGE_BUTTON
;
1145 if (HAS_TITLEBAR(wwin
))
1146 foo
|= WFF_TITLEBAR
;
1147 if (HAS_RESIZEBAR(wwin
))
1148 foo
|= WFF_RESIZEBAR
;
1149 if (HAS_BORDER(wwin
))
1152 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1153 x
, y
, width
, height
,
1154 &wPreferences
.window_title_clearance
, foo
,
1155 scr
->window_title_texture
,
1156 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1158 wwin
->frame
->flags
.is_client_window_frame
= 1;
1159 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1161 /* setup button images */
1162 wWindowUpdateButtonImages(wwin
);
1164 /* hide unused buttons */
1166 if (WFLAGP(wwin
, no_close_button
))
1167 foo
|= WFF_RIGHT_BUTTON
;
1168 if (WFLAGP(wwin
, no_miniaturize_button
))
1169 foo
|= WFF_LEFT_BUTTON
;
1170 #ifdef XKB_BUTTON_HINT
1171 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1172 foo
|= WFF_LANGUAGE_BUTTON
;
1175 wFrameWindowHideButton(wwin
->frame
, foo
);
1177 wwin
->frame
->child
= wwin
;
1178 wwin
->frame
->workspace
= workspace
;
1179 wwin
->frame
->on_click_left
= windowIconifyClick
;
1181 #ifdef XKB_BUTTON_HINT
1182 if (wPreferences
.modelock
)
1183 wwin
->frame
->on_click_language
= windowLanguageClick
;
1186 wwin
->frame
->on_click_right
= windowCloseClick
;
1187 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1188 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1189 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1190 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1192 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1193 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1194 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1199 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1201 /* if gravity is to the south, account for the border sizes */
1203 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1207 * wWindowConfigure() will init the client window's size
1208 * (wwin->client.{width,height}) and all other geometry
1209 * related variables (frame_x,frame_y)
1211 wWindowConfigure(wwin
, x
, y
, width
, height
);
1213 /* to make sure the window receives it's new position after reparenting */
1214 wWindowSynthConfigureNotify(wwin
);
1217 * Setup descriptors and save window to internal
1220 if (wwin
->main_window
!= None
) {
1224 /* Leader windows do not necessary set themselves as leaders.
1225 * If this is the case, point the leader of this window to
1227 leader
= wWindowFor(wwin
->main_window
);
1228 if (leader
&& leader
->main_window
== None
) {
1229 leader
->main_window
= leader
->client_win
;
1231 app
= wApplicationCreate(wwin
);
1233 app
->last_workspace
= workspace
;
1236 * Do application specific stuff, like setting application
1240 if (wwin
->flags
.hidden
) {
1241 /* if the window was set to hidden because it was hidden
1242 * in a previous incarnation and that state was restored */
1243 app
->flags
.hidden
= 1;
1244 } else if (app
->flags
.hidden
) {
1245 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1246 wwin
->flags
.hidden
= 1;
1248 wUnhideApplication(app
, False
, False
);
1255 /* setup the frame descriptor */
1256 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1257 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1258 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1260 /* don't let windows go away if we die */
1261 XAddToSaveSet(dpy
, window
);
1263 XLowerWindow(dpy
, window
);
1265 /* if window is in this workspace and should be mapped, then map it */
1266 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1267 && !wwin
->flags
.hidden
&& !withdraw
) {
1269 /* The following "if" is to avoid crashing of clients that expect
1270 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1271 * after the return from this function.
1273 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1274 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1276 wClientSetState(wwin
, NormalState
, None
);
1280 /* if not auto focus, then map the window under the currently
1282 #define _WIDTH(w) (w)->frame->core->width
1283 #define _HEIGHT(w) (w)->frame->core->height
1284 if (!wPreferences
.auto_focus
&& scr
->focused_window
1285 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1287 (_WIDTH(scr
->focused_window
) * 5) / 3
1289 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1290 && WINDOW_LEVEL(scr
->focused_window
) ==
1292 || wwin
->flags
.maximized
)) {
1293 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1300 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1301 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1303 * The brain damaged idiotic non-click to focus modes will
1304 * have trouble with this because:
1306 * 1. window is created and mapped by the client
1307 * 2. window is mapped by wmaker in small size
1308 * 3. window is animated to grow to normal size
1309 * 4. this function returns to normal event loop
1310 * 5. eventually, the EnterNotify event that would trigger
1311 * the window focusing (if the mouse is over that window)
1312 * will be processed by wmaker.
1313 * But since this event will be rather delayed
1314 * (step 3 has a large delay) the time when the event ocurred
1315 * and when it is processed, the client that owns that window
1316 * will reject the XSetInputFocus() for it.
1318 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1319 DoWindowBirth(wwin
);
1325 /* setup stacking descriptor */
1326 if (transientOwner
) {
1327 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1329 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1332 if (!scr
->focused_window
) {
1333 /* first window on the list */
1336 scr
->focused_window
= wwin
;
1340 /* add window at beginning of focus window list */
1341 tmp
= scr
->focused_window
;
1349 /* raise is set to true if we un-hid the app when this window was born.
1350 * we raise, else old windows of this app will be above this new one. */
1352 wRaiseFrame(wwin
->frame
->core
);
1355 /* Update name must come after WApplication stuff is done */
1356 wWindowUpdateName(wwin
, title
);
1363 * Final preparations before window is ready to go
1365 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1367 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1368 if (((transientOwner
&& transientOwner
->flags
.focused
)
1369 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1370 wSetFocusTo(scr
, wwin
);
1372 wWindowResetMouseGrabs(wwin
);
1374 if (!WFLAGP(wwin
, no_bind_keys
))
1375 wWindowSetKeyGrabs(wwin
);
1377 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1378 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1380 /* Setup Notification Observers */
1381 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1383 /* Cleanup temporary stuff */
1385 wWindowDeleteSavedState(win_state
);
1387 /* If the window must be withdrawed, then do it now.
1388 * Must do some optimization, 'though */
1390 wwin
->flags
.mapped
= 0;
1391 wClientSetState(wwin
, WithdrawnState
, None
);
1392 wUnmanageWindow(wwin
, True
, False
);
1399 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1400 char *title
, int x
, int y
, int width
, int height
)
1405 wwin
= wWindowCreate();
1407 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1409 wwin
->flags
.internal_window
= 1;
1411 WSETUFLAG(wwin
, omnipresent
, 1);
1412 WSETUFLAG(wwin
, no_shadeable
, 1);
1413 WSETUFLAG(wwin
, no_resizable
, 1);
1414 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1416 wwin
->focus_mode
= WFM_PASSIVE
;
1417 wwin
->client_win
= window
;
1418 wwin
->screen_ptr
= scr
;
1419 wwin
->transient_for
= owner
;
1422 wwin
->client
.width
= width
;
1423 wwin
->client
.height
= height
;
1424 wwin
->frame_x
= wwin
->client
.x
;
1425 wwin
->frame_y
= wwin
->client
.y
;
1427 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1428 foo
|= WFF_TITLEBAR
;
1429 #ifdef XKB_BUTTON_HINT
1430 foo
|= WFF_LANGUAGE_BUTTON
;
1433 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1434 wwin
->frame_x
, wwin
->frame_y
,
1436 &wPreferences
.window_title_clearance
, foo
,
1437 scr
->window_title_texture
,
1438 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1440 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1442 wwin
->frame
->flags
.is_client_window_frame
= 1;
1443 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1445 wFrameWindowChangeTitle(wwin
->frame
, title
);
1447 /* setup button images */
1448 wWindowUpdateButtonImages(wwin
);
1451 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1453 wwin
->frame
->child
= wwin
;
1454 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1456 #ifdef XKB_BUTTON_HINT
1457 if (wPreferences
.modelock
)
1458 wwin
->frame
->on_click_language
= windowLanguageClick
;
1461 wwin
->frame
->on_click_right
= windowCloseClick
;
1462 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1463 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1464 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1465 wwin
->client
.y
+= wwin
->frame
->top_width
;
1467 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1468 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1470 /* setup the frame descriptor */
1471 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1472 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1473 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1475 XLowerWindow(dpy
, window
);
1476 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1478 /* setup stacking descriptor */
1479 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1481 tmp
= wWindowFor(wwin
->transient_for
);
1483 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1485 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1488 if (!scr
->focused_window
) {
1489 /* first window on the list */
1492 scr
->focused_window
= wwin
;
1496 /* add window at beginning of focus window list */
1497 tmp
= scr
->focused_window
;
1505 if (wwin
->flags
.is_gnustep
== 0)
1506 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1508 /* if (wPreferences.auto_focus) */
1509 wSetFocusTo(scr
, wwin
);
1510 wWindowResetMouseGrabs(wwin
);
1511 wWindowSetKeyGrabs(wwin
);
1517 *----------------------------------------------------------------------
1519 * Removes the frame window from a window and destroys all data
1520 * related to it. The window will be reparented back to the root window
1521 * if restore is True.
1524 * Everything related to the window is destroyed and the window
1525 * is removed from the window lists. Focus is set to the previous on the
1527 *----------------------------------------------------------------------
1529 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1531 WCoreWindow
*frame
= wwin
->frame
->core
;
1532 WWindow
*owner
= NULL
;
1533 WWindow
*newFocusedWindow
= NULL
;
1535 WScreen
*scr
= wwin
->screen_ptr
;
1537 /* First close attribute editor window if open */
1538 if (wwin
->flags
.inspector_open
) {
1539 wCloseInspectorForWindow(wwin
);
1542 /* Close window menu if it's open for this window */
1543 if (wwin
->flags
.menu_open_for_me
) {
1544 CloseWindowMenu(scr
);
1548 if (!wwin
->flags
.internal_window
)
1549 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1551 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1553 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1554 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1557 XUnmapWindow(dpy
, frame
->window
);
1559 XUnmapWindow(dpy
, wwin
->client_win
);
1561 /* deselect window */
1562 wSelectWindow(wwin
, False
);
1564 /* remove all pending events on window */
1565 /* I think this only matters for autoraise */
1566 if (wPreferences
.raise_delay
)
1567 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1571 /* reparent the window back to the root */
1573 wClientRestore(wwin
);
1575 if (wwin
->transient_for
!= scr
->root_win
) {
1576 owner
= wWindowFor(wwin
->transient_for
);
1578 if (!owner
->flags
.semi_focused
) {
1581 owner
->flags
.semi_focused
= 0;
1586 wasFocused
= wwin
->flags
.focused
;
1588 /* remove from window focus list */
1589 if (!wwin
->prev
&& !wwin
->next
) {
1590 /* was the only window */
1591 scr
->focused_window
= NULL
;
1592 newFocusedWindow
= NULL
;
1597 wwin
->prev
->next
= wwin
->next
;
1599 wwin
->next
->prev
= wwin
->prev
;
1601 scr
->focused_window
= wwin
->prev
;
1602 scr
->focused_window
->next
= NULL
;
1605 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1607 /* if in click to focus mode and the window
1608 * was a transient, focus the owner window
1611 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1612 tmp
= wWindowFor(wwin
->transient_for
);
1613 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1617 /* otherwise, focus the next one in the focus list */
1619 tmp
= scr
->focused_window
;
1620 while (tmp
) { /* look for one in the window list first */
1621 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1622 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1626 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1627 tmp
= scr
->focused_window
;
1629 if (!WFLAGP(tmp
, no_focusable
)
1630 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1637 newFocusedWindow
= tmp
;
1639 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1644 /* This is to let the root window get the keyboard input
1645 * if Sloppy focus mode and no other window get focus.
1646 * This way keybindings will not freeze.
1649 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1650 tmp
= wWindowFor(win
);
1653 newFocusedWindow
= tmp
;
1655 newFocusedWindow
= NULL
;
1659 if (!wwin
->flags
.internal_window
)
1660 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1662 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
, (unsigned)frame
->window
);
1666 if (newFocusedWindow
!= owner
&& owner
) {
1667 if (wwin
->flags
.is_gnustep
== 0)
1668 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1670 wSetFocusTo(scr
, newFocusedWindow
);
1672 wWindowDestroy(wwin
);
1676 void wWindowMap(WWindow
*wwin
)
1678 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1679 if (!wwin
->flags
.shaded
) {
1680 /* window will be remapped when getting MapNotify */
1681 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1682 XMapWindow(dpy
, wwin
->client_win
);
1683 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1685 wwin
->flags
.mapped
= 1;
1689 void wWindowUnmap(WWindow
*wwin
)
1691 wwin
->flags
.mapped
= 0;
1693 /* prevent window withdrawal when getting UnmapNotify */
1694 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1695 XUnmapWindow(dpy
, wwin
->client_win
);
1696 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1698 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1701 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1706 #ifdef KEEP_XKB_LOCK_STATUS
1707 if (wPreferences
.modelock
) {
1708 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1710 #endif /* KEEP_XKB_LOCK_STATUS */
1712 wwin
->flags
.semi_focused
= 0;
1714 if (wwin
->flags
.is_gnustep
== 0)
1715 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1717 wwin
->flags
.focused
= 1;
1719 wWindowResetMouseGrabs(wwin
);
1721 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1723 if (owin
== wwin
|| !owin
)
1726 nowner
= wWindowFor(wwin
->transient_for
);
1728 /* new window is a transient for the old window */
1729 if (nowner
== owin
) {
1730 owin
->flags
.semi_focused
= 1;
1731 wWindowUnfocus(nowner
);
1735 oowner
= wWindowFor(owin
->transient_for
);
1737 /* new window is owner of old window */
1738 if (wwin
== oowner
) {
1739 wWindowUnfocus(owin
);
1744 wWindowUnfocus(owin
);
1748 /* new window has same owner of old window */
1749 if (oowner
== nowner
) {
1750 /* prevent unfocusing of owner */
1751 oowner
->flags
.semi_focused
= 0;
1752 wWindowUnfocus(owin
);
1753 oowner
->flags
.semi_focused
= 1;
1758 /* nowner != NULL && oowner != nowner */
1759 nowner
->flags
.semi_focused
= 1;
1760 wWindowUnfocus(nowner
);
1761 wWindowUnfocus(owin
);
1764 void wWindowUnfocus(WWindow
*wwin
)
1766 CloseWindowMenu(wwin
->screen_ptr
);
1768 if (wwin
->flags
.is_gnustep
== 0)
1769 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1771 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1773 owner
= wWindowFor(wwin
->transient_for
);
1774 if (owner
&& owner
->flags
.semi_focused
) {
1775 owner
->flags
.semi_focused
= 0;
1776 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1777 wWindowUnfocus(owner
);
1778 wFrameWindowPaint(owner
->frame
);
1782 wwin
->flags
.focused
= 0;
1783 wWindowResetMouseGrabs(wwin
);
1784 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1787 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1794 wwin
->flags
.wm_name_changed
= 1;
1797 /* the hint was removed */
1798 title
= DEF_WINDOW_TITLE
;
1803 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1804 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1809 *----------------------------------------------------------------------
1811 * wWindowConstrainSize--
1812 * Constrains size for the client window, taking the maximal size,
1813 * window resize increments and other size hints into account.
1816 * The closest size to what was given that the client window can
1819 *----------------------------------------------------------------------
1821 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1823 int width
= (int)*nwidth
;
1824 int height
= (int)*nheight
;
1827 int minW
= 1, minH
= 1;
1828 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1829 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1830 int minAX
= -1, minAY
= -1;
1831 int maxAX
= -1, maxAY
= -1;
1835 if (wwin
->normal_hints
) {
1836 winc
= wwin
->normal_hints
->width_inc
;
1837 hinc
= wwin
->normal_hints
->height_inc
;
1838 minW
= wwin
->normal_hints
->min_width
;
1839 minH
= wwin
->normal_hints
->min_height
;
1840 maxW
= wwin
->normal_hints
->max_width
;
1841 maxH
= wwin
->normal_hints
->max_height
;
1842 if (wwin
->normal_hints
->flags
& PAspect
) {
1843 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1844 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1845 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1846 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1849 baseW
= wwin
->normal_hints
->base_width
;
1850 baseH
= wwin
->normal_hints
->base_height
;
1863 /* aspect ratio code borrowed from olwm */
1865 /* adjust max aspect ratio */
1866 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1867 if (maxAX
> maxAY
) {
1868 height
= (width
* maxAY
) / maxAX
;
1869 if (height
> maxH
) {
1871 width
= (height
* maxAX
) / maxAY
;
1874 width
= (height
* maxAX
) / maxAY
;
1877 height
= (width
* maxAY
) / maxAX
;
1882 /* adjust min aspect ratio */
1883 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1884 if (minAX
> minAY
) {
1885 height
= (width
* minAY
) / minAX
;
1886 if (height
< minH
) {
1888 width
= (height
* minAX
) / minAY
;
1891 width
= (height
* minAX
) / minAY
;
1894 height
= (width
* minAY
) / minAX
;
1901 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1903 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1906 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1908 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1910 /* broken stupid apps may cause preposterous values for these.. */
1917 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1918 unsigned int *width
, unsigned int *height
)
1920 int baseW
= 0, baseH
= 0;
1921 int winc
= 1, hinc
= 1;
1923 if (wwin
->normal_hints
) {
1924 baseW
= wwin
->normal_hints
->base_width
;
1925 baseH
= wwin
->normal_hints
->base_height
;
1927 winc
= wwin
->normal_hints
->width_inc
;
1928 hinc
= wwin
->normal_hints
->height_inc
;
1932 *width
= maxW
- (maxW
- baseW
) % winc
;
1935 *height
= maxH
- (maxH
- baseH
) % hinc
;
1938 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1940 WScreen
*scr
= wwin
->screen_ptr
;
1944 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1947 if (workspace
!= scr
->current_workspace
) {
1948 /* Sent to other workspace. Unmap window */
1949 if ((wwin
->flags
.mapped
1950 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1951 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1953 wapp
= wApplicationOf(wwin
->main_window
);
1955 wapp
->last_workspace
= workspace
;
1957 if (wwin
->flags
.miniaturized
) {
1959 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1960 wwin
->icon
->mapped
= 0;
1964 wSetFocusTo(scr
, NULL
);
1968 /* brought to current workspace. Map window */
1969 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1971 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1972 wwin
->icon
->mapped
= 1;
1974 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1978 if (!IS_OMNIPRESENT(wwin
)) {
1979 int oldWorkspace
= wwin
->frame
->workspace
;
1981 wwin
->frame
->workspace
= workspace
;
1983 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1990 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1994 sevent
.type
= ConfigureNotify
;
1995 sevent
.xconfigure
.display
= dpy
;
1996 sevent
.xconfigure
.event
= wwin
->client_win
;
1997 sevent
.xconfigure
.window
= wwin
->client_win
;
1999 sevent
.xconfigure
.x
= wwin
->client
.x
;
2000 sevent
.xconfigure
.y
= wwin
->client
.y
;
2001 sevent
.xconfigure
.width
= wwin
->client
.width
;
2002 sevent
.xconfigure
.height
= wwin
->client
.height
;
2004 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2005 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2006 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2008 sevent
.xconfigure
.above
= None
;
2010 sevent
.xconfigure
.override_redirect
= False
;
2011 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2016 *----------------------------------------------------------------------
2017 * wWindowConfigure()
2019 * req_x, req_y: new requested positions for the frame
2020 * req_width, req_height: new requested sizes for the client
2022 * Configures the frame, decorations and client window to the specified
2023 * geometry, whose validity is not checked -- wWindowConstrainSize()
2024 * must be used for that.
2025 * The size parameters are for the client window, but the position is
2027 * The client window receives a ConfigureNotify event, according
2028 * to what ICCCM says.
2034 * Window size and position are changed and client window receives
2035 * a ConfigureNotify event.
2036 *----------------------------------------------------------------------
2038 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2040 int synth_notify
= False
;
2043 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2045 * if the window is being moved but not resized then
2046 * send a synthetic ConfigureNotify
2048 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2049 synth_notify
= True
;
2052 if (WFLAGP(wwin
, dont_move_off
))
2053 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2055 if (req_width
< MIN_WINDOW_SIZE
)
2056 req_width
= MIN_WINDOW_SIZE
;
2057 if (req_height
< MIN_WINDOW_SIZE
)
2058 req_height
= MIN_WINDOW_SIZE
;
2060 /* If growing, resize inner part before frame,
2061 * if shrinking, resize frame before.
2062 * This will prevent the frame (that can have a different color)
2063 * to be exposed, causing flicker */
2064 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2065 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2067 if (wwin
->flags
.shaded
) {
2068 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2069 wwin
->old_geometry
.height
= req_height
;
2073 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2075 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2078 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2079 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2081 wwin
->client
.x
= req_x
;
2082 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2083 wwin
->client
.width
= req_width
;
2084 wwin
->client
.height
= req_height
;
2086 wwin
->client
.x
= req_x
;
2087 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2089 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2091 wwin
->frame_x
= req_x
;
2092 wwin
->frame_y
= req_y
;
2093 if (HAS_BORDER(wwin
)) {
2094 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2095 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2098 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2099 wWindowSetShape(wwin
);
2104 wWindowSynthConfigureNotify(wwin
);
2108 /* req_x, req_y: new position of the frame */
2109 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2111 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2112 int synth_notify
= False
;
2114 /* Send a synthetic ConfigureNotify event for every window movement. */
2115 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2116 synth_notify
= True
;
2119 /* A single synthetic ConfigureNotify event is sent at the end of
2120 * a completed (opaque) movement in moveres.c */
2123 if (WFLAGP(wwin
, dont_move_off
))
2124 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2125 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2127 wwin
->client
.x
= req_x
;
2128 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2129 if (HAS_BORDER(wwin
)) {
2130 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2131 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2134 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2136 wwin
->frame_x
= req_x
;
2137 wwin
->frame_y
= req_y
;
2139 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2141 wWindowSynthConfigureNotify(wwin
);
2145 void wWindowUpdateButtonImages(WWindow
*wwin
)
2147 WScreen
*scr
= wwin
->screen_ptr
;
2148 Pixmap pixmap
, mask
;
2149 WFrameWindow
*fwin
= wwin
->frame
;
2151 if (!HAS_TITLEBAR(wwin
))
2154 /* miniaturize button */
2155 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2156 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2157 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2159 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2160 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2165 if (fwin
->lbutton_image
2166 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2167 wPixmapDestroy(fwin
->lbutton_image
);
2168 fwin
->lbutton_image
= NULL
;
2171 if (!fwin
->lbutton_image
) {
2172 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2173 fwin
->lbutton_image
->client_owned
= 1;
2174 fwin
->lbutton_image
->client_owned_mask
= 1;
2177 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2178 wPixmapDestroy(fwin
->lbutton_image
);
2180 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2183 #ifdef XKB_BUTTON_HINT
2184 if (!WFLAGP(wwin
, no_language_button
)) {
2185 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2186 wPixmapDestroy(fwin
->languagebutton_image
);
2188 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2194 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2195 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2197 if (!WFLAGP(wwin
, no_close_button
)) {
2198 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2199 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2201 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2202 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2206 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2207 || fwin
->rbutton_image
->mask
!= mask
)) {
2208 wPixmapDestroy(fwin
->rbutton_image
);
2209 fwin
->rbutton_image
= NULL
;
2212 if (!fwin
->rbutton_image
) {
2213 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2214 fwin
->rbutton_image
->client_owned
= 1;
2215 fwin
->rbutton_image
->client_owned_mask
= 1;
2218 } else if (WFLAGP(wwin
, kill_close
)) {
2220 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2221 wPixmapDestroy(fwin
->rbutton_image
);
2223 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2225 } else if (MGFLAGP(wwin
, broken_close
)) {
2227 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2228 wPixmapDestroy(fwin
->rbutton_image
);
2230 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2234 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2235 wPixmapDestroy(fwin
->rbutton_image
);
2237 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2241 /* force buttons to be redrawn */
2242 fwin
->flags
.need_texture_change
= 1;
2243 wFrameWindowPaint(fwin
);
2247 *---------------------------------------------------------------------------
2248 * wWindowConfigureBorders--
2249 * Update window border configuration according to attribute flags.
2251 *---------------------------------------------------------------------------
2253 void wWindowConfigureBorders(WWindow
*wwin
)
2259 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2261 #ifdef XKB_BUTTON_HINT
2262 if (wPreferences
.modelock
)
2263 flags
|= WFF_LANGUAGE_BUTTON
;
2266 if (HAS_TITLEBAR(wwin
))
2267 flags
|= WFF_TITLEBAR
;
2268 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2269 flags
|= WFF_RESIZEBAR
;
2270 if (HAS_BORDER(wwin
))
2271 flags
|= WFF_BORDER
;
2272 if (wwin
->flags
.shaded
)
2273 flags
|= WFF_IS_SHADED
;
2275 oldh
= wwin
->frame
->top_width
;
2276 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2277 if (oldh
!= wwin
->frame
->top_width
) {
2278 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2280 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2281 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2285 if (!WFLAGP(wwin
, no_miniaturize_button
)
2286 && wwin
->frame
->flags
.hide_left_button
)
2287 flags
|= WFF_LEFT_BUTTON
;
2289 #ifdef XKB_BUTTON_HINT
2290 if (!WFLAGP(wwin
, no_language_button
)
2291 && wwin
->frame
->flags
.hide_language_button
) {
2292 flags
|= WFF_LANGUAGE_BUTTON
;
2296 if (!WFLAGP(wwin
, no_close_button
)
2297 && wwin
->frame
->flags
.hide_right_button
)
2298 flags
|= WFF_RIGHT_BUTTON
;
2301 wWindowUpdateButtonImages(wwin
);
2302 wFrameWindowShowButton(wwin
->frame
, flags
);
2306 if (WFLAGP(wwin
, no_miniaturize_button
)
2307 && !wwin
->frame
->flags
.hide_left_button
)
2308 flags
|= WFF_LEFT_BUTTON
;
2310 #ifdef XKB_BUTTON_HINT
2311 if (WFLAGP(wwin
, no_language_button
)
2312 && !wwin
->frame
->flags
.hide_language_button
)
2313 flags
|= WFF_LANGUAGE_BUTTON
;
2316 if (WFLAGP(wwin
, no_close_button
)
2317 && !wwin
->frame
->flags
.hide_right_button
)
2318 flags
|= WFF_RIGHT_BUTTON
;
2321 wFrameWindowHideButton(wwin
->frame
, flags
);
2324 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2325 wWindowSetShape(wwin
);
2331 void wWindowSaveState(WWindow
* wwin
)
2336 memset(data
, 0, sizeof(CARD32
) * 10);
2337 data
[0] = wwin
->frame
->workspace
;
2338 data
[1] = wwin
->flags
.miniaturized
;
2339 data
[2] = wwin
->flags
.shaded
;
2340 data
[3] = wwin
->flags
.hidden
;
2341 data
[4] = wwin
->flags
.maximized
;
2342 if (wwin
->flags
.maximized
== 0) {
2343 data
[5] = wwin
->frame_x
;
2344 data
[6] = wwin
->frame_y
;
2345 data
[7] = wwin
->frame
->core
->width
;
2346 data
[8] = wwin
->frame
->core
->height
;
2348 data
[5] = wwin
->old_geometry
.x
;
2349 data
[6] = wwin
->old_geometry
.y
;
2350 data
[7] = wwin
->old_geometry
.width
;
2351 data
[8] = wwin
->old_geometry
.height
;
2354 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2355 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2356 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2359 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2360 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2363 static int getSavedState(Window window
, WSavedState
** state
)
2367 unsigned long nitems_ret
;
2368 unsigned long bytes_after_ret
;
2371 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2372 True
, _XA_WINDOWMAKER_STATE
,
2373 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2374 (unsigned char **)&data
) != Success
|| !data
)
2377 *state
= wmalloc(sizeof(WSavedState
));
2379 (*state
)->workspace
= data
[0];
2380 (*state
)->miniaturized
= data
[1];
2381 (*state
)->shaded
= data
[2];
2382 (*state
)->hidden
= data
[3];
2383 (*state
)->maximized
= data
[4];
2384 (*state
)->x
= data
[5];
2385 (*state
)->y
= data
[6];
2386 (*state
)->w
= data
[7];
2387 (*state
)->h
= data
[8];
2388 (*state
)->window_shortcuts
= data
[9];
2392 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2399 void wWindowClearShape(WWindow
* wwin
)
2401 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2402 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2406 void wWindowSetShape(WWindow
* wwin
)
2410 #ifdef OPTIMIZE_SHAPE
2415 /* only shape is the client's */
2416 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2420 /* Get array of rectangles describing the shape mask */
2421 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2426 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2432 /* insert our decoration rectangles in the rect list */
2433 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2436 if (HAS_TITLEBAR(wwin
)) {
2438 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2439 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2440 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2443 if (HAS_RESIZEBAR(wwin
)) {
2445 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2446 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2447 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2451 /* shape our frame window */
2452 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2453 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2459 #endif /* OPTIMIZE_SHAPE */
2461 if (HAS_TITLEBAR(wwin
)) {
2464 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2465 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2468 if (HAS_RESIZEBAR(wwin
)) {
2470 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2471 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2472 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2476 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2477 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2479 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2480 0, wwin
->frame
->top_width
, wwin
->client_win
,
2481 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2486 /* ====================================================================== */
2488 static FocusMode
getFocusMode(WWindow
* wwin
)
2492 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2493 if (wwin
->wm_hints
->input
== True
) {
2494 if (wwin
->protocols
.TAKE_FOCUS
)
2495 mode
= WFM_LOCALLY_ACTIVE
;
2499 if (wwin
->protocols
.TAKE_FOCUS
)
2500 mode
= WFM_GLOBALLY_ACTIVE
;
2502 mode
= WFM_NO_INPUT
;
2510 void wWindowSetKeyGrabs(WWindow
* wwin
)
2515 for (i
= 0; i
< WKBD_LAST
; i
++) {
2516 key
= &wKeyBindings
[i
];
2518 if (key
->keycode
== 0)
2520 if (key
->modifier
!= AnyModifier
) {
2521 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2522 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2524 /* Also grab all modifier combinations possible that include,
2525 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2526 * work even if the NumLock/ScrollLock key is on.
2528 wHackedGrabKey(key
->keycode
, key
->modifier
,
2529 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2532 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2533 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2536 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2539 void wWindowResetMouseGrabs(WWindow
* wwin
)
2541 /* Mouse grabs can't be done on the client window because of
2542 * ICCCM and because clients that try to do the same will crash.
2544 * But there is a problem wich makes tbar buttons of unfocused
2545 * windows not usable as the click goes to the frame window instead
2546 * of the button itself. Must figure a way to fix that.
2549 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2551 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2552 /* grabs for Meta+drag */
2553 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2554 True
, ButtonPressMask
| ButtonReleaseMask
,
2555 GrabModeSync
, GrabModeAsync
, None
, None
);
2558 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2559 && !wwin
->flags
.is_gnustep
) {
2560 /* the passive grabs to focus the window */
2561 /* if (wPreferences.focus_mode == WKF_CLICK) */
2562 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2563 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2568 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2570 if (attr
->flags
& GSExtraFlagsAttr
) {
2571 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2572 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2573 wWindowUpdateButtonImages(wwin
);
2578 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2580 WWindowState
*wstate
;
2582 wstate
= malloc(sizeof(WWindowState
));
2586 memset(wstate
, 0, sizeof(WWindowState
));
2589 wstate
->instance
= wstrdup(instance
);
2591 wstate
->class = wstrdup(class);
2593 wstate
->command
= wstrdup(command
);
2594 wstate
->state
= state
;
2596 wstate
->next
= windowState
;
2597 windowState
= wstate
;
2600 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2606 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2608 WMagicNumber
wWindowGetSavedState(Window win
)
2610 char *instance
, *class, *command
= NULL
;
2611 WWindowState
*wstate
= windowState
;
2616 command
= GetCommandForWindow(win
);
2620 if (PropGetWMClass(win
, &class, &instance
)) {
2622 if (SAME(instance
, wstate
->instance
) &&
2623 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2626 wstate
= wstate
->next
;
2633 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2646 void wWindowDeleteSavedState(WMagicNumber id
)
2648 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2650 if (!wstate
|| !windowState
)
2654 if (tmp
== wstate
) {
2655 windowState
= wstate
->next
;
2657 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2658 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2660 if (wstate
->instance
)
2661 wfree(wstate
->instance
);
2663 wfree(wstate
->class);
2664 if (wstate
->command
)
2665 wfree(wstate
->command
);
2666 wfree(wstate
->state
);
2670 if (tmp
->next
== wstate
) {
2671 tmp
->next
= 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
);
2691 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2693 WWindowState
*tmp
, *wstate
;
2699 if (tmp
->pid
== pid
) {
2700 wstate
= windowState
;
2701 windowState
= tmp
->next
;
2703 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2704 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2706 if (wstate
->instance
)
2707 wfree(wstate
->instance
);
2709 wfree(wstate
->class);
2710 if (wstate
->command
)
2711 wfree(wstate
->command
);
2712 wfree(wstate
->state
);
2716 if (tmp
->next
->pid
== pid
) {
2718 tmp
->next
= wstate
->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
);
2738 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2740 if (wwin
->flags
.omnipresent
== flag
)
2743 wwin
->flags
.omnipresent
= flag
;
2744 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2747 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2749 WWindow
*wwin
= data
;
2751 #ifndef NUMLOCK_HACK
2752 if ((event
->xbutton
.state
& ValidModMask
)
2753 != (event
->xbutton
.state
& ~LockMask
)) {
2754 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2755 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2759 event
->xbutton
.state
&= ValidModMask
;
2761 CloseWindowMenu(wwin
->screen_ptr
);
2763 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2764 && !WFLAGP(wwin
, no_focusable
)) {
2765 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2768 if (event
->xbutton
.button
== Button1
)
2769 wRaiseFrame(wwin
->frame
->core
);
2771 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2772 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2773 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2774 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2776 wwarning("pointer grab failed for window move");
2782 if (event
->xbutton
.state
& MOD_MASK
) {
2783 /* move the window */
2784 wMouseMoveWindow(wwin
, event
);
2785 XUngrabPointer(dpy
, CurrentTime
);
2787 wMouseResizeWindow(wwin
, event
);
2788 XUngrabPointer(dpy
, CurrentTime
);
2792 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2794 WWindow
*wwin
= data
;
2796 event
->xbutton
.state
&= ValidModMask
;
2798 if (event
->xbutton
.button
== Button1
) {
2799 if (event
->xbutton
.state
== 0) {
2800 if (!WFLAGP(wwin
, no_shadeable
)) {
2802 if (wwin
->flags
.shaded
)
2803 wUnshadeWindow(wwin
);
2810 if (event
->xbutton
.state
& ControlMask
)
2811 dir
|= MAX_VERTICAL
;
2813 if (event
->xbutton
.state
& ShiftMask
) {
2814 dir
|= MAX_HORIZONTAL
;
2815 if (!(event
->xbutton
.state
& ControlMask
))
2816 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2819 /* maximize window */
2820 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2821 int ndir
= dir
^ wwin
->flags
.maximized
;
2824 wMaximizeWindow(wwin
, ndir
);
2826 wUnmaximizeWindow(wwin
);
2829 } else if (event
->xbutton
.button
== Button3
) {
2830 if (event
->xbutton
.state
& MOD_MASK
) {
2831 wHideOtherApplications(wwin
);
2833 } else if (event
->xbutton
.button
== Button2
) {
2834 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2835 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2837 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2838 wUnshadeWindow(wwin
);
2842 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2844 WWindow
*wwin
= desc
->parent
;
2845 unsigned int new_width
, w_scale
;
2846 unsigned int new_height
, h_scale
;
2847 unsigned int resize_width_increment
= 0;
2848 unsigned int resize_height_increment
= 0;
2850 if (wwin
->normal_hints
) {
2851 w_scale
= ceil(wPreferences
.resize_increment
/ wwin
->normal_hints
->width_inc
);
2852 h_scale
= ceil(wPreferences
.resize_increment
/ wwin
->normal_hints
->height_inc
);
2853 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2854 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2856 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2857 resize_width_increment
= wPreferences
.resize_increment
;
2858 resize_height_increment
= wPreferences
.resize_increment
;
2861 event
->xbutton
.state
&= ValidModMask
;
2863 CloseWindowMenu(wwin
->screen_ptr
);
2865 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2866 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2868 if (event
->xbutton
.button
== Button1
)
2869 wRaiseFrame(wwin
->frame
->core
);
2871 if (event
->xbutton
.state
& MOD_MASK
) {
2872 /* move the window */
2873 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2874 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2875 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2877 wwarning("pointer grab failed for window move");
2881 if (event
->xbutton
.button
== Button3
) {
2882 wMouseResizeWindow(wwin
, event
);
2883 } else if (event
->xbutton
.button
== Button4
) {
2884 new_width
= wwin
->client
.width
- resize_width_increment
;
2885 new_height
= wwin
->client
.height
- resize_height_increment
;
2886 wWindowConstrainSize(wwin
, &new_width
,&new_height
);
2887 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, new_height
);
2888 } else if (event
->xbutton
.button
== Button5
) {
2889 new_width
= wwin
->client
.width
+ resize_width_increment
;
2890 new_height
= wwin
->client
.height
+ resize_height_increment
;
2891 wWindowConstrainSize(wwin
, &new_width
,&new_height
);
2892 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, new_height
);
2893 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2894 wMouseMoveWindow(wwin
, event
);
2896 XUngrabPointer(dpy
, CurrentTime
);
2900 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2902 WWindow
*wwin
= (WWindow
*) data
;
2904 #ifndef NUMLOCK_HACK
2905 if ((event
->xbutton
.state
& ValidModMask
)
2906 != (event
->xbutton
.state
& ~LockMask
)) {
2907 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2908 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2911 event
->xbutton
.state
&= ValidModMask
;
2913 CloseWindowMenu(wwin
->screen_ptr
);
2915 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2916 && !WFLAGP(wwin
, no_focusable
)) {
2917 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2920 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2922 if (event
->xbutton
.button
== Button1
) {
2923 if (event
->xbutton
.state
& MOD_MASK
) {
2924 wLowerFrame(wwin
->frame
->core
);
2926 wRaiseFrame(wwin
->frame
->core
);
2929 if ((event
->xbutton
.state
& ShiftMask
)
2930 && !(event
->xbutton
.state
& ControlMask
)) {
2931 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2934 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2935 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2936 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2937 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2939 wwarning("pointer grab failed for window move");
2944 /* move the window */
2945 wMouseMoveWindow(wwin
, event
);
2947 XUngrabPointer(dpy
, CurrentTime
);
2948 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2949 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2950 WObjDescriptor
*desc
;
2952 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2953 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2954 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2955 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2957 wwarning("pointer grab failed for window move");
2962 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2964 /* allow drag select */
2965 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2966 event
->xany
.send_event
= True
;
2967 (*desc
->handle_mousedown
) (desc
, event
);
2969 XUngrabPointer(dpy
, CurrentTime
);
2973 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2975 WWindow
*wwin
= data
;
2977 event
->xbutton
.state
&= ValidModMask
;
2979 CloseWindowMenu(wwin
->screen_ptr
);
2981 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2984 /* if control-click, kill the client */
2985 if (event
->xbutton
.state
& ControlMask
) {
2988 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2989 /* send delete message */
2990 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2995 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2997 WWindow
*wwin
= data
;
2999 CloseWindowMenu(wwin
->screen_ptr
);
3001 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3004 /* send delete message */
3005 if (wwin
->protocols
.DELETE_WINDOW
) {
3006 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3012 #ifdef XKB_BUTTON_HINT
3013 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3015 WWindow
*wwin
= data
;
3016 WFrameWindow
*fwin
= wwin
->frame
;
3017 WScreen
*scr
= fwin
->screen_ptr
;
3018 XkbStateRec staterec
;
3021 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3023 tl
= wwin
->frame
->languagemode
;
3024 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3025 wwin
->frame
->last_languagemode
= tl
;
3026 wSetFocusTo(scr
, wwin
);
3027 wwin
->frame
->languagebutton_image
=
3028 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3029 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3030 if (event
->xbutton
.button
== Button3
)
3032 wRaiseFrame(fwin
->core
);
3036 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3038 WWindow
*wwin
= data
;
3040 event
->xbutton
.state
&= ValidModMask
;
3042 CloseWindowMenu(wwin
->screen_ptr
);
3044 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3047 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3048 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3051 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3053 wapp
= wApplicationOf(wwin
->main_window
);
3054 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3055 wHideApplication(wapp
);
3056 } else if (event
->xbutton
.state
== 0) {
3057 wIconifyWindow(wwin
);