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 WMRemoveFromBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
232 if (!WMGetBagItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
233 WMFreeBag(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;
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 */
434 if (WFLAGP(wwin
, floating
))
435 *level
= WMFloatingLevel
;
436 else if (WFLAGP(wwin
, sunken
))
437 *level
= WMSunkenLevel
;
439 *level
= WMNormalLevel
;
444 if (tmp_workspace
>= 0) {
445 *workspace
= tmp_workspace
% scr
->workspace_count
;
450 * Set attributes specified only for that window/class.
451 * This might do duplicate work with the 1st wDefaultFillAttributes().
453 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
454 &wwin
->user_flags
, &wwin
->defined_user_flags
,
457 * Sanity checks for attributes that depend on other attributes
459 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
460 wwin
->user_flags
.emulate_appicon
= 0;
462 if (wwin
->main_window
!=None
) {
463 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
464 if (wapp
&& !wapp
->flags
.emulated
)
465 wwin
->user_flags
.emulate_appicon
= 0;
468 if (wwin
->transient_for
!=None
469 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
470 wwin
->user_flags
.emulate_appicon
= 0;
472 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
473 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
474 wwin
->user_flags
.sunken
= 0;
476 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
483 wWindowCanReceiveFocus(WWindow
*wwin
)
485 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
487 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
489 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
497 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
501 w1
= wwin
->frame
->core
->width
;
502 h1
= wwin
->frame
->core
->height
;
503 w2
= obscured
->frame
->core
->width
;
504 h2
= obscured
->frame
->core
->height
;
506 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
507 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
510 if (wwin
->frame_x
+ w1
< obscured
->frame_x
511 || wwin
->frame_y
+ h1
< obscured
->frame_y
512 || wwin
->frame_x
> obscured
->frame_x
+ w2
513 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
522 *----------------------------------------------------------------
524 * reparents the window and allocates a descriptor for it.
525 * Window manager hints and other hints are fetched to configure
526 * the window decoration attributes and others. User preferences
527 * for the window are used if available, to configure window
528 * decorations and some behaviour.
529 * If in startup, windows that are override redirect,
530 * unmapped and never were managed and are Withdrawn are not
534 * the new window descriptor
537 * The window is reparented and appropriate notification
538 * is done to the client. Input mask for the window is setup.
539 * The window descriptor is also associated with various window
540 * contexts and inserted in the head of the window list.
541 * Event handler contexts are associated for some objects
542 * (buttons, titlebar and resizebar)
544 *----------------------------------------------------------------
547 wManageWindow(WScreen
*scr
, Window window
)
551 unsigned width
, height
;
552 XWindowAttributes wattribs
;
553 XSetWindowAttributes attribs
;
554 WWindowState
*win_state
;
555 WWindow
*transientOwner
= NULL
;
561 Bool withdraw
= False
;
564 /* XGrabServer(dpy); */
566 /* make sure the window is still there */
567 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
572 /* if it's an override-redirect, ignore it */
573 if (wattribs
.override_redirect
) {
578 wm_state
= PropGetWindowState(window
);
580 /* if it's startup and the window is unmapped, don't manage it */
581 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
586 if (!wFetchName(dpy
, window
, &title
)) {
591 if (title
&& !wKWMManageableClient(scr
, window
, title
)) {
596 #endif /* KWM_HINTS */
599 wwin
= wWindowCreate();
601 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
604 printf("managing window %x\n", (unsigned)window
);
608 if (wShapeSupported
) {
613 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
614 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
615 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
616 wwin
->flags
.shaped
= b_shaped
;
621 *--------------------------------------------------
623 * Get hints and other information in properties
625 *--------------------------------------------------
627 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
629 /* setup descriptor */
630 wwin
->client_win
= window
;
631 wwin
->screen_ptr
= scr
;
633 wwin
->old_border_width
= wattribs
.border_width
;
635 wwin
->event_mask
= CLIENT_EVENTS
;
636 attribs
.event_mask
= CLIENT_EVENTS
;
637 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
638 attribs
.save_under
= False
;
639 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
640 |CWSaveUnder
, &attribs
);
641 XSetWindowBorderWidth(dpy
, window
, 0);
643 /* get hints from GNUstep app */
644 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
645 wwin
->flags
.is_gnustep
= 1;
647 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
648 wwin
->wm_gnustep_attr
= NULL
;
651 wwin
->client_leader
= PropGetClientLeader(window
);
652 if (wwin
->client_leader
!=None
)
653 wwin
->main_window
= wwin
->client_leader
;
655 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
657 if (wwin
->wm_hints
) {
658 if (wwin
->wm_hints
->flags
& StateHint
) {
660 if (wwin
->wm_hints
->initial_state
== IconicState
) {
662 wwin
->flags
.miniaturized
= 1;
664 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
670 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
671 wwin
->group_id
= wwin
->wm_hints
->window_group
;
672 /* window_group has priority over CLIENT_LEADER */
673 wwin
->main_window
= wwin
->group_id
;
675 wwin
->group_id
= None
;
678 if (wwin
->wm_hints
->flags
& UrgencyHint
)
679 wwin
->flags
.urgent
= 1;
681 wwin
->group_id
= None
;
684 PropGetProtocols(window
, &wwin
->protocols
);
686 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
687 wwin
->transient_for
= None
;
689 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
690 wwin
->transient_for
= scr
->root_win
;
692 transientOwner
= wWindowFor(wwin
->transient_for
);
693 if (transientOwner
&& transientOwner
->main_window
!=None
) {
694 wwin
->main_window
= transientOwner
->main_window
;
696 wwin->main_window = None;
701 /* guess the focus mode */
702 wwin
->focus_mode
= getFocusMode(wwin
);
704 /* get geometry stuff */
705 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
707 /* get colormap windows */
708 GetColormapWindows(wwin
);
711 *--------------------------------------------------
713 * Setup the decoration/window attributes and
716 *--------------------------------------------------
719 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
722 if (wwin
->client_flags
.olwm_transient
&& wwin
->transient_for
==None
723 && wwin
->group_id
!= None
&& wwin
->group_id
!= window
) {
725 transientOwner
= wWindowFor(wwin
->group_id
);
727 if (transientOwner
) {
728 wwin
->transient_for
= wwin
->group_id
;
730 /* transients can't be iconified or maximized */
731 if (wwin
->transient_for
) {
732 WSETUFLAG(wwin
, no_miniaturizable
, 1);
733 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
737 #endif /* OLWM_HINTS */
740 * Make broken apps behave as a nice app.
742 if (WFLAGP(wwin
, emulate_appicon
)) {
743 wwin
->main_window
= wwin
->client_win
;
747 *------------------------------------------------------------
749 * Setup the initial state of the window
751 *------------------------------------------------------------
754 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
755 wwin
->flags
.miniaturized
= 1;
758 if (WFLAGP(wwin
, start_maximized
) && !WFLAGP(wwin
, no_resizable
)) {
759 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
767 bla
= wGNOMECheckInitialClientState(wwin
);
771 wKWMCheckClientInitialState(wwin
);
775 /* apply previous state if it exists and we're in startup */
776 if (scr
->flags
.startup
&& wm_state
>= 0) {
778 if (wm_state
== IconicState
) {
780 wwin
->flags
.miniaturized
= 1;
782 } else if (wm_state
== WithdrawnState
) {
788 /* if there is a saved state (from file), restore it */
790 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
791 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
793 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
795 if (win_state
&& !withdraw
) {
797 if (win_state
->state
->hidden
>0)
798 wwin
->flags
.hidden
= win_state
->state
->hidden
;
800 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
801 wwin
->flags
.shaded
= win_state
->state
->shaded
;
803 if (win_state
->state
->miniaturized
>0 &&
804 !WFLAGP(wwin
, no_miniaturizable
)) {
805 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
808 if (!IS_OMNIPRESENT(wwin
)) {
809 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
811 if (w
< 0 || w
>= scr
->workspace_count
) {
812 workspace
= win_state
->state
->workspace
;
813 if (workspace
>= scr
->workspace_count
)
814 workspace
= scr
->current_workspace
;
819 workspace
= scr
->current_workspace
;
823 /* if we're restarting, restore saved state (from hints).
824 * This will overwrite previous */
828 if (getSavedState(window
, &wstate
)) {
829 wwin
->flags
.shaded
= wstate
->shaded
;
830 wwin
->flags
.hidden
= wstate
->hidden
;
831 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
832 wwin
->flags
.maximized
= wstate
->maximized
;
833 if (wwin
->flags
.maximized
) {
834 wwin
->old_geometry
.x
= wstate
->x
;
835 wwin
->old_geometry
.y
= wstate
->y
;
836 wwin
->old_geometry
.width
= wstate
->w
;
837 wwin
->old_geometry
.height
= wstate
->h
;
840 workspace
= wstate
->workspace
;
845 /* restore window shortcut */
846 if (wstate
!= NULL
|| win_state
!= NULL
) {
849 if (win_state
!= NULL
)
850 mask
= win_state
->state
->window_shortcuts
;
852 if (wstate
!= NULL
&& mask
== 0)
853 mask
= wstate
->window_shortcuts
;
858 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
860 if (!scr
->shortcutWindows
[i
])
861 scr
->shortcutWindows
[i
] = WMCreateBag(4);
863 WMPutInBag(scr
->shortcutWindows
[i
], wwin
);
868 if (wstate
!= NULL
) {
873 /* don't let transients start miniaturized if their owners are not */
874 if (transientOwner
&& !transientOwner
->flags
.miniaturized
875 && wwin
->flags
.miniaturized
&& !withdraw
) {
876 wwin
->flags
.miniaturized
= 0;
878 wwin
->wm_hints
->initial_state
= NormalState
;
881 /* set workspace on which the window starts */
882 if (workspace
>= 0) {
883 if (workspace
> scr
->workspace_count
-1) {
884 workspace
= workspace
% scr
->workspace_count
;
889 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
891 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
896 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
898 workspace
= transientOwner
->frame
->workspace
;
902 workspace
= scr
->current_workspace
;
907 /* setup window geometry */
908 if (win_state
&& win_state
->state
->w
> 0) {
909 width
= win_state
->state
->w
;
910 height
= win_state
->state
->h
;
912 wWindowConstrainSize(wwin
, &width
, &height
);
914 /* do not ask for window placement if the window is
915 * transient, during startup, if the initial workspace is another one
916 * or if the window wants to start iconic.
917 * If geometry was saved, restore it. */
919 Bool dontBring
= False
;
921 if (win_state
&& win_state
->state
->w
> 0) {
922 x
= win_state
->state
->x
;
923 y
= win_state
->state
->y
;
924 } else if ((wwin
->transient_for
==None
925 || wPreferences
.window_placement
!=WPM_MANUAL
)
926 && !scr
->flags
.startup
927 && workspace
== scr
->current_workspace
928 && !wwin
->flags
.miniaturized
929 && !wwin
->flags
.maximized
930 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
932 if (transientOwner
&& transientOwner
->flags
.mapped
) {
933 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
935 x
= transientOwner
->frame_x
+
936 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
937 y
= transientOwner
->frame_y
+
938 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
942 else if (x
+ width
> scr
->scr_width
)
943 x
= scr
->scr_width
- width
;
947 else if (y
+ height
> scr
->scr_height
)
948 y
= scr
->scr_height
- height
;
950 PlaceWindow(wwin
, &x
, &y
, width
, height
);
952 if (wPreferences
.window_placement
== WPM_MANUAL
)
956 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
957 wScreenBringInside(scr
, &x
, &y
, width
, height
);
960 if (wwin
->flags
.urgent
) {
961 if (!IS_OMNIPRESENT(wwin
))
962 wwin
->flags
.omnipresent
^= 1;
966 *--------------------------------------------------
968 * Create frame, borders and do reparenting
970 *--------------------------------------------------
972 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
973 #ifdef XKB_BUTTON_HINT
974 if (wPreferences
.modelock
)
975 foo
|= WFF_LANGUAGE_BUTTON
;
977 if (!WFLAGP(wwin
, no_titlebar
))
979 if (!WFLAGP(wwin
, no_resizebar
))
980 foo
|= WFF_RESIZEBAR
;
981 if (!WFLAGP(wwin
, no_border
))
984 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
986 &wPreferences
.window_title_clearance
, foo
,
987 scr
->window_title_texture
,
988 scr
->resizebar_texture
,
989 scr
->window_title_pixel
,
990 &scr
->window_title_gc
,
993 wwin
->frame
->flags
.is_client_window_frame
= 1;
994 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
996 /* setup button images */
997 wWindowUpdateButtonImages(wwin
);
999 /* hide unused buttons */
1001 if (WFLAGP(wwin
, no_close_button
))
1002 foo
|= WFF_RIGHT_BUTTON
;
1003 if (WFLAGP(wwin
, no_miniaturize_button
))
1004 foo
|= WFF_LEFT_BUTTON
;
1005 #ifdef XKB_BUTTON_HINT
1006 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1007 foo
|= WFF_LANGUAGE_BUTTON
;
1010 wFrameWindowHideButton(wwin
->frame
, foo
);
1012 wwin
->frame
->child
= wwin
;
1015 /* emulate olwm push pin. Make the button look as pushed-in for
1016 * the pinned-out state. When the button is clicked, it will
1017 * revert to the normal position, which means the pin is pinned-in.
1019 if (wwin
->flags
.olwm_push_pin_out
)
1020 wFrameWindowUpdatePushButton(wwin
->frame
, True
);
1021 #endif /* OLWM_HINTS */
1023 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
1027 wwin
->frame
->workspace
= workspace
;
1029 wwin
->frame
->on_click_left
= windowIconifyClick
;
1030 #ifdef XKB_BUTTON_HINT
1031 if (wPreferences
.modelock
)
1032 wwin
->frame
->on_click_language
= windowLanguageClick
;
1035 wwin
->frame
->on_click_right
= windowCloseClick
;
1036 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1038 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1039 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1041 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1044 XSelectInput(dpy
, wwin
->client_win
,
1045 wwin
->event_mask
& ~StructureNotifyMask
);
1047 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1048 0, wwin
->frame
->top_width
);
1050 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1056 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1058 /* if gravity is to the south, account for the border sizes */
1060 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1064 * wWindowConfigure() will init the client window's size
1065 * (wwin->client.{width,height}) and all other geometry
1066 * related variables (frame_x,frame_y)
1068 wWindowConfigure(wwin
, x
, y
, width
, height
);
1070 /* to make sure the window receives it's new position after reparenting */
1071 wWindowSynthConfigureNotify(wwin
);
1074 *--------------------------------------------------
1076 * Setup descriptors and save window to internal
1079 *--------------------------------------------------
1082 if (wwin
->main_window
!=None
) {
1086 /* Leader windows do not necessary set themselves as leaders.
1087 * If this is the case, point the leader of this window to
1089 leader
= wWindowFor(wwin
->main_window
);
1090 if (leader
&& leader
->main_window
==None
) {
1091 leader
->main_window
= leader
->client_win
;
1093 app
= wApplicationCreate(scr
, wwin
->main_window
);
1095 app
->last_workspace
= workspace
;
1098 * Do application specific stuff, like setting application
1102 if (wwin
->flags
.hidden
) {
1103 /* if the window was set to hidden because it was hidden
1104 * in a previous incarnation and that state was restored */
1105 app
->flags
.hidden
= 1;
1108 if (app
->flags
.hidden
) {
1109 wwin
->flags
.hidden
= 1;
1114 /* setup the frame descriptor */
1115 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1116 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1117 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1119 /* don't let windows go away if we die */
1120 XAddToSaveSet(dpy
, window
);
1122 XLowerWindow(dpy
, window
);
1124 /* if window is in this workspace and should be mapped, then map it */
1125 if (!wwin
->flags
.miniaturized
1126 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1127 && !wwin
->flags
.hidden
&& !withdraw
) {
1129 /* The following "if" is to avoid crashing of clients that expect
1130 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1131 * after the return from this function.
1133 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1134 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1136 wClientSetState(wwin
, NormalState
, None
);
1140 /* if not auto focus, then map the window under the currently
1142 #define _WIDTH(w) (w)->frame->core->width
1143 #define _HEIGHT(w) (w)->frame->core->height
1144 if (!wPreferences
.auto_focus
&& scr
->focused_window
1145 && !scr
->flags
.startup
&& !transientOwner
1146 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1147 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1148 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1149 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1150 || wwin
->flags
.maximized
)) {
1151 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1159 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1160 && !scr
->flags
.startup
&& wwin
->transient_for
==None
1162 * The brain damaged idiotic non-click to focus modes will
1163 * have trouble with this because:
1165 * 1. window is created and mapped by the client
1166 * 2. window is mapped by wmaker in small size
1167 * 3. window is animated to grow to normal size
1168 * 4. this function returns to normal event loop
1169 * 5. eventually, the EnterNotify event that would trigger
1170 * the window focusing (if the mouse is over that window)
1171 * will be processed by wmaker.
1172 * But since this event will be rather delayed
1173 * (step 3 has a large delay) the time when the event ocurred
1174 * and when it is processed, the client that owns that window
1175 * will reject the XSetInputFocus() for it.
1177 && (wPreferences
.focus_mode
==WKF_CLICK
1178 || wPreferences
.auto_focus
)) {
1179 DoWindowBirth(wwin
);
1185 /* setup stacking descriptor */
1186 if (transientOwner
) {
1187 /* && wPreferences.on_top_transients */
1188 if (transientOwner
) {
1189 wwin
->frame
->core
->stacking
->child_of
=
1190 transientOwner
->frame
->core
;
1193 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1197 if (!scr
->focused_window
) {
1198 /* first window on the list */
1201 scr
->focused_window
= wwin
;
1205 /* add window at beginning of focus window list */
1206 tmp
= scr
->focused_window
;
1215 wGNOMEUpdateClientStateHint(wwin
, True
);
1218 wKWMUpdateClientWorkspace(wwin
);
1219 wKWMUpdateClientStateHint(wwin
, KWMAllFlags
);
1225 *--------------------------------------------------
1227 * Final preparations before window is ready to go
1229 *--------------------------------------------------
1232 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1235 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1236 && !wwin
->flags
.hidden
) {
1237 if (((transientOwner
&& transientOwner
->flags
.focused
)
1238 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1239 wSetFocusTo(scr
, wwin
);
1241 wWindowResetMouseGrabs(wwin
);
1243 if (!WFLAGP(wwin
, no_bind_keys
)) {
1244 wWindowSetKeyGrabs(wwin
);
1247 wGNOMEUpdateClientListHint(scr
);
1250 wwin
->flags
.kwm_managed
= 1;
1252 wKWMSendEventMessage(wwin
, WKWMAddWindow
);
1255 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1257 UpdateSwitchMenu(scr
, wwin
, ACTION_ADD
);
1260 if (wwin
->client_flags
.olwm_warp_to_pin
&& wwin
->frame
->titlebar
!= NULL
1261 && !WFLAGP(wwin
, no_close_button
) && !withdraw
) {
1263 XWarpPointer(dpy
, None
, None
, 0, 0, 0, 0,
1264 wwin
->frame_x
+ width
- wwin
->frame
->titlebar
->height
* 2,
1270 *------------------------------------------------------------
1271 * Setup Notification Observers
1272 *------------------------------------------------------------
1274 WMAddNotificationObserver(appearanceObserver
, wwin
,
1275 WNWindowAppearanceSettingsChanged
, wwin
);
1279 *--------------------------------------------------
1281 * Cleanup temporary stuff
1283 *--------------------------------------------------
1287 wWindowDeleteSavedState(win_state
);
1289 /* If the window must be withdrawed, then do it now.
1290 * Must do some optimization, 'though */
1292 wwin
->flags
.mapped
= 0;
1293 wClientSetState(wwin
, WithdrawnState
, None
);
1294 wUnmanageWindow(wwin
, True
, False
);
1306 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1307 char *title
, int x
, int y
, int width
, int height
)
1312 wwin
= wWindowCreate();
1314 WMAddNotificationObserver(appearanceObserver
, wwin
,
1315 WNWindowAppearanceSettingsChanged
, wwin
);
1317 wwin
->flags
.internal_window
= 1;
1319 WSETUFLAG(wwin
, omnipresent
, 1);
1320 WSETUFLAG(wwin
, no_shadeable
, 1);
1321 WSETUFLAG(wwin
, no_resizable
, 1);
1322 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1324 wwin
->focus_mode
= WFM_PASSIVE
;
1326 wwin
->client_win
= window
;
1327 wwin
->screen_ptr
= scr
;
1329 wwin
->transient_for
= owner
;
1333 wwin
->client
.width
= width
;
1334 wwin
->client
.height
= height
;
1336 wwin
->frame_x
= wwin
->client
.x
;
1337 wwin
->frame_y
= wwin
->client
.y
;
1340 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1341 foo
|= WFF_TITLEBAR
;
1342 #ifdef XKB_BUTTON_HINT
1343 foo
|= WFF_LANGUAGE_BUTTON
;
1346 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1347 wwin
->frame_x
, wwin
->frame_y
,
1349 &wPreferences
.window_title_clearance
, foo
,
1350 scr
->window_title_texture
,
1351 scr
->resizebar_texture
,
1352 scr
->window_title_pixel
,
1353 &scr
->window_title_gc
,
1356 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1358 wwin
->frame
->flags
.is_client_window_frame
= 1;
1359 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1361 wFrameWindowChangeTitle(wwin
->frame
, title
);
1363 /* setup button images */
1364 wWindowUpdateButtonImages(wwin
);
1367 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1369 wwin
->frame
->child
= wwin
;
1371 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1373 #ifdef XKB_BUTTON_HINT
1374 if (wPreferences
.modelock
)
1375 wwin
->frame
->on_click_language
= windowLanguageClick
;
1378 wwin
->frame
->on_click_right
= windowCloseClick
;
1380 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1381 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1383 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1385 wwin
->client
.y
+= wwin
->frame
->top_width
;
1386 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1387 0, wwin
->frame
->top_width
);
1389 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1390 wwin
->client
.width
, wwin
->client
.height
);
1392 /* setup the frame descriptor */
1393 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1394 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1395 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1398 XLowerWindow(dpy
, window
);
1399 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1401 /* setup stacking descriptor */
1404 wPreferences
.on_top_transients
&&
1406 wwin
->transient_for
!=None
1407 && wwin
->transient_for
!=scr
->root_win
) {
1409 tmp
= wWindowFor(wwin
->transient_for
);
1411 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1413 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1417 if (!scr
->focused_window
) {
1418 /* first window on the list */
1421 scr
->focused_window
= wwin
;
1425 /* add window at beginning of focus window list */
1426 tmp
= scr
->focused_window
;
1434 if (wwin
->flags
.is_gnustep
== 0)
1435 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1437 /* if (wPreferences.auto_focus)*/
1438 wSetFocusTo(scr
, wwin
);
1440 wWindowResetMouseGrabs(wwin
);
1442 wWindowSetKeyGrabs(wwin
);
1444 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1451 *----------------------------------------------------------------------
1453 * Removes the frame window from a window and destroys all data
1454 * related to it. The window will be reparented back to the root window
1455 * if restore is True.
1458 * Everything related to the window is destroyed and the window
1459 * is removed from the window lists. Focus is set to the previous on the
1461 *----------------------------------------------------------------------
1464 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1466 WCoreWindow
*frame
= wwin
->frame
->core
;
1467 WWindow
*owner
= NULL
;
1468 WWindow
*newFocusedWindow
= NULL
;
1470 WScreen
*scr
= wwin
->screen_ptr
;
1474 wwin
->frame
->workspace
= -1;
1476 wKWMUpdateClientWorkspace(wwin
);
1479 /* First close attribute editor window if open */
1480 if (wwin
->flags
.inspector_open
) {
1481 wCloseInspectorForWindow(wwin
);
1484 /* Close window menu if it's open for this window */
1485 if (wwin
->flags
.menu_open_for_me
) {
1486 CloseWindowMenu(scr
);
1490 if (!wwin
->flags
.internal_window
)
1491 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1493 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1495 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1496 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1499 XUnmapWindow(dpy
, frame
->window
);
1501 XUnmapWindow(dpy
, wwin
->client_win
);
1503 /* deselect window */
1504 wSelectWindow(wwin
, False
);
1506 /* remove all pending events on window */
1507 /* I think this only matters for autoraise */
1508 if (wPreferences
.raise_delay
)
1509 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1513 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1515 /* reparent the window back to the root */
1517 wClientRestore(wwin
);
1519 if (wwin
->transient_for
!=scr
->root_win
) {
1520 owner
= wWindowFor(wwin
->transient_for
);
1522 if (!owner
->flags
.semi_focused
) {
1525 owner
->flags
.semi_focused
= 0;
1530 wasFocused
= wwin
->flags
.focused
;
1532 /* remove from window focus list */
1533 if (!wwin
->prev
&& !wwin
->next
) {
1534 /* was the only window */
1535 scr
->focused_window
= NULL
;
1536 newFocusedWindow
= NULL
;
1541 wwin
->prev
->next
= wwin
->next
;
1543 wwin
->next
->prev
= wwin
->prev
;
1545 scr
->focused_window
= wwin
->prev
;
1546 scr
->focused_window
->next
= NULL
;
1549 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1551 /* if in click to focus mode and the window
1552 * was a transient, focus the owner window
1555 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1556 tmp
= wWindowFor(wwin
->transient_for
);
1557 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1561 /* otherwise, focus the next one in the focus list */
1563 tmp
= scr
->focused_window
;
1564 while (tmp
) { /* look for one in the window list first */
1565 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1566 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1570 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1571 tmp
= scr
->focused_window
;
1573 if (!WFLAGP(tmp
, no_focusable
)
1574 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1581 newFocusedWindow
= tmp
;
1583 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1584 || wPreferences
.focus_mode
==WKF_POINTER
) {
1589 /* This is to let the root window get the keyboard input
1590 * if Sloppy focus mode and no other window get focus.
1591 * This way keybindings will not freeze.
1594 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1595 &foo
, &foo
, &foo
, &foo
, &mask
))
1596 tmp
= wWindowFor(win
);
1599 newFocusedWindow
= tmp
;
1601 newFocusedWindow
= NULL
;
1605 if (!wwin
->flags
.internal_window
) {
1607 wGNOMERemoveClient(wwin
);
1610 wKWMSendEventMessage(wwin
, WKWMRemoveWindow
);
1615 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1616 (unsigned)frame
->window
);
1620 if (newFocusedWindow
!= owner
&& owner
) {
1621 if (wwin
->flags
.is_gnustep
== 0)
1622 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1624 wSetFocusTo(scr
, newFocusedWindow
);
1626 wWindowDestroy(wwin
);
1632 wWindowMap(WWindow
*wwin
)
1634 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1635 if (!wwin
->flags
.shaded
) {
1636 /* window will be remapped when getting MapNotify */
1637 XSelectInput(dpy
, wwin
->client_win
,
1638 wwin
->event_mask
& ~StructureNotifyMask
);
1639 XMapWindow(dpy
, wwin
->client_win
);
1640 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1642 wwin
->flags
.mapped
= 1;
1648 wWindowUnmap(WWindow
*wwin
)
1650 wwin
->flags
.mapped
= 0;
1652 /* prevent window withdrawal when getting UnmapNotify */
1653 XSelectInput(dpy
, wwin
->client_win
,
1654 wwin
->event_mask
& ~StructureNotifyMask
);
1655 XUnmapWindow(dpy
, wwin
->client_win
);
1656 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1658 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1664 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1669 #ifdef KEEP_XKB_LOCK_STATUS
1670 if (wPreferences
.modelock
) {
1671 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1673 #endif /* KEEP_XKB_LOCK_STATUS */
1675 wwin
->flags
.semi_focused
= 0;
1677 if (wwin
->flags
.is_gnustep
== 0)
1678 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1680 wwin
->flags
.focused
= 1;
1682 wWindowResetMouseGrabs(wwin
);
1684 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1686 if (owin
== wwin
|| !owin
)
1689 nowner
= wWindowFor(wwin
->transient_for
);
1691 /* new window is a transient for the old window */
1692 if (nowner
== owin
) {
1693 owin
->flags
.semi_focused
= 1;
1694 wWindowUnfocus(nowner
);
1698 oowner
= wWindowFor(owin
->transient_for
);
1700 /* new window is owner of old window */
1701 if (wwin
== oowner
) {
1702 wWindowUnfocus(owin
);
1707 wWindowUnfocus(owin
);
1711 /* new window has same owner of old window */
1712 if (oowner
== nowner
) {
1713 /* prevent unfocusing of owner */
1714 oowner
->flags
.semi_focused
= 0;
1715 wWindowUnfocus(owin
);
1716 oowner
->flags
.semi_focused
= 1;
1721 /* nowner != NULL && oowner != nowner */
1722 nowner
->flags
.semi_focused
= 1;
1723 wWindowUnfocus(nowner
);
1724 wWindowUnfocus(owin
);
1729 wWindowUnfocus(WWindow
*wwin
)
1731 CloseWindowMenu(wwin
->screen_ptr
);
1733 if (wwin
->flags
.is_gnustep
== 0)
1734 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1735 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1737 if (wwin
->transient_for
!=None
1738 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1740 owner
= wWindowFor(wwin
->transient_for
);
1741 if (owner
&& owner
->flags
.semi_focused
) {
1742 owner
->flags
.semi_focused
= 0;
1743 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1744 wWindowUnfocus(owner
);
1745 wFrameWindowPaint(owner
->frame
);
1749 wwin
->flags
.focused
= 0;
1751 wWindowResetMouseGrabs(wwin
);
1753 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1760 *----------------------------------------------------------------------
1762 * wWindowConstrainSize--
1763 * Constrains size for the client window, taking the maximal size,
1764 * window resize increments and other size hints into account.
1767 * The closest size to what was given that the client window can
1770 *----------------------------------------------------------------------
1773 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1775 int width
= *nwidth
;
1776 int height
= *nheight
;
1779 int minW
= 1, minH
= 1;
1780 int maxW
= wwin
->screen_ptr
->scr_width
*2;
1781 int maxH
= wwin
->screen_ptr
->scr_height
*2;
1782 int minAX
= -1, minAY
= -1;
1783 int maxAX
= -1, maxAY
= -1;
1787 if (wwin
->normal_hints
) {
1788 winc
= wwin
->normal_hints
->width_inc
;
1789 hinc
= wwin
->normal_hints
->height_inc
;
1790 minW
= wwin
->normal_hints
->min_width
;
1791 minH
= wwin
->normal_hints
->min_height
;
1792 maxW
= wwin
->normal_hints
->max_width
;
1793 maxH
= wwin
->normal_hints
->max_height
;
1794 if (wwin
->normal_hints
->flags
& PAspect
) {
1795 minAX
= wwin
->normal_hints
->min_aspect
.x
;
1796 minAY
= wwin
->normal_hints
->min_aspect
.y
;
1797 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
1798 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
1812 /* aspect ratio code borrowed from olwm */
1814 /* adjust max aspect ratio */
1815 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
1816 if (maxAX
> maxAY
) {
1817 height
= (width
* maxAY
) / maxAX
;
1818 if (height
> maxH
) {
1820 width
= (height
* maxAX
) / maxAY
;
1823 width
= (height
* maxAX
) / maxAY
;
1826 height
= (width
* maxAY
) / maxAX
;
1831 /* adjust min aspect ratio */
1832 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
1833 if (minAX
> minAY
) {
1834 height
= (width
* minAY
) / minAX
;
1835 if (height
< minH
) {
1837 width
= (height
* minAX
) / minAY
;
1840 width
= (height
* minAX
) / minAY
;
1843 height
= (width
* minAY
) / minAX
;
1850 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
1852 width
= (((width
- minW
) / winc
) * winc
) + minW
;
1856 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
1858 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
1861 /* broken stupid apps may cause preposterous values for these.. */
1870 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1872 WScreen
*scr
= wwin
->screen_ptr
;
1876 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1877 || workspace
== wwin
->frame
->workspace
)
1880 if (workspace
!= scr
->current_workspace
) {
1881 /* Sent to other workspace. Unmap window */
1882 if ((wwin
->flags
.mapped
1883 || wwin
->flags
.shaded
1884 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
1885 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
1887 wapp
= wApplicationOf(wwin
->main_window
);
1889 wapp
->last_workspace
= workspace
;
1891 if (wwin
->flags
.miniaturized
) {
1893 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1894 wwin
->icon
->mapped
= 0;
1898 wSetFocusTo(scr
, NULL
);
1902 /* brought to current workspace. Map window */
1903 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
1905 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1906 wwin
->icon
->mapped
= 1;
1908 } else if (!wwin
->flags
.mapped
&&
1909 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1913 if (!IS_OMNIPRESENT(wwin
)) {
1914 wwin
->frame
->workspace
= workspace
;
1915 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1918 wGNOMEUpdateClientStateHint(wwin
, True
);
1921 wKWMUpdateClientWorkspace(wwin
);
1922 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1931 wWindowSynthConfigureNotify(WWindow
*wwin
)
1935 sevent
.type
= ConfigureNotify
;
1936 sevent
.xconfigure
.display
= dpy
;
1937 sevent
.xconfigure
.event
= wwin
->client_win
;
1938 sevent
.xconfigure
.window
= wwin
->client_win
;
1940 sevent
.xconfigure
.x
= wwin
->client
.x
;
1941 sevent
.xconfigure
.y
= wwin
->client
.y
;
1942 sevent
.xconfigure
.width
= wwin
->client
.width
;
1943 sevent
.xconfigure
.height
= wwin
->client
.height
;
1945 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1946 if (WFLAGP(wwin
, no_titlebar
))
1947 sevent
.xconfigure
.above
= None
;
1949 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1951 sevent
.xconfigure
.override_redirect
= False
;
1952 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1954 wKWMSendEventMessage(wwin
, WKWMChangedClient
);
1961 *----------------------------------------------------------------------
1962 * wWindowConfigure--
1963 * Configures the frame, decorations and client window to the
1964 * specified geometry. The geometry is not checked for validity,
1965 * wWindowConstrainSize() must be used for that.
1966 * The size parameters are for the client window, but the position is
1968 * The client window receives a ConfigureNotify event, according
1969 * to what ICCCM says.
1975 * Window size and position are changed and client window receives
1976 * a ConfigureNotify event.
1977 *----------------------------------------------------------------------
1980 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1982 int req_x
, req_y
; /* new position of the frame */
1983 int req_width
, req_height
; /* new size of the client */
1985 int synth_notify
= False
;
1988 resize
= (req_width
!=wwin
->client
.width
1989 || req_height
!=wwin
->client
.height
);
1991 * if the window is being moved but not resized then
1992 * send a synthetic ConfigureNotify
1994 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1995 synth_notify
= True
;
1998 if (WFLAGP(wwin
, dont_move_off
))
1999 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2000 req_width
, req_height
);
2002 if (req_width
< MIN_WINDOW_SIZE
)
2003 req_width
= MIN_WINDOW_SIZE
;
2004 if (req_height
< MIN_WINDOW_SIZE
)
2005 req_height
= MIN_WINDOW_SIZE
;
2007 /* If growing, resize inner part before frame,
2008 * if shrinking, resize frame before.
2009 * This will prevent the frame (that can have a different color)
2010 * to be exposed, causing flicker */
2011 if (req_height
> wwin
->frame
->core
->height
2012 || req_width
> wwin
->frame
->core
->width
)
2013 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2015 if (wwin
->flags
.shaded
) {
2016 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2017 req_width
, wwin
->frame
->core
->height
);
2018 wwin
->old_geometry
.height
= req_height
;
2022 h
= req_height
+ wwin
->frame
->top_width
2023 + wwin
->frame
->bottom_width
;
2025 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2028 if (!(req_height
> wwin
->frame
->core
->height
2029 || req_width
> wwin
->frame
->core
->width
))
2030 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2032 wwin
->client
.x
= req_x
;
2033 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2034 wwin
->client
.width
= req_width
;
2035 wwin
->client
.height
= req_height
;
2037 wwin
->client
.x
= req_x
;
2038 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2040 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2042 wwin
->frame_x
= req_x
;
2043 wwin
->frame_y
= req_y
;
2044 if (!WFLAGP(wwin
, no_border
)) {
2045 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2046 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2050 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2051 wWindowSetShape(wwin
);
2056 wWindowSynthConfigureNotify(wwin
);
2062 wWindowMove(wwin
, req_x
, req_y
)
2064 int req_x
, req_y
; /* new position of the frame */
2066 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2067 int synth_notify
= False
;
2069 /* Send a synthetic ConfigureNotify event for every window movement. */
2070 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2071 synth_notify
= True
;
2074 /* A single synthetic ConfigureNotify event is sent at the end of
2075 * a completed (opaque) movement in moveres.c */
2078 if (WFLAGP(wwin
, dont_move_off
))
2079 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2080 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2082 wwin
->client
.x
= req_x
;
2083 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2084 if (!WFLAGP(wwin
, no_border
)) {
2085 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2086 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2089 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2091 wwin
->frame_x
= req_x
;
2092 wwin
->frame_y
= req_y
;
2094 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2096 wWindowSynthConfigureNotify(wwin
);
2102 wWindowUpdateButtonImages(WWindow
*wwin
)
2104 WScreen
*scr
= wwin
->screen_ptr
;
2105 Pixmap pixmap
, mask
;
2106 WFrameWindow
*fwin
= wwin
->frame
;
2108 if (WFLAGP(wwin
, no_titlebar
))
2111 /* miniaturize button */
2113 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2114 if (wwin
->wm_gnustep_attr
2115 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2116 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2118 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2119 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2124 if (fwin
->lbutton_image
2125 && (fwin
->lbutton_image
->image
!= pixmap
2126 || fwin
->lbutton_image
->mask
!= mask
)) {
2127 wPixmapDestroy(fwin
->lbutton_image
);
2128 fwin
->lbutton_image
= NULL
;
2131 if (!fwin
->lbutton_image
) {
2132 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2133 fwin
->lbutton_image
->client_owned
= 1;
2134 fwin
->lbutton_image
->client_owned_mask
= 1;
2137 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2138 wPixmapDestroy(fwin
->lbutton_image
);
2140 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2144 #ifdef XKB_BUTTON_HINT
2145 if (!WFLAGP(wwin
, no_language_button
)) {
2146 if (fwin
->languagebutton_image
&&
2147 !fwin
->languagebutton_image
->shared
) {
2148 wPixmapDestroy(fwin
->languagebutton_image
);
2150 fwin
->languagebutton_image
=
2151 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2157 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2158 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2160 if (!WFLAGP(wwin
, no_close_button
)) {
2161 if (wwin
->wm_gnustep_attr
2162 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2163 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2165 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2166 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2170 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2171 || fwin
->rbutton_image
->mask
!= mask
)) {
2172 wPixmapDestroy(fwin
->rbutton_image
);
2173 fwin
->rbutton_image
= NULL
;
2176 if (!fwin
->rbutton_image
) {
2177 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2178 fwin
->rbutton_image
->client_owned
= 1;
2179 fwin
->rbutton_image
->client_owned_mask
= 1;
2182 } else if (WFLAGP(wwin
, kill_close
)) {
2184 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2185 wPixmapDestroy(fwin
->rbutton_image
);
2187 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2189 } else if (MGFLAGP(wwin
, broken_close
)) {
2191 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2192 wPixmapDestroy(fwin
->rbutton_image
);
2194 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2198 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2199 wPixmapDestroy(fwin
->rbutton_image
);
2201 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2205 /* force buttons to be redrawn */
2206 fwin
->flags
.need_texture_change
= 1;
2207 wFrameWindowPaint(fwin
);
2212 *---------------------------------------------------------------------------
2213 * wWindowConfigureBorders--
2214 * Update window border configuration according to attribute flags.
2216 *---------------------------------------------------------------------------
2219 wWindowConfigureBorders(WWindow
*wwin
)
2225 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2226 #ifdef XKB_BUTTON_HINT
2227 flags
|= WFF_LANGUAGE_BUTTON
;
2229 if (!WFLAGP(wwin
, no_titlebar
))
2230 flags
|= WFF_TITLEBAR
;
2231 if (!WFLAGP(wwin
, no_resizebar
))
2232 flags
|= WFF_RESIZEBAR
;
2233 if (!WFLAGP(wwin
, no_border
))
2234 flags
|= WFF_BORDER
;
2235 if (wwin
->flags
.shaded
)
2236 flags
|= WFF_IS_SHADED
;
2238 oldh
= wwin
->frame
->top_width
;
2239 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2240 if (oldh
!= wwin
->frame
->top_width
) {
2241 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2243 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2244 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2245 wwin
->client
.width
, wwin
->client
.height
);
2249 if (!WFLAGP(wwin
, no_miniaturize_button
)
2250 && wwin
->frame
->flags
.hide_left_button
)
2251 flags
|= WFF_LEFT_BUTTON
;
2253 #ifdef XKB_BUTTON_HINT
2254 if (!WFLAGP(wwin
, no_language_button
)
2255 && wwin
->frame
->flags
.hide_language_button
)
2256 flags
|= WFF_LANGUAGE_BUTTON
;
2259 if (!WFLAGP(wwin
, no_close_button
)
2260 && wwin
->frame
->flags
.hide_right_button
)
2261 flags
|= WFF_RIGHT_BUTTON
;
2264 wWindowUpdateButtonImages(wwin
);
2265 wFrameWindowShowButton(wwin
->frame
, flags
);
2269 if (WFLAGP(wwin
, no_miniaturize_button
)
2270 && !wwin
->frame
->flags
.hide_left_button
)
2271 flags
|= WFF_LEFT_BUTTON
;
2273 #ifdef XKB_BUTTON_HINT
2274 if (WFLAGP(wwin
, no_language_button
)
2275 && !wwin
->frame
->flags
.hide_language_button
)
2276 flags
|= WFF_LANGUAGE_BUTTON
;
2279 if (WFLAGP(wwin
, no_close_button
)
2280 && !wwin
->frame
->flags
.hide_right_button
)
2281 flags
|= WFF_RIGHT_BUTTON
;
2284 wFrameWindowHideButton(wwin
->frame
, flags
);
2287 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2288 wWindowSetShape(wwin
);
2296 wWindowSaveState(WWindow
*wwin
)
2301 memset(data
, 0, sizeof(CARD32
)*10);
2302 data
[0] = wwin
->frame
->workspace
;
2303 data
[1] = wwin
->flags
.miniaturized
;
2304 data
[2] = wwin
->flags
.shaded
;
2305 data
[3] = wwin
->flags
.hidden
;
2306 data
[4] = wwin
->flags
.maximized
;
2307 if (wwin
->flags
.maximized
== 0) {
2308 data
[5] = wwin
->frame_x
;
2309 data
[6] = wwin
->frame_y
;
2310 data
[7] = wwin
->frame
->core
->width
;
2311 data
[8] = wwin
->frame
->core
->height
;
2313 data
[5] = wwin
->old_geometry
.x
;
2314 data
[6] = wwin
->old_geometry
.y
;
2315 data
[7] = wwin
->old_geometry
.width
;
2316 data
[8] = wwin
->old_geometry
.height
;
2319 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2320 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2321 WMCountInBag(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2324 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2325 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2326 (unsigned char *)data
, 10);
2331 getSavedState(Window window
, WSavedState
**state
)
2335 unsigned long nitems_ret
;
2336 unsigned long bytes_after_ret
;
2339 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2340 True
, _XA_WINDOWMAKER_STATE
,
2341 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2342 (unsigned char **)&data
)!=Success
|| !data
)
2345 *state
= malloc(sizeof(WSavedState
));
2348 (*state
)->workspace
= data
[0];
2349 (*state
)->miniaturized
= data
[1];
2350 (*state
)->shaded
= data
[2];
2351 (*state
)->hidden
= data
[3];
2352 (*state
)->maximized
= data
[4];
2353 (*state
)->x
= data
[5];
2354 (*state
)->y
= data
[6];
2355 (*state
)->w
= data
[7];
2356 (*state
)->h
= data
[8];
2357 (*state
)->window_shortcuts
= data
[9];
2361 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2370 wWindowClearShape(WWindow
*wwin
)
2372 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2373 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2378 wWindowSetShape(WWindow
*wwin
)
2382 #ifdef OPTIMIZE_SHAPE
2387 /* only shape is the client's */
2388 if (WFLAGP(wwin
, no_titlebar
) && WFLAGP(wwin
, no_resizebar
)) {
2392 /* Get array of rectangles describing the shape mask */
2393 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2399 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2405 /* insert our decoration rectangles in the rect list */
2406 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2409 if (!WFLAGP(wwin
, no_titlebar
)) {
2411 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2412 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2413 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2416 if (!WFLAGP(wwin
, no_resizebar
)) {
2418 urec
[count
].y
= wwin
->frame
->core
->height
2419 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2420 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2421 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2425 /* shape our frame window */
2426 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2427 0, wwin
->frame
->top_width
, urec
, count
,
2428 ShapeSet
, Unsorted
);
2434 #endif /* OPTIMIZE_SHAPE */
2436 if (!WFLAGP(wwin
, no_titlebar
)) {
2439 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2440 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2443 if (!WFLAGP(wwin
, no_resizebar
)) {
2445 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2446 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2447 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2451 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2452 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2454 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2455 0, wwin
->frame
->top_width
, wwin
->client_win
,
2456 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2461 /* ====================================================================== */
2464 getFocusMode(WWindow
*wwin
)
2468 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2469 if (wwin
->wm_hints
->input
== True
) {
2470 if (wwin
->protocols
.TAKE_FOCUS
)
2471 mode
= WFM_LOCALLY_ACTIVE
;
2475 if (wwin
->protocols
.TAKE_FOCUS
)
2476 mode
= WFM_GLOBALLY_ACTIVE
;
2478 mode
= WFM_NO_INPUT
;
2488 wWindowSetKeyGrabs(WWindow
*wwin
)
2493 for (i
=0; i
<WKBD_LAST
; i
++) {
2494 key
= &wKeyBindings
[i
];
2496 if (key
->keycode
==0)
2498 if (key
->modifier
!=AnyModifier
) {
2499 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2500 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2502 /* Also grab all modifier combinations possible that include,
2503 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2504 * work even if the NumLock/ScrollLock key is on.
2506 wHackedGrabKey(key
->keycode
, key
->modifier
,
2507 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2511 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2512 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2516 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2523 wWindowResetMouseGrabs(WWindow
*wwin
)
2525 /* Mouse grabs can't be done on the client window because of
2526 * ICCCM and because clients that try to do the same will crash.
2528 * But there is a problem wich makes tbar buttons of unfocused
2529 * windows not usable as the click goes to the frame window instead
2530 * of the button itself. Must figure a way to fix that.
2533 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2535 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2536 /* grabs for Meta+drag */
2537 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2538 True
, ButtonPressMask
, GrabModeSync
,
2539 GrabModeAsync
, None
, None
);
2542 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2543 && !wwin
->flags
.is_gnustep
) {
2544 /* the passive grabs to focus the window */
2545 /* if (wPreferences.focus_mode == WKF_CLICK) */
2546 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2547 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2555 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2557 if (attr
->flags
& GSExtraFlagsAttr
) {
2558 if (MGFLAGP(wwin
, broken_close
) !=
2559 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2560 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2561 wWindowUpdateButtonImages(wwin
);
2568 wWindowAddSavedState(char *instance
, char *class, char *command
,
2569 pid_t pid
, WSavedState
*state
)
2571 WWindowState
*wstate
;
2573 wstate
= malloc(sizeof(WWindowState
));
2577 memset(wstate
, 0, sizeof(WWindowState
));
2580 wstate
->instance
= wstrdup(instance
);
2582 wstate
->class = wstrdup(class);
2584 wstate
->command
= wstrdup(command
);
2585 wstate
->state
= state
;
2587 wstate
->next
= windowState
;
2588 windowState
= wstate
;
2591 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2599 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2603 wWindowGetSavedState(Window win
)
2605 char *instance
, *class, *command
=NULL
;
2606 WWindowState
*wstate
= windowState
;
2613 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2615 command
= wtokenjoin(argv
, argc
);
2616 XFreeStringList(argv
);
2621 if (PropGetWMClass(win
, &class, &instance
)) {
2623 if (SAME(instance
, wstate
->instance
) &&
2624 SAME(class, wstate
->class) &&
2625 SAME(command
, wstate
->command
)) {
2628 wstate
= wstate
->next
;
2635 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2639 if (command
) wfree(command
);
2640 if (instance
) XFree(instance
);
2641 if (class) XFree(class);
2648 wWindowDeleteSavedState(WMagicNumber id
)
2650 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2652 if (!wstate
|| !windowState
)
2657 windowState
= wstate
->next
;
2659 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2660 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2662 if (wstate
->instance
) wfree(wstate
->instance
);
2663 if (wstate
->class) wfree(wstate
->class);
2664 if (wstate
->command
) wfree(wstate
->command
);
2665 wfree(wstate
->state
);
2669 if (tmp
->next
==wstate
) {
2670 tmp
->next
=wstate
->next
;
2672 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2673 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2675 if (wstate
->instance
) wfree(wstate
->instance
);
2676 if (wstate
->class) wfree(wstate
->class);
2677 if (wstate
->command
) wfree(wstate
->command
);
2678 wfree(wstate
->state
);
2689 wWindowDeleteSavedStatesForPID(pid_t pid
)
2691 WWindowState
*tmp
, *wstate
;
2697 if (tmp
->pid
== pid
) {
2698 wstate
= windowState
;
2699 windowState
= tmp
->next
;
2701 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2702 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2704 if (wstate
->instance
) wfree(wstate
->instance
);
2705 if (wstate
->class) wfree(wstate
->class);
2706 if (wstate
->command
) wfree(wstate
->command
);
2707 wfree(wstate
->state
);
2711 if (tmp
->next
->pid
==pid
) {
2713 tmp
->next
= wstate
->next
;
2715 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2716 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2718 if (wstate
->instance
) wfree(wstate
->instance
);
2719 if (wstate
->class) wfree(wstate
->class);
2720 if (wstate
->command
) wfree(wstate
->command
);
2721 wfree(wstate
->state
);
2731 /* ====================================================================== */
2734 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2736 WWindow
*wwin
= data
;
2738 #ifndef NUMLOCK_HACK
2739 if ((event
->xbutton
.state
& ValidModMask
)
2740 != (event
->xbutton
.state
& ~LockMask
)) {
2741 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2742 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2746 event
->xbutton
.state
&= ValidModMask
;
2748 CloseWindowMenu(wwin
->screen_ptr
);
2750 if (wPreferences
.focus_mode
==WKF_CLICK
2751 && !(event
->xbutton
.state
&ControlMask
)
2752 && !WFLAGP(wwin
, no_focusable
)) {
2753 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2756 if (event
->xbutton
.button
== Button1
)
2757 wRaiseFrame(wwin
->frame
->core
);
2759 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2760 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2761 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2762 GrabModeAsync
, GrabModeAsync
, None
,
2763 None
, CurrentTime
)!=GrabSuccess
) {
2765 wwarning("pointer grab failed for window move");
2771 if (event
->xbutton
.state
& MOD_MASK
) {
2772 /* move the window */
2773 wMouseMoveWindow(wwin
, event
);
2774 XUngrabPointer(dpy
, CurrentTime
);
2776 wMouseResizeWindow(wwin
, event
);
2777 XUngrabPointer(dpy
, CurrentTime
);
2784 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2786 WWindow
*wwin
= data
;
2788 event
->xbutton
.state
&= ValidModMask
;
2790 if (event
->xbutton
.button
==Button1
) {
2791 if (event
->xbutton
.state
== 0) {
2792 if (!WFLAGP(wwin
, no_shadeable
)) {
2794 if (wwin
->flags
.shaded
)
2795 wUnshadeWindow(wwin
);
2802 if (event
->xbutton
.state
& ControlMask
)
2803 dir
|= MAX_VERTICAL
;
2805 if (event
->xbutton
.state
& ShiftMask
) {
2806 dir
|= MAX_HORIZONTAL
;
2807 if (!(event
->xbutton
.state
& ControlMask
))
2808 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2811 /* maximize window */
2812 if (dir
!=0 && !WFLAGP(wwin
, no_resizable
)) {
2813 int ndir
= dir
^ wwin
->flags
.maximized
;
2814 if (wwin
->flags
.maximized
!= 0)
2815 wUnmaximizeWindow(wwin
);
2817 wMaximizeWindow(wwin
, ndir
);
2820 } else if (event
->xbutton
.button
==Button3
) {
2821 if (event
->xbutton
.state
& MOD_MASK
) {
2822 wHideOtherApplications(wwin
);
2824 } else if (event
->xbutton
.button
==Button2
) {
2825 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2831 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2833 WWindow
*wwin
= desc
->parent
;
2835 event
->xbutton
.state
&= ValidModMask
;
2837 CloseWindowMenu(wwin
->screen_ptr
);
2839 if (/*wPreferences.focus_mode==WKF_CLICK
2840 &&*/ !(event
->xbutton
.state
&ControlMask
)
2841 && !WFLAGP(wwin
, no_focusable
)) {
2842 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2844 if (event
->xbutton
.button
== Button1
) {
2845 wRaiseFrame(wwin
->frame
->core
);
2848 if (event
->xbutton
.state
& MOD_MASK
) {
2849 /* move the window */
2850 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2851 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2852 GrabModeAsync
, GrabModeAsync
, None
,
2853 None
, CurrentTime
)!=GrabSuccess
) {
2855 wwarning("pointer grab failed for window move");
2859 if (event
->xbutton
.button
== Button3
&& !WFLAGP(wwin
, no_resizable
))
2860 wMouseResizeWindow(wwin
, event
);
2862 wMouseMoveWindow(wwin
, event
);
2863 XUngrabPointer(dpy
, CurrentTime
);
2869 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2871 WWindow
*wwin
= (WWindow
*)data
;
2873 #ifndef NUMLOCK_HACK
2874 if ((event
->xbutton
.state
& ValidModMask
)
2875 != (event
->xbutton
.state
& ~LockMask
)) {
2876 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2877 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2880 event
->xbutton
.state
&= ValidModMask
;
2882 CloseWindowMenu(wwin
->screen_ptr
);
2884 if (wPreferences
.focus_mode
==WKF_CLICK
2885 && !(event
->xbutton
.state
&ControlMask
)
2886 && !WFLAGP(wwin
, no_focusable
)) {
2887 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2890 if (event
->xbutton
.button
== Button1
2891 || event
->xbutton
.button
== Button2
) {
2893 if (event
->xbutton
.button
== Button1
) {
2894 if (event
->xbutton
.state
& MOD_MASK
) {
2895 wLowerFrame(wwin
->frame
->core
);
2897 wRaiseFrame(wwin
->frame
->core
);
2900 if ((event
->xbutton
.state
& ShiftMask
)
2901 && !(event
->xbutton
.state
& ControlMask
)) {
2902 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2905 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2906 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2907 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2908 GrabModeAsync
, GrabModeAsync
, None
,
2909 None
, CurrentTime
)!=GrabSuccess
) {
2911 wwarning("pointer grab failed for window move");
2916 /* move the window */
2917 wMouseMoveWindow(wwin
, event
);
2919 XUngrabPointer(dpy
, CurrentTime
);
2920 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2921 && !wwin
->flags
.internal_window
2922 && !WCHECK_STATE(WSTATE_MODAL
)) {
2923 WObjDescriptor
*desc
;
2925 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2926 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2927 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2928 GrabModeAsync
, GrabModeAsync
, None
,
2929 None
, CurrentTime
)!=GrabSuccess
) {
2931 wwarning("pointer grab failed for window move");
2936 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2937 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2939 /* allow drag select */
2940 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2941 event
->xany
.send_event
= True
;
2942 (*desc
->handle_mousedown
)(desc
, event
);
2944 XUngrabPointer(dpy
, CurrentTime
);
2951 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2953 WWindow
*wwin
= data
;
2955 event
->xbutton
.state
&= ValidModMask
;
2957 CloseWindowMenu(wwin
->screen_ptr
);
2959 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2962 /* if control-click, kill the client */
2963 if (event
->xbutton
.state
& ControlMask
) {
2967 if (wwin
->flags
.olwm_push_pin_out
) {
2969 wwin
->flags
.olwm_push_pin_out
= 0;
2971 wOLWMChangePushpinState(wwin
, True
);
2973 wFrameWindowUpdatePushButton(wwin
->frame
, False
);
2978 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2979 /* send delete message */
2980 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2987 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2989 WWindow
*wwin
= data
;
2991 CloseWindowMenu(wwin
->screen_ptr
);
2993 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
2996 /* send delete message */
2997 if (wwin
->protocols
.DELETE_WINDOW
) {
2998 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3005 #ifdef XKB_BUTTON_HINT
3007 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3009 WWindow
*wwin
= data
;
3010 WFrameWindow
*fwin
= wwin
->frame
;
3011 WScreen
*scr
= fwin
->screen_ptr
;
3012 XkbStateRec staterec
;
3015 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3017 tl
= wwin
->frame
->languagemode
;
3018 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3019 wwin
->frame
->last_languagemode
= tl
;
3020 wSetFocusTo(scr
, wwin
);
3021 wwin
->frame
->languagebutton_image
=
3022 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3023 wwin
->frame
->languagemode
];
3024 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3025 if (event
->xbutton
.button
== Button3
)
3027 wRaiseFrame(fwin
->core
);
3033 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3035 WWindow
*wwin
= data
;
3037 event
->xbutton
.state
&= ValidModMask
;
3039 CloseWindowMenu(wwin
->screen_ptr
);
3041 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3044 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3045 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3049 if ((event
->xbutton
.state
& ControlMask
) ||
3050 (event
->xbutton
.button
== Button3
)) {
3052 wapp
= wApplicationOf(wwin
->main_window
);
3053 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3054 wHideApplication(wapp
);
3055 } else if (event
->xbutton
.state
==0) {
3056 wIconifyWindow(wwin
);