1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
38 /* For getting mouse wheel mappings from WINGs */
39 #include <WINGs/WINGsP.h>
41 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
56 #include "workspace.h"
66 /****** 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
;
84 extern Atom _XA_WINDOWMAKER_STATE
;
86 extern WPreferences wPreferences
;
88 #define MOD_MASK wPreferences.modifier_mask
90 extern Time LastTimestamp
;
93 extern void DoWindowBirth(WWindow
*);
95 /***** Local Stuff *****/
97 static WWindowState
*windowState
= NULL
;
100 static FocusMode
getFocusMode(WWindow
* wwin
);
102 static int getSavedState(Window window
, WSavedState
** state
);
104 static void setupGNUstepHints(WWindow
* wwin
, GNUstepWMAttributes
* gs_hints
);
108 /* frame window (during window grabs) */
109 static void frameMouseDown(WObjDescriptor
* desc
, XEvent
* event
);
112 static void windowCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
113 static void windowCloseDblClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
116 static void windowIconifyClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
118 #ifdef XKB_BUTTON_HINT
119 static void windowLanguageClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
122 static void titlebarMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
);
123 static void titlebarDblClick(WCoreWindow
* sender
, void *data
, XEvent
* event
);
125 static void resizebarMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
);
127 /****** Notification Observers ******/
129 static void appearanceObserver(void *self
, WMNotification
* notif
)
131 WWindow
*wwin
= (WWindow
*) self
;
132 uintptr_t flags
= (uintptr_t)WMGetNotificationClientData(notif
);
134 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
137 if (flags
& WFontSettings
) {
138 wWindowConfigureBorders(wwin
);
139 if (wwin
->flags
.shaded
) {
140 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
142 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
143 wWindowSynthConfigureNotify(wwin
);
146 if (flags
& WTextureSettings
) {
147 wwin
->frame
->flags
.need_texture_remake
= 1;
149 if (flags
& (WTextureSettings
| WColorSettings
)) {
150 if (wwin
->frame
->titlebar
)
151 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
153 wFrameWindowPaint(wwin
->frame
);
157 /************************************/
159 WWindow
*wWindowFor(Window window
)
161 WObjDescriptor
*desc
;
166 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*) & desc
) == XCNOENT
)
169 if (desc
->parent_type
== WCLASS_WINDOW
)
171 else if (desc
->parent_type
== WCLASS_FRAME
) {
172 WFrameWindow
*frame
= (WFrameWindow
*) desc
->parent
;
173 if (frame
->flags
.is_client_window_frame
)
180 WWindow
*wWindowCreate()
184 wwin
= wmalloc(sizeof(WWindow
));
187 memset(wwin
, 0, sizeof(WWindow
));
189 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
190 wwin
->client_descriptor
.parent
= wwin
;
191 wwin
->client_descriptor
.self
= wwin
;
192 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
197 void wWindowDestroy(WWindow
* wwin
)
201 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
202 wwin
->screen_ptr
->cmap_window
= NULL
;
205 WMRemoveNotificationObserver(wwin
);
207 wwin
->flags
.destroyed
= 1;
209 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
210 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
213 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
215 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
216 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
217 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
221 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
> 0) {
222 wwin
->fake_group
->retainCount
--;
223 if (wwin
->fake_group
->retainCount
== 0 && wwin
->fake_group
->leader
!= None
) {
224 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
225 wwin
->fake_group
->leader
= None
;
226 wwin
->fake_group
->origLeader
= None
;
231 if (wwin
->normal_hints
)
232 XFree(wwin
->normal_hints
);
235 XFree(wwin
->wm_hints
);
237 if (wwin
->wm_instance
)
238 XFree(wwin
->wm_instance
);
241 XFree(wwin
->wm_class
);
243 if (wwin
->wm_gnustep_attr
)
244 wfree(wwin
->wm_gnustep_attr
);
246 if (wwin
->cmap_windows
)
247 XFree(wwin
->cmap_windows
);
249 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
252 wFrameWindowDestroy(wwin
->frame
);
255 RemoveFromStackList(wwin
->icon
->core
);
256 wIconDestroy(wwin
->icon
);
257 if (wPreferences
.auto_arrange_icons
)
258 wArrangeIcons(wwin
->screen_ptr
, True
);
261 if (wwin
->net_icon_image
)
262 RReleaseImage(wwin
->net_icon_image
);
268 static void setupGNUstepHints(WWindow
* wwin
, GNUstepWMAttributes
* gs_hints
)
270 if (gs_hints
->flags
& GSWindowStyleAttr
) {
271 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
272 wwin
->client_flags
.no_border
= 1;
273 wwin
->client_flags
.no_titlebar
= 1;
274 wwin
->client_flags
.no_closable
= 1;
275 wwin
->client_flags
.no_miniaturizable
= 1;
276 wwin
->client_flags
.no_resizable
= 1;
277 wwin
->client_flags
.no_close_button
= 1;
278 wwin
->client_flags
.no_miniaturize_button
= 1;
279 wwin
->client_flags
.no_resizebar
= 1;
281 wwin
->client_flags
.no_close_button
=
282 ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
284 wwin
->client_flags
.no_closable
= ((gs_hints
->window_style
& WMClosableWindowMask
) ? 0 : 1);
286 wwin
->client_flags
.no_miniaturize_button
=
287 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
) ? 0 : 1);
289 wwin
->client_flags
.no_miniaturizable
= wwin
->client_flags
.no_miniaturize_button
;
291 wwin
->client_flags
.no_resizebar
=
292 ((gs_hints
->window_style
& WMResizableWindowMask
) ? 0 : 1);
294 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
296 /* these attributes supposedly imply in the existence
298 if (gs_hints
->window_style
& (WMResizableWindowMask
|
299 WMClosableWindowMask
| WMMiniaturizableWindowMask
)) {
300 wwin
->client_flags
.no_titlebar
= 0;
302 wwin
->client_flags
.no_titlebar
=
303 ((gs_hints
->window_style
& WMTitledWindowMask
) ? 0 : 1);
308 /* setup the defaults */
309 wwin
->client_flags
.no_border
= 0;
310 wwin
->client_flags
.no_titlebar
= 0;
311 wwin
->client_flags
.no_closable
= 0;
312 wwin
->client_flags
.no_miniaturizable
= 0;
313 wwin
->client_flags
.no_resizable
= 0;
314 wwin
->client_flags
.no_close_button
= 0;
315 wwin
->client_flags
.no_miniaturize_button
= 0;
316 wwin
->client_flags
.no_resizebar
= 0;
318 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
319 wwin
->client_flags
.no_appicon
= 1;
324 void wWindowCheckAttributeSanity(WWindow
* wwin
, WWindowAttributes
* wflags
, WWindowAttributes
* mask
)
326 if (wflags
->no_appicon
&& mask
->no_appicon
)
327 wflags
->emulate_appicon
= 0;
329 if (wwin
->main_window
!= None
) {
330 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
331 if (wapp
&& !wapp
->flags
.emulated
)
332 wflags
->emulate_appicon
= 0;
335 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
336 wflags
->emulate_appicon
= 0;
338 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
342 void wWindowSetupInitialAttributes(WWindow
* wwin
, int *level
, int *workspace
)
344 WScreen
*scr
= wwin
->screen_ptr
;
346 /* sets global default stuff */
347 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
, &wwin
->client_flags
, NULL
, True
);
349 * Decoration setting is done in this precedence (lower to higher)
350 * - use global default in the resource database
351 * - guess some settings
352 * - use GNUstep/external window attributes
353 * - set hints specified for the app in the resource DB
356 WSETUFLAG(wwin
, broken_close
, 0);
358 if (wwin
->protocols
.DELETE_WINDOW
)
359 WSETUFLAG(wwin
, kill_close
, 0);
361 WSETUFLAG(wwin
, kill_close
, 1);
363 /* transients can't be iconified or maximized */
364 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
365 WSETUFLAG(wwin
, no_miniaturizable
, 1);
366 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
369 /* if the window can't be resized, remove the resizebar */
370 if (wwin
->normal_hints
->flags
& (PMinSize
| PMaxSize
)
371 && (wwin
->normal_hints
->min_width
== wwin
->normal_hints
->max_width
)
372 && (wwin
->normal_hints
->min_height
== wwin
->normal_hints
->max_height
)) {
373 WSETUFLAG(wwin
, no_resizable
, 1);
374 WSETUFLAG(wwin
, no_resizebar
, 1);
377 /* set GNUstep window attributes */
378 if (wwin
->wm_gnustep_attr
) {
379 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
381 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
383 *level
= wwin
->wm_gnustep_attr
->window_level
;
385 * INT_MIN is the only illegal window level.
387 if (*level
== INT_MIN
)
388 *level
= INT_MIN
+ 1;
391 *level
= WMNormalLevel
;
394 int tmp_workspace
= -1;
395 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
401 wMWMCheckClientHints(wwin
);
402 #endif /* MWM_HINTS */
406 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
409 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
410 * have INT_MIN that means that no window level was requested. -Dan
412 if (tmp_level
== INT_MIN
) {
413 if (WFLAGP(wwin
, floating
))
414 *level
= WMFloatingLevel
;
415 else if (WFLAGP(wwin
, sunken
))
416 *level
= WMSunkenLevel
;
418 *level
= WMNormalLevel
;
423 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
424 WWindow
*transientOwner
= wWindowFor(wwin
->transient_for
);
425 if (transientOwner
) {
426 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
427 if (ownerLevel
> *level
)
432 if (tmp_workspace
>= 0) {
433 *workspace
= tmp_workspace
% scr
->workspace_count
;
438 * Set attributes specified only for that window/class.
439 * This might do duplicate work with the 1st wDefaultFillAttributes().
441 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
442 &wwin
->user_flags
, &wwin
->defined_user_flags
, False
);
444 * Sanity checks for attributes that depend on other attributes
446 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
447 wwin
->user_flags
.emulate_appicon
= 0;
449 if (wwin
->main_window
!= None
) {
450 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
451 if (wapp
&& !wapp
->flags
.emulated
)
452 wwin
->user_flags
.emulate_appicon
= 0;
455 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
)
456 wwin
->user_flags
.emulate_appicon
= 0;
458 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
459 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
460 wwin
->user_flags
.sunken
= 0;
462 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
464 /* windows that have takefocus=False shouldn't take focus at all */
465 if (wwin
->focus_mode
== WFM_NO_INPUT
) {
466 wwin
->client_flags
.no_focusable
= 1;
470 Bool
wWindowCanReceiveFocus(WWindow
* wwin
)
472 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
474 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
476 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
482 Bool
wWindowObscuresWindow(WWindow
* wwin
, WWindow
* obscured
)
486 w1
= wwin
->frame
->core
->width
;
487 h1
= wwin
->frame
->core
->height
;
488 w2
= obscured
->frame
->core
->width
;
489 h2
= obscured
->frame
->core
->height
;
491 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
492 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
495 if (wwin
->frame_x
+ w1
< obscured
->frame_x
496 || wwin
->frame_y
+ h1
< obscured
->frame_y
497 || wwin
->frame_x
> obscured
->frame_x
+ w2
|| wwin
->frame_y
> obscured
->frame_y
+ h2
) {
504 static void fixLeaderProperties(WWindow
* wwin
)
506 XClassHint
*classHint
;
507 XWMHints
*hints
, *clientHints
;
508 Window leaders
[2], window
;
509 char **argv
, *command
;
513 classHint
= XAllocClassHint();
514 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
515 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
517 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
522 leaders
[0] = wwin
->client_leader
;
523 leaders
[1] = wwin
->group_id
;
526 command
= GetCommandForWindow(wwin
->client_win
);
528 /* command already set. nothing to do. */
531 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
535 for (i
= 0; i
< 2; i
++) {
538 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
539 classHint
->res_name
= wwin
->wm_instance
;
540 classHint
->res_class
= wwin
->wm_class
;
541 XSetClassHint(dpy
, window
, classHint
);
543 hints
= XGetWMHints(dpy
, window
);
546 } else if (clientHints
) {
547 /* set window group leader to self */
548 clientHints
->window_group
= window
;
549 clientHints
->flags
|= WindowGroupHint
;
550 XSetWMHints(dpy
, window
, clientHints
);
554 command
= GetCommandForWindow(window
);
556 /* command already set. nothing to do. */
559 XSetCommand(dpy
, window
, argv
, argc
);
574 static Window
createFakeWindowGroupLeader(WScreen
* scr
, Window win
, char *instance
, char *class)
576 XClassHint
*classHint
;
582 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
584 classHint
= XAllocClassHint();
585 classHint
->res_name
= instance
;
586 classHint
->res_class
= class;
587 XSetClassHint(dpy
, leader
, classHint
);
590 /* inherit these from the original leader if available */
591 hints
= XGetWMHints(dpy
, win
);
593 hints
= XAllocWMHints();
596 /* set window group leader to self */
597 hints
->window_group
= leader
;
598 hints
->flags
|= WindowGroupHint
;
599 XSetWMHints(dpy
, leader
, hints
);
602 if (XGetCommand(dpy
, win
, &argv
, &argc
) != 0 && argc
> 0) {
603 XSetCommand(dpy
, leader
, argv
, argc
);
604 XFreeStringList(argv
);
610 static int matchIdentifier(void *item
, void *cdata
)
612 return (strcmp(((WFakeGroupLeader
*) item
)->identifier
, (char *)cdata
) == 0);
616 *----------------------------------------------------------------
618 * reparents the window and allocates a descriptor for it.
619 * Window manager hints and other hints are fetched to configure
620 * the window decoration attributes and others. User preferences
621 * for the window are used if available, to configure window
622 * decorations and some behaviour.
623 * If in startup, windows that are override redirect,
624 * unmapped and never were managed and are Withdrawn are not
628 * the new window descriptor
631 * The window is reparented and appropriate notification
632 * is done to the client. Input mask for the window is setup.
633 * The window descriptor is also associated with various window
634 * contexts and inserted in the head of the window list.
635 * Event handler contexts are associated for some objects
636 * (buttons, titlebar and resizebar)
638 *----------------------------------------------------------------
640 WWindow
*wManageWindow(WScreen
* scr
, Window window
)
644 unsigned width
, height
;
645 XWindowAttributes wattribs
;
646 XSetWindowAttributes attribs
;
647 WWindowState
*win_state
;
648 WWindow
*transientOwner
= NULL
;
654 Bool withdraw
= False
;
658 /* XGrabServer(dpy); */
660 /* make sure the window is still there */
661 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
666 /* if it's an override-redirect, ignore it */
667 if (wattribs
.override_redirect
) {
672 wm_state
= PropGetWindowState(window
);
674 /* if it's startup and the window is unmapped, don't manage it */
675 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
== IsUnmapped
) {
680 wwin
= wWindowCreate();
682 title
= wNETWMGetWindowName(window
);
684 wwin
->flags
.net_has_title
= 1;
685 if (!title
&& !wFetchName(dpy
, window
, &title
))
688 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
691 printf("managing window %x\n", (unsigned)window
);
695 if (wShapeSupported
) {
700 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
701 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
702 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
703 wwin
->flags
.shaped
= b_shaped
;
708 *--------------------------------------------------
710 * Get hints and other information in properties
712 *--------------------------------------------------
714 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
716 /* setup descriptor */
717 wwin
->client_win
= window
;
718 wwin
->screen_ptr
= scr
;
720 wwin
->old_border_width
= wattribs
.border_width
;
722 wwin
->event_mask
= CLIENT_EVENTS
;
723 attribs
.event_mask
= CLIENT_EVENTS
;
724 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
725 attribs
.save_under
= False
;
726 XChangeWindowAttributes(dpy
, window
, CWEventMask
| CWDontPropagate
| CWSaveUnder
, &attribs
);
727 XSetWindowBorderWidth(dpy
, window
, 0);
729 /* get hints from GNUstep app */
730 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
731 wwin
->flags
.is_gnustep
= 1;
733 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
734 wwin
->wm_gnustep_attr
= NULL
;
737 wwin
->client_leader
= PropGetClientLeader(window
);
738 if (wwin
->client_leader
!= None
)
739 wwin
->main_window
= wwin
->client_leader
;
741 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
743 if (wwin
->wm_hints
) {
744 if (wwin
->wm_hints
->flags
& StateHint
) {
746 if (wwin
->wm_hints
->initial_state
== IconicState
) {
748 wwin
->flags
.miniaturized
= 1;
750 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
756 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
757 wwin
->group_id
= wwin
->wm_hints
->window_group
;
758 /* window_group has priority over CLIENT_LEADER */
759 wwin
->main_window
= wwin
->group_id
;
761 wwin
->group_id
= None
;
764 if (wwin
->wm_hints
->flags
& UrgencyHint
)
765 wwin
->flags
.urgent
= 1;
767 wwin
->group_id
= None
;
770 PropGetProtocols(window
, &wwin
->protocols
);
772 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
773 wwin
->transient_for
= None
;
775 if (wwin
->transient_for
== None
|| wwin
->transient_for
== window
) {
776 wwin
->transient_for
= scr
->root_win
;
778 transientOwner
= wWindowFor(wwin
->transient_for
);
779 if (transientOwner
&& transientOwner
->main_window
!= None
) {
780 wwin
->main_window
= transientOwner
->main_window
;
782 wwin->main_window = None;
787 /* guess the focus mode */
788 wwin
->focus_mode
= getFocusMode(wwin
);
790 /* get geometry stuff */
791 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
793 /* printf("wManageWindow: %d %d %d %d\n", x, y, width, height); */
795 /* get colormap windows */
796 GetColormapWindows(wwin
);
799 *--------------------------------------------------
801 * Setup the decoration/window attributes and
804 *--------------------------------------------------
807 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
809 /* Make broken apps behave as a nice app. */
810 if (WFLAGP(wwin
, emulate_appicon
)) {
811 wwin
->main_window
= wwin
->client_win
;
814 fixLeaderProperties(wwin
);
816 wwin
->orig_main_window
= wwin
->main_window
;
818 if (wwin
->flags
.is_gnustep
) {
819 WSETUFLAG(wwin
, shared_appicon
, 0);
822 if (wwin
->main_window
) {
823 extern Atom _XA_WINDOWMAKER_MENU
;
824 XTextProperty text_prop
;
826 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
, _XA_WINDOWMAKER_MENU
)) {
827 WSETUFLAG(wwin
, shared_appicon
, 0);
831 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
832 char *buffer
, *instance
, *class;
833 WFakeGroupLeader
*fPtr
;
836 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
838 /* // only enter here if PropGetWMClass() succeds */
839 PropGetWMClass(wwin
->main_window
, &class, &instance
);
840 buffer
= StrConcatDot(instance
, class);
842 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void *)buffer
);
843 if (index
!= WANotFound
) {
844 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
845 if (fPtr
->retainCount
== 0) {
846 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
851 if (fPtr
->origLeader
== None
) {
853 if (ADEQUATE(wwin
->group_id
)) {
855 fPtr
->origLeader
= wwin
->group_id
;
856 } else if (ADEQUATE(wwin
->client_leader
)) {
858 fPtr
->origLeader
= wwin
->client_leader
;
859 } else if (ADEQUATE(wwin
->main_window
)) {
861 fPtr
->origLeader
= wwin
->main_window
;
864 if (ADEQUATE(wwin
->main_window
)) {
866 fPtr
->origLeader
= wwin
->main_window
;
870 wwin
->fake_group
= fPtr
;
871 /*wwin->group_id = fPtr->leader; */
872 wwin
->main_window
= fPtr
->leader
;
875 fPtr
= (WFakeGroupLeader
*) wmalloc(sizeof(WFakeGroupLeader
));
877 fPtr
->identifier
= buffer
;
878 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
, instance
, class);
879 fPtr
->origLeader
= None
;
880 fPtr
->retainCount
= 1;
882 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
885 if (ADEQUATE(wwin
->group_id
)) {
887 fPtr
->origLeader
= wwin
->group_id
;
888 } else if (ADEQUATE(wwin
->client_leader
)) {
890 fPtr
->origLeader
= wwin
->client_leader
;
891 } else if (ADEQUATE(wwin
->main_window
)) {
893 fPtr
->origLeader
= wwin
->main_window
;
896 if (ADEQUATE(wwin
->main_window
)) {
898 fPtr
->origLeader
= wwin
->main_window
;
901 wwin
->fake_group
= fPtr
;
902 /*wwin->group_id = fPtr->leader; */
903 wwin
->main_window
= fPtr
->leader
;
915 *------------------------------------------------------------
917 * Setup the initial state of the window
919 *------------------------------------------------------------
922 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
923 wwin
->flags
.miniaturized
= 1;
926 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
)) {
927 wwin
->flags
.maximized
= MAX_VERTICAL
| MAX_HORIZONTAL
;
930 wNETWMCheckInitialClientState(wwin
);
933 /* apply previous state if it exists and we're in startup */
934 if (scr
->flags
.startup
&& wm_state
>= 0) {
936 if (wm_state
== IconicState
) {
938 wwin
->flags
.miniaturized
= 1;
940 } else if (wm_state
== WithdrawnState
) {
946 /* if there is a saved state (from file), restore it */
948 if (wwin
->main_window
!= None
/* && wwin->main_window!=window */ ) {
949 win_state
= (WWindowState
*) wWindowGetSavedState(wwin
->main_window
);
951 win_state
= (WWindowState
*) wWindowGetSavedState(window
);
953 if (win_state
&& !withdraw
) {
955 if (win_state
->state
->hidden
> 0)
956 wwin
->flags
.hidden
= win_state
->state
->hidden
;
958 if (win_state
->state
->shaded
> 0 && !WFLAGP(wwin
, no_shadeable
))
959 wwin
->flags
.shaded
= win_state
->state
->shaded
;
961 if (win_state
->state
->miniaturized
> 0 && !WFLAGP(wwin
, no_miniaturizable
)) {
962 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
965 if (!IS_OMNIPRESENT(wwin
)) {
966 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
968 if (w
< 0 || w
>= scr
->workspace_count
) {
969 workspace
= win_state
->state
->workspace
;
970 if (workspace
>= scr
->workspace_count
)
971 workspace
= scr
->current_workspace
;
976 workspace
= scr
->current_workspace
;
980 /* if we're restarting, restore saved state (from hints).
981 * This will overwrite previous */
985 if (getSavedState(window
, &wstate
)) {
986 wwin
->flags
.shaded
= wstate
->shaded
;
987 wwin
->flags
.hidden
= wstate
->hidden
;
988 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
989 wwin
->flags
.maximized
= wstate
->maximized
;
990 if (wwin
->flags
.maximized
) {
991 wwin
->old_geometry
.x
= wstate
->x
;
992 wwin
->old_geometry
.y
= wstate
->y
;
993 wwin
->old_geometry
.width
= wstate
->w
;
994 wwin
->old_geometry
.height
= wstate
->h
;
997 workspace
= wstate
->workspace
;
1002 /* restore window shortcut */
1003 if (wstate
!= NULL
|| win_state
!= NULL
) {
1006 if (win_state
!= NULL
)
1007 mask
= win_state
->state
->window_shortcuts
;
1009 if (wstate
!= NULL
&& mask
== 0)
1010 mask
= wstate
->window_shortcuts
;
1015 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
1016 if (mask
& (1 << i
)) {
1017 if (!scr
->shortcutWindows
[i
])
1018 scr
->shortcutWindows
[i
] = WMCreateArray(4);
1020 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
1025 if (wstate
!= NULL
) {
1030 /* don't let transients start miniaturized if their owners are not */
1031 if (transientOwner
&& !transientOwner
->flags
.miniaturized
&& wwin
->flags
.miniaturized
&& !withdraw
) {
1032 wwin
->flags
.miniaturized
= 0;
1034 wwin
->wm_hints
->initial_state
= NormalState
;
1037 /* set workspace on which the window starts */
1038 if (workspace
>= 0) {
1039 if (workspace
> scr
->workspace_count
- 1) {
1040 workspace
= workspace
% scr
->workspace_count
;
1045 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
1047 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1052 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1054 workspace
= transientOwner
->frame
->workspace
;
1058 workspace
= scr
->current_workspace
;
1063 /* setup window geometry */
1064 if (win_state
&& win_state
->state
->w
> 0) {
1065 width
= win_state
->state
->w
;
1066 height
= win_state
->state
->h
;
1068 wWindowConstrainSize(wwin
, &width
, &height
);
1070 /* do not ask for window placement if the window is
1071 * transient, during startup, if the initial workspace is another one
1072 * or if the window wants to start iconic.
1073 * If geometry was saved, restore it. */
1075 Bool dontBring
= False
;
1077 if (win_state
&& win_state
->state
->w
> 0) {
1078 x
= win_state
->state
->x
;
1079 y
= win_state
->state
->y
;
1080 } else if ((wwin
->transient_for
== None
|| wPreferences
.window_placement
!= WPM_MANUAL
)
1081 && !scr
->flags
.startup
1082 && workspace
== scr
->current_workspace
1083 && !wwin
->flags
.miniaturized
1084 && !wwin
->flags
.maximized
&& !(wwin
->normal_hints
->flags
& (USPosition
| PPosition
))) {
1086 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1087 int offs
= WMAX(20, 2 * transientOwner
->frame
->top_width
);
1091 x
= transientOwner
->frame_x
+
1092 abs((transientOwner
->frame
->core
->width
- width
) / 2) + offs
;
1093 y
= transientOwner
->frame_y
+
1094 abs((transientOwner
->frame
->core
->height
- height
) / 3) + offs
;
1097 * limit transient windows to be inside their parent's head
1099 rect
.pos
.x
= transientOwner
->frame_x
;
1100 rect
.pos
.y
= transientOwner
->frame_y
;
1101 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1102 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1104 head
= wGetHeadForRect(scr
, rect
);
1105 rect
= wGetRectForHead(scr
, head
);
1109 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1110 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1114 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1115 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1118 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1120 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1123 } else if (scr
->xine_info
.count
&& (wwin
->normal_hints
->flags
& PPosition
)) {
1129 * Make spash screens come out in the center of a head
1130 * trouble is that most splashies never get here
1131 * they are managed trough atoms but god knows where.
1132 * Dan, do you know ? -peter
1134 * Most of them are not managed, they have set
1135 * OverrideRedirect, which means we can't do anything about
1139 printf("xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
) / 2);
1140 printf("xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
) / 2);
1142 if ((unsigned)(x
+ (width
- scr
->scr_width
) / 2 + 10) < 20 &&
1143 (unsigned)(y
+ (height
- scr
->scr_height
) / 2 + 10) < 20) {
1151 * xinerama checks for: across head and dead space
1155 rect
.size
.width
= width
;
1156 rect
.size
.height
= height
;
1158 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1160 if (flags
& XFLAG_DEAD
)
1163 if (flags
& XFLAG_MULTIPLE
)
1167 switch (reposition
) {
1169 head
= wGetHeadForPointerLocation(scr
);
1170 rect
= wGetRectForHead(scr
, head
);
1172 x
= rect
.pos
.x
+ (x
* rect
.size
.width
) / scr
->scr_width
;
1173 y
= rect
.pos
.y
+ (y
* rect
.size
.height
) / scr
->scr_height
;
1177 rect
= wGetRectForHead(scr
, head
);
1181 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1182 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1186 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1187 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1196 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1197 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1201 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1204 if (wwin
->flags
.urgent
) {
1205 if (!IS_OMNIPRESENT(wwin
))
1206 wwin
->flags
.omnipresent
^= 1;
1210 *--------------------------------------------------
1212 * Create frame, borders and do reparenting
1214 *--------------------------------------------------
1216 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1217 #ifdef XKB_BUTTON_HINT
1218 if (wPreferences
.modelock
)
1219 foo
|= WFF_LANGUAGE_BUTTON
;
1221 if (HAS_TITLEBAR(wwin
))
1222 foo
|= WFF_TITLEBAR
;
1223 if (HAS_RESIZEBAR(wwin
))
1224 foo
|= WFF_RESIZEBAR
;
1225 if (HAS_BORDER(wwin
))
1228 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1229 x
, y
, width
, height
,
1230 &wPreferences
.window_title_clearance
, foo
,
1231 scr
->window_title_texture
,
1232 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1234 wwin
->frame
->flags
.is_client_window_frame
= 1;
1235 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1237 /* setup button images */
1238 wWindowUpdateButtonImages(wwin
);
1240 /* hide unused buttons */
1242 if (WFLAGP(wwin
, no_close_button
))
1243 foo
|= WFF_RIGHT_BUTTON
;
1244 if (WFLAGP(wwin
, no_miniaturize_button
))
1245 foo
|= WFF_LEFT_BUTTON
;
1246 #ifdef XKB_BUTTON_HINT
1247 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1248 foo
|= WFF_LANGUAGE_BUTTON
;
1251 wFrameWindowHideButton(wwin
->frame
, foo
);
1253 wwin
->frame
->child
= wwin
;
1255 wwin
->frame
->workspace
= workspace
;
1257 wwin
->frame
->on_click_left
= windowIconifyClick
;
1258 #ifdef XKB_BUTTON_HINT
1259 if (wPreferences
.modelock
)
1260 wwin
->frame
->on_click_language
= windowLanguageClick
;
1263 wwin
->frame
->on_click_right
= windowCloseClick
;
1264 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1266 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1267 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1269 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1271 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1273 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1275 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1280 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1282 /* if gravity is to the south, account for the border sizes */
1284 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1288 * wWindowConfigure() will init the client window's size
1289 * (wwin->client.{width,height}) and all other geometry
1290 * related variables (frame_x,frame_y)
1292 wWindowConfigure(wwin
, x
, y
, width
, height
);
1294 /* to make sure the window receives it's new position after reparenting */
1295 wWindowSynthConfigureNotify(wwin
);
1298 *--------------------------------------------------
1300 * Setup descriptors and save window to internal
1303 *--------------------------------------------------
1306 if (wwin
->main_window
!= None
) {
1310 /* Leader windows do not necessary set themselves as leaders.
1311 * If this is the case, point the leader of this window to
1313 leader
= wWindowFor(wwin
->main_window
);
1314 if (leader
&& leader
->main_window
== None
) {
1315 leader
->main_window
= leader
->client_win
;
1317 app
= wApplicationCreate(wwin
);
1319 app
->last_workspace
= workspace
;
1322 * Do application specific stuff, like setting application
1326 if (wwin
->flags
.hidden
) {
1327 /* if the window was set to hidden because it was hidden
1328 * in a previous incarnation and that state was restored */
1329 app
->flags
.hidden
= 1;
1330 } else if (app
->flags
.hidden
) {
1331 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1332 wwin
->flags
.hidden
= 1;
1334 wUnhideApplication(app
, False
, False
);
1341 /* setup the frame descriptor */
1342 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1343 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1344 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1346 /* don't let windows go away if we die */
1347 XAddToSaveSet(dpy
, window
);
1349 XLowerWindow(dpy
, window
);
1351 /* if window is in this workspace and should be mapped, then map it */
1352 if (!wwin
->flags
.miniaturized
&& (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1353 && !wwin
->flags
.hidden
&& !withdraw
) {
1355 /* The following "if" is to avoid crashing of clients that expect
1356 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1357 * after the return from this function.
1359 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1360 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1362 wClientSetState(wwin
, NormalState
, None
);
1366 /* if not auto focus, then map the window under the currently
1368 #define _WIDTH(w) (w)->frame->core->width
1369 #define _HEIGHT(w) (w)->frame->core->height
1370 if (!wPreferences
.auto_focus
&& scr
->focused_window
1371 && !scr
->flags
.startup
&& !transientOwner
&& ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1373 (_WIDTH(scr
->focused_window
) * 5) / 3
1375 (_HEIGHT(scr
->focused_window
) * 5) / 3)
1376 && WINDOW_LEVEL(scr
->focused_window
) ==
1378 || wwin
->flags
.maximized
)) {
1379 MoveInStackListUnder(scr
->focused_window
->frame
->core
, wwin
->frame
->core
);
1386 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1387 && !scr
->flags
.startup
&& (wwin
->transient_for
== None
|| wwin
->transient_for
== scr
->root_win
)
1389 * The brain damaged idiotic non-click to focus modes will
1390 * have trouble with this because:
1392 * 1. window is created and mapped by the client
1393 * 2. window is mapped by wmaker in small size
1394 * 3. window is animated to grow to normal size
1395 * 4. this function returns to normal event loop
1396 * 5. eventually, the EnterNotify event that would trigger
1397 * the window focusing (if the mouse is over that window)
1398 * will be processed by wmaker.
1399 * But since this event will be rather delayed
1400 * (step 3 has a large delay) the time when the event ocurred
1401 * and when it is processed, the client that owns that window
1402 * will reject the XSetInputFocus() for it.
1404 && (wPreferences
.focus_mode
== WKF_CLICK
|| wPreferences
.auto_focus
)) {
1405 DoWindowBirth(wwin
);
1411 /* setup stacking descriptor */
1412 if (transientOwner
) {
1413 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1415 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1418 if (!scr
->focused_window
) {
1419 /* first window on the list */
1422 scr
->focused_window
= wwin
;
1426 /* add window at beginning of focus window list */
1427 tmp
= scr
->focused_window
;
1435 /* raise is set to true if we un-hid the app when this window was born.
1436 * we raise, else old windows of this app will be above this new one. */
1438 wRaiseFrame(wwin
->frame
->core
);
1441 /* Update name must come after WApplication stuff is done */
1442 wWindowUpdateName(wwin
, title
);
1449 *--------------------------------------------------
1451 * Final preparations before window is ready to go
1453 *--------------------------------------------------
1456 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1458 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
&& !wwin
->flags
.hidden
) {
1459 if (((transientOwner
&& transientOwner
->flags
.focused
)
1460 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1461 wSetFocusTo(scr
, wwin
);
1463 wWindowResetMouseGrabs(wwin
);
1465 if (!WFLAGP(wwin
, no_bind_keys
)) {
1466 wWindowSetKeyGrabs(wwin
);
1469 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1471 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1474 *------------------------------------------------------------
1475 * Setup Notification Observers
1476 *------------------------------------------------------------
1478 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1481 *--------------------------------------------------
1483 * Cleanup temporary stuff
1485 *--------------------------------------------------
1489 wWindowDeleteSavedState(win_state
);
1491 /* If the window must be withdrawed, then do it now.
1492 * Must do some optimization, 'though */
1494 wwin
->flags
.mapped
= 0;
1495 wClientSetState(wwin
, WithdrawnState
, None
);
1496 wUnmanageWindow(wwin
, True
, False
);
1503 WWindow
*wManageInternalWindow(WScreen
* scr
, Window window
, Window owner
,
1504 char *title
, int x
, int y
, int width
, int height
)
1509 wwin
= wWindowCreate();
1511 WMAddNotificationObserver(appearanceObserver
, wwin
, WNWindowAppearanceSettingsChanged
, wwin
);
1513 wwin
->flags
.internal_window
= 1;
1515 WSETUFLAG(wwin
, omnipresent
, 1);
1516 WSETUFLAG(wwin
, no_shadeable
, 1);
1517 WSETUFLAG(wwin
, no_resizable
, 1);
1518 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1520 wwin
->focus_mode
= WFM_PASSIVE
;
1522 wwin
->client_win
= window
;
1523 wwin
->screen_ptr
= scr
;
1525 wwin
->transient_for
= owner
;
1529 wwin
->client
.width
= width
;
1530 wwin
->client
.height
= height
;
1532 wwin
->frame_x
= wwin
->client
.x
;
1533 wwin
->frame_y
= wwin
->client
.y
;
1535 foo
= WFF_RIGHT_BUTTON
| WFF_BORDER
;
1536 foo
|= WFF_TITLEBAR
;
1537 #ifdef XKB_BUTTON_HINT
1538 foo
|= WFF_LANGUAGE_BUTTON
;
1541 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1542 wwin
->frame_x
, wwin
->frame_y
,
1544 &wPreferences
.window_title_clearance
, foo
,
1545 scr
->window_title_texture
,
1546 scr
->resizebar_texture
, scr
->window_title_color
, &scr
->title_font
);
1548 XSaveContext(dpy
, window
, wWinContext
, (XPointer
) & wwin
->client_descriptor
);
1550 wwin
->frame
->flags
.is_client_window_frame
= 1;
1551 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1553 wFrameWindowChangeTitle(wwin
->frame
, title
);
1555 /* setup button images */
1556 wWindowUpdateButtonImages(wwin
);
1559 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1561 wwin
->frame
->child
= wwin
;
1563 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1565 #ifdef XKB_BUTTON_HINT
1566 if (wPreferences
.modelock
)
1567 wwin
->frame
->on_click_language
= windowLanguageClick
;
1570 wwin
->frame
->on_click_right
= windowCloseClick
;
1572 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1573 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1575 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1577 wwin
->client
.y
+= wwin
->frame
->top_width
;
1578 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
, 0, wwin
->frame
->top_width
);
1580 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
, wwin
->client
.width
, wwin
->client
.height
);
1582 /* setup the frame descriptor */
1583 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1584 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1585 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1587 XLowerWindow(dpy
, window
);
1588 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1590 /* setup stacking descriptor */
1591 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= scr
->root_win
) {
1593 tmp
= wWindowFor(wwin
->transient_for
);
1595 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1597 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1600 if (!scr
->focused_window
) {
1601 /* first window on the list */
1604 scr
->focused_window
= wwin
;
1608 /* add window at beginning of focus window list */
1609 tmp
= scr
->focused_window
;
1617 if (wwin
->flags
.is_gnustep
== 0)
1618 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1620 /* if (wPreferences.auto_focus) */
1621 wSetFocusTo(scr
, wwin
);
1623 wWindowResetMouseGrabs(wwin
);
1625 wWindowSetKeyGrabs(wwin
);
1631 *----------------------------------------------------------------------
1633 * Removes the frame window from a window and destroys all data
1634 * related to it. The window will be reparented back to the root window
1635 * if restore is True.
1638 * Everything related to the window is destroyed and the window
1639 * is removed from the window lists. Focus is set to the previous on the
1641 *----------------------------------------------------------------------
1643 void wUnmanageWindow(WWindow
* wwin
, Bool restore
, Bool destroyed
)
1645 WCoreWindow
*frame
= wwin
->frame
->core
;
1646 WWindow
*owner
= NULL
;
1647 WWindow
*newFocusedWindow
= NULL
;
1649 WScreen
*scr
= wwin
->screen_ptr
;
1651 /* First close attribute editor window if open */
1652 if (wwin
->flags
.inspector_open
) {
1653 wCloseInspectorForWindow(wwin
);
1656 /* Close window menu if it's open for this window */
1657 if (wwin
->flags
.menu_open_for_me
) {
1658 CloseWindowMenu(scr
);
1662 if (!wwin
->flags
.internal_window
)
1663 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1665 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1667 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1668 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1671 XUnmapWindow(dpy
, frame
->window
);
1673 XUnmapWindow(dpy
, wwin
->client_win
);
1675 /* deselect window */
1676 wSelectWindow(wwin
, False
);
1678 /* remove all pending events on window */
1679 /* I think this only matters for autoraise */
1680 if (wPreferences
.raise_delay
)
1681 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1685 /* reparent the window back to the root */
1687 wClientRestore(wwin
);
1689 if (wwin
->transient_for
!= scr
->root_win
) {
1690 owner
= wWindowFor(wwin
->transient_for
);
1692 if (!owner
->flags
.semi_focused
) {
1695 owner
->flags
.semi_focused
= 0;
1700 wasFocused
= wwin
->flags
.focused
;
1702 /* remove from window focus list */
1703 if (!wwin
->prev
&& !wwin
->next
) {
1704 /* was the only window */
1705 scr
->focused_window
= NULL
;
1706 newFocusedWindow
= NULL
;
1711 wwin
->prev
->next
= wwin
->next
;
1713 wwin
->next
->prev
= wwin
->prev
;
1715 scr
->focused_window
= wwin
->prev
;
1716 scr
->focused_window
->next
= NULL
;
1719 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1721 /* if in click to focus mode and the window
1722 * was a transient, focus the owner window
1725 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1726 tmp
= wWindowFor(wwin
->transient_for
);
1727 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1731 /* otherwise, focus the next one in the focus list */
1733 tmp
= scr
->focused_window
;
1734 while (tmp
) { /* look for one in the window list first */
1735 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1736 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1740 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1741 tmp
= scr
->focused_window
;
1743 if (!WFLAGP(tmp
, no_focusable
)
1744 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1751 newFocusedWindow
= tmp
;
1753 } else if (wPreferences
.focus_mode
== WKF_SLOPPY
) {
1758 /* This is to let the root window get the keyboard input
1759 * if Sloppy focus mode and no other window get focus.
1760 * This way keybindings will not freeze.
1763 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
))
1764 tmp
= wWindowFor(win
);
1767 newFocusedWindow
= tmp
;
1769 newFocusedWindow
= NULL
;
1773 if (!wwin
->flags
.internal_window
) {
1774 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1777 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
, (unsigned)frame
->window
);
1781 if (newFocusedWindow
!= owner
&& owner
) {
1782 if (wwin
->flags
.is_gnustep
== 0)
1783 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1785 wSetFocusTo(scr
, newFocusedWindow
);
1787 wWindowDestroy(wwin
);
1791 void wWindowMap(WWindow
* wwin
)
1793 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1794 if (!wwin
->flags
.shaded
) {
1795 /* window will be remapped when getting MapNotify */
1796 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1797 XMapWindow(dpy
, wwin
->client_win
);
1798 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1800 wwin
->flags
.mapped
= 1;
1804 void wWindowUnmap(WWindow
* wwin
)
1806 wwin
->flags
.mapped
= 0;
1808 /* prevent window withdrawal when getting UnmapNotify */
1809 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
1810 XUnmapWindow(dpy
, wwin
->client_win
);
1811 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1813 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1816 void wWindowFocus(WWindow
* wwin
, WWindow
* owin
)
1821 #ifdef KEEP_XKB_LOCK_STATUS
1822 if (wPreferences
.modelock
) {
1823 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1825 #endif /* KEEP_XKB_LOCK_STATUS */
1827 wwin
->flags
.semi_focused
= 0;
1829 if (wwin
->flags
.is_gnustep
== 0)
1830 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1832 wwin
->flags
.focused
= 1;
1834 wWindowResetMouseGrabs(wwin
);
1836 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)True
);
1838 if (owin
== wwin
|| !owin
)
1841 nowner
= wWindowFor(wwin
->transient_for
);
1843 /* new window is a transient for the old window */
1844 if (nowner
== owin
) {
1845 owin
->flags
.semi_focused
= 1;
1846 wWindowUnfocus(nowner
);
1850 oowner
= wWindowFor(owin
->transient_for
);
1852 /* new window is owner of old window */
1853 if (wwin
== oowner
) {
1854 wWindowUnfocus(owin
);
1859 wWindowUnfocus(owin
);
1863 /* new window has same owner of old window */
1864 if (oowner
== nowner
) {
1865 /* prevent unfocusing of owner */
1866 oowner
->flags
.semi_focused
= 0;
1867 wWindowUnfocus(owin
);
1868 oowner
->flags
.semi_focused
= 1;
1873 /* nowner != NULL && oowner != nowner */
1874 nowner
->flags
.semi_focused
= 1;
1875 wWindowUnfocus(nowner
);
1876 wWindowUnfocus(owin
);
1879 void wWindowUnfocus(WWindow
* wwin
)
1881 CloseWindowMenu(wwin
->screen_ptr
);
1883 if (wwin
->flags
.is_gnustep
== 0)
1884 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
? WS_PFOCUSED
: WS_UNFOCUSED
);
1886 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1888 owner
= wWindowFor(wwin
->transient_for
);
1889 if (owner
&& owner
->flags
.semi_focused
) {
1890 owner
->flags
.semi_focused
= 0;
1891 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1892 wWindowUnfocus(owner
);
1893 wFrameWindowPaint(owner
->frame
);
1897 wwin
->flags
.focused
= 0;
1899 wWindowResetMouseGrabs(wwin
);
1901 WMPostNotificationName(WMNChangedFocus
, wwin
, (void *)False
);
1904 void wWindowUpdateName(WWindow
* wwin
, char *newTitle
)
1911 wwin
->flags
.wm_name_changed
= 1;
1914 /* the hint was removed */
1915 title
= DEF_WINDOW_TITLE
;
1920 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1921 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1926 *----------------------------------------------------------------------
1928 * wWindowConstrainSize--
1929 * Constrains size for the client window, taking the maximal size,
1930 * window resize increments and other size hints into account.
1933 * The closest size to what was given that the client window can
1936 *----------------------------------------------------------------------
1938 void wWindowConstrainSize(WWindow
* wwin
, unsigned int *nwidth
, unsigned int *nheight
)
1940 int width
= (int)*nwidth
;
1941 int height
= (int)*nheight
;
1944 int minW
= 1, minH
= 1;
1945 int maxW
= wwin
->screen_ptr
->scr_width
* 2;
1946 int maxH
= wwin
->screen_ptr
->scr_height
* 2;
1947 int minAX
= -1, minAY
= -1;
1948 int maxAX
= -1, maxAY
= -1;
1952 if (wwin
->normal_hints
) {
1953 winc
= wwin
->normal_hints
->width_inc
;
1954 hinc
= wwin
->normal_hints
->height_inc
;
1955 minW
= wwin
->normal_hints
->min_width
;
1956 minH
= wwin
->normal_hints
->min_height
;
1957 maxW
= wwin
->normal_hints
->max_width
;
1958 maxH
= wwin
->normal_hints
->max_height
;
1959 if (wwin
->normal_hints
->flags
& PAspect
) {
1960 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1961 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1962 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1963 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1966 baseW
= wwin
->normal_hints
->base_width
;
1967 baseH
= wwin
->normal_hints
->base_height
;
1980 /* aspect ratio code borrowed from olwm */
1982 /* adjust max aspect ratio */
1983 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1984 if (maxAX
> maxAY
) {
1985 height
= (width
* maxAY
) / maxAX
;
1986 if (height
> maxH
) {
1988 width
= (height
* maxAX
) / maxAY
;
1991 width
= (height
* maxAX
) / maxAY
;
1994 height
= (width
* maxAY
) / maxAX
;
1999 /* adjust min aspect ratio */
2000 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
2001 if (minAX
> minAY
) {
2002 height
= (width
* minAY
) / minAX
;
2003 if (height
< minH
) {
2005 width
= (height
* minAX
) / minAY
;
2008 width
= (height
* minAX
) / minAY
;
2011 height
= (width
* minAY
) / minAX
;
2018 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
2020 width
= (((width
- minW
) / winc
) * winc
) + minW
;
2024 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
2026 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
2029 /* broken stupid apps may cause preposterous values for these.. */
2037 wWindowCropSize(WWindow
* wwin
, unsigned int maxW
, unsigned int maxH
, unsigned int *width
, unsigned int *height
)
2039 int baseW
= 0, baseH
= 0;
2040 int winc
= 1, hinc
= 1;
2042 if (wwin
->normal_hints
) {
2043 baseW
= wwin
->normal_hints
->base_width
;
2044 baseH
= wwin
->normal_hints
->base_height
;
2046 winc
= wwin
->normal_hints
->width_inc
;
2047 hinc
= wwin
->normal_hints
->height_inc
;
2051 *width
= maxW
- (maxW
- baseW
) % winc
;
2054 *height
= maxH
- (maxH
- baseH
) % hinc
;
2057 void wWindowChangeWorkspace(WWindow
* wwin
, int workspace
)
2059 WScreen
*scr
= wwin
->screen_ptr
;
2063 if (workspace
>= scr
->workspace_count
|| workspace
< 0 || workspace
== wwin
->frame
->workspace
)
2066 if (workspace
!= scr
->current_workspace
) {
2067 /* Sent to other workspace. Unmap window */
2068 if ((wwin
->flags
.mapped
2069 || wwin
->flags
.shaded
|| (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
2070 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
2072 wapp
= wApplicationOf(wwin
->main_window
);
2074 wapp
->last_workspace
= workspace
;
2076 if (wwin
->flags
.miniaturized
) {
2078 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
2079 wwin
->icon
->mapped
= 0;
2083 wSetFocusTo(scr
, NULL
);
2087 /* brought to current workspace. Map window */
2088 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
2090 XMapWindow(dpy
, wwin
->icon
->core
->window
);
2091 wwin
->icon
->mapped
= 1;
2093 } else if (!wwin
->flags
.mapped
&& !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
2097 if (!IS_OMNIPRESENT(wwin
)) {
2098 int oldWorkspace
= wwin
->frame
->workspace
;
2100 wwin
->frame
->workspace
= workspace
;
2102 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void *)(uintptr_t) oldWorkspace
);
2110 void wWindowSynthConfigureNotify(WWindow
* wwin
)
2114 sevent
.type
= ConfigureNotify
;
2115 sevent
.xconfigure
.display
= dpy
;
2116 sevent
.xconfigure
.event
= wwin
->client_win
;
2117 sevent
.xconfigure
.window
= wwin
->client_win
;
2119 sevent
.xconfigure
.x
= wwin
->client
.x
;
2120 sevent
.xconfigure
.y
= wwin
->client
.y
;
2121 sevent
.xconfigure
.width
= wwin
->client
.width
;
2122 sevent
.xconfigure
.height
= wwin
->client
.height
;
2124 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2125 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2126 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2128 sevent
.xconfigure
.above
= None
;
2130 sevent
.xconfigure
.override_redirect
= False
;
2131 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2136 *----------------------------------------------------------------------
2137 * wWindowConfigure()
2139 * req_x, req_y: new requested positions for the frame
2140 * req_width, req_height: new requested sizes for the client
2142 * Configures the frame, decorations and client window to the specified
2143 * geometry, whose validity is not checked -- wWindowConstrainSize()
2144 * must be used for that.
2145 * The size parameters are for the client window, but the position is
2147 * The client window receives a ConfigureNotify event, according
2148 * to what ICCCM says.
2154 * Window size and position are changed and client window receives
2155 * a ConfigureNotify event.
2156 *----------------------------------------------------------------------
2158 void wWindowConfigure(WWindow
*wwin
, int req_x
, int req_y
, int req_width
, int req_height
)
2160 int synth_notify
= False
;
2163 resize
= (req_width
!= wwin
->client
.width
|| req_height
!= wwin
->client
.height
);
2165 * if the window is being moved but not resized then
2166 * send a synthetic ConfigureNotify
2168 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
) && !resize
) {
2169 synth_notify
= True
;
2172 if (WFLAGP(wwin
, dont_move_off
))
2173 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
, req_width
, req_height
);
2175 if (req_width
< MIN_WINDOW_SIZE
)
2176 req_width
= MIN_WINDOW_SIZE
;
2177 if (req_height
< MIN_WINDOW_SIZE
)
2178 req_height
= MIN_WINDOW_SIZE
;
2180 /* If growing, resize inner part before frame,
2181 * if shrinking, resize frame before.
2182 * This will prevent the frame (that can have a different color)
2183 * to be exposed, causing flicker */
2184 if (req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
)
2185 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2187 if (wwin
->flags
.shaded
) {
2188 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, wwin
->frame
->core
->height
);
2189 wwin
->old_geometry
.height
= req_height
;
2193 h
= req_height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2195 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2198 if (!(req_height
> wwin
->frame
->core
->height
|| req_width
> wwin
->frame
->core
->width
))
2199 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2201 wwin
->client
.x
= req_x
;
2202 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2203 wwin
->client
.width
= req_width
;
2204 wwin
->client
.height
= req_height
;
2206 wwin
->client
.x
= req_x
;
2207 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2209 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2211 wwin
->frame_x
= req_x
;
2212 wwin
->frame_y
= req_y
;
2213 if (HAS_BORDER(wwin
)) {
2214 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2215 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2218 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2219 wWindowSetShape(wwin
);
2224 wWindowSynthConfigureNotify(wwin
);
2228 void wWindowMove(wwin
, req_x
, req_y
)
2230 int req_x
, req_y
; /* new position of the frame */
2232 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2233 int synth_notify
= False
;
2235 /* Send a synthetic ConfigureNotify event for every window movement. */
2236 if ((req_x
!= wwin
->frame_x
|| req_y
!= wwin
->frame_y
)) {
2237 synth_notify
= True
;
2240 /* A single synthetic ConfigureNotify event is sent at the end of
2241 * a completed (opaque) movement in moveres.c */
2244 if (WFLAGP(wwin
, dont_move_off
))
2245 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2246 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2248 wwin
->client
.x
= req_x
;
2249 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2250 if (HAS_BORDER(wwin
)) {
2251 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2252 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2255 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2257 wwin
->frame_x
= req_x
;
2258 wwin
->frame_y
= req_y
;
2260 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2262 wWindowSynthConfigureNotify(wwin
);
2266 void wWindowUpdateButtonImages(WWindow
* wwin
)
2268 WScreen
*scr
= wwin
->screen_ptr
;
2269 Pixmap pixmap
, mask
;
2270 WFrameWindow
*fwin
= wwin
->frame
;
2272 if (!HAS_TITLEBAR(wwin
))
2275 /* miniaturize button */
2277 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2278 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2279 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2281 if (wwin
->wm_gnustep_attr
->flags
& GSMiniaturizeMaskAttr
) {
2282 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2287 if (fwin
->lbutton_image
2288 && (fwin
->lbutton_image
->image
!= pixmap
|| fwin
->lbutton_image
->mask
!= mask
)) {
2289 wPixmapDestroy(fwin
->lbutton_image
);
2290 fwin
->lbutton_image
= NULL
;
2293 if (!fwin
->lbutton_image
) {
2294 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2295 fwin
->lbutton_image
->client_owned
= 1;
2296 fwin
->lbutton_image
->client_owned_mask
= 1;
2299 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2300 wPixmapDestroy(fwin
->lbutton_image
);
2302 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2305 #ifdef XKB_BUTTON_HINT
2306 if (!WFLAGP(wwin
, no_language_button
)) {
2307 if (fwin
->languagebutton_image
&& !fwin
->languagebutton_image
->shared
) {
2308 wPixmapDestroy(fwin
->languagebutton_image
);
2310 fwin
->languagebutton_image
= scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2316 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2317 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2319 if (!WFLAGP(wwin
, no_close_button
)) {
2320 if (wwin
->wm_gnustep_attr
&& wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2321 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2323 if (wwin
->wm_gnustep_attr
->flags
& GSCloseMaskAttr
)
2324 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2328 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2329 || fwin
->rbutton_image
->mask
!= mask
)) {
2330 wPixmapDestroy(fwin
->rbutton_image
);
2331 fwin
->rbutton_image
= NULL
;
2334 if (!fwin
->rbutton_image
) {
2335 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2336 fwin
->rbutton_image
->client_owned
= 1;
2337 fwin
->rbutton_image
->client_owned_mask
= 1;
2340 } else if (WFLAGP(wwin
, kill_close
)) {
2342 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2343 wPixmapDestroy(fwin
->rbutton_image
);
2345 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2347 } else if (MGFLAGP(wwin
, broken_close
)) {
2349 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2350 wPixmapDestroy(fwin
->rbutton_image
);
2352 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2356 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2357 wPixmapDestroy(fwin
->rbutton_image
);
2359 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2363 /* force buttons to be redrawn */
2364 fwin
->flags
.need_texture_change
= 1;
2365 wFrameWindowPaint(fwin
);
2369 *---------------------------------------------------------------------------
2370 * wWindowConfigureBorders--
2371 * Update window border configuration according to attribute flags.
2373 *---------------------------------------------------------------------------
2375 void wWindowConfigureBorders(WWindow
* wwin
)
2381 flags
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
2383 #ifdef XKB_BUTTON_HINT
2384 flags
|= WFF_LANGUAGE_BUTTON
;
2387 if (HAS_TITLEBAR(wwin
))
2388 flags
|= WFF_TITLEBAR
;
2389 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2390 flags
|= WFF_RESIZEBAR
;
2391 if (HAS_BORDER(wwin
))
2392 flags
|= WFF_BORDER
;
2393 if (wwin
->flags
.shaded
)
2394 flags
|= WFF_IS_SHADED
;
2396 oldh
= wwin
->frame
->top_width
;
2397 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2398 if (oldh
!= wwin
->frame
->top_width
) {
2399 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2401 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2402 wWindowConfigure(wwin
, wwin
->frame_x
, newy
, wwin
->client
.width
, wwin
->client
.height
);
2406 if (!WFLAGP(wwin
, no_miniaturize_button
)
2407 && wwin
->frame
->flags
.hide_left_button
)
2408 flags
|= WFF_LEFT_BUTTON
;
2410 #ifdef XKB_BUTTON_HINT
2411 if (!WFLAGP(wwin
, no_language_button
)
2412 && wwin
->frame
->flags
.hide_language_button
) {
2413 flags
|= WFF_LANGUAGE_BUTTON
;
2417 if (!WFLAGP(wwin
, no_close_button
)
2418 && wwin
->frame
->flags
.hide_right_button
)
2419 flags
|= WFF_RIGHT_BUTTON
;
2422 wWindowUpdateButtonImages(wwin
);
2423 wFrameWindowShowButton(wwin
->frame
, flags
);
2427 if (WFLAGP(wwin
, no_miniaturize_button
)
2428 && !wwin
->frame
->flags
.hide_left_button
)
2429 flags
|= WFF_LEFT_BUTTON
;
2431 #ifdef XKB_BUTTON_HINT
2432 if (WFLAGP(wwin
, no_language_button
)
2433 && !wwin
->frame
->flags
.hide_language_button
)
2434 flags
|= WFF_LANGUAGE_BUTTON
;
2437 if (WFLAGP(wwin
, no_close_button
)
2438 && !wwin
->frame
->flags
.hide_right_button
)
2439 flags
|= WFF_RIGHT_BUTTON
;
2442 wFrameWindowHideButton(wwin
->frame
, flags
);
2445 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2446 wWindowSetShape(wwin
);
2452 void wWindowSaveState(WWindow
* wwin
)
2457 memset(data
, 0, sizeof(CARD32
) * 10);
2458 data
[0] = wwin
->frame
->workspace
;
2459 data
[1] = wwin
->flags
.miniaturized
;
2460 data
[2] = wwin
->flags
.shaded
;
2461 data
[3] = wwin
->flags
.hidden
;
2462 data
[4] = wwin
->flags
.maximized
;
2463 if (wwin
->flags
.maximized
== 0) {
2464 data
[5] = wwin
->frame_x
;
2465 data
[6] = wwin
->frame_y
;
2466 data
[7] = wwin
->frame
->core
->width
;
2467 data
[8] = wwin
->frame
->core
->height
;
2469 data
[5] = wwin
->old_geometry
.x
;
2470 data
[6] = wwin
->old_geometry
.y
;
2471 data
[7] = wwin
->old_geometry
.width
;
2472 data
[8] = wwin
->old_geometry
.height
;
2475 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2476 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2477 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2480 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2481 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
, (unsigned char *)data
, 10);
2484 static int getSavedState(Window window
, WSavedState
** state
)
2488 unsigned long nitems_ret
;
2489 unsigned long bytes_after_ret
;
2492 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2493 True
, _XA_WINDOWMAKER_STATE
,
2494 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2495 (unsigned char **)&data
) != Success
|| !data
)
2498 *state
= wmalloc(sizeof(WSavedState
));
2500 (*state
)->workspace
= data
[0];
2501 (*state
)->miniaturized
= data
[1];
2502 (*state
)->shaded
= data
[2];
2503 (*state
)->hidden
= data
[3];
2504 (*state
)->maximized
= data
[4];
2505 (*state
)->x
= data
[5];
2506 (*state
)->y
= data
[6];
2507 (*state
)->w
= data
[7];
2508 (*state
)->h
= data
[8];
2509 (*state
)->window_shortcuts
= data
[9];
2513 if (*state
&& type_ret
== _XA_WINDOWMAKER_STATE
)
2520 void wWindowClearShape(WWindow
* wwin
)
2522 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2523 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2527 void wWindowSetShape(WWindow
* wwin
)
2531 #ifdef OPTIMIZE_SHAPE
2536 /* only shape is the client's */
2537 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2541 /* Get array of rectangles describing the shape mask */
2542 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
, &count
, &ordering
);
2547 urec
= malloc(sizeof(XRectangle
) * (count
+ 2));
2553 /* insert our decoration rectangles in the rect list */
2554 memcpy(urec
, rects
, sizeof(XRectangle
) * count
);
2557 if (HAS_TITLEBAR(wwin
)) {
2559 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2560 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2561 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2564 if (HAS_RESIZEBAR(wwin
)) {
2566 urec
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2567 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2568 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2572 /* shape our frame window */
2573 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2574 0, wwin
->frame
->top_width
, urec
, count
, ShapeSet
, Unsorted
);
2580 #endif /* OPTIMIZE_SHAPE */
2582 if (HAS_TITLEBAR(wwin
)) {
2585 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2586 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2589 if (HAS_RESIZEBAR(wwin
)) {
2591 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2592 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2593 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2597 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2598 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2600 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2601 0, wwin
->frame
->top_width
, wwin
->client_win
,
2602 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2607 /* ====================================================================== */
2609 static FocusMode
getFocusMode(WWindow
* wwin
)
2613 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2614 if (wwin
->wm_hints
->input
== True
) {
2615 if (wwin
->protocols
.TAKE_FOCUS
)
2616 mode
= WFM_LOCALLY_ACTIVE
;
2620 if (wwin
->protocols
.TAKE_FOCUS
)
2621 mode
= WFM_GLOBALLY_ACTIVE
;
2623 mode
= WFM_NO_INPUT
;
2631 void wWindowSetKeyGrabs(WWindow
* wwin
)
2636 for (i
= 0; i
< WKBD_LAST
; i
++) {
2637 key
= &wKeyBindings
[i
];
2639 if (key
->keycode
== 0)
2641 if (key
->modifier
!= AnyModifier
) {
2642 XGrabKey(dpy
, key
->keycode
, key
->modifier
| LockMask
,
2643 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2645 /* Also grab all modifier combinations possible that include,
2646 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2647 * work even if the NumLock/ScrollLock key is on.
2649 wHackedGrabKey(key
->keycode
, key
->modifier
,
2650 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2653 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2654 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2657 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2660 void wWindowResetMouseGrabs(WWindow
* wwin
)
2662 /* Mouse grabs can't be done on the client window because of
2663 * ICCCM and because clients that try to do the same will crash.
2665 * But there is a problem wich makes tbar buttons of unfocused
2666 * windows not usable as the click goes to the frame window instead
2667 * of the button itself. Must figure a way to fix that.
2670 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2672 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2673 /* grabs for Meta+drag */
2674 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2675 True
, ButtonPressMask
| ButtonReleaseMask
,
2676 GrabModeSync
, GrabModeAsync
, None
, None
);
2679 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2680 && !wwin
->flags
.is_gnustep
) {
2681 /* the passive grabs to focus the window */
2682 /* if (wPreferences.focus_mode == WKF_CLICK) */
2683 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2684 True
, ButtonPressMask
| ButtonReleaseMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
2689 void wWindowUpdateGNUstepAttr(WWindow
* wwin
, GNUstepWMAttributes
* attr
)
2691 if (attr
->flags
& GSExtraFlagsAttr
) {
2692 if (MGFLAGP(wwin
, broken_close
) != (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2693 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2694 wWindowUpdateButtonImages(wwin
);
2699 WMagicNumber
wWindowAddSavedState(char *instance
, char *class, char *command
, pid_t pid
, WSavedState
* state
)
2701 WWindowState
*wstate
;
2703 wstate
= malloc(sizeof(WWindowState
));
2707 memset(wstate
, 0, sizeof(WWindowState
));
2710 wstate
->instance
= wstrdup(instance
);
2712 wstate
->class = wstrdup(class);
2714 wstate
->command
= wstrdup(command
);
2715 wstate
->state
= state
;
2717 wstate
->next
= windowState
;
2718 windowState
= wstate
;
2721 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2727 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2729 WMagicNumber
wWindowGetSavedState(Window win
)
2731 char *instance
, *class, *command
= NULL
;
2732 WWindowState
*wstate
= windowState
;
2737 command
= GetCommandForWindow(win
);
2741 if (PropGetWMClass(win
, &class, &instance
)) {
2743 if (SAME(instance
, wstate
->instance
) &&
2744 SAME(class, wstate
->class) && SAME(command
, wstate
->command
)) {
2747 wstate
= wstate
->next
;
2754 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
, class, command
);
2767 void wWindowDeleteSavedState(WMagicNumber id
)
2769 WWindowState
*tmp
, *wstate
= (WWindowState
*) id
;
2771 if (!wstate
|| !windowState
)
2775 if (tmp
== wstate
) {
2776 windowState
= wstate
->next
;
2778 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2779 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2781 if (wstate
->instance
)
2782 wfree(wstate
->instance
);
2784 wfree(wstate
->class);
2785 if (wstate
->command
)
2786 wfree(wstate
->command
);
2787 wfree(wstate
->state
);
2791 if (tmp
->next
== wstate
) {
2792 tmp
->next
= wstate
->next
;
2794 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2795 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2797 if (wstate
->instance
)
2798 wfree(wstate
->instance
);
2800 wfree(wstate
->class);
2801 if (wstate
->command
)
2802 wfree(wstate
->command
);
2803 wfree(wstate
->state
);
2812 void wWindowDeleteSavedStatesForPID(pid_t pid
)
2814 WWindowState
*tmp
, *wstate
;
2820 if (tmp
->pid
== pid
) {
2821 wstate
= windowState
;
2822 windowState
= tmp
->next
;
2824 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2825 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2827 if (wstate
->instance
)
2828 wfree(wstate
->instance
);
2830 wfree(wstate
->class);
2831 if (wstate
->command
)
2832 wfree(wstate
->command
);
2833 wfree(wstate
->state
);
2837 if (tmp
->next
->pid
== pid
) {
2839 tmp
->next
= wstate
->next
;
2841 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2842 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2844 if (wstate
->instance
)
2845 wfree(wstate
->instance
);
2847 wfree(wstate
->class);
2848 if (wstate
->command
)
2849 wfree(wstate
->command
);
2850 wfree(wstate
->state
);
2859 void wWindowSetOmnipresent(WWindow
* wwin
, Bool flag
)
2861 if (wwin
->flags
.omnipresent
== flag
)
2864 wwin
->flags
.omnipresent
= flag
;
2865 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2868 /* ====================================================================== */
2870 static void resizebarMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2872 WWindow
*wwin
= data
;
2874 #ifndef NUMLOCK_HACK
2875 if ((event
->xbutton
.state
& ValidModMask
)
2876 != (event
->xbutton
.state
& ~LockMask
)) {
2877 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
2878 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2882 event
->xbutton
.state
&= ValidModMask
;
2884 CloseWindowMenu(wwin
->screen_ptr
);
2886 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
2887 && !WFLAGP(wwin
, no_focusable
)) {
2888 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2891 if (event
->xbutton
.button
== Button1
)
2892 wRaiseFrame(wwin
->frame
->core
);
2894 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2895 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2896 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2897 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2899 wwarning("pointer grab failed for window move");
2905 if (event
->xbutton
.state
& MOD_MASK
) {
2906 /* move the window */
2907 wMouseMoveWindow(wwin
, event
);
2908 XUngrabPointer(dpy
, CurrentTime
);
2910 wMouseResizeWindow(wwin
, event
);
2911 XUngrabPointer(dpy
, CurrentTime
);
2915 static void titlebarDblClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
2917 WWindow
*wwin
= data
;
2919 event
->xbutton
.state
&= ValidModMask
;
2921 if (event
->xbutton
.button
== Button1
) {
2922 if (event
->xbutton
.state
== 0) {
2923 if (!WFLAGP(wwin
, no_shadeable
)) {
2925 if (wwin
->flags
.shaded
)
2926 wUnshadeWindow(wwin
);
2933 if (event
->xbutton
.state
& ControlMask
)
2934 dir
|= MAX_VERTICAL
;
2936 if (event
->xbutton
.state
& ShiftMask
) {
2937 dir
|= MAX_HORIZONTAL
;
2938 if (!(event
->xbutton
.state
& ControlMask
))
2939 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2942 /* maximize window */
2943 if (dir
!= 0 && IS_RESIZABLE(wwin
)) {
2944 int ndir
= dir
^ wwin
->flags
.maximized
;
2947 wMaximizeWindow(wwin
, ndir
);
2949 wUnmaximizeWindow(wwin
);
2953 } else if (event
->xbutton
.button
== Button3
) {
2954 if (event
->xbutton
.state
& MOD_MASK
) {
2955 wHideOtherApplications(wwin
);
2957 } else if (event
->xbutton
.button
== Button2
) {
2958 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2959 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2961 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2962 wUnshadeWindow(wwin
);
2966 static void frameMouseDown(WObjDescriptor
* desc
, XEvent
* event
)
2968 WWindow
*wwin
= desc
->parent
;
2970 event
->xbutton
.state
&= ValidModMask
;
2972 CloseWindowMenu(wwin
->screen_ptr
);
2974 if ( /*wPreferences.focus_mode==WKF_CLICK
2975 && */ !(event
->xbutton
.state
& ControlMask
)
2976 && !WFLAGP(wwin
, no_focusable
)) {
2977 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2979 if (event
->xbutton
.button
== Button1
) {
2980 wRaiseFrame(wwin
->frame
->core
);
2983 if (event
->xbutton
.state
& MOD_MASK
) {
2984 /* move the window */
2985 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2986 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
2987 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
2989 wwarning("pointer grab failed for window move");
2993 if (event
->xbutton
.button
== Button3
)
2994 wMouseResizeWindow(wwin
, event
);
2995 else if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
)
2996 wMouseMoveWindow(wwin
, event
);
2997 XUngrabPointer(dpy
, CurrentTime
);
3001 static void titlebarMouseDown(WCoreWindow
* sender
, void *data
, XEvent
* event
)
3003 WWindow
*wwin
= (WWindow
*) data
;
3005 #ifndef NUMLOCK_HACK
3006 if ((event
->xbutton
.state
& ValidModMask
)
3007 != (event
->xbutton
.state
& ~LockMask
)) {
3008 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"
3009 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3012 event
->xbutton
.state
&= ValidModMask
;
3014 CloseWindowMenu(wwin
->screen_ptr
);
3016 if (wPreferences
.focus_mode
== WKF_CLICK
&& !(event
->xbutton
.state
& ControlMask
)
3017 && !WFLAGP(wwin
, no_focusable
)) {
3018 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3021 if (event
->xbutton
.button
== Button1
|| event
->xbutton
.button
== Button2
) {
3023 if (event
->xbutton
.button
== Button1
) {
3024 if (event
->xbutton
.state
& MOD_MASK
) {
3025 wLowerFrame(wwin
->frame
->core
);
3027 wRaiseFrame(wwin
->frame
->core
);
3030 if ((event
->xbutton
.state
& ShiftMask
)
3031 && !(event
->xbutton
.state
& ControlMask
)) {
3032 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3035 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3036 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3037 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
3038 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3040 wwarning("pointer grab failed for window move");
3045 /* move the window */
3046 wMouseMoveWindow(wwin
, event
);
3048 XUngrabPointer(dpy
, CurrentTime
);
3049 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
== 0
3050 && !wwin
->flags
.internal_window
&& !WCHECK_STATE(WSTATE_MODAL
)) {
3051 WObjDescriptor
*desc
;
3053 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3054 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3055 ButtonMotionMask
| ButtonReleaseMask
| ButtonPressMask
,
3056 GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
) != GrabSuccess
) {
3058 wwarning("pointer grab failed for window move");
3063 OpenWindowMenu(wwin
, event
->xbutton
.x_root
, wwin
->frame_y
+ wwin
->frame
->top_width
, False
);
3065 /* allow drag select */
3066 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3067 event
->xany
.send_event
= True
;
3068 (*desc
->handle_mousedown
) (desc
, event
);
3070 XUngrabPointer(dpy
, CurrentTime
);
3074 static void windowCloseClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
3076 WWindow
*wwin
= data
;
3078 event
->xbutton
.state
&= ValidModMask
;
3080 CloseWindowMenu(wwin
->screen_ptr
);
3082 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3085 /* if control-click, kill the client */
3086 if (event
->xbutton
.state
& ControlMask
) {
3089 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
== 0) {
3090 /* send delete message */
3091 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3096 static void windowCloseDblClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
3098 WWindow
*wwin
= data
;
3100 CloseWindowMenu(wwin
->screen_ptr
);
3102 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3105 /* send delete message */
3106 if (wwin
->protocols
.DELETE_WINDOW
) {
3107 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3113 #ifdef XKB_BUTTON_HINT
3114 static void windowLanguageClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
3116 WWindow
*wwin
= data
;
3117 WFrameWindow
*fwin
= wwin
->frame
;
3118 WScreen
*scr
= fwin
->screen_ptr
;
3119 XkbStateRec staterec
;
3122 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3124 tl
= wwin
->frame
->languagemode
;
3125 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3126 wwin
->frame
->last_languagemode
= tl
;
3127 wSetFocusTo(scr
, wwin
);
3128 wwin
->frame
->languagebutton_image
=
3129 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+ wwin
->frame
->languagemode
];
3130 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3131 if (event
->xbutton
.button
== Button3
)
3133 wRaiseFrame(fwin
->core
);
3137 static void windowIconifyClick(WCoreWindow
* sender
, void *data
, XEvent
* event
)
3139 WWindow
*wwin
= data
;
3141 event
->xbutton
.state
&= ValidModMask
;
3143 CloseWindowMenu(wwin
->screen_ptr
);
3145 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3148 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
== 0) {
3149 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
, LastTimestamp
);
3152 if ((event
->xbutton
.state
& ControlMask
) || (event
->xbutton
.button
== Button3
)) {
3154 wapp
= wApplicationOf(wwin
->main_window
);
3155 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3156 wHideApplication(wapp
);
3157 } else if (event
->xbutton
.state
== 0) {
3158 wIconifyWindow(wwin
);