1 /* window.c - client window managing stuffs
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 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"
66 /****** Global Variables ******/
68 extern WShortKey wKeyBindings
[WKBD_LAST
];
71 extern Bool wShapeSupported
;
75 extern XContext wWinContext
;
78 extern Cursor wCursor
[WCUR_LAST
];
81 extern Atom _XA_WM_DELETE_WINDOW
;
82 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
84 extern Atom _XA_WINDOWMAKER_STATE
;
86 extern WPreferences wPreferences
;
88 #define MOD_MASK wPreferences.modifier_mask
90 extern Time LastTimestamp
;
93 extern void DoWindowBirth(WWindow
*);
97 /***** Local Stuff *****/
100 static WWindowState
*windowState
=NULL
;
104 /* local functions */
105 static FocusMode
getFocusMode(WWindow
*wwin
);
107 static int getSavedState(Window window
, WSavedState
**state
);
109 static void setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
);
114 /* frame window (during window grabs) */
115 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
118 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
119 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
122 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 #ifdef XKB_BUTTON_HINT
125 static void windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
128 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
129 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
131 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
134 /****** Notification Observers ******/
137 appearanceObserver(void *self
, WMNotification
*notif
)
139 WWindow
*wwin
= (WWindow
*)self
;
140 int flags
= (int)WMGetNotificationClientData(notif
);
142 if (!wwin
->frame
|| (!wwin
->frame
->titlebar
&& !wwin
->frame
->resizebar
))
145 if (flags
& WFontSettings
) {
146 wWindowConfigureBorders(wwin
);
147 if(wwin
->flags
.shaded
) {
148 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
149 wwin
->frame
->top_width
- 1);
151 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
152 + wwin
->frame
->top_width
;
153 wWindowSynthConfigureNotify(wwin
);
156 if (flags
& WTextureSettings
) {
157 wwin
->frame
->flags
.need_texture_remake
= 1;
159 if (flags
& (WTextureSettings
| WColorSettings
)) {
160 if (wwin
->frame
->titlebar
)
161 XClearWindow(dpy
, wwin
->frame
->titlebar
->window
);
163 wFrameWindowPaint(wwin
->frame
);
167 /************************************/
170 wWindowFor(Window window
)
172 WObjDescriptor
*desc
;
177 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
180 if (desc
->parent_type
==WCLASS_WINDOW
)
182 else if (desc
->parent_type
==WCLASS_FRAME
) {
183 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
184 if (frame
->flags
.is_client_window_frame
)
197 wwin
= wmalloc(sizeof(WWindow
));
200 memset(wwin
, 0, sizeof(WWindow
));
202 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
203 wwin
->client_descriptor
.parent
= wwin
;
204 wwin
->client_descriptor
.self
= wwin
;
205 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
212 wWindowDestroy(WWindow
*wwin
)
216 if (wwin
->screen_ptr
->cmap_window
== wwin
) {
217 wwin
->screen_ptr
->cmap_window
= NULL
;
220 WMRemoveNotificationObserver(wwin
);
222 wwin
->flags
.destroyed
= 1;
224 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
225 if (!wwin
->screen_ptr
->shortcutWindows
[i
])
228 WMRemoveFromArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
);
230 if (!WMGetArrayItemCount(wwin
->screen_ptr
->shortcutWindows
[i
])) {
231 WMFreeArray(wwin
->screen_ptr
->shortcutWindows
[i
]);
232 wwin
->screen_ptr
->shortcutWindows
[i
] = NULL
;
236 if (wwin
->fake_group
&& wwin
->fake_group
->retainCount
>0) {
237 wwin
->fake_group
->retainCount
--;
238 if (wwin
->fake_group
->retainCount
==0 && wwin
->fake_group
->leader
!=None
) {
239 XDestroyWindow(dpy
, wwin
->fake_group
->leader
);
240 wwin
->fake_group
->leader
= None
;
241 wwin
->fake_group
->origLeader
= None
;
246 if (wwin
->normal_hints
)
247 XFree(wwin
->normal_hints
);
250 XFree(wwin
->wm_hints
);
252 if (wwin
->wm_instance
)
253 XFree(wwin
->wm_instance
);
256 XFree(wwin
->wm_class
);
258 if (wwin
->wm_gnustep_attr
)
259 wfree(wwin
->wm_gnustep_attr
);
261 if (wwin
->cmap_windows
)
262 XFree(wwin
->cmap_windows
);
264 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
267 wFrameWindowDestroy(wwin
->frame
);
270 RemoveFromStackList(wwin
->icon
->core
);
271 wIconDestroy(wwin
->icon
);
272 if (wPreferences
.auto_arrange_icons
)
273 wArrangeIcons(wwin
->screen_ptr
, True
);
277 if (wwin
->net_icon_image
)
278 RReleaseImage(wwin
->net_icon_image
);
286 setupGNUstepHints(WWindow
*wwin
, GNUstepWMAttributes
*gs_hints
)
288 if (gs_hints
->flags
& GSWindowStyleAttr
) {
289 if (gs_hints
->window_style
== WMBorderlessWindowMask
) {
290 wwin
->client_flags
.no_border
= 1;
291 wwin
->client_flags
.no_titlebar
= 1;
292 wwin
->client_flags
.no_closable
= 1;
293 wwin
->client_flags
.no_miniaturizable
= 1;
294 wwin
->client_flags
.no_resizable
= 1;
295 wwin
->client_flags
.no_close_button
= 1;
296 wwin
->client_flags
.no_miniaturize_button
= 1;
297 wwin
->client_flags
.no_resizebar
= 1;
299 wwin
->client_flags
.no_close_button
=
300 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
302 wwin
->client_flags
.no_closable
=
303 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
305 wwin
->client_flags
.no_miniaturize_button
=
306 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
308 wwin
->client_flags
.no_miniaturizable
=
309 wwin
->client_flags
.no_miniaturize_button
;
311 wwin
->client_flags
.no_resizebar
=
312 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
314 wwin
->client_flags
.no_resizable
= wwin
->client_flags
.no_resizebar
;
316 /* these attributes supposedly imply in the existence
318 if (gs_hints
->window_style
& (WMResizableWindowMask
|
319 WMClosableWindowMask
|
320 WMMiniaturizableWindowMask
)) {
321 wwin
->client_flags
.no_titlebar
= 0;
323 wwin
->client_flags
.no_titlebar
=
324 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
329 /* setup the defaults */
330 wwin
->client_flags
.no_border
= 0;
331 wwin
->client_flags
.no_titlebar
= 0;
332 wwin
->client_flags
.no_closable
= 0;
333 wwin
->client_flags
.no_miniaturizable
= 0;
334 wwin
->client_flags
.no_resizable
= 0;
335 wwin
->client_flags
.no_close_button
= 0;
336 wwin
->client_flags
.no_miniaturize_button
= 0;
337 wwin
->client_flags
.no_resizebar
= 0;
339 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
340 wwin
->client_flags
.no_appicon
= 1;
347 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
348 WWindowAttributes
*mask
)
350 if (wflags
->no_appicon
&& mask
->no_appicon
)
351 wflags
->emulate_appicon
= 0;
353 if (wwin
->main_window
!=None
) {
354 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
355 if (wapp
&& !wapp
->flags
.emulated
)
356 wflags
->emulate_appicon
= 0;
359 if (wwin
->transient_for
!=None
360 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
361 wflags
->emulate_appicon
= 0;
363 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
370 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
372 WScreen
*scr
= wwin
->screen_ptr
;
374 /* sets global default stuff */
375 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
376 &wwin
->client_flags
, NULL
, True
);
378 * Decoration setting is done in this precedence (lower to higher)
379 * - use global default in the resource database
380 * - guess some settings
381 * - use GNUstep/external window attributes
382 * - set hints specified for the app in the resource DB
385 WSETUFLAG(wwin
, broken_close
, 0);
387 if (wwin
->protocols
.DELETE_WINDOW
)
388 WSETUFLAG(wwin
, kill_close
, 0);
390 WSETUFLAG(wwin
, kill_close
, 1);
392 /* transients can't be iconified or maximized */
393 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
394 WSETUFLAG(wwin
, no_miniaturizable
, 1);
395 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
398 /* if the window can't be resized, remove the resizebar */
399 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
400 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
401 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
402 WSETUFLAG(wwin
, no_resizable
, 1);
403 WSETUFLAG(wwin
, no_resizebar
, 1);
406 /* set GNUstep window attributes */
407 if (wwin
->wm_gnustep_attr
) {
408 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
410 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
412 *level
= wwin
->wm_gnustep_attr
->window_level
;
414 * INT_MIN is the only illegal window level.
416 if (*level
== INT_MIN
)
417 *level
= INT_MIN
+ 1;
420 *level
= WMNormalLevel
;
423 int tmp_workspace
= -1;
424 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
430 wMWMCheckClientHints(wwin
);
431 #endif /* MWM_HINTS */
435 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
438 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
439 * have INT_MIN that means that no window level was requested. -Dan
441 if (tmp_level
== INT_MIN
) {
442 if (WFLAGP(wwin
, floating
))
443 *level
= WMFloatingLevel
;
444 else if (WFLAGP(wwin
, sunken
))
445 *level
= WMSunkenLevel
;
447 *level
= WMNormalLevel
;
452 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!= scr
->root_win
) {
453 WWindow
* transientOwner
= wWindowFor(wwin
->transient_for
);
454 if (transientOwner
) {
455 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
456 if (ownerLevel
> *level
) *level
= ownerLevel
;
460 if (tmp_workspace
>= 0) {
461 *workspace
= tmp_workspace
% scr
->workspace_count
;
466 * Set attributes specified only for that window/class.
467 * This might do duplicate work with the 1st wDefaultFillAttributes().
469 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
470 &wwin
->user_flags
, &wwin
->defined_user_flags
,
473 * Sanity checks for attributes that depend on other attributes
475 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
476 wwin
->user_flags
.emulate_appicon
= 0;
478 if (wwin
->main_window
!=None
) {
479 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
480 if (wapp
&& !wapp
->flags
.emulated
)
481 wwin
->user_flags
.emulate_appicon
= 0;
484 if (wwin
->transient_for
!=None
485 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
486 wwin
->user_flags
.emulate_appicon
= 0;
488 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
489 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
490 wwin
->user_flags
.sunken
= 0;
492 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
495 /* windows that have takefocus=False shouldn't take focus at all */
496 if (wwin
->focus_mode
== WFM_NO_INPUT
) {
497 wwin
->client_flags
.no_focusable
= 1;
505 wWindowCanReceiveFocus(WWindow
*wwin
)
507 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
509 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
511 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
519 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
523 w1
= wwin
->frame
->core
->width
;
524 h1
= wwin
->frame
->core
->height
;
525 w2
= obscured
->frame
->core
->width
;
526 h2
= obscured
->frame
->core
->height
;
528 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
529 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
532 if (wwin
->frame_x
+ w1
< obscured
->frame_x
533 || wwin
->frame_y
+ h1
< obscured
->frame_y
534 || wwin
->frame_x
> obscured
->frame_x
+ w2
535 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
544 fixLeaderProperties(WWindow
*wwin
)
546 XClassHint
*classHint
;
547 XWMHints
*hints
, *clientHints
;
548 Window leaders
[2], window
;
549 char **argv
, *command
;
553 classHint
= XAllocClassHint();
554 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
555 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
557 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
562 leaders
[0] = wwin
->client_leader
;
563 leaders
[1] = wwin
->group_id
;
566 command
= GetCommandForWindow(wwin
->client_win
);
568 /* command already set. nothing to do. */
571 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
575 for (i
=0; i
<2; i
++) {
578 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
579 classHint
->res_name
= wwin
->wm_instance
;
580 classHint
->res_class
= wwin
->wm_class
;
581 XSetClassHint(dpy
, window
, classHint
);
583 hints
= XGetWMHints(dpy
, window
);
586 } else if (clientHints
) {
587 /* set window group leader to self */
588 clientHints
->window_group
= window
;
589 clientHints
->flags
|= WindowGroupHint
;
590 XSetWMHints(dpy
, window
, clientHints
);
594 command
= GetCommandForWindow(window
);
596 /* command already set. nothing to do. */
599 XSetCommand(dpy
, window
, argv
, argc
);
616 createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
618 XClassHint
*classHint
;
624 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
626 classHint
= XAllocClassHint();
627 classHint
->res_name
= instance
;
628 classHint
->res_class
= class;
629 XSetClassHint(dpy
, leader
, classHint
);
632 /* inherit these from the original leader if available */
633 hints
= XGetWMHints(dpy
, win
);
635 hints
= XAllocWMHints();
638 /* set window group leader to self */
639 hints
->window_group
= leader
;
640 hints
->flags
|= WindowGroupHint
;
641 XSetWMHints(dpy
, leader
, hints
);
644 if (XGetCommand(dpy
, win
, &argv
, &argc
)!=0 && argc
> 0) {
645 XSetCommand(dpy
, leader
, argv
, argc
);
646 XFreeStringList(argv
);
654 matchIdentifier(void *item
, void *cdata
)
656 return (strcmp(((WFakeGroupLeader
*)item
)->identifier
, (char*)cdata
)==0);
661 *----------------------------------------------------------------
663 * reparents the window and allocates a descriptor for it.
664 * Window manager hints and other hints are fetched to configure
665 * the window decoration attributes and others. User preferences
666 * for the window are used if available, to configure window
667 * decorations and some behaviour.
668 * If in startup, windows that are override redirect,
669 * unmapped and never were managed and are Withdrawn are not
673 * the new window descriptor
676 * The window is reparented and appropriate notification
677 * is done to the client. Input mask for the window is setup.
678 * The window descriptor is also associated with various window
679 * contexts and inserted in the head of the window list.
680 * Event handler contexts are associated for some objects
681 * (buttons, titlebar and resizebar)
683 *----------------------------------------------------------------
686 wManageWindow(WScreen
*scr
, Window window
)
690 unsigned width
, height
;
691 XWindowAttributes wattribs
;
692 XSetWindowAttributes attribs
;
693 WWindowState
*win_state
;
694 WWindow
*transientOwner
= NULL
;
700 Bool withdraw
= False
;
704 /* XGrabServer(dpy); */
706 /* make sure the window is still there */
707 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
712 /* if it's an override-redirect, ignore it */
713 if (wattribs
.override_redirect
) {
718 wm_state
= PropGetWindowState(window
);
720 /* if it's startup and the window is unmapped, don't manage it */
721 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
726 wwin
= wWindowCreate();
728 title
= wNETWMGetWindowName(window
);
730 wwin
->flags
.net_has_title
= 1;
731 if (!title
&& !wFetchName(dpy
, window
, &title
))
734 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
737 printf("managing window %x\n", (unsigned)window
);
741 if (wShapeSupported
) {
746 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
747 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
748 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
749 wwin
->flags
.shaped
= b_shaped
;
754 *--------------------------------------------------
756 * Get hints and other information in properties
758 *--------------------------------------------------
760 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
762 /* setup descriptor */
763 wwin
->client_win
= window
;
764 wwin
->screen_ptr
= scr
;
766 wwin
->old_border_width
= wattribs
.border_width
;
768 wwin
->event_mask
= CLIENT_EVENTS
;
769 attribs
.event_mask
= CLIENT_EVENTS
;
770 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
771 attribs
.save_under
= False
;
772 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
773 |CWSaveUnder
, &attribs
);
774 XSetWindowBorderWidth(dpy
, window
, 0);
776 /* get hints from GNUstep app */
777 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
778 wwin
->flags
.is_gnustep
= 1;
780 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
781 wwin
->wm_gnustep_attr
= NULL
;
784 wwin
->client_leader
= PropGetClientLeader(window
);
785 if (wwin
->client_leader
!=None
)
786 wwin
->main_window
= wwin
->client_leader
;
788 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
790 if (wwin
->wm_hints
) {
791 if (wwin
->wm_hints
->flags
& StateHint
) {
793 if (wwin
->wm_hints
->initial_state
== IconicState
) {
795 wwin
->flags
.miniaturized
= 1;
797 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
803 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
804 wwin
->group_id
= wwin
->wm_hints
->window_group
;
805 /* window_group has priority over CLIENT_LEADER */
806 wwin
->main_window
= wwin
->group_id
;
808 wwin
->group_id
= None
;
811 if (wwin
->wm_hints
->flags
& UrgencyHint
)
812 wwin
->flags
.urgent
= 1;
814 wwin
->group_id
= None
;
817 PropGetProtocols(window
, &wwin
->protocols
);
819 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
820 wwin
->transient_for
= None
;
822 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
823 wwin
->transient_for
= scr
->root_win
;
825 transientOwner
= wWindowFor(wwin
->transient_for
);
826 if (transientOwner
&& transientOwner
->main_window
!=None
) {
827 wwin
->main_window
= transientOwner
->main_window
;
829 wwin->main_window = None;
834 /* guess the focus mode */
835 wwin
->focus_mode
= getFocusMode(wwin
);
837 /* get geometry stuff */
838 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
840 /* printf("wManageWindow: %d %d %d %d\n", x, y, width, height);*/
842 /* get colormap windows */
843 GetColormapWindows(wwin
);
846 *--------------------------------------------------
848 * Setup the decoration/window attributes and
851 *--------------------------------------------------
854 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
856 /* Make broken apps behave as a nice app. */
857 if (WFLAGP(wwin
, emulate_appicon
)) {
858 wwin
->main_window
= wwin
->client_win
;
861 fixLeaderProperties(wwin
);
863 wwin
->orig_main_window
= wwin
->main_window
;
865 if (wwin
->flags
.is_gnustep
) {
866 WSETUFLAG(wwin
, shared_appicon
, 0);
869 if (wwin
->main_window
) {
870 extern Atom _XA_WINDOWMAKER_MENU
;
871 XTextProperty text_prop
;
873 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
,
874 _XA_WINDOWMAKER_MENU
)) {
875 WSETUFLAG(wwin
, shared_appicon
, 0);
879 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
880 char *buffer
, *instance
, *class;
881 WFakeGroupLeader
*fPtr
;
884 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
886 /* // only enter here if PropGetWMClass() succeds */
887 PropGetWMClass(wwin
->main_window
, &class, &instance
);
888 buffer
= StrConcatDot(instance
, class);
890 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void*)buffer
);
891 if (index
!= WANotFound
) {
892 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
893 if (fPtr
->retainCount
== 0) {
894 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
899 if (fPtr
->origLeader
==None
) {
901 if (ADEQUATE(wwin
->group_id
)) {
903 fPtr
->origLeader
= wwin
->group_id
;
904 } else if (ADEQUATE(wwin
->client_leader
)) {
906 fPtr
->origLeader
= wwin
->client_leader
;
907 } else if (ADEQUATE(wwin
->main_window
)) {
909 fPtr
->origLeader
= wwin
->main_window
;
912 if (ADEQUATE(wwin
->main_window
)) {
914 fPtr
->origLeader
= wwin
->main_window
;
918 wwin
->fake_group
= fPtr
;
919 /*wwin->group_id = fPtr->leader;*/
920 wwin
->main_window
= fPtr
->leader
;
923 fPtr
= (WFakeGroupLeader
*)wmalloc(sizeof(WFakeGroupLeader
));
925 fPtr
->identifier
= buffer
;
926 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
928 fPtr
->origLeader
= None
;
929 fPtr
->retainCount
= 1;
931 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
934 if (ADEQUATE(wwin
->group_id
)) {
936 fPtr
->origLeader
= wwin
->group_id
;
937 } else if (ADEQUATE(wwin
->client_leader
)) {
939 fPtr
->origLeader
= wwin
->client_leader
;
940 } else if (ADEQUATE(wwin
->main_window
)) {
942 fPtr
->origLeader
= wwin
->main_window
;
945 if (ADEQUATE(wwin
->main_window
)) {
947 fPtr
->origLeader
= wwin
->main_window
;
950 wwin
->fake_group
= fPtr
;
951 /*wwin->group_id = fPtr->leader;*/
952 wwin
->main_window
= fPtr
->leader
;
964 *------------------------------------------------------------
966 * Setup the initial state of the window
968 *------------------------------------------------------------
971 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
972 wwin
->flags
.miniaturized
= 1;
975 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
)) {
976 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
980 wNETWMCheckInitialClientState(wwin
);
983 /* apply previous state if it exists and we're in startup */
984 if (scr
->flags
.startup
&& wm_state
>= 0) {
986 if (wm_state
== IconicState
) {
988 wwin
->flags
.miniaturized
= 1;
990 } else if (wm_state
== WithdrawnState
) {
996 /* if there is a saved state (from file), restore it */
998 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
999 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
1001 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
1003 if (win_state
&& !withdraw
) {
1005 if (win_state
->state
->hidden
>0)
1006 wwin
->flags
.hidden
= win_state
->state
->hidden
;
1008 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
1009 wwin
->flags
.shaded
= win_state
->state
->shaded
;
1011 if (win_state
->state
->miniaturized
>0 &&
1012 !WFLAGP(wwin
, no_miniaturizable
)) {
1013 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
1016 if (!IS_OMNIPRESENT(wwin
)) {
1017 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
1019 if (w
< 0 || w
>= scr
->workspace_count
) {
1020 workspace
= win_state
->state
->workspace
;
1021 if (workspace
>= scr
->workspace_count
)
1022 workspace
= scr
->current_workspace
;
1027 workspace
= scr
->current_workspace
;
1031 /* if we're restarting, restore saved state (from hints).
1032 * This will overwrite previous */
1034 WSavedState
*wstate
;
1036 if (getSavedState(window
, &wstate
)) {
1037 wwin
->flags
.shaded
= wstate
->shaded
;
1038 wwin
->flags
.hidden
= wstate
->hidden
;
1039 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
1040 wwin
->flags
.maximized
= wstate
->maximized
;
1041 if (wwin
->flags
.maximized
) {
1042 wwin
->old_geometry
.x
= wstate
->x
;
1043 wwin
->old_geometry
.y
= wstate
->y
;
1044 wwin
->old_geometry
.width
= wstate
->w
;
1045 wwin
->old_geometry
.height
= wstate
->h
;
1048 workspace
= wstate
->workspace
;
1053 /* restore window shortcut */
1054 if (wstate
!= NULL
|| win_state
!= NULL
) {
1057 if (win_state
!= NULL
)
1058 mask
= win_state
->state
->window_shortcuts
;
1060 if (wstate
!= NULL
&& mask
== 0)
1061 mask
= wstate
->window_shortcuts
;
1066 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
1067 if (mask
& (1<<i
)) {
1068 if (!scr
->shortcutWindows
[i
])
1069 scr
->shortcutWindows
[i
] = WMCreateArray(4);
1071 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
1076 if (wstate
!= NULL
) {
1081 /* don't let transients start miniaturized if their owners are not */
1082 if (transientOwner
&& !transientOwner
->flags
.miniaturized
1083 && wwin
->flags
.miniaturized
&& !withdraw
) {
1084 wwin
->flags
.miniaturized
= 0;
1086 wwin
->wm_hints
->initial_state
= NormalState
;
1089 /* set workspace on which the window starts */
1090 if (workspace
>= 0) {
1091 if (workspace
> scr
->workspace_count
-1) {
1092 workspace
= workspace
% scr
->workspace_count
;
1097 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
1099 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1104 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1106 workspace
= transientOwner
->frame
->workspace
;
1110 workspace
= scr
->current_workspace
;
1115 /* setup window geometry */
1116 if (win_state
&& win_state
->state
->w
> 0) {
1117 width
= win_state
->state
->w
;
1118 height
= win_state
->state
->h
;
1120 wWindowConstrainSize(wwin
, &width
, &height
);
1122 /* do not ask for window placement if the window is
1123 * transient, during startup, if the initial workspace is another one
1124 * or if the window wants to start iconic.
1125 * If geometry was saved, restore it. */
1127 Bool dontBring
= False
;
1129 if (win_state
&& win_state
->state
->w
> 0) {
1130 x
= win_state
->state
->x
;
1131 y
= win_state
->state
->y
;
1132 } else if ((wwin
->transient_for
==None
1133 || wPreferences
.window_placement
!=WPM_MANUAL
)
1134 && !scr
->flags
.startup
1135 && workspace
== scr
->current_workspace
1136 && !wwin
->flags
.miniaturized
1137 && !wwin
->flags
.maximized
1138 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
1140 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1141 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
1145 x
= transientOwner
->frame_x
+
1146 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
1147 y
= transientOwner
->frame_y
+
1148 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
1151 * limit transient windows to be inside their parent's head
1153 rect
.pos
.x
= transientOwner
->frame_x
;
1154 rect
.pos
.y
= transientOwner
->frame_y
;
1155 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1156 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1158 head
= wGetHeadForRect(scr
, rect
);
1159 rect
= wGetRectForHead(scr
, head
);
1163 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1164 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1168 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1169 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1172 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1174 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1177 } else if (scr
->xine_info
.count
&&
1178 (wwin
->normal_hints
->flags
& PPosition
)) {
1184 * Make spash screens come out in the center of a head
1185 * trouble is that most splashies never get here
1186 * they are managed trough atoms but god knows where.
1187 * Dan, do you know ? -peter
1189 * Most of them are not managed, they have set
1190 * OverrideRedirect, which means we can't do anything about
1194 printf("xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
)/2);
1195 printf("xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
)/2);
1197 if ((unsigned)(x
+ (width
- scr
->scr_width
)/2 + 10) < 20 &&
1198 (unsigned)(y
+ (height
- scr
->scr_height
)/2 + 10) < 20) {
1206 * xinerama checks for: across head and dead space
1210 rect
.size
.width
= width
;
1211 rect
.size
.height
= height
;
1213 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1215 if (flags
& XFLAG_DEAD
)
1218 if (flags
& XFLAG_MULTIPLE
)
1222 switch (reposition
) {
1224 head
= wGetHeadForPointerLocation(scr
);
1225 rect
= wGetRectForHead(scr
, head
);
1227 x
= rect
.pos
.x
+ (x
* rect
.size
.width
)/scr
->scr_width
;
1228 y
= rect
.pos
.y
+ (y
* rect
.size
.height
)/scr
->scr_height
;
1232 rect
= wGetRectForHead(scr
, head
);
1236 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1237 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1241 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1242 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1251 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1252 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1256 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1259 if (wwin
->flags
.urgent
) {
1260 if (!IS_OMNIPRESENT(wwin
))
1261 wwin
->flags
.omnipresent
^= 1;
1265 *--------------------------------------------------
1267 * Create frame, borders and do reparenting
1269 *--------------------------------------------------
1271 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1272 #ifdef XKB_BUTTON_HINT
1273 if (wPreferences
.modelock
)
1274 foo
|= WFF_LANGUAGE_BUTTON
;
1276 if (HAS_TITLEBAR(wwin
))
1277 foo
|= WFF_TITLEBAR
;
1278 if (HAS_RESIZEBAR(wwin
))
1279 foo
|= WFF_RESIZEBAR
;
1280 if (HAS_BORDER(wwin
))
1283 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1284 x
, y
, width
, height
,
1285 &wPreferences
.window_title_clearance
, foo
,
1286 scr
->window_title_texture
,
1287 scr
->resizebar_texture
,
1288 scr
->window_title_color
,
1291 wwin
->frame
->flags
.is_client_window_frame
= 1;
1292 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1294 /* setup button images */
1295 wWindowUpdateButtonImages(wwin
);
1297 /* hide unused buttons */
1299 if (WFLAGP(wwin
, no_close_button
))
1300 foo
|= WFF_RIGHT_BUTTON
;
1301 if (WFLAGP(wwin
, no_miniaturize_button
))
1302 foo
|= WFF_LEFT_BUTTON
;
1303 #ifdef XKB_BUTTON_HINT
1304 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1305 foo
|= WFF_LANGUAGE_BUTTON
;
1308 wFrameWindowHideButton(wwin
->frame
, foo
);
1310 wwin
->frame
->child
= wwin
;
1312 wwin
->frame
->workspace
= workspace
;
1314 wwin
->frame
->on_click_left
= windowIconifyClick
;
1315 #ifdef XKB_BUTTON_HINT
1316 if (wPreferences
.modelock
)
1317 wwin
->frame
->on_click_language
= windowLanguageClick
;
1320 wwin
->frame
->on_click_right
= windowCloseClick
;
1321 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1323 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1324 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1326 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1329 XSelectInput(dpy
, wwin
->client_win
,
1330 wwin
->event_mask
& ~StructureNotifyMask
);
1332 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1333 0, wwin
->frame
->top_width
);
1335 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1341 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1343 /* if gravity is to the south, account for the border sizes */
1345 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1349 * wWindowConfigure() will init the client window's size
1350 * (wwin->client.{width,height}) and all other geometry
1351 * related variables (frame_x,frame_y)
1353 wWindowConfigure(wwin
, x
, y
, width
, height
);
1355 /* to make sure the window receives it's new position after reparenting */
1356 wWindowSynthConfigureNotify(wwin
);
1359 *--------------------------------------------------
1361 * Setup descriptors and save window to internal
1364 *--------------------------------------------------
1367 if (wwin
->main_window
!=None
) {
1371 /* Leader windows do not necessary set themselves as leaders.
1372 * If this is the case, point the leader of this window to
1374 leader
= wWindowFor(wwin
->main_window
);
1375 if (leader
&& leader
->main_window
==None
) {
1376 leader
->main_window
= leader
->client_win
;
1378 app
= wApplicationCreate(wwin
);
1380 app
->last_workspace
= workspace
;
1383 * Do application specific stuff, like setting application
1387 if (wwin
->flags
.hidden
) {
1388 /* if the window was set to hidden because it was hidden
1389 * in a previous incarnation and that state was restored */
1390 app
->flags
.hidden
= 1;
1391 } else if (app
->flags
.hidden
) {
1392 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1393 wwin
->flags
.hidden
= 1;
1395 wUnhideApplication(app
, False
, False
);
1402 /* setup the frame descriptor */
1403 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1404 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1405 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1407 /* don't let windows go away if we die */
1408 XAddToSaveSet(dpy
, window
);
1410 XLowerWindow(dpy
, window
);
1412 /* if window is in this workspace and should be mapped, then map it */
1413 if (!wwin
->flags
.miniaturized
1414 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1415 && !wwin
->flags
.hidden
&& !withdraw
) {
1417 /* The following "if" is to avoid crashing of clients that expect
1418 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1419 * after the return from this function.
1421 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1422 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1424 wClientSetState(wwin
, NormalState
, None
);
1428 /* if not auto focus, then map the window under the currently
1430 #define _WIDTH(w) (w)->frame->core->width
1431 #define _HEIGHT(w) (w)->frame->core->height
1432 if (!wPreferences
.auto_focus
&& scr
->focused_window
1433 && !scr
->flags
.startup
&& !transientOwner
1434 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1435 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1436 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1437 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1438 || wwin
->flags
.maximized
)) {
1439 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1447 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1448 && !scr
->flags
.startup
&&
1449 (wwin
->transient_for
==None
|| wwin
->transient_for
==scr
->root_win
)
1451 * The brain damaged idiotic non-click to focus modes will
1452 * have trouble with this because:
1454 * 1. window is created and mapped by the client
1455 * 2. window is mapped by wmaker in small size
1456 * 3. window is animated to grow to normal size
1457 * 4. this function returns to normal event loop
1458 * 5. eventually, the EnterNotify event that would trigger
1459 * the window focusing (if the mouse is over that window)
1460 * will be processed by wmaker.
1461 * But since this event will be rather delayed
1462 * (step 3 has a large delay) the time when the event ocurred
1463 * and when it is processed, the client that owns that window
1464 * will reject the XSetInputFocus() for it.
1466 && (wPreferences
.focus_mode
==WKF_CLICK
1467 || wPreferences
.auto_focus
)) {
1468 DoWindowBirth(wwin
);
1474 /* setup stacking descriptor */
1475 if (transientOwner
) {
1476 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1478 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1482 if (!scr
->focused_window
) {
1483 /* first window on the list */
1486 scr
->focused_window
= wwin
;
1490 /* add window at beginning of focus window list */
1491 tmp
= scr
->focused_window
;
1499 /* raise is set to true if we un-hid the app when this window was born.
1500 * we raise, else old windows of this app will be above this new one. */
1502 wRaiseFrame(wwin
->frame
->core
);
1505 /* Update name must come after WApplication stuff is done */
1506 wWindowUpdateName(wwin
, title
);
1513 *--------------------------------------------------
1515 * Final preparations before window is ready to go
1517 *--------------------------------------------------
1520 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1523 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1524 && !wwin
->flags
.hidden
) {
1525 if (((transientOwner
&& transientOwner
->flags
.focused
)
1526 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1527 wSetFocusTo(scr
, wwin
);
1529 wWindowResetMouseGrabs(wwin
);
1531 if (!WFLAGP(wwin
, no_bind_keys
)) {
1532 wWindowSetKeyGrabs(wwin
);
1536 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1539 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1543 *------------------------------------------------------------
1544 * Setup Notification Observers
1545 *------------------------------------------------------------
1547 WMAddNotificationObserver(appearanceObserver
, wwin
,
1548 WNWindowAppearanceSettingsChanged
, wwin
);
1552 *--------------------------------------------------
1554 * Cleanup temporary stuff
1556 *--------------------------------------------------
1560 wWindowDeleteSavedState(win_state
);
1562 /* If the window must be withdrawed, then do it now.
1563 * Must do some optimization, 'though */
1565 wwin
->flags
.mapped
= 0;
1566 wClientSetState(wwin
, WithdrawnState
, None
);
1567 wUnmanageWindow(wwin
, True
, False
);
1579 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1580 char *title
, int x
, int y
, int width
, int height
)
1585 wwin
= wWindowCreate();
1587 WMAddNotificationObserver(appearanceObserver
, wwin
,
1588 WNWindowAppearanceSettingsChanged
, wwin
);
1590 wwin
->flags
.internal_window
= 1;
1592 WSETUFLAG(wwin
, omnipresent
, 1);
1593 WSETUFLAG(wwin
, no_shadeable
, 1);
1594 WSETUFLAG(wwin
, no_resizable
, 1);
1595 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1597 wwin
->focus_mode
= WFM_PASSIVE
;
1599 wwin
->client_win
= window
;
1600 wwin
->screen_ptr
= scr
;
1602 wwin
->transient_for
= owner
;
1606 wwin
->client
.width
= width
;
1607 wwin
->client
.height
= height
;
1609 wwin
->frame_x
= wwin
->client
.x
;
1610 wwin
->frame_y
= wwin
->client
.y
;
1613 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1614 foo
|= WFF_TITLEBAR
;
1615 #ifdef XKB_BUTTON_HINT
1616 foo
|= WFF_LANGUAGE_BUTTON
;
1619 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1620 wwin
->frame_x
, wwin
->frame_y
,
1622 &wPreferences
.window_title_clearance
, foo
,
1623 scr
->window_title_texture
,
1624 scr
->resizebar_texture
,
1625 scr
->window_title_color
,
1628 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1630 wwin
->frame
->flags
.is_client_window_frame
= 1;
1631 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1633 wFrameWindowChangeTitle(wwin
->frame
, title
);
1635 /* setup button images */
1636 wWindowUpdateButtonImages(wwin
);
1639 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1641 wwin
->frame
->child
= wwin
;
1643 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1645 #ifdef XKB_BUTTON_HINT
1646 if (wPreferences
.modelock
)
1647 wwin
->frame
->on_click_language
= windowLanguageClick
;
1650 wwin
->frame
->on_click_right
= windowCloseClick
;
1652 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1653 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1655 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1657 wwin
->client
.y
+= wwin
->frame
->top_width
;
1658 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1659 0, wwin
->frame
->top_width
);
1661 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1662 wwin
->client
.width
, wwin
->client
.height
);
1664 /* setup the frame descriptor */
1665 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1666 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1667 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1670 XLowerWindow(dpy
, window
);
1671 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1673 /* setup stacking descriptor */
1674 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
1676 tmp
= wWindowFor(wwin
->transient_for
);
1678 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1680 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1684 if (!scr
->focused_window
) {
1685 /* first window on the list */
1688 scr
->focused_window
= wwin
;
1692 /* add window at beginning of focus window list */
1693 tmp
= scr
->focused_window
;
1701 if (wwin
->flags
.is_gnustep
== 0)
1702 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1704 /* if (wPreferences.auto_focus)*/
1705 wSetFocusTo(scr
, wwin
);
1707 wWindowResetMouseGrabs(wwin
);
1709 wWindowSetKeyGrabs(wwin
);
1716 *----------------------------------------------------------------------
1718 * Removes the frame window from a window and destroys all data
1719 * related to it. The window will be reparented back to the root window
1720 * if restore is True.
1723 * Everything related to the window is destroyed and the window
1724 * is removed from the window lists. Focus is set to the previous on the
1726 *----------------------------------------------------------------------
1729 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1731 WCoreWindow
*frame
= wwin
->frame
->core
;
1732 WWindow
*owner
= NULL
;
1733 WWindow
*newFocusedWindow
= NULL
;
1735 WScreen
*scr
= wwin
->screen_ptr
;
1738 /* First close attribute editor window if open */
1739 if (wwin
->flags
.inspector_open
) {
1740 wCloseInspectorForWindow(wwin
);
1743 /* Close window menu if it's open for this window */
1744 if (wwin
->flags
.menu_open_for_me
) {
1745 CloseWindowMenu(scr
);
1749 if (!wwin
->flags
.internal_window
)
1750 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1752 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1754 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1755 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1758 XUnmapWindow(dpy
, frame
->window
);
1760 XUnmapWindow(dpy
, wwin
->client_win
);
1762 /* deselect window */
1763 wSelectWindow(wwin
, False
);
1765 /* remove all pending events on window */
1766 /* I think this only matters for autoraise */
1767 if (wPreferences
.raise_delay
)
1768 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1772 /* reparent the window back to the root */
1774 wClientRestore(wwin
);
1776 if (wwin
->transient_for
!=scr
->root_win
) {
1777 owner
= wWindowFor(wwin
->transient_for
);
1779 if (!owner
->flags
.semi_focused
) {
1782 owner
->flags
.semi_focused
= 0;
1787 wasFocused
= wwin
->flags
.focused
;
1789 /* remove from window focus list */
1790 if (!wwin
->prev
&& !wwin
->next
) {
1791 /* was the only window */
1792 scr
->focused_window
= NULL
;
1793 newFocusedWindow
= NULL
;
1798 wwin
->prev
->next
= wwin
->next
;
1800 wwin
->next
->prev
= wwin
->prev
;
1802 scr
->focused_window
= wwin
->prev
;
1803 scr
->focused_window
->next
= NULL
;
1806 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1808 /* if in click to focus mode and the window
1809 * was a transient, focus the owner window
1812 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1813 tmp
= wWindowFor(wwin
->transient_for
);
1814 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1818 /* otherwise, focus the next one in the focus list */
1820 tmp
= scr
->focused_window
;
1821 while (tmp
) { /* look for one in the window list first */
1822 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1823 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1827 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1828 tmp
= scr
->focused_window
;
1830 if (!WFLAGP(tmp
, no_focusable
)
1831 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1838 newFocusedWindow
= tmp
;
1840 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1845 /* This is to let the root window get the keyboard input
1846 * if Sloppy focus mode and no other window get focus.
1847 * This way keybindings will not freeze.
1850 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1851 &foo
, &foo
, &foo
, &foo
, &mask
))
1852 tmp
= wWindowFor(win
);
1855 newFocusedWindow
= tmp
;
1857 newFocusedWindow
= NULL
;
1861 if (!wwin
->flags
.internal_window
) {
1862 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1866 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1867 (unsigned)frame
->window
);
1871 if (newFocusedWindow
!= owner
&& owner
) {
1872 if (wwin
->flags
.is_gnustep
== 0)
1873 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1875 wSetFocusTo(scr
, newFocusedWindow
);
1877 wWindowDestroy(wwin
);
1883 wWindowMap(WWindow
*wwin
)
1885 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1886 if (!wwin
->flags
.shaded
) {
1887 /* window will be remapped when getting MapNotify */
1888 XSelectInput(dpy
, wwin
->client_win
,
1889 wwin
->event_mask
& ~StructureNotifyMask
);
1890 XMapWindow(dpy
, wwin
->client_win
);
1891 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1893 wwin
->flags
.mapped
= 1;
1899 wWindowUnmap(WWindow
*wwin
)
1901 wwin
->flags
.mapped
= 0;
1903 /* prevent window withdrawal when getting UnmapNotify */
1904 XSelectInput(dpy
, wwin
->client_win
,
1905 wwin
->event_mask
& ~StructureNotifyMask
);
1906 XUnmapWindow(dpy
, wwin
->client_win
);
1907 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1909 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1915 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1920 #ifdef KEEP_XKB_LOCK_STATUS
1921 if (wPreferences
.modelock
) {
1922 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1924 #endif /* KEEP_XKB_LOCK_STATUS */
1926 wwin
->flags
.semi_focused
= 0;
1928 if (wwin
->flags
.is_gnustep
== 0)
1929 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1931 wwin
->flags
.focused
= 1;
1933 wWindowResetMouseGrabs(wwin
);
1935 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)True
);
1937 if (owin
== wwin
|| !owin
)
1940 nowner
= wWindowFor(wwin
->transient_for
);
1942 /* new window is a transient for the old window */
1943 if (nowner
== owin
) {
1944 owin
->flags
.semi_focused
= 1;
1945 wWindowUnfocus(nowner
);
1949 oowner
= wWindowFor(owin
->transient_for
);
1951 /* new window is owner of old window */
1952 if (wwin
== oowner
) {
1953 wWindowUnfocus(owin
);
1958 wWindowUnfocus(owin
);
1962 /* new window has same owner of old window */
1963 if (oowner
== nowner
) {
1964 /* prevent unfocusing of owner */
1965 oowner
->flags
.semi_focused
= 0;
1966 wWindowUnfocus(owin
);
1967 oowner
->flags
.semi_focused
= 1;
1972 /* nowner != NULL && oowner != nowner */
1973 nowner
->flags
.semi_focused
= 1;
1974 wWindowUnfocus(nowner
);
1975 wWindowUnfocus(owin
);
1980 wWindowUnfocus(WWindow
*wwin
)
1982 CloseWindowMenu(wwin
->screen_ptr
);
1984 if (wwin
->flags
.is_gnustep
== 0)
1985 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1986 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1988 if (wwin
->transient_for
!=None
1989 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1991 owner
= wWindowFor(wwin
->transient_for
);
1992 if (owner
&& owner
->flags
.semi_focused
) {
1993 owner
->flags
.semi_focused
= 0;
1994 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1995 wWindowUnfocus(owner
);
1996 wFrameWindowPaint(owner
->frame
);
2000 wwin
->flags
.focused
= 0;
2002 wWindowResetMouseGrabs(wwin
);
2004 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)False
);
2009 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
2016 wwin
->flags
.wm_name_changed
= 1;
2019 /* the hint was removed */
2020 title
= DEF_WINDOW_TITLE
;
2025 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
2026 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
2033 *----------------------------------------------------------------------
2035 * wWindowConstrainSize--
2036 * Constrains size for the client window, taking the maximal size,
2037 * window resize increments and other size hints into account.
2040 * The closest size to what was given that the client window can
2043 *----------------------------------------------------------------------
2046 wWindowConstrainSize(WWindow
*wwin
, unsigned int *nwidth
, unsigned int *nheight
)
2048 int width
= (int)*nwidth
;
2049 int height
= (int)*nheight
;
2052 int minW
= 1, minH
= 1;
2053 int maxW
= wwin
->screen_ptr
->scr_width
*2;
2054 int maxH
= wwin
->screen_ptr
->scr_height
*2;
2055 int minAX
= -1, minAY
= -1;
2056 int maxAX
= -1, maxAY
= -1;
2060 if (wwin
->normal_hints
) {
2061 winc
= wwin
->normal_hints
->width_inc
;
2062 hinc
= wwin
->normal_hints
->height_inc
;
2063 minW
= wwin
->normal_hints
->min_width
;
2064 minH
= wwin
->normal_hints
->min_height
;
2065 maxW
= wwin
->normal_hints
->max_width
;
2066 maxH
= wwin
->normal_hints
->max_height
;
2067 if (wwin
->normal_hints
->flags
& PAspect
) {
2068 minAX
= wwin
->normal_hints
->min_aspect
.x
;
2069 minAY
= wwin
->normal_hints
->min_aspect
.y
;
2070 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
2071 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
2074 baseW
= wwin
->normal_hints
->base_width
;
2075 baseH
= wwin
->normal_hints
->base_height
;
2088 /* aspect ratio code borrowed from olwm */
2090 /* adjust max aspect ratio */
2091 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
2092 if (maxAX
> maxAY
) {
2093 height
= (width
* maxAY
) / maxAX
;
2094 if (height
> maxH
) {
2096 width
= (height
* maxAX
) / maxAY
;
2099 width
= (height
* maxAX
) / maxAY
;
2102 height
= (width
* maxAY
) / maxAX
;
2107 /* adjust min aspect ratio */
2108 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
2109 if (minAX
> minAY
) {
2110 height
= (width
* minAY
) / minAX
;
2111 if (height
< minH
) {
2113 width
= (height
* minAX
) / minAY
;
2116 width
= (height
* minAX
) / minAY
;
2119 height
= (width
* minAY
) / minAX
;
2126 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
2128 width
= (((width
- minW
) / winc
) * winc
) + minW
;
2132 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
2134 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
2137 /* broken stupid apps may cause preposterous values for these.. */
2146 wWindowCropSize(WWindow
*wwin
, unsigned int maxW
, unsigned int maxH
,
2147 unsigned int *width
, unsigned int *height
)
2149 int baseW
= 0, baseH
= 0;
2150 int winc
= 1, hinc
= 1;
2152 if (wwin
->normal_hints
) {
2153 baseW
= wwin
->normal_hints
->base_width
;
2154 baseH
= wwin
->normal_hints
->base_height
;
2156 winc
= wwin
->normal_hints
->width_inc
;
2157 hinc
= wwin
->normal_hints
->height_inc
;
2161 *width
= maxW
- (maxW
- baseW
) % winc
;
2164 *height
= maxH
- (maxH
- baseH
) % hinc
;
2169 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
2171 WScreen
*scr
= wwin
->screen_ptr
;
2175 if (workspace
>= scr
->workspace_count
|| workspace
< 0
2176 || workspace
== wwin
->frame
->workspace
)
2179 if (workspace
!= scr
->current_workspace
) {
2180 /* Sent to other workspace. Unmap window */
2181 if ((wwin
->flags
.mapped
2182 || wwin
->flags
.shaded
2183 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
2184 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
2186 wapp
= wApplicationOf(wwin
->main_window
);
2188 wapp
->last_workspace
= workspace
;
2190 if (wwin
->flags
.miniaturized
) {
2192 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
2193 wwin
->icon
->mapped
= 0;
2197 wSetFocusTo(scr
, NULL
);
2201 /* brought to current workspace. Map window */
2202 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
2204 XMapWindow(dpy
, wwin
->icon
->core
->window
);
2205 wwin
->icon
->mapped
= 1;
2207 } else if (!wwin
->flags
.mapped
&&
2208 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
2212 if (!IS_OMNIPRESENT(wwin
)) {
2213 int oldWorkspace
= wwin
->frame
->workspace
;
2215 wwin
->frame
->workspace
= workspace
;
2217 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void*)oldWorkspace
);
2227 wWindowSynthConfigureNotify(WWindow
*wwin
)
2231 sevent
.type
= ConfigureNotify
;
2232 sevent
.xconfigure
.display
= dpy
;
2233 sevent
.xconfigure
.event
= wwin
->client_win
;
2234 sevent
.xconfigure
.window
= wwin
->client_win
;
2236 sevent
.xconfigure
.x
= wwin
->client
.x
;
2237 sevent
.xconfigure
.y
= wwin
->client
.y
;
2238 sevent
.xconfigure
.width
= wwin
->client
.width
;
2239 sevent
.xconfigure
.height
= wwin
->client
.height
;
2241 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2242 if (HAS_TITLEBAR(wwin
) && wwin
->frame
->titlebar
)
2243 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2245 sevent
.xconfigure
.above
= None
;
2247 sevent
.xconfigure
.override_redirect
= False
;
2248 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2254 *----------------------------------------------------------------------
2255 * wWindowConfigure--
2256 * Configures the frame, decorations and client window to the
2257 * specified geometry. The geometry is not checked for validity,
2258 * wWindowConstrainSize() must be used for that.
2259 * The size parameters are for the client window, but the position is
2261 * The client window receives a ConfigureNotify event, according
2262 * to what ICCCM says.
2268 * Window size and position are changed and client window receives
2269 * a ConfigureNotify event.
2270 *----------------------------------------------------------------------
2273 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2275 int req_x
, req_y
; /* new position of the frame */
2276 int req_width
, req_height
; /* new size of the client */
2278 int synth_notify
= False
;
2281 resize
= (req_width
!=wwin
->client
.width
2282 || req_height
!=wwin
->client
.height
);
2284 * if the window is being moved but not resized then
2285 * send a synthetic ConfigureNotify
2287 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2288 synth_notify
= True
;
2291 if (WFLAGP(wwin
, dont_move_off
))
2292 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2293 req_width
, req_height
);
2295 if (req_width
< MIN_WINDOW_SIZE
)
2296 req_width
= MIN_WINDOW_SIZE
;
2297 if (req_height
< MIN_WINDOW_SIZE
)
2298 req_height
= MIN_WINDOW_SIZE
;
2300 /* If growing, resize inner part before frame,
2301 * if shrinking, resize frame before.
2302 * This will prevent the frame (that can have a different color)
2303 * to be exposed, causing flicker */
2304 if (req_height
> wwin
->frame
->core
->height
2305 || req_width
> wwin
->frame
->core
->width
)
2306 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2308 if (wwin
->flags
.shaded
) {
2309 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2310 req_width
, wwin
->frame
->core
->height
);
2311 wwin
->old_geometry
.height
= req_height
;
2315 h
= req_height
+ wwin
->frame
->top_width
2316 + wwin
->frame
->bottom_width
;
2318 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2321 if (!(req_height
> wwin
->frame
->core
->height
2322 || req_width
> wwin
->frame
->core
->width
))
2323 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2325 wwin
->client
.x
= req_x
;
2326 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2327 wwin
->client
.width
= req_width
;
2328 wwin
->client
.height
= req_height
;
2330 wwin
->client
.x
= req_x
;
2331 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2333 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2335 wwin
->frame_x
= req_x
;
2336 wwin
->frame_y
= req_y
;
2337 if (HAS_BORDER(wwin
)) {
2338 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2339 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2343 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2344 wWindowSetShape(wwin
);
2349 wWindowSynthConfigureNotify(wwin
);
2355 wWindowMove(wwin
, req_x
, req_y
)
2357 int req_x
, req_y
; /* new position of the frame */
2359 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2360 int synth_notify
= False
;
2362 /* Send a synthetic ConfigureNotify event for every window movement. */
2363 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2364 synth_notify
= True
;
2367 /* A single synthetic ConfigureNotify event is sent at the end of
2368 * a completed (opaque) movement in moveres.c */
2371 if (WFLAGP(wwin
, dont_move_off
))
2372 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2373 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2375 wwin
->client
.x
= req_x
;
2376 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2377 if (HAS_BORDER(wwin
)) {
2378 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2379 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2382 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2384 wwin
->frame_x
= req_x
;
2385 wwin
->frame_y
= req_y
;
2387 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2389 wWindowSynthConfigureNotify(wwin
);
2395 wWindowUpdateButtonImages(WWindow
*wwin
)
2397 WScreen
*scr
= wwin
->screen_ptr
;
2398 Pixmap pixmap
, mask
;
2399 WFrameWindow
*fwin
= wwin
->frame
;
2401 if (!HAS_TITLEBAR(wwin
))
2404 /* miniaturize button */
2406 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2407 if (wwin
->wm_gnustep_attr
2408 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2409 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2411 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2412 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2417 if (fwin
->lbutton_image
2418 && (fwin
->lbutton_image
->image
!= pixmap
2419 || fwin
->lbutton_image
->mask
!= mask
)) {
2420 wPixmapDestroy(fwin
->lbutton_image
);
2421 fwin
->lbutton_image
= NULL
;
2424 if (!fwin
->lbutton_image
) {
2425 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2426 fwin
->lbutton_image
->client_owned
= 1;
2427 fwin
->lbutton_image
->client_owned_mask
= 1;
2430 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2431 wPixmapDestroy(fwin
->lbutton_image
);
2433 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2437 #ifdef XKB_BUTTON_HINT
2438 if (!WFLAGP(wwin
, no_language_button
)) {
2439 if (fwin
->languagebutton_image
&&
2440 !fwin
->languagebutton_image
->shared
) {
2441 wPixmapDestroy(fwin
->languagebutton_image
);
2443 fwin
->languagebutton_image
=
2444 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2450 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2451 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2453 if (!WFLAGP(wwin
, no_close_button
)) {
2454 if (wwin
->wm_gnustep_attr
2455 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2456 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2458 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2459 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2463 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2464 || fwin
->rbutton_image
->mask
!= mask
)) {
2465 wPixmapDestroy(fwin
->rbutton_image
);
2466 fwin
->rbutton_image
= NULL
;
2469 if (!fwin
->rbutton_image
) {
2470 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2471 fwin
->rbutton_image
->client_owned
= 1;
2472 fwin
->rbutton_image
->client_owned_mask
= 1;
2475 } else if (WFLAGP(wwin
, kill_close
)) {
2477 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2478 wPixmapDestroy(fwin
->rbutton_image
);
2480 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2482 } else if (MGFLAGP(wwin
, broken_close
)) {
2484 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2485 wPixmapDestroy(fwin
->rbutton_image
);
2487 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2491 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2492 wPixmapDestroy(fwin
->rbutton_image
);
2494 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2498 /* force buttons to be redrawn */
2499 fwin
->flags
.need_texture_change
= 1;
2500 wFrameWindowPaint(fwin
);
2505 *---------------------------------------------------------------------------
2506 * wWindowConfigureBorders--
2507 * Update window border configuration according to attribute flags.
2509 *---------------------------------------------------------------------------
2512 wWindowConfigureBorders(WWindow
*wwin
)
2518 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2520 #ifdef XKB_BUTTON_HINT
2521 flags
|= WFF_LANGUAGE_BUTTON
;
2524 if (HAS_TITLEBAR(wwin
))
2525 flags
|= WFF_TITLEBAR
;
2526 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2527 flags
|= WFF_RESIZEBAR
;
2528 if (HAS_BORDER(wwin
))
2529 flags
|= WFF_BORDER
;
2530 if (wwin
->flags
.shaded
)
2531 flags
|= WFF_IS_SHADED
;
2533 oldh
= wwin
->frame
->top_width
;
2534 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2535 if (oldh
!= wwin
->frame
->top_width
) {
2536 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2538 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2539 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2540 wwin
->client
.width
, wwin
->client
.height
);
2544 if (!WFLAGP(wwin
, no_miniaturize_button
)
2545 && wwin
->frame
->flags
.hide_left_button
)
2546 flags
|= WFF_LEFT_BUTTON
;
2548 #ifdef XKB_BUTTON_HINT
2549 if (!WFLAGP(wwin
, no_language_button
)
2550 && wwin
->frame
->flags
.hide_language_button
) {
2551 flags
|= WFF_LANGUAGE_BUTTON
;
2555 if (!WFLAGP(wwin
, no_close_button
)
2556 && wwin
->frame
->flags
.hide_right_button
)
2557 flags
|= WFF_RIGHT_BUTTON
;
2560 wWindowUpdateButtonImages(wwin
);
2561 wFrameWindowShowButton(wwin
->frame
, flags
);
2565 if (WFLAGP(wwin
, no_miniaturize_button
)
2566 && !wwin
->frame
->flags
.hide_left_button
)
2567 flags
|= WFF_LEFT_BUTTON
;
2569 #ifdef XKB_BUTTON_HINT
2570 if (WFLAGP(wwin
, no_language_button
)
2571 && !wwin
->frame
->flags
.hide_language_button
)
2572 flags
|= WFF_LANGUAGE_BUTTON
;
2575 if (WFLAGP(wwin
, no_close_button
)
2576 && !wwin
->frame
->flags
.hide_right_button
)
2577 flags
|= WFF_RIGHT_BUTTON
;
2580 wFrameWindowHideButton(wwin
->frame
, flags
);
2583 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2584 wWindowSetShape(wwin
);
2592 wWindowSaveState(WWindow
*wwin
)
2597 memset(data
, 0, sizeof(CARD32
)*10);
2598 data
[0] = wwin
->frame
->workspace
;
2599 data
[1] = wwin
->flags
.miniaturized
;
2600 data
[2] = wwin
->flags
.shaded
;
2601 data
[3] = wwin
->flags
.hidden
;
2602 data
[4] = wwin
->flags
.maximized
;
2603 if (wwin
->flags
.maximized
== 0) {
2604 data
[5] = wwin
->frame_x
;
2605 data
[6] = wwin
->frame_y
;
2606 data
[7] = wwin
->frame
->core
->width
;
2607 data
[8] = wwin
->frame
->core
->height
;
2609 data
[5] = wwin
->old_geometry
.x
;
2610 data
[6] = wwin
->old_geometry
.y
;
2611 data
[7] = wwin
->old_geometry
.width
;
2612 data
[8] = wwin
->old_geometry
.height
;
2615 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2616 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2617 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2620 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2621 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2622 (unsigned char *)data
, 10);
2627 getSavedState(Window window
, WSavedState
**state
)
2631 unsigned long nitems_ret
;
2632 unsigned long bytes_after_ret
;
2635 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2636 True
, _XA_WINDOWMAKER_STATE
,
2637 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2638 (unsigned char **)&data
)!=Success
|| !data
)
2641 *state
= wmalloc(sizeof(WSavedState
));
2643 (*state
)->workspace
= data
[0];
2644 (*state
)->miniaturized
= data
[1];
2645 (*state
)->shaded
= data
[2];
2646 (*state
)->hidden
= data
[3];
2647 (*state
)->maximized
= data
[4];
2648 (*state
)->x
= data
[5];
2649 (*state
)->y
= data
[6];
2650 (*state
)->w
= data
[7];
2651 (*state
)->h
= data
[8];
2652 (*state
)->window_shortcuts
= data
[9];
2656 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2665 wWindowClearShape(WWindow
*wwin
)
2667 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2668 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2673 wWindowSetShape(WWindow
*wwin
)
2677 #ifdef OPTIMIZE_SHAPE
2682 /* only shape is the client's */
2683 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2687 /* Get array of rectangles describing the shape mask */
2688 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2694 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2700 /* insert our decoration rectangles in the rect list */
2701 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2704 if (HAS_TITLEBAR(wwin
)) {
2706 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2707 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2708 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2711 if (HAS_RESIZEBAR(wwin
)) {
2713 urec
[count
].y
= wwin
->frame
->core
->height
2714 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2715 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2716 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2720 /* shape our frame window */
2721 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2722 0, wwin
->frame
->top_width
, urec
, count
,
2723 ShapeSet
, Unsorted
);
2729 #endif /* OPTIMIZE_SHAPE */
2731 if (HAS_TITLEBAR(wwin
)) {
2734 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2735 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2738 if (HAS_RESIZEBAR(wwin
)) {
2740 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2741 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2742 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2746 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2747 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2749 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2750 0, wwin
->frame
->top_width
, wwin
->client_win
,
2751 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2756 /* ====================================================================== */
2759 getFocusMode(WWindow
*wwin
)
2763 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2764 if (wwin
->wm_hints
->input
== True
) {
2765 if (wwin
->protocols
.TAKE_FOCUS
)
2766 mode
= WFM_LOCALLY_ACTIVE
;
2770 if (wwin
->protocols
.TAKE_FOCUS
)
2771 mode
= WFM_GLOBALLY_ACTIVE
;
2773 mode
= WFM_NO_INPUT
;
2783 wWindowSetKeyGrabs(WWindow
*wwin
)
2788 for (i
=0; i
<WKBD_LAST
; i
++) {
2789 key
= &wKeyBindings
[i
];
2791 if (key
->keycode
==0)
2793 if (key
->modifier
!=AnyModifier
) {
2794 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2795 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2797 /* Also grab all modifier combinations possible that include,
2798 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2799 * work even if the NumLock/ScrollLock key is on.
2801 wHackedGrabKey(key
->keycode
, key
->modifier
,
2802 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2806 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2807 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2811 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2818 wWindowResetMouseGrabs(WWindow
*wwin
)
2820 /* Mouse grabs can't be done on the client window because of
2821 * ICCCM and because clients that try to do the same will crash.
2823 * But there is a problem wich makes tbar buttons of unfocused
2824 * windows not usable as the click goes to the frame window instead
2825 * of the button itself. Must figure a way to fix that.
2828 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2830 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2831 /* grabs for Meta+drag */
2832 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2833 True
, ButtonPressMask
|ButtonReleaseMask
,
2834 GrabModeSync
, GrabModeAsync
, None
, None
);
2837 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2838 && !wwin
->flags
.is_gnustep
) {
2839 /* the passive grabs to focus the window */
2840 /* if (wPreferences.focus_mode == WKF_CLICK) */
2841 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2842 True
, ButtonPressMask
|ButtonReleaseMask
,
2843 GrabModeSync
, GrabModeAsync
, None
, None
);
2850 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2852 if (attr
->flags
& GSExtraFlagsAttr
) {
2853 if (MGFLAGP(wwin
, broken_close
) !=
2854 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2855 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2856 wWindowUpdateButtonImages(wwin
);
2863 wWindowAddSavedState(char *instance
, char *class, char *command
,
2864 pid_t pid
, WSavedState
*state
)
2866 WWindowState
*wstate
;
2868 wstate
= malloc(sizeof(WWindowState
));
2872 memset(wstate
, 0, sizeof(WWindowState
));
2875 wstate
->instance
= wstrdup(instance
);
2877 wstate
->class = wstrdup(class);
2879 wstate
->command
= wstrdup(command
);
2880 wstate
->state
= state
;
2882 wstate
->next
= windowState
;
2883 windowState
= wstate
;
2886 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2894 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2898 wWindowGetSavedState(Window win
)
2900 char *instance
, *class, *command
=NULL
;
2901 WWindowState
*wstate
= windowState
;
2906 command
= GetCommandForWindow(win
);
2910 if (PropGetWMClass(win
, &class, &instance
)) {
2912 if (SAME(instance
, wstate
->instance
) &&
2913 SAME(class, wstate
->class) &&
2914 SAME(command
, wstate
->command
)) {
2917 wstate
= wstate
->next
;
2924 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2928 if (command
) wfree(command
);
2929 if (instance
) XFree(instance
);
2930 if (class) XFree(class);
2937 wWindowDeleteSavedState(WMagicNumber id
)
2939 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2941 if (!wstate
|| !windowState
)
2946 windowState
= wstate
->next
;
2948 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2949 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2951 if (wstate
->instance
) wfree(wstate
->instance
);
2952 if (wstate
->class) wfree(wstate
->class);
2953 if (wstate
->command
) wfree(wstate
->command
);
2954 wfree(wstate
->state
);
2958 if (tmp
->next
==wstate
) {
2959 tmp
->next
=wstate
->next
;
2961 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2962 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2964 if (wstate
->instance
) wfree(wstate
->instance
);
2965 if (wstate
->class) wfree(wstate
->class);
2966 if (wstate
->command
) wfree(wstate
->command
);
2967 wfree(wstate
->state
);
2978 wWindowDeleteSavedStatesForPID(pid_t pid
)
2980 WWindowState
*tmp
, *wstate
;
2986 if (tmp
->pid
== pid
) {
2987 wstate
= windowState
;
2988 windowState
= tmp
->next
;
2990 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2991 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2993 if (wstate
->instance
) wfree(wstate
->instance
);
2994 if (wstate
->class) wfree(wstate
->class);
2995 if (wstate
->command
) wfree(wstate
->command
);
2996 wfree(wstate
->state
);
3000 if (tmp
->next
->pid
==pid
) {
3002 tmp
->next
= wstate
->next
;
3004 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
3005 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
3007 if (wstate
->instance
) wfree(wstate
->instance
);
3008 if (wstate
->class) wfree(wstate
->class);
3009 if (wstate
->command
) wfree(wstate
->command
);
3010 wfree(wstate
->state
);
3021 wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
3023 if (wwin
->flags
.omnipresent
== flag
)
3026 wwin
->flags
.omnipresent
= flag
;
3027 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
3031 /* ====================================================================== */
3034 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3036 WWindow
*wwin
= data
;
3038 #ifndef NUMLOCK_HACK
3039 if ((event
->xbutton
.state
& ValidModMask
)
3040 != (event
->xbutton
.state
& ~LockMask
)) {
3041 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3042 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3046 event
->xbutton
.state
&= ValidModMask
;
3048 CloseWindowMenu(wwin
->screen_ptr
);
3050 if (wPreferences
.focus_mode
==WKF_CLICK
3051 && !(event
->xbutton
.state
&ControlMask
)
3052 && !WFLAGP(wwin
, no_focusable
)) {
3053 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3056 if (event
->xbutton
.button
== Button1
)
3057 wRaiseFrame(wwin
->frame
->core
);
3059 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
3060 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
3061 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3062 GrabModeAsync
, GrabModeAsync
, None
,
3063 None
, CurrentTime
)!=GrabSuccess
) {
3065 wwarning("pointer grab failed for window move");
3071 if (event
->xbutton
.state
& MOD_MASK
) {
3072 /* move the window */
3073 wMouseMoveWindow(wwin
, event
);
3074 XUngrabPointer(dpy
, CurrentTime
);
3076 wMouseResizeWindow(wwin
, event
);
3077 XUngrabPointer(dpy
, CurrentTime
);
3084 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3086 WWindow
*wwin
= data
;
3088 event
->xbutton
.state
&= ValidModMask
;
3090 if (event
->xbutton
.button
==Button1
) {
3091 if (event
->xbutton
.state
== 0) {
3092 if (!WFLAGP(wwin
, no_shadeable
)) {
3094 if (wwin
->flags
.shaded
)
3095 wUnshadeWindow(wwin
);
3102 if (event
->xbutton
.state
& ControlMask
)
3103 dir
|= MAX_VERTICAL
;
3105 if (event
->xbutton
.state
& ShiftMask
) {
3106 dir
|= MAX_HORIZONTAL
;
3107 if (!(event
->xbutton
.state
& ControlMask
))
3108 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3111 /* maximize window */
3112 if (dir
!=0 && IS_RESIZABLE(wwin
)) {
3113 int ndir
= dir
^ wwin
->flags
.maximized
;
3116 wMaximizeWindow(wwin
, ndir
);
3118 wUnmaximizeWindow(wwin
);
3122 } else if (event
->xbutton
.button
==Button3
) {
3123 if (event
->xbutton
.state
& MOD_MASK
) {
3124 wHideOtherApplications(wwin
);
3126 } else if (event
->xbutton
.button
==Button2
) {
3127 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3128 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
3130 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
3131 wUnshadeWindow(wwin
);
3137 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3139 WWindow
*wwin
= desc
->parent
;
3141 event
->xbutton
.state
&= ValidModMask
;
3143 CloseWindowMenu(wwin
->screen_ptr
);
3145 if (/*wPreferences.focus_mode==WKF_CLICK
3146 &&*/ !(event
->xbutton
.state
&ControlMask
)
3147 && !WFLAGP(wwin
, no_focusable
)) {
3148 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3150 if (event
->xbutton
.button
== Button1
) {
3151 wRaiseFrame(wwin
->frame
->core
);
3154 if (event
->xbutton
.state
& MOD_MASK
) {
3155 /* move the window */
3156 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
3157 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3158 GrabModeAsync
, GrabModeAsync
, None
,
3159 None
, CurrentTime
)!=GrabSuccess
) {
3161 wwarning("pointer grab failed for window move");
3165 if (event
->xbutton
.button
== Button3
)
3166 wMouseResizeWindow(wwin
, event
);
3167 else if (event
->xbutton
.button
==Button1
|| event
->xbutton
.button
==Button2
)
3168 wMouseMoveWindow(wwin
, event
);
3169 XUngrabPointer(dpy
, CurrentTime
);
3175 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3177 WWindow
*wwin
= (WWindow
*)data
;
3179 #ifndef NUMLOCK_HACK
3180 if ((event
->xbutton
.state
& ValidModMask
)
3181 != (event
->xbutton
.state
& ~LockMask
)) {
3182 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3183 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3186 event
->xbutton
.state
&= ValidModMask
;
3188 CloseWindowMenu(wwin
->screen_ptr
);
3190 if (wPreferences
.focus_mode
==WKF_CLICK
3191 && !(event
->xbutton
.state
&ControlMask
)
3192 && !WFLAGP(wwin
, no_focusable
)) {
3193 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3196 if (event
->xbutton
.button
== Button1
3197 || event
->xbutton
.button
== Button2
) {
3199 if (event
->xbutton
.button
== Button1
) {
3200 if (event
->xbutton
.state
& MOD_MASK
) {
3201 wLowerFrame(wwin
->frame
->core
);
3203 wRaiseFrame(wwin
->frame
->core
);
3206 if ((event
->xbutton
.state
& ShiftMask
)
3207 && !(event
->xbutton
.state
& ControlMask
)) {
3208 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3211 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3212 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3213 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3214 GrabModeAsync
, GrabModeAsync
, None
,
3215 None
, CurrentTime
)!=GrabSuccess
) {
3217 wwarning("pointer grab failed for window move");
3222 /* move the window */
3223 wMouseMoveWindow(wwin
, event
);
3225 XUngrabPointer(dpy
, CurrentTime
);
3226 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
3227 && !wwin
->flags
.internal_window
3228 && !WCHECK_STATE(WSTATE_MODAL
)) {
3229 WObjDescriptor
*desc
;
3231 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3232 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3233 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3234 GrabModeAsync
, GrabModeAsync
, None
,
3235 None
, CurrentTime
)!=GrabSuccess
) {
3237 wwarning("pointer grab failed for window move");
3242 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
3243 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3245 /* allow drag select */
3246 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3247 event
->xany
.send_event
= True
;
3248 (*desc
->handle_mousedown
)(desc
, event
);
3250 XUngrabPointer(dpy
, CurrentTime
);
3257 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3259 WWindow
*wwin
= data
;
3261 event
->xbutton
.state
&= ValidModMask
;
3263 CloseWindowMenu(wwin
->screen_ptr
);
3265 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3268 /* if control-click, kill the client */
3269 if (event
->xbutton
.state
& ControlMask
) {
3272 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3273 /* send delete message */
3274 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3281 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3283 WWindow
*wwin
= data
;
3285 CloseWindowMenu(wwin
->screen_ptr
);
3287 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3290 /* send delete message */
3291 if (wwin
->protocols
.DELETE_WINDOW
) {
3292 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3299 #ifdef XKB_BUTTON_HINT
3301 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3303 WWindow
*wwin
= data
;
3304 WFrameWindow
*fwin
= wwin
->frame
;
3305 WScreen
*scr
= fwin
->screen_ptr
;
3306 XkbStateRec staterec
;
3309 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3311 tl
= wwin
->frame
->languagemode
;
3312 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3313 wwin
->frame
->last_languagemode
= tl
;
3314 wSetFocusTo(scr
, wwin
);
3315 wwin
->frame
->languagebutton_image
=
3316 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3317 wwin
->frame
->languagemode
];
3318 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3319 if (event
->xbutton
.button
== Button3
)
3321 wRaiseFrame(fwin
->core
);
3327 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3329 WWindow
*wwin
= data
;
3331 event
->xbutton
.state
&= ValidModMask
;
3333 CloseWindowMenu(wwin
->screen_ptr
);
3335 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3338 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3339 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3343 if ((event
->xbutton
.state
& ControlMask
) ||
3344 (event
->xbutton
.button
== Button3
)) {
3346 wapp
= wApplicationOf(wwin
->main_window
);
3347 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3348 wHideApplication(wapp
);
3349 } else if (event
->xbutton
.state
==0) {
3350 wIconifyWindow(wwin
);