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 */
37 /* For getting mouse wheel mappings from WINGs */
38 #include <WINGs/WINGsP.h>
40 #include "WindowMaker.h"
46 #include "winspector.h"
48 #include "properties.h"
55 #include "workspace.h"
68 # include "openlook.h"
71 /****** Global Variables ******/
73 extern WShortKey wKeyBindings
[WKBD_LAST
];
76 extern Bool wShapeSupported
;
80 extern XContext wWinContext
;
83 extern Cursor wCursor
[WCUR_LAST
];
86 extern Atom _XA_WM_DELETE_WINDOW
;
87 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
89 extern Atom _XA_WINDOWMAKER_STATE
;
91 extern WPreferences wPreferences
;
93 #define MOD_MASK wPreferences.modifier_mask
95 extern Time LastTimestamp
;
98 extern void DoWindowBirth(WWindow
*);
102 /***** Local Stuff *****/
105 static WWindowState
*windowState
=NULL
;
109 /* local functions */
110 static FocusMode
getFocusMode(WWindow
*wwin
);
112 static int getSavedState(Window window
, WSavedState
**state
);
114 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
119 /* frame window (during window grabs) */
120 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
123 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
127 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
129 #ifdef XKB_BUTTON_HINT
130 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
133 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
134 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
136 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
139 /****** Notification Observers ******/
142 appearanceObserver(void *self
, WMNotification
*notif
)
144 WWindow
*wwin
= (WWindow
*)self
;
145 int flags
= (int)WMGetNotificationClientData(notif
);
147 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
150 if (flags
& WFontSettings
) {
151 wWindowConfigureBorders(wwin
);
152 if(wwin
->flags
.shaded
) {
153 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
154 wwin
->frame
->top_width
- 1);
156 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
157 + wwin
->frame
->top_width
;
158 wWindowSynthConfigureNotify(wwin
);
161 if (flags
& WTextureSettings
) {
162 wwin
->frame
->flags
.need_texture_remake
= 1;
164 if (flags
& (WTextureSettings
| WColorSettings
)) {
165 if (wwin
->frame
->titlebar
)
166 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
168 wFrameWindowPaint(wwin
->frame
);
172 /************************************/
175 wWindowFor(Window window
)
177 WObjDescriptor
*desc
;
182 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
185 if (desc
->parent_type
==WCLASS_WINDOW
)
187 else if (desc
->parent_type
==WCLASS_FRAME
) {
188 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
189 if (frame
->flags
.is_client_window_frame
)
202 wwin
= wmalloc(sizeof(WWindow
));
205 memset(wwin
, 0, sizeof(WWindow
));
207 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
208 wwin
->client_descriptor
.parent
= wwin
;
209 wwin
->client_descriptor
.self
= wwin
;
210 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
217 wWindowDestroy(WWindow
*wwin
)
221 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
222 wwin
->screen_ptr
->cmap_window
= NULL
;
225 WMRemoveNotificationObserver(wwin
);
227 wwin
->flags
.destroyed
= 1;
229 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
230 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
233 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
235 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
236 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
237 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
241 if (wwin
->normal_hints
)
242 XFree(wwin
->normal_hints
);
245 XFree(wwin
->wm_hints
);
247 if (wwin
->wm_instance
)
248 XFree(wwin
->wm_instance
);
251 XFree(wwin
->wm_class
);
253 if (wwin
->wm_gnustep_attr
)
254 wfree(wwin
->wm_gnustep_attr
);
256 if (wwin
->cmap_windows
)
257 XFree(wwin
->cmap_windows
);
259 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
262 wFrameWindowDestroy(wwin
->frame
);
265 RemoveFromStackList(wwin
->icon
->core
);
266 wIconDestroy(wwin
->icon
);
267 if (wPreferences
.auto_arrange_icons
)
268 wArrangeIcons(wwin
->screen_ptr
, True
);
277 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
279 if (gs_hints
->flags
& GSWindowStyleAttr
) {
280 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
281 wwin
->client_flags
.no_border
= 1;
282 wwin
->client_flags
.no_titlebar
= 1;
283 wwin
->client_flags
.no_closable
= 1;
284 wwin
->client_flags
.no_miniaturizable
= 1;
285 wwin
->client_flags
.no_resizable
= 1;
286 wwin
->client_flags
.no_close_button
= 1;
287 wwin
->client_flags
.no_miniaturize_button
= 1;
288 wwin
->client_flags
.no_resizebar
= 1;
290 wwin
->client_flags
.no_close_button
=
291 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
293 wwin
->client_flags
.no_closable
=
294 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
296 wwin
->client_flags
.no_miniaturize_button
=
297 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
299 wwin
->client_flags
.no_miniaturizable
=
300 wwin
->client_flags
.no_miniaturize_button
;
302 wwin
->client_flags
.no_resizebar
=
303 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
305 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
307 /* these attributes supposedly imply in the existence
309 if (gs_hints
->window_style
& (WMResizableWindowMask
|
310 WMClosableWindowMask
|
311 WMMiniaturizableWindowMask
)) {
312 wwin
->client_flags
.no_titlebar
= 0;
314 wwin
->client_flags
.no_titlebar
=
315 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
320 /* setup the defaults */
321 wwin
->client_flags
.no_border
= 0;
322 wwin
->client_flags
.no_titlebar
= 0;
323 wwin
->client_flags
.no_closable
= 0;
324 wwin
->client_flags
.no_miniaturizable
= 0;
325 wwin
->client_flags
.no_resizable
= 0;
326 wwin
->client_flags
.no_close_button
= 0;
327 wwin
->client_flags
.no_miniaturize_button
= 0;
328 wwin
->client_flags
.no_resizebar
= 0;
330 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
331 wwin
->client_flags
.no_appicon
= 1;
337 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
338 WWindowAttributes
*mask
)
340 if (wflags
->no_appicon
&& mask
->no_appicon
)
341 wflags
->emulate_appicon
= 0;
343 if (wwin
->main_window
!=None
) {
344 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
345 if (wapp
&& !wapp
->flags
.emulated
)
346 wflags
->emulate_appicon
= 0;
349 if (wwin
->transient_for
!=None
350 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
351 wflags
->emulate_appicon
= 0;
353 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
360 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
362 WScreen
*scr
= wwin
->screen_ptr
;
364 /* sets global default stuff */
365 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
366 &wwin
->client_flags
, NULL
, True
);
368 * Decoration setting is done in this precedence (lower to higher)
369 * - use global default in the resource database
370 * - guess some settings
371 * - use GNUstep/external window attributes
372 * - set hints specified for the app in the resource DB
375 WSETUFLAG(wwin
, broken_close
, 0);
377 if (wwin
->protocols
.DELETE_WINDOW
)
378 WSETUFLAG(wwin
, kill_close
, 0);
380 WSETUFLAG(wwin
, kill_close
, 1);
382 /* transients can't be iconified or maximized */
383 if (wwin
->transient_for
) {
384 WSETUFLAG(wwin
, no_miniaturizable
, 1);
385 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
388 /* if the window can't be resized, remove the resizebar */
389 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
390 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
391 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
392 WSETUFLAG(wwin
, no_resizable
, 1);
393 WSETUFLAG(wwin
, no_resizebar
, 1);
396 /* set GNUstep window attributes */
397 if (wwin
->wm_gnustep_attr
) {
398 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
400 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
402 *level
= wwin
->wm_gnustep_attr
->window_level
;
404 * INT_MIN is the only illegal window level.
406 if (*level
== INT_MIN
)
407 *level
= INT_MIN
+ 1;
410 *level
= WMNormalLevel
;
413 int tmp_workspace
= -1;
414 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
420 wMWMCheckClientHints(wwin
);
421 #endif /* MWM_HINTS */
424 check
= wGNOMECheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
425 #endif /* GNOME_STUFF */
429 wKWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
430 #endif /* KWM_HINTS */
433 wOLWMCheckClientHints(wwin
);
434 #endif /* OLWM_HINTS */
436 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
437 * have INT_MIN that means that no window level was requested. -Dan
439 if (tmp_level
== INT_MIN
) {
440 if (WFLAGP(wwin
, floating
))
441 *level
= WMFloatingLevel
;
442 else if (WFLAGP(wwin
, sunken
))
443 *level
= WMSunkenLevel
;
445 *level
= WMNormalLevel
;
450 if (tmp_workspace
>= 0) {
451 *workspace
= tmp_workspace
% scr
->workspace_count
;
456 * Set attributes specified only for that window/class.
457 * This might do duplicate work with the 1st wDefaultFillAttributes().
459 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
460 &wwin
->user_flags
, &wwin
->defined_user_flags
,
463 * Sanity checks for attributes that depend on other attributes
465 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
466 wwin
->user_flags
.emulate_appicon
= 0;
468 if (wwin
->main_window
!=None
) {
469 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
470 if (wapp
&& !wapp
->flags
.emulated
)
471 wwin
->user_flags
.emulate_appicon
= 0;
474 if (wwin
->transient_for
!=None
475 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
476 wwin
->user_flags
.emulate_appicon
= 0;
478 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
479 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
480 wwin
->user_flags
.sunken
= 0;
482 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
489 wWindowCanReceiveFocus(WWindow
*wwin
)
491 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
493 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
495 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
503 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
507 w1
= wwin
->frame
->core
->width
;
508 h1
= wwin
->frame
->core
->height
;
509 w2
= obscured
->frame
->core
->width
;
510 h2
= obscured
->frame
->core
->height
;
512 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
513 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
516 if (wwin
->frame_x
+ w1
< obscured
->frame_x
517 || wwin
->frame_y
+ h1
< obscured
->frame_y
518 || wwin
->frame_x
> obscured
->frame_x
+ w2
519 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
529 *----------------------------------------------------------------
531 * reparents the window and allocates a descriptor for it.
532 * Window manager hints and other hints are fetched to configure
533 * the window decoration attributes and others. User preferences
534 * for the window are used if available, to configure window
535 * decorations and some behaviour.
536 * If in startup, windows that are override redirect,
537 * unmapped and never were managed and are Withdrawn are not
541 * the new window descriptor
544 * The window is reparented and appropriate notification
545 * is done to the client. Input mask for the window is setup.
546 * The window descriptor is also associated with various window
547 * contexts and inserted in the head of the window list.
548 * Event handler contexts are associated for some objects
549 * (buttons, titlebar and resizebar)
551 *----------------------------------------------------------------
554 wManageWindow(WScreen
*scr
, Window window
)
558 unsigned width
, height
;
559 XWindowAttributes wattribs
;
560 XSetWindowAttributes attribs
;
561 WWindowState
*win_state
;
562 WWindow
*transientOwner
= NULL
;
568 Bool withdraw
= False
;
571 /* XGrabServer(dpy); */
573 /* make sure the window is still there */
574 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
579 /* if it's an override-redirect, ignore it */
580 if (wattribs
.override_redirect
) {
585 wm_state
= PropGetWindowState(window
);
587 /* if it's startup and the window is unmapped, don't manage it */
588 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
593 if (!wFetchName(dpy
, window
, &title
)) {
598 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
603 #endif /* KWM_HINTS */
606 wwin
= wWindowCreate();
608 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
611 printf("managing window %x\n", (unsigned)window
);
615 if (wShapeSupported
) {
620 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
621 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
622 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
623 wwin
->flags
.shaped
= b_shaped
;
628 *--------------------------------------------------
630 * Get hints and other information in properties
632 *--------------------------------------------------
634 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
636 /* setup descriptor */
637 wwin
->client_win
= window
;
638 wwin
->screen_ptr
= scr
;
640 wwin
->old_border_width
= wattribs
.border_width
;
642 wwin
->event_mask
= CLIENT_EVENTS
;
643 attribs
.event_mask
= CLIENT_EVENTS
;
644 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
645 attribs
.save_under
= False
;
646 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
647 |CWSaveUnder
, &attribs
);
648 XSetWindowBorderWidth(dpy
, window
, 0);
650 /* get hints from GNUstep app */
651 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
652 wwin
->flags
.is_gnustep
= 1;
654 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
655 wwin
->wm_gnustep_attr
= NULL
;
658 wwin
->client_leader
= PropGetClientLeader(window
);
659 if (wwin
->client_leader
!=None
)
660 wwin
->main_window
= wwin
->client_leader
;
662 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
664 if (wwin
->wm_hints
) {
665 if (wwin
->wm_hints
->flags
& StateHint
) {
667 if (wwin
->wm_hints
->initial_state
== IconicState
) {
669 wwin
->flags
.miniaturized
= 1;
671 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
677 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
678 wwin
->group_id
= wwin
->wm_hints
->window_group
;
679 /* window_group has priority over CLIENT_LEADER */
680 wwin
->main_window
= wwin
->group_id
;
682 wwin
->group_id
= None
;
685 if (wwin
->wm_hints
->flags
& UrgencyHint
)
686 wwin
->flags
.urgent
= 1;
688 wwin
->group_id
= None
;
691 PropGetProtocols(window
, &wwin
->protocols
);
693 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
694 wwin
->transient_for
= None
;
696 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
697 wwin
->transient_for
= scr
->root_win
;
699 transientOwner
= wWindowFor(wwin
->transient_for
);
700 if (transientOwner
&& transientOwner
->main_window
!=None
) {
701 wwin
->main_window
= transientOwner
->main_window
;
703 wwin->main_window = None;
708 /* guess the focus mode */
709 wwin
->focus_mode
= getFocusMode(wwin
);
711 /* get geometry stuff */
712 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
714 /* get colormap windows */
715 GetColormapWindows(wwin
);
718 *--------------------------------------------------
720 * Setup the decoration/window attributes and
723 *--------------------------------------------------
726 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
729 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
730 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
732 transientOwner
= wWindowFor(wwin
->group_id
);
734 if (transientOwner
) {
735 wwin
->transient_for
= wwin
->group_id
;
737 /* transients can't be iconified or maximized */
738 if (wwin
->transient_for
) {
739 WSETUFLAG(wwin
, no_miniaturizable
, 1);
740 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
744 #endif /* OLWM_HINTS */
747 * Make broken apps behave as a nice app.
749 if (WFLAGP(wwin
, emulate_appicon
)) {
750 wwin
->main_window
= wwin
->client_win
;
754 *------------------------------------------------------------
756 * Setup the initial state of the window
758 *------------------------------------------------------------
761 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
762 wwin
->flags
.miniaturized
= 1;
765 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
766 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
774 bla
= wGNOMECheckInitialClientState(wwin
);
778 wKWMCheckClientInitialState(wwin
);
782 /* apply previous state if it exists and we're in startup */
783 if (scr
->flags
.startup
&& wm_state
>= 0) {
785 if (wm_state
== IconicState
) {
787 wwin
->flags
.miniaturized
= 1;
789 } else if (wm_state
== WithdrawnState
) {
795 /* if there is a saved state (from file), restore it */
797 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
798 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
800 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
802 if (win_state
&& !withdraw
) {
804 if (win_state
->state
->hidden
>0)
805 wwin
->flags
.hidden
= win_state
->state
->hidden
;
807 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
808 wwin
->flags
.shaded
= win_state
->state
->shaded
;
810 if (win_state
->state
->miniaturized
>0 &&
811 !WFLAGP(wwin
, no_miniaturizable
)) {
812 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
815 if (!IS_OMNIPRESENT(wwin
)) {
816 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
818 if (w
< 0 || w
>= scr
->workspace_count
) {
819 workspace
= win_state
->state
->workspace
;
820 if (workspace
>= scr
->workspace_count
)
821 workspace
= scr
->current_workspace
;
826 workspace
= scr
->current_workspace
;
830 /* if we're restarting, restore saved state (from hints).
831 * This will overwrite previous */
835 if (getSavedState(window
, &wstate
)) {
836 wwin
->flags
.shaded
= wstate
->shaded
;
837 wwin
->flags
.hidden
= wstate
->hidden
;
838 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
839 wwin
->flags
.maximized
= wstate
->maximized
;
840 if (wwin
->flags
.maximized
) {
841 wwin
->old_geometry
.x
= wstate
->x
;
842 wwin
->old_geometry
.y
= wstate
->y
;
843 wwin
->old_geometry
.width
= wstate
->w
;
844 wwin
->old_geometry
.height
= wstate
->h
;
847 workspace
= wstate
->workspace
;
852 /* restore window shortcut */
853 if (wstate
!= NULL
|| win_state
!= NULL
) {
856 if (win_state
!= NULL
)
857 mask
= win_state
->state
->window_shortcuts
;
859 if (wstate
!= NULL
&& mask
== 0)
860 mask
= wstate
->window_shortcuts
;
865 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
867 if (!scr
->shortcutWindows
[i
])
868 scr
->shortcutWindows
[i
] = WMCreateArray(4);
870 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
875 if (wstate
!= NULL
) {
880 /* don't let transients start miniaturized if their owners are not */
881 if (transientOwner
&& !transientOwner
->flags
.miniaturized
882 && wwin
->flags
.miniaturized
&& !withdraw
) {
883 wwin
->flags
.miniaturized
= 0;
885 wwin
->wm_hints
->initial_state
= NormalState
;
888 /* set workspace on which the window starts */
889 if (workspace
>= 0) {
890 if (workspace
> scr
->workspace_count
-1) {
891 workspace
= workspace
% scr
->workspace_count
;
896 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
898 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
903 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
905 workspace
= transientOwner
->frame
->workspace
;
909 workspace
= scr
->current_workspace
;
914 /* setup window geometry */
915 if (win_state
&& win_state
->state
->w
> 0) {
916 width
= win_state
->state
->w
;
917 height
= win_state
->state
->h
;
919 wWindowConstrainSize(wwin
, &width
, &height
);
921 /* do not ask for window placement if the window is
922 * transient, during startup, if the initial workspace is another one
923 * or if the window wants to start iconic.
924 * If geometry was saved, restore it. */
926 Bool dontBring
= False
;
928 if (win_state
&& win_state
->state
->w
> 0) {
929 x
= win_state
->state
->x
;
930 y
= win_state
->state
->y
;
931 } else if ((wwin
->transient_for
==None
932 || wPreferences
.window_placement
!=WPM_MANUAL
)
933 && !scr
->flags
.startup
934 && workspace
== scr
->current_workspace
935 && !wwin
->flags
.miniaturized
936 && !wwin
->flags
.maximized
937 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
939 if (transientOwner
&& transientOwner
->flags
.mapped
) {
940 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
942 x
= transientOwner
->frame_x
+
943 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
944 y
= transientOwner
->frame_y
+
945 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
949 else if (x
+ width
> scr
->scr_width
)
950 x
= scr
->scr_width
- width
;
954 else if (y
+ height
> scr
->scr_height
)
955 y
= scr
->scr_height
- height
;
957 PlaceWindow(wwin
, &x
, &y
, width
, height
);
959 if (wPreferences
.window_placement
== WPM_MANUAL
)
963 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
964 wScreenBringInside(scr
, &x
, &y
, width
, height
);
967 if (wwin
->flags
.urgent
) {
968 if (!IS_OMNIPRESENT(wwin
))
969 wwin
->flags
.omnipresent
^= 1;
973 *--------------------------------------------------
975 * Create frame, borders and do reparenting
977 *--------------------------------------------------
979 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
980 #ifdef XKB_BUTTON_HINT
981 if (wPreferences
.modelock
)
982 foo
|= WFF_LANGUAGE_BUTTON
;
984 if (!WFLAGP(wwin
, no_titlebar
))
986 if (!WFLAGP(wwin
, no_resizebar
))
987 foo
|= WFF_RESIZEBAR
;
988 if (!WFLAGP(wwin
, no_border
))
991 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
993 &wPreferences
.window_title_clearance
, foo
,
994 scr
->window_title_texture
,
995 scr
->resizebar_texture
,
996 scr
->window_title_pixel
,
997 &scr
->window_title_gc
,
1000 wwin
->frame
->flags
.is_client_window_frame
= 1;
1001 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1003 /* setup button images */
1004 wWindowUpdateButtonImages(wwin
);
1006 /* hide unused buttons */
1008 if (WFLAGP(wwin
, no_close_button
))
1009 foo
|= WFF_RIGHT_BUTTON
;
1010 if (WFLAGP(wwin
, no_miniaturize_button
))
1011 foo
|= WFF_LEFT_BUTTON
;
1012 #ifdef XKB_BUTTON_HINT
1013 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1014 foo
|= WFF_LANGUAGE_BUTTON
;
1017 wFrameWindowHideButton(wwin
->frame
, foo
);
1019 wwin
->frame
->child
= wwin
;
1022 /* emulate olwm push pin. Make the button look as pushed-in for
1023 * the pinned-out state. When the button is clicked, it will
1024 * revert to the normal position, which means the pin is pinned-in.
1026 if (wwin
->flags
.olwm_push_pin_out
)
1027 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1028 #endif /* OLWM_HINTS */
1031 wwin
->frame
->workspace
= workspace
;
1033 wwin
->frame
->on_click_left
= windowIconifyClick
;
1034 #ifdef XKB_BUTTON_HINT
1035 if (wPreferences
.modelock
)
1036 wwin
->frame
->on_click_language
= windowLanguageClick
;
1039 wwin
->frame
->on_click_right
= windowCloseClick
;
1040 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1042 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1043 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1045 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1048 XSelectInput(dpy
, wwin
->client_win
,
1049 wwin
->event_mask
& ~StructureNotifyMask
);
1051 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1052 0, wwin
->frame
->top_width
);
1054 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1060 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1062 /* if gravity is to the south, account for the border sizes */
1064 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1068 * wWindowConfigure() will init the client window's size
1069 * (wwin->client.{width,height}) and all other geometry
1070 * related variables (frame_x,frame_y)
1072 wWindowConfigure(wwin
, x
, y
, width
, height
);
1074 /* to make sure the window receives it's new position after reparenting */
1075 wWindowSynthConfigureNotify(wwin
);
1078 *--------------------------------------------------
1080 * Setup descriptors and save window to internal
1083 *--------------------------------------------------
1086 if (wwin
->main_window
!=None
) {
1090 /* Leader windows do not necessary set themselves as leaders.
1091 * If this is the case, point the leader of this window to
1093 leader
= wWindowFor(wwin
->main_window
);
1094 if (leader
&& leader
->main_window
==None
) {
1095 leader
->main_window
= leader
->client_win
;
1097 app
= wApplicationCreate(scr
, wwin
->main_window
);
1099 app
->last_workspace
= workspace
;
1102 * Do application specific stuff, like setting application
1106 if (wwin
->flags
.hidden
) {
1107 /* if the window was set to hidden because it was hidden
1108 * in a previous incarnation and that state was restored */
1109 app
->flags
.hidden
= 1;
1112 if (app
->flags
.hidden
) {
1113 wwin
->flags
.hidden
= 1;
1118 /* setup the frame descriptor */
1119 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1120 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1121 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1123 /* don't let windows go away if we die */
1124 XAddToSaveSet(dpy
, window
);
1126 XLowerWindow(dpy
, window
);
1128 /* if window is in this workspace and should be mapped, then map it */
1129 if (!wwin
->flags
.miniaturized
1130 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1131 && !wwin
->flags
.hidden
&& !withdraw
) {
1133 /* The following "if" is to avoid crashing of clients that expect
1134 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1135 * after the return from this function.
1137 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1138 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1140 wClientSetState(wwin
, NormalState
, None
);
1144 /* if not auto focus, then map the window under the currently
1146 #define _WIDTH(w) (w)->frame->core->width
1147 #define _HEIGHT(w) (w)->frame->core->height
1148 if (!wPreferences
.auto_focus
&& scr
->focused_window
1149 && !scr
->flags
.startup
&& !transientOwner
1150 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1151 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1152 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1153 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1154 || wwin
->flags
.maximized
)) {
1155 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1163 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1164 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1166 * The brain damaged idiotic non-click to focus modes will
1167 * have trouble with this because:
1169 * 1. window is created and mapped by the client
1170 * 2. window is mapped by wmaker in small size
1171 * 3. window is animated to grow to normal size
1172 * 4. this function returns to normal event loop
1173 * 5. eventually, the EnterNotify event that would trigger
1174 * the window focusing (if the mouse is over that window)
1175 * will be processed by wmaker.
1176 * But since this event will be rather delayed
1177 * (step 3 has a large delay) the time when the event ocurred
1178 * and when it is processed, the client that owns that window
1179 * will reject the XSetInputFocus() for it.
1181 && (wPreferences
.focus_mode
==WKF_CLICK
1182 || wPreferences
.auto_focus
)) {
1183 DoWindowBirth(wwin
);
1189 /* setup stacking descriptor */
1190 if (transientOwner
) {
1191 /* && wPreferences.on_top_transients */
1192 if (transientOwner
) {
1193 wwin
->frame
->core
->stacking
->child_of
=
1194 transientOwner
->frame
->core
;
1197 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1201 if (!scr
->focused_window
) {
1202 /* first window on the list */
1205 scr
->focused_window
= wwin
;
1209 /* add window at beginning of focus window list */
1210 tmp
= scr
->focused_window
;
1218 /* Update name must come after WApplication stuff is done */
1219 wWindowUpdateName(wwin
, title
);
1226 *--------------------------------------------------
1228 * Final preparations before window is ready to go
1230 *--------------------------------------------------
1233 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1236 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1237 && !wwin
->flags
.hidden
) {
1238 if (((transientOwner
&& transientOwner
->flags
.focused
)
1239 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1240 wSetFocusTo(scr
, wwin
);
1242 wWindowResetMouseGrabs(wwin
);
1244 if (!WFLAGP(wwin
, no_bind_keys
)) {
1245 wWindowSetKeyGrabs(wwin
);
1249 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1252 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1256 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1257 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1259 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1260 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1266 *------------------------------------------------------------
1267 * Setup Notification Observers
1268 *------------------------------------------------------------
1270 WMAddNotificationObserver(appearanceObserver
, wwin
,
1271 WNWindowAppearanceSettingsChanged
, wwin
);
1275 *--------------------------------------------------
1277 * Cleanup temporary stuff
1279 *--------------------------------------------------
1283 wWindowDeleteSavedState(win_state
);
1285 /* If the window must be withdrawed, then do it now.
1286 * Must do some optimization, 'though */
1288 wwin
->flags
.mapped
= 0;
1289 wClientSetState(wwin
, WithdrawnState
, None
);
1290 wUnmanageWindow(wwin
, True
, False
);
1302 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1303 char *title
, int x
, int y
, int width
, int height
)
1308 wwin
= wWindowCreate();
1310 WMAddNotificationObserver(appearanceObserver
, wwin
,
1311 WNWindowAppearanceSettingsChanged
, wwin
);
1313 wwin
->flags
.internal_window
= 1;
1315 WSETUFLAG(wwin
, omnipresent
, 1);
1316 WSETUFLAG(wwin
, no_shadeable
, 1);
1317 WSETUFLAG(wwin
, no_resizable
, 1);
1318 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1320 wwin
->focus_mode
= WFM_PASSIVE
;
1322 wwin
->client_win
= window
;
1323 wwin
->screen_ptr
= scr
;
1325 wwin
->transient_for
= owner
;
1329 wwin
->client
.width
= width
;
1330 wwin
->client
.height
= height
;
1332 wwin
->frame_x
= wwin
->client
.x
;
1333 wwin
->frame_y
= wwin
->client
.y
;
1336 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1337 foo
|= WFF_TITLEBAR
;
1338 #ifdef XKB_BUTTON_HINT
1339 foo
|= WFF_LANGUAGE_BUTTON
;
1342 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1343 wwin
->frame_x
, wwin
->frame_y
,
1345 &wPreferences
.window_title_clearance
, foo
,
1346 scr
->window_title_texture
,
1347 scr
->resizebar_texture
,
1348 scr
->window_title_pixel
,
1349 &scr
->window_title_gc
,
1352 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1354 wwin
->frame
->flags
.is_client_window_frame
= 1;
1355 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1357 wFrameWindowChangeTitle(wwin
->frame
, title
);
1359 /* setup button images */
1360 wWindowUpdateButtonImages(wwin
);
1363 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1365 wwin
->frame
->child
= wwin
;
1367 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1369 #ifdef XKB_BUTTON_HINT
1370 if (wPreferences
.modelock
)
1371 wwin
->frame
->on_click_language
= windowLanguageClick
;
1374 wwin
->frame
->on_click_right
= windowCloseClick
;
1376 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1377 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1379 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1381 wwin
->client
.y
+= wwin
->frame
->top_width
;
1382 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1383 0, wwin
->frame
->top_width
);
1385 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1386 wwin
->client
.width
, wwin
->client
.height
);
1388 /* setup the frame descriptor */
1389 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1390 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1391 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1394 XLowerWindow(dpy
, window
);
1395 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1397 /* setup stacking descriptor */
1400 wPreferences
.on_top_transients
&&
1402 wwin
->transient_for
!=None
1403 && wwin
->transient_for
!=scr
->root_win
) {
1405 tmp
= wWindowFor(wwin
->transient_for
);
1407 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1409 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1413 if (!scr
->focused_window
) {
1414 /* first window on the list */
1417 scr
->focused_window
= wwin
;
1421 /* add window at beginning of focus window list */
1422 tmp
= scr
->focused_window
;
1430 if (wwin
->flags
.is_gnustep
== 0)
1431 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1433 /* if (wPreferences.auto_focus)*/
1434 wSetFocusTo(scr
, wwin
);
1436 wWindowResetMouseGrabs(wwin
);
1438 wWindowSetKeyGrabs(wwin
);
1445 *----------------------------------------------------------------------
1447 * Removes the frame window from a window and destroys all data
1448 * related to it. The window will be reparented back to the root window
1449 * if restore is True.
1452 * Everything related to the window is destroyed and the window
1453 * is removed from the window lists. Focus is set to the previous on the
1455 *----------------------------------------------------------------------
1458 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1460 WCoreWindow
*frame
= wwin
->frame
->core
;
1461 WWindow
*owner
= NULL
;
1462 WWindow
*newFocusedWindow
= NULL
;
1464 WScreen
*scr
= wwin
->screen_ptr
;
1467 /* First close attribute editor window if open */
1468 if (wwin
->flags
.inspector_open
) {
1469 wCloseInspectorForWindow(wwin
);
1472 /* Close window menu if it's open for this window */
1473 if (wwin
->flags
.menu_open_for_me
) {
1474 CloseWindowMenu(scr
);
1478 if (!wwin
->flags
.internal_window
)
1479 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1481 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1483 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1484 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1487 XUnmapWindow(dpy
, frame
->window
);
1489 XUnmapWindow(dpy
, wwin
->client_win
);
1491 /* deselect window */
1492 wSelectWindow(wwin
, False
);
1494 /* remove all pending events on window */
1495 /* I think this only matters for autoraise */
1496 if (wPreferences
.raise_delay
)
1497 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1501 /* reparent the window back to the root */
1503 wClientRestore(wwin
);
1505 if (wwin
->transient_for
!=scr
->root_win
) {
1506 owner
= wWindowFor(wwin
->transient_for
);
1508 if (!owner
->flags
.semi_focused
) {
1511 owner
->flags
.semi_focused
= 0;
1516 wasFocused
= wwin
->flags
.focused
;
1518 /* remove from window focus list */
1519 if (!wwin
->prev
&& !wwin
->next
) {
1520 /* was the only window */
1521 scr
->focused_window
= NULL
;
1522 newFocusedWindow
= NULL
;
1527 wwin
->prev
->next
= wwin
->next
;
1529 wwin
->next
->prev
= wwin
->prev
;
1531 scr
->focused_window
= wwin
->prev
;
1532 scr
->focused_window
->next
= NULL
;
1535 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1537 /* if in click to focus mode and the window
1538 * was a transient, focus the owner window
1541 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1542 tmp
= wWindowFor(wwin
->transient_for
);
1543 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1547 /* otherwise, focus the next one in the focus list */
1549 tmp
= scr
->focused_window
;
1550 while (tmp
) { /* look for one in the window list first */
1551 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1552 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1556 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1557 tmp
= scr
->focused_window
;
1559 if (!WFLAGP(tmp
, no_focusable
)
1560 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1567 newFocusedWindow
= tmp
;
1569 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1574 /* This is to let the root window get the keyboard input
1575 * if Sloppy focus mode and no other window get focus.
1576 * This way keybindings will not freeze.
1579 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1580 &foo
, &foo
, &foo
, &foo
, &mask
))
1581 tmp
= wWindowFor(win
);
1584 newFocusedWindow
= tmp
;
1586 newFocusedWindow
= NULL
;
1590 if (!wwin
->flags
.internal_window
) {
1591 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1595 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1596 (unsigned)frame
->window
);
1600 if (newFocusedWindow
!= owner
&& owner
) {
1601 if (wwin
->flags
.is_gnustep
== 0)
1602 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1604 wSetFocusTo(scr
, newFocusedWindow
);
1606 wWindowDestroy(wwin
);
1612 wWindowMap(WWindow
*wwin
)
1614 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1615 if (!wwin
->flags
.shaded
) {
1616 /* window will be remapped when getting MapNotify */
1617 XSelectInput(dpy
, wwin
->client_win
,
1618 wwin
->event_mask
& ~StructureNotifyMask
);
1619 XMapWindow(dpy
, wwin
->client_win
);
1620 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1622 wwin
->flags
.mapped
= 1;
1628 wWindowUnmap(WWindow
*wwin
)
1630 wwin
->flags
.mapped
= 0;
1632 /* prevent window withdrawal when getting UnmapNotify */
1633 XSelectInput(dpy
, wwin
->client_win
,
1634 wwin
->event_mask
& ~StructureNotifyMask
);
1635 XUnmapWindow(dpy
, wwin
->client_win
);
1636 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1638 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1644 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1649 #ifdef KEEP_XKB_LOCK_STATUS
1650 if (wPreferences
.modelock
) {
1651 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1653 #endif /* KEEP_XKB_LOCK_STATUS */
1655 wwin
->flags
.semi_focused
= 0;
1657 if (wwin
->flags
.is_gnustep
== 0)
1658 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1660 wwin
->flags
.focused
= 1;
1662 wWindowResetMouseGrabs(wwin
);
1664 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)True
);
1666 if (owin
== wwin
|| !owin
)
1669 nowner
= wWindowFor(wwin
->transient_for
);
1671 /* new window is a transient for the old window */
1672 if (nowner
== owin
) {
1673 owin
->flags
.semi_focused
= 1;
1674 wWindowUnfocus(nowner
);
1678 oowner
= wWindowFor(owin
->transient_for
);
1680 /* new window is owner of old window */
1681 if (wwin
== oowner
) {
1682 wWindowUnfocus(owin
);
1687 wWindowUnfocus(owin
);
1691 /* new window has same owner of old window */
1692 if (oowner
== nowner
) {
1693 /* prevent unfocusing of owner */
1694 oowner
->flags
.semi_focused
= 0;
1695 wWindowUnfocus(owin
);
1696 oowner
->flags
.semi_focused
= 1;
1701 /* nowner != NULL && oowner != nowner */
1702 nowner
->flags
.semi_focused
= 1;
1703 wWindowUnfocus(nowner
);
1704 wWindowUnfocus(owin
);
1709 wWindowUnfocus(WWindow
*wwin
)
1711 CloseWindowMenu(wwin
->screen_ptr
);
1713 if (wwin
->flags
.is_gnustep
== 0)
1714 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1715 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1717 if (wwin
->transient_for
!=None
1718 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1720 owner
= wWindowFor(wwin
->transient_for
);
1721 if (owner
&& owner
->flags
.semi_focused
) {
1722 owner
->flags
.semi_focused
= 0;
1723 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1724 wWindowUnfocus(owner
);
1725 wFrameWindowPaint(owner
->frame
);
1729 wwin
->flags
.focused
= 0;
1731 wWindowResetMouseGrabs(wwin
);
1733 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)False
);
1738 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
1740 WApplication
*app
= wApplicationOf(wwin
->main_window
);
1742 char prefix
[32] = "";
1749 instIndex
= wApplicationIndexOfGroup(app
);
1752 wwin
->flags
.wm_name_changed
= 1;
1755 /* the hint was removed */
1756 title
= DEF_WINDOW_TITLE
;
1758 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1763 #ifndef NO_WINDOW_ENUMERATOR
1764 if (instIndex
> 0) {
1765 snprintf(prefix
, sizeof(prefix
), " [%i]", instIndex
);
1767 title
= wstrconcat(title
, prefix
);
1771 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
1773 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
1776 #ifndef NO_WINDOW_ENUMERATOR
1786 *----------------------------------------------------------------------
1788 * wWindowConstrainSize--
1789 * Constrains size for the client window, taking the maximal size,
1790 * window resize increments and other size hints into account.
1793 * The closest size to what was given that the client window can
1796 *----------------------------------------------------------------------
1799 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1801 int width
= *nwidth
;
1802 int height
= *nheight
;
1805 int minW
= 1, minH
= 1;
1806 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1807 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1808 int minAX
= -1, minAY
= -1;
1809 int maxAX
= -1, maxAY
= -1;
1813 if (wwin
->normal_hints
) {
1814 winc
= wwin
->normal_hints
->width_inc
;
1815 hinc
= wwin
->normal_hints
->height_inc
;
1816 minW
= wwin
->normal_hints
->min_width
;
1817 minH
= wwin
->normal_hints
->min_height
;
1818 maxW
= wwin
->normal_hints
->max_width
;
1819 maxH
= wwin
->normal_hints
->max_height
;
1820 if (wwin
->normal_hints
->flags
& PAspect
) {
1821 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1822 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1823 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1824 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1827 baseW
= wwin
->normal_hints
->base_width
;
1828 baseH
= wwin
->normal_hints
->base_height
;
1841 /* aspect ratio code borrowed from olwm */
1843 /* adjust max aspect ratio */
1844 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1845 if (maxAX
> maxAY
) {
1846 height
= (width
* maxAY
) / maxAX
;
1847 if (height
> maxH
) {
1849 width
= (height
* maxAX
) / maxAY
;
1852 width
= (height
* maxAX
) / maxAY
;
1855 height
= (width
* maxAY
) / maxAX
;
1860 /* adjust min aspect ratio */
1861 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1862 if (minAX
> minAY
) {
1863 height
= (width
* minAY
) / minAX
;
1864 if (height
< minH
) {
1866 width
= (height
* minAX
) / minAY
;
1869 width
= (height
* minAX
) / minAY
;
1872 height
= (width
* minAY
) / minAX
;
1879 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1881 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1885 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1887 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1890 /* broken stupid apps may cause preposterous values for these.. */
1899 wWindowCropSize(WWindow
*wwin
, int maxW
, int maxH
,
1900 int *width
, int *height
)
1902 int baseW
= 0, baseH
= 0;
1903 int winc
= 1, hinc
= 1;
1905 if (wwin
->normal_hints
) {
1906 baseW
= wwin
->normal_hints
->base_width
;
1907 baseH
= wwin
->normal_hints
->base_height
;
1909 winc
= wwin
->normal_hints
->width_inc
;
1910 hinc
= wwin
->normal_hints
->height_inc
;
1914 *width
= maxW
- (maxW
- baseW
) % winc
;
1917 *height
= maxH
- (maxH
- baseH
) % hinc
;
1922 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1924 WScreen
*scr
= wwin
->screen_ptr
;
1928 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1929 || workspace
== wwin
->frame
->workspace
)
1932 if (workspace
!= scr
->current_workspace
) {
1933 /* Sent to other workspace. Unmap window */
1934 if ((wwin
->flags
.mapped
1935 || wwin
->flags
.shaded
1936 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1937 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1939 wapp
= wApplicationOf(wwin
->main_window
);
1941 wapp
->last_workspace
= workspace
;
1943 if (wwin
->flags
.miniaturized
) {
1945 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1946 wwin
->icon
->mapped
= 0;
1950 wSetFocusTo(scr
, NULL
);
1954 /* brought to current workspace. Map window */
1955 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1957 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1958 wwin
->icon
->mapped
= 1;
1960 } else if (!wwin
->flags
.mapped
&&
1961 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1965 if (!IS_OMNIPRESENT(wwin
)) {
1966 int oldWorkspace
= wwin
->frame
->workspace
;
1968 wwin
->frame
->workspace
= workspace
;
1970 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void*)oldWorkspace
);
1980 wWindowSynthConfigureNotify(WWindow
*wwin
)
1984 sevent
.type
= ConfigureNotify
;
1985 sevent
.xconfigure
.display
= dpy
;
1986 sevent
.xconfigure
.event
= wwin
->client_win
;
1987 sevent
.xconfigure
.window
= wwin
->client_win
;
1989 sevent
.xconfigure
.x
= wwin
->client
.x
;
1990 sevent
.xconfigure
.y
= wwin
->client
.y
;
1991 sevent
.xconfigure
.width
= wwin
->client
.width
;
1992 sevent
.xconfigure
.height
= wwin
->client
.height
;
1994 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1995 if (WFLAGP(wwin
, no_titlebar
))
1996 sevent
.xconfigure
.above
= None
;
1998 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2000 sevent
.xconfigure
.override_redirect
= False
;
2001 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2003 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
2010 *----------------------------------------------------------------------
2011 * wWindowConfigure--
2012 * Configures the frame, decorations and client window to the
2013 * specified geometry. The geometry is not checked for validity,
2014 * wWindowConstrainSize() must be used for that.
2015 * The size parameters are for the client window, but the position is
2017 * The client window receives a ConfigureNotify event, according
2018 * to what ICCCM says.
2024 * Window size and position are changed and client window receives
2025 * a ConfigureNotify event.
2026 *----------------------------------------------------------------------
2029 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2031 int req_x
, req_y
; /* new position of the frame */
2032 int req_width
, req_height
; /* new size of the client */
2034 int synth_notify
= False
;
2037 resize
= (req_width
!=wwin
->client
.width
2038 || req_height
!=wwin
->client
.height
);
2040 * if the window is being moved but not resized then
2041 * send a synthetic ConfigureNotify
2043 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2044 synth_notify
= True
;
2047 if (WFLAGP(wwin
, dont_move_off
))
2048 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2049 req_width
, req_height
);
2051 if (req_width
< MIN_WINDOW_SIZE
)
2052 req_width
= MIN_WINDOW_SIZE
;
2053 if (req_height
< MIN_WINDOW_SIZE
)
2054 req_height
= MIN_WINDOW_SIZE
;
2056 /* If growing, resize inner part before frame,
2057 * if shrinking, resize frame before.
2058 * This will prevent the frame (that can have a different color)
2059 * to be exposed, causing flicker */
2060 if (req_height
> wwin
->frame
->core
->height
2061 || req_width
> wwin
->frame
->core
->width
)
2062 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2064 if (wwin
->flags
.shaded
) {
2065 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2066 req_width
, wwin
->frame
->core
->height
);
2067 wwin
->old_geometry
.height
= req_height
;
2071 h
= req_height
+ wwin
->frame
->top_width
2072 + wwin
->frame
->bottom_width
;
2074 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2077 if (!(req_height
> wwin
->frame
->core
->height
2078 || req_width
> wwin
->frame
->core
->width
))
2079 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2081 wwin
->client
.x
= req_x
;
2082 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2083 wwin
->client
.width
= req_width
;
2084 wwin
->client
.height
= req_height
;
2086 wwin
->client
.x
= req_x
;
2087 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2089 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2091 wwin
->frame_x
= req_x
;
2092 wwin
->frame_y
= req_y
;
2093 if (!WFLAGP(wwin
, no_border
)) {
2094 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2095 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2099 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2100 wWindowSetShape(wwin
);
2105 wWindowSynthConfigureNotify(wwin
);
2111 wWindowMove(wwin
, req_x
, req_y
)
2113 int req_x
, req_y
; /* new position of the frame */
2115 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2116 int synth_notify
= False
;
2118 /* Send a synthetic ConfigureNotify event for every window movement. */
2119 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2120 synth_notify
= True
;
2123 /* A single synthetic ConfigureNotify event is sent at the end of
2124 * a completed (opaque) movement in moveres.c */
2127 if (WFLAGP(wwin
, dont_move_off
))
2128 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2129 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2131 wwin
->client
.x
= req_x
;
2132 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2133 if (!WFLAGP(wwin
, no_border
)) {
2134 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2135 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2138 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2140 wwin
->frame_x
= req_x
;
2141 wwin
->frame_y
= req_y
;
2143 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2145 wWindowSynthConfigureNotify(wwin
);
2151 wWindowUpdateButtonImages(WWindow
*wwin
)
2153 WScreen
*scr
= wwin
->screen_ptr
;
2154 Pixmap pixmap
, mask
;
2155 WFrameWindow
*fwin
= wwin
->frame
;
2157 if (WFLAGP(wwin
, no_titlebar
))
2160 /* miniaturize button */
2162 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2163 if (wwin
->wm_gnustep_attr
2164 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2165 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2167 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2168 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2173 if (fwin
->lbutton_image
2174 && (fwin
->lbutton_image
->image
!= pixmap
2175 || fwin
->lbutton_image
->mask
!= mask
)) {
2176 wPixmapDestroy(fwin
->lbutton_image
);
2177 fwin
->lbutton_image
= NULL
;
2180 if (!fwin
->lbutton_image
) {
2181 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2182 fwin
->lbutton_image
->client_owned
= 1;
2183 fwin
->lbutton_image
->client_owned_mask
= 1;
2186 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2187 wPixmapDestroy(fwin
->lbutton_image
);
2189 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2193 #ifdef XKB_BUTTON_HINT
2194 if (!WFLAGP(wwin
, no_language_button
)) {
2195 if (fwin
->languagebutton_image
&&
2196 !fwin
->languagebutton_image
->shared
) {
2197 wPixmapDestroy(fwin
->languagebutton_image
);
2199 fwin
->languagebutton_image
=
2200 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2206 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2207 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2209 if (!WFLAGP(wwin
, no_close_button
)) {
2210 if (wwin
->wm_gnustep_attr
2211 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2212 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2214 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2215 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2219 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2220 || fwin
->rbutton_image
->mask
!= mask
)) {
2221 wPixmapDestroy(fwin
->rbutton_image
);
2222 fwin
->rbutton_image
= NULL
;
2225 if (!fwin
->rbutton_image
) {
2226 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2227 fwin
->rbutton_image
->client_owned
= 1;
2228 fwin
->rbutton_image
->client_owned_mask
= 1;
2231 } else if (WFLAGP(wwin
, kill_close
)) {
2233 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2234 wPixmapDestroy(fwin
->rbutton_image
);
2236 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2238 } else if (MGFLAGP(wwin
, broken_close
)) {
2240 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2241 wPixmapDestroy(fwin
->rbutton_image
);
2243 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2247 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2248 wPixmapDestroy(fwin
->rbutton_image
);
2250 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2254 /* force buttons to be redrawn */
2255 fwin
->flags
.need_texture_change
= 1;
2256 wFrameWindowPaint(fwin
);
2261 *---------------------------------------------------------------------------
2262 * wWindowConfigureBorders--
2263 * Update window border configuration according to attribute flags.
2265 *---------------------------------------------------------------------------
2268 wWindowConfigureBorders(WWindow
*wwin
)
2274 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2275 #ifdef XKB_BUTTON_HINT
2276 flags
|= WFF_LANGUAGE_BUTTON
;
2278 if (!WFLAGP(wwin
, no_titlebar
))
2279 flags
|= WFF_TITLEBAR
;
2280 if (!WFLAGP(wwin
, no_resizebar
))
2281 flags
|= WFF_RESIZEBAR
;
2282 if (!WFLAGP(wwin
, no_border
))
2283 flags
|= WFF_BORDER
;
2284 if (wwin
->flags
.shaded
)
2285 flags
|= WFF_IS_SHADED
;
2287 oldh
= wwin
->frame
->top_width
;
2288 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2289 if (oldh
!= wwin
->frame
->top_width
) {
2290 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2292 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2293 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2294 wwin
->client
.width
, wwin
->client
.height
);
2298 if (!WFLAGP(wwin
, no_miniaturize_button
)
2299 && wwin
->frame
->flags
.hide_left_button
)
2300 flags
|= WFF_LEFT_BUTTON
;
2302 #ifdef XKB_BUTTON_HINT
2303 if (!WFLAGP(wwin
, no_language_button
)
2304 && wwin
->frame
->flags
.hide_language_button
)
2305 flags
|= WFF_LANGUAGE_BUTTON
;
2308 if (!WFLAGP(wwin
, no_close_button
)
2309 && wwin
->frame
->flags
.hide_right_button
)
2310 flags
|= WFF_RIGHT_BUTTON
;
2313 wWindowUpdateButtonImages(wwin
);
2314 wFrameWindowShowButton(wwin
->frame
, flags
);
2318 if (WFLAGP(wwin
, no_miniaturize_button
)
2319 && !wwin
->frame
->flags
.hide_left_button
)
2320 flags
|= WFF_LEFT_BUTTON
;
2322 #ifdef XKB_BUTTON_HINT
2323 if (WFLAGP(wwin
, no_language_button
)
2324 && !wwin
->frame
->flags
.hide_language_button
)
2325 flags
|= WFF_LANGUAGE_BUTTON
;
2328 if (WFLAGP(wwin
, no_close_button
)
2329 && !wwin
->frame
->flags
.hide_right_button
)
2330 flags
|= WFF_RIGHT_BUTTON
;
2333 wFrameWindowHideButton(wwin
->frame
, flags
);
2336 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2337 wWindowSetShape(wwin
);
2345 wWindowSaveState(WWindow
*wwin
)
2350 memset(data
, 0, sizeof(CARD32
)*10);
2351 data
[0] = wwin
->frame
->workspace
;
2352 data
[1] = wwin
->flags
.miniaturized
;
2353 data
[2] = wwin
->flags
.shaded
;
2354 data
[3] = wwin
->flags
.hidden
;
2355 data
[4] = wwin
->flags
.maximized
;
2356 if (wwin
->flags
.maximized
== 0) {
2357 data
[5] = wwin
->frame_x
;
2358 data
[6] = wwin
->frame_y
;
2359 data
[7] = wwin
->frame
->core
->width
;
2360 data
[8] = wwin
->frame
->core
->height
;
2362 data
[5] = wwin
->old_geometry
.x
;
2363 data
[6] = wwin
->old_geometry
.y
;
2364 data
[7] = wwin
->old_geometry
.width
;
2365 data
[8] = wwin
->old_geometry
.height
;
2368 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2369 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2370 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2373 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2374 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2375 (unsigned char *)data
, 10);
2380 getSavedState(Window window
, WSavedState
**state
)
2384 unsigned long nitems_ret
;
2385 unsigned long bytes_after_ret
;
2388 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2389 True
, _XA_WINDOWMAKER_STATE
,
2390 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2391 (unsigned char **)&data
)!=Success
|| !data
)
2394 *state
= wmalloc(sizeof(WSavedState
));
2396 (*state
)->workspace
= data
[0];
2397 (*state
)->miniaturized
= data
[1];
2398 (*state
)->shaded
= data
[2];
2399 (*state
)->hidden
= data
[3];
2400 (*state
)->maximized
= data
[4];
2401 (*state
)->x
= data
[5];
2402 (*state
)->y
= data
[6];
2403 (*state
)->w
= data
[7];
2404 (*state
)->h
= data
[8];
2405 (*state
)->window_shortcuts
= data
[9];
2409 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2418 wWindowClearShape(WWindow
*wwin
)
2420 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2421 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2426 wWindowSetShape(WWindow
*wwin
)
2430 #ifdef OPTIMIZE_SHAPE
2435 /* only shape is the client's */
2436 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2440 /* Get array of rectangles describing the shape mask */
2441 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2447 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2453 /* insert our decoration rectangles in the rect list */
2454 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2457 if (!WFLAGP(wwin
, no_titlebar
)) {
2459 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2460 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2461 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2464 if (!WFLAGP(wwin
, no_resizebar
)) {
2466 urec
[count
].y
= wwin
->frame
->core
->height
2467 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2468 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2469 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2473 /* shape our frame window */
2474 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2475 0, wwin
->frame
->top_width
, urec
, count
,
2476 ShapeSet
, Unsorted
);
2482 #endif /* OPTIMIZE_SHAPE */
2484 if (!WFLAGP(wwin
, no_titlebar
)) {
2487 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2488 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2491 if (!WFLAGP(wwin
, no_resizebar
)) {
2493 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2494 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2495 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2499 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2500 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2502 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2503 0, wwin
->frame
->top_width
, wwin
->client_win
,
2504 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2509 /* ====================================================================== */
2512 getFocusMode(WWindow
*wwin
)
2516 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2517 if (wwin
->wm_hints
->input
== True
) {
2518 if (wwin
->protocols
.TAKE_FOCUS
)
2519 mode
= WFM_LOCALLY_ACTIVE
;
2523 if (wwin
->protocols
.TAKE_FOCUS
)
2524 mode
= WFM_GLOBALLY_ACTIVE
;
2526 mode
= WFM_NO_INPUT
;
2536 wWindowSetKeyGrabs(WWindow
*wwin
)
2541 for (i
=0; i
<WKBD_LAST
; i
++) {
2542 key
= &wKeyBindings
[i
];
2544 if (key
->keycode
==0)
2546 if (key
->modifier
!=AnyModifier
) {
2547 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2548 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2550 /* Also grab all modifier combinations possible that include,
2551 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2552 * work even if the NumLock/ScrollLock key is on.
2554 wHackedGrabKey(key
->keycode
, key
->modifier
,
2555 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2559 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2560 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2564 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2571 wWindowResetMouseGrabs(WWindow
*wwin
)
2573 /* Mouse grabs can't be done on the client window because of
2574 * ICCCM and because clients that try to do the same will crash.
2576 * But there is a problem wich makes tbar buttons of unfocused
2577 * windows not usable as the click goes to the frame window instead
2578 * of the button itself. Must figure a way to fix that.
2581 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2583 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2584 /* grabs for Meta+drag */
2585 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2586 True
, ButtonPressMask
, GrabModeSync
,
2587 GrabModeAsync
, None
, None
);
2590 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2591 && !wwin
->flags
.is_gnustep
) {
2592 /* the passive grabs to focus the window */
2593 /* if (wPreferences.focus_mode == WKF_CLICK) */
2594 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2595 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2603 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2605 if (attr
->flags
& GSExtraFlagsAttr
) {
2606 if (MGFLAGP(wwin
, broken_close
) !=
2607 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2608 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2609 wWindowUpdateButtonImages(wwin
);
2616 wWindowAddSavedState(char *instance
, char *class, char *command
,
2617 pid_t pid
, WSavedState
*state
)
2619 WWindowState
*wstate
;
2621 wstate
= malloc(sizeof(WWindowState
));
2625 memset(wstate
, 0, sizeof(WWindowState
));
2628 wstate
->instance
= wstrdup(instance
);
2630 wstate
->class = wstrdup(class);
2632 wstate
->command
= wstrdup(command
);
2633 wstate
->state
= state
;
2635 wstate
->next
= windowState
;
2636 windowState
= wstate
;
2639 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2647 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2651 wWindowGetSavedState(Window win
)
2653 char *instance
, *class, *command
=NULL
;
2654 WWindowState
*wstate
= windowState
;
2661 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2663 command
= wtokenjoin(argv
, argc
);
2664 XFreeStringList(argv
);
2669 if (PropGetWMClass(win
, &class, &instance
)) {
2671 if (SAME(instance
, wstate
->instance
) &&
2672 SAME(class, wstate
->class) &&
2673 SAME(command
, wstate
->command
)) {
2676 wstate
= wstate
->next
;
2683 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2687 if (command
) wfree(command
);
2688 if (instance
) XFree(instance
);
2689 if (class) XFree(class);
2696 wWindowDeleteSavedState(WMagicNumber id
)
2698 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2700 if (!wstate
|| !windowState
)
2705 windowState
= wstate
->next
;
2707 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2708 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2710 if (wstate
->instance
) wfree(wstate
->instance
);
2711 if (wstate
->class) wfree(wstate
->class);
2712 if (wstate
->command
) wfree(wstate
->command
);
2713 wfree(wstate
->state
);
2717 if (tmp
->next
==wstate
) {
2718 tmp
->next
=wstate
->next
;
2720 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2721 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2723 if (wstate
->instance
) wfree(wstate
->instance
);
2724 if (wstate
->class) wfree(wstate
->class);
2725 if (wstate
->command
) wfree(wstate
->command
);
2726 wfree(wstate
->state
);
2737 wWindowDeleteSavedStatesForPID(pid_t pid
)
2739 WWindowState
*tmp
, *wstate
;
2745 if (tmp
->pid
== pid
) {
2746 wstate
= windowState
;
2747 windowState
= tmp
->next
;
2749 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2750 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2752 if (wstate
->instance
) wfree(wstate
->instance
);
2753 if (wstate
->class) wfree(wstate
->class);
2754 if (wstate
->command
) wfree(wstate
->command
);
2755 wfree(wstate
->state
);
2759 if (tmp
->next
->pid
==pid
) {
2761 tmp
->next
= wstate
->next
;
2763 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2764 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2766 if (wstate
->instance
) wfree(wstate
->instance
);
2767 if (wstate
->class) wfree(wstate
->class);
2768 if (wstate
->command
) wfree(wstate
->command
);
2769 wfree(wstate
->state
);
2780 wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
2782 wwin
->flags
.omnipresent
= flag
;
2784 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
2788 /* ====================================================================== */
2791 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2793 WWindow
*wwin
= data
;
2795 #ifndef NUMLOCK_HACK
2796 if ((event
->xbutton
.state
& ValidModMask
)
2797 != (event
->xbutton
.state
& ~LockMask
)) {
2798 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2799 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2803 event
->xbutton
.state
&= ValidModMask
;
2805 CloseWindowMenu(wwin
->screen_ptr
);
2807 if (wPreferences
.focus_mode
==WKF_CLICK
2808 && !(event
->xbutton
.state
&ControlMask
)
2809 && !WFLAGP(wwin
, no_focusable
)) {
2810 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2813 if (event
->xbutton
.button
== Button1
)
2814 wRaiseFrame(wwin
->frame
->core
);
2816 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2817 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2818 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2819 GrabModeAsync
, GrabModeAsync
, None
,
2820 None
, CurrentTime
)!=GrabSuccess
) {
2822 wwarning("pointer grab failed for window move");
2828 if (event
->xbutton
.state
& MOD_MASK
) {
2829 /* move the window */
2830 wMouseMoveWindow(wwin
, event
);
2831 XUngrabPointer(dpy
, CurrentTime
);
2833 wMouseResizeWindow(wwin
, event
);
2834 XUngrabPointer(dpy
, CurrentTime
);
2841 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2843 WWindow
*wwin
= data
;
2845 event
->xbutton
.state
&= ValidModMask
;
2847 if (event
->xbutton
.button
==Button1
) {
2848 if (event
->xbutton
.state
== 0) {
2849 if (!WFLAGP(wwin
, no_shadeable
)) {
2851 if (wwin
->flags
.shaded
)
2852 wUnshadeWindow(wwin
);
2859 if (event
->xbutton
.state
& ControlMask
)
2860 dir
|= MAX_VERTICAL
;
2862 if (event
->xbutton
.state
& ShiftMask
) {
2863 dir
|= MAX_HORIZONTAL
;
2864 if (!(event
->xbutton
.state
& ControlMask
))
2865 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2868 /* maximize window */
2869 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2870 int ndir
= dir
^ wwin
->flags
.maximized
;
2871 if (wwin
->flags
.maximized
!= 0)
2872 wUnmaximizeWindow(wwin
);
2874 wMaximizeWindow(wwin
, ndir
);
2877 } else if (event
->xbutton
.button
==Button3
) {
2878 if (event
->xbutton
.state
& MOD_MASK
) {
2879 wHideOtherApplications(wwin
);
2881 } else if (event
->xbutton
.button
==Button2
) {
2882 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2883 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
2885 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
2886 wUnshadeWindow(wwin
);
2892 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2894 WWindow
*wwin
= desc
->parent
;
2896 event
->xbutton
.state
&= ValidModMask
;
2898 CloseWindowMenu(wwin
->screen_ptr
);
2900 if (/*wPreferences.focus_mode==WKF_CLICK
2901 &&*/ !(event
->xbutton
.state
&ControlMask
)
2902 && !WFLAGP(wwin
, no_focusable
)) {
2903 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2905 if (event
->xbutton
.button
== Button1
) {
2906 wRaiseFrame(wwin
->frame
->core
);
2909 if (event
->xbutton
.state
& MOD_MASK
) {
2910 /* move the window */
2911 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2912 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2913 GrabModeAsync
, GrabModeAsync
, None
,
2914 None
, CurrentTime
)!=GrabSuccess
) {
2916 wwarning("pointer grab failed for window move");
2920 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2921 wMouseResizeWindow(wwin
, event
);
2923 wMouseMoveWindow(wwin
, event
);
2924 XUngrabPointer(dpy
, CurrentTime
);
2930 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2932 WWindow
*wwin
= (WWindow
*)data
;
2934 #ifndef NUMLOCK_HACK
2935 if ((event
->xbutton
.state
& ValidModMask
)
2936 != (event
->xbutton
.state
& ~LockMask
)) {
2937 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2938 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2941 event
->xbutton
.state
&= ValidModMask
;
2943 CloseWindowMenu(wwin
->screen_ptr
);
2945 if (wPreferences
.focus_mode
==WKF_CLICK
2946 && !(event
->xbutton
.state
&ControlMask
)
2947 && !WFLAGP(wwin
, no_focusable
)) {
2948 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2951 if (event
->xbutton
.button
== Button1
2952 || event
->xbutton
.button
== Button2
) {
2954 if (event
->xbutton
.button
== Button1
) {
2955 if (event
->xbutton
.state
& MOD_MASK
) {
2956 wLowerFrame(wwin
->frame
->core
);
2958 wRaiseFrame(wwin
->frame
->core
);
2961 if ((event
->xbutton
.state
& ShiftMask
)
2962 && !(event
->xbutton
.state
& ControlMask
)) {
2963 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2966 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2967 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2968 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2969 GrabModeAsync
, GrabModeAsync
, None
,
2970 None
, CurrentTime
)!=GrabSuccess
) {
2972 wwarning("pointer grab failed for window move");
2977 /* move the window */
2978 wMouseMoveWindow(wwin
, event
);
2980 XUngrabPointer(dpy
, CurrentTime
);
2981 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2982 && !wwin
->flags
.internal_window
2983 && !WCHECK_STATE(WSTATE_MODAL
)) {
2984 WObjDescriptor
*desc
;
2986 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2987 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2988 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2989 GrabModeAsync
, GrabModeAsync
, None
,
2990 None
, CurrentTime
)!=GrabSuccess
) {
2992 wwarning("pointer grab failed for window move");
2997 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2998 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3000 /* allow drag select */
3001 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3002 event
->xany
.send_event
= True
;
3003 (*desc
->handle_mousedown
)(desc
, event
);
3005 XUngrabPointer(dpy
, CurrentTime
);
3012 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3014 WWindow
*wwin
= data
;
3016 event
->xbutton
.state
&= ValidModMask
;
3018 CloseWindowMenu(wwin
->screen_ptr
);
3020 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3023 /* if control-click, kill the client */
3024 if (event
->xbutton
.state
& ControlMask
) {
3028 if (wwin
->flags
.olwm_push_pin_out
) {
3030 wwin
->flags
.olwm_push_pin_out
= 0;
3032 wOLWMChangePushpinState(wwin
, True
);
3034 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
3039 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3040 /* send delete message */
3041 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3048 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3050 WWindow
*wwin
= data
;
3052 CloseWindowMenu(wwin
->screen_ptr
);
3054 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3057 /* send delete message */
3058 if (wwin
->protocols
.DELETE_WINDOW
) {
3059 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3066 #ifdef XKB_BUTTON_HINT
3068 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3070 WWindow
*wwin
= data
;
3071 WFrameWindow
*fwin
= wwin
->frame
;
3072 WScreen
*scr
= fwin
->screen_ptr
;
3073 XkbStateRec staterec
;
3076 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3078 tl
= wwin
->frame
->languagemode
;
3079 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3080 wwin
->frame
->last_languagemode
= tl
;
3081 wSetFocusTo(scr
, wwin
);
3082 wwin
->frame
->languagebutton_image
=
3083 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3084 wwin
->frame
->languagemode
];
3085 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3086 if (event
->xbutton
.button
== Button3
)
3088 wRaiseFrame(fwin
->core
);
3094 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3096 WWindow
*wwin
= data
;
3098 event
->xbutton
.state
&= ValidModMask
;
3100 CloseWindowMenu(wwin
->screen_ptr
);
3102 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3105 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3106 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3110 if ((event
->xbutton
.state
& ControlMask
) ||
3111 (event
->xbutton
.button
== Button3
)) {
3113 wapp
= wApplicationOf(wwin
->main_window
);
3114 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3115 wHideApplication(wapp
);
3116 } else if (event
->xbutton
.state
==0) {
3117 wIconifyWindow(wwin
);