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;
346 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
,
347 WWindowAttributes
*mask
)
349 if (wflags
->no_appicon
&& mask
->no_appicon
)
350 wflags
->emulate_appicon
= 0;
352 if (wwin
->main_window
!=None
) {
353 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
354 if (wapp
&& !wapp
->flags
.emulated
)
355 wflags
->emulate_appicon
= 0;
358 if (wwin
->transient_for
!=None
359 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
360 wflags
->emulate_appicon
= 0;
362 if (wflags
->sunken
&& mask
->sunken
&& wflags
->floating
&& mask
->floating
)
369 wWindowSetupInitialAttributes(WWindow
*wwin
, int *level
, int *workspace
)
371 WScreen
*scr
= wwin
->screen_ptr
;
373 /* sets global default stuff */
374 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
375 &wwin
->client_flags
, NULL
, True
);
377 * Decoration setting is done in this precedence (lower to higher)
378 * - use global default in the resource database
379 * - guess some settings
380 * - use GNUstep/external window attributes
381 * - set hints specified for the app in the resource DB
384 WSETUFLAG(wwin
, broken_close
, 0);
386 if (wwin
->protocols
.DELETE_WINDOW
)
387 WSETUFLAG(wwin
, kill_close
, 0);
389 WSETUFLAG(wwin
, kill_close
, 1);
391 /* transients can't be iconified or maximized */
392 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
393 WSETUFLAG(wwin
, no_miniaturizable
, 1);
394 WSETUFLAG(wwin
, no_miniaturize_button
, 1);
397 /* if the window can't be resized, remove the resizebar */
398 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
399 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
400 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
401 WSETUFLAG(wwin
, no_resizable
, 1);
402 WSETUFLAG(wwin
, no_resizebar
, 1);
405 /* set GNUstep window attributes */
406 if (wwin
->wm_gnustep_attr
) {
407 setupGNUstepHints(wwin
, wwin
->wm_gnustep_attr
);
409 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
411 *level
= wwin
->wm_gnustep_attr
->window_level
;
413 * INT_MIN is the only illegal window level.
415 if (*level
== INT_MIN
)
416 *level
= INT_MIN
+ 1;
419 *level
= WMNormalLevel
;
422 int tmp_workspace
= -1;
423 int tmp_level
= INT_MIN
; /* INT_MIN is never used by the window levels */
429 wMWMCheckClientHints(wwin
);
430 #endif /* MWM_HINTS */
434 check
= wNETWMCheckClientHints(wwin
, &tmp_level
, &tmp_workspace
);
437 /* window levels are between INT_MIN+1 and INT_MAX, so if we still
438 * have INT_MIN that means that no window level was requested. -Dan
440 if (tmp_level
== INT_MIN
) {
441 if (WFLAGP(wwin
, floating
))
442 *level
= WMFloatingLevel
;
443 else if (WFLAGP(wwin
, sunken
))
444 *level
= WMSunkenLevel
;
446 *level
= WMNormalLevel
;
451 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!= scr
->root_win
) {
452 WWindow
* transientOwner
= wWindowFor(wwin
->transient_for
);
453 if (transientOwner
) {
454 int ownerLevel
= transientOwner
->frame
->core
->stacking
->window_level
;
455 if (ownerLevel
> *level
) *level
= ownerLevel
;
459 if (tmp_workspace
>= 0) {
460 *workspace
= tmp_workspace
% scr
->workspace_count
;
465 * Set attributes specified only for that window/class.
466 * This might do duplicate work with the 1st wDefaultFillAttributes().
468 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
469 &wwin
->user_flags
, &wwin
->defined_user_flags
,
472 * Sanity checks for attributes that depend on other attributes
474 if (wwin
->user_flags
.no_appicon
&& wwin
->defined_user_flags
.no_appicon
)
475 wwin
->user_flags
.emulate_appicon
= 0;
477 if (wwin
->main_window
!=None
) {
478 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
479 if (wapp
&& !wapp
->flags
.emulated
)
480 wwin
->user_flags
.emulate_appicon
= 0;
483 if (wwin
->transient_for
!=None
484 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
485 wwin
->user_flags
.emulate_appicon
= 0;
487 if (wwin
->user_flags
.sunken
&& wwin
->defined_user_flags
.sunken
488 && wwin
->user_flags
.floating
&& wwin
->defined_user_flags
.floating
)
489 wwin
->user_flags
.sunken
= 0;
491 WSETUFLAG(wwin
, no_shadeable
, WFLAGP(wwin
, no_titlebar
));
494 /* windows that have takefocus=False shouldn't take focus at all */
495 if (wwin
->focus_mode
== WFM_NO_INPUT
) {
496 wwin
->client_flags
.no_focusable
= 1;
504 wWindowCanReceiveFocus(WWindow
*wwin
)
506 if (!wwin
->flags
.mapped
&& (!wwin
->flags
.shaded
|| wwin
->flags
.hidden
))
508 if (WFLAGP(wwin
, no_focusable
) || wwin
->flags
.miniaturized
)
510 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
518 wWindowObscuresWindow(WWindow
*wwin
, WWindow
*obscured
)
522 w1
= wwin
->frame
->core
->width
;
523 h1
= wwin
->frame
->core
->height
;
524 w2
= obscured
->frame
->core
->width
;
525 h2
= obscured
->frame
->core
->height
;
527 if (!IS_OMNIPRESENT(wwin
) && !IS_OMNIPRESENT(obscured
)
528 && wwin
->frame
->workspace
!= obscured
->frame
->workspace
)
531 if (wwin
->frame_x
+ w1
< obscured
->frame_x
532 || wwin
->frame_y
+ h1
< obscured
->frame_y
533 || wwin
->frame_x
> obscured
->frame_x
+ w2
534 || wwin
->frame_y
> obscured
->frame_y
+ h2
) {
543 fixLeaderProperties(WWindow
*wwin
)
545 XClassHint
*classHint
;
546 XWMHints
*hints
, *clientHints
;
547 Window leaders
[2], window
;
548 char **argv
, *command
;
552 classHint
= XAllocClassHint();
553 clientHints
= XGetWMHints(dpy
, wwin
->client_win
);
554 pid
= wNETWMGetPidForWindow(wwin
->client_win
);
556 haveCommand
= GetCommandForPid(pid
, &argv
, &argc
);
561 leaders
[0] = wwin
->client_leader
;
562 leaders
[1] = wwin
->group_id
;
565 command
= GetCommandForWindow(wwin
->client_win
);
567 /* command already set. nothing to do. */
570 XSetCommand(dpy
, wwin
->client_win
, argv
, argc
);
574 for (i
=0; i
<2; i
++) {
577 if (XGetClassHint(dpy
, window
, classHint
) == 0) {
578 classHint
->res_name
= wwin
->wm_instance
;
579 classHint
->res_class
= wwin
->wm_class
;
580 XSetClassHint(dpy
, window
, classHint
);
582 hints
= XGetWMHints(dpy
, window
);
585 } else if (clientHints
) {
586 /* set window group leader to self */
587 clientHints
->window_group
= window
;
588 clientHints
->flags
|= WindowGroupHint
;
589 XSetWMHints(dpy
, window
, clientHints
);
593 command
= GetCommandForWindow(window
);
595 /* command already set. nothing to do. */
598 XSetCommand(dpy
, window
, argv
, argc
);
615 createFakeWindowGroupLeader(WScreen
*scr
, Window win
, char *instance
, char *class)
617 XClassHint
*classHint
;
623 leader
= XCreateSimpleWindow(dpy
, scr
->root_win
, 10, 10, 10, 10, 0, 0, 0);
625 classHint
= XAllocClassHint();
626 classHint
->res_name
= instance
;
627 classHint
->res_class
= class;
628 XSetClassHint(dpy
, leader
, classHint
);
631 /* inherit these from the original leader if available */
632 hints
= XGetWMHints(dpy
, win
);
634 hints
= XAllocWMHints();
637 /* set window group leader to self */
638 hints
->window_group
= leader
;
639 hints
->flags
|= WindowGroupHint
;
640 XSetWMHints(dpy
, leader
, hints
);
643 if (XGetCommand(dpy
, win
, &argv
, &argc
)!=0 && argc
> 0) {
644 XSetCommand(dpy
, leader
, argv
, argc
);
645 XFreeStringList(argv
);
653 matchIdentifier(void *item
, void *cdata
)
655 return (strcmp(((WFakeGroupLeader
*)item
)->identifier
, (char*)cdata
)==0);
660 *----------------------------------------------------------------
662 * reparents the window and allocates a descriptor for it.
663 * Window manager hints and other hints are fetched to configure
664 * the window decoration attributes and others. User preferences
665 * for the window are used if available, to configure window
666 * decorations and some behaviour.
667 * If in startup, windows that are override redirect,
668 * unmapped and never were managed and are Withdrawn are not
672 * the new window descriptor
675 * The window is reparented and appropriate notification
676 * is done to the client. Input mask for the window is setup.
677 * The window descriptor is also associated with various window
678 * contexts and inserted in the head of the window list.
679 * Event handler contexts are associated for some objects
680 * (buttons, titlebar and resizebar)
682 *----------------------------------------------------------------
685 wManageWindow(WScreen
*scr
, Window window
)
689 unsigned width
, height
;
690 XWindowAttributes wattribs
;
691 XSetWindowAttributes attribs
;
692 WWindowState
*win_state
;
693 WWindow
*transientOwner
= NULL
;
699 Bool withdraw
= False
;
703 /* XGrabServer(dpy); */
705 /* make sure the window is still there */
706 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
711 /* if it's an override-redirect, ignore it */
712 if (wattribs
.override_redirect
) {
717 wm_state
= PropGetWindowState(window
);
719 /* if it's startup and the window is unmapped, don't manage it */
720 if (scr
->flags
.startup
&& wm_state
< 0 && wattribs
.map_state
==IsUnmapped
) {
725 wwin
= wWindowCreate();
727 title
= wNETWMGetWindowName(window
);
729 wwin
->flags
.net_has_title
= 1;
730 if (!title
&& !wFetchName(dpy
, window
, &title
))
733 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
736 printf("managing window %x\n", (unsigned)window
);
740 if (wShapeSupported
) {
745 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
746 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
747 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
748 wwin
->flags
.shaped
= b_shaped
;
753 *--------------------------------------------------
755 * Get hints and other information in properties
757 *--------------------------------------------------
759 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
761 /* setup descriptor */
762 wwin
->client_win
= window
;
763 wwin
->screen_ptr
= scr
;
765 wwin
->old_border_width
= wattribs
.border_width
;
767 wwin
->event_mask
= CLIENT_EVENTS
;
768 attribs
.event_mask
= CLIENT_EVENTS
;
769 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
770 attribs
.save_under
= False
;
771 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
772 |CWSaveUnder
, &attribs
);
773 XSetWindowBorderWidth(dpy
, window
, 0);
775 /* get hints from GNUstep app */
776 if (wwin
->wm_class
!= 0 && strcmp(wwin
->wm_class
, "GNUstep") == 0) {
777 wwin
->flags
.is_gnustep
= 1;
779 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
780 wwin
->wm_gnustep_attr
= NULL
;
783 wwin
->client_leader
= PropGetClientLeader(window
);
784 if (wwin
->client_leader
!=None
)
785 wwin
->main_window
= wwin
->client_leader
;
787 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
789 if (wwin
->wm_hints
) {
790 if (wwin
->wm_hints
->flags
& StateHint
) {
792 if (wwin
->wm_hints
->initial_state
== IconicState
) {
794 wwin
->flags
.miniaturized
= 1;
796 } else if (wwin
->wm_hints
->initial_state
== WithdrawnState
) {
802 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
803 wwin
->group_id
= wwin
->wm_hints
->window_group
;
804 /* window_group has priority over CLIENT_LEADER */
805 wwin
->main_window
= wwin
->group_id
;
807 wwin
->group_id
= None
;
810 if (wwin
->wm_hints
->flags
& UrgencyHint
)
811 wwin
->flags
.urgent
= 1;
813 wwin
->group_id
= None
;
816 PropGetProtocols(window
, &wwin
->protocols
);
818 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
819 wwin
->transient_for
= None
;
821 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
822 wwin
->transient_for
= scr
->root_win
;
824 transientOwner
= wWindowFor(wwin
->transient_for
);
825 if (transientOwner
&& transientOwner
->main_window
!=None
) {
826 wwin
->main_window
= transientOwner
->main_window
;
828 wwin->main_window = None;
833 /* guess the focus mode */
834 wwin
->focus_mode
= getFocusMode(wwin
);
836 /* get geometry stuff */
837 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
839 /* printf("wManageWindow: %d %d %d %d\n", x, y, width, height);*/
841 /* get colormap windows */
842 GetColormapWindows(wwin
);
845 *--------------------------------------------------
847 * Setup the decoration/window attributes and
850 *--------------------------------------------------
853 wWindowSetupInitialAttributes(wwin
, &window_level
, &workspace
);
855 /* Make broken apps behave as a nice app. */
856 if (WFLAGP(wwin
, emulate_appicon
)) {
857 wwin
->main_window
= wwin
->client_win
;
860 fixLeaderProperties(wwin
);
862 wwin
->orig_main_window
= wwin
->main_window
;
864 if (wwin
->flags
.is_gnustep
) {
865 WSETUFLAG(wwin
, shared_appicon
, 0);
868 if (wwin
->main_window
) {
869 extern Atom _XA_WINDOWMAKER_MENU
;
870 XTextProperty text_prop
;
872 if (XGetTextProperty(dpy
, wwin
->main_window
, &text_prop
,
873 _XA_WINDOWMAKER_MENU
)) {
874 WSETUFLAG(wwin
, shared_appicon
, 0);
878 if (!withdraw
&& wwin
->main_window
&& WFLAGP(wwin
, shared_appicon
)) {
879 char *buffer
, *instance
, *class;
880 WFakeGroupLeader
*fPtr
;
883 #define ADEQUATE(x) ((x)!=None && (x)!=wwin->client_win && (x)!=fPtr->leader)
885 // only enter here if PropGetWMClass() succeds
886 PropGetWMClass(wwin
->main_window
, &class, &instance
);
887 buffer
= StrConcatDot(instance
, class);
889 index
= WMFindInArray(scr
->fakeGroupLeaders
, matchIdentifier
, (void*)buffer
);
890 if (index
!= WANotFound
) {
891 fPtr
= WMGetFromArray(scr
->fakeGroupLeaders
, index
);
892 if (fPtr
->retainCount
== 0) {
893 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
898 if (fPtr
->origLeader
==None
) {
900 if (ADEQUATE(wwin
->group_id
)) {
902 fPtr
->origLeader
= wwin
->group_id
;
903 } else if (ADEQUATE(wwin
->client_leader
)) {
905 fPtr
->origLeader
= wwin
->client_leader
;
906 } else if (ADEQUATE(wwin
->main_window
)) {
908 fPtr
->origLeader
= wwin
->main_window
;
911 if (ADEQUATE(wwin
->main_window
)) {
913 fPtr
->origLeader
= wwin
->main_window
;
917 wwin
->fake_group
= fPtr
;
918 /*wwin->group_id = fPtr->leader;*/
919 wwin
->main_window
= fPtr
->leader
;
922 fPtr
= (WFakeGroupLeader
*)wmalloc(sizeof(WFakeGroupLeader
));
924 fPtr
->identifier
= buffer
;
925 fPtr
->leader
= createFakeWindowGroupLeader(scr
, wwin
->main_window
,
927 fPtr
->origLeader
= None
;
928 fPtr
->retainCount
= 1;
930 WMAddToArray(scr
->fakeGroupLeaders
, fPtr
);
933 if (ADEQUATE(wwin
->group_id
)) {
935 fPtr
->origLeader
= wwin
->group_id
;
936 } else if (ADEQUATE(wwin
->client_leader
)) {
938 fPtr
->origLeader
= wwin
->client_leader
;
939 } else if (ADEQUATE(wwin
->main_window
)) {
941 fPtr
->origLeader
= wwin
->main_window
;
944 if (ADEQUATE(wwin
->main_window
)) {
946 fPtr
->origLeader
= wwin
->main_window
;
949 wwin
->fake_group
= fPtr
;
950 /*wwin->group_id = fPtr->leader;*/
951 wwin
->main_window
= fPtr
->leader
;
963 *------------------------------------------------------------
965 * Setup the initial state of the window
967 *------------------------------------------------------------
970 if (WFLAGP(wwin
, start_miniaturized
) && !WFLAGP(wwin
, no_miniaturizable
)) {
971 wwin
->flags
.miniaturized
= 1;
974 if (WFLAGP(wwin
, start_maximized
) && IS_RESIZABLE(wwin
)) {
975 wwin
->flags
.maximized
= MAX_VERTICAL
|MAX_HORIZONTAL
;
979 wNETWMCheckInitialClientState(wwin
);
982 /* apply previous state if it exists and we're in startup */
983 if (scr
->flags
.startup
&& wm_state
>= 0) {
985 if (wm_state
== IconicState
) {
987 wwin
->flags
.miniaturized
= 1;
989 } else if (wm_state
== WithdrawnState
) {
995 /* if there is a saved state (from file), restore it */
997 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
998 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
1000 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
1002 if (win_state
&& !withdraw
) {
1004 if (win_state
->state
->hidden
>0)
1005 wwin
->flags
.hidden
= win_state
->state
->hidden
;
1007 if (win_state
->state
->shaded
>0 && !WFLAGP(wwin
, no_shadeable
))
1008 wwin
->flags
.shaded
= win_state
->state
->shaded
;
1010 if (win_state
->state
->miniaturized
>0 &&
1011 !WFLAGP(wwin
, no_miniaturizable
)) {
1012 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
1015 if (!IS_OMNIPRESENT(wwin
)) {
1016 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
1018 if (w
< 0 || w
>= scr
->workspace_count
) {
1019 workspace
= win_state
->state
->workspace
;
1020 if (workspace
>= scr
->workspace_count
)
1021 workspace
= scr
->current_workspace
;
1026 workspace
= scr
->current_workspace
;
1030 /* if we're restarting, restore saved state (from hints).
1031 * This will overwrite previous */
1033 WSavedState
*wstate
;
1035 if (getSavedState(window
, &wstate
)) {
1036 wwin
->flags
.shaded
= wstate
->shaded
;
1037 wwin
->flags
.hidden
= wstate
->hidden
;
1038 wwin
->flags
.miniaturized
= wstate
->miniaturized
;
1039 wwin
->flags
.maximized
= wstate
->maximized
;
1040 if (wwin
->flags
.maximized
) {
1041 wwin
->old_geometry
.x
= wstate
->x
;
1042 wwin
->old_geometry
.y
= wstate
->y
;
1043 wwin
->old_geometry
.width
= wstate
->w
;
1044 wwin
->old_geometry
.height
= wstate
->h
;
1047 workspace
= wstate
->workspace
;
1052 /* restore window shortcut */
1053 if (wstate
!= NULL
|| win_state
!= NULL
) {
1056 if (win_state
!= NULL
)
1057 mask
= win_state
->state
->window_shortcuts
;
1059 if (wstate
!= NULL
&& mask
== 0)
1060 mask
= wstate
->window_shortcuts
;
1065 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
1066 if (mask
& (1<<i
)) {
1067 if (!scr
->shortcutWindows
[i
])
1068 scr
->shortcutWindows
[i
] = WMCreateArray(4);
1070 WMAddToArray(scr
->shortcutWindows
[i
], wwin
);
1075 if (wstate
!= NULL
) {
1080 /* don't let transients start miniaturized if their owners are not */
1081 if (transientOwner
&& !transientOwner
->flags
.miniaturized
1082 && wwin
->flags
.miniaturized
&& !withdraw
) {
1083 wwin
->flags
.miniaturized
= 0;
1085 wwin
->wm_hints
->initial_state
= NormalState
;
1088 /* set workspace on which the window starts */
1089 if (workspace
>= 0) {
1090 if (workspace
> scr
->workspace_count
-1) {
1091 workspace
= workspace
% scr
->workspace_count
;
1096 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
1098 if (w
>= 0 && w
< scr
->workspace_count
&& !(IS_OMNIPRESENT(wwin
))) {
1103 if (wPreferences
.open_transients_with_parent
&& transientOwner
) {
1105 workspace
= transientOwner
->frame
->workspace
;
1109 workspace
= scr
->current_workspace
;
1114 /* setup window geometry */
1115 if (win_state
&& win_state
->state
->w
> 0) {
1116 width
= win_state
->state
->w
;
1117 height
= win_state
->state
->h
;
1119 wWindowConstrainSize(wwin
, &width
, &height
);
1121 /* do not ask for window placement if the window is
1122 * transient, during startup, if the initial workspace is another one
1123 * or if the window wants to start iconic.
1124 * If geometry was saved, restore it. */
1126 Bool dontBring
= False
;
1128 if (win_state
&& win_state
->state
->w
> 0) {
1129 x
= win_state
->state
->x
;
1130 y
= win_state
->state
->y
;
1131 } else if ((wwin
->transient_for
==None
1132 || wPreferences
.window_placement
!=WPM_MANUAL
)
1133 && !scr
->flags
.startup
1134 && workspace
== scr
->current_workspace
1135 && !wwin
->flags
.miniaturized
1136 && !wwin
->flags
.maximized
1137 && !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
1139 if (transientOwner
&& transientOwner
->flags
.mapped
) {
1140 int offs
= WMAX(20, 2*transientOwner
->frame
->top_width
);
1144 x
= transientOwner
->frame_x
+
1145 abs((transientOwner
->frame
->core
->width
- width
)/2) + offs
;
1146 y
= transientOwner
->frame_y
+
1147 abs((transientOwner
->frame
->core
->height
- height
)/3) + offs
;
1150 * limit transient windows to be inside their parent's head
1152 rect
.pos
.x
= transientOwner
->frame_x
;
1153 rect
.pos
.y
= transientOwner
->frame_y
;
1154 rect
.size
.width
= transientOwner
->frame
->core
->width
;
1155 rect
.size
.height
= transientOwner
->frame
->core
->height
;
1157 head
= wGetHeadForRect(scr
, rect
);
1158 rect
= wGetRectForHead(scr
, head
);
1162 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1163 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1167 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1168 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1171 PlaceWindow(wwin
, &x
, &y
, width
, height
);
1173 if (wPreferences
.window_placement
== WPM_MANUAL
) {
1176 } else if (scr
->xine_info
.count
&&
1177 (wwin
->normal_hints
->flags
& PPosition
)) {
1183 * Make spash screens come out in the center of a head
1184 * trouble is that most splashies never get here
1185 * they are managed trough atoms but god knows where.
1186 * Dan, do you know ? -peter
1188 * Most of them are not managed, they have set
1189 * OverrideRedirect, which means we can't do anything about
1193 printf("xinerama PPosition: x: %d %d\n", x
, (scr
->scr_width
- width
)/2);
1194 printf("xinerama PPosition: y: %d %d\n", y
, (scr
->scr_height
- height
)/2);
1196 if ((unsigned)(x
+ (width
- scr
->scr_width
)/2 + 10) < 20 &&
1197 (unsigned)(y
+ (height
- scr
->scr_height
)/2 + 10) < 20) {
1205 * xinerama checks for: across head and dead space
1209 rect
.size
.width
= width
;
1210 rect
.size
.height
= height
;
1212 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1214 if (flags
& XFLAG_DEAD
)
1217 if (flags
& XFLAG_MULTIPLE
)
1221 switch (reposition
) {
1223 head
= wGetHeadForPointerLocation(scr
);
1224 rect
= wGetRectForHead(scr
, head
);
1226 x
= rect
.pos
.x
+ (x
* rect
.size
.width
)/scr
->scr_width
;
1227 y
= rect
.pos
.y
+ (y
* rect
.size
.height
)/scr
->scr_height
;
1231 rect
= wGetRectForHead(scr
, head
);
1235 else if (x
+ width
> rect
.pos
.x
+ rect
.size
.width
)
1236 x
= rect
.pos
.x
+ rect
.size
.width
- width
;
1240 else if (y
+ height
> rect
.pos
.y
+ rect
.size
.height
)
1241 y
= rect
.pos
.y
+ rect
.size
.height
- height
;
1250 if (WFLAGP(wwin
, dont_move_off
) && dontBring
)
1251 wScreenBringInside(scr
, &x
, &y
, width
, height
);
1255 wNETWMPositionSplash(wwin
, &x
, &y
, width
, height
);
1258 if (wwin
->flags
.urgent
) {
1259 if (!IS_OMNIPRESENT(wwin
))
1260 wwin
->flags
.omnipresent
^= 1;
1264 *--------------------------------------------------
1266 * Create frame, borders and do reparenting
1268 *--------------------------------------------------
1270 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
1271 #ifdef XKB_BUTTON_HINT
1272 if (wPreferences
.modelock
)
1273 foo
|= WFF_LANGUAGE_BUTTON
;
1275 if (HAS_TITLEBAR(wwin
))
1276 foo
|= WFF_TITLEBAR
;
1277 if (HAS_RESIZEBAR(wwin
))
1278 foo
|= WFF_RESIZEBAR
;
1279 if (HAS_BORDER(wwin
))
1282 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
1283 x
, y
, width
, height
,
1284 &wPreferences
.window_title_clearance
, foo
,
1285 scr
->window_title_texture
,
1286 scr
->resizebar_texture
,
1287 scr
->window_title_color
,
1290 wwin
->frame
->flags
.is_client_window_frame
= 1;
1291 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1293 /* setup button images */
1294 wWindowUpdateButtonImages(wwin
);
1296 /* hide unused buttons */
1298 if (WFLAGP(wwin
, no_close_button
))
1299 foo
|= WFF_RIGHT_BUTTON
;
1300 if (WFLAGP(wwin
, no_miniaturize_button
))
1301 foo
|= WFF_LEFT_BUTTON
;
1302 #ifdef XKB_BUTTON_HINT
1303 if (WFLAGP(wwin
, no_language_button
) || WFLAGP(wwin
, no_focusable
))
1304 foo
|= WFF_LANGUAGE_BUTTON
;
1307 wFrameWindowHideButton(wwin
->frame
, foo
);
1309 wwin
->frame
->child
= wwin
;
1311 wwin
->frame
->workspace
= workspace
;
1313 wwin
->frame
->on_click_left
= windowIconifyClick
;
1314 #ifdef XKB_BUTTON_HINT
1315 if (wPreferences
.modelock
)
1316 wwin
->frame
->on_click_language
= windowLanguageClick
;
1319 wwin
->frame
->on_click_right
= windowCloseClick
;
1320 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
1322 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1323 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1325 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1328 XSelectInput(dpy
, wwin
->client_win
,
1329 wwin
->event_mask
& ~StructureNotifyMask
);
1331 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1332 0, wwin
->frame
->top_width
);
1334 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1340 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
1342 /* if gravity is to the south, account for the border sizes */
1344 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1348 * wWindowConfigure() will init the client window's size
1349 * (wwin->client.{width,height}) and all other geometry
1350 * related variables (frame_x,frame_y)
1352 wWindowConfigure(wwin
, x
, y
, width
, height
);
1354 /* to make sure the window receives it's new position after reparenting */
1355 wWindowSynthConfigureNotify(wwin
);
1358 *--------------------------------------------------
1360 * Setup descriptors and save window to internal
1363 *--------------------------------------------------
1366 if (wwin
->main_window
!=None
) {
1370 /* Leader windows do not necessary set themselves as leaders.
1371 * If this is the case, point the leader of this window to
1373 leader
= wWindowFor(wwin
->main_window
);
1374 if (leader
&& leader
->main_window
==None
) {
1375 leader
->main_window
= leader
->client_win
;
1377 app
= wApplicationCreate(wwin
);
1379 app
->last_workspace
= workspace
;
1382 * Do application specific stuff, like setting application
1386 if (wwin
->flags
.hidden
) {
1387 /* if the window was set to hidden because it was hidden
1388 * in a previous incarnation and that state was restored */
1389 app
->flags
.hidden
= 1;
1390 } else if (app
->flags
.hidden
) {
1391 if (WFLAGP(app
->main_window_desc
, start_hidden
)) {
1392 wwin
->flags
.hidden
= 1;
1394 wUnhideApplication(app
, False
, False
);
1401 /* setup the frame descriptor */
1402 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1403 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1404 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1406 /* don't let windows go away if we die */
1407 XAddToSaveSet(dpy
, window
);
1409 XLowerWindow(dpy
, window
);
1411 /* if window is in this workspace and should be mapped, then map it */
1412 if (!wwin
->flags
.miniaturized
1413 && (workspace
== scr
->current_workspace
|| IS_OMNIPRESENT(wwin
))
1414 && !wwin
->flags
.hidden
&& !withdraw
) {
1416 /* The following "if" is to avoid crashing of clients that expect
1417 * WM_STATE set before they get mapped. Else WM_STATE is set later,
1418 * after the return from this function.
1420 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
1421 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
1423 wClientSetState(wwin
, NormalState
, None
);
1427 /* if not auto focus, then map the window under the currently
1429 #define _WIDTH(w) (w)->frame->core->width
1430 #define _HEIGHT(w) (w)->frame->core->height
1431 if (!wPreferences
.auto_focus
&& scr
->focused_window
1432 && !scr
->flags
.startup
&& !transientOwner
1433 && ((wWindowObscuresWindow(wwin
, scr
->focused_window
)
1434 && (_WIDTH(wwin
) > (_WIDTH(scr
->focused_window
)*5)/3
1435 || _HEIGHT(wwin
) > (_HEIGHT(scr
->focused_window
)*5)/3)
1436 && WINDOW_LEVEL(scr
->focused_window
) == WINDOW_LEVEL(wwin
))
1437 || wwin
->flags
.maximized
)) {
1438 MoveInStackListUnder(scr
->focused_window
->frame
->core
,
1446 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
1447 && !scr
->flags
.startup
&&
1448 (wwin
->transient_for
==None
|| wwin
->transient_for
==scr
->root_win
)
1450 * The brain damaged idiotic non-click to focus modes will
1451 * have trouble with this because:
1453 * 1. window is created and mapped by the client
1454 * 2. window is mapped by wmaker in small size
1455 * 3. window is animated to grow to normal size
1456 * 4. this function returns to normal event loop
1457 * 5. eventually, the EnterNotify event that would trigger
1458 * the window focusing (if the mouse is over that window)
1459 * will be processed by wmaker.
1460 * But since this event will be rather delayed
1461 * (step 3 has a large delay) the time when the event ocurred
1462 * and when it is processed, the client that owns that window
1463 * will reject the XSetInputFocus() for it.
1465 && (wPreferences
.focus_mode
==WKF_CLICK
1466 || wPreferences
.auto_focus
)) {
1467 DoWindowBirth(wwin
);
1473 /* setup stacking descriptor */
1474 if (transientOwner
) {
1475 wwin
->frame
->core
->stacking
->child_of
= transientOwner
->frame
->core
;
1477 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1481 if (!scr
->focused_window
) {
1482 /* first window on the list */
1485 scr
->focused_window
= wwin
;
1489 /* add window at beginning of focus window list */
1490 tmp
= scr
->focused_window
;
1498 /* raise is set to true if we un-hid the app when this window was born.
1499 * we raise, else old windows of this app will be above this new one. */
1501 wRaiseFrame(wwin
->frame
->core
);
1504 /* Update name must come after WApplication stuff is done */
1505 wWindowUpdateName(wwin
, title
);
1512 *--------------------------------------------------
1514 * Final preparations before window is ready to go
1516 *--------------------------------------------------
1519 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1522 if (!wwin
->flags
.miniaturized
&& workspace
== scr
->current_workspace
1523 && !wwin
->flags
.hidden
) {
1524 if (((transientOwner
&& transientOwner
->flags
.focused
)
1525 || wPreferences
.auto_focus
) && !WFLAGP(wwin
, no_focusable
))
1526 wSetFocusTo(scr
, wwin
);
1528 wWindowResetMouseGrabs(wwin
);
1530 if (!WFLAGP(wwin
, no_bind_keys
)) {
1531 wWindowSetKeyGrabs(wwin
);
1535 WMPostNotificationName(WMNManaged
, wwin
, NULL
);
1538 wColormapInstallForWindow(scr
, scr
->cmap_window
);
1542 *------------------------------------------------------------
1543 * Setup Notification Observers
1544 *------------------------------------------------------------
1546 WMAddNotificationObserver(appearanceObserver
, wwin
,
1547 WNWindowAppearanceSettingsChanged
, wwin
);
1551 *--------------------------------------------------
1553 * Cleanup temporary stuff
1555 *--------------------------------------------------
1559 wWindowDeleteSavedState(win_state
);
1561 /* If the window must be withdrawed, then do it now.
1562 * Must do some optimization, 'though */
1564 wwin
->flags
.mapped
= 0;
1565 wClientSetState(wwin
, WithdrawnState
, None
);
1566 wUnmanageWindow(wwin
, True
, False
);
1578 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1579 char *title
, int x
, int y
, int width
, int height
)
1584 wwin
= wWindowCreate();
1586 WMAddNotificationObserver(appearanceObserver
, wwin
,
1587 WNWindowAppearanceSettingsChanged
, wwin
);
1589 wwin
->flags
.internal_window
= 1;
1591 WSETUFLAG(wwin
, omnipresent
, 1);
1592 WSETUFLAG(wwin
, no_shadeable
, 1);
1593 WSETUFLAG(wwin
, no_resizable
, 1);
1594 WSETUFLAG(wwin
, no_miniaturizable
, 1);
1596 wwin
->focus_mode
= WFM_PASSIVE
;
1598 wwin
->client_win
= window
;
1599 wwin
->screen_ptr
= scr
;
1601 wwin
->transient_for
= owner
;
1605 wwin
->client
.width
= width
;
1606 wwin
->client
.height
= height
;
1608 wwin
->frame_x
= wwin
->client
.x
;
1609 wwin
->frame_y
= wwin
->client
.y
;
1612 foo
= WFF_RIGHT_BUTTON
|WFF_BORDER
;
1613 foo
|= WFF_TITLEBAR
;
1614 #ifdef XKB_BUTTON_HINT
1615 foo
|= WFF_LANGUAGE_BUTTON
;
1618 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1619 wwin
->frame_x
, wwin
->frame_y
,
1621 &wPreferences
.window_title_clearance
, foo
,
1622 scr
->window_title_texture
,
1623 scr
->resizebar_texture
,
1624 scr
->window_title_color
,
1627 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1629 wwin
->frame
->flags
.is_client_window_frame
= 1;
1630 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1632 wFrameWindowChangeTitle(wwin
->frame
, title
);
1634 /* setup button images */
1635 wWindowUpdateButtonImages(wwin
);
1638 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1640 wwin
->frame
->child
= wwin
;
1642 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1644 #ifdef XKB_BUTTON_HINT
1645 if (wPreferences
.modelock
)
1646 wwin
->frame
->on_click_language
= windowLanguageClick
;
1649 wwin
->frame
->on_click_right
= windowCloseClick
;
1651 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1652 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1654 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1656 wwin
->client
.y
+= wwin
->frame
->top_width
;
1657 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1658 0, wwin
->frame
->top_width
);
1660 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1661 wwin
->client
.width
, wwin
->client
.height
);
1663 /* setup the frame descriptor */
1664 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1665 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1666 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1669 XLowerWindow(dpy
, window
);
1670 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1672 /* setup stacking descriptor */
1673 if (wwin
->transient_for
!=None
&& wwin
->transient_for
!=scr
->root_win
) {
1675 tmp
= wWindowFor(wwin
->transient_for
);
1677 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1679 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1683 if (!scr
->focused_window
) {
1684 /* first window on the list */
1687 scr
->focused_window
= wwin
;
1691 /* add window at beginning of focus window list */
1692 tmp
= scr
->focused_window
;
1700 if (wwin
->flags
.is_gnustep
== 0)
1701 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1703 /* if (wPreferences.auto_focus)*/
1704 wSetFocusTo(scr
, wwin
);
1706 wWindowResetMouseGrabs(wwin
);
1708 wWindowSetKeyGrabs(wwin
);
1715 *----------------------------------------------------------------------
1717 * Removes the frame window from a window and destroys all data
1718 * related to it. The window will be reparented back to the root window
1719 * if restore is True.
1722 * Everything related to the window is destroyed and the window
1723 * is removed from the window lists. Focus is set to the previous on the
1725 *----------------------------------------------------------------------
1728 wUnmanageWindow(WWindow
*wwin
, Bool restore
, Bool destroyed
)
1730 WCoreWindow
*frame
= wwin
->frame
->core
;
1731 WWindow
*owner
= NULL
;
1732 WWindow
*newFocusedWindow
= NULL
;
1734 WScreen
*scr
= wwin
->screen_ptr
;
1737 /* First close attribute editor window if open */
1738 if (wwin
->flags
.inspector_open
) {
1739 wCloseInspectorForWindow(wwin
);
1742 /* Close window menu if it's open for this window */
1743 if (wwin
->flags
.menu_open_for_me
) {
1744 CloseWindowMenu(scr
);
1748 if (!wwin
->flags
.internal_window
)
1749 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1751 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1753 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
1754 XUngrabKey(dpy
, AnyKey
, AnyModifier
, wwin
->client_win
);
1757 XUnmapWindow(dpy
, frame
->window
);
1759 XUnmapWindow(dpy
, wwin
->client_win
);
1761 /* deselect window */
1762 wSelectWindow(wwin
, False
);
1764 /* remove all pending events on window */
1765 /* I think this only matters for autoraise */
1766 if (wPreferences
.raise_delay
)
1767 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1771 /* reparent the window back to the root */
1773 wClientRestore(wwin
);
1775 if (wwin
->transient_for
!=scr
->root_win
) {
1776 owner
= wWindowFor(wwin
->transient_for
);
1778 if (!owner
->flags
.semi_focused
) {
1781 owner
->flags
.semi_focused
= 0;
1786 wasFocused
= wwin
->flags
.focused
;
1788 /* remove from window focus list */
1789 if (!wwin
->prev
&& !wwin
->next
) {
1790 /* was the only window */
1791 scr
->focused_window
= NULL
;
1792 newFocusedWindow
= NULL
;
1797 wwin
->prev
->next
= wwin
->next
;
1799 wwin
->next
->prev
= wwin
->prev
;
1801 scr
->focused_window
= wwin
->prev
;
1802 scr
->focused_window
->next
= NULL
;
1805 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1807 /* if in click to focus mode and the window
1808 * was a transient, focus the owner window
1811 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1812 tmp
= wWindowFor(wwin
->transient_for
);
1813 if (tmp
&& (!tmp
->flags
.mapped
|| WFLAGP(tmp
, no_focusable
))) {
1817 /* otherwise, focus the next one in the focus list */
1819 tmp
= scr
->focused_window
;
1820 while (tmp
) { /* look for one in the window list first */
1821 if (!WFLAGP(tmp
, no_focusable
) && !WFLAGP(tmp
, skip_window_list
)
1822 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1826 if (!tmp
) { /* if unsuccessful, choose any focusable window */
1827 tmp
= scr
->focused_window
;
1829 if (!WFLAGP(tmp
, no_focusable
)
1830 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1837 newFocusedWindow
= tmp
;
1839 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
) {
1844 /* This is to let the root window get the keyboard input
1845 * if Sloppy focus mode and no other window get focus.
1846 * This way keybindings will not freeze.
1849 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1850 &foo
, &foo
, &foo
, &foo
, &mask
))
1851 tmp
= wWindowFor(win
);
1854 newFocusedWindow
= tmp
;
1856 newFocusedWindow
= NULL
;
1860 if (!wwin
->flags
.internal_window
) {
1861 WMPostNotificationName(WMNUnmanaged
, wwin
, NULL
);
1865 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1866 (unsigned)frame
->window
);
1870 if (newFocusedWindow
!= owner
&& owner
) {
1871 if (wwin
->flags
.is_gnustep
== 0)
1872 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1874 wSetFocusTo(scr
, newFocusedWindow
);
1876 wWindowDestroy(wwin
);
1882 wWindowMap(WWindow
*wwin
)
1884 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1885 if (!wwin
->flags
.shaded
) {
1886 /* window will be remapped when getting MapNotify */
1887 XSelectInput(dpy
, wwin
->client_win
,
1888 wwin
->event_mask
& ~StructureNotifyMask
);
1889 XMapWindow(dpy
, wwin
->client_win
);
1890 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1892 wwin
->flags
.mapped
= 1;
1898 wWindowUnmap(WWindow
*wwin
)
1900 wwin
->flags
.mapped
= 0;
1902 /* prevent window withdrawal when getting UnmapNotify */
1903 XSelectInput(dpy
, wwin
->client_win
,
1904 wwin
->event_mask
& ~StructureNotifyMask
);
1905 XUnmapWindow(dpy
, wwin
->client_win
);
1906 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
1908 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1914 wWindowFocus(WWindow
*wwin
, WWindow
*owin
)
1919 #ifdef KEEP_XKB_LOCK_STATUS
1920 if (wPreferences
.modelock
) {
1921 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->frame
->languagemode
);
1923 #endif /* KEEP_XKB_LOCK_STATUS */
1925 wwin
->flags
.semi_focused
= 0;
1927 if (wwin
->flags
.is_gnustep
== 0)
1928 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1930 wwin
->flags
.focused
= 1;
1932 wWindowResetMouseGrabs(wwin
);
1934 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)True
);
1936 if (owin
== wwin
|| !owin
)
1939 nowner
= wWindowFor(wwin
->transient_for
);
1941 /* new window is a transient for the old window */
1942 if (nowner
== owin
) {
1943 owin
->flags
.semi_focused
= 1;
1944 wWindowUnfocus(nowner
);
1948 oowner
= wWindowFor(owin
->transient_for
);
1950 /* new window is owner of old window */
1951 if (wwin
== oowner
) {
1952 wWindowUnfocus(owin
);
1957 wWindowUnfocus(owin
);
1961 /* new window has same owner of old window */
1962 if (oowner
== nowner
) {
1963 /* prevent unfocusing of owner */
1964 oowner
->flags
.semi_focused
= 0;
1965 wWindowUnfocus(owin
);
1966 oowner
->flags
.semi_focused
= 1;
1971 /* nowner != NULL && oowner != nowner */
1972 nowner
->flags
.semi_focused
= 1;
1973 wWindowUnfocus(nowner
);
1974 wWindowUnfocus(owin
);
1979 wWindowUnfocus(WWindow
*wwin
)
1981 CloseWindowMenu(wwin
->screen_ptr
);
1983 if (wwin
->flags
.is_gnustep
== 0)
1984 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1985 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1987 if (wwin
->transient_for
!=None
1988 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1990 owner
= wWindowFor(wwin
->transient_for
);
1991 if (owner
&& owner
->flags
.semi_focused
) {
1992 owner
->flags
.semi_focused
= 0;
1993 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1994 wWindowUnfocus(owner
);
1995 wFrameWindowPaint(owner
->frame
);
1999 wwin
->flags
.focused
= 0;
2001 wWindowResetMouseGrabs(wwin
);
2003 WMPostNotificationName(WMNChangedFocus
, wwin
, (void*)False
);
2008 wWindowUpdateName(WWindow
*wwin
, char *newTitle
)
2015 wwin
->flags
.wm_name_changed
= 1;
2018 /* the hint was removed */
2019 title
= DEF_WINDOW_TITLE
;
2024 if (wFrameWindowChangeTitle(wwin
->frame
, title
)) {
2025 WMPostNotificationName(WMNChangedName
, wwin
, NULL
);
2032 *----------------------------------------------------------------------
2034 * wWindowConstrainSize--
2035 * Constrains size for the client window, taking the maximal size,
2036 * window resize increments and other size hints into account.
2039 * The closest size to what was given that the client window can
2042 *----------------------------------------------------------------------
2045 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
2047 int width
= *nwidth
;
2048 int height
= *nheight
;
2051 int minW
= 1, minH
= 1;
2052 int maxW
= wwin
->screen_ptr
->scr_width
*2;
2053 int maxH
= wwin
->screen_ptr
->scr_height
*2;
2054 int minAX
= -1, minAY
= -1;
2055 int maxAX
= -1, maxAY
= -1;
2059 if (wwin
->normal_hints
) {
2060 winc
= wwin
->normal_hints
->width_inc
;
2061 hinc
= wwin
->normal_hints
->height_inc
;
2062 minW
= wwin
->normal_hints
->min_width
;
2063 minH
= wwin
->normal_hints
->min_height
;
2064 maxW
= wwin
->normal_hints
->max_width
;
2065 maxH
= wwin
->normal_hints
->max_height
;
2066 if (wwin
->normal_hints
->flags
& PAspect
) {
2067 minAX
= wwin
->normal_hints
->min_aspect
.x
;
2068 minAY
= wwin
->normal_hints
->min_aspect
.y
;
2069 maxAX
= wwin
->normal_hints
->max_aspect
.x
;
2070 maxAY
= wwin
->normal_hints
->max_aspect
.y
;
2073 baseW
= wwin
->normal_hints
->base_width
;
2074 baseH
= wwin
->normal_hints
->base_height
;
2087 /* aspect ratio code borrowed from olwm */
2089 /* adjust max aspect ratio */
2090 if (!(maxAX
== 1 && maxAY
== 1) && width
* maxAY
> height
* maxAX
) {
2091 if (maxAX
> maxAY
) {
2092 height
= (width
* maxAY
) / maxAX
;
2093 if (height
> maxH
) {
2095 width
= (height
* maxAX
) / maxAY
;
2098 width
= (height
* maxAX
) / maxAY
;
2101 height
= (width
* maxAY
) / maxAX
;
2106 /* adjust min aspect ratio */
2107 if (!(minAX
== 1 && minAY
== 1) && width
* minAY
< height
* minAX
) {
2108 if (minAX
> minAY
) {
2109 height
= (width
* minAY
) / minAX
;
2110 if (height
< minH
) {
2112 width
= (height
* minAX
) / minAY
;
2115 width
= (height
* minAX
) / minAY
;
2118 height
= (width
* minAY
) / minAX
;
2125 width
= (((width
- baseW
) / winc
) * winc
) + baseW
;
2127 width
= (((width
- minW
) / winc
) * winc
) + minW
;
2131 height
= (((height
- baseH
) / hinc
) * hinc
) + baseH
;
2133 height
= (((height
- minH
) / hinc
) * hinc
) + minH
;
2136 /* broken stupid apps may cause preposterous values for these.. */
2145 wWindowCropSize(WWindow
*wwin
, int maxW
, int maxH
,
2146 int *width
, int *height
)
2148 int baseW
= 0, baseH
= 0;
2149 int winc
= 1, hinc
= 1;
2151 if (wwin
->normal_hints
) {
2152 baseW
= wwin
->normal_hints
->base_width
;
2153 baseH
= wwin
->normal_hints
->base_height
;
2155 winc
= wwin
->normal_hints
->width_inc
;
2156 hinc
= wwin
->normal_hints
->height_inc
;
2160 *width
= maxW
- (maxW
- baseW
) % winc
;
2163 *height
= maxH
- (maxH
- baseH
) % hinc
;
2168 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
2170 WScreen
*scr
= wwin
->screen_ptr
;
2174 if (workspace
>= scr
->workspace_count
|| workspace
< 0
2175 || workspace
== wwin
->frame
->workspace
)
2178 if (workspace
!= scr
->current_workspace
) {
2179 /* Sent to other workspace. Unmap window */
2180 if ((wwin
->flags
.mapped
2181 || wwin
->flags
.shaded
2182 || (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
))
2183 && !IS_OMNIPRESENT(wwin
) && !wwin
->flags
.changing_workspace
) {
2185 wapp
= wApplicationOf(wwin
->main_window
);
2187 wapp
->last_workspace
= workspace
;
2189 if (wwin
->flags
.miniaturized
) {
2191 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
2192 wwin
->icon
->mapped
= 0;
2196 wSetFocusTo(scr
, NULL
);
2200 /* brought to current workspace. Map window */
2201 if (wwin
->flags
.miniaturized
&& !wPreferences
.sticky_icons
) {
2203 XMapWindow(dpy
, wwin
->icon
->core
->window
);
2204 wwin
->icon
->mapped
= 1;
2206 } else if (!wwin
->flags
.mapped
&&
2207 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
2211 if (!IS_OMNIPRESENT(wwin
)) {
2212 int oldWorkspace
= wwin
->frame
->workspace
;
2214 wwin
->frame
->workspace
= workspace
;
2216 WMPostNotificationName(WMNChangedWorkspace
, wwin
, (void*)oldWorkspace
);
2226 wWindowSynthConfigureNotify(WWindow
*wwin
)
2230 sevent
.type
= ConfigureNotify
;
2231 sevent
.xconfigure
.display
= dpy
;
2232 sevent
.xconfigure
.event
= wwin
->client_win
;
2233 sevent
.xconfigure
.window
= wwin
->client_win
;
2235 sevent
.xconfigure
.x
= wwin
->client
.x
;
2236 sevent
.xconfigure
.y
= wwin
->client
.y
;
2237 sevent
.xconfigure
.width
= wwin
->client
.width
;
2238 sevent
.xconfigure
.height
= wwin
->client
.height
;
2240 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
2241 if (!HAS_TITLEBAR(wwin
))
2242 sevent
.xconfigure
.above
= None
;
2244 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
2246 sevent
.xconfigure
.override_redirect
= False
;
2247 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
2253 *----------------------------------------------------------------------
2254 * wWindowConfigure--
2255 * Configures the frame, decorations and client window to the
2256 * specified geometry. The geometry is not checked for validity,
2257 * wWindowConstrainSize() must be used for that.
2258 * The size parameters are for the client window, but the position is
2260 * The client window receives a ConfigureNotify event, according
2261 * to what ICCCM says.
2267 * Window size and position are changed and client window receives
2268 * a ConfigureNotify event.
2269 *----------------------------------------------------------------------
2272 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
2274 int req_x
, req_y
; /* new position of the frame */
2275 int req_width
, req_height
; /* new size of the client */
2277 int synth_notify
= False
;
2280 resize
= (req_width
!=wwin
->client
.width
2281 || req_height
!=wwin
->client
.height
);
2283 * if the window is being moved but not resized then
2284 * send a synthetic ConfigureNotify
2286 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
2287 synth_notify
= True
;
2290 if (WFLAGP(wwin
, dont_move_off
))
2291 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2292 req_width
, req_height
);
2294 if (req_width
< MIN_WINDOW_SIZE
)
2295 req_width
= MIN_WINDOW_SIZE
;
2296 if (req_height
< MIN_WINDOW_SIZE
)
2297 req_height
= MIN_WINDOW_SIZE
;
2299 /* If growing, resize inner part before frame,
2300 * if shrinking, resize frame before.
2301 * This will prevent the frame (that can have a different color)
2302 * to be exposed, causing flicker */
2303 if (req_height
> wwin
->frame
->core
->height
2304 || req_width
> wwin
->frame
->core
->width
)
2305 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2307 if (wwin
->flags
.shaded
) {
2308 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
,
2309 req_width
, wwin
->frame
->core
->height
);
2310 wwin
->old_geometry
.height
= req_height
;
2314 h
= req_height
+ wwin
->frame
->top_width
2315 + wwin
->frame
->bottom_width
;
2317 wFrameWindowConfigure(wwin
->frame
, req_x
, req_y
, req_width
, h
);
2320 if (!(req_height
> wwin
->frame
->core
->height
2321 || req_width
> wwin
->frame
->core
->width
))
2322 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
2324 wwin
->client
.x
= req_x
;
2325 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2326 wwin
->client
.width
= req_width
;
2327 wwin
->client
.height
= req_height
;
2329 wwin
->client
.x
= req_x
;
2330 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2332 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2334 wwin
->frame_x
= req_x
;
2335 wwin
->frame_y
= req_y
;
2336 if (HAS_BORDER(wwin
)) {
2337 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2338 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2342 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
2343 wWindowSetShape(wwin
);
2348 wWindowSynthConfigureNotify(wwin
);
2354 wWindowMove(wwin
, req_x
, req_y
)
2356 int req_x
, req_y
; /* new position of the frame */
2358 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2359 int synth_notify
= False
;
2361 /* Send a synthetic ConfigureNotify event for every window movement. */
2362 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
2363 synth_notify
= True
;
2366 /* A single synthetic ConfigureNotify event is sent at the end of
2367 * a completed (opaque) movement in moveres.c */
2370 if (WFLAGP(wwin
, dont_move_off
))
2371 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
2372 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
2374 wwin
->client
.x
= req_x
;
2375 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
2376 if (HAS_BORDER(wwin
)) {
2377 wwin
->client
.x
+= FRAME_BORDER_WIDTH
;
2378 wwin
->client
.y
+= FRAME_BORDER_WIDTH
;
2381 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
2383 wwin
->frame_x
= req_x
;
2384 wwin
->frame_y
= req_y
;
2386 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
2388 wWindowSynthConfigureNotify(wwin
);
2394 wWindowUpdateButtonImages(WWindow
*wwin
)
2396 WScreen
*scr
= wwin
->screen_ptr
;
2397 Pixmap pixmap
, mask
;
2398 WFrameWindow
*fwin
= wwin
->frame
;
2400 if (!HAS_TITLEBAR(wwin
))
2403 /* miniaturize button */
2405 if (!WFLAGP(wwin
, no_miniaturize_button
)) {
2406 if (wwin
->wm_gnustep_attr
2407 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
2408 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
2410 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
2411 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
2416 if (fwin
->lbutton_image
2417 && (fwin
->lbutton_image
->image
!= pixmap
2418 || fwin
->lbutton_image
->mask
!= mask
)) {
2419 wPixmapDestroy(fwin
->lbutton_image
);
2420 fwin
->lbutton_image
= NULL
;
2423 if (!fwin
->lbutton_image
) {
2424 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2425 fwin
->lbutton_image
->client_owned
= 1;
2426 fwin
->lbutton_image
->client_owned_mask
= 1;
2429 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
2430 wPixmapDestroy(fwin
->lbutton_image
);
2432 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
2436 #ifdef XKB_BUTTON_HINT
2437 if (!WFLAGP(wwin
, no_language_button
)) {
2438 if (fwin
->languagebutton_image
&&
2439 !fwin
->languagebutton_image
->shared
) {
2440 wPixmapDestroy(fwin
->languagebutton_image
);
2442 fwin
->languagebutton_image
=
2443 scr
->b_pixmaps
[WBUT_XKBGROUP1
+ fwin
->languagemode
];
2449 /* redefine WFLAGP to MGFLAGP to allow broken close operation */
2450 #define MGFLAGP(wwin, FLAG) (wwin)->client_flags.FLAG
2452 if (!WFLAGP(wwin
, no_close_button
)) {
2453 if (wwin
->wm_gnustep_attr
2454 && wwin
->wm_gnustep_attr
->flags
& GSClosePixmapAttr
) {
2455 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
2457 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
)
2458 mask
= wwin
->wm_gnustep_attr
->close_mask
;
2462 if (fwin
->rbutton_image
&& (fwin
->rbutton_image
->image
!= pixmap
2463 || fwin
->rbutton_image
->mask
!= mask
)) {
2464 wPixmapDestroy(fwin
->rbutton_image
);
2465 fwin
->rbutton_image
= NULL
;
2468 if (!fwin
->rbutton_image
) {
2469 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
2470 fwin
->rbutton_image
->client_owned
= 1;
2471 fwin
->rbutton_image
->client_owned_mask
= 1;
2474 } else if (WFLAGP(wwin
, kill_close
)) {
2476 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2477 wPixmapDestroy(fwin
->rbutton_image
);
2479 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
2481 } else if (MGFLAGP(wwin
, broken_close
)) {
2483 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2484 wPixmapDestroy(fwin
->rbutton_image
);
2486 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
2490 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
)
2491 wPixmapDestroy(fwin
->rbutton_image
);
2493 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
2497 /* force buttons to be redrawn */
2498 fwin
->flags
.need_texture_change
= 1;
2499 wFrameWindowPaint(fwin
);
2504 *---------------------------------------------------------------------------
2505 * wWindowConfigureBorders--
2506 * Update window border configuration according to attribute flags.
2508 *---------------------------------------------------------------------------
2511 wWindowConfigureBorders(WWindow
*wwin
)
2517 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
2519 #ifdef XKB_BUTTON_HINT
2520 flags
|= WFF_LANGUAGE_BUTTON
;
2523 if (HAS_TITLEBAR(wwin
))
2524 flags
|= WFF_TITLEBAR
;
2525 if (HAS_RESIZEBAR(wwin
) && IS_RESIZABLE(wwin
))
2526 flags
|= WFF_RESIZEBAR
;
2527 if (HAS_BORDER(wwin
))
2528 flags
|= WFF_BORDER
;
2529 if (wwin
->flags
.shaded
)
2530 flags
|= WFF_IS_SHADED
;
2532 oldh
= wwin
->frame
->top_width
;
2533 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
2534 if (oldh
!= wwin
->frame
->top_width
) {
2535 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
2537 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2538 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
2539 wwin
->client
.width
, wwin
->client
.height
);
2543 if (!WFLAGP(wwin
, no_miniaturize_button
)
2544 && wwin
->frame
->flags
.hide_left_button
)
2545 flags
|= WFF_LEFT_BUTTON
;
2547 #ifdef XKB_BUTTON_HINT
2548 if (!WFLAGP(wwin
, no_language_button
)
2549 && wwin
->frame
->flags
.hide_language_button
) {
2550 flags
|= WFF_LANGUAGE_BUTTON
;
2554 if (!WFLAGP(wwin
, no_close_button
)
2555 && wwin
->frame
->flags
.hide_right_button
)
2556 flags
|= WFF_RIGHT_BUTTON
;
2559 wWindowUpdateButtonImages(wwin
);
2560 wFrameWindowShowButton(wwin
->frame
, flags
);
2564 if (WFLAGP(wwin
, no_miniaturize_button
)
2565 && !wwin
->frame
->flags
.hide_left_button
)
2566 flags
|= WFF_LEFT_BUTTON
;
2568 #ifdef XKB_BUTTON_HINT
2569 if (WFLAGP(wwin
, no_language_button
)
2570 && !wwin
->frame
->flags
.hide_language_button
)
2571 flags
|= WFF_LANGUAGE_BUTTON
;
2574 if (WFLAGP(wwin
, no_close_button
)
2575 && !wwin
->frame
->flags
.hide_right_button
)
2576 flags
|= WFF_RIGHT_BUTTON
;
2579 wFrameWindowHideButton(wwin
->frame
, flags
);
2582 if (wShapeSupported
&& wwin
->flags
.shaped
) {
2583 wWindowSetShape(wwin
);
2591 wWindowSaveState(WWindow
*wwin
)
2596 memset(data
, 0, sizeof(CARD32
)*10);
2597 data
[0] = wwin
->frame
->workspace
;
2598 data
[1] = wwin
->flags
.miniaturized
;
2599 data
[2] = wwin
->flags
.shaded
;
2600 data
[3] = wwin
->flags
.hidden
;
2601 data
[4] = wwin
->flags
.maximized
;
2602 if (wwin
->flags
.maximized
== 0) {
2603 data
[5] = wwin
->frame_x
;
2604 data
[6] = wwin
->frame_y
;
2605 data
[7] = wwin
->frame
->core
->width
;
2606 data
[8] = wwin
->frame
->core
->height
;
2608 data
[5] = wwin
->old_geometry
.x
;
2609 data
[6] = wwin
->old_geometry
.y
;
2610 data
[7] = wwin
->old_geometry
.width
;
2611 data
[8] = wwin
->old_geometry
.height
;
2614 for (i
= 0; i
< MAX_WINDOW_SHORTCUTS
; i
++) {
2615 if (wwin
->screen_ptr
->shortcutWindows
[i
] &&
2616 WMCountInArray(wwin
->screen_ptr
->shortcutWindows
[i
], wwin
))
2619 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
2620 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
2621 (unsigned char *)data
, 10);
2626 getSavedState(Window window
, WSavedState
**state
)
2630 unsigned long nitems_ret
;
2631 unsigned long bytes_after_ret
;
2634 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 10,
2635 True
, _XA_WINDOWMAKER_STATE
,
2636 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
2637 (unsigned char **)&data
)!=Success
|| !data
)
2640 *state
= wmalloc(sizeof(WSavedState
));
2642 (*state
)->workspace
= data
[0];
2643 (*state
)->miniaturized
= data
[1];
2644 (*state
)->shaded
= data
[2];
2645 (*state
)->hidden
= data
[3];
2646 (*state
)->maximized
= data
[4];
2647 (*state
)->x
= data
[5];
2648 (*state
)->y
= data
[6];
2649 (*state
)->w
= data
[7];
2650 (*state
)->h
= data
[8];
2651 (*state
)->window_shortcuts
= data
[9];
2655 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
2664 wWindowClearShape(WWindow
*wwin
)
2666 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2667 0, wwin
->frame
->top_width
, None
, ShapeSet
);
2672 wWindowSetShape(WWindow
*wwin
)
2676 #ifdef OPTIMIZE_SHAPE
2681 /* only shape is the client's */
2682 if (!HAS_TITLEBAR(wwin
) && !HAS_RESIZEBAR(wwin
)) {
2686 /* Get array of rectangles describing the shape mask */
2687 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
2693 urec
= malloc(sizeof(XRectangle
)*(count
+2));
2699 /* insert our decoration rectangles in the rect list */
2700 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
2703 if (HAS_TITLEBAR(wwin
)) {
2705 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
2706 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2707 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
2710 if (HAS_RESIZEBAR(wwin
)) {
2712 urec
[count
].y
= wwin
->frame
->core
->height
2713 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
2714 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
2715 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2719 /* shape our frame window */
2720 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2721 0, wwin
->frame
->top_width
, urec
, count
,
2722 ShapeSet
, Unsorted
);
2728 #endif /* OPTIMIZE_SHAPE */
2730 if (HAS_TITLEBAR(wwin
)) {
2733 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2734 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
2737 if (HAS_RESIZEBAR(wwin
)) {
2739 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
2740 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
2741 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
2745 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2746 0, 0, rect
, count
, ShapeSet
, Unsorted
);
2748 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
2749 0, wwin
->frame
->top_width
, wwin
->client_win
,
2750 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
2755 /* ====================================================================== */
2758 getFocusMode(WWindow
*wwin
)
2762 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2763 if (wwin
->wm_hints
->input
== True
) {
2764 if (wwin
->protocols
.TAKE_FOCUS
)
2765 mode
= WFM_LOCALLY_ACTIVE
;
2769 if (wwin
->protocols
.TAKE_FOCUS
)
2770 mode
= WFM_GLOBALLY_ACTIVE
;
2772 mode
= WFM_NO_INPUT
;
2782 wWindowSetKeyGrabs(WWindow
*wwin
)
2787 for (i
=0; i
<WKBD_LAST
; i
++) {
2788 key
= &wKeyBindings
[i
];
2790 if (key
->keycode
==0)
2792 if (key
->modifier
!=AnyModifier
) {
2793 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2794 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2796 /* Also grab all modifier combinations possible that include,
2797 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2798 * work even if the NumLock/ScrollLock key is on.
2800 wHackedGrabKey(key
->keycode
, key
->modifier
,
2801 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2805 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2806 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2810 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2817 wWindowResetMouseGrabs(WWindow
*wwin
)
2819 /* Mouse grabs can't be done on the client window because of
2820 * ICCCM and because clients that try to do the same will crash.
2822 * But there is a problem wich makes tbar buttons of unfocused
2823 * windows not usable as the click goes to the frame window instead
2824 * of the button itself. Must figure a way to fix that.
2827 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2829 if (!WFLAGP(wwin
, no_bind_mouse
)) {
2830 /* grabs for Meta+drag */
2831 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2832 True
, ButtonPressMask
|ButtonReleaseMask
,
2833 GrabModeSync
, GrabModeAsync
, None
, None
);
2836 if (!wwin
->flags
.focused
&& !WFLAGP(wwin
, no_focusable
)
2837 && !wwin
->flags
.is_gnustep
) {
2838 /* the passive grabs to focus the window */
2839 /* if (wPreferences.focus_mode == WKF_CLICK) */
2840 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2841 True
, ButtonPressMask
|ButtonReleaseMask
,
2842 GrabModeSync
, GrabModeAsync
, None
, None
);
2849 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2851 if (attr
->flags
& GSExtraFlagsAttr
) {
2852 if (MGFLAGP(wwin
, broken_close
) !=
2853 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2854 wwin
->client_flags
.broken_close
= !MGFLAGP(wwin
, broken_close
);
2855 wWindowUpdateButtonImages(wwin
);
2862 wWindowAddSavedState(char *instance
, char *class, char *command
,
2863 pid_t pid
, WSavedState
*state
)
2865 WWindowState
*wstate
;
2867 wstate
= malloc(sizeof(WWindowState
));
2871 memset(wstate
, 0, sizeof(WWindowState
));
2874 wstate
->instance
= wstrdup(instance
);
2876 wstate
->class = wstrdup(class);
2878 wstate
->command
= wstrdup(command
);
2879 wstate
->state
= state
;
2881 wstate
->next
= windowState
;
2882 windowState
= wstate
;
2885 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2893 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2897 wWindowGetSavedState(Window win
)
2899 char *instance
, *class, *command
=NULL
;
2900 WWindowState
*wstate
= windowState
;
2905 command
= GetCommandForWindow(win
);
2909 if (PropGetWMClass(win
, &class, &instance
)) {
2911 if (SAME(instance
, wstate
->instance
) &&
2912 SAME(class, wstate
->class) &&
2913 SAME(command
, wstate
->command
)) {
2916 wstate
= wstate
->next
;
2923 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2927 if (command
) wfree(command
);
2928 if (instance
) XFree(instance
);
2929 if (class) XFree(class);
2936 wWindowDeleteSavedState(WMagicNumber id
)
2938 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2940 if (!wstate
|| !windowState
)
2945 windowState
= wstate
->next
;
2947 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2948 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2950 if (wstate
->instance
) wfree(wstate
->instance
);
2951 if (wstate
->class) wfree(wstate
->class);
2952 if (wstate
->command
) wfree(wstate
->command
);
2953 wfree(wstate
->state
);
2957 if (tmp
->next
==wstate
) {
2958 tmp
->next
=wstate
->next
;
2960 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2961 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2963 if (wstate
->instance
) wfree(wstate
->instance
);
2964 if (wstate
->class) wfree(wstate
->class);
2965 if (wstate
->command
) wfree(wstate
->command
);
2966 wfree(wstate
->state
);
2977 wWindowDeleteSavedStatesForPID(pid_t pid
)
2979 WWindowState
*tmp
, *wstate
;
2985 if (tmp
->pid
== pid
) {
2986 wstate
= windowState
;
2987 windowState
= tmp
->next
;
2989 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2990 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2992 if (wstate
->instance
) wfree(wstate
->instance
);
2993 if (wstate
->class) wfree(wstate
->class);
2994 if (wstate
->command
) wfree(wstate
->command
);
2995 wfree(wstate
->state
);
2999 if (tmp
->next
->pid
==pid
) {
3001 tmp
->next
= wstate
->next
;
3003 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
3004 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
3006 if (wstate
->instance
) wfree(wstate
->instance
);
3007 if (wstate
->class) wfree(wstate
->class);
3008 if (wstate
->command
) wfree(wstate
->command
);
3009 wfree(wstate
->state
);
3020 wWindowSetOmnipresent(WWindow
*wwin
, Bool flag
)
3022 if (wwin
->flags
.omnipresent
== flag
)
3025 wwin
->flags
.omnipresent
= flag
;
3026 WMPostNotificationName(WMNChangedState
, wwin
, "omnipresent");
3030 /* ====================================================================== */
3033 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3035 WWindow
*wwin
= data
;
3037 #ifndef NUMLOCK_HACK
3038 if ((event
->xbutton
.state
& ValidModMask
)
3039 != (event
->xbutton
.state
& ~LockMask
)) {
3040 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3041 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3045 event
->xbutton
.state
&= ValidModMask
;
3047 CloseWindowMenu(wwin
->screen_ptr
);
3049 if (wPreferences
.focus_mode
==WKF_CLICK
3050 && !(event
->xbutton
.state
&ControlMask
)
3051 && !WFLAGP(wwin
, no_focusable
)) {
3052 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3055 if (event
->xbutton
.button
== Button1
)
3056 wRaiseFrame(wwin
->frame
->core
);
3058 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
3059 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
3060 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3061 GrabModeAsync
, GrabModeAsync
, None
,
3062 None
, CurrentTime
)!=GrabSuccess
) {
3064 wwarning("pointer grab failed for window move");
3070 if (event
->xbutton
.state
& MOD_MASK
) {
3071 /* move the window */
3072 wMouseMoveWindow(wwin
, event
);
3073 XUngrabPointer(dpy
, CurrentTime
);
3075 wMouseResizeWindow(wwin
, event
);
3076 XUngrabPointer(dpy
, CurrentTime
);
3083 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3085 WWindow
*wwin
= data
;
3087 event
->xbutton
.state
&= ValidModMask
;
3089 if (event
->xbutton
.button
==Button1
) {
3090 if (event
->xbutton
.state
== 0) {
3091 if (!WFLAGP(wwin
, no_shadeable
)) {
3093 if (wwin
->flags
.shaded
)
3094 wUnshadeWindow(wwin
);
3101 if (event
->xbutton
.state
& ControlMask
)
3102 dir
|= MAX_VERTICAL
;
3104 if (event
->xbutton
.state
& ShiftMask
) {
3105 dir
|= MAX_HORIZONTAL
;
3106 if (!(event
->xbutton
.state
& ControlMask
))
3107 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3110 /* maximize window */
3111 if (dir
!=0 && IS_RESIZABLE(wwin
)) {
3112 int ndir
= dir
^ wwin
->flags
.maximized
;
3115 wMaximizeWindow(wwin
, ndir
);
3117 wUnmaximizeWindow(wwin
);
3121 } else if (event
->xbutton
.button
==Button3
) {
3122 if (event
->xbutton
.state
& MOD_MASK
) {
3123 wHideOtherApplications(wwin
);
3125 } else if (event
->xbutton
.button
==Button2
) {
3126 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3127 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelUp
) {
3129 } else if (event
->xbutton
.button
== WINGsConfiguration
.mouseWheelDown
) {
3130 wUnshadeWindow(wwin
);
3136 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
3138 WWindow
*wwin
= desc
->parent
;
3140 event
->xbutton
.state
&= ValidModMask
;
3142 CloseWindowMenu(wwin
->screen_ptr
);
3144 if (/*wPreferences.focus_mode==WKF_CLICK
3145 &&*/ !(event
->xbutton
.state
&ControlMask
)
3146 && !WFLAGP(wwin
, no_focusable
)) {
3147 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3149 if (event
->xbutton
.button
== Button1
) {
3150 wRaiseFrame(wwin
->frame
->core
);
3153 if (event
->xbutton
.state
& MOD_MASK
) {
3154 /* move the window */
3155 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
3156 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3157 GrabModeAsync
, GrabModeAsync
, None
,
3158 None
, CurrentTime
)!=GrabSuccess
) {
3160 wwarning("pointer grab failed for window move");
3164 if (event
->xbutton
.button
== Button3
)
3165 wMouseResizeWindow(wwin
, event
);
3166 else if (event
->xbutton
.button
==Button1
|| event
->xbutton
.button
==Button2
)
3167 wMouseMoveWindow(wwin
, event
);
3168 XUngrabPointer(dpy
, CurrentTime
);
3174 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3176 WWindow
*wwin
= (WWindow
*)data
;
3178 #ifndef NUMLOCK_HACK
3179 if ((event
->xbutton
.state
& ValidModMask
)
3180 != (event
->xbutton
.state
& ~LockMask
)) {
3181 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
3182 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
3185 event
->xbutton
.state
&= ValidModMask
;
3187 CloseWindowMenu(wwin
->screen_ptr
);
3189 if (wPreferences
.focus_mode
==WKF_CLICK
3190 && !(event
->xbutton
.state
&ControlMask
)
3191 && !WFLAGP(wwin
, no_focusable
)) {
3192 wSetFocusTo(wwin
->screen_ptr
, wwin
);
3195 if (event
->xbutton
.button
== Button1
3196 || event
->xbutton
.button
== Button2
) {
3198 if (event
->xbutton
.button
== Button1
) {
3199 if (event
->xbutton
.state
& MOD_MASK
) {
3200 wLowerFrame(wwin
->frame
->core
);
3202 wRaiseFrame(wwin
->frame
->core
);
3205 if ((event
->xbutton
.state
& ShiftMask
)
3206 && !(event
->xbutton
.state
& ControlMask
)) {
3207 wSelectWindow(wwin
, !wwin
->flags
.selected
);
3210 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3211 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3212 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3213 GrabModeAsync
, GrabModeAsync
, None
,
3214 None
, CurrentTime
)!=GrabSuccess
) {
3216 wwarning("pointer grab failed for window move");
3221 /* move the window */
3222 wMouseMoveWindow(wwin
, event
);
3224 XUngrabPointer(dpy
, CurrentTime
);
3225 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
3226 && !wwin
->flags
.internal_window
3227 && !WCHECK_STATE(WSTATE_MODAL
)) {
3228 WObjDescriptor
*desc
;
3230 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
3231 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
3232 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
3233 GrabModeAsync
, GrabModeAsync
, None
,
3234 None
, CurrentTime
)!=GrabSuccess
) {
3236 wwarning("pointer grab failed for window move");
3241 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
3242 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
3244 /* allow drag select */
3245 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
3246 event
->xany
.send_event
= True
;
3247 (*desc
->handle_mousedown
)(desc
, event
);
3249 XUngrabPointer(dpy
, CurrentTime
);
3256 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3258 WWindow
*wwin
= data
;
3260 event
->xbutton
.state
&= ValidModMask
;
3262 CloseWindowMenu(wwin
->screen_ptr
);
3264 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3267 /* if control-click, kill the client */
3268 if (event
->xbutton
.state
& ControlMask
) {
3271 if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
3272 /* send delete message */
3273 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3280 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3282 WWindow
*wwin
= data
;
3284 CloseWindowMenu(wwin
->screen_ptr
);
3286 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3289 /* send delete message */
3290 if (wwin
->protocols
.DELETE_WINDOW
) {
3291 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
3298 #ifdef XKB_BUTTON_HINT
3300 windowLanguageClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3302 WWindow
*wwin
= data
;
3303 WFrameWindow
*fwin
= wwin
->frame
;
3304 WScreen
*scr
= fwin
->screen_ptr
;
3305 XkbStateRec staterec
;
3308 if (event
->xbutton
.button
!= Button1
&& event
->xbutton
.button
!= Button3
)
3310 tl
= wwin
->frame
->languagemode
;
3311 wwin
->frame
->languagemode
= wwin
->frame
->last_languagemode
;
3312 wwin
->frame
->last_languagemode
= tl
;
3313 wSetFocusTo(scr
, wwin
);
3314 wwin
->frame
->languagebutton_image
=
3315 wwin
->frame
->screen_ptr
->b_pixmaps
[WBUT_XKBGROUP1
+
3316 wwin
->frame
->languagemode
];
3317 wFrameWindowUpdateLanguageButton(wwin
->frame
);
3318 if (event
->xbutton
.button
== Button3
)
3320 wRaiseFrame(fwin
->core
);
3326 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
3328 WWindow
*wwin
= data
;
3330 event
->xbutton
.state
&= ValidModMask
;
3332 CloseWindowMenu(wwin
->screen_ptr
);
3334 if (event
->xbutton
.button
< Button1
|| event
->xbutton
.button
> Button3
)
3337 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
3338 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
3342 if ((event
->xbutton
.state
& ControlMask
) ||
3343 (event
->xbutton
.button
== Button3
)) {
3345 wapp
= wApplicationOf(wwin
->main_window
);
3346 if (wapp
&& !WFLAGP(wwin
, no_appicon
))
3347 wHideApplication(wapp
);
3348 } else if (event
->xbutton
.state
==0) {
3349 wIconifyWindow(wwin
);