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 Atom _XA_WM_DELETE_WINDOW
;
79 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
80 extern Atom _XA_WINDOWMAKER_STATE
;
81 extern WPreferences wPreferences
;
82 extern Time LastTimestamp
;
85 extern void DoWindowBirth(WWindow
*wwin
);
87 /***** Local Stuff *****/
88 static WWindowState
*windowState
= NULL
;
89 static FocusMode
getFocusMode(WWindow
*wwin
);
90 static int getSavedState(Window window
, WSavedState
**state
);
91 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
93 /* frame window (during window grabs) */
94 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
97 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
98 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
101 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
103 #ifdef XKB_BUTTON_HINT
104 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
107 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
108 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
109 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
111 /****** Notification Observers ******/
113 static void appearanceObserver(void *self
, WMNotification
* notif
)
115 WWindow
*wwin
= (WWindow
*) self
;
116 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
118 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
121 if (flags
& WFontSettings
) {
122 wWindowConfigureBorders(wwin
);
123 if (wwin
->flags
.shaded
) {
124 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
126 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
127 wWindowSynthConfigureNotify(wwin
);
130 if (flags
& WTextureSettings
) {
131 wwin
->frame
->flags
.need_texture_remake
= 1;
133 if (flags
& (WTextureSettings
| WColorSettings
)) {
134 if (wwin
->frame
->titlebar
)
135 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
137 wFrameWindowPaint(wwin
->frame
);
142 WWindow
*wWindowFor(Window window
)
144 WObjDescriptor
*desc
;
149 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
152 if (desc
->parent_type
== WCLASS_WINDOW
)
154 else if (desc
->parent_type
== WCLASS_FRAME
) {
155 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
156 if (frame
->flags
.is_client_window_frame
)
163 WWindow
*wWindowCreate(void)
167 wwin
= wmalloc(sizeof(WWindow
));
170 memset(wwin
, 0, sizeof(WWindow
));
172 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
173 wwin
->client_descriptor
.parent
= wwin
;
174 wwin
->client_descriptor
.self
= wwin
;
175 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
180 void wWindowDestroy(WWindow
*wwin
)
184 if (wwin
->screen_ptr
->cmap_window
== wwin
)
185 wwin
->screen_ptr
->cmap_window
= NULL
;
187 WMRemoveNotificationObserver(wwin
);
189 wwin
->flags
.destroyed
= 1;
191 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
192 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
195 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
197 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
198 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
199 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
203 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
204 wwin
->fake_group
->retainCount
--;
205 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
206 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
207 wwin
->fake_group
->leader
= None
;
208 wwin
->fake_group
->origLeader
= None
;
213 if (wwin
->normal_hints
)
214 XFree(wwin
->normal_hints
);
217 XFree(wwin
->wm_hints
);
219 if (wwin
->wm_instance
)
220 XFree(wwin
->wm_instance
);
223 XFree(wwin
->wm_class
);
225 if (wwin
->wm_gnustep_attr
)
226 wfree(wwin
->wm_gnustep_attr
);
228 if (wwin
->cmap_windows
)
229 XFree(wwin
->cmap_windows
);
231 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
234 wFrameWindowDestroy(wwin
->frame
);
237 RemoveFromStackList(wwin
->icon
->core
);
238 wIconDestroy(wwin
->icon
);
239 if (wPreferences
.auto_arrange_icons
)
240 wArrangeIcons(wwin
->screen_ptr
, True
);
242 if (wwin
->net_icon_image
)
243 RReleaseImage(wwin
->net_icon_image
);
248 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
250 if (gs_hints
->flags
& GSWindowStyleAttr
) {
251 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
252 wwin
->client_flags
.no_border
= 1;
253 wwin
->client_flags
.no_titlebar
= 1;
254 wwin
->client_flags
.no_closable
= 1;
255 wwin
->client_flags
.no_miniaturizable
= 1;
256 wwin
->client_flags
.no_resizable
= 1;
257 wwin
->client_flags
.no_close_button
= 1;
258 wwin
->client_flags
.no_miniaturize_button
= 1;
259 wwin
->client_flags
.no_resizebar
= 1;
261 wwin
->client_flags
.no_close_button
=
262 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
264 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
266 wwin
->client_flags
.no_miniaturize_button
=
267 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
269 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
271 wwin
->client_flags
.no_resizebar
=
272 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
274 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
276 /* these attributes supposedly imply in the existence
278 if (gs_hints
->window_style
& (WMResizableWindowMask
|
279 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
280 wwin
->client_flags
.no_titlebar
= 0;
282 wwin
->client_flags
.no_titlebar
=
283 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
288 /* setup the defaults */
289 wwin
->client_flags
.no_border
= 0;
290 wwin
->client_flags
.no_titlebar
= 0;
291 wwin
->client_flags
.no_closable
= 0;
292 wwin
->client_flags
.no_miniaturizable
= 0;
293 wwin
->client_flags
.no_resizable
= 0;
294 wwin
->client_flags
.no_close_button
= 0;
295 wwin
->client_flags
.no_miniaturize_button
= 0;
296 wwin
->client_flags
.no_resizebar
= 0;
298 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
)
299 wwin
->client_flags
.no_appicon
= 1;
302 void wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
304 WScreen
*scr
= wwin
->screen_ptr
;
306 /* sets global default stuff */
307 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
309 * Decoration setting is done in this precedence (lower to higher)
310 * - use global default in the resource database
311 * - guess some settings
312 * - use GNUstep/external window attributes
313 * - set hints specified for the app in the resource DB
316 WSETUFLAG(wwin
, broken_close
, 0);
318 if (wwin
->protocols
.DELETE_WINDOW
)
319 WSETUFLAG(wwin
, kill_close
, 0);
321 WSETUFLAG(wwin
, kill_close
, 1);
323 /* transients can't be iconified or maximized */
324 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
325 WSETUFLAG(wwin
, no_miniaturizable
, 1);
326 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
329 /* if the window can't be resized, remove the resizebar */
330 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
331 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
332 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
333 WSETUFLAG(wwin
, no_resizable
, 1);
334 WSETUFLAG(wwin
, no_resizebar
, 1);
337 /* set GNUstep window attributes */
338 if (wwin
->wm_gnustep_attr
) {
339 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
341 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
343 *level
= wwin
->wm_gnustep_attr
->window_level
;
345 * INT_MIN is the only illegal window level.
347 if (*level
== INT_MIN
)
348 *level
= INT_MIN
+ 1;
351 *level
= WMNormalLevel
;
354 int tmp_workspace
= -1;
355 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
361 wMWMCheckClientHints(wwin
);
362 #endif /* MWM_HINTS */
365 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
367 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
368 * have INT_MIN that means that no window level was requested. -Dan
370 if (tmp_level
== INT_MIN
) {
371 if (WFLAGP(wwin
, floating
))
372 *level
= WMFloatingLevel
;
373 else if (WFLAGP(wwin
, sunken
))
374 *level
= WMSunkenLevel
;
376 *level
= WMNormalLevel
;
381 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
382 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
383 if (transientOwner
) {
384 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
385 if (ownerLevel
> *level
)
390 if (tmp_workspace
>= 0)
391 *workspace
= tmp_workspace
% scr
->workspace_count
;
395 * Set attributes specified only for that window/class.
396 * This might do duplicate work with the 1st wDefaultFillAttributes().
398 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
399 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
401 * Sanity checks for attributes that depend on other attributes
403 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
404 wwin
->user_flags
.emulate_appicon
= 0;
406 if (wwin
->main_window
!= None
) {
407 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
408 if (wapp
&& !wapp
->flags
.emulated
)
409 wwin
->user_flags
.emulate_appicon
= 0;
412 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
413 wwin
->user_flags
.emulate_appicon
= 0;
415 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
416 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
417 wwin
->user_flags
.sunken
= 0;
419 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
421 /* windows that have takefocus=False shouldn't take focus at all */
422 if (wwin
->focus_mode
== WFM_NO_INPUT
)
423 wwin
->client_flags
.no_focusable
= 1;
426 Bool
wWindowCanReceiveFocus(WWindow
*wwin
)
428 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
430 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
432 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
438 Bool
wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
442 w1
= wwin
->frame
->core
->width
;
443 h1
= wwin
->frame
->core
->height
;
444 w2
= obscured
->frame
->core
->width
;
445 h2
= obscured
->frame
->core
->height
;
447 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
448 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
451 if (wwin
->frame_x
+ w1
< obscured
->frame_x
452 || wwin
->frame_y
+ h1
< obscured
->frame_y
453 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
)
459 static void fixLeaderProperties(WWindow
*wwin
)
461 XClassHint
*classHint
;
462 XWMHints
*hints
, *clientHints
;
463 Window leaders
[2], window
;
464 char **argv
, *command
;
468 classHint
= XAllocClassHint();
469 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
470 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
472 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
476 leaders
[0] = wwin
->client_leader
;
477 leaders
[1] = wwin
->group_id
;
480 command
= GetCommandForWindow(wwin
->client_win
);
482 /* command already set. nothing to do. */
485 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
489 for (i
= 0; i
< 2; i
++) {
492 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
493 classHint
->res_name
= wwin
->wm_instance
;
494 classHint
->res_class
= wwin
->wm_class
;
495 XSetClassHint(dpy
, window
, classHint
);
497 hints
= XGetWMHints(dpy
, window
);
500 } else if (clientHints
) {
501 /* set window group leader to self */
502 clientHints
->window_group
= window
;
503 clientHints
->flags
|= WindowGroupHint
;
504 XSetWMHints(dpy
, window
, clientHints
);
508 command
= GetCommandForWindow(window
);
510 /* command already set. nothing to do. */
513 XSetCommand(dpy
, window
, argv
, argc
);
526 static Window
createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
528 XClassHint
*classHint
;
534 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
536 classHint
= XAllocClassHint();
537 classHint
->res_name
= instance
;
538 classHint
->res_class
= class;
539 XSetClassHint(dpy
, leader
, classHint
);
542 /* inherit these from the original leader if available */
543 hints
= XGetWMHints(dpy
, win
);
545 hints
= XAllocWMHints();
548 /* set window group leader to self */
549 hints
->window_group
= leader
;
550 hints
->flags
|= WindowGroupHint
;
551 XSetWMHints(dpy
, leader
, hints
);
554 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
555 XSetCommand(dpy
, leader
, argv
, argc
);
556 XFreeStringList(argv
);
562 static int matchIdentifier(const void *item
, const void *cdata
)
564 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
568 *----------------------------------------------------------------
570 * reparents the window and allocates a descriptor for it.
571 * Window manager hints and other hints are fetched to configure
572 * the window decoration attributes and others. User preferences
573 * for the window are used if available, to configure window
574 * decorations and some behaviour.
575 * If in startup, windows that are override redirect,
576 * unmapped and never were managed and are Withdrawn are not
580 * the new window descriptor
583 * The window is reparented and appropriate notification
584 * is done to the client. Input mask for the window is setup.
585 * The window descriptor is also associated with various window
586 * contexts and inserted in the head of the window list.
587 * Event handler contexts are associated for some objects
588 * (buttons, titlebar and resizebar)
590 *----------------------------------------------------------------
592 WWindow
*wManageWindow(WScreen
*scr
, Window window
)
596 unsigned width
, height
;
597 XWindowAttributes wattribs
;
598 XSetWindowAttributes attribs
;
599 WWindowState
*win_state
;
600 WWindow
*transientOwner
= NULL
;
606 Bool withdraw
= False
;
612 /* make sure the window is still there */
613 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
618 /* if it's an override-redirect, ignore it */
619 if (wattribs
.override_redirect
) {
624 wm_state
= PropGetWindowState(window
);
626 /* if it's startup and the window is unmapped, don't manage it */
627 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
632 wwin
= wWindowCreate();
634 title
= wNETWMGetWindowName(window
);
636 wwin
->flags
.net_has_title
= 1;
637 if (!title
&& !wFetchName(dpy
, window
, &title
))
640 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
643 if (wShapeSupported
) {
648 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
649 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
650 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
651 wwin
->flags
.shaped
= b_shaped
;
656 * Get hints and other information in properties
658 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
660 /* setup descriptor */
661 wwin
->client_win
= window
;
662 wwin
->screen_ptr
= scr
;
663 wwin
->old_border_width
= wattribs
.border_width
;
664 wwin
->event_mask
= CLIENT_EVENTS
;
665 attribs
.event_mask
= CLIENT_EVENTS
;
666 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
667 attribs
.save_under
= False
;
669 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
670 XSetWindowBorderWidth(dpy
, window
, 0);
672 /* get hints from GNUstep app */
673 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "GNUstep") == 0) {
674 wwin
->flags
.is_gnustep
= 1;
676 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
677 wwin
->wm_gnustep_attr
= NULL
;
680 if (wwin
->wm_class
!= NULL
&& strcmp(wwin
->wm_class
, "DockApp") == 0) {
681 wwin
->flags
.is_dockapp
= 1;
685 wwin
->client_leader
= PropGetClientLeader(window
);
686 if (wwin
->client_leader
!= None
)
687 wwin
->main_window
= wwin
->client_leader
;
689 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
691 if (wwin
->wm_hints
) {
692 if (wwin
->wm_hints
->flags
& StateHint
) {
694 if (wwin
->wm_hints
->initial_state
== IconicState
) {
696 wwin
->flags
.miniaturized
= 1;
698 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
700 wwin
->flags
.is_dockapp
= 1;
705 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
706 wwin
->group_id
= wwin
->wm_hints
->window_group
;
707 /* window_group has priority over CLIENT_LEADER */
708 wwin
->main_window
= wwin
->group_id
;
710 wwin
->group_id
= None
;
713 if (wwin
->wm_hints
->flags
& UrgencyHint
)
714 wwin
->flags
.urgent
= 1;
716 wwin
->group_id
= None
;
719 PropGetProtocols(window
, &wwin
->protocols
);
721 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
722 wwin
->transient_for
= None
;
724 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
725 wwin
->transient_for
= scr
->root_win
;
727 transientOwner
= wWindowFor(wwin
->transient_for
);
728 if (transientOwner
&& transientOwner
->main_window
!= None
)
729 wwin
->main_window
= transientOwner
->main_window
;
733 /* guess the focus mode */
734 wwin
->focus_mode
= getFocusMode(wwin
);
736 /* get geometry stuff */
737 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
739 /* get colormap windows */
740 GetColormapWindows(wwin
);
743 * Setup the decoration/window attributes and
746 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
748 /* Make broken apps behave as a nice app. */
749 if (WFLAGP(wwin
, emulate_appicon
))
750 wwin
->main_window
= wwin
->client_win
;
752 fixLeaderProperties(wwin
);
754 wwin
->orig_main_window
= wwin
->main_window
;
756 if (wwin
->flags
.is_gnustep
)
757 WSETUFLAG(wwin
, shared_appicon
, 0);
759 if (wwin
->main_window
) {
760 extern Atom _XA_WINDOWMAKER_MENU
;
761 XTextProperty text_prop
;
763 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
764 WSETUFLAG(wwin
, shared_appicon
, 0);
768 if (wwin
->flags
.is_dockapp
)
769 WSETUFLAG(wwin
, shared_appicon
, 0);
771 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
772 char *buffer
, *instance
, *class;
773 WFakeGroupLeader
*fPtr
;
776 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
778 /* // only enter here if PropGetWMClass() succeds */
779 PropGetWMClass(wwin
->main_window
, &class, &instance
);
780 buffer
= StrConcatDot(instance
, class);
782 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
783 if (index
!= WANotFound
) {
784 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
785 if (fPtr
->retainCount
== 0) {
786 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
790 if (fPtr
->origLeader
== None
) {
791 if (ADEQUATE(wwin
->main_window
)) {
793 fPtr
->origLeader
= wwin
->main_window
;
796 wwin
->fake_group
= fPtr
;
797 /*wwin->group_id = fPtr->leader; */
798 wwin
->main_window
= fPtr
->leader
;
801 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
803 fPtr
->identifier
= buffer
;
804 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
805 fPtr
->origLeader
= None
;
806 fPtr
->retainCount
= 1;
808 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
810 if (ADEQUATE(wwin
->main_window
)) {
812 fPtr
->origLeader
= wwin
->main_window
;
814 wwin
->fake_group
= fPtr
;
815 /*wwin->group_id = fPtr->leader; */
816 wwin
->main_window
= fPtr
->leader
;
826 * Setup the initial state of the window
828 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
))
829 wwin
->flags
.miniaturized
= 1;
831 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
))
832 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
834 wNETWMCheckInitialClientState(wwin
);
836 /* apply previous state if it exists and we're in startup */
837 if (scr
->flags
.startup
&& wm_state
>= 0) {
839 if (wm_state
== IconicState
) {
841 wwin
->flags
.miniaturized
= 1;
843 } else if (wm_state
== WithdrawnState
) {
849 /* if there is a saved state (from file), restore it */
851 if (wwin
->main_window
!= None
)
852 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
854 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
856 if (win_state
&& !withdraw
) {
857 if (win_state
->state
->hidden
> 0)
858 wwin
->flags
.hidden
= win_state
->state
->hidden
;
860 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
861 wwin
->flags
.shaded
= win_state
->state
->shaded
;
863 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
864 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
867 if (!IS_OMNIPRESENT(wwin
)) {
868 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
870 if (w
< 0 || w
>= scr
->workspace_count
) {
871 workspace
= win_state
->state
->workspace
;
872 if (workspace
>= scr
->workspace_count
)
873 workspace
= scr
->current_workspace
;
878 workspace
= scr
->current_workspace
;
882 /* if we're restarting, restore saved state (from hints).
883 * This will overwrite previous */
887 if (getSavedState(window
, &wstate
)) {
888 wwin
->flags
.shaded
= wstate
->shaded
;
889 wwin
->flags
.hidden
= wstate
->hidden
;
890 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
891 wwin
->flags
.maximized
= wstate
->maximized
;
892 if (wwin
->flags
.maximized
) {
893 wwin
->old_geometry
.x
= wstate
->x
;
894 wwin
->old_geometry
.y
= wstate
->y
;
895 wwin
->old_geometry
.width
= wstate
->w
;
896 wwin
->old_geometry
.height
= wstate
->h
;
899 workspace
= wstate
->workspace
;
904 /* restore window shortcut */
905 if (wstate
!= NULL
|| win_state
!= NULL
) {
908 if (win_state
!= NULL
)
909 mask
= win_state
->state
->window_shortcuts
;
911 if (wstate
!= NULL
&& mask
== 0)
912 mask
= wstate
->window_shortcuts
;
917 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
918 if (mask
& (1 << i
)) {
919 if (!scr
->shortcutWindows
[i
])
920 scr
->shortcutWindows
[i
] = WMCreateArray(4);
922 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
931 /* don't let transients start miniaturized if their owners are not */
932 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
933 wwin
->flags
.miniaturized
= 0;
935 wwin
->wm_hints
->initial_state
= NormalState
;
938 /* set workspace on which the window starts */
939 if (workspace
>= 0) {
940 if (workspace
> scr
->workspace_count
- 1) {
941 workspace
= workspace
% scr
->workspace_count
;
946 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
948 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
953 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
955 workspace
= transientOwner
->frame
->workspace
;
959 workspace
= scr
->current_workspace
;
964 /* setup window geometry */
965 if (win_state
&& win_state
->state
->w
> 0) {
966 width
= win_state
->state
->w
;
967 height
= win_state
->state
->h
;
969 wWindowConstrainSize(wwin
, &width
, &height
);
971 /* do not ask for window placement if the window is
972 * transient, during startup, if the initial workspace is another one
973 * or if the window wants to start iconic.
974 * If geometry was saved, restore it. */
976 Bool dontBring
= False
;
978 if (win_state
&& win_state
->state
->w
> 0) {
979 x
= win_state
->state
->x
;
980 y
= win_state
->state
->y
;
981 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
982 && !scr
->flags
.startup
983 && workspace
== scr
->current_workspace
984 && !wwin
->flags
.miniaturized
985 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
987 if (transientOwner
&& transientOwner
->flags
.mapped
) {
988 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
992 x
= transientOwner
->frame_x
+
993 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
994 y
= transientOwner
->frame_y
+
995 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
998 * limit transient windows to be inside their parent's head
1000 rect
.pos
.x
= transientOwner
->frame_x
;
1001 rect
.pos
.y
= transientOwner
->frame_y
;
1002 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1003 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1005 head
= wGetHeadForRect(scr
, rect
);
1006 rect
= wGetRectForHead(scr
, head
);
1010 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1011 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1015 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1016 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1019 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1021 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1024 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1030 * Make spash screens come out in the center of a head
1031 * trouble is that most splashies never get here
1032 * they are managed trough atoms but god knows where.
1033 * Dan, do you know ? -peter
1035 * Most of them are not managed, they have set
1036 * OverrideRedirect, which means we can't do anything about
1041 * xinerama checks for: across head and dead space
1045 rect
.size
.width
= width
;
1046 rect
.size
.height
= height
;
1048 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1050 if (flags
& XFLAG_DEAD
)
1053 if (flags
& XFLAG_MULTIPLE
)
1057 switch (reposition
) {
1059 head
= wGetHeadForPointerLocation(scr
);
1060 rect
= wGetRectForHead(scr
, head
);
1062 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1063 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1067 rect
= wGetRectForHead(scr
, head
);
1071 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1072 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1076 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1077 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1086 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1087 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1090 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1092 if (wwin
->flags
.urgent
) {
1093 if (!IS_OMNIPRESENT(wwin
))
1094 wwin
->flags
.omnipresent
^= 1;
1098 * Create frame, borders and do reparenting
1100 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1101 #ifdef XKB_BUTTON_HINT
1102 if (wPreferences
.modelock
)
1103 foo
|= WFF_LANGUAGE_BUTTON
;
1105 if (HAS_TITLEBAR(wwin
))
1106 foo
|= WFF_TITLEBAR
;
1107 if (HAS_RESIZEBAR(wwin
))
1108 foo
|= WFF_RESIZEBAR
;
1109 if (HAS_BORDER(wwin
))
1112 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1113 x
, y
, width
, height
,
1114 &wPreferences
.window_title_clearance
, foo
,
1115 scr
->window_title_texture
,
1116 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1118 wwin
->frame
->flags
.is_client_window_frame
= 1;
1119 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1121 /* setup button images */
1122 wWindowUpdateButtonImages(wwin
);
1124 /* hide unused buttons */
1126 if (WFLAGP(wwin
, no_close_button
))
1127 foo
|= WFF_RIGHT_BUTTON
;
1128 if (WFLAGP(wwin
, no_miniaturize_button
))
1129 foo
|= WFF_LEFT_BUTTON
;
1130 #ifdef XKB_BUTTON_HINT
1131 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1132 foo
|= WFF_LANGUAGE_BUTTON
;
1135 wFrameWindowHideButton(wwin
->frame
, foo
);
1137 wwin
->frame
->child
= wwin
;
1138 wwin
->frame
->workspace
= workspace
;
1139 wwin
->frame
->on_click_left
= windowIconifyClick
;
1141 #ifdef XKB_BUTTON_HINT
1142 if (wPreferences
.modelock
)
1143 wwin
->frame
->on_click_language
= windowLanguageClick
;
1146 wwin
->frame
->on_click_right
= windowCloseClick
;
1147 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1148 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1149 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1150 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1152 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1153 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1154 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1159 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1161 /* if gravity is to the south, account for the border sizes */
1163 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1167 * wWindowConfigure() will init the client window's size
1168 * (wwin->client.{width,height}) and all other geometry
1169 * related variables (frame_x,frame_y)
1171 wWindowConfigure(wwin
, x
, y
, width
, height
);
1173 /* to make sure the window receives it's new position after reparenting */
1174 wWindowSynthConfigureNotify(wwin
);
1177 * Setup descriptors and save window to internal
1180 if (wwin
->main_window
!= None
) {
1184 /* Leader windows do not necessary set themselves as leaders.
1185 * If this is the case, point the leader of this window to
1187 leader
= wWindowFor(wwin
->main_window
);
1188 if (leader
&& leader
->main_window
== None
) {
1189 leader
->main_window
= leader
->client_win
;
1191 app
= wApplicationCreate(wwin
);
1193 app
->last_workspace
= workspace
;
1196 * Do application specific stuff, like setting application
1200 if (wwin
->flags
.hidden
) {
1201 /* if the window was set to hidden because it was hidden
1202 * in a previous incarnation and that state was restored */
1203 app
->flags
.hidden
= 1;
1204 } else if (app
->flags
.hidden
) {
1205 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1206 wwin
->flags
.hidden
= 1;
1208 wUnhideApplication(app
, False
, False
);
1216 /* setup the frame descriptor */
1217 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1218 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1219 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1221 /* don't let windows go away if we die */
1222 XAddToSaveSet(dpy
, window
);
1224 XLowerWindow(dpy
, window
);
1226 /* if window is in this workspace and should be mapped, then map it */
1227 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1228 && !wwin
->flags
.hidden
&& !withdraw
) {
1230 /* The following "if" is to avoid crashing of clients that expect
1231 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1232 * after the return from this function.
1234 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1235 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1237 wClientSetState(wwin
, NormalState
, None
);
1241 /* if not auto focus, then map the window under the currently
1243 #define _WIDTH(w) (w)->frame->core->width
1244 #define _HEIGHT(w) (w)->frame->core->height
1245 if (!wPreferences
.auto_focus
&& scr
->focused_window
1246 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1248 (_WIDTH(scr
->focused_window
) * 5) / 3
1250 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1251 && WINDOW_LEVEL(scr
->focused_window
) ==
1253 || wwin
->flags
.maximized
)) {
1254 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1261 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1262 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1264 * The brain damaged idiotic non-click to focus modes will
1265 * have trouble with this because:
1267 * 1. window is created and mapped by the client
1268 * 2. window is mapped by wmaker in small size
1269 * 3. window is animated to grow to normal size
1270 * 4. this function returns to normal event loop
1271 * 5. eventually, the EnterNotify event that would trigger
1272 * the window focusing (if the mouse is over that window)
1273 * will be processed by wmaker.
1274 * But since this event will be rather delayed
1275 * (step 3 has a large delay) the time when the event ocurred
1276 * and when it is processed, the client that owns that window
1277 * will reject the XSetInputFocus() for it.
1279 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1280 DoWindowBirth(wwin
);
1286 /* setup stacking descriptor */
1287 if (transientOwner
) {
1288 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1290 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1293 if (!scr
->focused_window
) {
1294 /* first window on the list */
1297 scr
->focused_window
= wwin
;
1301 /* add window at beginning of focus window list */
1302 tmp
= scr
->focused_window
;
1310 /* raise is set to true if we un-hid the app when this window was born.
1311 * we raise, else old windows of this app will be above this new one. */
1313 wRaiseFrame(wwin
->frame
->core
);
1316 /* Update name must come after WApplication stuff is done */
1317 wWindowUpdateName(wwin
, title
);
1324 * Final preparations before window is ready to go
1326 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1328 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1329 if (((transientOwner
&& transientOwner
->flags
.focused
)
1330 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
)) {
1332 /* only auto_focus if on same screen as mouse
1333 * (and same head for xinerama mode)
1334 * TODO: make it an option */
1336 /*TODO add checking the head of the window, is it available? */
1337 short same_screen
= 0, same_head
= 1;
1343 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1344 &foo
, &foo
, &foo
, &foo
, &bar
) != False
) {
1348 if (same_screen
== 1 && same_head
== 1) {
1349 wSetFocusTo(scr
, wwin
);
1353 wWindowResetMouseGrabs(wwin
);
1355 if (!WFLAGP(wwin
, no_bind_keys
))
1356 wWindowSetKeyGrabs(wwin
);
1358 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1359 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1361 /* Setup Notification Observers */
1362 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1364 /* Cleanup temporary stuff */
1366 wWindowDeleteSavedState(win_state
);
1368 /* If the window must be withdrawed, then do it now.
1369 * Must do some optimization, 'though */
1371 wwin
->flags
.mapped
= 0;
1372 wClientSetState(wwin
, WithdrawnState
, None
);
1373 wUnmanageWindow(wwin
, True
, False
);
1380 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1381 char *title
, int x
, int y
, int width
, int height
)
1386 wwin
= wWindowCreate();
1388 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1390 wwin
->flags
.internal_window
= 1;
1392 WSETUFLAG(wwin
, omnipresent
, 1);
1393 WSETUFLAG(wwin
, no_shadeable
, 1);
1394 WSETUFLAG(wwin
, no_resizable
, 1);
1395 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1397 wwin
->focus_mode
= WFM_PASSIVE
;
1398 wwin
->client_win
= window
;
1399 wwin
->screen_ptr
= scr
;
1400 wwin
->transient_for
= owner
;
1403 wwin
->client
.width
= width
;
1404 wwin
->client
.height
= height
;
1405 wwin
->frame_x
= wwin
->client
.x
;
1406 wwin
->frame_y
= wwin
->client
.y
;
1408 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1409 foo
|= WFF_TITLEBAR
;
1410 #ifdef XKB_BUTTON_HINT
1411 foo
|= WFF_LANGUAGE_BUTTON
;
1414 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1415 wwin
->frame_x
, wwin
->frame_y
,
1417 &wPreferences
.window_title_clearance
, foo
,
1418 scr
->window_title_texture
,
1419 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1421 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1423 wwin
->frame
->flags
.is_client_window_frame
= 1;
1424 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1426 wFrameWindowChangeTitle(wwin
->frame
, title
);
1428 /* setup button images */
1429 wWindowUpdateButtonImages(wwin
);
1432 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1434 wwin
->frame
->child
= wwin
;
1435 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1437 #ifdef XKB_BUTTON_HINT
1438 if (wPreferences
.modelock
)
1439 wwin
->frame
->on_click_language
= windowLanguageClick
;
1442 wwin
->frame
->on_click_right
= windowCloseClick
;
1443 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1444 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1445 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1446 wwin
->client
.y
+= wwin
->frame
->top_width
;
1448 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1449 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1451 /* setup the frame descriptor */
1452 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1453 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1454 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1456 XLowerWindow(dpy
, window
);
1457 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1459 /* setup stacking descriptor */
1460 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1462 tmp
= wWindowFor(wwin
->transient_for
);
1464 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1466 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1469 if (!scr
->focused_window
) {
1470 /* first window on the list */
1473 scr
->focused_window
= wwin
;
1477 /* add window at beginning of focus window list */
1478 tmp
= scr
->focused_window
;
1486 if (wwin
->flags
.is_gnustep
== 0)
1487 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1489 /* if (wPreferences.auto_focus) */
1490 wSetFocusTo(scr
, wwin
);
1491 wWindowResetMouseGrabs(wwin
);
1492 wWindowSetKeyGrabs(wwin
);
1498 *----------------------------------------------------------------------
1500 * Removes the frame window from a window and destroys all data
1501 * related to it. The window will be reparented back to the root window
1502 * if restore is True.
1505 * Everything related to the window is destroyed and the window
1506 * is removed from the window lists. Focus is set to the previous on the
1508 *----------------------------------------------------------------------
1510 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1512 WCoreWindow
*frame
= wwin
->frame
->core
;
1513 WWindow
*owner
= NULL
;
1514 WWindow
*newFocusedWindow
= NULL
;
1516 WScreen
*scr
= wwin
->screen_ptr
;
1518 /* First close attribute editor window if open */
1519 if (wwin
->flags
.inspector_open
) {
1520 wCloseInspectorForWindow(wwin
);
1523 /* Close window menu if it's open for this window */
1524 if (wwin
->flags
.menu_open_for_me
) {
1525 CloseWindowMenu(scr
);
1529 if (!wwin
->flags
.internal_window
)
1530 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1532 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1534 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1535 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1538 XUnmapWindow(dpy
, frame
->window
);
1540 XUnmapWindow(dpy
, wwin
->client_win
);
1542 /* deselect window */
1543 wSelectWindow(wwin
, False
);
1545 /* remove all pending events on window */
1546 /* I think this only matters for autoraise */
1547 if (wPreferences
.raise_delay
)
1548 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1552 /* reparent the window back to the root */
1554 wClientRestore(wwin
);
1556 if (wwin
->transient_for
!= scr
->root_win
) {
1557 owner
= wWindowFor(wwin
->transient_for
);
1559 if (!owner
->flags
.semi_focused
) {
1562 owner
->flags
.semi_focused
= 0;
1567 wasFocused
= wwin
->flags
.focused
;
1569 /* remove from window focus list */
1570 if (!wwin
->prev
&& !wwin
->next
) {
1571 /* was the only window */
1572 scr
->focused_window
= NULL
;
1573 newFocusedWindow
= NULL
;
1578 wwin
->prev
->next
= wwin
->next
;
1580 wwin
->next
->prev
= wwin
->prev
;
1582 scr
->focused_window
= wwin
->prev
;
1583 scr
->focused_window
->next
= NULL
;
1586 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1588 /* if in click to focus mode and the window
1589 * was a transient, focus the owner window
1592 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1593 tmp
= wWindowFor(wwin
->transient_for
);
1594 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1598 /* otherwise, focus the next one in the focus list */
1600 tmp
= scr
->focused_window
;
1601 while (tmp
) { /* look for one in the window list first */
1602 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1603 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1607 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1608 tmp
= scr
->focused_window
;
1610 if (!WFLAGP(tmp
, no_focusable
)
1611 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1618 newFocusedWindow
= tmp
;
1620 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1625 /* This is to let the root window get the keyboard input
1626 * if Sloppy focus mode and no other window get focus.
1627 * This way keybindings will not freeze.
1630 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1631 tmp
= wWindowFor(win
);
1634 newFocusedWindow
= tmp
;
1636 newFocusedWindow
= NULL
;
1640 if (!wwin
->flags
.internal_window
)
1641 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1643 if (newFocusedWindow
!= owner
&& owner
) {
1644 if (wwin
->flags
.is_gnustep
== 0)
1645 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1647 wSetFocusTo(scr
, newFocusedWindow
);
1649 wWindowDestroy(wwin
);
1653 void wWindowMap(WWindow
*wwin
)
1655 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1656 if (!wwin
->flags
.shaded
) {
1657 /* window will be remapped when getting MapNotify */
1658 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1659 XMapWindow(dpy
, wwin
->client_win
);
1660 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1662 wwin
->flags
.mapped
= 1;
1666 void wWindowUnmap(WWindow
*wwin
)
1668 wwin
->flags
.mapped
= 0;
1670 /* prevent window withdrawal when getting UnmapNotify */
1671 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1672 XUnmapWindow(dpy
, wwin
->client_win
);
1673 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1675 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1678 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1683 #ifdef KEEP_XKB_LOCK_STATUS
1684 if (wPreferences
.modelock
) {
1685 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1687 #endif /* KEEP_XKB_LOCK_STATUS */
1689 wwin
->flags
.semi_focused
= 0;
1691 if (wwin
->flags
.is_gnustep
== 0)
1692 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1694 wwin
->flags
.focused
= 1;
1696 wWindowResetMouseGrabs(wwin
);
1698 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1700 if (owin
== wwin
|| !owin
)
1703 nowner
= wWindowFor(wwin
->transient_for
);
1705 /* new window is a transient for the old window */
1706 if (nowner
== owin
) {
1707 owin
->flags
.semi_focused
= 1;
1708 wWindowUnfocus(nowner
);
1712 oowner
= wWindowFor(owin
->transient_for
);
1714 /* new window is owner of old window */
1715 if (wwin
== oowner
) {
1716 wWindowUnfocus(owin
);
1721 wWindowUnfocus(owin
);
1725 /* new window has same owner of old window */
1726 if (oowner
== nowner
) {
1727 /* prevent unfocusing of owner */
1728 oowner
->flags
.semi_focused
= 0;
1729 wWindowUnfocus(owin
);
1730 oowner
->flags
.semi_focused
= 1;
1735 /* nowner != NULL && oowner != nowner */
1736 nowner
->flags
.semi_focused
= 1;
1737 wWindowUnfocus(nowner
);
1738 wWindowUnfocus(owin
);
1741 void wWindowUnfocus(WWindow
*wwin
)
1743 CloseWindowMenu(wwin
->screen_ptr
);
1745 if (wwin
->flags
.is_gnustep
== 0)
1746 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1748 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1750 owner
= wWindowFor(wwin
->transient_for
);
1751 if (owner
&& owner
->flags
.semi_focused
) {
1752 owner
->flags
.semi_focused
= 0;
1753 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1754 wWindowUnfocus(owner
);
1755 wFrameWindowPaint(owner
->frame
);
1759 wwin
->flags
.focused
= 0;
1760 wWindowResetMouseGrabs(wwin
);
1761 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1764 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1771 wwin
->flags
.wm_name_changed
= 1;
1774 /* the hint was removed */
1775 title
= DEF_WINDOW_TITLE
;
1780 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1781 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1786 *----------------------------------------------------------------------
1788 * wWindowConstrainSize--
1789 * Constrains size for the client window, taking the maximal size,
1790 * window resize increments and other size hints into account.
1793 * The closest size to what was given that the client window can
1796 *----------------------------------------------------------------------
1798 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1800 int width
= (int)*nwidth
;
1801 int height
= (int)*nheight
;
1804 int minW
= 1, minH
= 1;
1805 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1806 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1807 int minAX
= -1, minAY
= -1;
1808 int maxAX
= -1, maxAY
= -1;
1812 if (wwin
->normal_hints
) {
1813 winc
= wwin
->normal_hints
->width_inc
;
1814 hinc
= wwin
->normal_hints
->height_inc
;
1815 minW
= wwin
->normal_hints
->min_width
;
1816 minH
= wwin
->normal_hints
->min_height
;
1817 maxW
= wwin
->normal_hints
->max_width
;
1818 maxH
= wwin
->normal_hints
->max_height
;
1819 if (wwin
->normal_hints
->flags
& PAspect
) {
1820 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1821 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1822 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1823 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1826 baseW
= wwin
->normal_hints
->base_width
;
1827 baseH
= wwin
->normal_hints
->base_height
;
1840 /* aspect ratio code borrowed from olwm */
1842 /* adjust max aspect ratio */
1843 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1844 if (maxAX
> maxAY
) {
1845 height
= (width
* maxAY
) / maxAX
;
1846 if (height
> maxH
) {
1848 width
= (height
* maxAX
) / maxAY
;
1851 width
= (height
* maxAX
) / maxAY
;
1854 height
= (width
* maxAY
) / maxAX
;
1859 /* adjust min aspect ratio */
1860 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1861 if (minAX
> minAY
) {
1862 height
= (width
* minAY
) / minAX
;
1863 if (height
< minH
) {
1865 width
= (height
* minAX
) / minAY
;
1868 width
= (height
* minAX
) / minAY
;
1871 height
= (width
* minAY
) / minAX
;
1878 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1880 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1883 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1885 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1887 /* broken stupid apps may cause preposterous values for these.. */
1894 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1895 unsigned int *width
, unsigned int *height
)
1897 int baseW
= 0, baseH
= 0;
1898 int winc
= 1, hinc
= 1;
1900 if (wwin
->normal_hints
) {
1901 baseW
= wwin
->normal_hints
->base_width
;
1902 baseH
= wwin
->normal_hints
->base_height
;
1904 winc
= wwin
->normal_hints
->width_inc
;
1905 hinc
= wwin
->normal_hints
->height_inc
;
1909 *width
= maxW
- (maxW
- baseW
) % winc
;
1912 *height
= maxH
- (maxH
- baseH
) % hinc
;
1915 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1917 WScreen
*scr
= wwin
->screen_ptr
;
1921 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1924 if (workspace
!= scr
->current_workspace
) {
1925 /* Sent to other workspace. Unmap window */
1926 if ((wwin
->flags
.mapped
1927 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1928 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1930 wapp
= wApplicationOf(wwin
->main_window
);
1932 wapp
->last_workspace
= workspace
;
1934 if (wwin
->flags
.miniaturized
) {
1936 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1937 wwin
->icon
->mapped
= 0;
1941 wSetFocusTo(scr
, NULL
);
1945 /* brought to current workspace. Map window */
1946 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1948 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1949 wwin
->icon
->mapped
= 1;
1951 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1955 if (!IS_OMNIPRESENT(wwin
)) {
1956 int oldWorkspace
= wwin
->frame
->workspace
;
1958 wwin
->frame
->workspace
= workspace
;
1960 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
1967 void wWindowSynthConfigureNotify(WWindow
*wwin
)
1971 sevent
.type
= ConfigureNotify
;
1972 sevent
.xconfigure
.display
= dpy
;
1973 sevent
.xconfigure
.event
= wwin
->client_win
;
1974 sevent
.xconfigure
.window
= wwin
->client_win
;
1976 sevent
.xconfigure
.x
= wwin
->client
.x
;
1977 sevent
.xconfigure
.y
= wwin
->client
.y
;
1978 sevent
.xconfigure
.width
= wwin
->client
.width
;
1979 sevent
.xconfigure
.height
= wwin
->client
.height
;
1981 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1982 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
1983 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1985 sevent
.xconfigure
.above
= None
;
1987 sevent
.xconfigure
.override_redirect
= False
;
1988 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1993 *----------------------------------------------------------------------
1994 * wWindowConfigure()
1996 * req_x, req_y: new requested positions for the frame
1997 * req_width, req_height: new requested sizes for the client
1999 * Configures the frame, decorations and client window to the specified
2000 * geometry, whose validity is not checked -- wWindowConstrainSize()
2001 * must be used for that.
2002 * The size parameters are for the client window, but the position is
2004 * The client window receives a ConfigureNotify event, according
2005 * to what ICCCM says.
2011 * Window size and position are changed and client window receives
2012 * a ConfigureNotify event.
2013 *----------------------------------------------------------------------
2015 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2017 int synth_notify
= False
;
2020 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2022 * if the window is being moved but not resized then
2023 * send a synthetic ConfigureNotify
2025 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2026 synth_notify
= True
;
2029 if (WFLAGP(wwin
, dont_move_off
))
2030 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2032 if (req_width
< MIN_WINDOW_SIZE
)
2033 req_width
= MIN_WINDOW_SIZE
;
2034 if (req_height
< MIN_WINDOW_SIZE
)
2035 req_height
= MIN_WINDOW_SIZE
;
2037 /* If growing, resize inner part before frame,
2038 * if shrinking, resize frame before.
2039 * This will prevent the frame (that can have a different color)
2040 * to be exposed, causing flicker */
2041 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2042 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2044 if (wwin
->flags
.shaded
) {
2045 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2046 wwin
->old_geometry
.height
= req_height
;
2050 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2052 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2055 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2056 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2058 wwin
->client
.x
= req_x
;
2059 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2060 wwin
->client
.width
= req_width
;
2061 wwin
->client
.height
= req_height
;
2063 wwin
->client
.x
= req_x
;
2064 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2066 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2068 wwin
->frame_x
= req_x
;
2069 wwin
->frame_y
= req_y
;
2070 if (HAS_BORDER(wwin
)) {
2071 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2072 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2075 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2076 wWindowSetShape(wwin
);
2081 wWindowSynthConfigureNotify(wwin
);
2085 /* req_x, req_y: new position of the frame */
2086 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2088 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2089 int synth_notify
= False
;
2091 /* Send a synthetic ConfigureNotify event for every window movement. */
2092 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2093 synth_notify
= True
;
2096 /* A single synthetic ConfigureNotify event is sent at the end of
2097 * a completed (opaque) movement in moveres.c */
2100 if (WFLAGP(wwin
, dont_move_off
))
2101 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2102 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2104 wwin
->client
.x
= req_x
;
2105 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2106 if (HAS_BORDER(wwin
)) {
2107 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2108 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2111 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2113 wwin
->frame_x
= req_x
;
2114 wwin
->frame_y
= req_y
;
2116 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2118 wWindowSynthConfigureNotify(wwin
);
2122 void wWindowUpdateButtonImages(WWindow
*wwin
)
2124 WScreen
*scr
= wwin
->screen_ptr
;
2125 Pixmap pixmap
, mask
;
2126 WFrameWindow
*fwin
= wwin
->frame
;
2128 if (!HAS_TITLEBAR(wwin
))
2131 /* miniaturize button */
2132 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2133 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2134 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2136 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2137 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2142 if (fwin
->lbutton_image
2143 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2144 wPixmapDestroy(fwin
->lbutton_image
);
2145 fwin
->lbutton_image
= NULL
;
2148 if (!fwin
->lbutton_image
) {
2149 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2150 fwin
->lbutton_image
->client_owned
= 1;
2151 fwin
->lbutton_image
->client_owned_mask
= 1;
2154 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2155 wPixmapDestroy(fwin
->lbutton_image
);
2157 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2160 #ifdef XKB_BUTTON_HINT
2161 if (!WFLAGP(wwin
, no_language_button
)) {
2162 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2163 wPixmapDestroy(fwin
->languagebutton_image
);
2165 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2171 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2172 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2174 if (!WFLAGP(wwin
, no_close_button
)) {
2175 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2176 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2178 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2179 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2183 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2184 || fwin
->rbutton_image
->mask
!= mask
)) {
2185 wPixmapDestroy(fwin
->rbutton_image
);
2186 fwin
->rbutton_image
= NULL
;
2189 if (!fwin
->rbutton_image
) {
2190 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2191 fwin
->rbutton_image
->client_owned
= 1;
2192 fwin
->rbutton_image
->client_owned_mask
= 1;
2195 } else if (WFLAGP(wwin
, kill_close
)) {
2197 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2198 wPixmapDestroy(fwin
->rbutton_image
);
2200 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2202 } else if (MGFLAGP(wwin
, broken_close
)) {
2204 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2205 wPixmapDestroy(fwin
->rbutton_image
);
2207 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2211 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2212 wPixmapDestroy(fwin
->rbutton_image
);
2214 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2218 /* force buttons to be redrawn */
2219 fwin
->flags
.need_texture_change
= 1;
2220 wFrameWindowPaint(fwin
);
2224 *---------------------------------------------------------------------------
2225 * wWindowConfigureBorders--
2226 * Update window border configuration according to attribute flags.
2228 *---------------------------------------------------------------------------
2230 void wWindowConfigureBorders(WWindow
*wwin
)
2236 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2238 #ifdef XKB_BUTTON_HINT
2239 if (wPreferences
.modelock
)
2240 flags
|= WFF_LANGUAGE_BUTTON
;
2243 if (HAS_TITLEBAR(wwin
))
2244 flags
|= WFF_TITLEBAR
;
2245 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2246 flags
|= WFF_RESIZEBAR
;
2247 if (HAS_BORDER(wwin
))
2248 flags
|= WFF_BORDER
;
2249 if (wwin
->flags
.shaded
)
2250 flags
|= WFF_IS_SHADED
;
2252 oldh
= wwin
->frame
->top_width
;
2253 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2254 if (oldh
!= wwin
->frame
->top_width
) {
2255 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2257 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2258 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2262 if (!WFLAGP(wwin
, no_miniaturize_button
)
2263 && wwin
->frame
->flags
.hide_left_button
)
2264 flags
|= WFF_LEFT_BUTTON
;
2266 #ifdef XKB_BUTTON_HINT
2267 if (!WFLAGP(wwin
, no_language_button
)
2268 && wwin
->frame
->flags
.hide_language_button
) {
2269 flags
|= WFF_LANGUAGE_BUTTON
;
2273 if (!WFLAGP(wwin
, no_close_button
)
2274 && wwin
->frame
->flags
.hide_right_button
)
2275 flags
|= WFF_RIGHT_BUTTON
;
2278 wWindowUpdateButtonImages(wwin
);
2279 wFrameWindowShowButton(wwin
->frame
, flags
);
2283 if (WFLAGP(wwin
, no_miniaturize_button
)
2284 && !wwin
->frame
->flags
.hide_left_button
)
2285 flags
|= WFF_LEFT_BUTTON
;
2287 #ifdef XKB_BUTTON_HINT
2288 if (WFLAGP(wwin
, no_language_button
)
2289 && !wwin
->frame
->flags
.hide_language_button
)
2290 flags
|= WFF_LANGUAGE_BUTTON
;
2293 if (WFLAGP(wwin
, no_close_button
)
2294 && !wwin
->frame
->flags
.hide_right_button
)
2295 flags
|= WFF_RIGHT_BUTTON
;
2298 wFrameWindowHideButton(wwin
->frame
, flags
);
2301 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2302 wWindowSetShape(wwin
);
2308 void wWindowSaveState(WWindow
* wwin
)
2313 memset(data
, 0, sizeof(long) * 10);
2314 data
[0] = wwin
->frame
->workspace
;
2315 data
[1] = wwin
->flags
.miniaturized
;
2316 data
[2] = wwin
->flags
.shaded
;
2317 data
[3] = wwin
->flags
.hidden
;
2318 data
[4] = wwin
->flags
.maximized
;
2319 if (wwin
->flags
.maximized
== 0) {
2320 data
[5] = wwin
->frame_x
;
2321 data
[6] = wwin
->frame_y
;
2322 data
[7] = wwin
->frame
->core
->width
;
2323 data
[8] = wwin
->frame
->core
->height
;
2325 data
[5] = wwin
->old_geometry
.x
;
2326 data
[6] = wwin
->old_geometry
.y
;
2327 data
[7] = wwin
->old_geometry
.width
;
2328 data
[8] = wwin
->old_geometry
.height
;
2331 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2332 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2333 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2336 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2337 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2340 static int getSavedState(Window window
, WSavedState
** state
)
2344 unsigned long nitems_ret
;
2345 unsigned long bytes_after_ret
;
2348 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2349 True
, _XA_WINDOWMAKER_STATE
,
2350 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2351 (unsigned char **)&data
) != Success
|| !data
|| nitems_ret
< 10)
2354 *state
= wmalloc(sizeof(WSavedState
));
2356 (*state
)->workspace
= data
[0];
2357 (*state
)->miniaturized
= data
[1];
2358 (*state
)->shaded
= data
[2];
2359 (*state
)->hidden
= data
[3];
2360 (*state
)->maximized
= data
[4];
2361 (*state
)->x
= data
[5];
2362 (*state
)->y
= data
[6];
2363 (*state
)->w
= data
[7];
2364 (*state
)->h
= data
[8];
2365 (*state
)->window_shortcuts
= data
[9];
2369 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2376 void wWindowClearShape(WWindow
* wwin
)
2378 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2379 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2383 void wWindowSetShape(WWindow
* wwin
)
2387 #ifdef OPTIMIZE_SHAPE
2392 /* only shape is the client's */
2393 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2397 /* Get array of rectangles describing the shape mask */
2398 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2403 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2409 /* insert our decoration rectangles in the rect list */
2410 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2413 if (HAS_TITLEBAR(wwin
)) {
2415 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2416 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2417 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2420 if (HAS_RESIZEBAR(wwin
)) {
2422 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2423 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2424 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2428 /* shape our frame window */
2429 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2430 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2436 #endif /* OPTIMIZE_SHAPE */
2438 if (HAS_TITLEBAR(wwin
)) {
2441 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2442 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2445 if (HAS_RESIZEBAR(wwin
)) {
2447 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2448 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2449 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2453 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2454 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2456 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2457 0, wwin
->frame
->top_width
, wwin
->client_win
,
2458 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2463 /* ====================================================================== */
2465 static FocusMode
getFocusMode(WWindow
* wwin
)
2469 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2470 if (wwin
->wm_hints
->input
== True
) {
2471 if (wwin
->protocols
.TAKE_FOCUS
)
2472 mode
= WFM_LOCALLY_ACTIVE
;
2476 if (wwin
->protocols
.TAKE_FOCUS
)
2477 mode
= WFM_GLOBALLY_ACTIVE
;
2479 mode
= WFM_NO_INPUT
;
2487 void wWindowSetKeyGrabs(WWindow
* wwin
)
2492 for (i
= 0; i
< WKBD_LAST
; i
++) {
2493 key
= &wKeyBindings
[i
];
2495 if (key
->keycode
== 0)
2497 if (key
->modifier
!= AnyModifier
) {
2498 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2499 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2501 /* Also grab all modifier combinations possible that include,
2502 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2503 * work even if the NumLock/ScrollLock key is on.
2505 wHackedGrabKey(key
->keycode
, key
->modifier
,
2506 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2509 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2510 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2513 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2516 void wWindowResetMouseGrabs(WWindow
* wwin
)
2518 /* Mouse grabs can't be done on the client window because of
2519 * ICCCM and because clients that try to do the same will crash.
2521 * But there is a problem wich makes tbar buttons of unfocused
2522 * windows not usable as the click goes to the frame window instead
2523 * of the button itself. Must figure a way to fix that.
2526 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2528 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2529 /* grabs for Meta+drag */
2530 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2531 True
, ButtonPressMask
| ButtonReleaseMask
,
2532 GrabModeSync
, GrabModeAsync
, None
, None
);
2534 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2535 * but we only grab it for Button4 and Button 5 since a lot of apps
2536 * use CTRL+Button1-3 for app related functionality
2538 if (wPreferences
.resize_increment
> 0) {
2539 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2540 True
, ButtonPressMask
| ButtonReleaseMask
,
2541 GrabModeSync
, GrabModeAsync
, None
, None
);
2542 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2543 True
, ButtonPressMask
| ButtonReleaseMask
,
2544 GrabModeSync
, GrabModeAsync
, None
, None
);
2546 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2547 True
, ButtonPressMask
| ButtonReleaseMask
,
2548 GrabModeSync
, GrabModeAsync
, None
, None
);
2549 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2550 True
, ButtonPressMask
| ButtonReleaseMask
,
2551 GrabModeSync
, GrabModeAsync
, None
, None
);
2555 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2556 && !wwin
->flags
.is_gnustep
) {
2557 /* the passive grabs to focus the window */
2558 /* if (wPreferences.focus_mode == WKF_CLICK) */
2559 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2560 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2565 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2567 if (attr
->flags
& GSExtraFlagsAttr
) {
2568 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2569 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2570 wWindowUpdateButtonImages(wwin
);
2575 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2577 WWindowState
*wstate
;
2579 wstate
= malloc(sizeof(WWindowState
));
2583 memset(wstate
, 0, sizeof(WWindowState
));
2586 wstate
->instance
= wstrdup(instance
);
2588 wstate
->class = wstrdup(class);
2590 wstate
->command
= wstrdup(command
);
2591 wstate
->state
= state
;
2593 wstate
->next
= windowState
;
2594 windowState
= wstate
;
2599 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2601 WMagicNumber
wWindowGetSavedState(Window win
)
2603 char *instance
, *class, *command
= NULL
;
2604 WWindowState
*wstate
= windowState
;
2609 command
= GetCommandForWindow(win
);
2613 if (PropGetWMClass(win
, &class, &instance
)) {
2615 if (SAME(instance
, wstate
->instance
) &&
2616 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2619 wstate
= wstate
->next
;
2635 void wWindowDeleteSavedState(WMagicNumber id
)
2637 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2639 if (!wstate
|| !windowState
)
2643 if (tmp
== wstate
) {
2644 windowState
= wstate
->next
;
2645 if (wstate
->instance
)
2646 wfree(wstate
->instance
);
2648 wfree(wstate
->class);
2649 if (wstate
->command
)
2650 wfree(wstate
->command
);
2651 wfree(wstate
->state
);
2655 if (tmp
->next
== wstate
) {
2656 tmp
->next
= wstate
->next
;
2657 if (wstate
->instance
)
2658 wfree(wstate
->instance
);
2660 wfree(wstate
->class);
2661 if (wstate
->command
)
2662 wfree(wstate
->command
);
2663 wfree(wstate
->state
);
2672 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2674 WWindowState
*tmp
, *wstate
;
2680 if (tmp
->pid
== pid
) {
2681 wstate
= windowState
;
2682 windowState
= tmp
->next
;
2683 if (wstate
->instance
)
2684 wfree(wstate
->instance
);
2686 wfree(wstate
->class);
2687 if (wstate
->command
)
2688 wfree(wstate
->command
);
2689 wfree(wstate
->state
);
2693 if (tmp
->next
->pid
== pid
) {
2695 tmp
->next
= wstate
->next
;
2696 if (wstate
->instance
)
2697 wfree(wstate
->instance
);
2699 wfree(wstate
->class);
2700 if (wstate
->command
)
2701 wfree(wstate
->command
);
2702 wfree(wstate
->state
);
2711 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2713 if (wwin
->flags
.omnipresent
== flag
)
2716 wwin
->flags
.omnipresent
= flag
;
2717 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2720 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2722 WWindow
*wwin
= data
;
2724 #ifndef NUMLOCK_HACK
2725 if ((event
->xbutton
.state
& ValidModMask
)
2726 != (event
->xbutton
.state
& ~LockMask
)) {
2727 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2728 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2732 event
->xbutton
.state
&= ValidModMask
;
2734 CloseWindowMenu(wwin
->screen_ptr
);
2736 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2737 && !WFLAGP(wwin
, no_focusable
)) {
2738 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2741 if (event
->xbutton
.button
== Button1
)
2742 wRaiseFrame(wwin
->frame
->core
);
2744 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2745 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2746 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2747 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2752 if (event
->xbutton
.state
& MOD_MASK
) {
2753 /* move the window */
2754 wMouseMoveWindow(wwin
, event
);
2755 XUngrabPointer(dpy
, CurrentTime
);
2757 wMouseResizeWindow(wwin
, event
);
2758 XUngrabPointer(dpy
, CurrentTime
);
2762 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2764 WWindow
*wwin
= data
;
2766 event
->xbutton
.state
&= ValidModMask
;
2768 if (event
->xbutton
.button
== Button1
) {
2769 if (event
->xbutton
.state
== 0) {
2770 if (!WFLAGP(wwin
, no_shadeable
)) {
2772 if (wwin
->flags
.shaded
)
2773 wUnshadeWindow(wwin
);
2780 if (event
->xbutton
.state
& ControlMask
)
2781 dir
|= MAX_VERTICAL
;
2783 if (event
->xbutton
.state
& ShiftMask
) {
2784 dir
|= MAX_HORIZONTAL
;
2785 if (!(event
->xbutton
.state
& ControlMask
))
2786 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2789 /* maximize window */
2790 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2791 int ndir
= dir
^ wwin
->flags
.maximized
;
2794 wMaximizeWindow(wwin
, ndir
);
2796 wUnmaximizeWindow(wwin
);
2799 } else if (event
->xbutton
.button
== Button3
) {
2800 if (event
->xbutton
.state
& MOD_MASK
) {
2801 wHideOtherApplications(wwin
);
2803 } else if (event
->xbutton
.button
== Button2
) {
2804 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2805 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2807 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2808 wUnshadeWindow(wwin
);
2812 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2814 WWindow
*wwin
= desc
->parent
;
2815 unsigned int new_width
, w_scale
;
2816 unsigned int new_height
, h_scale
;
2817 unsigned int resize_width_increment
= 0;
2818 unsigned int resize_height_increment
= 0;
2820 if (wwin
->normal_hints
) {
2821 w_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->width_inc
- 1) / wwin
->normal_hints
->width_inc
;
2822 h_scale
= (wPreferences
.resize_increment
+ wwin
->normal_hints
->height_inc
- 1) / wwin
->normal_hints
->height_inc
;
2823 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2824 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2826 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2827 resize_width_increment
= wPreferences
.resize_increment
;
2828 resize_height_increment
= wPreferences
.resize_increment
;
2831 event
->xbutton
.state
&= ValidModMask
;
2833 CloseWindowMenu(wwin
->screen_ptr
);
2835 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2836 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2838 if (event
->xbutton
.button
== Button1
)
2839 wRaiseFrame(wwin
->frame
->core
);
2841 if (event
->xbutton
.state
& ControlMask
) {
2842 if (event
->xbutton
.button
== Button4
) {
2843 new_width
= wwin
->client
.width
- resize_width_increment
;
2844 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2845 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2847 if (event
->xbutton
.button
== Button5
) {
2848 new_width
= wwin
->client
.width
+ resize_width_increment
;
2849 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2850 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2854 if (event
->xbutton
.state
& MOD_MASK
) {
2855 /* move the window */
2856 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2857 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2858 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2861 if (event
->xbutton
.button
== Button3
) {
2862 wMouseResizeWindow(wwin
, event
);
2863 } else if (event
->xbutton
.button
== Button4
) {
2864 new_height
= wwin
->client
.height
- resize_height_increment
;
2865 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2866 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2867 } else if (event
->xbutton
.button
== Button5
) {
2868 new_height
= wwin
->client
.height
+ resize_height_increment
;
2869 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2870 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2871 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2872 wMouseMoveWindow(wwin
, event
);
2874 XUngrabPointer(dpy
, CurrentTime
);
2878 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2880 WWindow
*wwin
= (WWindow
*) data
;
2882 #ifndef NUMLOCK_HACK
2883 if ((event
->xbutton
.state
& ValidModMask
)
2884 != (event
->xbutton
.state
& ~LockMask
)) {
2885 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2886 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2889 event
->xbutton
.state
&= ValidModMask
;
2891 CloseWindowMenu(wwin
->screen_ptr
);
2893 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2894 && !WFLAGP(wwin
, no_focusable
)) {
2895 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2898 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2900 if (event
->xbutton
.button
== Button1
) {
2901 if (event
->xbutton
.state
& MOD_MASK
) {
2902 wLowerFrame(wwin
->frame
->core
);
2904 wRaiseFrame(wwin
->frame
->core
);
2907 if ((event
->xbutton
.state
& ShiftMask
)
2908 && !(event
->xbutton
.state
& ControlMask
)) {
2909 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2912 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2913 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2914 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2915 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2919 /* move the window */
2920 wMouseMoveWindow(wwin
, event
);
2922 XUngrabPointer(dpy
, CurrentTime
);
2923 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2924 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2925 WObjDescriptor
*desc
;
2927 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2928 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2929 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2930 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2934 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
2936 /* allow drag select */
2937 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2938 event
->xany
.send_event
= True
;
2939 (*desc
->handle_mousedown
) (desc
, event
);
2941 XUngrabPointer(dpy
, CurrentTime
);
2945 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2947 WWindow
*wwin
= data
;
2949 event
->xbutton
.state
&= ValidModMask
;
2951 CloseWindowMenu(wwin
->screen_ptr
);
2953 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2956 /* if control-click, kill the client */
2957 if (event
->xbutton
.state
& ControlMask
) {
2960 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
2961 /* send delete message */
2962 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2967 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2969 WWindow
*wwin
= data
;
2971 CloseWindowMenu(wwin
->screen_ptr
);
2973 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2976 /* send delete message */
2977 if (wwin
->protocols
.DELETE_WINDOW
) {
2978 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2984 #ifdef XKB_BUTTON_HINT
2985 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2987 WWindow
*wwin
= data
;
2988 WFrameWindow
*fwin
= wwin
->frame
;
2989 WScreen
*scr
= fwin
->screen_ptr
;
2992 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
2994 tl
= wwin
->frame
->languagemode
;
2995 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
2996 wwin
->frame
->last_languagemode
= tl
;
2997 wSetFocusTo(scr
, wwin
);
2998 wwin
->frame
->languagebutton_image
=
2999 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3000 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3001 if (event
->xbutton
.button
== Button3
)
3003 wRaiseFrame(fwin
->core
);
3007 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3009 WWindow
*wwin
= data
;
3011 event
->xbutton
.state
&= ValidModMask
;
3013 CloseWindowMenu(wwin
->screen_ptr
);
3015 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3018 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3019 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3022 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3024 wapp
= wApplicationOf(wwin
->main_window
);
3025 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3026 wHideApplication(wapp
);
3027 } else if (event
->xbutton
.state
== 0) {
3028 wIconifyWindow(wwin
);