1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 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 */
37 /* For getting mouse wheel mappings from WINGs */
38 #include <WINGs/WINGsP.h>
40 #include "WindowMaker.h"
46 #include "winspector.h"
48 #include "properties.h"
55 #include "workspace.h"
69 # include "openlook.h"
72 /****** Global Variables ******/
74 extern WShortKey wKeyBindings
[WKBD_LAST
];
77 extern Bool wShapeSupported
;
81 extern XContext wWinContext
;
84 extern Cursor wCursor
[WCUR_LAST
];
87 extern Atom _XA_WM_DELETE_WINDOW
;
88 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
90 extern Atom _XA_WINDOWMAKER_STATE
;
92 extern WPreferences wPreferences
;
94 #define MOD_MASK wPreferences.modifier_mask
96 extern Time LastTimestamp
;
99 extern void DoWindowBirth(WWindow
*);
103 /***** Local Stuff *****/
106 static WWindowState
*windowState
=NULL
;
110 /* local functions */
111 static FocusMode
getFocusMode(WWindow
*wwin
);
113 static int getSavedState(Window window
, WSavedState
**state
);
115 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
120 /* frame window (during window grabs) */
121 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
124 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
125 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
128 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
130 #ifdef XKB_BUTTON_HINT
131 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
134 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
135 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
137 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
140 /****** Notification Observers ******/
143 appearanceObserver(void *self
, WMNotification
*notif
)
145 WWindow
*wwin
= (WWindow
*)self
;
146 int flags
= (int)WMGetNotificationClientData(notif
);
148 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
151 if (flags
& WFontSettings
) {
152 wWindowConfigureBorders(wwin
);
153 if(wwin
->flags
.shaded
) {
154 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
155 wwin
->frame
->top_width
- 1);
157 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
158 + wwin
->frame
->top_width
;
159 wWindowSynthConfigureNotify(wwin
);
162 if (flags
& WTextureSettings
) {
163 wwin
->frame
->flags
.need_texture_remake
= 1;
165 if (flags
& (WTextureSettings
| WColorSettings
)) {
166 if (wwin
->frame
->titlebar
)
167 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
169 wFrameWindowPaint(wwin
->frame
);
173 /************************************/
176 wWindowFor(Window window
)
178 WObjDescriptor
*desc
;
183 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
186 if (desc
->parent_type
==WCLASS_WINDOW
)
188 else if (desc
->parent_type
==WCLASS_FRAME
) {
189 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
190 if (frame
->flags
.is_client_window_frame
)
203 wwin
= wmalloc(sizeof(WWindow
));
206 memset(wwin
, 0, sizeof(WWindow
));
208 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
209 wwin
->client_descriptor
.parent
= wwin
;
210 wwin
->client_descriptor
.self
= wwin
;
211 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
218 wWindowDestroy(WWindow
*wwin
)
222 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
223 wwin
->screen_ptr
->cmap_window
= NULL
;
226 WMRemoveNotificationObserver(wwin
);
228 wwin
->flags
.destroyed
= 1;
230 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
231 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
234 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
236 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
237 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
238 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
242 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
>0) {
243 wwin
->fake_group
->retainCount
--;
244 if (wwin
->fake_group
->retainCount
==0 && wwin
->fake_group
->leader
!=None
) {
245 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
246 wwin
->fake_group
->leader
= None
;
247 wwin
->fake_group
->origLeader
= None
;
252 if (wwin
->normal_hints
)
253 XFree(wwin
->normal_hints
);
256 XFree(wwin
->wm_hints
);
258 if (wwin
->wm_instance
)
259 XFree(wwin
->wm_instance
);
262 XFree(wwin
->wm_class
);
264 if (wwin
->wm_gnustep_attr
)
265 wfree(wwin
->wm_gnustep_attr
);
267 if (wwin
->cmap_windows
)
268 XFree(wwin
->cmap_windows
);
270 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
273 wFrameWindowDestroy(wwin
->frame
);
276 RemoveFromStackList(wwin
->icon
->core
);
277 wIconDestroy(wwin
->icon
);
278 if (wPreferences
.auto_arrange_icons
)
279 wArrangeIcons(wwin
->screen_ptr
, True
);
288 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
290 if (gs_hints
->flags
& GSWindowStyleAttr
) {
291 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
292 wwin
->client_flags
.no_border
= 1;
293 wwin
->client_flags
.no_titlebar
= 1;
294 wwin
->client_flags
.no_closable
= 1;
295 wwin
->client_flags
.no_miniaturizable
= 1;
296 wwin
->client_flags
.no_resizable
= 1;
297 wwin
->client_flags
.no_close_button
= 1;
298 wwin
->client_flags
.no_miniaturize_button
= 1;
299 wwin
->client_flags
.no_resizebar
= 1;
301 wwin
->client_flags
.no_close_button
=
302 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
304 wwin
->client_flags
.no_closable
=
305 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
307 wwin
->client_flags
.no_miniaturize_button
=
308 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
310 wwin
->client_flags
.no_miniaturizable
=
311 wwin
->client_flags
.no_miniaturize_button
;
313 wwin
->client_flags
.no_resizebar
=
314 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
316 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
318 /* these attributes supposedly imply in the existence
320 if (gs_hints
->window_style
& (WMResizableWindowMask
|
321 WMClosableWindowMask
|
322 WMMiniaturizableWindowMask
)) {
323 wwin
->client_flags
.no_titlebar
= 0;
325 wwin
->client_flags
.no_titlebar
=
326 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
331 /* setup the defaults */
332 wwin
->client_flags
.no_border
= 0;
333 wwin
->client_flags
.no_titlebar
= 0;
334 wwin
->client_flags
.no_closable
= 0;
335 wwin
->client_flags
.no_miniaturizable
= 0;
336 wwin
->client_flags
.no_resizable
= 0;
337 wwin
->client_flags
.no_close_button
= 0;
338 wwin
->client_flags
.no_miniaturize_button
= 0;
339 wwin
->client_flags
.no_resizebar
= 0;
341 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
342 wwin
->client_flags
.no_appicon
= 1;
348 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
349 WWindowAttributes
*mask
)
351 if (wflags
->no_appicon
&& mask
->no_appicon
)
352 wflags
->emulate_appicon
= 0;
354 if (wwin
->main_window
!=None
) {
355 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
356 if (wapp
&& !wapp
->flags
.emulated
)
357 wflags
->emulate_appicon
= 0;
360 if (wwin
->transient_for
!=None
361 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
362 wflags
->emulate_appicon
= 0;
364 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
371 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
373 WScreen
*scr
= wwin
->screen_ptr
;
375 /* sets global default stuff */
376 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
377 &wwin
->client_flags
, NULL
, True
);
379 * Decoration setting is done in this precedence (lower to higher)
380 * - use global default in the resource database
381 * - guess some settings
382 * - use GNUstep/external window attributes
383 * - set hints specified for the app in the resource DB
386 WSETUFLAG(wwin
, broken_close
, 0);
388 if (wwin
->protocols
.DELETE_WINDOW
)
389 WSETUFLAG(wwin
, kill_close
, 0);
391 WSETUFLAG(wwin
, kill_close
, 1);
393 /* transients can't be iconified or maximized */
394 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
395 WSETUFLAG(wwin
, no_miniaturizable
, 1);
396 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
399 /* if the window can't be resized, remove the resizebar */
400 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
401 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
402 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
403 WSETUFLAG(wwin
, no_resizable
, 1);
404 WSETUFLAG(wwin
, no_resizebar
, 1);
407 /* set GNUstep window attributes */
408 if (wwin
->wm_gnustep_attr
) {
409 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
411 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
413 *level
= wwin
->wm_gnustep_attr
->window_level
;
415 * INT_MIN is the only illegal window level.
417 if (*level
== INT_MIN
)
418 *level
= INT_MIN
+ 1;
421 *level
= WMNormalLevel
;
424 int tmp_workspace
= -1;
425 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
431 wMWMCheckClientHints(wwin
);
432 #endif /* MWM_HINTS */
435 check
= wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
436 #endif /* GNOME_STUFF */
440 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
441 #endif /* KWM_HINTS */
444 wOLWMCheckClientHints(wwin
);
445 #endif /* OLWM_HINTS */
447 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
448 * have INT_MIN that means that no window level was requested. -Dan
450 if (tmp_level
== INT_MIN
) {
451 if (WFLAGP(wwin
, floating
))
452 *level
= WMFloatingLevel
;
453 else if (WFLAGP(wwin
, sunken
))
454 *level
= WMSunkenLevel
;
456 *level
= WMNormalLevel
;
461 if (tmp_workspace
>= 0) {
462 *workspace
= tmp_workspace
% scr
->workspace_count
;
467 * Set attributes specified only for that window/class.
468 * This might do duplicate work with the 1st wDefaultFillAttributes().
470 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
471 &wwin
->user_flags
, &wwin
->defined_user_flags
,
474 * Sanity checks for attributes that depend on other attributes
476 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
477 wwin
->user_flags
.emulate_appicon
= 0;
479 if (wwin
->main_window
!=None
) {
480 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
481 if (wapp
&& !wapp
->flags
.emulated
)
482 wwin
->user_flags
.emulate_appicon
= 0;
485 if (wwin
->transient_for
!=None
486 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
487 wwin
->user_flags
.emulate_appicon
= 0;
489 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
490 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
491 wwin
->user_flags
.sunken
= 0;
493 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
496 /* windows that have takefocus=False shouldn't take focus at all */
497 if (wwin
->focus_mode
== WFM_NO_INPUT
) {
498 /* dont use WSETUFLAG, since this was not an attribute change
499 * made by the user */
500 wwin
->user_flags
.no_focusable
= 1;
508 wWindowCanReceiveFocus(WWindow
*wwin
)
510 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
512 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
514 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
522 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
526 w1
= wwin
->frame
->core
->width
;
527 h1
= wwin
->frame
->core
->height
;
528 w2
= obscured
->frame
->core
->width
;
529 h2
= obscured
->frame
->core
->height
;
531 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
532 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
535 if (wwin
->frame_x
+ w1
< obscured
->frame_x
536 || wwin
->frame_y
+ h1
< obscured
->frame_y
537 || wwin
->frame_x
> obscured
->frame_x
+ w2
538 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
547 createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
549 XClassHint
*classHint
;
555 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
557 classHint
= XAllocClassHint();
558 classHint
->res_name
= instance
;
559 classHint
->res_class
= class;
560 XSetClassHint(dpy
, leader
, classHint
);
563 /* inherit these from the original leader if available */
564 hints
= XGetWMHints(dpy
, win
);
566 hints
= XAllocWMHints();
569 /* set window group leader to self */
570 hints
->window_group
= leader
;
571 hints
->flags
|= WindowGroupHint
;
572 XSetWMHints(dpy
, leader
, hints
);
575 if (XGetCommand(dpy
, win
, &argv
, &argc
)!=0 && argc
> 0) {
576 XSetCommand(dpy
, leader
, argv
, argc
);
577 XFreeStringList(argv
);
585 matchIdentifier(void *item
, void *cdata
)
587 return (strcmp(((WFakeGroupLeader
*)item
)->identifier
, (char*)cdata
)==0);
592 *----------------------------------------------------------------
594 * reparents the window and allocates a descriptor for it.
595 * Window manager hints and other hints are fetched to configure
596 * the window decoration attributes and others. User preferences
597 * for the window are used if available, to configure window
598 * decorations and some behaviour.
599 * If in startup, windows that are override redirect,
600 * unmapped and never were managed and are Withdrawn are not
604 * the new window descriptor
607 * The window is reparented and appropriate notification
608 * is done to the client. Input mask for the window is setup.
609 * The window descriptor is also associated with various window
610 * contexts and inserted in the head of the window list.
611 * Event handler contexts are associated for some objects
612 * (buttons, titlebar and resizebar)
614 *----------------------------------------------------------------
617 wManageWindow(WScreen
*scr
, Window window
)
621 unsigned width
, height
;
622 XWindowAttributes wattribs
;
623 XSetWindowAttributes attribs
;
624 WWindowState
*win_state
;
625 WWindow
*transientOwner
= NULL
;
631 Bool withdraw
= False
;
635 /* XGrabServer(dpy); */
637 /* make sure the window is still there */
638 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
643 /* if it's an override-redirect, ignore it */
644 if (wattribs
.override_redirect
) {
649 wm_state
= PropGetWindowState(window
);
651 /* if it's startup and the window is unmapped, don't manage it */
652 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
657 if (!wFetchName(dpy
, window
, &title
)) {
662 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
667 #endif /* KWM_HINTS */
670 wwin
= wWindowCreate();
672 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
675 printf("managing window %x\n", (unsigned)window
);
679 if (wShapeSupported
) {
684 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
685 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
686 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
687 wwin
->flags
.shaped
= b_shaped
;
692 *--------------------------------------------------
694 * Get hints and other information in properties
696 *--------------------------------------------------
698 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
700 /* setup descriptor */
701 wwin
->client_win
= window
;
702 wwin
->screen_ptr
= scr
;
704 wwin
->old_border_width
= wattribs
.border_width
;
706 wwin
->event_mask
= CLIENT_EVENTS
;
707 attribs
.event_mask
= CLIENT_EVENTS
;
708 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
709 attribs
.save_under
= False
;
710 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
711 |CWSaveUnder
, &attribs
);
712 XSetWindowBorderWidth(dpy
, window
, 0);
714 /* get hints from GNUstep app */
715 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
716 wwin
->flags
.is_gnustep
= 1;
718 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
719 wwin
->wm_gnustep_attr
= NULL
;
722 wwin
->client_leader
= PropGetClientLeader(window
);
723 if (wwin
->client_leader
!=None
)
724 wwin
->main_window
= wwin
->client_leader
;
726 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
728 if (wwin
->wm_hints
) {
729 if (wwin
->wm_hints
->flags
& StateHint
) {
731 if (wwin
->wm_hints
->initial_state
== IconicState
) {
733 wwin
->flags
.miniaturized
= 1;
735 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
741 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
742 wwin
->group_id
= wwin
->wm_hints
->window_group
;
743 /* window_group has priority over CLIENT_LEADER */
744 wwin
->main_window
= wwin
->group_id
;
746 wwin
->group_id
= None
;
749 if (wwin
->wm_hints
->flags
& UrgencyHint
)
750 wwin
->flags
.urgent
= 1;
752 wwin
->group_id
= None
;
755 PropGetProtocols(window
, &wwin
->protocols
);
757 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
758 wwin
->transient_for
= None
;
760 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
761 wwin
->transient_for
= scr
->root_win
;
763 transientOwner
= wWindowFor(wwin
->transient_for
);
764 if (transientOwner
&& transientOwner
->main_window
!=None
) {
765 wwin
->main_window
= transientOwner
->main_window
;
767 wwin->main_window = None;
772 /* guess the focus mode */
773 wwin
->focus_mode
= getFocusMode(wwin
);
775 /* get geometry stuff */
776 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
778 /* printf( "wManageWindow: %d %d %d %d\n", x, y, width, height);*/
780 /* get colormap windows */
781 GetColormapWindows(wwin
);
784 *--------------------------------------------------
786 * Setup the decoration/window attributes and
789 *--------------------------------------------------
792 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
795 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
796 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
798 transientOwner
= wWindowFor(wwin
->group_id
);
800 if (transientOwner
) {
801 wwin
->transient_for
= wwin
->group_id
;
803 /* transients can't be iconified or maximized */
804 if (wwin
->transient_for
) {
805 WSETUFLAG(wwin
, no_miniaturizable
, 1);
806 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
810 #endif /* OLWM_HINTS */
812 /* Make broken apps behave as a nice app. */
813 if (WFLAGP(wwin
, emulate_appicon
)) {
814 wwin
->main_window
= wwin
->client_win
;
817 wwin
->orig_main_window
= wwin
->main_window
;
819 if (wwin
->flags
.is_gnustep
) {
820 WSETUFLAG(wwin
, shared_appicon
, 0);
823 if (wwin
->main_window
) {
824 extern Atom _XA_WINDOWMAKER_MENU
;
825 XTextProperty text_prop
;
827 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
,
828 _XA_WINDOWMAKER_MENU
)) {
829 WSETUFLAG(wwin
, shared_appicon
, 0);
833 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
834 char *buffer
, *instance
, *class;
835 WFakeGroupLeader
*fPtr
;
838 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
841 PropGetWMClass(wwin
->main_window
, &class, &instance
);
842 buffer
= StrConcatDot(instance
, class);
844 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void*)buffer
);
845 if (index
!= WANotFound
) {
846 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
847 if (fPtr
->retainCount
== 0) {
848 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
853 if (fPtr
->origLeader
==None
) {
855 if (ADEQUATE(wwin
->group_id
)) {
857 fPtr
->origLeader
= wwin
->group_id
;
858 } else if (ADEQUATE(wwin
->client_leader
)) {
860 fPtr
->origLeader
= wwin
->client_leader
;
861 } else if (ADEQUATE(wwin
->main_window
)) {
863 fPtr
->origLeader
= wwin
->main_window
;
866 if (ADEQUATE(wwin
->main_window
)) {
868 fPtr
->origLeader
= wwin
->main_window
;
872 wwin
->fake_group
= fPtr
;
873 /*wwin->group_id = fPtr->leader;*/
874 wwin
->main_window
= fPtr
->leader
;
877 fPtr
= (WFakeGroupLeader
*)wmalloc(sizeof(WFakeGroupLeader
));
879 fPtr
->identifier
= buffer
;
880 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
882 fPtr
->origLeader
= None
;
883 fPtr
->retainCount
= 1;
885 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
888 if (ADEQUATE(wwin
->group_id
)) {
890 fPtr
->origLeader
= wwin
->group_id
;
891 } else if (ADEQUATE(wwin
->client_leader
)) {
893 fPtr
->origLeader
= wwin
->client_leader
;
894 } else if (ADEQUATE(wwin
->main_window
)) {
896 fPtr
->origLeader
= wwin
->main_window
;
899 if (ADEQUATE(wwin
->main_window
)) {
901 fPtr
->origLeader
= wwin
->main_window
;
904 wwin
->fake_group
= fPtr
;
905 /*wwin->group_id = fPtr->leader;*/
906 wwin
->main_window
= fPtr
->leader
;
918 *------------------------------------------------------------
920 * Setup the initial state of the window
922 *------------------------------------------------------------
925 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
926 wwin
->flags
.miniaturized
= 1;
929 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
930 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
938 bla
= wGNOMECheckInitialClientState(wwin
);
942 wKWMCheckClientInitialState(wwin
);
946 /* apply previous state if it exists and we're in startup */
947 if (scr
->flags
.startup
&& wm_state
>= 0) {
949 if (wm_state
== IconicState
) {
951 wwin
->flags
.miniaturized
= 1;
953 } else if (wm_state
== WithdrawnState
) {
959 /* if there is a saved state (from file), restore it */
961 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
962 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
964 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
966 if (win_state
&& !withdraw
) {
968 if (win_state
->state
->hidden
>0)
969 wwin
->flags
.hidden
= win_state
->state
->hidden
;
971 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
972 wwin
->flags
.shaded
= win_state
->state
->shaded
;
974 if (win_state
->state
->miniaturized
>0 &&
975 !WFLAGP(wwin
, no_miniaturizable
)) {
976 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
979 if (!IS_OMNIPRESENT(wwin
)) {
980 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
982 if (w
< 0 || w
>= scr
->workspace_count
) {
983 workspace
= win_state
->state
->workspace
;
984 if (workspace
>= scr
->workspace_count
)
985 workspace
= scr
->current_workspace
;
990 workspace
= scr
->current_workspace
;
994 /* if we're restarting, restore saved state (from hints).
995 * This will overwrite previous */
999 if (getSavedState(window
, &wstate
)) {
1000 wwin
->flags
.shaded
= wstate
->shaded
;
1001 wwin
->flags
.hidden
= wstate
->hidden
;
1002 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
1003 wwin
->flags
.maximized
= wstate
->maximized
;
1004 if (wwin
->flags
.maximized
) {
1005 wwin
->old_geometry
.x
= wstate
->x
;
1006 wwin
->old_geometry
.y
= wstate
->y
;
1007 wwin
->old_geometry
.width
= wstate
->w
;
1008 wwin
->old_geometry
.height
= wstate
->h
;
1011 workspace
= wstate
->workspace
;
1016 /* restore window shortcut */
1017 if (wstate
!= NULL
|| win_state
!= NULL
) {
1020 if (win_state
!= NULL
)
1021 mask
= win_state
->state
->window_shortcuts
;
1023 if (wstate
!= NULL
&& mask
== 0)
1024 mask
= wstate
->window_shortcuts
;
1029 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
1030 if (mask
& (1<<i
)) {
1031 if (!scr
->shortcutWindows
[i
])
1032 scr
->shortcutWindows
[i
] = WMCreateArray(4);
1034 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
1039 if (wstate
!= NULL
) {
1044 /* don't let transients start miniaturized if their owners are not */
1045 if (transientOwner
&& !transientOwner
->flags
.miniaturized
1046 && wwin
->flags
.miniaturized
&& !withdraw
) {
1047 wwin
->flags
.miniaturized
= 0;
1049 wwin
->wm_hints
->initial_state
= NormalState
;
1052 /* set workspace on which the window starts */
1053 if (workspace
>= 0) {
1054 if (workspace
> scr
->workspace_count
-1) {
1055 workspace
= workspace
% scr
->workspace_count
;
1060 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
1062 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1067 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1069 workspace
= transientOwner
->frame
->workspace
;
1073 workspace
= scr
->current_workspace
;
1078 /* setup window geometry */
1079 if (win_state
&& win_state
->state
->w
> 0) {
1080 width
= win_state
->state
->w
;
1081 height
= win_state
->state
->h
;
1083 wWindowConstrainSize(wwin
, &width
, &height
);
1085 /* do not ask for window placement if the window is
1086 * transient, during startup, if the initial workspace is another one
1087 * or if the window wants to start iconic.
1088 * If geometry was saved, restore it. */
1090 Bool dontBring
= False
;
1092 if (win_state
&& win_state
->state
->w
> 0) {
1093 x
= win_state
->state
->x
;
1094 y
= win_state
->state
->y
;
1095 } else if ((wwin
->transient_for
==None
1096 || wPreferences
.window_placement
!=WPM_MANUAL
)
1097 && !scr
->flags
.startup
1098 && workspace
== scr
->current_workspace
1099 && !wwin
->flags
.miniaturized
1100 && !wwin
->flags
.maximized
1101 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
1103 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1104 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
1108 x
= transientOwner
->frame_x
+
1109 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
1110 y
= transientOwner
->frame_y
+
1111 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
1114 * limit transient windows to be inside their parent's head
1116 rect
.pos
.x
= transientOwner
->frame_x
;
1117 rect
.pos
.y
= transientOwner
->frame_y
;
1118 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1119 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1121 head
= wGetHeadForRect(scr
, rect
);
1122 rect
= wGetRectForHead(scr
, head
);
1126 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1127 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1131 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1132 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1135 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1137 if (wPreferences
.window_placement
== WPM_MANUAL
)
1140 else if (scr
->xine_count
&&
1141 wwin
->normal_hints
->flags
& PPosition
) {
1147 * Make spash screens come out in the center of a head
1148 * trouble is that most splashies never get here
1149 * they are managed trough atoms but god knows where.
1150 * Dan, do you know ?
1152 * Most of them are not managed, they are set
1153 * OverrideRedirect, which means we can't do anything about
1157 printf( "xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
)/2);
1158 printf( "xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
)/2);
1160 if ( (unsigned)(x
+ (width
- scr
->scr_width
)/2 + 10) < 20 &&
1161 (unsigned)(y
+ (height
- scr
->scr_height
)/2 + 10) < 20) {
1169 * xinerama checks for: across head and dead space
1173 rect
.size
.width
= width
;
1174 rect
.size
.height
= height
;
1176 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1178 if (flags
& XFLAG_DEAD
)
1181 if (flags
& XFLAG_MULTIPLE
)
1185 switch (reposition
) {
1187 head
= wGetHeadForPointerLocation(scr
);
1188 rect
= wGetRectForHead(scr
, head
);
1190 x
= rect
.pos
.x
+ (x
* rect
.size
.width
)/scr
->scr_width
;
1191 y
= rect
.pos
.y
+ (y
* rect
.size
.height
)/scr
->scr_height
;
1195 rect
= wGetRectForHead(scr
, head
);
1199 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1200 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1204 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1205 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1214 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1215 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1218 if (wwin
->flags
.urgent
) {
1219 if (!IS_OMNIPRESENT(wwin
))
1220 wwin
->flags
.omnipresent
^= 1;
1224 *--------------------------------------------------
1226 * Create frame, borders and do reparenting
1228 *--------------------------------------------------
1230 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1231 #ifdef XKB_BUTTON_HINT
1232 if (wPreferences
.modelock
)
1233 foo
|= WFF_LANGUAGE_BUTTON
;
1235 if (!WFLAGP(wwin
, no_titlebar
))
1236 foo
|= WFF_TITLEBAR
;
1237 if (!WFLAGP(wwin
, no_resizebar
))
1238 foo
|= WFF_RESIZEBAR
;
1239 if (!WFLAGP(wwin
, no_border
))
1242 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1243 x
, y
, width
, height
,
1244 &wPreferences
.window_title_clearance
, foo
,
1245 scr
->window_title_texture
,
1246 scr
->resizebar_texture
,
1247 scr
->window_title_color
,
1250 wwin
->frame
->flags
.is_client_window_frame
= 1;
1251 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1253 /* setup button images */
1254 wWindowUpdateButtonImages(wwin
);
1256 /* hide unused buttons */
1258 if (WFLAGP(wwin
, no_close_button
))
1259 foo
|= WFF_RIGHT_BUTTON
;
1260 if (WFLAGP(wwin
, no_miniaturize_button
))
1261 foo
|= WFF_LEFT_BUTTON
;
1262 #ifdef XKB_BUTTON_HINT
1263 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1264 foo
|= WFF_LANGUAGE_BUTTON
;
1267 wFrameWindowHideButton(wwin
->frame
, foo
);
1269 wwin
->frame
->child
= wwin
;
1272 /* emulate olwm push pin. Make the button look as pushed-in for
1273 * the pinned-out state. When the button is clicked, it will
1274 * revert to the normal position, which means the pin is pinned-in.
1276 if (wwin
->flags
.olwm_push_pin_out
)
1277 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1278 #endif /* OLWM_HINTS */
1281 wwin
->frame
->workspace
= workspace
;
1283 wwin
->frame
->on_click_left
= windowIconifyClick
;
1284 #ifdef XKB_BUTTON_HINT
1285 if (wPreferences
.modelock
)
1286 wwin
->frame
->on_click_language
= windowLanguageClick
;
1289 wwin
->frame
->on_click_right
= windowCloseClick
;
1290 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1292 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1293 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1295 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1298 XSelectInput(dpy
, wwin
->client_win
,
1299 wwin
->event_mask
& ~StructureNotifyMask
);
1301 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1302 0, wwin
->frame
->top_width
);
1304 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1310 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1312 /* if gravity is to the south, account for the border sizes */
1314 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1318 * wWindowConfigure() will init the client window's size
1319 * (wwin->client.{width,height}) and all other geometry
1320 * related variables (frame_x,frame_y)
1322 wWindowConfigure(wwin
, x
, y
, width
, height
);
1324 /* to make sure the window receives it's new position after reparenting */
1325 wWindowSynthConfigureNotify(wwin
);
1328 *--------------------------------------------------
1330 * Setup descriptors and save window to internal
1333 *--------------------------------------------------
1336 if (wwin
->main_window
!=None
) {
1340 /* Leader windows do not necessary set themselves as leaders.
1341 * If this is the case, point the leader of this window to
1343 leader
= wWindowFor(wwin
->main_window
);
1344 if (leader
&& leader
->main_window
==None
) {
1345 leader
->main_window
= leader
->client_win
;
1347 app
= wApplicationCreate(scr
, wwin
->main_window
);
1349 app
->last_workspace
= workspace
;
1351 app
->main_window_desc
->fake_group
= wwin
->fake_group
;
1354 * Do application specific stuff, like setting application
1358 if (wwin
->flags
.hidden
) {
1359 /* if the window was set to hidden because it was hidden
1360 * in a previous incarnation and that state was restored */
1361 app
->flags
.hidden
= 1;
1362 } else if (app
->flags
.hidden
) {
1363 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1364 wwin
->flags
.hidden
= 1;
1366 wUnhideApplication(app
, False
, False
);
1373 /* setup the frame descriptor */
1374 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1375 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1376 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1378 /* don't let windows go away if we die */
1379 XAddToSaveSet(dpy
, window
);
1381 XLowerWindow(dpy
, window
);
1383 /* if window is in this workspace and should be mapped, then map it */
1384 if (!wwin
->flags
.miniaturized
1385 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1386 && !wwin
->flags
.hidden
&& !withdraw
) {
1388 /* The following "if" is to avoid crashing of clients that expect
1389 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1390 * after the return from this function.
1392 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1393 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1395 wClientSetState(wwin
, NormalState
, None
);
1399 /* if not auto focus, then map the window under the currently
1401 #define _WIDTH(w) (w)->frame->core->width
1402 #define _HEIGHT(w) (w)->frame->core->height
1403 if (!wPreferences
.auto_focus
&& scr
->focused_window
1404 && !scr
->flags
.startup
&& !transientOwner
1405 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1406 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1407 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1408 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1409 || wwin
->flags
.maximized
)) {
1410 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1418 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1419 && !scr
->flags
.startup
&&
1420 (wwin
->transient_for
==None
|| wwin
->transient_for
==scr
->root_win
)
1422 * The brain damaged idiotic non-click to focus modes will
1423 * have trouble with this because:
1425 * 1. window is created and mapped by the client
1426 * 2. window is mapped by wmaker in small size
1427 * 3. window is animated to grow to normal size
1428 * 4. this function returns to normal event loop
1429 * 5. eventually, the EnterNotify event that would trigger
1430 * the window focusing (if the mouse is over that window)
1431 * will be processed by wmaker.
1432 * But since this event will be rather delayed
1433 * (step 3 has a large delay) the time when the event ocurred
1434 * and when it is processed, the client that owns that window
1435 * will reject the XSetInputFocus() for it.
1437 && (wPreferences
.focus_mode
==WKF_CLICK
1438 || wPreferences
.auto_focus
)) {
1439 DoWindowBirth(wwin
);
1445 /* setup stacking descriptor */
1446 if (transientOwner
) {
1447 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1449 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1453 if (!scr
->focused_window
) {
1454 /* first window on the list */
1457 scr
->focused_window
= wwin
;
1461 /* add window at beginning of focus window list */
1462 tmp
= scr
->focused_window
;
1470 /* raise is set to true if we un-hid the app when this window was born.
1471 * we raise, else old windows of this app will be above this new one. */
1473 wRaiseFrame(wwin
->frame
->core
);
1476 /* Update name must come after WApplication stuff is done */
1477 wWindowUpdateName(wwin
, title
);
1484 *--------------------------------------------------
1486 * Final preparations before window is ready to go
1488 *--------------------------------------------------
1491 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1494 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1495 && !wwin
->flags
.hidden
) {
1496 if (((transientOwner
&& transientOwner
->flags
.focused
)
1497 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1498 wSetFocusTo(scr
, wwin
);
1500 wWindowResetMouseGrabs(wwin
);
1502 if (!WFLAGP(wwin
, no_bind_keys
)) {
1503 wWindowSetKeyGrabs(wwin
);
1507 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1510 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1514 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1515 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1517 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1518 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1524 *------------------------------------------------------------
1525 * Setup Notification Observers
1526 *------------------------------------------------------------
1528 WMAddNotificationObserver(appearanceObserver
, wwin
,
1529 WNWindowAppearanceSettingsChanged
, wwin
);
1533 *--------------------------------------------------
1535 * Cleanup temporary stuff
1537 *--------------------------------------------------
1541 wWindowDeleteSavedState(win_state
);
1543 /* If the window must be withdrawed, then do it now.
1544 * Must do some optimization, 'though */
1546 wwin
->flags
.mapped
= 0;
1547 wClientSetState(wwin
, WithdrawnState
, None
);
1548 wUnmanageWindow(wwin
, True
, False
);
1560 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1561 char *title
, int x
, int y
, int width
, int height
)
1566 wwin
= wWindowCreate();
1568 WMAddNotificationObserver(appearanceObserver
, wwin
,
1569 WNWindowAppearanceSettingsChanged
, wwin
);
1571 wwin
->flags
.internal_window
= 1;
1573 WSETUFLAG(wwin
, omnipresent
, 1);
1574 WSETUFLAG(wwin
, no_shadeable
, 1);
1575 WSETUFLAG(wwin
, no_resizable
, 1);
1576 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1578 wwin
->focus_mode
= WFM_PASSIVE
;
1580 wwin
->client_win
= window
;
1581 wwin
->screen_ptr
= scr
;
1583 wwin
->transient_for
= owner
;
1587 wwin
->client
.width
= width
;
1588 wwin
->client
.height
= height
;
1590 wwin
->frame_x
= wwin
->client
.x
;
1591 wwin
->frame_y
= wwin
->client
.y
;
1594 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1595 foo
|= WFF_TITLEBAR
;
1596 #ifdef XKB_BUTTON_HINT
1597 foo
|= WFF_LANGUAGE_BUTTON
;
1600 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1601 wwin
->frame_x
, wwin
->frame_y
,
1603 &wPreferences
.window_title_clearance
, foo
,
1604 scr
->window_title_texture
,
1605 scr
->resizebar_texture
,
1606 scr
->window_title_color
,
1609 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1611 wwin
->frame
->flags
.is_client_window_frame
= 1;
1612 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1614 wFrameWindowChangeTitle(wwin
->frame
, title
);
1616 /* setup button images */
1617 wWindowUpdateButtonImages(wwin
);
1620 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1622 wwin
->frame
->child
= wwin
;
1624 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1626 #ifdef XKB_BUTTON_HINT
1627 if (wPreferences
.modelock
)
1628 wwin
->frame
->on_click_language
= windowLanguageClick
;
1631 wwin
->frame
->on_click_right
= windowCloseClick
;
1633 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1634 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1636 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1638 wwin
->client
.y
+= wwin
->frame
->top_width
;
1639 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1640 0, wwin
->frame
->top_width
);
1642 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1643 wwin
->client
.width
, wwin
->client
.height
);
1645 /* setup the frame descriptor */
1646 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1647 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1648 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1651 XLowerWindow(dpy
, window
);
1652 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1654 /* setup stacking descriptor */
1655 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
1657 tmp
= wWindowFor(wwin
->transient_for
);
1659 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1661 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1665 if (!scr
->focused_window
) {
1666 /* first window on the list */
1669 scr
->focused_window
= wwin
;
1673 /* add window at beginning of focus window list */
1674 tmp
= scr
->focused_window
;
1682 if (wwin
->flags
.is_gnustep
== 0)
1683 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1685 /* if (wPreferences.auto_focus)*/
1686 wSetFocusTo(scr
, wwin
);
1688 wWindowResetMouseGrabs(wwin
);
1690 wWindowSetKeyGrabs(wwin
);
1697 *----------------------------------------------------------------------
1699 * Removes the frame window from a window and destroys all data
1700 * related to it. The window will be reparented back to the root window
1701 * if restore is True.
1704 * Everything related to the window is destroyed and the window
1705 * is removed from the window lists. Focus is set to the previous on the
1707 *----------------------------------------------------------------------
1710 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1712 WCoreWindow
*frame
= wwin
->frame
->core
;
1713 WWindow
*owner
= NULL
;
1714 WWindow
*newFocusedWindow
= NULL
;
1716 WScreen
*scr
= wwin
->screen_ptr
;
1719 /* First close attribute editor window if open */
1720 if (wwin
->flags
.inspector_open
) {
1721 wCloseInspectorForWindow(wwin
);
1724 /* Close window menu if it's open for this window */
1725 if (wwin
->flags
.menu_open_for_me
) {
1726 CloseWindowMenu(scr
);
1730 if (!wwin
->flags
.internal_window
)
1731 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1733 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1735 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1736 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1739 XUnmapWindow(dpy
, frame
->window
);
1741 XUnmapWindow(dpy
, wwin
->client_win
);
1743 /* deselect window */
1744 wSelectWindow(wwin
, False
);
1746 /* remove all pending events on window */
1747 /* I think this only matters for autoraise */
1748 if (wPreferences
.raise_delay
)
1749 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1753 /* reparent the window back to the root */
1755 wClientRestore(wwin
);
1757 if (wwin
->transient_for
!=scr
->root_win
) {
1758 owner
= wWindowFor(wwin
->transient_for
);
1760 if (!owner
->flags
.semi_focused
) {
1763 owner
->flags
.semi_focused
= 0;
1768 wasFocused
= wwin
->flags
.focused
;
1770 /* remove from window focus list */
1771 if (!wwin
->prev
&& !wwin
->next
) {
1772 /* was the only window */
1773 scr
->focused_window
= NULL
;
1774 newFocusedWindow
= NULL
;
1779 wwin
->prev
->next
= wwin
->next
;
1781 wwin
->next
->prev
= wwin
->prev
;
1783 scr
->focused_window
= wwin
->prev
;
1784 scr
->focused_window
->next
= NULL
;
1787 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1789 /* if in click to focus mode and the window
1790 * was a transient, focus the owner window
1793 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1794 tmp
= wWindowFor(wwin
->transient_for
);
1795 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1799 /* otherwise, focus the next one in the focus list */
1801 tmp
= scr
->focused_window
;
1802 while (tmp
) { /* look for one in the window list first */
1803 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1804 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1808 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1809 tmp
= scr
->focused_window
;
1811 if (!WFLAGP(tmp
, no_focusable
)
1812 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1819 newFocusedWindow
= tmp
;
1821 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1826 /* This is to let the root window get the keyboard input
1827 * if Sloppy focus mode and no other window get focus.
1828 * This way keybindings will not freeze.
1831 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1832 &foo
, &foo
, &foo
, &foo
, &mask
))
1833 tmp
= wWindowFor(win
);
1836 newFocusedWindow
= tmp
;
1838 newFocusedWindow
= NULL
;
1842 if (!wwin
->flags
.internal_window
) {
1843 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1847 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1848 (unsigned)frame
->window
);
1852 if (newFocusedWindow
!= owner
&& owner
) {
1853 if (wwin
->flags
.is_gnustep
== 0)
1854 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1856 wSetFocusTo(scr
, newFocusedWindow
);
1858 wWindowDestroy(wwin
);
1864 wWindowMap(WWindow
*wwin
)
1866 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1867 if (!wwin
->flags
.shaded
) {
1868 /* window will be remapped when getting MapNotify */
1869 XSelectInput(dpy
, wwin
->client_win
,
1870 wwin
->event_mask
& ~StructureNotifyMask
);
1871 XMapWindow(dpy
, wwin
->client_win
);
1872 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1874 wwin
->flags
.mapped
= 1;
1880 wWindowUnmap(WWindow
*wwin
)
1882 wwin
->flags
.mapped
= 0;
1884 /* prevent window withdrawal when getting UnmapNotify */
1885 XSelectInput(dpy
, wwin
->client_win
,
1886 wwin
->event_mask
& ~StructureNotifyMask
);
1887 XUnmapWindow(dpy
, wwin
->client_win
);
1888 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1890 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1896 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1901 #ifdef KEEP_XKB_LOCK_STATUS
1902 if (wPreferences
.modelock
) {
1903 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1905 #endif /* KEEP_XKB_LOCK_STATUS */
1907 wwin
->flags
.semi_focused
= 0;
1909 if (wwin
->flags
.is_gnustep
== 0)
1910 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1912 wwin
->flags
.focused
= 1;
1914 wWindowResetMouseGrabs(wwin
);
1916 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)True
);
1918 if (owin
== wwin
|| !owin
)
1921 nowner
= wWindowFor(wwin
->transient_for
);
1923 /* new window is a transient for the old window */
1924 if (nowner
== owin
) {
1925 owin
->flags
.semi_focused
= 1;
1926 wWindowUnfocus(nowner
);
1930 oowner
= wWindowFor(owin
->transient_for
);
1932 /* new window is owner of old window */
1933 if (wwin
== oowner
) {
1934 wWindowUnfocus(owin
);
1939 wWindowUnfocus(owin
);
1943 /* new window has same owner of old window */
1944 if (oowner
== nowner
) {
1945 /* prevent unfocusing of owner */
1946 oowner
->flags
.semi_focused
= 0;
1947 wWindowUnfocus(owin
);
1948 oowner
->flags
.semi_focused
= 1;
1953 /* nowner != NULL && oowner != nowner */
1954 nowner
->flags
.semi_focused
= 1;
1955 wWindowUnfocus(nowner
);
1956 wWindowUnfocus(owin
);
1961 wWindowUnfocus(WWindow
*wwin
)
1963 CloseWindowMenu(wwin
->screen_ptr
);
1965 if (wwin
->flags
.is_gnustep
== 0)
1966 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1967 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1969 if (wwin
->transient_for
!=None
1970 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1972 owner
= wWindowFor(wwin
->transient_for
);
1973 if (owner
&& owner
->flags
.semi_focused
) {
1974 owner
->flags
.semi_focused
= 0;
1975 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1976 wWindowUnfocus(owner
);
1977 wFrameWindowPaint(owner
->frame
);
1981 wwin
->flags
.focused
= 0;
1983 wWindowResetMouseGrabs(wwin
);
1985 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)False
);
1990 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1997 wwin
->flags
.wm_name_changed
= 1;
2000 /* the hint was removed */
2001 title
= DEF_WINDOW_TITLE
;
2006 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
2007 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
2014 *----------------------------------------------------------------------
2016 * wWindowConstrainSize--
2017 * Constrains size for the client window, taking the maximal size,
2018 * window resize increments and other size hints into account.
2021 * The closest size to what was given that the client window can
2024 *----------------------------------------------------------------------
2027 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
2029 int width
= *nwidth
;
2030 int height
= *nheight
;
2033 int minW
= 1, minH
= 1;
2034 int maxW
= wwin
->screen_ptr
->scr_width
*2;
2035 int maxH
= wwin
->screen_ptr
->scr_height
*2;
2036 int minAX
= -1, minAY
= -1;
2037 int maxAX
= -1, maxAY
= -1;
2041 if (wwin
->normal_hints
) {
2042 winc
= wwin
->normal_hints
->width_inc
;
2043 hinc
= wwin
->normal_hints
->height_inc
;
2044 minW
= wwin
->normal_hints
->min_width
;
2045 minH
= wwin
->normal_hints
->min_height
;
2046 maxW
= wwin
->normal_hints
->max_width
;
2047 maxH
= wwin
->normal_hints
->max_height
;
2048 if (wwin
->normal_hints
->flags
& PAspect
) {
2049 minAX
= wwin
->normal_hints
->min_aspect
.x
;
2050 minAY
= wwin
->normal_hints
->min_aspect
.y
;
2051 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
2052 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
2055 baseW
= wwin
->normal_hints
->base_width
;
2056 baseH
= wwin
->normal_hints
->base_height
;
2069 /* aspect ratio code borrowed from olwm */
2071 /* adjust max aspect ratio */
2072 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
2073 if (maxAX
> maxAY
) {
2074 height
= (width
* maxAY
) / maxAX
;
2075 if (height
> maxH
) {
2077 width
= (height
* maxAX
) / maxAY
;
2080 width
= (height
* maxAX
) / maxAY
;
2083 height
= (width
* maxAY
) / maxAX
;
2088 /* adjust min aspect ratio */
2089 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
2090 if (minAX
> minAY
) {
2091 height
= (width
* minAY
) / minAX
;
2092 if (height
< minH
) {
2094 width
= (height
* minAX
) / minAY
;
2097 width
= (height
* minAX
) / minAY
;
2100 height
= (width
* minAY
) / minAX
;
2107 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
2109 width
= (((width
- minW
) / winc
) * winc
) + minW
;
2113 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
2115 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
2118 /* broken stupid apps may cause preposterous values for these.. */
2127 wWindowCropSize(WWindow
*wwin
, int maxW
, int maxH
,
2128 int *width
, int *height
)
2130 int baseW
= 0, baseH
= 0;
2131 int winc
= 1, hinc
= 1;
2133 if (wwin
->normal_hints
) {
2134 baseW
= wwin
->normal_hints
->base_width
;
2135 baseH
= wwin
->normal_hints
->base_height
;
2137 winc
= wwin
->normal_hints
->width_inc
;
2138 hinc
= wwin
->normal_hints
->height_inc
;
2142 *width
= maxW
- (maxW
- baseW
) % winc
;
2145 *height
= maxH
- (maxH
- baseH
) % hinc
;
2150 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
2152 WScreen
*scr
= wwin
->screen_ptr
;
2156 if (workspace
>= scr
->workspace_count
|| workspace
< 0
2157 || workspace
== wwin
->frame
->workspace
)
2160 if (workspace
!= scr
->current_workspace
) {
2161 /* Sent to other workspace. Unmap window */
2162 if ((wwin
->flags
.mapped
2163 || wwin
->flags
.shaded
2164 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
2165 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
2167 wapp
= wApplicationOf(wwin
->main_window
);
2169 wapp
->last_workspace
= workspace
;
2171 if (wwin
->flags
.miniaturized
) {
2173 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
2174 wwin
->icon
->mapped
= 0;
2178 wSetFocusTo(scr
, NULL
);
2182 /* brought to current workspace. Map window */
2183 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
2185 XMapWindow(dpy
, wwin
->icon
->core
->window
);
2186 wwin
->icon
->mapped
= 1;
2188 } else if (!wwin
->flags
.mapped
&&
2189 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
2193 if (!IS_OMNIPRESENT(wwin
)) {
2194 int oldWorkspace
= wwin
->frame
->workspace
;
2196 wwin
->frame
->workspace
= workspace
;
2198 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void*)oldWorkspace
);
2208 wWindowSynthConfigureNotify(WWindow
*wwin
)
2212 sevent
.type
= ConfigureNotify
;
2213 sevent
.xconfigure
.display
= dpy
;
2214 sevent
.xconfigure
.event
= wwin
->client_win
;
2215 sevent
.xconfigure
.window
= wwin
->client_win
;
2217 sevent
.xconfigure
.x
= wwin
->client
.x
;
2218 sevent
.xconfigure
.y
= wwin
->client
.y
;
2219 sevent
.xconfigure
.width
= wwin
->client
.width
;
2220 sevent
.xconfigure
.height
= wwin
->client
.height
;
2222 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2223 if (WFLAGP(wwin
, no_titlebar
))
2224 sevent
.xconfigure
.above
= None
;
2226 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2228 sevent
.xconfigure
.override_redirect
= False
;
2229 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2231 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2238 *----------------------------------------------------------------------
2239 * wWindowConfigure--
2240 * Configures the frame, decorations and client window to the
2241 * specified geometry. The geometry is not checked for validity,
2242 * wWindowConstrainSize() must be used for that.
2243 * The size parameters are for the client window, but the position is
2245 * The client window receives a ConfigureNotify event, according
2246 * to what ICCCM says.
2252 * Window size and position are changed and client window receives
2253 * a ConfigureNotify event.
2254 *----------------------------------------------------------------------
2257 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2259 int req_x
, req_y
; /* new position of the frame */
2260 int req_width
, req_height
; /* new size of the client */
2262 int synth_notify
= False
;
2265 resize
= (req_width
!=wwin
->client
.width
2266 || req_height
!=wwin
->client
.height
);
2268 * if the window is being moved but not resized then
2269 * send a synthetic ConfigureNotify
2271 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2272 synth_notify
= True
;
2275 if (WFLAGP(wwin
, dont_move_off
))
2276 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2277 req_width
, req_height
);
2279 if (req_width
< MIN_WINDOW_SIZE
)
2280 req_width
= MIN_WINDOW_SIZE
;
2281 if (req_height
< MIN_WINDOW_SIZE
)
2282 req_height
= MIN_WINDOW_SIZE
;
2284 /* If growing, resize inner part before frame,
2285 * if shrinking, resize frame before.
2286 * This will prevent the frame (that can have a different color)
2287 * to be exposed, causing flicker */
2288 if (req_height
> wwin
->frame
->core
->height
2289 || req_width
> wwin
->frame
->core
->width
)
2290 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2292 if (wwin
->flags
.shaded
) {
2293 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2294 req_width
, wwin
->frame
->core
->height
);
2295 wwin
->old_geometry
.height
= req_height
;
2299 h
= req_height
+ wwin
->frame
->top_width
2300 + wwin
->frame
->bottom_width
;
2302 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2305 if (!(req_height
> wwin
->frame
->core
->height
2306 || req_width
> wwin
->frame
->core
->width
))
2307 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2309 wwin
->client
.x
= req_x
;
2310 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2311 wwin
->client
.width
= req_width
;
2312 wwin
->client
.height
= req_height
;
2314 wwin
->client
.x
= req_x
;
2315 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2317 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2319 wwin
->frame_x
= req_x
;
2320 wwin
->frame_y
= req_y
;
2321 if (!WFLAGP(wwin
, no_border
)) {
2322 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2323 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2327 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2328 wWindowSetShape(wwin
);
2333 wWindowSynthConfigureNotify(wwin
);
2339 wWindowMove(wwin
, req_x
, req_y
)
2341 int req_x
, req_y
; /* new position of the frame */
2343 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2344 int synth_notify
= False
;
2346 /* Send a synthetic ConfigureNotify event for every window movement. */
2347 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2348 synth_notify
= True
;
2351 /* A single synthetic ConfigureNotify event is sent at the end of
2352 * a completed (opaque) movement in moveres.c */
2355 if (WFLAGP(wwin
, dont_move_off
))
2356 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2357 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2359 wwin
->client
.x
= req_x
;
2360 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2361 if (!WFLAGP(wwin
, no_border
)) {
2362 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2363 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2366 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2368 wwin
->frame_x
= req_x
;
2369 wwin
->frame_y
= req_y
;
2371 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2373 wWindowSynthConfigureNotify(wwin
);
2379 wWindowUpdateButtonImages(WWindow
*wwin
)
2381 WScreen
*scr
= wwin
->screen_ptr
;
2382 Pixmap pixmap
, mask
;
2383 WFrameWindow
*fwin
= wwin
->frame
;
2385 if (WFLAGP(wwin
, no_titlebar
))
2388 /* miniaturize button */
2390 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2391 if (wwin
->wm_gnustep_attr
2392 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2393 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2395 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2396 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2401 if (fwin
->lbutton_image
2402 && (fwin
->lbutton_image
->image
!= pixmap
2403 || fwin
->lbutton_image
->mask
!= mask
)) {
2404 wPixmapDestroy(fwin
->lbutton_image
);
2405 fwin
->lbutton_image
= NULL
;
2408 if (!fwin
->lbutton_image
) {
2409 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2410 fwin
->lbutton_image
->client_owned
= 1;
2411 fwin
->lbutton_image
->client_owned_mask
= 1;
2414 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2415 wPixmapDestroy(fwin
->lbutton_image
);
2417 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2421 #ifdef XKB_BUTTON_HINT
2422 if (!WFLAGP(wwin
, no_language_button
)) {
2423 if (fwin
->languagebutton_image
&&
2424 !fwin
->languagebutton_image
->shared
) {
2425 wPixmapDestroy(fwin
->languagebutton_image
);
2427 fwin
->languagebutton_image
=
2428 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2434 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2435 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2437 if (!WFLAGP(wwin
, no_close_button
)) {
2438 if (wwin
->wm_gnustep_attr
2439 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2440 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2442 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2443 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2447 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2448 || fwin
->rbutton_image
->mask
!= mask
)) {
2449 wPixmapDestroy(fwin
->rbutton_image
);
2450 fwin
->rbutton_image
= NULL
;
2453 if (!fwin
->rbutton_image
) {
2454 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2455 fwin
->rbutton_image
->client_owned
= 1;
2456 fwin
->rbutton_image
->client_owned_mask
= 1;
2459 } else if (WFLAGP(wwin
, kill_close
)) {
2461 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2462 wPixmapDestroy(fwin
->rbutton_image
);
2464 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2466 } else if (MGFLAGP(wwin
, broken_close
)) {
2468 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2469 wPixmapDestroy(fwin
->rbutton_image
);
2471 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2475 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2476 wPixmapDestroy(fwin
->rbutton_image
);
2478 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2482 /* force buttons to be redrawn */
2483 fwin
->flags
.need_texture_change
= 1;
2484 wFrameWindowPaint(fwin
);
2489 *---------------------------------------------------------------------------
2490 * wWindowConfigureBorders--
2491 * Update window border configuration according to attribute flags.
2493 *---------------------------------------------------------------------------
2496 wWindowConfigureBorders(WWindow
*wwin
)
2502 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2503 #ifdef XKB_BUTTON_HINT
2504 flags
|= WFF_LANGUAGE_BUTTON
;
2506 if (!WFLAGP(wwin
, no_titlebar
))
2507 flags
|= WFF_TITLEBAR
;
2508 if (!WFLAGP(wwin
, no_resizebar
) && !WFLAGP(wwin
, no_resizable
))
2509 flags
|= WFF_RESIZEBAR
;
2510 if (!WFLAGP(wwin
, no_border
))
2511 flags
|= WFF_BORDER
;
2512 if (wwin
->flags
.shaded
)
2513 flags
|= WFF_IS_SHADED
;
2515 oldh
= wwin
->frame
->top_width
;
2516 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2517 if (oldh
!= wwin
->frame
->top_width
) {
2518 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2520 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2521 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2522 wwin
->client
.width
, wwin
->client
.height
);
2526 if (!WFLAGP(wwin
, no_miniaturize_button
)
2527 && wwin
->frame
->flags
.hide_left_button
)
2528 flags
|= WFF_LEFT_BUTTON
;
2530 #ifdef XKB_BUTTON_HINT
2531 if (!WFLAGP(wwin
, no_language_button
)
2532 && wwin
->frame
->flags
.hide_language_button
)
2533 flags
|= WFF_LANGUAGE_BUTTON
;
2536 if (!WFLAGP(wwin
, no_close_button
)
2537 && wwin
->frame
->flags
.hide_right_button
)
2538 flags
|= WFF_RIGHT_BUTTON
;
2541 wWindowUpdateButtonImages(wwin
);
2542 wFrameWindowShowButton(wwin
->frame
, flags
);
2546 if (WFLAGP(wwin
, no_miniaturize_button
)
2547 && !wwin
->frame
->flags
.hide_left_button
)
2548 flags
|= WFF_LEFT_BUTTON
;
2550 #ifdef XKB_BUTTON_HINT
2551 if (WFLAGP(wwin
, no_language_button
)
2552 && !wwin
->frame
->flags
.hide_language_button
)
2553 flags
|= WFF_LANGUAGE_BUTTON
;
2556 if (WFLAGP(wwin
, no_close_button
)
2557 && !wwin
->frame
->flags
.hide_right_button
)
2558 flags
|= WFF_RIGHT_BUTTON
;
2561 wFrameWindowHideButton(wwin
->frame
, flags
);
2564 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2565 wWindowSetShape(wwin
);
2573 wWindowSaveState(WWindow
*wwin
)
2578 memset(data
, 0, sizeof(CARD32
)*10);
2579 data
[0] = wwin
->frame
->workspace
;
2580 data
[1] = wwin
->flags
.miniaturized
;
2581 data
[2] = wwin
->flags
.shaded
;
2582 data
[3] = wwin
->flags
.hidden
;
2583 data
[4] = wwin
->flags
.maximized
;
2584 if (wwin
->flags
.maximized
== 0) {
2585 data
[5] = wwin
->frame_x
;
2586 data
[6] = wwin
->frame_y
;
2587 data
[7] = wwin
->frame
->core
->width
;
2588 data
[8] = wwin
->frame
->core
->height
;
2590 data
[5] = wwin
->old_geometry
.x
;
2591 data
[6] = wwin
->old_geometry
.y
;
2592 data
[7] = wwin
->old_geometry
.width
;
2593 data
[8] = wwin
->old_geometry
.height
;
2596 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2597 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2598 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2601 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2602 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2603 (unsigned char *)data
, 10);
2608 getSavedState(Window window
, WSavedState
**state
)
2612 unsigned long nitems_ret
;
2613 unsigned long bytes_after_ret
;
2616 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2617 True
, _XA_WINDOWMAKER_STATE
,
2618 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2619 (unsigned char **)&data
)!=Success
|| !data
)
2622 *state
= wmalloc(sizeof(WSavedState
));
2624 (*state
)->workspace
= data
[0];
2625 (*state
)->miniaturized
= data
[1];
2626 (*state
)->shaded
= data
[2];
2627 (*state
)->hidden
= data
[3];
2628 (*state
)->maximized
= data
[4];
2629 (*state
)->x
= data
[5];
2630 (*state
)->y
= data
[6];
2631 (*state
)->w
= data
[7];
2632 (*state
)->h
= data
[8];
2633 (*state
)->window_shortcuts
= data
[9];
2637 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2646 wWindowClearShape(WWindow
*wwin
)
2648 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2649 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2654 wWindowSetShape(WWindow
*wwin
)
2658 #ifdef OPTIMIZE_SHAPE
2663 /* only shape is the client's */
2664 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2668 /* Get array of rectangles describing the shape mask */
2669 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2675 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2681 /* insert our decoration rectangles in the rect list */
2682 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2685 if (!WFLAGP(wwin
, no_titlebar
)) {
2687 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2688 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2689 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2692 if (!WFLAGP(wwin
, no_resizebar
)) {
2694 urec
[count
].y
= wwin
->frame
->core
->height
2695 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2696 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2697 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2701 /* shape our frame window */
2702 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2703 0, wwin
->frame
->top_width
, urec
, count
,
2704 ShapeSet
, Unsorted
);
2710 #endif /* OPTIMIZE_SHAPE */
2712 if (!WFLAGP(wwin
, no_titlebar
)) {
2715 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2716 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2719 if (!WFLAGP(wwin
, no_resizebar
)) {
2721 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2722 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2723 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2727 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2728 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2730 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2731 0, wwin
->frame
->top_width
, wwin
->client_win
,
2732 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2737 /* ====================================================================== */
2740 getFocusMode(WWindow
*wwin
)
2744 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2745 if (wwin
->wm_hints
->input
== True
) {
2746 if (wwin
->protocols
.TAKE_FOCUS
)
2747 mode
= WFM_LOCALLY_ACTIVE
;
2751 if (wwin
->protocols
.TAKE_FOCUS
)
2752 mode
= WFM_GLOBALLY_ACTIVE
;
2754 mode
= WFM_NO_INPUT
;
2764 wWindowSetKeyGrabs(WWindow
*wwin
)
2769 for (i
=0; i
<WKBD_LAST
; i
++) {
2770 key
= &wKeyBindings
[i
];
2772 if (key
->keycode
==0)
2774 if (key
->modifier
!=AnyModifier
) {
2775 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2776 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2778 /* Also grab all modifier combinations possible that include,
2779 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2780 * work even if the NumLock/ScrollLock key is on.
2782 wHackedGrabKey(key
->keycode
, key
->modifier
,
2783 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2787 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2788 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2792 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2799 wWindowResetMouseGrabs(WWindow
*wwin
)
2801 /* Mouse grabs can't be done on the client window because of
2802 * ICCCM and because clients that try to do the same will crash.
2804 * But there is a problem wich makes tbar buttons of unfocused
2805 * windows not usable as the click goes to the frame window instead
2806 * of the button itself. Must figure a way to fix that.
2809 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2811 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2812 /* grabs for Meta+drag */
2813 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2814 True
, ButtonPressMask
, GrabModeSync
,
2815 GrabModeAsync
, None
, None
);
2818 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2819 && !wwin
->flags
.is_gnustep
) {
2820 /* the passive grabs to focus the window */
2821 /* if (wPreferences.focus_mode == WKF_CLICK) */
2822 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2823 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2831 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2833 if (attr
->flags
& GSExtraFlagsAttr
) {
2834 if (MGFLAGP(wwin
, broken_close
) !=
2835 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2836 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2837 wWindowUpdateButtonImages(wwin
);
2844 wWindowAddSavedState(char *instance
, char *class, char *command
,
2845 pid_t pid
, WSavedState
*state
)
2847 WWindowState
*wstate
;
2849 wstate
= malloc(sizeof(WWindowState
));
2853 memset(wstate
, 0, sizeof(WWindowState
));
2856 wstate
->instance
= wstrdup(instance
);
2858 wstate
->class = wstrdup(class);
2860 wstate
->command
= wstrdup(command
);
2861 wstate
->state
= state
;
2863 wstate
->next
= windowState
;
2864 windowState
= wstate
;
2867 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2875 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2879 wWindowGetSavedState(Window win
)
2881 char *instance
, *class, *command
=NULL
;
2882 WWindowState
*wstate
= windowState
;
2889 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2891 command
= wtokenjoin(argv
, argc
);
2892 XFreeStringList(argv
);
2897 if (PropGetWMClass(win
, &class, &instance
)) {
2899 if (SAME(instance
, wstate
->instance
) &&
2900 SAME(class, wstate
->class) &&
2901 SAME(command
, wstate
->command
)) {
2904 wstate
= wstate
->next
;
2911 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2915 if (command
) wfree(command
);
2916 if (instance
) XFree(instance
);
2917 if (class) XFree(class);
2924 wWindowDeleteSavedState(WMagicNumber id
)
2926 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2928 if (!wstate
|| !windowState
)
2933 windowState
= wstate
->next
;
2935 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2936 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2938 if (wstate
->instance
) wfree(wstate
->instance
);
2939 if (wstate
->class) wfree(wstate
->class);
2940 if (wstate
->command
) wfree(wstate
->command
);
2941 wfree(wstate
->state
);
2945 if (tmp
->next
==wstate
) {
2946 tmp
->next
=wstate
->next
;
2948 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2949 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2951 if (wstate
->instance
) wfree(wstate
->instance
);
2952 if (wstate
->class) wfree(wstate
->class);
2953 if (wstate
->command
) wfree(wstate
->command
);
2954 wfree(wstate
->state
);
2965 wWindowDeleteSavedStatesForPID(pid_t pid
)
2967 WWindowState
*tmp
, *wstate
;
2973 if (tmp
->pid
== pid
) {
2974 wstate
= windowState
;
2975 windowState
= tmp
->next
;
2977 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2978 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2980 if (wstate
->instance
) wfree(wstate
->instance
);
2981 if (wstate
->class) wfree(wstate
->class);
2982 if (wstate
->command
) wfree(wstate
->command
);
2983 wfree(wstate
->state
);
2987 if (tmp
->next
->pid
==pid
) {
2989 tmp
->next
= wstate
->next
;
2991 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2992 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2994 if (wstate
->instance
) wfree(wstate
->instance
);
2995 if (wstate
->class) wfree(wstate
->class);
2996 if (wstate
->command
) wfree(wstate
->command
);
2997 wfree(wstate
->state
);
3008 wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
3010 wwin
->flags
.omnipresent
= flag
;
3012 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
3016 /* ====================================================================== */
3019 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3021 WWindow
*wwin
= data
;
3023 #ifndef NUMLOCK_HACK
3024 if ((event
->xbutton
.state
& ValidModMask
)
3025 != (event
->xbutton
.state
& ~LockMask
)) {
3026 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3027 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3031 event
->xbutton
.state
&= ValidModMask
;
3033 CloseWindowMenu(wwin
->screen_ptr
);
3035 if (wPreferences
.focus_mode
==WKF_CLICK
3036 && !(event
->xbutton
.state
&ControlMask
)
3037 && !WFLAGP(wwin
, no_focusable
)) {
3038 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3041 if (event
->xbutton
.button
== Button1
)
3042 wRaiseFrame(wwin
->frame
->core
);
3044 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
3045 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
3046 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3047 GrabModeAsync
, GrabModeAsync
, None
,
3048 None
, CurrentTime
)!=GrabSuccess
) {
3050 wwarning("pointer grab failed for window move");
3056 if (event
->xbutton
.state
& MOD_MASK
) {
3057 /* move the window */
3058 wMouseMoveWindow(wwin
, event
);
3059 XUngrabPointer(dpy
, CurrentTime
);
3061 wMouseResizeWindow(wwin
, event
);
3062 XUngrabPointer(dpy
, CurrentTime
);
3069 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3071 WWindow
*wwin
= data
;
3073 event
->xbutton
.state
&= ValidModMask
;
3075 if (event
->xbutton
.button
==Button1
) {
3076 if (event
->xbutton
.state
== 0) {
3077 if (!WFLAGP(wwin
, no_shadeable
)) {
3079 if (wwin
->flags
.shaded
)
3080 wUnshadeWindow(wwin
);
3087 if (event
->xbutton
.state
& ControlMask
)
3088 dir
|= MAX_VERTICAL
;
3090 if (event
->xbutton
.state
& ShiftMask
) {
3091 dir
|= MAX_HORIZONTAL
;
3092 if (!(event
->xbutton
.state
& ControlMask
))
3093 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3096 /* maximize window */
3097 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
3098 int ndir
= dir
^ wwin
->flags
.maximized
;
3099 if (wwin
->flags
.maximized
!= 0)
3100 wUnmaximizeWindow(wwin
);
3102 wMaximizeWindow(wwin
, ndir
);
3105 } else if (event
->xbutton
.button
==Button3
) {
3106 if (event
->xbutton
.state
& MOD_MASK
) {
3107 wHideOtherApplications(wwin
);
3109 } else if (event
->xbutton
.button
==Button2
) {
3110 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3111 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
3113 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
3114 wUnshadeWindow(wwin
);
3120 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3122 WWindow
*wwin
= desc
->parent
;
3124 event
->xbutton
.state
&= ValidModMask
;
3126 CloseWindowMenu(wwin
->screen_ptr
);
3128 if (/*wPreferences.focus_mode==WKF_CLICK
3129 &&*/ !(event
->xbutton
.state
&ControlMask
)
3130 && !WFLAGP(wwin
, no_focusable
)) {
3131 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3133 if (event
->xbutton
.button
== Button1
) {
3134 wRaiseFrame(wwin
->frame
->core
);
3137 if (event
->xbutton
.state
& MOD_MASK
) {
3138 /* move the window */
3139 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
3140 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3141 GrabModeAsync
, GrabModeAsync
, None
,
3142 None
, CurrentTime
)!=GrabSuccess
) {
3144 wwarning("pointer grab failed for window move");
3148 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
3149 wMouseResizeWindow(wwin
, event
);
3151 wMouseMoveWindow(wwin
, event
);
3152 XUngrabPointer(dpy
, CurrentTime
);
3158 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3160 WWindow
*wwin
= (WWindow
*)data
;
3162 #ifndef NUMLOCK_HACK
3163 if ((event
->xbutton
.state
& ValidModMask
)
3164 != (event
->xbutton
.state
& ~LockMask
)) {
3165 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3166 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3169 event
->xbutton
.state
&= ValidModMask
;
3171 CloseWindowMenu(wwin
->screen_ptr
);
3173 if (wPreferences
.focus_mode
==WKF_CLICK
3174 && !(event
->xbutton
.state
&ControlMask
)
3175 && !WFLAGP(wwin
, no_focusable
)) {
3176 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3179 if (event
->xbutton
.button
== Button1
3180 || event
->xbutton
.button
== Button2
) {
3182 if (event
->xbutton
.button
== Button1
) {
3183 if (event
->xbutton
.state
& MOD_MASK
) {
3184 wLowerFrame(wwin
->frame
->core
);
3186 wRaiseFrame(wwin
->frame
->core
);
3189 if ((event
->xbutton
.state
& ShiftMask
)
3190 && !(event
->xbutton
.state
& ControlMask
)) {
3191 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3194 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3195 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3196 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3197 GrabModeAsync
, GrabModeAsync
, None
,
3198 None
, CurrentTime
)!=GrabSuccess
) {
3200 wwarning("pointer grab failed for window move");
3205 /* move the window */
3206 wMouseMoveWindow(wwin
, event
);
3208 XUngrabPointer(dpy
, CurrentTime
);
3209 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
3210 && !wwin
->flags
.internal_window
3211 && !WCHECK_STATE(WSTATE_MODAL
)) {
3212 WObjDescriptor
*desc
;
3214 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3215 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3216 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3217 GrabModeAsync
, GrabModeAsync
, None
,
3218 None
, CurrentTime
)!=GrabSuccess
) {
3220 wwarning("pointer grab failed for window move");
3225 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
3226 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3228 /* allow drag select */
3229 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3230 event
->xany
.send_event
= True
;
3231 (*desc
->handle_mousedown
)(desc
, event
);
3233 XUngrabPointer(dpy
, CurrentTime
);
3240 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3242 WWindow
*wwin
= data
;
3244 event
->xbutton
.state
&= ValidModMask
;
3246 CloseWindowMenu(wwin
->screen_ptr
);
3248 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3251 /* if control-click, kill the client */
3252 if (event
->xbutton
.state
& ControlMask
) {
3256 if (wwin
->flags
.olwm_push_pin_out
) {
3258 wwin
->flags
.olwm_push_pin_out
= 0;
3260 wOLWMChangePushpinState(wwin
, True
);
3262 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3267 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3268 /* send delete message */
3269 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3276 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3278 WWindow
*wwin
= data
;
3280 CloseWindowMenu(wwin
->screen_ptr
);
3282 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3285 /* send delete message */
3286 if (wwin
->protocols
.DELETE_WINDOW
) {
3287 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3294 #ifdef XKB_BUTTON_HINT
3296 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3298 WWindow
*wwin
= data
;
3299 WFrameWindow
*fwin
= wwin
->frame
;
3300 WScreen
*scr
= fwin
->screen_ptr
;
3301 XkbStateRec staterec
;
3304 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3306 tl
= wwin
->frame
->languagemode
;
3307 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3308 wwin
->frame
->last_languagemode
= tl
;
3309 wSetFocusTo(scr
, wwin
);
3310 wwin
->frame
->languagebutton_image
=
3311 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3312 wwin
->frame
->languagemode
];
3313 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3314 if (event
->xbutton
.button
== Button3
)
3316 wRaiseFrame(fwin
->core
);
3322 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3324 WWindow
*wwin
= data
;
3326 event
->xbutton
.state
&= ValidModMask
;
3328 CloseWindowMenu(wwin
->screen_ptr
);
3330 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3333 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3334 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3338 if ((event
->xbutton
.state
& ControlMask
) ||
3339 (event
->xbutton
.button
== Button3
)) {
3341 wapp
= wApplicationOf(wwin
->main_window
);
3342 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3343 wHideApplication(wapp
);
3344 } else if (event
->xbutton
.state
==0) {
3345 wIconifyWindow(wwin
);