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
;
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
)) {
1371 /* only auto_focus if on same screen as mouse
1372 * (and same head for xinerama mode)
1373 * TODO: make it an option */
1375 /*TODO add checking the head of the window, is it available? */
1376 short same_screen
= 0, same_head
= 1;
1382 if (XQueryPointer(dpy
, scr
->root_win
, &dummy
, &dummy
,
1383 &foo
, &foo
, &foo
, &foo
, &bar
) != False
) {
1387 if (same_screen
== 1 && same_head
== 1) {
1388 wSetFocusTo(scr
, wwin
);
1392 wWindowResetMouseGrabs(wwin
);
1394 if (!WFLAGP(wwin
, no_bind_keys
))
1395 wWindowSetKeyGrabs(wwin
);
1397 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1398 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1400 /* Setup Notification Observers */
1401 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1403 /* Cleanup temporary stuff */
1405 wWindowDeleteSavedState(win_state
);
1407 /* If the window must be withdrawed, then do it now.
1408 * Must do some optimization, 'though */
1410 wwin
->flags
.mapped
= 0;
1411 wClientSetState(wwin
, WithdrawnState
, None
);
1412 wUnmanageWindow(wwin
, True
, False
);
1419 WWindow
*wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1420 char *title
, int x
, int y
, int width
, int height
)
1425 wwin
= wWindowCreate();
1427 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1429 wwin
->flags
.internal_window
= 1;
1431 WSETUFLAG(wwin
, omnipresent
, 1);
1432 WSETUFLAG(wwin
, no_shadeable
, 1);
1433 WSETUFLAG(wwin
, no_resizable
, 1);
1434 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1436 wwin
->focus_mode
= WFM_PASSIVE
;
1437 wwin
->client_win
= window
;
1438 wwin
->screen_ptr
= scr
;
1439 wwin
->transient_for
= owner
;
1442 wwin
->client
.width
= width
;
1443 wwin
->client
.height
= height
;
1444 wwin
->frame_x
= wwin
->client
.x
;
1445 wwin
->frame_y
= wwin
->client
.y
;
1447 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1448 foo
|= WFF_TITLEBAR
;
1449 #ifdef XKB_BUTTON_HINT
1450 foo
|= WFF_LANGUAGE_BUTTON
;
1453 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1454 wwin
->frame_x
, wwin
->frame_y
,
1456 &wPreferences
.window_title_clearance
, foo
,
1457 scr
->window_title_texture
,
1458 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1460 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1462 wwin
->frame
->flags
.is_client_window_frame
= 1;
1463 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1465 wFrameWindowChangeTitle(wwin
->frame
, title
);
1467 /* setup button images */
1468 wWindowUpdateButtonImages(wwin
);
1471 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1473 wwin
->frame
->child
= wwin
;
1474 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1476 #ifdef XKB_BUTTON_HINT
1477 if (wPreferences
.modelock
)
1478 wwin
->frame
->on_click_language
= windowLanguageClick
;
1481 wwin
->frame
->on_click_right
= windowCloseClick
;
1482 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1483 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1484 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1485 wwin
->client
.y
+= wwin
->frame
->top_width
;
1487 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1488 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1490 /* setup the frame descriptor */
1491 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1492 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1493 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1495 XLowerWindow(dpy
, window
);
1496 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1498 /* setup stacking descriptor */
1499 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1501 tmp
= wWindowFor(wwin
->transient_for
);
1503 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1505 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1508 if (!scr
->focused_window
) {
1509 /* first window on the list */
1512 scr
->focused_window
= wwin
;
1516 /* add window at beginning of focus window list */
1517 tmp
= scr
->focused_window
;
1525 if (wwin
->flags
.is_gnustep
== 0)
1526 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1528 /* if (wPreferences.auto_focus) */
1529 wSetFocusTo(scr
, wwin
);
1530 wWindowResetMouseGrabs(wwin
);
1531 wWindowSetKeyGrabs(wwin
);
1537 *----------------------------------------------------------------------
1539 * Removes the frame window from a window and destroys all data
1540 * related to it. The window will be reparented back to the root window
1541 * if restore is True.
1544 * Everything related to the window is destroyed and the window
1545 * is removed from the window lists. Focus is set to the previous on the
1547 *----------------------------------------------------------------------
1549 void wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1551 WCoreWindow
*frame
= wwin
->frame
->core
;
1552 WWindow
*owner
= NULL
;
1553 WWindow
*newFocusedWindow
= NULL
;
1555 WScreen
*scr
= wwin
->screen_ptr
;
1557 /* First close attribute editor window if open */
1558 if (wwin
->flags
.inspector_open
) {
1559 wCloseInspectorForWindow(wwin
);
1562 /* Close window menu if it's open for this window */
1563 if (wwin
->flags
.menu_open_for_me
) {
1564 CloseWindowMenu(scr
);
1568 if (!wwin
->flags
.internal_window
)
1569 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1571 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1573 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1574 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1577 XUnmapWindow(dpy
, frame
->window
);
1579 XUnmapWindow(dpy
, wwin
->client_win
);
1581 /* deselect window */
1582 wSelectWindow(wwin
, False
);
1584 /* remove all pending events on window */
1585 /* I think this only matters for autoraise */
1586 if (wPreferences
.raise_delay
)
1587 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1591 /* reparent the window back to the root */
1593 wClientRestore(wwin
);
1595 if (wwin
->transient_for
!= scr
->root_win
) {
1596 owner
= wWindowFor(wwin
->transient_for
);
1598 if (!owner
->flags
.semi_focused
) {
1601 owner
->flags
.semi_focused
= 0;
1606 wasFocused
= wwin
->flags
.focused
;
1608 /* remove from window focus list */
1609 if (!wwin
->prev
&& !wwin
->next
) {
1610 /* was the only window */
1611 scr
->focused_window
= NULL
;
1612 newFocusedWindow
= NULL
;
1617 wwin
->prev
->next
= wwin
->next
;
1619 wwin
->next
->prev
= wwin
->prev
;
1621 scr
->focused_window
= wwin
->prev
;
1622 scr
->focused_window
->next
= NULL
;
1625 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1627 /* if in click to focus mode and the window
1628 * was a transient, focus the owner window
1631 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1632 tmp
= wWindowFor(wwin
->transient_for
);
1633 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1637 /* otherwise, focus the next one in the focus list */
1639 tmp
= scr
->focused_window
;
1640 while (tmp
) { /* look for one in the window list first */
1641 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1642 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1646 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1647 tmp
= scr
->focused_window
;
1649 if (!WFLAGP(tmp
, no_focusable
)
1650 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1657 newFocusedWindow
= tmp
;
1659 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1664 /* This is to let the root window get the keyboard input
1665 * if Sloppy focus mode and no other window get focus.
1666 * This way keybindings will not freeze.
1669 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1670 tmp
= wWindowFor(win
);
1673 newFocusedWindow
= tmp
;
1675 newFocusedWindow
= NULL
;
1679 if (!wwin
->flags
.internal_window
)
1680 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1682 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
, (unsigned)frame
->window
);
1686 if (newFocusedWindow
!= owner
&& owner
) {
1687 if (wwin
->flags
.is_gnustep
== 0)
1688 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1690 wSetFocusTo(scr
, newFocusedWindow
);
1692 wWindowDestroy(wwin
);
1696 void wWindowMap(WWindow
*wwin
)
1698 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1699 if (!wwin
->flags
.shaded
) {
1700 /* window will be remapped when getting MapNotify */
1701 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1702 XMapWindow(dpy
, wwin
->client_win
);
1703 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1705 wwin
->flags
.mapped
= 1;
1709 void wWindowUnmap(WWindow
*wwin
)
1711 wwin
->flags
.mapped
= 0;
1713 /* prevent window withdrawal when getting UnmapNotify */
1714 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1715 XUnmapWindow(dpy
, wwin
->client_win
);
1716 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1718 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1721 void wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1726 #ifdef KEEP_XKB_LOCK_STATUS
1727 if (wPreferences
.modelock
) {
1728 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1730 #endif /* KEEP_XKB_LOCK_STATUS */
1732 wwin
->flags
.semi_focused
= 0;
1734 if (wwin
->flags
.is_gnustep
== 0)
1735 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1737 wwin
->flags
.focused
= 1;
1739 wWindowResetMouseGrabs(wwin
);
1741 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1743 if (owin
== wwin
|| !owin
)
1746 nowner
= wWindowFor(wwin
->transient_for
);
1748 /* new window is a transient for the old window */
1749 if (nowner
== owin
) {
1750 owin
->flags
.semi_focused
= 1;
1751 wWindowUnfocus(nowner
);
1755 oowner
= wWindowFor(owin
->transient_for
);
1757 /* new window is owner of old window */
1758 if (wwin
== oowner
) {
1759 wWindowUnfocus(owin
);
1764 wWindowUnfocus(owin
);
1768 /* new window has same owner of old window */
1769 if (oowner
== nowner
) {
1770 /* prevent unfocusing of owner */
1771 oowner
->flags
.semi_focused
= 0;
1772 wWindowUnfocus(owin
);
1773 oowner
->flags
.semi_focused
= 1;
1778 /* nowner != NULL && oowner != nowner */
1779 nowner
->flags
.semi_focused
= 1;
1780 wWindowUnfocus(nowner
);
1781 wWindowUnfocus(owin
);
1784 void wWindowUnfocus(WWindow
*wwin
)
1786 CloseWindowMenu(wwin
->screen_ptr
);
1788 if (wwin
->flags
.is_gnustep
== 0)
1789 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1791 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1793 owner
= wWindowFor(wwin
->transient_for
);
1794 if (owner
&& owner
->flags
.semi_focused
) {
1795 owner
->flags
.semi_focused
= 0;
1796 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1797 wWindowUnfocus(owner
);
1798 wFrameWindowPaint(owner
->frame
);
1802 wwin
->flags
.focused
= 0;
1803 wWindowResetMouseGrabs(wwin
);
1804 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1807 void wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1814 wwin
->flags
.wm_name_changed
= 1;
1817 /* the hint was removed */
1818 title
= DEF_WINDOW_TITLE
;
1823 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1824 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1829 *----------------------------------------------------------------------
1831 * wWindowConstrainSize--
1832 * Constrains size for the client window, taking the maximal size,
1833 * window resize increments and other size hints into account.
1836 * The closest size to what was given that the client window can
1839 *----------------------------------------------------------------------
1841 void wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1843 int width
= (int)*nwidth
;
1844 int height
= (int)*nheight
;
1847 int minW
= 1, minH
= 1;
1848 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1849 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1850 int minAX
= -1, minAY
= -1;
1851 int maxAX
= -1, maxAY
= -1;
1855 if (wwin
->normal_hints
) {
1856 winc
= wwin
->normal_hints
->width_inc
;
1857 hinc
= wwin
->normal_hints
->height_inc
;
1858 minW
= wwin
->normal_hints
->min_width
;
1859 minH
= wwin
->normal_hints
->min_height
;
1860 maxW
= wwin
->normal_hints
->max_width
;
1861 maxH
= wwin
->normal_hints
->max_height
;
1862 if (wwin
->normal_hints
->flags
& PAspect
) {
1863 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1864 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1865 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1866 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1869 baseW
= wwin
->normal_hints
->base_width
;
1870 baseH
= wwin
->normal_hints
->base_height
;
1883 /* aspect ratio code borrowed from olwm */
1885 /* adjust max aspect ratio */
1886 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1887 if (maxAX
> maxAY
) {
1888 height
= (width
* maxAY
) / maxAX
;
1889 if (height
> maxH
) {
1891 width
= (height
* maxAX
) / maxAY
;
1894 width
= (height
* maxAX
) / maxAY
;
1897 height
= (width
* maxAY
) / maxAX
;
1902 /* adjust min aspect ratio */
1903 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1904 if (minAX
> minAY
) {
1905 height
= (width
* minAY
) / minAX
;
1906 if (height
< minH
) {
1908 width
= (height
* minAX
) / minAY
;
1911 width
= (height
* minAX
) / minAY
;
1914 height
= (width
* minAY
) / minAX
;
1921 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1923 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1926 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1928 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1930 /* broken stupid apps may cause preposterous values for these.. */
1937 void wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
1938 unsigned int *width
, unsigned int *height
)
1940 int baseW
= 0, baseH
= 0;
1941 int winc
= 1, hinc
= 1;
1943 if (wwin
->normal_hints
) {
1944 baseW
= wwin
->normal_hints
->base_width
;
1945 baseH
= wwin
->normal_hints
->base_height
;
1947 winc
= wwin
->normal_hints
->width_inc
;
1948 hinc
= wwin
->normal_hints
->height_inc
;
1952 *width
= maxW
- (maxW
- baseW
) % winc
;
1955 *height
= maxH
- (maxH
- baseH
) % hinc
;
1958 void wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1960 WScreen
*scr
= wwin
->screen_ptr
;
1964 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
1967 if (workspace
!= scr
->current_workspace
) {
1968 /* Sent to other workspace. Unmap window */
1969 if ((wwin
->flags
.mapped
1970 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1971 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1973 wapp
= wApplicationOf(wwin
->main_window
);
1975 wapp
->last_workspace
= workspace
;
1977 if (wwin
->flags
.miniaturized
) {
1979 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1980 wwin
->icon
->mapped
= 0;
1984 wSetFocusTo(scr
, NULL
);
1988 /* brought to current workspace. Map window */
1989 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1991 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1992 wwin
->icon
->mapped
= 1;
1994 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1998 if (!IS_OMNIPRESENT(wwin
)) {
1999 int oldWorkspace
= wwin
->frame
->workspace
;
2001 wwin
->frame
->workspace
= workspace
;
2003 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
2010 void wWindowSynthConfigureNotify(WWindow
*wwin
)
2014 sevent
.type
= ConfigureNotify
;
2015 sevent
.xconfigure
.display
= dpy
;
2016 sevent
.xconfigure
.event
= wwin
->client_win
;
2017 sevent
.xconfigure
.window
= wwin
->client_win
;
2019 sevent
.xconfigure
.x
= wwin
->client
.x
;
2020 sevent
.xconfigure
.y
= wwin
->client
.y
;
2021 sevent
.xconfigure
.width
= wwin
->client
.width
;
2022 sevent
.xconfigure
.height
= wwin
->client
.height
;
2024 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2025 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2026 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2028 sevent
.xconfigure
.above
= None
;
2030 sevent
.xconfigure
.override_redirect
= False
;
2031 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2036 *----------------------------------------------------------------------
2037 * wWindowConfigure()
2039 * req_x, req_y: new requested positions for the frame
2040 * req_width, req_height: new requested sizes for the client
2042 * Configures the frame, decorations and client window to the specified
2043 * geometry, whose validity is not checked -- wWindowConstrainSize()
2044 * must be used for that.
2045 * The size parameters are for the client window, but the position is
2047 * The client window receives a ConfigureNotify event, according
2048 * to what ICCCM says.
2054 * Window size and position are changed and client window receives
2055 * a ConfigureNotify event.
2056 *----------------------------------------------------------------------
2058 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2060 int synth_notify
= False
;
2063 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2065 * if the window is being moved but not resized then
2066 * send a synthetic ConfigureNotify
2068 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2069 synth_notify
= True
;
2072 if (WFLAGP(wwin
, dont_move_off
))
2073 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2075 if (req_width
< MIN_WINDOW_SIZE
)
2076 req_width
= MIN_WINDOW_SIZE
;
2077 if (req_height
< MIN_WINDOW_SIZE
)
2078 req_height
= MIN_WINDOW_SIZE
;
2080 /* If growing, resize inner part before frame,
2081 * if shrinking, resize frame before.
2082 * This will prevent the frame (that can have a different color)
2083 * to be exposed, causing flicker */
2084 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2085 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2087 if (wwin
->flags
.shaded
) {
2088 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2089 wwin
->old_geometry
.height
= req_height
;
2093 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2095 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2098 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2099 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2101 wwin
->client
.x
= req_x
;
2102 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2103 wwin
->client
.width
= req_width
;
2104 wwin
->client
.height
= req_height
;
2106 wwin
->client
.x
= req_x
;
2107 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2109 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2111 wwin
->frame_x
= req_x
;
2112 wwin
->frame_y
= req_y
;
2113 if (HAS_BORDER(wwin
)) {
2114 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2115 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2118 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2119 wWindowSetShape(wwin
);
2124 wWindowSynthConfigureNotify(wwin
);
2128 /* req_x, req_y: new position of the frame */
2129 void wWindowMove(WWindow
*wwin
, int req_x
, int req_y
)
2131 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2132 int synth_notify
= False
;
2134 /* Send a synthetic ConfigureNotify event for every window movement. */
2135 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2136 synth_notify
= True
;
2139 /* A single synthetic ConfigureNotify event is sent at the end of
2140 * a completed (opaque) movement in moveres.c */
2143 if (WFLAGP(wwin
, dont_move_off
))
2144 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2145 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2147 wwin
->client
.x
= req_x
;
2148 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2149 if (HAS_BORDER(wwin
)) {
2150 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2151 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2154 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2156 wwin
->frame_x
= req_x
;
2157 wwin
->frame_y
= req_y
;
2159 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2161 wWindowSynthConfigureNotify(wwin
);
2165 void wWindowUpdateButtonImages(WWindow
*wwin
)
2167 WScreen
*scr
= wwin
->screen_ptr
;
2168 Pixmap pixmap
, mask
;
2169 WFrameWindow
*fwin
= wwin
->frame
;
2171 if (!HAS_TITLEBAR(wwin
))
2174 /* miniaturize button */
2175 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2176 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2177 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2179 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2180 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2185 if (fwin
->lbutton_image
2186 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2187 wPixmapDestroy(fwin
->lbutton_image
);
2188 fwin
->lbutton_image
= NULL
;
2191 if (!fwin
->lbutton_image
) {
2192 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2193 fwin
->lbutton_image
->client_owned
= 1;
2194 fwin
->lbutton_image
->client_owned_mask
= 1;
2197 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2198 wPixmapDestroy(fwin
->lbutton_image
);
2200 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2203 #ifdef XKB_BUTTON_HINT
2204 if (!WFLAGP(wwin
, no_language_button
)) {
2205 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2206 wPixmapDestroy(fwin
->languagebutton_image
);
2208 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2214 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2215 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2217 if (!WFLAGP(wwin
, no_close_button
)) {
2218 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2219 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2221 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2222 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2226 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2227 || fwin
->rbutton_image
->mask
!= mask
)) {
2228 wPixmapDestroy(fwin
->rbutton_image
);
2229 fwin
->rbutton_image
= NULL
;
2232 if (!fwin
->rbutton_image
) {
2233 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2234 fwin
->rbutton_image
->client_owned
= 1;
2235 fwin
->rbutton_image
->client_owned_mask
= 1;
2238 } else if (WFLAGP(wwin
, kill_close
)) {
2240 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2241 wPixmapDestroy(fwin
->rbutton_image
);
2243 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2245 } else if (MGFLAGP(wwin
, broken_close
)) {
2247 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2248 wPixmapDestroy(fwin
->rbutton_image
);
2250 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2254 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2255 wPixmapDestroy(fwin
->rbutton_image
);
2257 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2261 /* force buttons to be redrawn */
2262 fwin
->flags
.need_texture_change
= 1;
2263 wFrameWindowPaint(fwin
);
2267 *---------------------------------------------------------------------------
2268 * wWindowConfigureBorders--
2269 * Update window border configuration according to attribute flags.
2271 *---------------------------------------------------------------------------
2273 void wWindowConfigureBorders(WWindow
*wwin
)
2279 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2281 #ifdef XKB_BUTTON_HINT
2282 if (wPreferences
.modelock
)
2283 flags
|= WFF_LANGUAGE_BUTTON
;
2286 if (HAS_TITLEBAR(wwin
))
2287 flags
|= WFF_TITLEBAR
;
2288 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2289 flags
|= WFF_RESIZEBAR
;
2290 if (HAS_BORDER(wwin
))
2291 flags
|= WFF_BORDER
;
2292 if (wwin
->flags
.shaded
)
2293 flags
|= WFF_IS_SHADED
;
2295 oldh
= wwin
->frame
->top_width
;
2296 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2297 if (oldh
!= wwin
->frame
->top_width
) {
2298 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2300 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2301 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2305 if (!WFLAGP(wwin
, no_miniaturize_button
)
2306 && wwin
->frame
->flags
.hide_left_button
)
2307 flags
|= WFF_LEFT_BUTTON
;
2309 #ifdef XKB_BUTTON_HINT
2310 if (!WFLAGP(wwin
, no_language_button
)
2311 && wwin
->frame
->flags
.hide_language_button
) {
2312 flags
|= WFF_LANGUAGE_BUTTON
;
2316 if (!WFLAGP(wwin
, no_close_button
)
2317 && wwin
->frame
->flags
.hide_right_button
)
2318 flags
|= WFF_RIGHT_BUTTON
;
2321 wWindowUpdateButtonImages(wwin
);
2322 wFrameWindowShowButton(wwin
->frame
, flags
);
2326 if (WFLAGP(wwin
, no_miniaturize_button
)
2327 && !wwin
->frame
->flags
.hide_left_button
)
2328 flags
|= WFF_LEFT_BUTTON
;
2330 #ifdef XKB_BUTTON_HINT
2331 if (WFLAGP(wwin
, no_language_button
)
2332 && !wwin
->frame
->flags
.hide_language_button
)
2333 flags
|= WFF_LANGUAGE_BUTTON
;
2336 if (WFLAGP(wwin
, no_close_button
)
2337 && !wwin
->frame
->flags
.hide_right_button
)
2338 flags
|= WFF_RIGHT_BUTTON
;
2341 wFrameWindowHideButton(wwin
->frame
, flags
);
2344 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2345 wWindowSetShape(wwin
);
2351 void wWindowSaveState(WWindow
* wwin
)
2356 memset(data
, 0, sizeof(CARD32
) * 10);
2357 data
[0] = wwin
->frame
->workspace
;
2358 data
[1] = wwin
->flags
.miniaturized
;
2359 data
[2] = wwin
->flags
.shaded
;
2360 data
[3] = wwin
->flags
.hidden
;
2361 data
[4] = wwin
->flags
.maximized
;
2362 if (wwin
->flags
.maximized
== 0) {
2363 data
[5] = wwin
->frame_x
;
2364 data
[6] = wwin
->frame_y
;
2365 data
[7] = wwin
->frame
->core
->width
;
2366 data
[8] = wwin
->frame
->core
->height
;
2368 data
[5] = wwin
->old_geometry
.x
;
2369 data
[6] = wwin
->old_geometry
.y
;
2370 data
[7] = wwin
->old_geometry
.width
;
2371 data
[8] = wwin
->old_geometry
.height
;
2374 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2375 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2376 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2379 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2380 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2383 static int getSavedState(Window window
, WSavedState
** state
)
2387 unsigned long nitems_ret
;
2388 unsigned long bytes_after_ret
;
2391 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2392 True
, _XA_WINDOWMAKER_STATE
,
2393 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2394 (unsigned char **)&data
) != Success
|| !data
)
2397 *state
= wmalloc(sizeof(WSavedState
));
2399 (*state
)->workspace
= data
[0];
2400 (*state
)->miniaturized
= data
[1];
2401 (*state
)->shaded
= data
[2];
2402 (*state
)->hidden
= data
[3];
2403 (*state
)->maximized
= data
[4];
2404 (*state
)->x
= data
[5];
2405 (*state
)->y
= data
[6];
2406 (*state
)->w
= data
[7];
2407 (*state
)->h
= data
[8];
2408 (*state
)->window_shortcuts
= data
[9];
2412 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2419 void wWindowClearShape(WWindow
* wwin
)
2421 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2422 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2426 void wWindowSetShape(WWindow
* wwin
)
2430 #ifdef OPTIMIZE_SHAPE
2435 /* only shape is the client's */
2436 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2440 /* Get array of rectangles describing the shape mask */
2441 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2446 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2452 /* insert our decoration rectangles in the rect list */
2453 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2456 if (HAS_TITLEBAR(wwin
)) {
2458 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2459 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2460 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2463 if (HAS_RESIZEBAR(wwin
)) {
2465 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2466 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2467 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2471 /* shape our frame window */
2472 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2473 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2479 #endif /* OPTIMIZE_SHAPE */
2481 if (HAS_TITLEBAR(wwin
)) {
2484 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2485 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2488 if (HAS_RESIZEBAR(wwin
)) {
2490 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2491 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2492 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2496 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2497 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2499 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2500 0, wwin
->frame
->top_width
, wwin
->client_win
,
2501 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2506 /* ====================================================================== */
2508 static FocusMode
getFocusMode(WWindow
* wwin
)
2512 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2513 if (wwin
->wm_hints
->input
== True
) {
2514 if (wwin
->protocols
.TAKE_FOCUS
)
2515 mode
= WFM_LOCALLY_ACTIVE
;
2519 if (wwin
->protocols
.TAKE_FOCUS
)
2520 mode
= WFM_GLOBALLY_ACTIVE
;
2522 mode
= WFM_NO_INPUT
;
2530 void wWindowSetKeyGrabs(WWindow
* wwin
)
2535 for (i
= 0; i
< WKBD_LAST
; i
++) {
2536 key
= &wKeyBindings
[i
];
2538 if (key
->keycode
== 0)
2540 if (key
->modifier
!= AnyModifier
) {
2541 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2542 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2544 /* Also grab all modifier combinations possible that include,
2545 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2546 * work even if the NumLock/ScrollLock key is on.
2548 wHackedGrabKey(key
->keycode
, key
->modifier
,
2549 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2552 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2553 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2556 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2559 void wWindowResetMouseGrabs(WWindow
* wwin
)
2561 /* Mouse grabs can't be done on the client window because of
2562 * ICCCM and because clients that try to do the same will crash.
2564 * But there is a problem wich makes tbar buttons of unfocused
2565 * windows not usable as the click goes to the frame window instead
2566 * of the button itself. Must figure a way to fix that.
2569 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2571 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2572 /* grabs for Meta+drag */
2573 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2574 True
, ButtonPressMask
| ButtonReleaseMask
,
2575 GrabModeSync
, GrabModeAsync
, None
, None
);
2577 /* for CTRL+Wheel to Scroll Horiz, we have to grab CTRL as well
2578 * but we only grab it for Button4 and Button 5 since a lot of apps
2579 * use CTRL+Button1-3 for app related functionality
2581 wHackedGrabButton(Button4
, ControlMask
, wwin
->client_win
,
2582 True
, ButtonPressMask
| ButtonReleaseMask
,
2583 GrabModeSync
, GrabModeAsync
, None
, None
);
2584 wHackedGrabButton(Button5
, ControlMask
, wwin
->client_win
,
2585 True
, ButtonPressMask
| ButtonReleaseMask
,
2586 GrabModeSync
, GrabModeAsync
, None
, None
);
2588 wHackedGrabButton(Button4
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2589 True
, ButtonPressMask
| ButtonReleaseMask
,
2590 GrabModeSync
, GrabModeAsync
, None
, None
);
2591 wHackedGrabButton(Button5
, MOD_MASK
| ControlMask
, wwin
->client_win
,
2592 True
, ButtonPressMask
| ButtonReleaseMask
,
2593 GrabModeSync
, GrabModeAsync
, None
, None
);
2596 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2597 && !wwin
->flags
.is_gnustep
) {
2598 /* the passive grabs to focus the window */
2599 /* if (wPreferences.focus_mode == WKF_CLICK) */
2600 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2601 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2606 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2608 if (attr
->flags
& GSExtraFlagsAttr
) {
2609 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2610 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2611 wWindowUpdateButtonImages(wwin
);
2616 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2618 WWindowState
*wstate
;
2620 wstate
= malloc(sizeof(WWindowState
));
2624 memset(wstate
, 0, sizeof(WWindowState
));
2627 wstate
->instance
= wstrdup(instance
);
2629 wstate
->class = wstrdup(class);
2631 wstate
->command
= wstrdup(command
);
2632 wstate
->state
= state
;
2634 wstate
->next
= windowState
;
2635 windowState
= wstate
;
2638 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2644 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2646 WMagicNumber
wWindowGetSavedState(Window win
)
2648 char *instance
, *class, *command
= NULL
;
2649 WWindowState
*wstate
= windowState
;
2654 command
= GetCommandForWindow(win
);
2658 if (PropGetWMClass(win
, &class, &instance
)) {
2660 if (SAME(instance
, wstate
->instance
) &&
2661 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2664 wstate
= wstate
->next
;
2671 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2684 void wWindowDeleteSavedState(WMagicNumber id
)
2686 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2688 if (!wstate
|| !windowState
)
2692 if (tmp
== wstate
) {
2693 windowState
= wstate
->next
;
2695 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2696 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2698 if (wstate
->instance
)
2699 wfree(wstate
->instance
);
2701 wfree(wstate
->class);
2702 if (wstate
->command
)
2703 wfree(wstate
->command
);
2704 wfree(wstate
->state
);
2708 if (tmp
->next
== wstate
) {
2709 tmp
->next
= wstate
->next
;
2711 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2712 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2714 if (wstate
->instance
)
2715 wfree(wstate
->instance
);
2717 wfree(wstate
->class);
2718 if (wstate
->command
)
2719 wfree(wstate
->command
);
2720 wfree(wstate
->state
);
2729 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2731 WWindowState
*tmp
, *wstate
;
2737 if (tmp
->pid
== pid
) {
2738 wstate
= windowState
;
2739 windowState
= tmp
->next
;
2741 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2742 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2744 if (wstate
->instance
)
2745 wfree(wstate
->instance
);
2747 wfree(wstate
->class);
2748 if (wstate
->command
)
2749 wfree(wstate
->command
);
2750 wfree(wstate
->state
);
2754 if (tmp
->next
->pid
== pid
) {
2756 tmp
->next
= wstate
->next
;
2758 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2759 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2761 if (wstate
->instance
)
2762 wfree(wstate
->instance
);
2764 wfree(wstate
->class);
2765 if (wstate
->command
)
2766 wfree(wstate
->command
);
2767 wfree(wstate
->state
);
2776 void wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2778 if (wwin
->flags
.omnipresent
== flag
)
2781 wwin
->flags
.omnipresent
= flag
;
2782 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2785 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2787 WWindow
*wwin
= data
;
2789 #ifndef NUMLOCK_HACK
2790 if ((event
->xbutton
.state
& ValidModMask
)
2791 != (event
->xbutton
.state
& ~LockMask
)) {
2792 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2793 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2797 event
->xbutton
.state
&= ValidModMask
;
2799 CloseWindowMenu(wwin
->screen_ptr
);
2801 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2802 && !WFLAGP(wwin
, no_focusable
)) {
2803 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2806 if (event
->xbutton
.button
== Button1
)
2807 wRaiseFrame(wwin
->frame
->core
);
2809 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2810 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2811 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2812 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2814 wwarning("pointer grab failed for window move");
2820 if (event
->xbutton
.state
& MOD_MASK
) {
2821 /* move the window */
2822 wMouseMoveWindow(wwin
, event
);
2823 XUngrabPointer(dpy
, CurrentTime
);
2825 wMouseResizeWindow(wwin
, event
);
2826 XUngrabPointer(dpy
, CurrentTime
);
2830 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2832 WWindow
*wwin
= data
;
2834 event
->xbutton
.state
&= ValidModMask
;
2836 if (event
->xbutton
.button
== Button1
) {
2837 if (event
->xbutton
.state
== 0) {
2838 if (!WFLAGP(wwin
, no_shadeable
)) {
2840 if (wwin
->flags
.shaded
)
2841 wUnshadeWindow(wwin
);
2848 if (event
->xbutton
.state
& ControlMask
)
2849 dir
|= MAX_VERTICAL
;
2851 if (event
->xbutton
.state
& ShiftMask
) {
2852 dir
|= MAX_HORIZONTAL
;
2853 if (!(event
->xbutton
.state
& ControlMask
))
2854 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2857 /* maximize window */
2858 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2859 int ndir
= dir
^ wwin
->flags
.maximized
;
2862 wMaximizeWindow(wwin
, ndir
);
2864 wUnmaximizeWindow(wwin
);
2867 } else if (event
->xbutton
.button
== Button3
) {
2868 if (event
->xbutton
.state
& MOD_MASK
) {
2869 wHideOtherApplications(wwin
);
2871 } else if (event
->xbutton
.button
== Button2
) {
2872 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2873 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2875 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2876 wUnshadeWindow(wwin
);
2880 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2882 WWindow
*wwin
= desc
->parent
;
2883 unsigned int new_width
, w_scale
;
2884 unsigned int new_height
, h_scale
;
2885 unsigned int resize_width_increment
= 0;
2886 unsigned int resize_height_increment
= 0;
2888 if (wwin
->normal_hints
) {
2889 w_scale
= ceil(wPreferences
.resize_increment
/ wwin
->normal_hints
->width_inc
);
2890 h_scale
= ceil(wPreferences
.resize_increment
/ wwin
->normal_hints
->height_inc
);
2891 resize_width_increment
= wwin
->normal_hints
->width_inc
* w_scale
;
2892 resize_height_increment
= wwin
->normal_hints
->height_inc
* h_scale
;
2894 if (resize_width_increment
<= 1 && resize_height_increment
<= 1) {
2895 resize_width_increment
= wPreferences
.resize_increment
;
2896 resize_height_increment
= wPreferences
.resize_increment
;
2899 event
->xbutton
.state
&= ValidModMask
;
2901 CloseWindowMenu(wwin
->screen_ptr
);
2903 if (!(event
->xbutton
.state
& ControlMask
) && !WFLAGP(wwin
, no_focusable
))
2904 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2906 if (event
->xbutton
.button
== Button1
)
2907 wRaiseFrame(wwin
->frame
->core
);
2909 if (event
->xbutton
.state
& ControlMask
) {
2910 if (event
->xbutton
.button
== Button4
) {
2911 new_width
= wwin
->client
.width
- resize_width_increment
;
2912 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2913 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2915 if (event
->xbutton
.button
== Button5
) {
2916 new_width
= wwin
->client
.width
+ resize_width_increment
;
2917 wWindowConstrainSize(wwin
, &new_width
, &wwin
->client
.height
);
2918 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, new_width
, wwin
->client
.height
);
2922 if (event
->xbutton
.state
& MOD_MASK
) {
2923 /* move the window */
2924 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2925 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2926 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2928 wwarning("pointer grab failed for window move");
2932 if (event
->xbutton
.button
== Button3
) {
2933 wMouseResizeWindow(wwin
, event
);
2934 } else if (event
->xbutton
.button
== Button4
) {
2935 new_height
= wwin
->client
.height
- resize_height_increment
;
2936 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2937 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2938 } else if (event
->xbutton
.button
== Button5
) {
2939 new_height
= wwin
->client
.height
+ resize_height_increment
;
2940 wWindowConstrainSize(wwin
, &wwin
->client
.width
, &new_height
);
2941 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, new_height
);
2942 } else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2943 wMouseMoveWindow(wwin
, event
);
2945 XUngrabPointer(dpy
, CurrentTime
);
2949 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2951 WWindow
*wwin
= (WWindow
*) data
;
2953 #ifndef NUMLOCK_HACK
2954 if ((event
->xbutton
.state
& ValidModMask
)
2955 != (event
->xbutton
.state
& ~LockMask
)) {
2956 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2957 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2960 event
->xbutton
.state
&= ValidModMask
;
2962 CloseWindowMenu(wwin
->screen_ptr
);
2964 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2965 && !WFLAGP(wwin
, no_focusable
)) {
2966 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2969 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
2971 if (event
->xbutton
.button
== Button1
) {
2972 if (event
->xbutton
.state
& MOD_MASK
) {
2973 wLowerFrame(wwin
->frame
->core
);
2975 wRaiseFrame(wwin
->frame
->core
);
2978 if ((event
->xbutton
.state
& ShiftMask
)
2979 && !(event
->xbutton
.state
& ControlMask
)) {
2980 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2983 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2984 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2985 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2986 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2988 wwarning("pointer grab failed for window move");
2993 /* move the window */
2994 wMouseMoveWindow(wwin
, event
);
2996 XUngrabPointer(dpy
, CurrentTime
);
2997 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
2998 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
2999 WObjDescriptor
*desc
;
3001 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3002 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3003 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
3004 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3006 wwarning("pointer grab failed for window move");
3011 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
3013 /* allow drag select */
3014 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3015 event
->xany
.send_event
= True
;
3016 (*desc
->handle_mousedown
) (desc
, event
);
3018 XUngrabPointer(dpy
, CurrentTime
);
3022 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3024 WWindow
*wwin
= data
;
3026 event
->xbutton
.state
&= ValidModMask
;
3028 CloseWindowMenu(wwin
->screen_ptr
);
3030 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3033 /* if control-click, kill the client */
3034 if (event
->xbutton
.state
& ControlMask
) {
3037 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
3038 /* send delete message */
3039 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3044 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3046 WWindow
*wwin
= data
;
3048 CloseWindowMenu(wwin
->screen_ptr
);
3050 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3053 /* send delete message */
3054 if (wwin
->protocols
.DELETE_WINDOW
) {
3055 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3061 #ifdef XKB_BUTTON_HINT
3062 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3064 WWindow
*wwin
= data
;
3065 WFrameWindow
*fwin
= wwin
->frame
;
3066 WScreen
*scr
= fwin
->screen_ptr
;
3067 XkbStateRec staterec
;
3070 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3072 tl
= wwin
->frame
->languagemode
;
3073 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3074 wwin
->frame
->last_languagemode
= tl
;
3075 wSetFocusTo(scr
, wwin
);
3076 wwin
->frame
->languagebutton_image
=
3077 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3078 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3079 if (event
->xbutton
.button
== Button3
)
3081 wRaiseFrame(fwin
->core
);
3085 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3087 WWindow
*wwin
= data
;
3089 event
->xbutton
.state
&= ValidModMask
;
3091 CloseWindowMenu(wwin
->screen_ptr
);
3093 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3096 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3097 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3100 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3102 wapp
= wApplicationOf(wwin
->main_window
);
3103 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3104 wHideApplication(wapp
);
3105 } else if (event
->xbutton
.state
== 0) {
3106 wIconifyWindow(wwin
);