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 wwin
->client_flags
.no_focusable
= 1;
506 wWindowCanReceiveFocus(WWindow
*wwin
)
508 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
510 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
512 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
520 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
524 w1
= wwin
->frame
->core
->width
;
525 h1
= wwin
->frame
->core
->height
;
526 w2
= obscured
->frame
->core
->width
;
527 h2
= obscured
->frame
->core
->height
;
529 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
530 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
533 if (wwin
->frame_x
+ w1
< obscured
->frame_x
534 || wwin
->frame_y
+ h1
< obscured
->frame_y
535 || wwin
->frame_x
> obscured
->frame_x
+ w2
536 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
545 createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
547 XClassHint
*classHint
;
553 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
555 classHint
= XAllocClassHint();
556 classHint
->res_name
= instance
;
557 classHint
->res_class
= class;
558 XSetClassHint(dpy
, leader
, classHint
);
561 /* inherit these from the original leader if available */
562 hints
= XGetWMHints(dpy
, win
);
564 hints
= XAllocWMHints();
567 /* set window group leader to self */
568 hints
->window_group
= leader
;
569 hints
->flags
|= WindowGroupHint
;
570 XSetWMHints(dpy
, leader
, hints
);
573 if (XGetCommand(dpy
, win
, &argv
, &argc
)!=0 && argc
> 0) {
574 XSetCommand(dpy
, leader
, argv
, argc
);
575 XFreeStringList(argv
);
583 matchIdentifier(void *item
, void *cdata
)
585 return (strcmp(((WFakeGroupLeader
*)item
)->identifier
, (char*)cdata
)==0);
590 *----------------------------------------------------------------
592 * reparents the window and allocates a descriptor for it.
593 * Window manager hints and other hints are fetched to configure
594 * the window decoration attributes and others. User preferences
595 * for the window are used if available, to configure window
596 * decorations and some behaviour.
597 * If in startup, windows that are override redirect,
598 * unmapped and never were managed and are Withdrawn are not
602 * the new window descriptor
605 * The window is reparented and appropriate notification
606 * is done to the client. Input mask for the window is setup.
607 * The window descriptor is also associated with various window
608 * contexts and inserted in the head of the window list.
609 * Event handler contexts are associated for some objects
610 * (buttons, titlebar and resizebar)
612 *----------------------------------------------------------------
615 wManageWindow(WScreen
*scr
, Window window
)
619 unsigned width
, height
;
620 XWindowAttributes wattribs
;
621 XSetWindowAttributes attribs
;
622 WWindowState
*win_state
;
623 WWindow
*transientOwner
= NULL
;
629 Bool withdraw
= False
;
633 /* XGrabServer(dpy); */
635 /* make sure the window is still there */
636 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
641 /* if it's an override-redirect, ignore it */
642 if (wattribs
.override_redirect
) {
647 wm_state
= PropGetWindowState(window
);
649 /* if it's startup and the window is unmapped, don't manage it */
650 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
655 if (!wFetchName(dpy
, window
, &title
)) {
660 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
665 #endif /* KWM_HINTS */
668 wwin
= wWindowCreate();
670 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
673 printf("managing window %x\n", (unsigned)window
);
677 if (wShapeSupported
) {
682 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
683 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
684 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
685 wwin
->flags
.shaped
= b_shaped
;
690 *--------------------------------------------------
692 * Get hints and other information in properties
694 *--------------------------------------------------
696 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
698 /* setup descriptor */
699 wwin
->client_win
= window
;
700 wwin
->screen_ptr
= scr
;
702 wwin
->old_border_width
= wattribs
.border_width
;
704 wwin
->event_mask
= CLIENT_EVENTS
;
705 attribs
.event_mask
= CLIENT_EVENTS
;
706 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
707 attribs
.save_under
= False
;
708 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
709 |CWSaveUnder
, &attribs
);
710 XSetWindowBorderWidth(dpy
, window
, 0);
712 /* get hints from GNUstep app */
713 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
714 wwin
->flags
.is_gnustep
= 1;
716 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
717 wwin
->wm_gnustep_attr
= NULL
;
720 wwin
->client_leader
= PropGetClientLeader(window
);
721 if (wwin
->client_leader
!=None
)
722 wwin
->main_window
= wwin
->client_leader
;
724 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
726 if (wwin
->wm_hints
) {
727 if (wwin
->wm_hints
->flags
& StateHint
) {
729 if (wwin
->wm_hints
->initial_state
== IconicState
) {
731 wwin
->flags
.miniaturized
= 1;
733 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
739 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
740 wwin
->group_id
= wwin
->wm_hints
->window_group
;
741 /* window_group has priority over CLIENT_LEADER */
742 wwin
->main_window
= wwin
->group_id
;
744 wwin
->group_id
= None
;
747 if (wwin
->wm_hints
->flags
& UrgencyHint
)
748 wwin
->flags
.urgent
= 1;
750 wwin
->group_id
= None
;
753 PropGetProtocols(window
, &wwin
->protocols
);
755 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
756 wwin
->transient_for
= None
;
758 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
759 wwin
->transient_for
= scr
->root_win
;
761 transientOwner
= wWindowFor(wwin
->transient_for
);
762 if (transientOwner
&& transientOwner
->main_window
!=None
) {
763 wwin
->main_window
= transientOwner
->main_window
;
765 wwin->main_window = None;
770 /* guess the focus mode */
771 wwin
->focus_mode
= getFocusMode(wwin
);
773 /* get geometry stuff */
774 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
776 /* printf( "wManageWindow: %d %d %d %d\n", x, y, width, height);*/
778 /* get colormap windows */
779 GetColormapWindows(wwin
);
782 *--------------------------------------------------
784 * Setup the decoration/window attributes and
787 *--------------------------------------------------
790 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
793 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
794 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
796 transientOwner
= wWindowFor(wwin
->group_id
);
798 if (transientOwner
) {
799 wwin
->transient_for
= wwin
->group_id
;
801 /* transients can't be iconified or maximized */
802 if (wwin
->transient_for
) {
803 WSETUFLAG(wwin
, no_miniaturizable
, 1);
804 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
808 #endif /* OLWM_HINTS */
810 /* Make broken apps behave as a nice app. */
811 if (WFLAGP(wwin
, emulate_appicon
)) {
812 wwin
->main_window
= wwin
->client_win
;
815 wwin
->orig_main_window
= wwin
->main_window
;
817 if (wwin
->flags
.is_gnustep
) {
818 WSETUFLAG(wwin
, shared_appicon
, 0);
821 if (wwin
->main_window
) {
822 extern Atom _XA_WINDOWMAKER_MENU
;
823 XTextProperty text_prop
;
825 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
,
826 _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)
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
,
880 fPtr
->origLeader
= None
;
881 fPtr
->retainCount
= 1;
883 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
886 if (ADEQUATE(wwin
->group_id
)) {
888 fPtr
->origLeader
= wwin
->group_id
;
889 } else if (ADEQUATE(wwin
->client_leader
)) {
891 fPtr
->origLeader
= wwin
->client_leader
;
892 } else if (ADEQUATE(wwin
->main_window
)) {
894 fPtr
->origLeader
= wwin
->main_window
;
897 if (ADEQUATE(wwin
->main_window
)) {
899 fPtr
->origLeader
= wwin
->main_window
;
902 wwin
->fake_group
= fPtr
;
903 /*wwin->group_id = fPtr->leader;*/
904 wwin
->main_window
= fPtr
->leader
;
916 *------------------------------------------------------------
918 * Setup the initial state of the window
920 *------------------------------------------------------------
923 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
924 wwin
->flags
.miniaturized
= 1;
927 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
928 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
936 bla
= wGNOMECheckInitialClientState(wwin
);
940 wKWMCheckClientInitialState(wwin
);
944 /* apply previous state if it exists and we're in startup */
945 if (scr
->flags
.startup
&& wm_state
>= 0) {
947 if (wm_state
== IconicState
) {
949 wwin
->flags
.miniaturized
= 1;
951 } else if (wm_state
== WithdrawnState
) {
957 /* if there is a saved state (from file), restore it */
959 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
960 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
962 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
964 if (win_state
&& !withdraw
) {
966 if (win_state
->state
->hidden
>0)
967 wwin
->flags
.hidden
= win_state
->state
->hidden
;
969 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
970 wwin
->flags
.shaded
= win_state
->state
->shaded
;
972 if (win_state
->state
->miniaturized
>0 &&
973 !WFLAGP(wwin
, no_miniaturizable
)) {
974 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
977 if (!IS_OMNIPRESENT(wwin
)) {
978 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
980 if (w
< 0 || w
>= scr
->workspace_count
) {
981 workspace
= win_state
->state
->workspace
;
982 if (workspace
>= scr
->workspace_count
)
983 workspace
= scr
->current_workspace
;
988 workspace
= scr
->current_workspace
;
992 /* if we're restarting, restore saved state (from hints).
993 * This will overwrite previous */
997 if (getSavedState(window
, &wstate
)) {
998 wwin
->flags
.shaded
= wstate
->shaded
;
999 wwin
->flags
.hidden
= wstate
->hidden
;
1000 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
1001 wwin
->flags
.maximized
= wstate
->maximized
;
1002 if (wwin
->flags
.maximized
) {
1003 wwin
->old_geometry
.x
= wstate
->x
;
1004 wwin
->old_geometry
.y
= wstate
->y
;
1005 wwin
->old_geometry
.width
= wstate
->w
;
1006 wwin
->old_geometry
.height
= wstate
->h
;
1009 workspace
= wstate
->workspace
;
1014 /* restore window shortcut */
1015 if (wstate
!= NULL
|| win_state
!= NULL
) {
1018 if (win_state
!= NULL
)
1019 mask
= win_state
->state
->window_shortcuts
;
1021 if (wstate
!= NULL
&& mask
== 0)
1022 mask
= wstate
->window_shortcuts
;
1027 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
1028 if (mask
& (1<<i
)) {
1029 if (!scr
->shortcutWindows
[i
])
1030 scr
->shortcutWindows
[i
] = WMCreateArray(4);
1032 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
1037 if (wstate
!= NULL
) {
1042 /* don't let transients start miniaturized if their owners are not */
1043 if (transientOwner
&& !transientOwner
->flags
.miniaturized
1044 && wwin
->flags
.miniaturized
&& !withdraw
) {
1045 wwin
->flags
.miniaturized
= 0;
1047 wwin
->wm_hints
->initial_state
= NormalState
;
1050 /* set workspace on which the window starts */
1051 if (workspace
>= 0) {
1052 if (workspace
> scr
->workspace_count
-1) {
1053 workspace
= workspace
% scr
->workspace_count
;
1058 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
1060 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1065 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1067 workspace
= transientOwner
->frame
->workspace
;
1071 workspace
= scr
->current_workspace
;
1076 /* setup window geometry */
1077 if (win_state
&& win_state
->state
->w
> 0) {
1078 width
= win_state
->state
->w
;
1079 height
= win_state
->state
->h
;
1081 wWindowConstrainSize(wwin
, &width
, &height
);
1083 /* do not ask for window placement if the window is
1084 * transient, during startup, if the initial workspace is another one
1085 * or if the window wants to start iconic.
1086 * If geometry was saved, restore it. */
1088 Bool dontBring
= False
;
1090 if (win_state
&& win_state
->state
->w
> 0) {
1091 x
= win_state
->state
->x
;
1092 y
= win_state
->state
->y
;
1093 } else if ((wwin
->transient_for
==None
1094 || wPreferences
.window_placement
!=WPM_MANUAL
)
1095 && !scr
->flags
.startup
1096 && workspace
== scr
->current_workspace
1097 && !wwin
->flags
.miniaturized
1098 && !wwin
->flags
.maximized
1099 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
1101 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1102 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
1106 x
= transientOwner
->frame_x
+
1107 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
1108 y
= transientOwner
->frame_y
+
1109 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
1112 * limit transient windows to be inside their parent's head
1114 rect
.pos
.x
= transientOwner
->frame_x
;
1115 rect
.pos
.y
= transientOwner
->frame_y
;
1116 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1117 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1119 head
= wGetHeadForRect(scr
, rect
);
1120 rect
= wGetRectForHead(scr
, head
);
1124 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1125 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1129 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1130 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1133 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1135 if (wPreferences
.window_placement
== WPM_MANUAL
)
1138 else if (scr
->xine_count
&&
1139 wwin
->normal_hints
->flags
& PPosition
) {
1145 * Make spash screens come out in the center of a head
1146 * trouble is that most splashies never get here
1147 * they are managed trough atoms but god knows where.
1148 * Dan, do you know ?
1150 * Most of them are not managed, they are set
1151 * OverrideRedirect, which means we can't do anything about
1155 printf( "xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
)/2);
1156 printf( "xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
)/2);
1158 if ( (unsigned)(x
+ (width
- scr
->scr_width
)/2 + 10) < 20 &&
1159 (unsigned)(y
+ (height
- scr
->scr_height
)/2 + 10) < 20) {
1167 * xinerama checks for: across head and dead space
1171 rect
.size
.width
= width
;
1172 rect
.size
.height
= height
;
1174 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1176 if (flags
& XFLAG_DEAD
)
1179 if (flags
& XFLAG_MULTIPLE
)
1183 switch (reposition
) {
1185 head
= wGetHeadForPointerLocation(scr
);
1186 rect
= wGetRectForHead(scr
, head
);
1188 x
= rect
.pos
.x
+ (x
* rect
.size
.width
)/scr
->scr_width
;
1189 y
= rect
.pos
.y
+ (y
* rect
.size
.height
)/scr
->scr_height
;
1193 rect
= wGetRectForHead(scr
, head
);
1197 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1198 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1202 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1203 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1212 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1213 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1216 if (wwin
->flags
.urgent
) {
1217 if (!IS_OMNIPRESENT(wwin
))
1218 wwin
->flags
.omnipresent
^= 1;
1222 *--------------------------------------------------
1224 * Create frame, borders and do reparenting
1226 *--------------------------------------------------
1228 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1229 #ifdef XKB_BUTTON_HINT
1230 if (wPreferences
.modelock
)
1231 foo
|= WFF_LANGUAGE_BUTTON
;
1233 if (!WFLAGP(wwin
, no_titlebar
))
1234 foo
|= WFF_TITLEBAR
;
1235 if (!WFLAGP(wwin
, no_resizebar
))
1236 foo
|= WFF_RESIZEBAR
;
1237 if (!WFLAGP(wwin
, no_border
))
1240 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1241 x
, y
, width
, height
,
1242 &wPreferences
.window_title_clearance
, foo
,
1243 scr
->window_title_texture
,
1244 scr
->resizebar_texture
,
1245 scr
->window_title_color
,
1248 wwin
->frame
->flags
.is_client_window_frame
= 1;
1249 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1251 /* setup button images */
1252 wWindowUpdateButtonImages(wwin
);
1254 /* hide unused buttons */
1256 if (WFLAGP(wwin
, no_close_button
))
1257 foo
|= WFF_RIGHT_BUTTON
;
1258 if (WFLAGP(wwin
, no_miniaturize_button
))
1259 foo
|= WFF_LEFT_BUTTON
;
1260 #ifdef XKB_BUTTON_HINT
1261 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1262 foo
|= WFF_LANGUAGE_BUTTON
;
1265 wFrameWindowHideButton(wwin
->frame
, foo
);
1267 wwin
->frame
->child
= wwin
;
1270 /* emulate olwm push pin. Make the button look as pushed-in for
1271 * the pinned-out state. When the button is clicked, it will
1272 * revert to the normal position, which means the pin is pinned-in.
1274 if (wwin
->flags
.olwm_push_pin_out
)
1275 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1276 #endif /* OLWM_HINTS */
1279 wwin
->frame
->workspace
= workspace
;
1281 wwin
->frame
->on_click_left
= windowIconifyClick
;
1282 #ifdef XKB_BUTTON_HINT
1283 if (wPreferences
.modelock
)
1284 wwin
->frame
->on_click_language
= windowLanguageClick
;
1287 wwin
->frame
->on_click_right
= windowCloseClick
;
1288 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1290 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1291 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1293 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1296 XSelectInput(dpy
, wwin
->client_win
,
1297 wwin
->event_mask
& ~StructureNotifyMask
);
1299 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1300 0, wwin
->frame
->top_width
);
1302 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1308 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1310 /* if gravity is to the south, account for the border sizes */
1312 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1316 * wWindowConfigure() will init the client window's size
1317 * (wwin->client.{width,height}) and all other geometry
1318 * related variables (frame_x,frame_y)
1320 wWindowConfigure(wwin
, x
, y
, width
, height
);
1322 /* to make sure the window receives it's new position after reparenting */
1323 wWindowSynthConfigureNotify(wwin
);
1326 *--------------------------------------------------
1328 * Setup descriptors and save window to internal
1331 *--------------------------------------------------
1334 if (wwin
->main_window
!=None
) {
1338 /* Leader windows do not necessary set themselves as leaders.
1339 * If this is the case, point the leader of this window to
1341 leader
= wWindowFor(wwin
->main_window
);
1342 if (leader
&& leader
->main_window
==None
) {
1343 leader
->main_window
= leader
->client_win
;
1345 app
= wApplicationCreate(scr
, wwin
->main_window
);
1347 app
->last_workspace
= workspace
;
1349 app
->main_window_desc
->fake_group
= wwin
->fake_group
;
1352 * Do application specific stuff, like setting application
1356 if (wwin
->flags
.hidden
) {
1357 /* if the window was set to hidden because it was hidden
1358 * in a previous incarnation and that state was restored */
1359 app
->flags
.hidden
= 1;
1360 } else if (app
->flags
.hidden
) {
1361 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1362 wwin
->flags
.hidden
= 1;
1364 wUnhideApplication(app
, False
, False
);
1371 /* setup the frame descriptor */
1372 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1373 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1374 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1376 /* don't let windows go away if we die */
1377 XAddToSaveSet(dpy
, window
);
1379 XLowerWindow(dpy
, window
);
1381 /* if window is in this workspace and should be mapped, then map it */
1382 if (!wwin
->flags
.miniaturized
1383 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1384 && !wwin
->flags
.hidden
&& !withdraw
) {
1386 /* The following "if" is to avoid crashing of clients that expect
1387 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1388 * after the return from this function.
1390 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1391 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1393 wClientSetState(wwin
, NormalState
, None
);
1397 /* if not auto focus, then map the window under the currently
1399 #define _WIDTH(w) (w)->frame->core->width
1400 #define _HEIGHT(w) (w)->frame->core->height
1401 if (!wPreferences
.auto_focus
&& scr
->focused_window
1402 && !scr
->flags
.startup
&& !transientOwner
1403 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1404 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1405 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1406 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1407 || wwin
->flags
.maximized
)) {
1408 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1416 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1417 && !scr
->flags
.startup
&&
1418 (wwin
->transient_for
==None
|| wwin
->transient_for
==scr
->root_win
)
1420 * The brain damaged idiotic non-click to focus modes will
1421 * have trouble with this because:
1423 * 1. window is created and mapped by the client
1424 * 2. window is mapped by wmaker in small size
1425 * 3. window is animated to grow to normal size
1426 * 4. this function returns to normal event loop
1427 * 5. eventually, the EnterNotify event that would trigger
1428 * the window focusing (if the mouse is over that window)
1429 * will be processed by wmaker.
1430 * But since this event will be rather delayed
1431 * (step 3 has a large delay) the time when the event ocurred
1432 * and when it is processed, the client that owns that window
1433 * will reject the XSetInputFocus() for it.
1435 && (wPreferences
.focus_mode
==WKF_CLICK
1436 || wPreferences
.auto_focus
)) {
1437 DoWindowBirth(wwin
);
1443 /* setup stacking descriptor */
1444 if (transientOwner
) {
1445 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1447 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1451 if (!scr
->focused_window
) {
1452 /* first window on the list */
1455 scr
->focused_window
= wwin
;
1459 /* add window at beginning of focus window list */
1460 tmp
= scr
->focused_window
;
1468 /* raise is set to true if we un-hid the app when this window was born.
1469 * we raise, else old windows of this app will be above this new one. */
1471 wRaiseFrame(wwin
->frame
->core
);
1474 /* Update name must come after WApplication stuff is done */
1475 wWindowUpdateName(wwin
, title
);
1482 *--------------------------------------------------
1484 * Final preparations before window is ready to go
1486 *--------------------------------------------------
1489 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1492 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1493 && !wwin
->flags
.hidden
) {
1494 if (((transientOwner
&& transientOwner
->flags
.focused
)
1495 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1496 wSetFocusTo(scr
, wwin
);
1498 wWindowResetMouseGrabs(wwin
);
1500 if (!WFLAGP(wwin
, no_bind_keys
)) {
1501 wWindowSetKeyGrabs(wwin
);
1505 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1508 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1512 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1513 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1515 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1516 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1522 *------------------------------------------------------------
1523 * Setup Notification Observers
1524 *------------------------------------------------------------
1526 WMAddNotificationObserver(appearanceObserver
, wwin
,
1527 WNWindowAppearanceSettingsChanged
, wwin
);
1531 *--------------------------------------------------
1533 * Cleanup temporary stuff
1535 *--------------------------------------------------
1539 wWindowDeleteSavedState(win_state
);
1541 /* If the window must be withdrawed, then do it now.
1542 * Must do some optimization, 'though */
1544 wwin
->flags
.mapped
= 0;
1545 wClientSetState(wwin
, WithdrawnState
, None
);
1546 wUnmanageWindow(wwin
, True
, False
);
1558 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1559 char *title
, int x
, int y
, int width
, int height
)
1564 wwin
= wWindowCreate();
1566 WMAddNotificationObserver(appearanceObserver
, wwin
,
1567 WNWindowAppearanceSettingsChanged
, wwin
);
1569 wwin
->flags
.internal_window
= 1;
1571 WSETUFLAG(wwin
, omnipresent
, 1);
1572 WSETUFLAG(wwin
, no_shadeable
, 1);
1573 WSETUFLAG(wwin
, no_resizable
, 1);
1574 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1576 wwin
->focus_mode
= WFM_PASSIVE
;
1578 wwin
->client_win
= window
;
1579 wwin
->screen_ptr
= scr
;
1581 wwin
->transient_for
= owner
;
1585 wwin
->client
.width
= width
;
1586 wwin
->client
.height
= height
;
1588 wwin
->frame_x
= wwin
->client
.x
;
1589 wwin
->frame_y
= wwin
->client
.y
;
1592 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1593 foo
|= WFF_TITLEBAR
;
1594 #ifdef XKB_BUTTON_HINT
1595 foo
|= WFF_LANGUAGE_BUTTON
;
1598 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1599 wwin
->frame_x
, wwin
->frame_y
,
1601 &wPreferences
.window_title_clearance
, foo
,
1602 scr
->window_title_texture
,
1603 scr
->resizebar_texture
,
1604 scr
->window_title_color
,
1607 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1609 wwin
->frame
->flags
.is_client_window_frame
= 1;
1610 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1612 wFrameWindowChangeTitle(wwin
->frame
, title
);
1614 /* setup button images */
1615 wWindowUpdateButtonImages(wwin
);
1618 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1620 wwin
->frame
->child
= wwin
;
1622 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1624 #ifdef XKB_BUTTON_HINT
1625 if (wPreferences
.modelock
)
1626 wwin
->frame
->on_click_language
= windowLanguageClick
;
1629 wwin
->frame
->on_click_right
= windowCloseClick
;
1631 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1632 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1634 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1636 wwin
->client
.y
+= wwin
->frame
->top_width
;
1637 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1638 0, wwin
->frame
->top_width
);
1640 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1641 wwin
->client
.width
, wwin
->client
.height
);
1643 /* setup the frame descriptor */
1644 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1645 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1646 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1649 XLowerWindow(dpy
, window
);
1650 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1652 /* setup stacking descriptor */
1653 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
1655 tmp
= wWindowFor(wwin
->transient_for
);
1657 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1659 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1663 if (!scr
->focused_window
) {
1664 /* first window on the list */
1667 scr
->focused_window
= wwin
;
1671 /* add window at beginning of focus window list */
1672 tmp
= scr
->focused_window
;
1680 if (wwin
->flags
.is_gnustep
== 0)
1681 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1683 /* if (wPreferences.auto_focus)*/
1684 wSetFocusTo(scr
, wwin
);
1686 wWindowResetMouseGrabs(wwin
);
1688 wWindowSetKeyGrabs(wwin
);
1695 *----------------------------------------------------------------------
1697 * Removes the frame window from a window and destroys all data
1698 * related to it. The window will be reparented back to the root window
1699 * if restore is True.
1702 * Everything related to the window is destroyed and the window
1703 * is removed from the window lists. Focus is set to the previous on the
1705 *----------------------------------------------------------------------
1708 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1710 WCoreWindow
*frame
= wwin
->frame
->core
;
1711 WWindow
*owner
= NULL
;
1712 WWindow
*newFocusedWindow
= NULL
;
1714 WScreen
*scr
= wwin
->screen_ptr
;
1717 /* First close attribute editor window if open */
1718 if (wwin
->flags
.inspector_open
) {
1719 wCloseInspectorForWindow(wwin
);
1722 /* Close window menu if it's open for this window */
1723 if (wwin
->flags
.menu_open_for_me
) {
1724 CloseWindowMenu(scr
);
1728 if (!wwin
->flags
.internal_window
)
1729 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1731 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1733 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1734 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1737 XUnmapWindow(dpy
, frame
->window
);
1739 XUnmapWindow(dpy
, wwin
->client_win
);
1741 /* deselect window */
1742 wSelectWindow(wwin
, False
);
1744 /* remove all pending events on window */
1745 /* I think this only matters for autoraise */
1746 if (wPreferences
.raise_delay
)
1747 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1751 /* reparent the window back to the root */
1753 wClientRestore(wwin
);
1755 if (wwin
->transient_for
!=scr
->root_win
) {
1756 owner
= wWindowFor(wwin
->transient_for
);
1758 if (!owner
->flags
.semi_focused
) {
1761 owner
->flags
.semi_focused
= 0;
1766 wasFocused
= wwin
->flags
.focused
;
1768 /* remove from window focus list */
1769 if (!wwin
->prev
&& !wwin
->next
) {
1770 /* was the only window */
1771 scr
->focused_window
= NULL
;
1772 newFocusedWindow
= NULL
;
1777 wwin
->prev
->next
= wwin
->next
;
1779 wwin
->next
->prev
= wwin
->prev
;
1781 scr
->focused_window
= wwin
->prev
;
1782 scr
->focused_window
->next
= NULL
;
1785 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1787 /* if in click to focus mode and the window
1788 * was a transient, focus the owner window
1791 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1792 tmp
= wWindowFor(wwin
->transient_for
);
1793 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1797 /* otherwise, focus the next one in the focus list */
1799 tmp
= scr
->focused_window
;
1800 while (tmp
) { /* look for one in the window list first */
1801 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1802 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1806 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1807 tmp
= scr
->focused_window
;
1809 if (!WFLAGP(tmp
, no_focusable
)
1810 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1817 newFocusedWindow
= tmp
;
1819 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1824 /* This is to let the root window get the keyboard input
1825 * if Sloppy focus mode and no other window get focus.
1826 * This way keybindings will not freeze.
1829 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1830 &foo
, &foo
, &foo
, &foo
, &mask
))
1831 tmp
= wWindowFor(win
);
1834 newFocusedWindow
= tmp
;
1836 newFocusedWindow
= NULL
;
1840 if (!wwin
->flags
.internal_window
) {
1841 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1845 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1846 (unsigned)frame
->window
);
1850 if (newFocusedWindow
!= owner
&& owner
) {
1851 if (wwin
->flags
.is_gnustep
== 0)
1852 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1854 wSetFocusTo(scr
, newFocusedWindow
);
1856 wWindowDestroy(wwin
);
1862 wWindowMap(WWindow
*wwin
)
1864 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1865 if (!wwin
->flags
.shaded
) {
1866 /* window will be remapped when getting MapNotify */
1867 XSelectInput(dpy
, wwin
->client_win
,
1868 wwin
->event_mask
& ~StructureNotifyMask
);
1869 XMapWindow(dpy
, wwin
->client_win
);
1870 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1872 wwin
->flags
.mapped
= 1;
1878 wWindowUnmap(WWindow
*wwin
)
1880 wwin
->flags
.mapped
= 0;
1882 /* prevent window withdrawal when getting UnmapNotify */
1883 XSelectInput(dpy
, wwin
->client_win
,
1884 wwin
->event_mask
& ~StructureNotifyMask
);
1885 XUnmapWindow(dpy
, wwin
->client_win
);
1886 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1888 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1894 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1899 #ifdef KEEP_XKB_LOCK_STATUS
1900 if (wPreferences
.modelock
) {
1901 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1903 #endif /* KEEP_XKB_LOCK_STATUS */
1905 wwin
->flags
.semi_focused
= 0;
1907 if (wwin
->flags
.is_gnustep
== 0)
1908 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1910 wwin
->flags
.focused
= 1;
1912 wWindowResetMouseGrabs(wwin
);
1914 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)True
);
1916 if (owin
== wwin
|| !owin
)
1919 nowner
= wWindowFor(wwin
->transient_for
);
1921 /* new window is a transient for the old window */
1922 if (nowner
== owin
) {
1923 owin
->flags
.semi_focused
= 1;
1924 wWindowUnfocus(nowner
);
1928 oowner
= wWindowFor(owin
->transient_for
);
1930 /* new window is owner of old window */
1931 if (wwin
== oowner
) {
1932 wWindowUnfocus(owin
);
1937 wWindowUnfocus(owin
);
1941 /* new window has same owner of old window */
1942 if (oowner
== nowner
) {
1943 /* prevent unfocusing of owner */
1944 oowner
->flags
.semi_focused
= 0;
1945 wWindowUnfocus(owin
);
1946 oowner
->flags
.semi_focused
= 1;
1951 /* nowner != NULL && oowner != nowner */
1952 nowner
->flags
.semi_focused
= 1;
1953 wWindowUnfocus(nowner
);
1954 wWindowUnfocus(owin
);
1959 wWindowUnfocus(WWindow
*wwin
)
1961 CloseWindowMenu(wwin
->screen_ptr
);
1963 if (wwin
->flags
.is_gnustep
== 0)
1964 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1965 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1967 if (wwin
->transient_for
!=None
1968 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1970 owner
= wWindowFor(wwin
->transient_for
);
1971 if (owner
&& owner
->flags
.semi_focused
) {
1972 owner
->flags
.semi_focused
= 0;
1973 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1974 wWindowUnfocus(owner
);
1975 wFrameWindowPaint(owner
->frame
);
1979 wwin
->flags
.focused
= 0;
1981 wWindowResetMouseGrabs(wwin
);
1983 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)False
);
1988 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1995 wwin
->flags
.wm_name_changed
= 1;
1998 /* the hint was removed */
1999 title
= DEF_WINDOW_TITLE
;
2004 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
2005 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
2012 *----------------------------------------------------------------------
2014 * wWindowConstrainSize--
2015 * Constrains size for the client window, taking the maximal size,
2016 * window resize increments and other size hints into account.
2019 * The closest size to what was given that the client window can
2022 *----------------------------------------------------------------------
2025 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
2027 int width
= *nwidth
;
2028 int height
= *nheight
;
2031 int minW
= 1, minH
= 1;
2032 int maxW
= wwin
->screen_ptr
->scr_width
*2;
2033 int maxH
= wwin
->screen_ptr
->scr_height
*2;
2034 int minAX
= -1, minAY
= -1;
2035 int maxAX
= -1, maxAY
= -1;
2039 if (wwin
->normal_hints
) {
2040 winc
= wwin
->normal_hints
->width_inc
;
2041 hinc
= wwin
->normal_hints
->height_inc
;
2042 minW
= wwin
->normal_hints
->min_width
;
2043 minH
= wwin
->normal_hints
->min_height
;
2044 maxW
= wwin
->normal_hints
->max_width
;
2045 maxH
= wwin
->normal_hints
->max_height
;
2046 if (wwin
->normal_hints
->flags
& PAspect
) {
2047 minAX
= wwin
->normal_hints
->min_aspect
.x
;
2048 minAY
= wwin
->normal_hints
->min_aspect
.y
;
2049 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
2050 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
2053 baseW
= wwin
->normal_hints
->base_width
;
2054 baseH
= wwin
->normal_hints
->base_height
;
2067 /* aspect ratio code borrowed from olwm */
2069 /* adjust max aspect ratio */
2070 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
2071 if (maxAX
> maxAY
) {
2072 height
= (width
* maxAY
) / maxAX
;
2073 if (height
> maxH
) {
2075 width
= (height
* maxAX
) / maxAY
;
2078 width
= (height
* maxAX
) / maxAY
;
2081 height
= (width
* maxAY
) / maxAX
;
2086 /* adjust min aspect ratio */
2087 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
2088 if (minAX
> minAY
) {
2089 height
= (width
* minAY
) / minAX
;
2090 if (height
< minH
) {
2092 width
= (height
* minAX
) / minAY
;
2095 width
= (height
* minAX
) / minAY
;
2098 height
= (width
* minAY
) / minAX
;
2105 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
2107 width
= (((width
- minW
) / winc
) * winc
) + minW
;
2111 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
2113 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
2116 /* broken stupid apps may cause preposterous values for these.. */
2125 wWindowCropSize(WWindow
*wwin
, int maxW
, int maxH
,
2126 int *width
, int *height
)
2128 int baseW
= 0, baseH
= 0;
2129 int winc
= 1, hinc
= 1;
2131 if (wwin
->normal_hints
) {
2132 baseW
= wwin
->normal_hints
->base_width
;
2133 baseH
= wwin
->normal_hints
->base_height
;
2135 winc
= wwin
->normal_hints
->width_inc
;
2136 hinc
= wwin
->normal_hints
->height_inc
;
2140 *width
= maxW
- (maxW
- baseW
) % winc
;
2143 *height
= maxH
- (maxH
- baseH
) % hinc
;
2148 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
2150 WScreen
*scr
= wwin
->screen_ptr
;
2154 if (workspace
>= scr
->workspace_count
|| workspace
< 0
2155 || workspace
== wwin
->frame
->workspace
)
2158 if (workspace
!= scr
->current_workspace
) {
2159 /* Sent to other workspace. Unmap window */
2160 if ((wwin
->flags
.mapped
2161 || wwin
->flags
.shaded
2162 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
2163 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
2165 wapp
= wApplicationOf(wwin
->main_window
);
2167 wapp
->last_workspace
= workspace
;
2169 if (wwin
->flags
.miniaturized
) {
2171 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
2172 wwin
->icon
->mapped
= 0;
2176 wSetFocusTo(scr
, NULL
);
2180 /* brought to current workspace. Map window */
2181 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
2183 XMapWindow(dpy
, wwin
->icon
->core
->window
);
2184 wwin
->icon
->mapped
= 1;
2186 } else if (!wwin
->flags
.mapped
&&
2187 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
2191 if (!IS_OMNIPRESENT(wwin
)) {
2192 int oldWorkspace
= wwin
->frame
->workspace
;
2194 wwin
->frame
->workspace
= workspace
;
2196 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void*)oldWorkspace
);
2206 wWindowSynthConfigureNotify(WWindow
*wwin
)
2210 sevent
.type
= ConfigureNotify
;
2211 sevent
.xconfigure
.display
= dpy
;
2212 sevent
.xconfigure
.event
= wwin
->client_win
;
2213 sevent
.xconfigure
.window
= wwin
->client_win
;
2215 sevent
.xconfigure
.x
= wwin
->client
.x
;
2216 sevent
.xconfigure
.y
= wwin
->client
.y
;
2217 sevent
.xconfigure
.width
= wwin
->client
.width
;
2218 sevent
.xconfigure
.height
= wwin
->client
.height
;
2220 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2221 if (WFLAGP(wwin
, no_titlebar
))
2222 sevent
.xconfigure
.above
= None
;
2224 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2226 sevent
.xconfigure
.override_redirect
= False
;
2227 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2229 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2236 *----------------------------------------------------------------------
2237 * wWindowConfigure--
2238 * Configures the frame, decorations and client window to the
2239 * specified geometry. The geometry is not checked for validity,
2240 * wWindowConstrainSize() must be used for that.
2241 * The size parameters are for the client window, but the position is
2243 * The client window receives a ConfigureNotify event, according
2244 * to what ICCCM says.
2250 * Window size and position are changed and client window receives
2251 * a ConfigureNotify event.
2252 *----------------------------------------------------------------------
2255 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2257 int req_x
, req_y
; /* new position of the frame */
2258 int req_width
, req_height
; /* new size of the client */
2260 int synth_notify
= False
;
2263 resize
= (req_width
!=wwin
->client
.width
2264 || req_height
!=wwin
->client
.height
);
2266 * if the window is being moved but not resized then
2267 * send a synthetic ConfigureNotify
2269 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2270 synth_notify
= True
;
2273 if (WFLAGP(wwin
, dont_move_off
))
2274 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2275 req_width
, req_height
);
2277 if (req_width
< MIN_WINDOW_SIZE
)
2278 req_width
= MIN_WINDOW_SIZE
;
2279 if (req_height
< MIN_WINDOW_SIZE
)
2280 req_height
= MIN_WINDOW_SIZE
;
2282 /* If growing, resize inner part before frame,
2283 * if shrinking, resize frame before.
2284 * This will prevent the frame (that can have a different color)
2285 * to be exposed, causing flicker */
2286 if (req_height
> wwin
->frame
->core
->height
2287 || req_width
> wwin
->frame
->core
->width
)
2288 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2290 if (wwin
->flags
.shaded
) {
2291 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2292 req_width
, wwin
->frame
->core
->height
);
2293 wwin
->old_geometry
.height
= req_height
;
2297 h
= req_height
+ wwin
->frame
->top_width
2298 + wwin
->frame
->bottom_width
;
2300 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2303 if (!(req_height
> wwin
->frame
->core
->height
2304 || req_width
> wwin
->frame
->core
->width
))
2305 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2307 wwin
->client
.x
= req_x
;
2308 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2309 wwin
->client
.width
= req_width
;
2310 wwin
->client
.height
= req_height
;
2312 wwin
->client
.x
= req_x
;
2313 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2315 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2317 wwin
->frame_x
= req_x
;
2318 wwin
->frame_y
= req_y
;
2319 if (!WFLAGP(wwin
, no_border
)) {
2320 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2321 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2325 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2326 wWindowSetShape(wwin
);
2331 wWindowSynthConfigureNotify(wwin
);
2337 wWindowMove(wwin
, req_x
, req_y
)
2339 int req_x
, req_y
; /* new position of the frame */
2341 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2342 int synth_notify
= False
;
2344 /* Send a synthetic ConfigureNotify event for every window movement. */
2345 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2346 synth_notify
= True
;
2349 /* A single synthetic ConfigureNotify event is sent at the end of
2350 * a completed (opaque) movement in moveres.c */
2353 if (WFLAGP(wwin
, dont_move_off
))
2354 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2355 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2357 wwin
->client
.x
= req_x
;
2358 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2359 if (!WFLAGP(wwin
, no_border
)) {
2360 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2361 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2364 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2366 wwin
->frame_x
= req_x
;
2367 wwin
->frame_y
= req_y
;
2369 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2371 wWindowSynthConfigureNotify(wwin
);
2377 wWindowUpdateButtonImages(WWindow
*wwin
)
2379 WScreen
*scr
= wwin
->screen_ptr
;
2380 Pixmap pixmap
, mask
;
2381 WFrameWindow
*fwin
= wwin
->frame
;
2383 if (WFLAGP(wwin
, no_titlebar
))
2386 /* miniaturize button */
2388 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2389 if (wwin
->wm_gnustep_attr
2390 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2391 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2393 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2394 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2399 if (fwin
->lbutton_image
2400 && (fwin
->lbutton_image
->image
!= pixmap
2401 || fwin
->lbutton_image
->mask
!= mask
)) {
2402 wPixmapDestroy(fwin
->lbutton_image
);
2403 fwin
->lbutton_image
= NULL
;
2406 if (!fwin
->lbutton_image
) {
2407 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2408 fwin
->lbutton_image
->client_owned
= 1;
2409 fwin
->lbutton_image
->client_owned_mask
= 1;
2412 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2413 wPixmapDestroy(fwin
->lbutton_image
);
2415 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2419 #ifdef XKB_BUTTON_HINT
2420 if (!WFLAGP(wwin
, no_language_button
)) {
2421 if (fwin
->languagebutton_image
&&
2422 !fwin
->languagebutton_image
->shared
) {
2423 wPixmapDestroy(fwin
->languagebutton_image
);
2425 fwin
->languagebutton_image
=
2426 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2432 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2433 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2435 if (!WFLAGP(wwin
, no_close_button
)) {
2436 if (wwin
->wm_gnustep_attr
2437 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2438 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2440 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2441 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2445 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2446 || fwin
->rbutton_image
->mask
!= mask
)) {
2447 wPixmapDestroy(fwin
->rbutton_image
);
2448 fwin
->rbutton_image
= NULL
;
2451 if (!fwin
->rbutton_image
) {
2452 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2453 fwin
->rbutton_image
->client_owned
= 1;
2454 fwin
->rbutton_image
->client_owned_mask
= 1;
2457 } else if (WFLAGP(wwin
, kill_close
)) {
2459 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2460 wPixmapDestroy(fwin
->rbutton_image
);
2462 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2464 } else if (MGFLAGP(wwin
, broken_close
)) {
2466 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2467 wPixmapDestroy(fwin
->rbutton_image
);
2469 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2473 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2474 wPixmapDestroy(fwin
->rbutton_image
);
2476 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2480 /* force buttons to be redrawn */
2481 fwin
->flags
.need_texture_change
= 1;
2482 wFrameWindowPaint(fwin
);
2487 *---------------------------------------------------------------------------
2488 * wWindowConfigureBorders--
2489 * Update window border configuration according to attribute flags.
2491 *---------------------------------------------------------------------------
2494 wWindowConfigureBorders(WWindow
*wwin
)
2500 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2501 #ifdef XKB_BUTTON_HINT
2502 flags
|= WFF_LANGUAGE_BUTTON
;
2504 if (!WFLAGP(wwin
, no_titlebar
))
2505 flags
|= WFF_TITLEBAR
;
2506 if (!WFLAGP(wwin
, no_resizebar
) && !WFLAGP(wwin
, no_resizable
))
2507 flags
|= WFF_RESIZEBAR
;
2508 if (!WFLAGP(wwin
, no_border
))
2509 flags
|= WFF_BORDER
;
2510 if (wwin
->flags
.shaded
)
2511 flags
|= WFF_IS_SHADED
;
2513 oldh
= wwin
->frame
->top_width
;
2514 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2515 if (oldh
!= wwin
->frame
->top_width
) {
2516 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2518 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2519 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2520 wwin
->client
.width
, wwin
->client
.height
);
2524 if (!WFLAGP(wwin
, no_miniaturize_button
)
2525 && wwin
->frame
->flags
.hide_left_button
)
2526 flags
|= WFF_LEFT_BUTTON
;
2528 #ifdef XKB_BUTTON_HINT
2529 if (!WFLAGP(wwin
, no_language_button
)
2530 && wwin
->frame
->flags
.hide_language_button
)
2531 flags
|= WFF_LANGUAGE_BUTTON
;
2534 if (!WFLAGP(wwin
, no_close_button
)
2535 && wwin
->frame
->flags
.hide_right_button
)
2536 flags
|= WFF_RIGHT_BUTTON
;
2539 wWindowUpdateButtonImages(wwin
);
2540 wFrameWindowShowButton(wwin
->frame
, flags
);
2544 if (WFLAGP(wwin
, no_miniaturize_button
)
2545 && !wwin
->frame
->flags
.hide_left_button
)
2546 flags
|= WFF_LEFT_BUTTON
;
2548 #ifdef XKB_BUTTON_HINT
2549 if (WFLAGP(wwin
, no_language_button
)
2550 && !wwin
->frame
->flags
.hide_language_button
)
2551 flags
|= WFF_LANGUAGE_BUTTON
;
2554 if (WFLAGP(wwin
, no_close_button
)
2555 && !wwin
->frame
->flags
.hide_right_button
)
2556 flags
|= WFF_RIGHT_BUTTON
;
2559 wFrameWindowHideButton(wwin
->frame
, flags
);
2562 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2563 wWindowSetShape(wwin
);
2571 wWindowSaveState(WWindow
*wwin
)
2576 memset(data
, 0, sizeof(CARD32
)*10);
2577 data
[0] = wwin
->frame
->workspace
;
2578 data
[1] = wwin
->flags
.miniaturized
;
2579 data
[2] = wwin
->flags
.shaded
;
2580 data
[3] = wwin
->flags
.hidden
;
2581 data
[4] = wwin
->flags
.maximized
;
2582 if (wwin
->flags
.maximized
== 0) {
2583 data
[5] = wwin
->frame_x
;
2584 data
[6] = wwin
->frame_y
;
2585 data
[7] = wwin
->frame
->core
->width
;
2586 data
[8] = wwin
->frame
->core
->height
;
2588 data
[5] = wwin
->old_geometry
.x
;
2589 data
[6] = wwin
->old_geometry
.y
;
2590 data
[7] = wwin
->old_geometry
.width
;
2591 data
[8] = wwin
->old_geometry
.height
;
2594 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2595 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2596 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2599 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2600 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2601 (unsigned char *)data
, 10);
2606 getSavedState(Window window
, WSavedState
**state
)
2610 unsigned long nitems_ret
;
2611 unsigned long bytes_after_ret
;
2614 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2615 True
, _XA_WINDOWMAKER_STATE
,
2616 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2617 (unsigned char **)&data
)!=Success
|| !data
)
2620 *state
= wmalloc(sizeof(WSavedState
));
2622 (*state
)->workspace
= data
[0];
2623 (*state
)->miniaturized
= data
[1];
2624 (*state
)->shaded
= data
[2];
2625 (*state
)->hidden
= data
[3];
2626 (*state
)->maximized
= data
[4];
2627 (*state
)->x
= data
[5];
2628 (*state
)->y
= data
[6];
2629 (*state
)->w
= data
[7];
2630 (*state
)->h
= data
[8];
2631 (*state
)->window_shortcuts
= data
[9];
2635 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2644 wWindowClearShape(WWindow
*wwin
)
2646 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2647 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2652 wWindowSetShape(WWindow
*wwin
)
2656 #ifdef OPTIMIZE_SHAPE
2661 /* only shape is the client's */
2662 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2666 /* Get array of rectangles describing the shape mask */
2667 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2673 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2679 /* insert our decoration rectangles in the rect list */
2680 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2683 if (!WFLAGP(wwin
, no_titlebar
)) {
2685 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2686 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2687 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2690 if (!WFLAGP(wwin
, no_resizebar
)) {
2692 urec
[count
].y
= wwin
->frame
->core
->height
2693 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2694 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2695 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2699 /* shape our frame window */
2700 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2701 0, wwin
->frame
->top_width
, urec
, count
,
2702 ShapeSet
, Unsorted
);
2708 #endif /* OPTIMIZE_SHAPE */
2710 if (!WFLAGP(wwin
, no_titlebar
)) {
2713 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2714 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2717 if (!WFLAGP(wwin
, no_resizebar
)) {
2719 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2720 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2721 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2725 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2726 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2728 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2729 0, wwin
->frame
->top_width
, wwin
->client_win
,
2730 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2735 /* ====================================================================== */
2738 getFocusMode(WWindow
*wwin
)
2742 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2743 if (wwin
->wm_hints
->input
== True
) {
2744 if (wwin
->protocols
.TAKE_FOCUS
)
2745 mode
= WFM_LOCALLY_ACTIVE
;
2749 if (wwin
->protocols
.TAKE_FOCUS
)
2750 mode
= WFM_GLOBALLY_ACTIVE
;
2752 mode
= WFM_NO_INPUT
;
2762 wWindowSetKeyGrabs(WWindow
*wwin
)
2767 for (i
=0; i
<WKBD_LAST
; i
++) {
2768 key
= &wKeyBindings
[i
];
2770 if (key
->keycode
==0)
2772 if (key
->modifier
!=AnyModifier
) {
2773 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2774 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2776 /* Also grab all modifier combinations possible that include,
2777 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2778 * work even if the NumLock/ScrollLock key is on.
2780 wHackedGrabKey(key
->keycode
, key
->modifier
,
2781 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2785 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2786 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2790 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2797 wWindowResetMouseGrabs(WWindow
*wwin
)
2799 /* Mouse grabs can't be done on the client window because of
2800 * ICCCM and because clients that try to do the same will crash.
2802 * But there is a problem wich makes tbar buttons of unfocused
2803 * windows not usable as the click goes to the frame window instead
2804 * of the button itself. Must figure a way to fix that.
2807 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2809 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2810 /* grabs for Meta+drag */
2811 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2812 True
, ButtonPressMask
, GrabModeSync
,
2813 GrabModeAsync
, None
, None
);
2816 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2817 && !wwin
->flags
.is_gnustep
) {
2818 /* the passive grabs to focus the window */
2819 /* if (wPreferences.focus_mode == WKF_CLICK) */
2820 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2821 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2829 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2831 if (attr
->flags
& GSExtraFlagsAttr
) {
2832 if (MGFLAGP(wwin
, broken_close
) !=
2833 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2834 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2835 wWindowUpdateButtonImages(wwin
);
2842 wWindowAddSavedState(char *instance
, char *class, char *command
,
2843 pid_t pid
, WSavedState
*state
)
2845 WWindowState
*wstate
;
2847 wstate
= malloc(sizeof(WWindowState
));
2851 memset(wstate
, 0, sizeof(WWindowState
));
2854 wstate
->instance
= wstrdup(instance
);
2856 wstate
->class = wstrdup(class);
2858 wstate
->command
= wstrdup(command
);
2859 wstate
->state
= state
;
2861 wstate
->next
= windowState
;
2862 windowState
= wstate
;
2865 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2873 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2877 wWindowGetSavedState(Window win
)
2879 char *instance
, *class, *command
=NULL
;
2880 WWindowState
*wstate
= windowState
;
2887 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2889 command
= wtokenjoin(argv
, argc
);
2890 XFreeStringList(argv
);
2895 if (PropGetWMClass(win
, &class, &instance
)) {
2897 if (SAME(instance
, wstate
->instance
) &&
2898 SAME(class, wstate
->class) &&
2899 SAME(command
, wstate
->command
)) {
2902 wstate
= wstate
->next
;
2909 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2913 if (command
) wfree(command
);
2914 if (instance
) XFree(instance
);
2915 if (class) XFree(class);
2922 wWindowDeleteSavedState(WMagicNumber id
)
2924 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2926 if (!wstate
|| !windowState
)
2931 windowState
= wstate
->next
;
2933 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2934 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2936 if (wstate
->instance
) wfree(wstate
->instance
);
2937 if (wstate
->class) wfree(wstate
->class);
2938 if (wstate
->command
) wfree(wstate
->command
);
2939 wfree(wstate
->state
);
2943 if (tmp
->next
==wstate
) {
2944 tmp
->next
=wstate
->next
;
2946 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2947 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2949 if (wstate
->instance
) wfree(wstate
->instance
);
2950 if (wstate
->class) wfree(wstate
->class);
2951 if (wstate
->command
) wfree(wstate
->command
);
2952 wfree(wstate
->state
);
2963 wWindowDeleteSavedStatesForPID(pid_t pid
)
2965 WWindowState
*tmp
, *wstate
;
2971 if (tmp
->pid
== pid
) {
2972 wstate
= windowState
;
2973 windowState
= tmp
->next
;
2975 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2976 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2978 if (wstate
->instance
) wfree(wstate
->instance
);
2979 if (wstate
->class) wfree(wstate
->class);
2980 if (wstate
->command
) wfree(wstate
->command
);
2981 wfree(wstate
->state
);
2985 if (tmp
->next
->pid
==pid
) {
2987 tmp
->next
= wstate
->next
;
2989 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2990 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2992 if (wstate
->instance
) wfree(wstate
->instance
);
2993 if (wstate
->class) wfree(wstate
->class);
2994 if (wstate
->command
) wfree(wstate
->command
);
2995 wfree(wstate
->state
);
3006 wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
3008 wwin
->flags
.omnipresent
= flag
;
3010 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
3014 /* ====================================================================== */
3017 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3019 WWindow
*wwin
= data
;
3021 #ifndef NUMLOCK_HACK
3022 if ((event
->xbutton
.state
& ValidModMask
)
3023 != (event
->xbutton
.state
& ~LockMask
)) {
3024 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3025 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3029 event
->xbutton
.state
&= ValidModMask
;
3031 CloseWindowMenu(wwin
->screen_ptr
);
3033 if (wPreferences
.focus_mode
==WKF_CLICK
3034 && !(event
->xbutton
.state
&ControlMask
)
3035 && !WFLAGP(wwin
, no_focusable
)) {
3036 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3039 if (event
->xbutton
.button
== Button1
)
3040 wRaiseFrame(wwin
->frame
->core
);
3042 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
3043 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
3044 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3045 GrabModeAsync
, GrabModeAsync
, None
,
3046 None
, CurrentTime
)!=GrabSuccess
) {
3048 wwarning("pointer grab failed for window move");
3054 if (event
->xbutton
.state
& MOD_MASK
) {
3055 /* move the window */
3056 wMouseMoveWindow(wwin
, event
);
3057 XUngrabPointer(dpy
, CurrentTime
);
3059 wMouseResizeWindow(wwin
, event
);
3060 XUngrabPointer(dpy
, CurrentTime
);
3067 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3069 WWindow
*wwin
= data
;
3071 event
->xbutton
.state
&= ValidModMask
;
3073 if (event
->xbutton
.button
==Button1
) {
3074 if (event
->xbutton
.state
== 0) {
3075 if (!WFLAGP(wwin
, no_shadeable
)) {
3077 if (wwin
->flags
.shaded
)
3078 wUnshadeWindow(wwin
);
3085 if (event
->xbutton
.state
& ControlMask
)
3086 dir
|= MAX_VERTICAL
;
3088 if (event
->xbutton
.state
& ShiftMask
) {
3089 dir
|= MAX_HORIZONTAL
;
3090 if (!(event
->xbutton
.state
& ControlMask
))
3091 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3094 /* maximize window */
3095 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
3096 int ndir
= dir
^ wwin
->flags
.maximized
;
3097 if (wwin
->flags
.maximized
!= 0)
3098 wUnmaximizeWindow(wwin
);
3100 wMaximizeWindow(wwin
, ndir
);
3103 } else if (event
->xbutton
.button
==Button3
) {
3104 if (event
->xbutton
.state
& MOD_MASK
) {
3105 wHideOtherApplications(wwin
);
3107 } else if (event
->xbutton
.button
==Button2
) {
3108 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3109 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
3111 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
3112 wUnshadeWindow(wwin
);
3118 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3120 WWindow
*wwin
= desc
->parent
;
3122 event
->xbutton
.state
&= ValidModMask
;
3124 CloseWindowMenu(wwin
->screen_ptr
);
3126 if (/*wPreferences.focus_mode==WKF_CLICK
3127 &&*/ !(event
->xbutton
.state
&ControlMask
)
3128 && !WFLAGP(wwin
, no_focusable
)) {
3129 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3131 if (event
->xbutton
.button
== Button1
) {
3132 wRaiseFrame(wwin
->frame
->core
);
3135 if (event
->xbutton
.state
& MOD_MASK
) {
3136 /* move the window */
3137 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
3138 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3139 GrabModeAsync
, GrabModeAsync
, None
,
3140 None
, CurrentTime
)!=GrabSuccess
) {
3142 wwarning("pointer grab failed for window move");
3146 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
3147 wMouseResizeWindow(wwin
, event
);
3149 wMouseMoveWindow(wwin
, event
);
3150 XUngrabPointer(dpy
, CurrentTime
);
3156 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3158 WWindow
*wwin
= (WWindow
*)data
;
3160 #ifndef NUMLOCK_HACK
3161 if ((event
->xbutton
.state
& ValidModMask
)
3162 != (event
->xbutton
.state
& ~LockMask
)) {
3163 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3164 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3167 event
->xbutton
.state
&= ValidModMask
;
3169 CloseWindowMenu(wwin
->screen_ptr
);
3171 if (wPreferences
.focus_mode
==WKF_CLICK
3172 && !(event
->xbutton
.state
&ControlMask
)
3173 && !WFLAGP(wwin
, no_focusable
)) {
3174 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3177 if (event
->xbutton
.button
== Button1
3178 || event
->xbutton
.button
== Button2
) {
3180 if (event
->xbutton
.button
== Button1
) {
3181 if (event
->xbutton
.state
& MOD_MASK
) {
3182 wLowerFrame(wwin
->frame
->core
);
3184 wRaiseFrame(wwin
->frame
->core
);
3187 if ((event
->xbutton
.state
& ShiftMask
)
3188 && !(event
->xbutton
.state
& ControlMask
)) {
3189 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3192 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3193 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3194 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3195 GrabModeAsync
, GrabModeAsync
, None
,
3196 None
, CurrentTime
)!=GrabSuccess
) {
3198 wwarning("pointer grab failed for window move");
3203 /* move the window */
3204 wMouseMoveWindow(wwin
, event
);
3206 XUngrabPointer(dpy
, CurrentTime
);
3207 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
3208 && !wwin
->flags
.internal_window
3209 && !WCHECK_STATE(WSTATE_MODAL
)) {
3210 WObjDescriptor
*desc
;
3212 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3213 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3214 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3215 GrabModeAsync
, GrabModeAsync
, None
,
3216 None
, CurrentTime
)!=GrabSuccess
) {
3218 wwarning("pointer grab failed for window move");
3223 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
3224 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3226 /* allow drag select */
3227 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3228 event
->xany
.send_event
= True
;
3229 (*desc
->handle_mousedown
)(desc
, event
);
3231 XUngrabPointer(dpy
, CurrentTime
);
3238 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3240 WWindow
*wwin
= data
;
3242 event
->xbutton
.state
&= ValidModMask
;
3244 CloseWindowMenu(wwin
->screen_ptr
);
3246 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3249 /* if control-click, kill the client */
3250 if (event
->xbutton
.state
& ControlMask
) {
3254 if (wwin
->flags
.olwm_push_pin_out
) {
3256 wwin
->flags
.olwm_push_pin_out
= 0;
3258 wOLWMChangePushpinState(wwin
, True
);
3260 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3265 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3266 /* send delete message */
3267 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3274 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3276 WWindow
*wwin
= data
;
3278 CloseWindowMenu(wwin
->screen_ptr
);
3280 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3283 /* send delete message */
3284 if (wwin
->protocols
.DELETE_WINDOW
) {
3285 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3292 #ifdef XKB_BUTTON_HINT
3294 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3296 WWindow
*wwin
= data
;
3297 WFrameWindow
*fwin
= wwin
->frame
;
3298 WScreen
*scr
= fwin
->screen_ptr
;
3299 XkbStateRec staterec
;
3302 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3304 tl
= wwin
->frame
->languagemode
;
3305 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3306 wwin
->frame
->last_languagemode
= tl
;
3307 wSetFocusTo(scr
, wwin
);
3308 wwin
->frame
->languagebutton_image
=
3309 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3310 wwin
->frame
->languagemode
];
3311 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3312 if (event
->xbutton
.button
== Button3
)
3314 wRaiseFrame(fwin
->core
);
3320 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3322 WWindow
*wwin
= data
;
3324 event
->xbutton
.state
&= ValidModMask
;
3326 CloseWindowMenu(wwin
->screen_ptr
);
3328 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3331 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3332 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3336 if ((event
->xbutton
.state
& ControlMask
) ||
3337 (event
->xbutton
.button
== Button3
)) {
3339 wapp
= wApplicationOf(wwin
->main_window
);
3340 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3341 wHideApplication(wapp
);
3342 } else if (event
->xbutton
.state
==0) {
3343 wIconifyWindow(wwin
);