1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 #include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
38 #include "WindowMaker.h"
44 #include "winspector.h"
46 #include "properties.h"
53 #include "workspace.h"
66 # include "openlook.h"
69 /****** Global Variables ******/
71 extern WShortKey wKeyBindings
[WKBD_LAST
];
74 extern Bool wShapeSupported
;
78 extern XContext wWinContext
;
81 extern Cursor wCursor
[WCUR_LAST
];
84 extern Atom _XA_WM_DELETE_WINDOW
;
85 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
87 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern WPreferences wPreferences
;
91 #define MOD_MASK wPreferences.modifier_mask
93 extern Time LastTimestamp
;
96 extern void DoWindowBirth(WWindow
*);
99 /***** Local Stuff *****/
102 static WWindowState
*windowState
=NULL
;
106 /* local functions */
107 static FocusMode
getFocusMode(WWindow
*wwin
);
109 static int getSavedState(Window window
, WSavedState
**state
);
111 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
116 /* frame window (during window grabs) */
117 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
120 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
121 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
126 #ifdef XKB_BUTTON_HINT
127 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
130 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
131 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
133 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
136 /****** Notification Observers ******/
139 appearanceObserver(void *self
, WMNotification
*notif
)
141 WWindow
*wwin
= (WWindow
*)self
;
142 int flags
= (int)WMGetNotificationClientData(notif
);
144 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
147 if (flags
& WFontSettings
) {
148 wWindowConfigureBorders(wwin
);
149 if(wwin
->flags
.shaded
) {
150 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
151 wwin
->frame
->top_width
- 1);
153 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
154 + wwin
->frame
->top_width
;
155 wWindowSynthConfigureNotify(wwin
);
158 if (flags
& WTextureSettings
) {
159 wwin
->frame
->flags
.need_texture_remake
= 1;
161 if (flags
& (WTextureSettings
| WColorSettings
)) {
162 if (wwin
->frame
->titlebar
)
163 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
165 wFrameWindowPaint(wwin
->frame
);
169 /************************************/
172 wWindowFor(Window window
)
174 WObjDescriptor
*desc
;
179 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
182 if (desc
->parent_type
==WCLASS_WINDOW
)
184 else if (desc
->parent_type
==WCLASS_FRAME
) {
185 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
186 if (frame
->flags
.is_client_window_frame
)
199 wwin
= wmalloc(sizeof(WWindow
));
202 memset(wwin
, 0, sizeof(WWindow
));
204 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
205 wwin
->client_descriptor
.parent
= wwin
;
206 wwin
->client_descriptor
.self
= wwin
;
207 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
214 wWindowDestroy(WWindow
*wwin
)
218 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
219 wwin
->screen_ptr
->cmap_window
= NULL
;
222 WMRemoveNotificationObserver(wwin
);
224 wwin
->flags
.destroyed
= 1;
226 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
227 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
230 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
232 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
233 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
234 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
238 if (wwin
->normal_hints
)
239 XFree(wwin
->normal_hints
);
242 XFree(wwin
->wm_hints
);
244 if (wwin
->wm_instance
)
245 XFree(wwin
->wm_instance
);
248 XFree(wwin
->wm_class
);
250 if (wwin
->wm_gnustep_attr
)
251 wfree(wwin
->wm_gnustep_attr
);
253 if (wwin
->cmap_windows
)
254 XFree(wwin
->cmap_windows
);
256 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
259 wFrameWindowDestroy(wwin
->frame
);
262 RemoveFromStackList(wwin
->icon
->core
);
263 wIconDestroy(wwin
->icon
);
264 if (wPreferences
.auto_arrange_icons
)
265 wArrangeIcons(wwin
->screen_ptr
, True
);
274 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
276 if (gs_hints
->flags
& GSWindowStyleAttr
) {
277 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
278 wwin
->client_flags
.no_border
= 1;
279 wwin
->client_flags
.no_titlebar
= 1;
280 wwin
->client_flags
.no_closable
= 1;
281 wwin
->client_flags
.no_miniaturizable
= 1;
282 wwin
->client_flags
.no_resizable
= 1;
283 wwin
->client_flags
.no_close_button
= 1;
284 wwin
->client_flags
.no_miniaturize_button
= 1;
285 wwin
->client_flags
.no_resizebar
= 1;
287 wwin
->client_flags
.no_close_button
=
288 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
290 wwin
->client_flags
.no_closable
=
291 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
293 wwin
->client_flags
.no_miniaturize_button
=
294 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
296 wwin
->client_flags
.no_miniaturizable
=
297 wwin
->client_flags
.no_miniaturize_button
;
299 wwin
->client_flags
.no_resizebar
=
300 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
302 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
304 /* these attributes supposedly imply in the existence
306 if (gs_hints
->window_style
& (WMResizableWindowMask
|
307 WMClosableWindowMask
|
308 WMMiniaturizableWindowMask
)) {
309 wwin
->client_flags
.no_titlebar
= 0;
311 wwin
->client_flags
.no_titlebar
=
312 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
317 /* setup the defaults */
318 wwin
->client_flags
.no_border
= 0;
319 wwin
->client_flags
.no_titlebar
= 0;
320 wwin
->client_flags
.no_closable
= 0;
321 wwin
->client_flags
.no_miniaturizable
= 0;
322 wwin
->client_flags
.no_resizable
= 0;
323 wwin
->client_flags
.no_close_button
= 0;
324 wwin
->client_flags
.no_miniaturize_button
= 0;
325 wwin
->client_flags
.no_resizebar
= 0;
327 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
328 wwin
->client_flags
.no_appicon
= 1;
334 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
335 WWindowAttributes
*mask
)
337 if (wflags
->no_appicon
&& mask
->no_appicon
)
338 wflags
->emulate_appicon
= 0;
340 if (wwin
->main_window
!=None
) {
341 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
342 if (wapp
&& !wapp
->flags
.emulated
)
343 wflags
->emulate_appicon
= 0;
346 if (wwin
->transient_for
!=None
347 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
348 wflags
->emulate_appicon
= 0;
350 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
357 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
359 WScreen
*scr
= wwin
->screen_ptr
;
361 /* sets global default stuff */
362 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
363 &wwin
->client_flags
, NULL
, True
);
365 * Decoration setting is done in this precedence (lower to higher)
366 * - use global default in the resource database
367 * - guess some settings
368 * - use GNUstep/external window attributes
369 * - set hints specified for the app in the resource DB
372 WSETUFLAG(wwin
, broken_close
, 0);
374 if (wwin
->protocols
.DELETE_WINDOW
)
375 WSETUFLAG(wwin
, kill_close
, 0);
377 WSETUFLAG(wwin
, kill_close
, 1);
379 /* transients can't be iconified or maximized */
380 if (wwin
->transient_for
) {
381 WSETUFLAG(wwin
, no_miniaturizable
, 1);
382 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
385 /* if the window can't be resized, remove the resizebar */
386 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
387 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
388 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
389 WSETUFLAG(wwin
, no_resizable
, 1);
390 WSETUFLAG(wwin
, no_resizebar
, 1);
393 /* set GNUstep window attributes */
394 if (wwin
->wm_gnustep_attr
) {
395 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
397 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
399 *level
= wwin
->wm_gnustep_attr
->window_level
;
401 * INT_MIN is the only illegal window level.
403 if (*level
== INT_MIN
)
404 *level
= INT_MIN
+ 1;
407 *level
= WMNormalLevel
;
410 int tmp_workspace
= -1;
411 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
417 wMWMCheckClientHints(wwin
);
418 #endif /* MWM_HINTS */
421 check
= wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
422 #endif /* GNOME_STUFF */
426 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
427 #endif /* KWM_HINTS */
430 wOLWMCheckClientHints(wwin
);
431 #endif /* OLWM_HINTS */
433 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
434 * have INT_MIN that means that no window level was requested. -Dan
436 if (tmp_level
== INT_MIN
) {
437 if (WFLAGP(wwin
, floating
))
438 *level
= WMFloatingLevel
;
439 else if (WFLAGP(wwin
, sunken
))
440 *level
= WMSunkenLevel
;
442 *level
= WMNormalLevel
;
447 if (tmp_workspace
>= 0) {
448 *workspace
= tmp_workspace
% scr
->workspace_count
;
453 * Set attributes specified only for that window/class.
454 * This might do duplicate work with the 1st wDefaultFillAttributes().
456 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
457 &wwin
->user_flags
, &wwin
->defined_user_flags
,
460 * Sanity checks for attributes that depend on other attributes
462 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
463 wwin
->user_flags
.emulate_appicon
= 0;
465 if (wwin
->main_window
!=None
) {
466 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
467 if (wapp
&& !wapp
->flags
.emulated
)
468 wwin
->user_flags
.emulate_appicon
= 0;
471 if (wwin
->transient_for
!=None
472 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
473 wwin
->user_flags
.emulate_appicon
= 0;
475 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
476 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
477 wwin
->user_flags
.sunken
= 0;
479 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
486 wWindowCanReceiveFocus(WWindow
*wwin
)
488 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
490 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
492 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
500 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
504 w1
= wwin
->frame
->core
->width
;
505 h1
= wwin
->frame
->core
->height
;
506 w2
= obscured
->frame
->core
->width
;
507 h2
= obscured
->frame
->core
->height
;
509 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
510 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
513 if (wwin
->frame_x
+ w1
< obscured
->frame_x
514 || wwin
->frame_y
+ h1
< obscured
->frame_y
515 || wwin
->frame_x
> obscured
->frame_x
+ w2
516 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
526 *----------------------------------------------------------------
528 * reparents the window and allocates a descriptor for it.
529 * Window manager hints and other hints are fetched to configure
530 * the window decoration attributes and others. User preferences
531 * for the window are used if available, to configure window
532 * decorations and some behaviour.
533 * If in startup, windows that are override redirect,
534 * unmapped and never were managed and are Withdrawn are not
538 * the new window descriptor
541 * The window is reparented and appropriate notification
542 * is done to the client. Input mask for the window is setup.
543 * The window descriptor is also associated with various window
544 * contexts and inserted in the head of the window list.
545 * Event handler contexts are associated for some objects
546 * (buttons, titlebar and resizebar)
548 *----------------------------------------------------------------
551 wManageWindow(WScreen
*scr
, Window window
)
555 unsigned width
, height
;
556 XWindowAttributes wattribs
;
557 XSetWindowAttributes attribs
;
558 WWindowState
*win_state
;
559 WWindow
*transientOwner
= NULL
;
565 Bool withdraw
= False
;
568 /* XGrabServer(dpy); */
570 /* make sure the window is still there */
571 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
576 /* if it's an override-redirect, ignore it */
577 if (wattribs
.override_redirect
) {
582 wm_state
= PropGetWindowState(window
);
584 /* if it's startup and the window is unmapped, don't manage it */
585 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
590 if (!wFetchName(dpy
, window
, &title
)) {
595 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
600 #endif /* KWM_HINTS */
603 wwin
= wWindowCreate();
605 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
608 printf("managing window %x\n", (unsigned)window
);
612 if (wShapeSupported
) {
617 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
618 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
619 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
620 wwin
->flags
.shaped
= b_shaped
;
625 *--------------------------------------------------
627 * Get hints and other information in properties
629 *--------------------------------------------------
631 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
633 /* setup descriptor */
634 wwin
->client_win
= window
;
635 wwin
->screen_ptr
= scr
;
637 wwin
->old_border_width
= wattribs
.border_width
;
639 wwin
->event_mask
= CLIENT_EVENTS
;
640 attribs
.event_mask
= CLIENT_EVENTS
;
641 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
642 attribs
.save_under
= False
;
643 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
644 |CWSaveUnder
, &attribs
);
645 XSetWindowBorderWidth(dpy
, window
, 0);
647 /* get hints from GNUstep app */
648 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
649 wwin
->flags
.is_gnustep
= 1;
651 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
652 wwin
->wm_gnustep_attr
= NULL
;
655 wwin
->client_leader
= PropGetClientLeader(window
);
656 if (wwin
->client_leader
!=None
)
657 wwin
->main_window
= wwin
->client_leader
;
659 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
661 if (wwin
->wm_hints
) {
662 if (wwin
->wm_hints
->flags
& StateHint
) {
664 if (wwin
->wm_hints
->initial_state
== IconicState
) {
666 wwin
->flags
.miniaturized
= 1;
668 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
674 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
675 wwin
->group_id
= wwin
->wm_hints
->window_group
;
676 /* window_group has priority over CLIENT_LEADER */
677 wwin
->main_window
= wwin
->group_id
;
679 wwin
->group_id
= None
;
682 if (wwin
->wm_hints
->flags
& UrgencyHint
)
683 wwin
->flags
.urgent
= 1;
685 wwin
->group_id
= None
;
688 PropGetProtocols(window
, &wwin
->protocols
);
690 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
691 wwin
->transient_for
= None
;
693 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
694 wwin
->transient_for
= scr
->root_win
;
696 transientOwner
= wWindowFor(wwin
->transient_for
);
697 if (transientOwner
&& transientOwner
->main_window
!=None
) {
698 wwin
->main_window
= transientOwner
->main_window
;
700 wwin->main_window = None;
705 /* guess the focus mode */
706 wwin
->focus_mode
= getFocusMode(wwin
);
708 /* get geometry stuff */
709 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
711 /* get colormap windows */
712 GetColormapWindows(wwin
);
715 *--------------------------------------------------
717 * Setup the decoration/window attributes and
720 *--------------------------------------------------
723 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
726 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
727 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
729 transientOwner
= wWindowFor(wwin
->group_id
);
731 if (transientOwner
) {
732 wwin
->transient_for
= wwin
->group_id
;
734 /* transients can't be iconified or maximized */
735 if (wwin
->transient_for
) {
736 WSETUFLAG(wwin
, no_miniaturizable
, 1);
737 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
741 #endif /* OLWM_HINTS */
744 * Make broken apps behave as a nice app.
746 if (WFLAGP(wwin
, emulate_appicon
)) {
747 wwin
->main_window
= wwin
->client_win
;
751 *------------------------------------------------------------
753 * Setup the initial state of the window
755 *------------------------------------------------------------
758 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
759 wwin
->flags
.miniaturized
= 1;
762 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
763 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
771 bla
= wGNOMECheckInitialClientState(wwin
);
775 wKWMCheckClientInitialState(wwin
);
779 /* apply previous state if it exists and we're in startup */
780 if (scr
->flags
.startup
&& wm_state
>= 0) {
782 if (wm_state
== IconicState
) {
784 wwin
->flags
.miniaturized
= 1;
786 } else if (wm_state
== WithdrawnState
) {
792 /* if there is a saved state (from file), restore it */
794 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
795 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
797 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
799 if (win_state
&& !withdraw
) {
801 if (win_state
->state
->hidden
>0)
802 wwin
->flags
.hidden
= win_state
->state
->hidden
;
804 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
805 wwin
->flags
.shaded
= win_state
->state
->shaded
;
807 if (win_state
->state
->miniaturized
>0 &&
808 !WFLAGP(wwin
, no_miniaturizable
)) {
809 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
812 if (!IS_OMNIPRESENT(wwin
)) {
813 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
815 if (w
< 0 || w
>= scr
->workspace_count
) {
816 workspace
= win_state
->state
->workspace
;
817 if (workspace
>= scr
->workspace_count
)
818 workspace
= scr
->current_workspace
;
823 workspace
= scr
->current_workspace
;
827 /* if we're restarting, restore saved state (from hints).
828 * This will overwrite previous */
832 if (getSavedState(window
, &wstate
)) {
833 wwin
->flags
.shaded
= wstate
->shaded
;
834 wwin
->flags
.hidden
= wstate
->hidden
;
835 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
836 wwin
->flags
.maximized
= wstate
->maximized
;
837 if (wwin
->flags
.maximized
) {
838 wwin
->old_geometry
.x
= wstate
->x
;
839 wwin
->old_geometry
.y
= wstate
->y
;
840 wwin
->old_geometry
.width
= wstate
->w
;
841 wwin
->old_geometry
.height
= wstate
->h
;
844 workspace
= wstate
->workspace
;
849 /* restore window shortcut */
850 if (wstate
!= NULL
|| win_state
!= NULL
) {
853 if (win_state
!= NULL
)
854 mask
= win_state
->state
->window_shortcuts
;
856 if (wstate
!= NULL
&& mask
== 0)
857 mask
= wstate
->window_shortcuts
;
862 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
864 if (!scr
->shortcutWindows
[i
])
865 scr
->shortcutWindows
[i
] = WMCreateArray(4);
867 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
872 if (wstate
!= NULL
) {
877 /* don't let transients start miniaturized if their owners are not */
878 if (transientOwner
&& !transientOwner
->flags
.miniaturized
879 && wwin
->flags
.miniaturized
&& !withdraw
) {
880 wwin
->flags
.miniaturized
= 0;
882 wwin
->wm_hints
->initial_state
= NormalState
;
885 /* set workspace on which the window starts */
886 if (workspace
>= 0) {
887 if (workspace
> scr
->workspace_count
-1) {
888 workspace
= workspace
% scr
->workspace_count
;
893 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
895 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
900 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
902 workspace
= transientOwner
->frame
->workspace
;
906 workspace
= scr
->current_workspace
;
911 /* setup window geometry */
912 if (win_state
&& win_state
->state
->w
> 0) {
913 width
= win_state
->state
->w
;
914 height
= win_state
->state
->h
;
916 wWindowConstrainSize(wwin
, &width
, &height
);
918 /* do not ask for window placement if the window is
919 * transient, during startup, if the initial workspace is another one
920 * or if the window wants to start iconic.
921 * If geometry was saved, restore it. */
923 Bool dontBring
= False
;
925 if (win_state
&& win_state
->state
->w
> 0) {
926 x
= win_state
->state
->x
;
927 y
= win_state
->state
->y
;
928 } else if ((wwin
->transient_for
==None
929 || wPreferences
.window_placement
!=WPM_MANUAL
)
930 && !scr
->flags
.startup
931 && workspace
== scr
->current_workspace
932 && !wwin
->flags
.miniaturized
933 && !wwin
->flags
.maximized
934 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
936 if (transientOwner
&& transientOwner
->flags
.mapped
) {
937 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
939 x
= transientOwner
->frame_x
+
940 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
941 y
= transientOwner
->frame_y
+
942 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
946 else if (x
+ width
> scr
->scr_width
)
947 x
= scr
->scr_width
- width
;
951 else if (y
+ height
> scr
->scr_height
)
952 y
= scr
->scr_height
- height
;
954 PlaceWindow(wwin
, &x
, &y
, width
, height
);
956 if (wPreferences
.window_placement
== WPM_MANUAL
)
960 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
961 wScreenBringInside(scr
, &x
, &y
, width
, height
);
964 if (wwin
->flags
.urgent
) {
965 if (!IS_OMNIPRESENT(wwin
))
966 wwin
->flags
.omnipresent
^= 1;
970 *--------------------------------------------------
972 * Create frame, borders and do reparenting
974 *--------------------------------------------------
976 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
977 #ifdef XKB_BUTTON_HINT
978 if (wPreferences
.modelock
)
979 foo
|= WFF_LANGUAGE_BUTTON
;
981 if (!WFLAGP(wwin
, no_titlebar
))
983 if (!WFLAGP(wwin
, no_resizebar
))
984 foo
|= WFF_RESIZEBAR
;
985 if (!WFLAGP(wwin
, no_border
))
988 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
990 &wPreferences
.window_title_clearance
, foo
,
991 scr
->window_title_texture
,
992 scr
->resizebar_texture
,
993 scr
->window_title_pixel
,
994 &scr
->window_title_gc
,
997 wwin
->frame
->flags
.is_client_window_frame
= 1;
998 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1000 /* setup button images */
1001 wWindowUpdateButtonImages(wwin
);
1003 /* hide unused buttons */
1005 if (WFLAGP(wwin
, no_close_button
))
1006 foo
|= WFF_RIGHT_BUTTON
;
1007 if (WFLAGP(wwin
, no_miniaturize_button
))
1008 foo
|= WFF_LEFT_BUTTON
;
1009 #ifdef XKB_BUTTON_HINT
1010 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1011 foo
|= WFF_LANGUAGE_BUTTON
;
1014 wFrameWindowHideButton(wwin
->frame
, foo
);
1016 wwin
->frame
->child
= wwin
;
1019 /* emulate olwm push pin. Make the button look as pushed-in for
1020 * the pinned-out state. When the button is clicked, it will
1021 * revert to the normal position, which means the pin is pinned-in.
1023 if (wwin
->flags
.olwm_push_pin_out
)
1024 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1025 #endif /* OLWM_HINTS */
1028 wwin
->frame
->workspace
= workspace
;
1030 wwin
->frame
->on_click_left
= windowIconifyClick
;
1031 #ifdef XKB_BUTTON_HINT
1032 if (wPreferences
.modelock
)
1033 wwin
->frame
->on_click_language
= windowLanguageClick
;
1036 wwin
->frame
->on_click_right
= windowCloseClick
;
1037 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1039 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1040 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1042 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1045 XSelectInput(dpy
, wwin
->client_win
,
1046 wwin
->event_mask
& ~StructureNotifyMask
);
1048 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1049 0, wwin
->frame
->top_width
);
1051 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1057 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1059 /* if gravity is to the south, account for the border sizes */
1061 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1065 * wWindowConfigure() will init the client window's size
1066 * (wwin->client.{width,height}) and all other geometry
1067 * related variables (frame_x,frame_y)
1069 wWindowConfigure(wwin
, x
, y
, width
, height
);
1071 /* to make sure the window receives it's new position after reparenting */
1072 wWindowSynthConfigureNotify(wwin
);
1075 *--------------------------------------------------
1077 * Setup descriptors and save window to internal
1080 *--------------------------------------------------
1083 if (wwin
->main_window
!=None
) {
1087 /* Leader windows do not necessary set themselves as leaders.
1088 * If this is the case, point the leader of this window to
1090 leader
= wWindowFor(wwin
->main_window
);
1091 if (leader
&& leader
->main_window
==None
) {
1092 leader
->main_window
= leader
->client_win
;
1094 app
= wApplicationCreate(scr
, wwin
->main_window
);
1096 app
->last_workspace
= workspace
;
1099 * Do application specific stuff, like setting application
1103 if (wwin
->flags
.hidden
) {
1104 /* if the window was set to hidden because it was hidden
1105 * in a previous incarnation and that state was restored */
1106 app
->flags
.hidden
= 1;
1109 if (app
->flags
.hidden
) {
1110 wwin
->flags
.hidden
= 1;
1115 /* setup the frame descriptor */
1116 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1117 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1118 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1120 /* don't let windows go away if we die */
1121 XAddToSaveSet(dpy
, window
);
1123 XLowerWindow(dpy
, window
);
1125 /* if window is in this workspace and should be mapped, then map it */
1126 if (!wwin
->flags
.miniaturized
1127 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1128 && !wwin
->flags
.hidden
&& !withdraw
) {
1130 /* The following "if" is to avoid crashing of clients that expect
1131 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1132 * after the return from this function.
1134 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1135 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1137 wClientSetState(wwin
, NormalState
, None
);
1141 /* if not auto focus, then map the window under the currently
1143 #define _WIDTH(w) (w)->frame->core->width
1144 #define _HEIGHT(w) (w)->frame->core->height
1145 if (!wPreferences
.auto_focus
&& scr
->focused_window
1146 && !scr
->flags
.startup
&& !transientOwner
1147 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1148 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1149 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1150 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1151 || wwin
->flags
.maximized
)) {
1152 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1160 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1161 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1163 * The brain damaged idiotic non-click to focus modes will
1164 * have trouble with this because:
1166 * 1. window is created and mapped by the client
1167 * 2. window is mapped by wmaker in small size
1168 * 3. window is animated to grow to normal size
1169 * 4. this function returns to normal event loop
1170 * 5. eventually, the EnterNotify event that would trigger
1171 * the window focusing (if the mouse is over that window)
1172 * will be processed by wmaker.
1173 * But since this event will be rather delayed
1174 * (step 3 has a large delay) the time when the event ocurred
1175 * and when it is processed, the client that owns that window
1176 * will reject the XSetInputFocus() for it.
1178 && (wPreferences
.focus_mode
==WKF_CLICK
1179 || wPreferences
.auto_focus
)) {
1180 DoWindowBirth(wwin
);
1186 /* setup stacking descriptor */
1187 if (transientOwner
) {
1188 /* && wPreferences.on_top_transients */
1189 if (transientOwner
) {
1190 wwin
->frame
->core
->stacking
->child_of
=
1191 transientOwner
->frame
->core
;
1194 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1198 if (!scr
->focused_window
) {
1199 /* first window on the list */
1202 scr
->focused_window
= wwin
;
1206 /* add window at beginning of focus window list */
1207 tmp
= scr
->focused_window
;
1215 /* Update name must come after WApplication stuff is done */
1216 wWindowUpdateName(wwin
, title
);
1222 wGNOMEUpdateClientStateHint(wwin
, True
);
1225 wKWMUpdateClientWorkspace(wwin
);
1226 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1232 *--------------------------------------------------
1234 * Final preparations before window is ready to go
1236 *--------------------------------------------------
1239 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1242 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1243 && !wwin
->flags
.hidden
) {
1244 if (((transientOwner
&& transientOwner
->flags
.focused
)
1245 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1246 wSetFocusTo(scr
, wwin
);
1248 wWindowResetMouseGrabs(wwin
);
1250 if (!WFLAGP(wwin
, no_bind_keys
)) {
1251 wWindowSetKeyGrabs(wwin
);
1254 wGNOMEUpdateClientListHint(scr
);
1257 wwin
->flags
.kwm_managed
= 1;
1259 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1262 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1264 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1267 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1268 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1270 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1271 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1277 *------------------------------------------------------------
1278 * Setup Notification Observers
1279 *------------------------------------------------------------
1281 WMAddNotificationObserver(appearanceObserver
, wwin
,
1282 WNWindowAppearanceSettingsChanged
, wwin
);
1286 *--------------------------------------------------
1288 * Cleanup temporary stuff
1290 *--------------------------------------------------
1294 wWindowDeleteSavedState(win_state
);
1296 /* If the window must be withdrawed, then do it now.
1297 * Must do some optimization, 'though */
1299 wwin
->flags
.mapped
= 0;
1300 wClientSetState(wwin
, WithdrawnState
, None
);
1301 wUnmanageWindow(wwin
, True
, False
);
1313 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1314 char *title
, int x
, int y
, int width
, int height
)
1319 wwin
= wWindowCreate();
1321 WMAddNotificationObserver(appearanceObserver
, wwin
,
1322 WNWindowAppearanceSettingsChanged
, wwin
);
1324 wwin
->flags
.internal_window
= 1;
1326 WSETUFLAG(wwin
, omnipresent
, 1);
1327 WSETUFLAG(wwin
, no_shadeable
, 1);
1328 WSETUFLAG(wwin
, no_resizable
, 1);
1329 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1331 wwin
->focus_mode
= WFM_PASSIVE
;
1333 wwin
->client_win
= window
;
1334 wwin
->screen_ptr
= scr
;
1336 wwin
->transient_for
= owner
;
1340 wwin
->client
.width
= width
;
1341 wwin
->client
.height
= height
;
1343 wwin
->frame_x
= wwin
->client
.x
;
1344 wwin
->frame_y
= wwin
->client
.y
;
1347 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1348 foo
|= WFF_TITLEBAR
;
1349 #ifdef XKB_BUTTON_HINT
1350 foo
|= WFF_LANGUAGE_BUTTON
;
1353 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1354 wwin
->frame_x
, wwin
->frame_y
,
1356 &wPreferences
.window_title_clearance
, foo
,
1357 scr
->window_title_texture
,
1358 scr
->resizebar_texture
,
1359 scr
->window_title_pixel
,
1360 &scr
->window_title_gc
,
1363 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1365 wwin
->frame
->flags
.is_client_window_frame
= 1;
1366 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1368 wFrameWindowChangeTitle(wwin
->frame
, title
);
1370 /* setup button images */
1371 wWindowUpdateButtonImages(wwin
);
1374 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1376 wwin
->frame
->child
= wwin
;
1378 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1380 #ifdef XKB_BUTTON_HINT
1381 if (wPreferences
.modelock
)
1382 wwin
->frame
->on_click_language
= windowLanguageClick
;
1385 wwin
->frame
->on_click_right
= windowCloseClick
;
1387 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1388 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1390 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1392 wwin
->client
.y
+= wwin
->frame
->top_width
;
1393 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1394 0, wwin
->frame
->top_width
);
1396 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1397 wwin
->client
.width
, wwin
->client
.height
);
1399 /* setup the frame descriptor */
1400 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1401 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1402 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1405 XLowerWindow(dpy
, window
);
1406 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1408 /* setup stacking descriptor */
1411 wPreferences
.on_top_transients
&&
1413 wwin
->transient_for
!=None
1414 && wwin
->transient_for
!=scr
->root_win
) {
1416 tmp
= wWindowFor(wwin
->transient_for
);
1418 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1420 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1424 if (!scr
->focused_window
) {
1425 /* first window on the list */
1428 scr
->focused_window
= wwin
;
1432 /* add window at beginning of focus window list */
1433 tmp
= scr
->focused_window
;
1441 if (wwin
->flags
.is_gnustep
== 0)
1442 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1444 /* if (wPreferences.auto_focus)*/
1445 wSetFocusTo(scr
, wwin
);
1447 wWindowResetMouseGrabs(wwin
);
1449 wWindowSetKeyGrabs(wwin
);
1451 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1458 *----------------------------------------------------------------------
1460 * Removes the frame window from a window and destroys all data
1461 * related to it. The window will be reparented back to the root window
1462 * if restore is True.
1465 * Everything related to the window is destroyed and the window
1466 * is removed from the window lists. Focus is set to the previous on the
1468 *----------------------------------------------------------------------
1471 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1473 WCoreWindow
*frame
= wwin
->frame
->core
;
1474 WWindow
*owner
= NULL
;
1475 WWindow
*newFocusedWindow
= NULL
;
1477 WScreen
*scr
= wwin
->screen_ptr
;
1481 wwin
->frame
->workspace
= -1;
1483 wKWMUpdateClientWorkspace(wwin
);
1486 /* First close attribute editor window if open */
1487 if (wwin
->flags
.inspector_open
) {
1488 wCloseInspectorForWindow(wwin
);
1491 /* Close window menu if it's open for this window */
1492 if (wwin
->flags
.menu_open_for_me
) {
1493 CloseWindowMenu(scr
);
1497 if (!wwin
->flags
.internal_window
)
1498 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1500 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1502 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1503 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1506 XUnmapWindow(dpy
, frame
->window
);
1508 XUnmapWindow(dpy
, wwin
->client_win
);
1510 /* deselect window */
1511 wSelectWindow(wwin
, False
);
1513 /* remove all pending events on window */
1514 /* I think this only matters for autoraise */
1515 if (wPreferences
.raise_delay
)
1516 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1520 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1522 /* reparent the window back to the root */
1524 wClientRestore(wwin
);
1526 if (wwin
->transient_for
!=scr
->root_win
) {
1527 owner
= wWindowFor(wwin
->transient_for
);
1529 if (!owner
->flags
.semi_focused
) {
1532 owner
->flags
.semi_focused
= 0;
1537 wasFocused
= wwin
->flags
.focused
;
1539 /* remove from window focus list */
1540 if (!wwin
->prev
&& !wwin
->next
) {
1541 /* was the only window */
1542 scr
->focused_window
= NULL
;
1543 newFocusedWindow
= NULL
;
1548 wwin
->prev
->next
= wwin
->next
;
1550 wwin
->next
->prev
= wwin
->prev
;
1552 scr
->focused_window
= wwin
->prev
;
1553 scr
->focused_window
->next
= NULL
;
1556 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1558 /* if in click to focus mode and the window
1559 * was a transient, focus the owner window
1562 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1563 tmp
= wWindowFor(wwin
->transient_for
);
1564 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1568 /* otherwise, focus the next one in the focus list */
1570 tmp
= scr
->focused_window
;
1571 while (tmp
) { /* look for one in the window list first */
1572 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1573 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1577 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1578 tmp
= scr
->focused_window
;
1580 if (!WFLAGP(tmp
, no_focusable
)
1581 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1588 newFocusedWindow
= tmp
;
1590 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1595 /* This is to let the root window get the keyboard input
1596 * if Sloppy focus mode and no other window get focus.
1597 * This way keybindings will not freeze.
1600 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1601 &foo
, &foo
, &foo
, &foo
, &mask
))
1602 tmp
= wWindowFor(win
);
1605 newFocusedWindow
= tmp
;
1607 newFocusedWindow
= NULL
;
1611 if (!wwin
->flags
.internal_window
) {
1613 wGNOMERemoveClient(wwin
);
1616 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1621 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1622 (unsigned)frame
->window
);
1626 if (newFocusedWindow
!= owner
&& owner
) {
1627 if (wwin
->flags
.is_gnustep
== 0)
1628 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1630 wSetFocusTo(scr
, newFocusedWindow
);
1632 wWindowDestroy(wwin
);
1638 wWindowMap(WWindow
*wwin
)
1640 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1641 if (!wwin
->flags
.shaded
) {
1642 /* window will be remapped when getting MapNotify */
1643 XSelectInput(dpy
, wwin
->client_win
,
1644 wwin
->event_mask
& ~StructureNotifyMask
);
1645 XMapWindow(dpy
, wwin
->client_win
);
1646 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1648 wwin
->flags
.mapped
= 1;
1654 wWindowUnmap(WWindow
*wwin
)
1656 wwin
->flags
.mapped
= 0;
1658 /* prevent window withdrawal when getting UnmapNotify */
1659 XSelectInput(dpy
, wwin
->client_win
,
1660 wwin
->event_mask
& ~StructureNotifyMask
);
1661 XUnmapWindow(dpy
, wwin
->client_win
);
1662 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1664 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1670 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1675 #ifdef KEEP_XKB_LOCK_STATUS
1676 if (wPreferences
.modelock
) {
1677 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1679 #endif /* KEEP_XKB_LOCK_STATUS */
1681 wwin
->flags
.semi_focused
= 0;
1683 if (wwin
->flags
.is_gnustep
== 0)
1684 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1686 wwin
->flags
.focused
= 1;
1688 wWindowResetMouseGrabs(wwin
);
1690 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1692 if (owin
== wwin
|| !owin
)
1695 nowner
= wWindowFor(wwin
->transient_for
);
1697 /* new window is a transient for the old window */
1698 if (nowner
== owin
) {
1699 owin
->flags
.semi_focused
= 1;
1700 wWindowUnfocus(nowner
);
1704 oowner
= wWindowFor(owin
->transient_for
);
1706 /* new window is owner of old window */
1707 if (wwin
== oowner
) {
1708 wWindowUnfocus(owin
);
1713 wWindowUnfocus(owin
);
1717 /* new window has same owner of old window */
1718 if (oowner
== nowner
) {
1719 /* prevent unfocusing of owner */
1720 oowner
->flags
.semi_focused
= 0;
1721 wWindowUnfocus(owin
);
1722 oowner
->flags
.semi_focused
= 1;
1727 /* nowner != NULL && oowner != nowner */
1728 nowner
->flags
.semi_focused
= 1;
1729 wWindowUnfocus(nowner
);
1730 wWindowUnfocus(owin
);
1735 wWindowUnfocus(WWindow
*wwin
)
1737 CloseWindowMenu(wwin
->screen_ptr
);
1739 if (wwin
->flags
.is_gnustep
== 0)
1740 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1741 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1743 if (wwin
->transient_for
!=None
1744 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1746 owner
= wWindowFor(wwin
->transient_for
);
1747 if (owner
&& owner
->flags
.semi_focused
) {
1748 owner
->flags
.semi_focused
= 0;
1749 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1750 wWindowUnfocus(owner
);
1751 wFrameWindowPaint(owner
->frame
);
1755 wwin
->flags
.focused
= 0;
1757 wWindowResetMouseGrabs(wwin
);
1759 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1765 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1767 WApplication
*app
= wApplicationOf(wwin
->main_window
);
1770 char prefix
[32] = "";
1777 instIndex
= wApplicationIndexOfGroup(app
);
1780 wwin
->flags
.wm_name_changed
= 1;
1783 /* the hint was removed */
1784 title
= DEF_WINDOW_TITLE
;
1787 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1793 #ifndef NO_WINDOW_ENUMERATOR
1794 if (instIndex
> 0) {
1795 snprintf(prefix
, sizeof(prefix
), " [%i]", instIndex
);
1797 title
= wstrconcat(title
, prefix
);
1801 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1802 /* only update the menu if the title has actually changed */
1803 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE
);
1805 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1809 #ifndef NO_WINDOW_ENUMERATOR
1819 *----------------------------------------------------------------------
1821 * wWindowConstrainSize--
1822 * Constrains size for the client window, taking the maximal size,
1823 * window resize increments and other size hints into account.
1826 * The closest size to what was given that the client window can
1829 *----------------------------------------------------------------------
1832 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1834 int width
= *nwidth
;
1835 int height
= *nheight
;
1838 int minW
= 1, minH
= 1;
1839 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1840 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1841 int minAX
= -1, minAY
= -1;
1842 int maxAX
= -1, maxAY
= -1;
1846 if (wwin
->normal_hints
) {
1847 winc
= wwin
->normal_hints
->width_inc
;
1848 hinc
= wwin
->normal_hints
->height_inc
;
1849 minW
= wwin
->normal_hints
->min_width
;
1850 minH
= wwin
->normal_hints
->min_height
;
1851 maxW
= wwin
->normal_hints
->max_width
;
1852 maxH
= wwin
->normal_hints
->max_height
;
1853 if (wwin
->normal_hints
->flags
& PAspect
) {
1854 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1855 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1856 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1857 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1860 baseW
= wwin
->normal_hints
->base_width
;
1861 baseH
= wwin
->normal_hints
->base_height
;
1874 /* aspect ratio code borrowed from olwm */
1876 /* adjust max aspect ratio */
1877 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1878 if (maxAX
> maxAY
) {
1879 height
= (width
* maxAY
) / maxAX
;
1880 if (height
> maxH
) {
1882 width
= (height
* maxAX
) / maxAY
;
1885 width
= (height
* maxAX
) / maxAY
;
1888 height
= (width
* maxAY
) / maxAX
;
1893 /* adjust min aspect ratio */
1894 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1895 if (minAX
> minAY
) {
1896 height
= (width
* minAY
) / minAX
;
1897 if (height
< minH
) {
1899 width
= (height
* minAX
) / minAY
;
1902 width
= (height
* minAX
) / minAY
;
1905 height
= (width
* minAY
) / minAX
;
1912 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1914 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1918 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1920 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1923 /* broken stupid apps may cause preposterous values for these.. */
1932 wWindowCropSize(WWindow
*wwin
, int maxW
, int maxH
,
1933 int *width
, int *height
)
1935 int baseW
= 0, baseH
= 0;
1936 int winc
= 1, hinc
= 1;
1938 if (wwin
->normal_hints
) {
1939 baseW
= wwin
->normal_hints
->base_width
;
1940 baseH
= wwin
->normal_hints
->base_height
;
1942 winc
= wwin
->normal_hints
->width_inc
;
1943 hinc
= wwin
->normal_hints
->height_inc
;
1947 *width
= maxW
- (maxW
- baseW
) % winc
;
1950 *height
= maxH
- (maxH
- baseH
) % hinc
;
1955 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1957 WScreen
*scr
= wwin
->screen_ptr
;
1961 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1962 || workspace
== wwin
->frame
->workspace
)
1965 if (workspace
!= scr
->current_workspace
) {
1966 /* Sent to other workspace. Unmap window */
1967 if ((wwin
->flags
.mapped
1968 || wwin
->flags
.shaded
1969 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1970 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1972 wapp
= wApplicationOf(wwin
->main_window
);
1974 wapp
->last_workspace
= workspace
;
1976 if (wwin
->flags
.miniaturized
) {
1978 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1979 wwin
->icon
->mapped
= 0;
1983 wSetFocusTo(scr
, NULL
);
1987 /* brought to current workspace. Map window */
1988 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1990 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1991 wwin
->icon
->mapped
= 1;
1993 } else if (!wwin
->flags
.mapped
&&
1994 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1998 if (!IS_OMNIPRESENT(wwin
)) {
1999 wwin
->frame
->workspace
= workspace
;
2000 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
2003 wGNOMEUpdateClientStateHint(wwin
, True
);
2006 wKWMUpdateClientWorkspace(wwin
);
2007 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2016 wWindowSynthConfigureNotify(WWindow
*wwin
)
2020 sevent
.type
= ConfigureNotify
;
2021 sevent
.xconfigure
.display
= dpy
;
2022 sevent
.xconfigure
.event
= wwin
->client_win
;
2023 sevent
.xconfigure
.window
= wwin
->client_win
;
2025 sevent
.xconfigure
.x
= wwin
->client
.x
;
2026 sevent
.xconfigure
.y
= wwin
->client
.y
;
2027 sevent
.xconfigure
.width
= wwin
->client
.width
;
2028 sevent
.xconfigure
.height
= wwin
->client
.height
;
2030 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2031 if (WFLAGP(wwin
, no_titlebar
))
2032 sevent
.xconfigure
.above
= None
;
2034 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2036 sevent
.xconfigure
.override_redirect
= False
;
2037 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2039 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2046 *----------------------------------------------------------------------
2047 * wWindowConfigure--
2048 * Configures the frame, decorations and client window to the
2049 * specified geometry. The geometry is not checked for validity,
2050 * wWindowConstrainSize() must be used for that.
2051 * The size parameters are for the client window, but the position is
2053 * The client window receives a ConfigureNotify event, according
2054 * to what ICCCM says.
2060 * Window size and position are changed and client window receives
2061 * a ConfigureNotify event.
2062 *----------------------------------------------------------------------
2065 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2067 int req_x
, req_y
; /* new position of the frame */
2068 int req_width
, req_height
; /* new size of the client */
2070 int synth_notify
= False
;
2073 resize
= (req_width
!=wwin
->client
.width
2074 || req_height
!=wwin
->client
.height
);
2076 * if the window is being moved but not resized then
2077 * send a synthetic ConfigureNotify
2079 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2080 synth_notify
= True
;
2083 if (WFLAGP(wwin
, dont_move_off
))
2084 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2085 req_width
, req_height
);
2087 if (req_width
< MIN_WINDOW_SIZE
)
2088 req_width
= MIN_WINDOW_SIZE
;
2089 if (req_height
< MIN_WINDOW_SIZE
)
2090 req_height
= MIN_WINDOW_SIZE
;
2092 /* If growing, resize inner part before frame,
2093 * if shrinking, resize frame before.
2094 * This will prevent the frame (that can have a different color)
2095 * to be exposed, causing flicker */
2096 if (req_height
> wwin
->frame
->core
->height
2097 || req_width
> wwin
->frame
->core
->width
)
2098 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2100 if (wwin
->flags
.shaded
) {
2101 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2102 req_width
, wwin
->frame
->core
->height
);
2103 wwin
->old_geometry
.height
= req_height
;
2107 h
= req_height
+ wwin
->frame
->top_width
2108 + wwin
->frame
->bottom_width
;
2110 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2113 if (!(req_height
> wwin
->frame
->core
->height
2114 || req_width
> wwin
->frame
->core
->width
))
2115 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2117 wwin
->client
.x
= req_x
;
2118 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2119 wwin
->client
.width
= req_width
;
2120 wwin
->client
.height
= req_height
;
2122 wwin
->client
.x
= req_x
;
2123 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2125 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2127 wwin
->frame_x
= req_x
;
2128 wwin
->frame_y
= req_y
;
2129 if (!WFLAGP(wwin
, no_border
)) {
2130 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2131 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2135 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2136 wWindowSetShape(wwin
);
2141 wWindowSynthConfigureNotify(wwin
);
2147 wWindowMove(wwin
, req_x
, req_y
)
2149 int req_x
, req_y
; /* new position of the frame */
2151 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2152 int synth_notify
= False
;
2154 /* Send a synthetic ConfigureNotify event for every window movement. */
2155 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2156 synth_notify
= True
;
2159 /* A single synthetic ConfigureNotify event is sent at the end of
2160 * a completed (opaque) movement in moveres.c */
2163 if (WFLAGP(wwin
, dont_move_off
))
2164 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2165 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2167 wwin
->client
.x
= req_x
;
2168 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2169 if (!WFLAGP(wwin
, no_border
)) {
2170 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2171 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2174 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2176 wwin
->frame_x
= req_x
;
2177 wwin
->frame_y
= req_y
;
2179 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2181 wWindowSynthConfigureNotify(wwin
);
2187 wWindowUpdateButtonImages(WWindow
*wwin
)
2189 WScreen
*scr
= wwin
->screen_ptr
;
2190 Pixmap pixmap
, mask
;
2191 WFrameWindow
*fwin
= wwin
->frame
;
2193 if (WFLAGP(wwin
, no_titlebar
))
2196 /* miniaturize button */
2198 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2199 if (wwin
->wm_gnustep_attr
2200 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2201 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2203 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2204 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2209 if (fwin
->lbutton_image
2210 && (fwin
->lbutton_image
->image
!= pixmap
2211 || fwin
->lbutton_image
->mask
!= mask
)) {
2212 wPixmapDestroy(fwin
->lbutton_image
);
2213 fwin
->lbutton_image
= NULL
;
2216 if (!fwin
->lbutton_image
) {
2217 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2218 fwin
->lbutton_image
->client_owned
= 1;
2219 fwin
->lbutton_image
->client_owned_mask
= 1;
2222 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2223 wPixmapDestroy(fwin
->lbutton_image
);
2225 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2229 #ifdef XKB_BUTTON_HINT
2230 if (!WFLAGP(wwin
, no_language_button
)) {
2231 if (fwin
->languagebutton_image
&&
2232 !fwin
->languagebutton_image
->shared
) {
2233 wPixmapDestroy(fwin
->languagebutton_image
);
2235 fwin
->languagebutton_image
=
2236 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2242 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2243 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2245 if (!WFLAGP(wwin
, no_close_button
)) {
2246 if (wwin
->wm_gnustep_attr
2247 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2248 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2250 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2251 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2255 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2256 || fwin
->rbutton_image
->mask
!= mask
)) {
2257 wPixmapDestroy(fwin
->rbutton_image
);
2258 fwin
->rbutton_image
= NULL
;
2261 if (!fwin
->rbutton_image
) {
2262 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2263 fwin
->rbutton_image
->client_owned
= 1;
2264 fwin
->rbutton_image
->client_owned_mask
= 1;
2267 } else if (WFLAGP(wwin
, kill_close
)) {
2269 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2270 wPixmapDestroy(fwin
->rbutton_image
);
2272 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2274 } else if (MGFLAGP(wwin
, broken_close
)) {
2276 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2277 wPixmapDestroy(fwin
->rbutton_image
);
2279 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2283 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2284 wPixmapDestroy(fwin
->rbutton_image
);
2286 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2290 /* force buttons to be redrawn */
2291 fwin
->flags
.need_texture_change
= 1;
2292 wFrameWindowPaint(fwin
);
2297 *---------------------------------------------------------------------------
2298 * wWindowConfigureBorders--
2299 * Update window border configuration according to attribute flags.
2301 *---------------------------------------------------------------------------
2304 wWindowConfigureBorders(WWindow
*wwin
)
2310 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2311 #ifdef XKB_BUTTON_HINT
2312 flags
|= WFF_LANGUAGE_BUTTON
;
2314 if (!WFLAGP(wwin
, no_titlebar
))
2315 flags
|= WFF_TITLEBAR
;
2316 if (!WFLAGP(wwin
, no_resizebar
))
2317 flags
|= WFF_RESIZEBAR
;
2318 if (!WFLAGP(wwin
, no_border
))
2319 flags
|= WFF_BORDER
;
2320 if (wwin
->flags
.shaded
)
2321 flags
|= WFF_IS_SHADED
;
2323 oldh
= wwin
->frame
->top_width
;
2324 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2325 if (oldh
!= wwin
->frame
->top_width
) {
2326 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2328 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2329 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2330 wwin
->client
.width
, wwin
->client
.height
);
2334 if (!WFLAGP(wwin
, no_miniaturize_button
)
2335 && wwin
->frame
->flags
.hide_left_button
)
2336 flags
|= WFF_LEFT_BUTTON
;
2338 #ifdef XKB_BUTTON_HINT
2339 if (!WFLAGP(wwin
, no_language_button
)
2340 && wwin
->frame
->flags
.hide_language_button
)
2341 flags
|= WFF_LANGUAGE_BUTTON
;
2344 if (!WFLAGP(wwin
, no_close_button
)
2345 && wwin
->frame
->flags
.hide_right_button
)
2346 flags
|= WFF_RIGHT_BUTTON
;
2349 wWindowUpdateButtonImages(wwin
);
2350 wFrameWindowShowButton(wwin
->frame
, flags
);
2354 if (WFLAGP(wwin
, no_miniaturize_button
)
2355 && !wwin
->frame
->flags
.hide_left_button
)
2356 flags
|= WFF_LEFT_BUTTON
;
2358 #ifdef XKB_BUTTON_HINT
2359 if (WFLAGP(wwin
, no_language_button
)
2360 && !wwin
->frame
->flags
.hide_language_button
)
2361 flags
|= WFF_LANGUAGE_BUTTON
;
2364 if (WFLAGP(wwin
, no_close_button
)
2365 && !wwin
->frame
->flags
.hide_right_button
)
2366 flags
|= WFF_RIGHT_BUTTON
;
2369 wFrameWindowHideButton(wwin
->frame
, flags
);
2372 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2373 wWindowSetShape(wwin
);
2381 wWindowSaveState(WWindow
*wwin
)
2386 memset(data
, 0, sizeof(CARD32
)*10);
2387 data
[0] = wwin
->frame
->workspace
;
2388 data
[1] = wwin
->flags
.miniaturized
;
2389 data
[2] = wwin
->flags
.shaded
;
2390 data
[3] = wwin
->flags
.hidden
;
2391 data
[4] = wwin
->flags
.maximized
;
2392 if (wwin
->flags
.maximized
== 0) {
2393 data
[5] = wwin
->frame_x
;
2394 data
[6] = wwin
->frame_y
;
2395 data
[7] = wwin
->frame
->core
->width
;
2396 data
[8] = wwin
->frame
->core
->height
;
2398 data
[5] = wwin
->old_geometry
.x
;
2399 data
[6] = wwin
->old_geometry
.y
;
2400 data
[7] = wwin
->old_geometry
.width
;
2401 data
[8] = wwin
->old_geometry
.height
;
2404 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2405 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2406 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2409 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2410 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2411 (unsigned char *)data
, 10);
2416 getSavedState(Window window
, WSavedState
**state
)
2420 unsigned long nitems_ret
;
2421 unsigned long bytes_after_ret
;
2424 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2425 True
, _XA_WINDOWMAKER_STATE
,
2426 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2427 (unsigned char **)&data
)!=Success
|| !data
)
2430 *state
= wmalloc(sizeof(WSavedState
));
2432 (*state
)->workspace
= data
[0];
2433 (*state
)->miniaturized
= data
[1];
2434 (*state
)->shaded
= data
[2];
2435 (*state
)->hidden
= data
[3];
2436 (*state
)->maximized
= data
[4];
2437 (*state
)->x
= data
[5];
2438 (*state
)->y
= data
[6];
2439 (*state
)->w
= data
[7];
2440 (*state
)->h
= data
[8];
2441 (*state
)->window_shortcuts
= data
[9];
2445 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2454 wWindowClearShape(WWindow
*wwin
)
2456 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2457 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2462 wWindowSetShape(WWindow
*wwin
)
2466 #ifdef OPTIMIZE_SHAPE
2471 /* only shape is the client's */
2472 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2476 /* Get array of rectangles describing the shape mask */
2477 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2483 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2489 /* insert our decoration rectangles in the rect list */
2490 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2493 if (!WFLAGP(wwin
, no_titlebar
)) {
2495 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2496 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2497 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2500 if (!WFLAGP(wwin
, no_resizebar
)) {
2502 urec
[count
].y
= wwin
->frame
->core
->height
2503 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2504 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2505 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2509 /* shape our frame window */
2510 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2511 0, wwin
->frame
->top_width
, urec
, count
,
2512 ShapeSet
, Unsorted
);
2518 #endif /* OPTIMIZE_SHAPE */
2520 if (!WFLAGP(wwin
, no_titlebar
)) {
2523 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2524 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2527 if (!WFLAGP(wwin
, no_resizebar
)) {
2529 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2530 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2531 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2535 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2536 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2538 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2539 0, wwin
->frame
->top_width
, wwin
->client_win
,
2540 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2545 /* ====================================================================== */
2548 getFocusMode(WWindow
*wwin
)
2552 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2553 if (wwin
->wm_hints
->input
== True
) {
2554 if (wwin
->protocols
.TAKE_FOCUS
)
2555 mode
= WFM_LOCALLY_ACTIVE
;
2559 if (wwin
->protocols
.TAKE_FOCUS
)
2560 mode
= WFM_GLOBALLY_ACTIVE
;
2562 mode
= WFM_NO_INPUT
;
2572 wWindowSetKeyGrabs(WWindow
*wwin
)
2577 for (i
=0; i
<WKBD_LAST
; i
++) {
2578 key
= &wKeyBindings
[i
];
2580 if (key
->keycode
==0)
2582 if (key
->modifier
!=AnyModifier
) {
2583 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2584 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2586 /* Also grab all modifier combinations possible that include,
2587 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2588 * work even if the NumLock/ScrollLock key is on.
2590 wHackedGrabKey(key
->keycode
, key
->modifier
,
2591 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2595 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2596 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2600 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2607 wWindowResetMouseGrabs(WWindow
*wwin
)
2609 /* Mouse grabs can't be done on the client window because of
2610 * ICCCM and because clients that try to do the same will crash.
2612 * But there is a problem wich makes tbar buttons of unfocused
2613 * windows not usable as the click goes to the frame window instead
2614 * of the button itself. Must figure a way to fix that.
2617 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2619 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2620 /* grabs for Meta+drag */
2621 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2622 True
, ButtonPressMask
, GrabModeSync
,
2623 GrabModeAsync
, None
, None
);
2626 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2627 && !wwin
->flags
.is_gnustep
) {
2628 /* the passive grabs to focus the window */
2629 /* if (wPreferences.focus_mode == WKF_CLICK) */
2630 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2631 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2639 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2641 if (attr
->flags
& GSExtraFlagsAttr
) {
2642 if (MGFLAGP(wwin
, broken_close
) !=
2643 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2644 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2645 wWindowUpdateButtonImages(wwin
);
2652 wWindowAddSavedState(char *instance
, char *class, char *command
,
2653 pid_t pid
, WSavedState
*state
)
2655 WWindowState
*wstate
;
2657 wstate
= malloc(sizeof(WWindowState
));
2661 memset(wstate
, 0, sizeof(WWindowState
));
2664 wstate
->instance
= wstrdup(instance
);
2666 wstate
->class = wstrdup(class);
2668 wstate
->command
= wstrdup(command
);
2669 wstate
->state
= state
;
2671 wstate
->next
= windowState
;
2672 windowState
= wstate
;
2675 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2683 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2687 wWindowGetSavedState(Window win
)
2689 char *instance
, *class, *command
=NULL
;
2690 WWindowState
*wstate
= windowState
;
2697 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2699 command
= wtokenjoin(argv
, argc
);
2700 XFreeStringList(argv
);
2705 if (PropGetWMClass(win
, &class, &instance
)) {
2707 if (SAME(instance
, wstate
->instance
) &&
2708 SAME(class, wstate
->class) &&
2709 SAME(command
, wstate
->command
)) {
2712 wstate
= wstate
->next
;
2719 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2723 if (command
) wfree(command
);
2724 if (instance
) XFree(instance
);
2725 if (class) XFree(class);
2732 wWindowDeleteSavedState(WMagicNumber id
)
2734 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2736 if (!wstate
|| !windowState
)
2741 windowState
= wstate
->next
;
2743 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2744 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2746 if (wstate
->instance
) wfree(wstate
->instance
);
2747 if (wstate
->class) wfree(wstate
->class);
2748 if (wstate
->command
) wfree(wstate
->command
);
2749 wfree(wstate
->state
);
2753 if (tmp
->next
==wstate
) {
2754 tmp
->next
=wstate
->next
;
2756 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2757 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2759 if (wstate
->instance
) wfree(wstate
->instance
);
2760 if (wstate
->class) wfree(wstate
->class);
2761 if (wstate
->command
) wfree(wstate
->command
);
2762 wfree(wstate
->state
);
2773 wWindowDeleteSavedStatesForPID(pid_t pid
)
2775 WWindowState
*tmp
, *wstate
;
2781 if (tmp
->pid
== pid
) {
2782 wstate
= windowState
;
2783 windowState
= tmp
->next
;
2785 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2786 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2788 if (wstate
->instance
) wfree(wstate
->instance
);
2789 if (wstate
->class) wfree(wstate
->class);
2790 if (wstate
->command
) wfree(wstate
->command
);
2791 wfree(wstate
->state
);
2795 if (tmp
->next
->pid
==pid
) {
2797 tmp
->next
= wstate
->next
;
2799 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2800 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2802 if (wstate
->instance
) wfree(wstate
->instance
);
2803 if (wstate
->class) wfree(wstate
->class);
2804 if (wstate
->command
) wfree(wstate
->command
);
2805 wfree(wstate
->state
);
2815 /* ====================================================================== */
2818 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2820 WWindow
*wwin
= data
;
2822 #ifndef NUMLOCK_HACK
2823 if ((event
->xbutton
.state
& ValidModMask
)
2824 != (event
->xbutton
.state
& ~LockMask
)) {
2825 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2826 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2830 event
->xbutton
.state
&= ValidModMask
;
2832 CloseWindowMenu(wwin
->screen_ptr
);
2834 if (wPreferences
.focus_mode
==WKF_CLICK
2835 && !(event
->xbutton
.state
&ControlMask
)
2836 && !WFLAGP(wwin
, no_focusable
)) {
2837 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2840 if (event
->xbutton
.button
== Button1
)
2841 wRaiseFrame(wwin
->frame
->core
);
2843 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2844 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2845 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2846 GrabModeAsync
, GrabModeAsync
, None
,
2847 None
, CurrentTime
)!=GrabSuccess
) {
2849 wwarning("pointer grab failed for window move");
2855 if (event
->xbutton
.state
& MOD_MASK
) {
2856 /* move the window */
2857 wMouseMoveWindow(wwin
, event
);
2858 XUngrabPointer(dpy
, CurrentTime
);
2860 wMouseResizeWindow(wwin
, event
);
2861 XUngrabPointer(dpy
, CurrentTime
);
2868 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2870 WWindow
*wwin
= data
;
2872 event
->xbutton
.state
&= ValidModMask
;
2874 if (event
->xbutton
.button
==Button1
) {
2875 if (event
->xbutton
.state
== 0) {
2876 if (!WFLAGP(wwin
, no_shadeable
)) {
2878 if (wwin
->flags
.shaded
)
2879 wUnshadeWindow(wwin
);
2886 if (event
->xbutton
.state
& ControlMask
)
2887 dir
|= MAX_VERTICAL
;
2889 if (event
->xbutton
.state
& ShiftMask
) {
2890 dir
|= MAX_HORIZONTAL
;
2891 if (!(event
->xbutton
.state
& ControlMask
))
2892 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2895 /* maximize window */
2896 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2897 int ndir
= dir
^ wwin
->flags
.maximized
;
2898 if (wwin
->flags
.maximized
!= 0)
2899 wUnmaximizeWindow(wwin
);
2901 wMaximizeWindow(wwin
, ndir
);
2904 } else if (event
->xbutton
.button
==Button3
) {
2905 if (event
->xbutton
.state
& MOD_MASK
) {
2906 wHideOtherApplications(wwin
);
2908 } else if (event
->xbutton
.button
==Button2
) {
2909 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2915 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2917 WWindow
*wwin
= desc
->parent
;
2919 event
->xbutton
.state
&= ValidModMask
;
2921 CloseWindowMenu(wwin
->screen_ptr
);
2923 if (/*wPreferences.focus_mode==WKF_CLICK
2924 &&*/ !(event
->xbutton
.state
&ControlMask
)
2925 && !WFLAGP(wwin
, no_focusable
)) {
2926 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2928 if (event
->xbutton
.button
== Button1
) {
2929 wRaiseFrame(wwin
->frame
->core
);
2932 if (event
->xbutton
.state
& MOD_MASK
) {
2933 /* move the window */
2934 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2935 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2936 GrabModeAsync
, GrabModeAsync
, None
,
2937 None
, CurrentTime
)!=GrabSuccess
) {
2939 wwarning("pointer grab failed for window move");
2943 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2944 wMouseResizeWindow(wwin
, event
);
2946 wMouseMoveWindow(wwin
, event
);
2947 XUngrabPointer(dpy
, CurrentTime
);
2953 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2955 WWindow
*wwin
= (WWindow
*)data
;
2957 #ifndef NUMLOCK_HACK
2958 if ((event
->xbutton
.state
& ValidModMask
)
2959 != (event
->xbutton
.state
& ~LockMask
)) {
2960 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2961 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2964 event
->xbutton
.state
&= ValidModMask
;
2966 CloseWindowMenu(wwin
->screen_ptr
);
2968 if (wPreferences
.focus_mode
==WKF_CLICK
2969 && !(event
->xbutton
.state
&ControlMask
)
2970 && !WFLAGP(wwin
, no_focusable
)) {
2971 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2974 if (event
->xbutton
.button
== Button1
2975 || event
->xbutton
.button
== Button2
) {
2977 if (event
->xbutton
.button
== Button1
) {
2978 if (event
->xbutton
.state
& MOD_MASK
) {
2979 wLowerFrame(wwin
->frame
->core
);
2981 wRaiseFrame(wwin
->frame
->core
);
2984 if ((event
->xbutton
.state
& ShiftMask
)
2985 && !(event
->xbutton
.state
& ControlMask
)) {
2986 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2989 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2990 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2991 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2992 GrabModeAsync
, GrabModeAsync
, None
,
2993 None
, CurrentTime
)!=GrabSuccess
) {
2995 wwarning("pointer grab failed for window move");
3000 /* move the window */
3001 wMouseMoveWindow(wwin
, event
);
3003 XUngrabPointer(dpy
, CurrentTime
);
3004 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
3005 && !wwin
->flags
.internal_window
3006 && !WCHECK_STATE(WSTATE_MODAL
)) {
3007 WObjDescriptor
*desc
;
3009 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3010 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3011 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3012 GrabModeAsync
, GrabModeAsync
, None
,
3013 None
, CurrentTime
)!=GrabSuccess
) {
3015 wwarning("pointer grab failed for window move");
3020 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
3021 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3023 /* allow drag select */
3024 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3025 event
->xany
.send_event
= True
;
3026 (*desc
->handle_mousedown
)(desc
, event
);
3028 XUngrabPointer(dpy
, CurrentTime
);
3035 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3037 WWindow
*wwin
= data
;
3039 event
->xbutton
.state
&= ValidModMask
;
3041 CloseWindowMenu(wwin
->screen_ptr
);
3043 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3046 /* if control-click, kill the client */
3047 if (event
->xbutton
.state
& ControlMask
) {
3051 if (wwin
->flags
.olwm_push_pin_out
) {
3053 wwin
->flags
.olwm_push_pin_out
= 0;
3055 wOLWMChangePushpinState(wwin
, True
);
3057 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3062 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3063 /* send delete message */
3064 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3071 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3073 WWindow
*wwin
= data
;
3075 CloseWindowMenu(wwin
->screen_ptr
);
3077 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3080 /* send delete message */
3081 if (wwin
->protocols
.DELETE_WINDOW
) {
3082 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3089 #ifdef XKB_BUTTON_HINT
3091 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3093 WWindow
*wwin
= data
;
3094 WFrameWindow
*fwin
= wwin
->frame
;
3095 WScreen
*scr
= fwin
->screen_ptr
;
3096 XkbStateRec staterec
;
3099 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3101 tl
= wwin
->frame
->languagemode
;
3102 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3103 wwin
->frame
->last_languagemode
= tl
;
3104 wSetFocusTo(scr
, wwin
);
3105 wwin
->frame
->languagebutton_image
=
3106 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3107 wwin
->frame
->languagemode
];
3108 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3109 if (event
->xbutton
.button
== Button3
)
3111 wRaiseFrame(fwin
->core
);
3117 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3119 WWindow
*wwin
= data
;
3121 event
->xbutton
.state
&= ValidModMask
;
3123 CloseWindowMenu(wwin
->screen_ptr
);
3125 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3128 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3129 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3133 if ((event
->xbutton
.state
& ControlMask
) ||
3134 (event
->xbutton
.button
== Button3
)) {
3136 wapp
= wApplicationOf(wwin
->main_window
);
3137 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3138 wHideApplication(wapp
);
3139 } else if (event
->xbutton
.state
==0) {
3140 wIconifyWindow(wwin
);