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
1591 || wPreferences
.focus_mode
==WKF_POINTER
) {
1596 /* This is to let the root window get the keyboard input
1597 * if Sloppy focus mode and no other window get focus.
1598 * This way keybindings will not freeze.
1601 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1602 &foo
, &foo
, &foo
, &foo
, &mask
))
1603 tmp
= wWindowFor(win
);
1606 newFocusedWindow
= tmp
;
1608 newFocusedWindow
= NULL
;
1612 if (!wwin
->flags
.internal_window
) {
1614 wGNOMERemoveClient(wwin
);
1617 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1622 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1623 (unsigned)frame
->window
);
1627 if (newFocusedWindow
!= owner
&& owner
) {
1628 if (wwin
->flags
.is_gnustep
== 0)
1629 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1631 wSetFocusTo(scr
, newFocusedWindow
);
1633 wWindowDestroy(wwin
);
1639 wWindowMap(WWindow
*wwin
)
1641 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1642 if (!wwin
->flags
.shaded
) {
1643 /* window will be remapped when getting MapNotify */
1644 XSelectInput(dpy
, wwin
->client_win
,
1645 wwin
->event_mask
& ~StructureNotifyMask
);
1646 XMapWindow(dpy
, wwin
->client_win
);
1647 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1649 wwin
->flags
.mapped
= 1;
1655 wWindowUnmap(WWindow
*wwin
)
1657 wwin
->flags
.mapped
= 0;
1659 /* prevent window withdrawal when getting UnmapNotify */
1660 XSelectInput(dpy
, wwin
->client_win
,
1661 wwin
->event_mask
& ~StructureNotifyMask
);
1662 XUnmapWindow(dpy
, wwin
->client_win
);
1663 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1665 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1671 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1676 #ifdef KEEP_XKB_LOCK_STATUS
1677 if (wPreferences
.modelock
) {
1678 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1680 #endif /* KEEP_XKB_LOCK_STATUS */
1682 wwin
->flags
.semi_focused
= 0;
1684 if (wwin
->flags
.is_gnustep
== 0)
1685 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1687 wwin
->flags
.focused
= 1;
1689 wWindowResetMouseGrabs(wwin
);
1691 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1693 if (owin
== wwin
|| !owin
)
1696 nowner
= wWindowFor(wwin
->transient_for
);
1698 /* new window is a transient for the old window */
1699 if (nowner
== owin
) {
1700 owin
->flags
.semi_focused
= 1;
1701 wWindowUnfocus(nowner
);
1705 oowner
= wWindowFor(owin
->transient_for
);
1707 /* new window is owner of old window */
1708 if (wwin
== oowner
) {
1709 wWindowUnfocus(owin
);
1714 wWindowUnfocus(owin
);
1718 /* new window has same owner of old window */
1719 if (oowner
== nowner
) {
1720 /* prevent unfocusing of owner */
1721 oowner
->flags
.semi_focused
= 0;
1722 wWindowUnfocus(owin
);
1723 oowner
->flags
.semi_focused
= 1;
1728 /* nowner != NULL && oowner != nowner */
1729 nowner
->flags
.semi_focused
= 1;
1730 wWindowUnfocus(nowner
);
1731 wWindowUnfocus(owin
);
1736 wWindowUnfocus(WWindow
*wwin
)
1738 CloseWindowMenu(wwin
->screen_ptr
);
1740 if (wwin
->flags
.is_gnustep
== 0)
1741 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1742 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1744 if (wwin
->transient_for
!=None
1745 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1747 owner
= wWindowFor(wwin
->transient_for
);
1748 if (owner
&& owner
->flags
.semi_focused
) {
1749 owner
->flags
.semi_focused
= 0;
1750 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1751 wWindowUnfocus(owner
);
1752 wFrameWindowPaint(owner
->frame
);
1756 wwin
->flags
.focused
= 0;
1758 wWindowResetMouseGrabs(wwin
);
1760 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1766 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1768 WApplication
*app
= wApplicationOf(wwin
->main_window
);
1771 char prefix
[32] = "";
1778 instIndex
= wApplicationIndexOfGroup(app
);
1781 wwin
->flags
.wm_name_changed
= 1;
1784 /* the hint was removed */
1785 title
= DEF_WINDOW_TITLE
;
1788 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1794 if (instIndex
> 0) {
1795 sprintf(prefix
, " [%i]", instIndex
);
1797 title
= wstrconcat(title
, prefix
);
1800 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1801 /* only update the menu if the title has actually changed */
1802 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE
);
1804 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1814 *----------------------------------------------------------------------
1816 * wWindowConstrainSize--
1817 * Constrains size for the client window, taking the maximal size,
1818 * window resize increments and other size hints into account.
1821 * The closest size to what was given that the client window can
1824 *----------------------------------------------------------------------
1827 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1829 int width
= *nwidth
;
1830 int height
= *nheight
;
1833 int minW
= 1, minH
= 1;
1834 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1835 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1836 int minAX
= -1, minAY
= -1;
1837 int maxAX
= -1, maxAY
= -1;
1841 if (wwin
->normal_hints
) {
1842 winc
= wwin
->normal_hints
->width_inc
;
1843 hinc
= wwin
->normal_hints
->height_inc
;
1844 minW
= wwin
->normal_hints
->min_width
;
1845 minH
= wwin
->normal_hints
->min_height
;
1846 maxW
= wwin
->normal_hints
->max_width
;
1847 maxH
= wwin
->normal_hints
->max_height
;
1848 if (wwin
->normal_hints
->flags
& PAspect
) {
1849 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1850 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1851 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1852 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1866 /* aspect ratio code borrowed from olwm */
1868 /* adjust max aspect ratio */
1869 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1870 if (maxAX
> maxAY
) {
1871 height
= (width
* maxAY
) / maxAX
;
1872 if (height
> maxH
) {
1874 width
= (height
* maxAX
) / maxAY
;
1877 width
= (height
* maxAX
) / maxAY
;
1880 height
= (width
* maxAY
) / maxAX
;
1885 /* adjust min aspect ratio */
1886 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1887 if (minAX
> minAY
) {
1888 height
= (width
* minAY
) / minAX
;
1889 if (height
< minH
) {
1891 width
= (height
* minAX
) / minAY
;
1894 width
= (height
* minAX
) / minAY
;
1897 height
= (width
* minAY
) / minAX
;
1904 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1906 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1910 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1912 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1915 /* broken stupid apps may cause preposterous values for these.. */
1924 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1926 WScreen
*scr
= wwin
->screen_ptr
;
1930 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1931 || workspace
== wwin
->frame
->workspace
)
1934 if (workspace
!= scr
->current_workspace
) {
1935 /* Sent to other workspace. Unmap window */
1936 if ((wwin
->flags
.mapped
1937 || wwin
->flags
.shaded
1938 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1939 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1941 wapp
= wApplicationOf(wwin
->main_window
);
1943 wapp
->last_workspace
= workspace
;
1945 if (wwin
->flags
.miniaturized
) {
1947 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1948 wwin
->icon
->mapped
= 0;
1952 wSetFocusTo(scr
, NULL
);
1956 /* brought to current workspace. Map window */
1957 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1959 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1960 wwin
->icon
->mapped
= 1;
1962 } else if (!wwin
->flags
.mapped
&&
1963 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1967 if (!IS_OMNIPRESENT(wwin
)) {
1968 wwin
->frame
->workspace
= workspace
;
1969 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1972 wGNOMEUpdateClientStateHint(wwin
, True
);
1975 wKWMUpdateClientWorkspace(wwin
);
1976 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1985 wWindowSynthConfigureNotify(WWindow
*wwin
)
1989 sevent
.type
= ConfigureNotify
;
1990 sevent
.xconfigure
.display
= dpy
;
1991 sevent
.xconfigure
.event
= wwin
->client_win
;
1992 sevent
.xconfigure
.window
= wwin
->client_win
;
1994 sevent
.xconfigure
.x
= wwin
->client
.x
;
1995 sevent
.xconfigure
.y
= wwin
->client
.y
;
1996 sevent
.xconfigure
.width
= wwin
->client
.width
;
1997 sevent
.xconfigure
.height
= wwin
->client
.height
;
1999 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2000 if (WFLAGP(wwin
, no_titlebar
))
2001 sevent
.xconfigure
.above
= None
;
2003 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2005 sevent
.xconfigure
.override_redirect
= False
;
2006 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2008 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2015 *----------------------------------------------------------------------
2016 * wWindowConfigure--
2017 * Configures the frame, decorations and client window to the
2018 * specified geometry. The geometry is not checked for validity,
2019 * wWindowConstrainSize() must be used for that.
2020 * The size parameters are for the client window, but the position is
2022 * The client window receives a ConfigureNotify event, according
2023 * to what ICCCM says.
2029 * Window size and position are changed and client window receives
2030 * a ConfigureNotify event.
2031 *----------------------------------------------------------------------
2034 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2036 int req_x
, req_y
; /* new position of the frame */
2037 int req_width
, req_height
; /* new size of the client */
2039 int synth_notify
= False
;
2042 resize
= (req_width
!=wwin
->client
.width
2043 || req_height
!=wwin
->client
.height
);
2045 * if the window is being moved but not resized then
2046 * send a synthetic ConfigureNotify
2048 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2049 synth_notify
= True
;
2052 if (WFLAGP(wwin
, dont_move_off
))
2053 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2054 req_width
, req_height
);
2056 if (req_width
< MIN_WINDOW_SIZE
)
2057 req_width
= MIN_WINDOW_SIZE
;
2058 if (req_height
< MIN_WINDOW_SIZE
)
2059 req_height
= MIN_WINDOW_SIZE
;
2061 /* If growing, resize inner part before frame,
2062 * if shrinking, resize frame before.
2063 * This will prevent the frame (that can have a different color)
2064 * to be exposed, causing flicker */
2065 if (req_height
> wwin
->frame
->core
->height
2066 || req_width
> wwin
->frame
->core
->width
)
2067 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2069 if (wwin
->flags
.shaded
) {
2070 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2071 req_width
, wwin
->frame
->core
->height
);
2072 wwin
->old_geometry
.height
= req_height
;
2076 h
= req_height
+ wwin
->frame
->top_width
2077 + wwin
->frame
->bottom_width
;
2079 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2082 if (!(req_height
> wwin
->frame
->core
->height
2083 || req_width
> wwin
->frame
->core
->width
))
2084 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2086 wwin
->client
.x
= req_x
;
2087 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2088 wwin
->client
.width
= req_width
;
2089 wwin
->client
.height
= req_height
;
2091 wwin
->client
.x
= req_x
;
2092 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2094 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2096 wwin
->frame_x
= req_x
;
2097 wwin
->frame_y
= req_y
;
2098 if (!WFLAGP(wwin
, no_border
)) {
2099 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2100 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2104 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2105 wWindowSetShape(wwin
);
2110 wWindowSynthConfigureNotify(wwin
);
2116 wWindowMove(wwin
, req_x
, req_y
)
2118 int req_x
, req_y
; /* new position of the frame */
2120 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2121 int synth_notify
= False
;
2123 /* Send a synthetic ConfigureNotify event for every window movement. */
2124 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2125 synth_notify
= True
;
2128 /* A single synthetic ConfigureNotify event is sent at the end of
2129 * a completed (opaque) movement in moveres.c */
2132 if (WFLAGP(wwin
, dont_move_off
))
2133 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2134 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2136 wwin
->client
.x
= req_x
;
2137 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2138 if (!WFLAGP(wwin
, no_border
)) {
2139 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2140 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2143 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2145 wwin
->frame_x
= req_x
;
2146 wwin
->frame_y
= req_y
;
2148 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2150 wWindowSynthConfigureNotify(wwin
);
2156 wWindowUpdateButtonImages(WWindow
*wwin
)
2158 WScreen
*scr
= wwin
->screen_ptr
;
2159 Pixmap pixmap
, mask
;
2160 WFrameWindow
*fwin
= wwin
->frame
;
2162 if (WFLAGP(wwin
, no_titlebar
))
2165 /* miniaturize button */
2167 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2168 if (wwin
->wm_gnustep_attr
2169 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2170 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2172 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2173 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2178 if (fwin
->lbutton_image
2179 && (fwin
->lbutton_image
->image
!= pixmap
2180 || fwin
->lbutton_image
->mask
!= mask
)) {
2181 wPixmapDestroy(fwin
->lbutton_image
);
2182 fwin
->lbutton_image
= NULL
;
2185 if (!fwin
->lbutton_image
) {
2186 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2187 fwin
->lbutton_image
->client_owned
= 1;
2188 fwin
->lbutton_image
->client_owned_mask
= 1;
2191 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2192 wPixmapDestroy(fwin
->lbutton_image
);
2194 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2198 #ifdef XKB_BUTTON_HINT
2199 if (!WFLAGP(wwin
, no_language_button
)) {
2200 if (fwin
->languagebutton_image
&&
2201 !fwin
->languagebutton_image
->shared
) {
2202 wPixmapDestroy(fwin
->languagebutton_image
);
2204 fwin
->languagebutton_image
=
2205 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2211 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2212 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2214 if (!WFLAGP(wwin
, no_close_button
)) {
2215 if (wwin
->wm_gnustep_attr
2216 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2217 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2219 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2220 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2224 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2225 || fwin
->rbutton_image
->mask
!= mask
)) {
2226 wPixmapDestroy(fwin
->rbutton_image
);
2227 fwin
->rbutton_image
= NULL
;
2230 if (!fwin
->rbutton_image
) {
2231 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2232 fwin
->rbutton_image
->client_owned
= 1;
2233 fwin
->rbutton_image
->client_owned_mask
= 1;
2236 } else if (WFLAGP(wwin
, kill_close
)) {
2238 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2239 wPixmapDestroy(fwin
->rbutton_image
);
2241 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2243 } else if (MGFLAGP(wwin
, broken_close
)) {
2245 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2246 wPixmapDestroy(fwin
->rbutton_image
);
2248 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2252 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2253 wPixmapDestroy(fwin
->rbutton_image
);
2255 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2259 /* force buttons to be redrawn */
2260 fwin
->flags
.need_texture_change
= 1;
2261 wFrameWindowPaint(fwin
);
2266 *---------------------------------------------------------------------------
2267 * wWindowConfigureBorders--
2268 * Update window border configuration according to attribute flags.
2270 *---------------------------------------------------------------------------
2273 wWindowConfigureBorders(WWindow
*wwin
)
2279 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2280 #ifdef XKB_BUTTON_HINT
2281 flags
|= WFF_LANGUAGE_BUTTON
;
2283 if (!WFLAGP(wwin
, no_titlebar
))
2284 flags
|= WFF_TITLEBAR
;
2285 if (!WFLAGP(wwin
, no_resizebar
))
2286 flags
|= WFF_RESIZEBAR
;
2287 if (!WFLAGP(wwin
, no_border
))
2288 flags
|= WFF_BORDER
;
2289 if (wwin
->flags
.shaded
)
2290 flags
|= WFF_IS_SHADED
;
2292 oldh
= wwin
->frame
->top_width
;
2293 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2294 if (oldh
!= wwin
->frame
->top_width
) {
2295 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2297 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2298 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2299 wwin
->client
.width
, wwin
->client
.height
);
2303 if (!WFLAGP(wwin
, no_miniaturize_button
)
2304 && wwin
->frame
->flags
.hide_left_button
)
2305 flags
|= WFF_LEFT_BUTTON
;
2307 #ifdef XKB_BUTTON_HINT
2308 if (!WFLAGP(wwin
, no_language_button
)
2309 && wwin
->frame
->flags
.hide_language_button
)
2310 flags
|= WFF_LANGUAGE_BUTTON
;
2313 if (!WFLAGP(wwin
, no_close_button
)
2314 && wwin
->frame
->flags
.hide_right_button
)
2315 flags
|= WFF_RIGHT_BUTTON
;
2318 wWindowUpdateButtonImages(wwin
);
2319 wFrameWindowShowButton(wwin
->frame
, flags
);
2323 if (WFLAGP(wwin
, no_miniaturize_button
)
2324 && !wwin
->frame
->flags
.hide_left_button
)
2325 flags
|= WFF_LEFT_BUTTON
;
2327 #ifdef XKB_BUTTON_HINT
2328 if (WFLAGP(wwin
, no_language_button
)
2329 && !wwin
->frame
->flags
.hide_language_button
)
2330 flags
|= WFF_LANGUAGE_BUTTON
;
2333 if (WFLAGP(wwin
, no_close_button
)
2334 && !wwin
->frame
->flags
.hide_right_button
)
2335 flags
|= WFF_RIGHT_BUTTON
;
2338 wFrameWindowHideButton(wwin
->frame
, flags
);
2341 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2342 wWindowSetShape(wwin
);
2350 wWindowSaveState(WWindow
*wwin
)
2355 memset(data
, 0, sizeof(CARD32
)*10);
2356 data
[0] = wwin
->frame
->workspace
;
2357 data
[1] = wwin
->flags
.miniaturized
;
2358 data
[2] = wwin
->flags
.shaded
;
2359 data
[3] = wwin
->flags
.hidden
;
2360 data
[4] = wwin
->flags
.maximized
;
2361 if (wwin
->flags
.maximized
== 0) {
2362 data
[5] = wwin
->frame_x
;
2363 data
[6] = wwin
->frame_y
;
2364 data
[7] = wwin
->frame
->core
->width
;
2365 data
[8] = wwin
->frame
->core
->height
;
2367 data
[5] = wwin
->old_geometry
.x
;
2368 data
[6] = wwin
->old_geometry
.y
;
2369 data
[7] = wwin
->old_geometry
.width
;
2370 data
[8] = wwin
->old_geometry
.height
;
2373 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2374 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2375 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2378 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2379 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2380 (unsigned char *)data
, 10);
2385 getSavedState(Window window
, WSavedState
**state
)
2389 unsigned long nitems_ret
;
2390 unsigned long bytes_after_ret
;
2393 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2394 True
, _XA_WINDOWMAKER_STATE
,
2395 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2396 (unsigned char **)&data
)!=Success
|| !data
)
2399 *state
= malloc(sizeof(WSavedState
));
2402 (*state
)->workspace
= data
[0];
2403 (*state
)->miniaturized
= data
[1];
2404 (*state
)->shaded
= data
[2];
2405 (*state
)->hidden
= data
[3];
2406 (*state
)->maximized
= data
[4];
2407 (*state
)->x
= data
[5];
2408 (*state
)->y
= data
[6];
2409 (*state
)->w
= data
[7];
2410 (*state
)->h
= data
[8];
2411 (*state
)->window_shortcuts
= data
[9];
2415 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2424 wWindowClearShape(WWindow
*wwin
)
2426 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2427 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2432 wWindowSetShape(WWindow
*wwin
)
2436 #ifdef OPTIMIZE_SHAPE
2441 /* only shape is the client's */
2442 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2446 /* Get array of rectangles describing the shape mask */
2447 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2453 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2459 /* insert our decoration rectangles in the rect list */
2460 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2463 if (!WFLAGP(wwin
, no_titlebar
)) {
2465 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2466 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2467 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2470 if (!WFLAGP(wwin
, no_resizebar
)) {
2472 urec
[count
].y
= wwin
->frame
->core
->height
2473 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2474 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2475 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2479 /* shape our frame window */
2480 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2481 0, wwin
->frame
->top_width
, urec
, count
,
2482 ShapeSet
, Unsorted
);
2488 #endif /* OPTIMIZE_SHAPE */
2490 if (!WFLAGP(wwin
, no_titlebar
)) {
2493 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2494 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2497 if (!WFLAGP(wwin
, no_resizebar
)) {
2499 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2500 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2501 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2505 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2506 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2508 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2509 0, wwin
->frame
->top_width
, wwin
->client_win
,
2510 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2515 /* ====================================================================== */
2518 getFocusMode(WWindow
*wwin
)
2522 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2523 if (wwin
->wm_hints
->input
== True
) {
2524 if (wwin
->protocols
.TAKE_FOCUS
)
2525 mode
= WFM_LOCALLY_ACTIVE
;
2529 if (wwin
->protocols
.TAKE_FOCUS
)
2530 mode
= WFM_GLOBALLY_ACTIVE
;
2532 mode
= WFM_NO_INPUT
;
2542 wWindowSetKeyGrabs(WWindow
*wwin
)
2547 for (i
=0; i
<WKBD_LAST
; i
++) {
2548 key
= &wKeyBindings
[i
];
2550 if (key
->keycode
==0)
2552 if (key
->modifier
!=AnyModifier
) {
2553 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2554 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2556 /* Also grab all modifier combinations possible that include,
2557 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2558 * work even if the NumLock/ScrollLock key is on.
2560 wHackedGrabKey(key
->keycode
, key
->modifier
,
2561 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2565 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2566 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2570 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2577 wWindowResetMouseGrabs(WWindow
*wwin
)
2579 /* Mouse grabs can't be done on the client window because of
2580 * ICCCM and because clients that try to do the same will crash.
2582 * But there is a problem wich makes tbar buttons of unfocused
2583 * windows not usable as the click goes to the frame window instead
2584 * of the button itself. Must figure a way to fix that.
2587 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2589 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2590 /* grabs for Meta+drag */
2591 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2592 True
, ButtonPressMask
, GrabModeSync
,
2593 GrabModeAsync
, None
, None
);
2596 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2597 && !wwin
->flags
.is_gnustep
) {
2598 /* the passive grabs to focus the window */
2599 /* if (wPreferences.focus_mode == WKF_CLICK) */
2600 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2601 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2609 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2611 if (attr
->flags
& GSExtraFlagsAttr
) {
2612 if (MGFLAGP(wwin
, broken_close
) !=
2613 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2614 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2615 wWindowUpdateButtonImages(wwin
);
2622 wWindowAddSavedState(char *instance
, char *class, char *command
,
2623 pid_t pid
, WSavedState
*state
)
2625 WWindowState
*wstate
;
2627 wstate
= malloc(sizeof(WWindowState
));
2631 memset(wstate
, 0, sizeof(WWindowState
));
2634 wstate
->instance
= wstrdup(instance
);
2636 wstate
->class = wstrdup(class);
2638 wstate
->command
= wstrdup(command
);
2639 wstate
->state
= state
;
2641 wstate
->next
= windowState
;
2642 windowState
= wstate
;
2645 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2653 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2657 wWindowGetSavedState(Window win
)
2659 char *instance
, *class, *command
=NULL
;
2660 WWindowState
*wstate
= windowState
;
2667 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2669 command
= wtokenjoin(argv
, argc
);
2670 XFreeStringList(argv
);
2675 if (PropGetWMClass(win
, &class, &instance
)) {
2677 if (SAME(instance
, wstate
->instance
) &&
2678 SAME(class, wstate
->class) &&
2679 SAME(command
, wstate
->command
)) {
2682 wstate
= wstate
->next
;
2689 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2693 if (command
) wfree(command
);
2694 if (instance
) XFree(instance
);
2695 if (class) XFree(class);
2702 wWindowDeleteSavedState(WMagicNumber id
)
2704 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2706 if (!wstate
|| !windowState
)
2711 windowState
= wstate
->next
;
2713 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2714 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2716 if (wstate
->instance
) wfree(wstate
->instance
);
2717 if (wstate
->class) wfree(wstate
->class);
2718 if (wstate
->command
) wfree(wstate
->command
);
2719 wfree(wstate
->state
);
2723 if (tmp
->next
==wstate
) {
2724 tmp
->next
=wstate
->next
;
2726 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2727 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2729 if (wstate
->instance
) wfree(wstate
->instance
);
2730 if (wstate
->class) wfree(wstate
->class);
2731 if (wstate
->command
) wfree(wstate
->command
);
2732 wfree(wstate
->state
);
2743 wWindowDeleteSavedStatesForPID(pid_t pid
)
2745 WWindowState
*tmp
, *wstate
;
2751 if (tmp
->pid
== pid
) {
2752 wstate
= windowState
;
2753 windowState
= tmp
->next
;
2755 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2756 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2758 if (wstate
->instance
) wfree(wstate
->instance
);
2759 if (wstate
->class) wfree(wstate
->class);
2760 if (wstate
->command
) wfree(wstate
->command
);
2761 wfree(wstate
->state
);
2765 if (tmp
->next
->pid
==pid
) {
2767 tmp
->next
= wstate
->next
;
2769 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2770 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2772 if (wstate
->instance
) wfree(wstate
->instance
);
2773 if (wstate
->class) wfree(wstate
->class);
2774 if (wstate
->command
) wfree(wstate
->command
);
2775 wfree(wstate
->state
);
2785 /* ====================================================================== */
2788 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2790 WWindow
*wwin
= data
;
2792 #ifndef NUMLOCK_HACK
2793 if ((event
->xbutton
.state
& ValidModMask
)
2794 != (event
->xbutton
.state
& ~LockMask
)) {
2795 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2796 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2800 event
->xbutton
.state
&= ValidModMask
;
2802 CloseWindowMenu(wwin
->screen_ptr
);
2804 if (wPreferences
.focus_mode
==WKF_CLICK
2805 && !(event
->xbutton
.state
&ControlMask
)
2806 && !WFLAGP(wwin
, no_focusable
)) {
2807 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2810 if (event
->xbutton
.button
== Button1
)
2811 wRaiseFrame(wwin
->frame
->core
);
2813 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2814 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2815 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2816 GrabModeAsync
, GrabModeAsync
, None
,
2817 None
, CurrentTime
)!=GrabSuccess
) {
2819 wwarning("pointer grab failed for window move");
2825 if (event
->xbutton
.state
& MOD_MASK
) {
2826 /* move the window */
2827 wMouseMoveWindow(wwin
, event
);
2828 XUngrabPointer(dpy
, CurrentTime
);
2830 wMouseResizeWindow(wwin
, event
);
2831 XUngrabPointer(dpy
, CurrentTime
);
2838 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2840 WWindow
*wwin
= data
;
2842 event
->xbutton
.state
&= ValidModMask
;
2844 if (event
->xbutton
.button
==Button1
) {
2845 if (event
->xbutton
.state
== 0) {
2846 if (!WFLAGP(wwin
, no_shadeable
)) {
2848 if (wwin
->flags
.shaded
)
2849 wUnshadeWindow(wwin
);
2856 if (event
->xbutton
.state
& ControlMask
)
2857 dir
|= MAX_VERTICAL
;
2859 if (event
->xbutton
.state
& ShiftMask
) {
2860 dir
|= MAX_HORIZONTAL
;
2861 if (!(event
->xbutton
.state
& ControlMask
))
2862 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2865 /* maximize window */
2866 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2867 int ndir
= dir
^ wwin
->flags
.maximized
;
2868 if (wwin
->flags
.maximized
!= 0)
2869 wUnmaximizeWindow(wwin
);
2871 wMaximizeWindow(wwin
, ndir
);
2874 } else if (event
->xbutton
.button
==Button3
) {
2875 if (event
->xbutton
.state
& MOD_MASK
) {
2876 wHideOtherApplications(wwin
);
2878 } else if (event
->xbutton
.button
==Button2
) {
2879 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2885 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2887 WWindow
*wwin
= desc
->parent
;
2889 event
->xbutton
.state
&= ValidModMask
;
2891 CloseWindowMenu(wwin
->screen_ptr
);
2893 if (/*wPreferences.focus_mode==WKF_CLICK
2894 &&*/ !(event
->xbutton
.state
&ControlMask
)
2895 && !WFLAGP(wwin
, no_focusable
)) {
2896 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2898 if (event
->xbutton
.button
== Button1
) {
2899 wRaiseFrame(wwin
->frame
->core
);
2902 if (event
->xbutton
.state
& MOD_MASK
) {
2903 /* move the window */
2904 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2905 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2906 GrabModeAsync
, GrabModeAsync
, None
,
2907 None
, CurrentTime
)!=GrabSuccess
) {
2909 wwarning("pointer grab failed for window move");
2913 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2914 wMouseResizeWindow(wwin
, event
);
2916 wMouseMoveWindow(wwin
, event
);
2917 XUngrabPointer(dpy
, CurrentTime
);
2923 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2925 WWindow
*wwin
= (WWindow
*)data
;
2927 #ifndef NUMLOCK_HACK
2928 if ((event
->xbutton
.state
& ValidModMask
)
2929 != (event
->xbutton
.state
& ~LockMask
)) {
2930 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2931 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2934 event
->xbutton
.state
&= ValidModMask
;
2936 CloseWindowMenu(wwin
->screen_ptr
);
2938 if (wPreferences
.focus_mode
==WKF_CLICK
2939 && !(event
->xbutton
.state
&ControlMask
)
2940 && !WFLAGP(wwin
, no_focusable
)) {
2941 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2944 if (event
->xbutton
.button
== Button1
2945 || event
->xbutton
.button
== Button2
) {
2947 if (event
->xbutton
.button
== Button1
) {
2948 if (event
->xbutton
.state
& MOD_MASK
) {
2949 wLowerFrame(wwin
->frame
->core
);
2951 wRaiseFrame(wwin
->frame
->core
);
2954 if ((event
->xbutton
.state
& ShiftMask
)
2955 && !(event
->xbutton
.state
& ControlMask
)) {
2956 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2959 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2960 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2961 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2962 GrabModeAsync
, GrabModeAsync
, None
,
2963 None
, CurrentTime
)!=GrabSuccess
) {
2965 wwarning("pointer grab failed for window move");
2970 /* move the window */
2971 wMouseMoveWindow(wwin
, event
);
2973 XUngrabPointer(dpy
, CurrentTime
);
2974 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2975 && !wwin
->flags
.internal_window
2976 && !WCHECK_STATE(WSTATE_MODAL
)) {
2977 WObjDescriptor
*desc
;
2979 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2980 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2981 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2982 GrabModeAsync
, GrabModeAsync
, None
,
2983 None
, CurrentTime
)!=GrabSuccess
) {
2985 wwarning("pointer grab failed for window move");
2990 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2991 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2993 /* allow drag select */
2994 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2995 event
->xany
.send_event
= True
;
2996 (*desc
->handle_mousedown
)(desc
, event
);
2998 XUngrabPointer(dpy
, CurrentTime
);
3005 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3007 WWindow
*wwin
= data
;
3009 event
->xbutton
.state
&= ValidModMask
;
3011 CloseWindowMenu(wwin
->screen_ptr
);
3013 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3016 /* if control-click, kill the client */
3017 if (event
->xbutton
.state
& ControlMask
) {
3021 if (wwin
->flags
.olwm_push_pin_out
) {
3023 wwin
->flags
.olwm_push_pin_out
= 0;
3025 wOLWMChangePushpinState(wwin
, True
);
3027 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3032 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3033 /* send delete message */
3034 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3041 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3043 WWindow
*wwin
= data
;
3045 CloseWindowMenu(wwin
->screen_ptr
);
3047 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3050 /* send delete message */
3051 if (wwin
->protocols
.DELETE_WINDOW
) {
3052 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3059 #ifdef XKB_BUTTON_HINT
3061 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3063 WWindow
*wwin
= data
;
3064 WFrameWindow
*fwin
= wwin
->frame
;
3065 WScreen
*scr
= fwin
->screen_ptr
;
3066 XkbStateRec staterec
;
3069 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3071 tl
= wwin
->frame
->languagemode
;
3072 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3073 wwin
->frame
->last_languagemode
= tl
;
3074 wSetFocusTo(scr
, wwin
);
3075 wwin
->frame
->languagebutton_image
=
3076 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3077 wwin
->frame
->languagemode
];
3078 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3079 if (event
->xbutton
.button
== Button3
)
3081 wRaiseFrame(fwin
->core
);
3087 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3089 WWindow
*wwin
= data
;
3091 event
->xbutton
.state
&= ValidModMask
;
3093 CloseWindowMenu(wwin
->screen_ptr
);
3095 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3098 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3099 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3103 if ((event
->xbutton
.state
& ControlMask
) ||
3104 (event
->xbutton
.button
== Button3
)) {
3106 wapp
= wApplicationOf(wwin
->main_window
);
3107 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3108 wHideApplication(wapp
);
3109 } else if (event
->xbutton
.state
==0) {
3110 wIconifyWindow(wwin
);