1 /* window.c - client window managing class
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 #include <X11/Xutil.h>
28 #include <X11/extensions/shape.h>
30 #ifdef KEEP_XKB_LOCK_STATUS
31 # include <X11/XKBlib.h>
32 #endif /* KEEP_XKB_LOCK_STATUS */
38 #include "WindowMaker.h"
47 #include "winspector.h"
49 #include "properties.h"
56 #include "workspace.h"
58 /****** Global Variables ******/
60 extern WShortKey wKeyBindings
[WKBD_LAST
];
63 extern Bool wShapeSupported
;
67 extern XContext wWinContext
;
70 extern Cursor wCursor
[WCUR_LAST
];
73 extern Atom _XA_WM_DELETE_WINDOW
;
74 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
76 extern Atom _XA_WINDOWMAKER_STATE
;
78 extern WPreferences wPreferences
;
80 #define MOD_MASK wPreferences.modifier_mask
82 extern Time LastTimestamp
;
85 extern void DoWindowBirth(WWindow
*);
88 /***** Local Stuff *****/
91 static WWindowState
*windowState
=NULL
;
96 static FocusMode
getFocusMode(WWindow
*wwin
);
98 static int getSavedState(Window window
, WSavedState
**state
);
100 static void setupGNUstepHints(WWindowAttributes
*attribs
,
101 GNUstepWMAttributes
*gs_hints
);
104 static void setupMWMHints(WWindowAttributes
*attribs
, MWMHints
*mwm_hints
);
110 /* frame window (during window grabs) */
111 static void frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
);
114 static void windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
115 static void windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
118 static void windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
121 static void titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
122 static void titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
);
124 static void resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
);
132 wWindowFor(Window window
)
134 WObjDescriptor
*desc
;
139 if (XFindContext(dpy
, window
, wWinContext
, (XPointer
*)&desc
)==XCNOENT
)
142 if (desc
->parent_type
==WCLASS_WINDOW
)
144 else if (desc
->parent_type
==WCLASS_FRAME
) {
145 WFrameWindow
*frame
= (WFrameWindow
*)desc
->parent
;
146 if (frame
->flags
.is_client_window_frame
)
158 wwin
= wmalloc(sizeof(WWindow
));
161 memset(wwin
, 0, sizeof(WWindow
));
163 wwin
->client_descriptor
.handle_mousedown
= frameMouseDown
;
164 wwin
->client_descriptor
.parent
= wwin
;
165 wwin
->client_descriptor
.self
= wwin
;
166 wwin
->client_descriptor
.parent_type
= WCLASS_WINDOW
;
172 wWindowDestroy(WWindow
*wwin
)
176 wwin
->flags
.destroyed
= 1;
178 for (i
= 0; i
< 4; i
++) {
179 if (wwin
->screen_ptr
->shortcutWindow
[i
] == wwin
) {
180 wwin
->screen_ptr
->shortcutWindow
[i
] = NULL
;
184 if (wwin
->normal_hints
)
185 free(wwin
->normal_hints
);
188 XFree(wwin
->wm_hints
);
190 if (wwin
->wm_instance
)
191 XFree(wwin
->wm_instance
);
194 XFree(wwin
->wm_class
);
196 if (wwin
->wm_gnustep_attr
)
197 free(wwin
->wm_gnustep_attr
);
199 if (wwin
->cmap_windows
)
200 XFree(wwin
->cmap_windows
);
202 XDeleteContext(dpy
, wwin
->client_win
, wWinContext
);
205 wFrameWindowDestroy(wwin
->frame
);
208 RemoveFromStackList(wwin
->icon
->core
);
209 wIconDestroy(wwin
->icon
);
210 if (wPreferences
.auto_arrange_icons
)
211 wArrangeIcons(wwin
->screen_ptr
, True
);
220 setupGNUstepHints(WWindowAttributes
*attribs
, GNUstepWMAttributes
*gs_hints
)
222 if (gs_hints
->flags
& GSWindowStyleAttr
) {
223 attribs
->no_titlebar
=
224 ((gs_hints
->window_style
& WMTitledWindowMask
)?0:1);
226 attribs
->no_close_button
= attribs
->no_closable
=
227 ((gs_hints
->window_style
& WMClosableWindowMask
)?0:1);
229 attribs
->no_miniaturize_button
= attribs
->no_miniaturizable
=
230 ((gs_hints
->window_style
& WMMiniaturizableWindowMask
)?0:1);
232 attribs
->no_resizebar
= attribs
->no_resizable
=
233 ((gs_hints
->window_style
& WMResizableWindowMask
)?0:1);
235 /* setup the defaults */
236 attribs
->no_titlebar
= 0;
237 attribs
->no_closable
= 0;
238 attribs
->no_miniaturizable
= 0;
239 attribs
->no_resizable
= 0;
240 attribs
->no_close_button
= 0;
241 attribs
->no_miniaturize_button
= 0;
242 attribs
->no_resizebar
= 0;
245 if (gs_hints
->extra_flags
& GSNoApplicationIconFlag
) {
246 attribs
->no_appicon
= 1;
253 setupMWMHints(WWindowAttributes
*attribs
, MWMHints
*mwm_hints
)
257 * We will ignore all decoration hints that have an equivalent as
258 * functions, because wmaker does not distinguish decoration hints
261 if (mwm_hints
->flags
& MWM_HINTS_DECORATIONS
) {
263 fprintf(stderr
,"has decor hints [ ");
265 attribs
->no_titlebar
= 1;
266 attribs
->no_close_button
= 1;
267 attribs
->no_miniaturize_button
= 1;
268 attribs
->no_resizebar
= 1;
270 if (mwm_hints
->decorations
& MWM_DECOR_ALL
) {
272 fprintf(stderr
,"ALL ");
274 attribs
->no_titlebar
= 0;
275 attribs
->no_close_button
= 0;
276 attribs
->no_closable
= 0;
277 attribs
->no_miniaturize_button
= 0;
278 attribs
->no_miniaturizable
= 0;
279 attribs
->no_resizebar
= 0;
280 attribs
->no_resizable
= 0;
283 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
285 fprintf(stderr,"(BORDER) ");
290 if (mwm_hints
->decorations
& MWM_DECOR_RESIZEH
) {
292 fprintf(stderr
,"RESIZEH ");
294 attribs
->no_resizebar
= 0;
297 if (mwm_hints
->decorations
& MWM_DECOR_TITLE
) {
299 fprintf(stderr
,"TITLE+close ");
301 attribs
->no_titlebar
= 0;
302 attribs
->no_close_button
= 0;
303 attribs
->no_closable
= 0;
306 if (mwm_hints->decorations & MWM_DECOR_MENU) {
308 fprintf(stderr,"(MENU) ");
313 if (mwm_hints
->decorations
& MWM_DECOR_MINIMIZE
) {
315 fprintf(stderr
,"MINIMIZE ");
317 attribs
->no_miniaturize_button
= 0;
318 attribs
->no_miniaturizable
= 0;
321 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
323 fprintf(stderr,"(MAXIMIZE) ");
328 fprintf(stderr
,"]\n");
333 if (mwm_hints
->flags
& MWM_HINTS_FUNCTIONS
) {
335 fprintf(stderr
,"has function hints [ ");
337 attribs
->no_closable
= 1;
338 attribs
->no_miniaturizable
= 1;
339 attribs
->no_resizable
= 1;
341 if (mwm_hints
->functions
& MWM_FUNC_ALL
) {
343 fprintf(stderr
,"ALL ");
345 attribs
->no_closable
= 0;
346 attribs
->no_miniaturizable
= 0;
347 attribs
->no_resizable
= 0;
349 if (mwm_hints
->functions
& MWM_FUNC_RESIZE
) {
351 fprintf(stderr
,"RESIZE ");
353 attribs
->no_resizable
= 0;
356 if (mwm_hints->functions & MWM_FUNC_MOVE) {
358 fprintf(stderr,"(MOVE) ");
362 if (mwm_hints
->functions
& MWM_FUNC_MINIMIZE
) {
364 fprintf(stderr
,"MINIMIZE ");
366 attribs
->no_miniaturizable
= 0;
368 if (mwm_hints
->functions
& MWM_FUNC_MAXIMIZE
) {
370 fprintf(stderr
,"MAXIMIZE ");
371 /* a window must be resizable to be maximizable */
372 attribs
->no_resizable
= 0;
375 if (mwm_hints
->functions
& MWM_FUNC_CLOSE
) {
377 fprintf(stderr
,"CLOSE ");
379 attribs
->no_closable
= 0;
382 fprintf(stderr
,"]\n");
386 #endif /* MWM_HINTS */
390 wWindowCheckAttributeSanity(WWindow
*wwin
, WWindowAttributes
*wflags
)
392 if (wflags
->no_appicon
)
393 wflags
->emulate_appicon
= 0;
395 if (wwin
->main_window
!=None
) {
396 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
397 if (wapp
&& !wapp
->flags
.emulated
)
398 wflags
->emulate_appicon
= 0;
401 if (wwin
->transient_for
!=None
402 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
)
403 wflags
->emulate_appicon
= 0;
405 if (wflags
->sunken
&& wflags
->floating
)
412 wWindowCanReceiveFocus(WWindow
*wwin
)
414 if (!wwin
->flags
.mapped
&& !wwin
->flags
.shaded
)
416 if (wwin
->window_flags
.no_focusable
|| wwin
->flags
.miniaturized
)
418 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
426 *----------------------------------------------------------------
428 * reparents the window and allocates a descriptor for it.
429 * Window manager hints and other hints are fetched to configure
430 * the window decoration attributes and others. User preferences
431 * for the window are used if available, to configure window
432 * decorations and some behaviour.
435 * the new window descriptor
438 * The window is reparented and appropriate notification
439 * is done to the client. Input mask for the window is setup.
440 * The window descriptor is also associated with various window
441 * contexts and inserted in the head of the window list.
442 * Event handler contexts are associated for some objects
443 * (buttons, titlebar and resizebar)
446 * Check if the window_flags setting is correct.
447 *----------------------------------------------------------------
450 wManageWindow(WScreen
*scr
, Window window
)
454 unsigned width
, height
;
455 XWindowAttributes wattribs
;
456 XSetWindowAttributes attribs
;
458 WWindowState
*win_state
;
460 MWMHints
*motif_hints
= NULL
;
470 /* make sure the window is still there */
471 if (!XGetWindowAttributes(dpy
, window
, &wattribs
)) {
475 wwin
= wWindowCreate();
477 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
480 printf("managing window %x\n", (unsigned)window
);
484 if (wShapeSupported
) {
489 XShapeSelectInput(dpy
, window
, ShapeNotifyMask
);
490 XShapeQueryExtents(dpy
, window
, &b_shaped
, &junk
, &junk
, &ujunk
,
491 &ujunk
, &junk
, &junk
, &junk
, &ujunk
, &ujunk
);
492 wwin
->flags
.shaped
= b_shaped
;
497 *--------------------------------------------------
499 * Get hints and other information in properties
501 *--------------------------------------------------
503 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
504 PropGetWMClass(window
, &wwin
->wm_class
, &wwin
->wm_instance
);
506 /* setup descriptor */
507 wwin
->client_win
= window
;
508 wwin
->screen_ptr
= scr
;
510 wwin
->old_border_width
= wattribs
.border_width
;
512 attribs
.event_mask
= CLIENT_EVENTS
;
513 attribs
.do_not_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
;
514 attribs
.save_under
= False
;
515 XChangeWindowAttributes(dpy
, window
, CWEventMask
|CWDontPropagate
516 |CWSaveUnder
, &attribs
);
517 XSetWindowBorderWidth(dpy
, window
, 0);
519 /* fill in property/hint data */
520 if (!wFetchName(dpy
, window
, &title
)) {
523 /* get hints from GNUstep app */
524 if (!PropGetGNUstepWMAttr(window
, &wwin
->wm_gnustep_attr
)) {
525 wwin
->wm_gnustep_attr
=NULL
;
529 if (!PropGetMotifWMHints(window
, &motif_hints
))
531 #endif /* MWM_HINTS */
533 wwin
->client_leader
= PropGetClientLeader(window
);
534 if (wwin
->client_leader
!=None
)
535 wwin
->main_window
= wwin
->client_leader
;
538 XFree(wwin
->wm_hints
);
540 wwin
->wm_hints
= XGetWMHints(dpy
, window
);
542 if (wwin
->wm_hints
) {
543 if ((wwin
->wm_hints
->flags
&StateHint
)
544 && (wwin
->wm_hints
->initial_state
== IconicState
)) {
546 /* don't do iconify animation */
547 wwin
->flags
.skip_next_animation
= 1;
550 if (wwin
->wm_hints
->flags
& WindowGroupHint
) {
551 wwin
->group_id
= wwin
->wm_hints
->window_group
;
552 /* window_group has priority over CLIENT_LEADER */
553 wwin
->main_window
= wwin
->group_id
;
555 wwin
->group_id
= None
;
558 if (wwin
->wm_hints
->flags
& UrgencyHint
)
559 wwin
->flags
.urgent
= 1;
561 wwin
->group_id
= None
;
564 PropGetProtocols(window
, &wwin
->protocols
);
566 if (!XGetTransientForHint(dpy
, window
, &wwin
->transient_for
)) {
567 wwin
->transient_for
= None
;
569 if (wwin
->transient_for
==None
|| wwin
->transient_for
==window
) {
570 wwin
->transient_for
= scr
->root_win
;
573 owner
= wWindowFor(wwin
->transient_for
);
574 if (owner
&& owner
->main_window
!=None
) {
575 wwin
->main_window
= owner
->main_window
;
577 wwin->main_window = None;
580 /* don't let transients start miniaturized if their owners
582 if (owner
&& !owner
->flags
.miniaturized
&& iconic
) {
585 wwin
->wm_hints
->initial_state
= NormalState
;
590 /* guess the focus mode */
591 wwin
->focus_mode
= getFocusMode(wwin
);
593 /* get geometry stuff */
594 wClientGetNormalHints(wwin
, &wattribs
, True
, &x
, &y
, &width
, &height
);
596 /* get colormap windows */
597 GetColormapWindows(wwin
);
601 *--------------------------------------------------
603 * Setup the decoration/window attributes and
606 *--------------------------------------------------
608 /* sets global default stuff */
609 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
610 &wwin
->window_flags
, True
);
612 * Decoration setting is done in this precedence (lower to higher)
613 * - use default in the resource database
614 * - guess some settings
615 * - use GNUstep/external window attributes
616 * - set hints specified for the app in the resource DB
618 wwin
->window_flags
.broken_close
= 0;
620 if (wwin
->protocols
.DELETE_WINDOW
)
621 wwin
->window_flags
.kill_close
= 0;
623 wwin
->window_flags
.kill_close
= 1;
625 /* transients can't be iconified or maximized */
626 if (wwin
->transient_for
) {
627 wwin
->window_flags
.no_miniaturizable
= 1;
628 wwin
->window_flags
.no_miniaturize_button
= 1;
630 printf("%x is transient for %x\n", (unsigned)window
,
631 (unsigned)wwin
->transient_for
);
635 /* if the window can't be resized, remove the resizebar */
636 if (wwin
->normal_hints
->flags
& (PMinSize
|PMaxSize
)
637 && (wwin
->normal_hints
->min_width
==wwin
->normal_hints
->max_width
)
638 && (wwin
->normal_hints
->min_height
==wwin
->normal_hints
->max_height
)) {
639 wwin
->window_flags
.no_resizable
= 1;
640 wwin
->window_flags
.no_resizebar
= 1;
643 /* set GNUstep window attributes */
644 if (wwin
->wm_gnustep_attr
) {
645 setupGNUstepHints(&wwin
->window_flags
, wwin
->wm_gnustep_attr
);
647 if (wwin
->wm_gnustep_attr
->flags
& GSWindowLevelAttr
) {
649 switch (wwin
->wm_gnustep_attr
->window_level
) {
650 case WMNormalWindowLevel
:
651 window_level
= WMNormalLevel
;
653 case WMFloatingWindowLevel
:
654 window_level
= WMFloatingLevel
;
656 case WMDockWindowLevel
:
657 window_level
= WMDockLevel
;
659 case WMSubmenuWindowLevel
:
660 window_level
= WMSubmenuLevel
;
662 case WMMainMenuWindowLevel
:
663 window_level
= WMMainMenuLevel
;
666 window_level
= WMNormalLevel
;
671 window_level
= WMNormalLevel
;
676 setupMWMHints(&wwin
->window_flags
, motif_hints
);
678 #endif /* MWM_HINTS */
679 if (wwin
->window_flags
.floating
)
680 window_level
= WMFloatingLevel
;
681 else if (wwin
->window_flags
.sunken
)
682 window_level
= WMSunkenLevel
;
684 window_level
= WMNormalLevel
;
692 * Set attributes specified only for that window/class.
693 * This might do duplicate work with the 1st wDefaultFillAttributes().
694 * TODO: Do something about that.
696 wDefaultFillAttributes(scr
, wwin
->wm_instance
, wwin
->wm_class
,
697 &wwin
->window_flags
, False
);
701 * Sanity checks for attributes that depend on other attributes
703 wWindowCheckAttributeSanity(wwin
, &wwin
->window_flags
);
705 wwin
->window_flags
.no_shadeable
= wwin
->window_flags
.no_titlebar
;
708 * Make broken apps behave as a nice app.
710 if (wwin
->window_flags
.emulate_appicon
) {
711 wwin
->main_window
= wwin
->client_win
;
715 *------------------------------------------------------------
717 * Setup the initial state of the window
719 *------------------------------------------------------------
721 if (wwin
->window_flags
.start_miniaturized
722 && !wwin
->window_flags
.no_miniaturizable
) {
723 wwin
->flags
.miniaturized
= 1;
727 /* if there is a saved state, restore it */
729 if (wwin
->main_window
!=None
/* && wwin->main_window!=window*/) {
730 win_state
= (WWindowState
*)wWindowGetSavedState(wwin
->main_window
);
732 win_state
= (WWindowState
*)wWindowGetSavedState(window
);
734 if (win_state
&& !(wwin
->wm_hints
&& wwin
->wm_hints
->flags
&StateHint
&&
735 wwin
->wm_hints
->initial_state
==WithdrawnState
)) {
736 if (win_state
->state
->hidden
>0)
737 wwin
->flags
.hidden
= win_state
->state
->hidden
;
738 if (win_state
->state
->shaded
>0 && !wwin
->window_flags
.no_shadeable
)
739 wwin
->flags
.shaded
= win_state
->state
->shaded
;
740 if (win_state
->state
->miniaturized
>0 &&
741 !wwin
->window_flags
.no_miniaturizable
) {
742 wwin
->flags
.miniaturized
= win_state
->state
->miniaturized
;
745 if (!wwin
->window_flags
.omnipresent
) {
746 int w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
,
748 if (w
< 0 || w
>= scr
->workspace_count
) {
749 workspace
= win_state
->state
->workspace
;
750 if (workspace
>=scr
->workspace_count
)
751 workspace
= scr
->current_workspace
;
756 workspace
= scr
->current_workspace
;
760 /* if we're restarting, restore saved state. This will overwrite previous */
764 if (getSavedState(window
, &wstate
)) {
765 wwin
->flags
.shaded
= wstate
->shaded
;
766 wwin
->flags
.hidden
= wstate
->hidden
;
767 wwin
->flags
.miniaturized
= 0;
768 workspace
= wstate
->workspace
;
774 /* set workspace on which the window starts */
775 if (workspace
>= 0) {
776 if (workspace
> scr
->workspace_count
-1) {
777 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
778 workspace
= scr
->workspace_count
- 1;
783 w
= wDefaultGetStartWorkspace(scr
, wwin
->wm_instance
, wwin
->wm_class
);
784 if (w
>=0 && w
<scr
->workspace_count
&& !wwin
->window_flags
.omnipresent
) {
787 workspace
= scr
->current_workspace
;
791 /* setup window geometry */
792 if (win_state
&& win_state
->state
->use_geometry
) {
793 width
= win_state
->state
->w
;
794 height
= win_state
->state
->h
;
796 wWindowConstrainSize(wwin
, &width
, &height
);
798 /* do not ask for window placement if the window is
799 * transient, during startup, if the initial workspace is another one
800 * or if the window wants to
802 * If geometry was saved, restore it. */
803 if (win_state
&& win_state
->state
->use_geometry
) {
804 x
= win_state
->state
->x
;
805 y
= win_state
->state
->y
;
806 } else if (wwin
->transient_for
==None
&& !scr
->flags
.startup
&&
807 workspace
==scr
->current_workspace
&& !iconic
&&
808 !(wwin
->normal_hints
->flags
& (USPosition
|PPosition
))) {
809 PlaceWindow(wwin
, &x
, &y
, width
, height
);
812 if (wwin
->window_flags
.dont_move_off
)
813 wScreenBringInside(scr
, &x
, &y
, width
, height
);
816 *--------------------------------------------------
818 * Create frame, borders and do reparenting
820 *--------------------------------------------------
823 foo
= WFF_LEFT_BUTTON
| WFF_RIGHT_BUTTON
;
824 if (!wwin
->window_flags
.no_titlebar
)
826 if (!wwin
->window_flags
.no_resizebar
)
827 foo
|= WFF_RESIZEBAR
;
829 wwin
->frame
= wFrameWindowCreate(scr
, window_level
,
830 x
, y
, width
, height
, foo
,
831 scr
->window_title_texture
,
832 (WTexture
**)scr
->resizebar_texture
,
833 scr
->window_title_pixel
,
834 &scr
->window_title_gc
,
837 wwin
->frame
->flags
.is_client_window_frame
= 1;
838 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
840 /* setup button images */
841 wWindowUpdateButtonImages(wwin
);
843 /* hide unused buttons */
845 if (wwin
->window_flags
.no_close_button
)
846 foo
|= WFF_RIGHT_BUTTON
;
847 if (wwin
->window_flags
.no_miniaturize_button
)
848 foo
|= WFF_LEFT_BUTTON
;
850 wFrameWindowHideButton(wwin
->frame
, foo
);
853 wwin
->frame
->child
= wwin
;
855 wFrameWindowChangeTitle(wwin
->frame
, title
? title
: DEF_WINDOW_TITLE
);
859 wwin
->frame
->workspace
= workspace
;
861 wwin
->frame
->on_click_left
= windowIconifyClick
;
863 wwin
->frame
->on_click_right
= windowCloseClick
;
864 wwin
->frame
->on_dblclick_right
= windowCloseDblClick
;
866 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
867 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
869 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
871 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
872 0, wwin
->frame
->top_width
);
878 wClientGetGravityOffsets(wwin
, &gx
, &gy
);
879 /* set the position of the frame on screen */
880 x
+= gx
* FRAME_BORDER_WIDTH
;
881 y
+= gy
* FRAME_BORDER_WIDTH
;
882 /* if gravity is to the south, account for the border sizes */
884 y
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
888 * wWindowConfigure() will init the client window's size
889 * (wwin->client.{width,height}) and all other geometry
890 * related variables (frame_x,frame_y)
892 wWindowConfigure(wwin
, x
, y
, width
, height
);
895 *--------------------------------------------------
897 * Setup descriptors and save window to internal
900 *--------------------------------------------------
903 if (wwin
->main_window
!=None
) {
907 /* Leader windows do not necessary set themselves as leaders.
908 * If this is the case, point the leader of this window to
910 leader
= wWindowFor(wwin
->main_window
);
911 if (leader
&& leader
->main_window
==None
) {
912 leader
->main_window
= leader
->client_win
;
915 app
= wApplicationCreate(scr
, wwin
->main_window
);
917 app
->last_workspace
= workspace
;
920 * Do application specific stuff, like setting application
924 if (wwin
->flags
.hidden
) {
925 /* if the window was set to hidden because it was hidden
926 * in a previous incarnation and that state was restored */
927 app
->flags
.hidden
= 1;
930 if (app
->flags
.hidden
) {
931 wwin
->flags
.hidden
= 1;
936 /* setup the frame descriptor */
937 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
938 wwin
->frame
->core
->descriptor
.parent
= wwin
;
939 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
941 /* don't let windows go away if we die */
942 XAddToSaveSet(dpy
, window
);
944 XLowerWindow(dpy
, window
);
946 /* if window is in this workspace and should be mapped, then map it */
947 if (!iconic
&& (workspace
== scr
->current_workspace
948 || wwin
->window_flags
.omnipresent
)
949 && !wwin
->flags
.hidden
950 && !(wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)
951 && wwin
->wm_hints
->initial_state
== WithdrawnState
)) {
952 /* The following "if" is to avoid crashing of clients that expect
953 * WM_STATE set before they get mapped. Else WM_STATE is set later,
954 * after the return from this function.
956 if (wwin
->wm_hints
&& (wwin
->wm_hints
->flags
& StateHint
)) {
957 wClientSetState(wwin
, wwin
->wm_hints
->initial_state
, None
);
959 wClientSetState(wwin
, NormalState
, None
);
961 if (wPreferences
.superfluous
&& !wPreferences
.no_animations
962 && !scr
->flags
.startup
&& wwin
->transient_for
==None
964 * The brain damaged idiotic non-click to focus modes will
965 * have trouble with this because:
967 * 1. window is created and mapped by the client
968 * 2. window is mapped by wmaker in small size
969 * 3. window is animated to grow to normal size
970 * 4. this function returns to normal event loop
971 * 5. eventually, the EnterNotify event that would trigger
972 * the window focusing (if the mouse is over that window)
973 * will be processed by wmaker.
974 * But since this event will be rather delayed
975 * (step 3 has a large delay) the time when the event ocurred
976 * and when it is processed, the client that owns that window
977 * will reject the XSetInputFocus() for it.
979 && (wPreferences
.focus_mode
==WKF_CLICK
980 || wPreferences
.auto_focus
)) {
983 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
986 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
989 /* setup stacking descriptor */
990 if (wPreferences
.on_top_transients
&& wwin
->transient_for
!=None
991 && wwin
->transient_for
!=scr
->root_win
) {
993 tmp
= wWindowFor(wwin
->transient_for
);
995 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
997 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1001 if (!scr
->focused_window
) {
1002 /* first window on the list */
1005 scr
->focused_window
= wwin
;
1009 /* add window at beginning of focus window list */
1010 tmp
= scr
->focused_window
;
1022 *--------------------------------------------------
1024 * Final preparations before window is ready to go
1026 *--------------------------------------------------
1029 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1032 if (!iconic
&& workspace
== scr
->current_workspace
) {
1033 WWindow
*tmp
= wWindowFor(wwin
->transient_for
);
1035 if ((tmp
&& tmp
->flags
.focused
) || wPreferences
.auto_focus
)
1036 wSetFocusTo(scr
, wwin
);
1038 wwin
->flags
.ignore_next_unmap
= 1;
1040 wWindowResetMouseGrabs(wwin
);
1042 if (!wwin
->window_flags
.no_bind_keys
) {
1043 wWindowSetKeyGrabs(wwin
);
1047 * Prevent window withdrawal when getting the
1048 * unmap notifies generated during reparenting
1050 wwin
->flags
.mapped
=0;
1054 wColormapInstallForWindow(wwin
->screen_ptr
, scr
->cmap_window
);
1056 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1058 *--------------------------------------------------
1059 * Cleanup temporary stuff
1060 *--------------------------------------------------
1064 wWindowDeleteSavedState(win_state
);
1074 wManageInternalWindow(WScreen
*scr
, Window window
, Window owner
,
1075 char *title
, int x
, int y
, int width
, int height
)
1080 wwin
= wWindowCreate();
1082 wwin
->flags
.internal_window
= 1;
1083 wwin
->window_flags
.omnipresent
= 1;
1084 wwin
->window_flags
.no_shadeable
= 1;
1085 wwin
->window_flags
.no_resizable
= 1;
1086 wwin
->window_flags
.no_miniaturizable
= 1;
1088 wwin
->focus_mode
= WFM_PASSIVE
;
1090 wwin
->client_win
= window
;
1091 wwin
->screen_ptr
= scr
;
1093 wwin
->transient_for
= owner
;
1097 wwin
->client
.width
= width
;
1098 wwin
->client
.height
= height
;
1100 wwin
->frame_x
= wwin
->client
.x
;
1101 wwin
->frame_y
= wwin
->client
.y
;
1104 foo
= WFF_RIGHT_BUTTON
;
1105 foo
|= WFF_TITLEBAR
;
1107 wwin
->frame
= wFrameWindowCreate(scr
, WMFloatingLevel
,
1108 wwin
->frame_x
, wwin
->frame_y
,
1110 scr
->window_title_texture
,
1111 (WTexture
**)scr
->resizebar_texture
,
1112 scr
->window_title_pixel
,
1113 &scr
->window_title_gc
,
1116 XSaveContext(dpy
, window
, wWinContext
, (XPointer
)&wwin
->client_descriptor
);
1118 wwin
->frame
->flags
.is_client_window_frame
= 1;
1119 wwin
->frame
->flags
.justification
= wPreferences
.title_justification
;
1121 wFrameWindowChangeTitle(wwin
->frame
, title
);
1123 /* setup button images */
1124 wWindowUpdateButtonImages(wwin
);
1127 wFrameWindowHideButton(wwin
->frame
, WFF_RIGHT_BUTTON
);
1129 wwin
->frame
->child
= wwin
;
1131 wwin
->frame
->workspace
= wwin
->screen_ptr
->current_workspace
;
1133 wwin
->frame
->on_click_right
= windowCloseClick
;
1135 wwin
->frame
->on_mousedown_titlebar
= titlebarMouseDown
;
1136 wwin
->frame
->on_dblclick_titlebar
= titlebarDblClick
;
1138 wwin
->frame
->on_mousedown_resizebar
= resizebarMouseDown
;
1140 wwin
->client
.y
+= wwin
->frame
->top_width
;
1141 XReparentWindow(dpy
, wwin
->client_win
, wwin
->frame
->core
->window
,
1142 0, wwin
->frame
->top_width
);
1144 wWindowConfigure(wwin
, wwin
->frame_x
, wwin
->frame_y
,
1145 wwin
->client
.width
, wwin
->client
.height
);
1147 /* setup the frame descriptor */
1148 wwin
->frame
->core
->descriptor
.handle_mousedown
= frameMouseDown
;
1149 wwin
->frame
->core
->descriptor
.parent
= wwin
;
1150 wwin
->frame
->core
->descriptor
.parent_type
= WCLASS_WINDOW
;
1153 XLowerWindow(dpy
, window
);
1154 XMapSubwindows(dpy
, wwin
->frame
->core
->window
);
1156 /* setup stacking descriptor */
1157 if (wPreferences
.on_top_transients
&& wwin
->transient_for
!=None
1158 && wwin
->transient_for
!=scr
->root_win
) {
1160 tmp
= wWindowFor(wwin
->transient_for
);
1162 wwin
->frame
->core
->stacking
->child_of
= tmp
->frame
->core
;
1164 wwin
->frame
->core
->stacking
->child_of
= NULL
;
1168 if (!scr
->focused_window
) {
1169 /* first window on the list */
1172 scr
->focused_window
= wwin
;
1176 /* add window at beginning of focus window list */
1177 tmp
= scr
->focused_window
;
1185 wFrameWindowChangeState(wwin
->frame
, WS_UNFOCUSED
);
1187 /* if (wPreferences.auto_focus)*/
1188 wSetFocusTo(scr
, wwin
);
1190 wWindowResetMouseGrabs(wwin
);
1192 wWindowSetKeyGrabs(wwin
);
1194 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_ADD
);
1201 *----------------------------------------------------------------------
1203 * Removes the frame window from a window and destroys all data
1204 * related to it. The window will be reparented back to the root window
1205 * if restore is True.
1208 * Everything related to the window is destroyed and the window
1209 * is removed from the window lists. Focus is set to the previous on the
1211 *----------------------------------------------------------------------
1214 wUnmanageWindow(WWindow
*wwin
, int restore
)
1216 WCoreWindow
*frame
= wwin
->frame
->core
;
1218 WWindow
*newFocusedWindow
;
1220 WScreen
*scr
= wwin
->screen_ptr
;
1222 /* First close attribute editor window if open */
1223 if (wwin
->flags
.inspector_open
) {
1224 WWindow
*pwin
= wwin
->inspector
->frame
; /* the inspector window */
1225 (*pwin
->frame
->on_click_right
)(NULL
, pwin
, NULL
);
1228 /* Close window menu if it's open for this window */
1229 if (wwin
->flags
.menu_open_for_me
) {
1230 CloseWindowMenu(scr
);
1232 if (!wwin
->flags
.internal_window
)
1233 XRemoveFromSaveSet(dpy
, wwin
->client_win
);
1234 XSelectInput(dpy
, wwin
->client_win
, NoEventMask
);
1236 XUnmapWindow(dpy
, frame
->window
);
1238 /* deselect window */
1239 wSelectWindow(wwin
, False
);
1241 /* remove all pending events on window */
1242 /* I think this only matters for autoraise */
1243 if (wPreferences
.raise_delay
)
1244 WMDeleteTimerWithClientData(wwin
->frame
->core
);
1248 UpdateSwitchMenu(scr
, wwin
, ACTION_REMOVE
);
1250 /* reparent the window back to the root */
1252 wClientRestore(wwin
);
1254 if (wwin
->transient_for
!=scr
->root_win
) {
1255 owner
= wWindowFor(wwin
->transient_for
);
1257 owner
->flags
.semi_focused
= 0;
1258 wFrameWindowChangeState(owner
->frame
, WS_UNFOCUSED
);
1262 wasNotFocused
= !wwin
->flags
.focused
;
1264 /* remove from window focus list */
1265 if (!wwin
->prev
&& !wwin
->next
) {
1266 /* was the only window */
1267 scr
->focused_window
= NULL
;
1268 newFocusedWindow
= NULL
;
1273 wwin
->prev
->next
= wwin
->next
;
1275 wwin
->next
->prev
= wwin
->prev
;
1277 scr
->focused_window
= wwin
->prev
;
1278 scr
->focused_window
->next
= NULL
;
1281 /* if in click to focus mode and the window
1282 * was a transient, focus the owner window
1285 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1286 tmp
= wWindowFor(wwin
->transient_for
);
1287 if (tmp
&& (!tmp
->flags
.mapped
|| tmp
->window_flags
.no_focusable
)) {
1291 /* otherwise, focus the next one in the focus list */
1293 tmp
= scr
->focused_window
;
1295 if (!tmp
->window_flags
.no_focusable
1296 && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
))
1301 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1302 newFocusedWindow
= tmp
;
1303 } else if (wPreferences
.focus_mode
==WKF_SLOPPY
1304 || wPreferences
.focus_mode
==WKF_POINTER
) {
1309 /* This is to let the root window get the keyboard input
1310 * if Sloppy focus mode and no other window get focus.
1311 * This way keybindings will not freeze.
1314 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
1315 &foo
, &foo
, &foo
, &foo
, &mask
))
1316 tmp
= wWindowFor(win
);
1319 newFocusedWindow
= tmp
;
1321 newFocusedWindow
= NULL
;
1325 printf("destroying window %x frame %x\n", (unsigned)wwin
->client_win
,
1326 (unsigned)frame
->window
);
1329 wSetFocusTo(scr
, newFocusedWindow
);
1330 wWindowDestroy(wwin
);
1336 wWindowFocus(WWindow
*wwin
)
1338 #ifdef KEEP_XKB_LOCK_STATUS
1339 if (wPreferences
.modelock
) {
1340 if (!wwin
->flags
.focused
) {
1341 XkbLockGroup(dpy
, XkbUseCoreKbd
, wwin
->languagemode
);
1344 #endif /* KEEP_XKB_LOCK_STATUS */
1346 wFrameWindowChangeState(wwin
->frame
, WS_FOCUSED
);
1348 wwin
->flags
.focused
=1;
1350 wWindowResetMouseGrabs(wwin
);
1352 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1357 wWindowMap(WWindow
*wwin
)
1359 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1360 wwin
->flags
.mapped
= 1;
1366 wWindowUnfocus(WWindow
*wwin
)
1368 #ifdef KEEP_XKB_LOCK_STATUS
1369 static XkbStateRec staterec
;
1370 if (wPreferences
.modelock
) {
1371 if (wwin
->flags
.focused
) {
1372 XkbGetState(dpy
,XkbUseCoreKbd
,&staterec
);
1373 wwin
->languagemode
=staterec
.compat_state
&32?1:0;
1374 XkbLockGroup(dpy
,XkbUseCoreKbd
,0); /* reset to workspace */
1377 #endif /* KEEP_XKB_LOCK_STATUS */
1379 CloseWindowMenu(wwin
->screen_ptr
);
1381 wFrameWindowChangeState(wwin
->frame
, wwin
->flags
.semi_focused
1382 ? WS_PFOCUSED
: WS_UNFOCUSED
);
1384 if (wwin
->transient_for
!=None
1385 && wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
1387 owner
= wWindowFor(wwin
->transient_for
);
1388 if (owner
&& owner
->flags
.semi_focused
) {
1389 owner
->flags
.semi_focused
= 0;
1390 if (owner
->flags
.mapped
|| owner
->flags
.shaded
) {
1391 wWindowUnfocus(owner
);
1392 wFrameWindowPaint(owner
->frame
);
1396 wwin
->flags
.focused
=0;
1397 wWindowResetMouseGrabs(wwin
);
1399 UpdateSwitchMenu(wwin
->screen_ptr
, wwin
, ACTION_CHANGE_STATE
);
1405 *----------------------------------------------------------------------
1407 * wWindowConstrainSize--
1408 * Constrains size for the client window, taking the maximal size,
1409 * window resize increments and other size hints into account.
1412 * The closest size to what was given that the client window can
1415 *----------------------------------------------------------------------
1418 wWindowConstrainSize(WWindow
*wwin
, int *nwidth
, int *nheight
)
1420 XSizeHints
*sizeh
= wwin
->normal_hints
;
1421 int width
= *nwidth
;
1422 int height
= *nheight
;
1423 int winc
= sizeh
->width_inc
;
1424 int hinc
= sizeh
->height_inc
;
1426 if (width
< sizeh
->min_width
)
1427 width
= sizeh
->min_width
;
1428 if (height
< sizeh
->min_height
)
1429 height
= sizeh
->min_height
;
1431 if (width
> sizeh
->max_width
)
1432 width
= sizeh
->max_width
;
1433 if (height
> sizeh
->max_height
)
1434 height
= sizeh
->max_height
;
1436 /* aspect ratio code borrowed from olwm */
1437 if (sizeh
->flags
& PAspect
) {
1438 /* adjust max aspect ratio */
1439 if (!(sizeh
->max_aspect
.x
==1 && sizeh
->max_aspect
.y
==1)
1440 && width
* sizeh
->max_aspect
.y
> height
* sizeh
->max_aspect
.x
) {
1441 if (sizeh
->max_aspect
.x
> sizeh
->max_aspect
.y
) {
1442 height
= (width
* sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1443 if (height
> sizeh
->max_height
) {
1444 height
= sizeh
->max_height
;
1445 width
= (height
*sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1448 width
= (height
* sizeh
->max_aspect
.x
) / sizeh
->max_aspect
.y
;
1449 if (width
> sizeh
->max_width
) {
1450 width
= sizeh
->max_width
;
1451 height
= (width
*sizeh
->max_aspect
.y
) / sizeh
->max_aspect
.x
;
1456 /* adjust min aspect ratio */
1457 if (!(sizeh
->min_aspect
.x
==1 && sizeh
->min_aspect
.y
==1)
1458 && width
* sizeh
->min_aspect
.y
< height
* sizeh
->min_aspect
.x
) {
1459 if (sizeh
->min_aspect
.x
> sizeh
->min_aspect
.y
) {
1460 height
= (width
* sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1461 if (height
< sizeh
->min_height
) {
1462 height
= sizeh
->min_height
;
1463 width
= (height
*sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1466 width
= (height
* sizeh
->min_aspect
.x
) / sizeh
->min_aspect
.y
;
1467 if (width
> sizeh
->min_width
) {
1468 width
= sizeh
->min_width
;
1469 height
= (width
*sizeh
->min_aspect
.y
) / sizeh
->min_aspect
.x
;
1475 if (sizeh
->base_width
!= 0) {
1476 width
= (((width
- sizeh
->base_width
) / winc
) * winc
)
1477 + sizeh
->base_width
;
1479 width
= (((width
- sizeh
->min_width
) / winc
) * winc
)
1483 if (sizeh
->base_width
!= 0) {
1484 height
= (((height
- sizeh
->base_height
) / hinc
) * hinc
)
1485 + sizeh
->base_height
;
1487 height
= (((height
- sizeh
->min_height
) / hinc
) * hinc
)
1488 + sizeh
->min_height
;
1497 wWindowChangeWorkspace(WWindow
*wwin
, int workspace
)
1499 WScreen
*scr
= wwin
->screen_ptr
;
1503 if (workspace
>= scr
->workspace_count
|| workspace
< 0
1504 || workspace
== wwin
->frame
->workspace
)
1507 if (workspace
!= scr
->current_workspace
) {
1508 /* Sent to other workspace. Unmap window */
1509 if ((wwin
->flags
.mapped
||wwin
->flags
.shaded
)
1510 && !wwin
->window_flags
.omnipresent
1511 && !wwin
->flags
.changing_workspace
) {
1513 wapp
= wApplicationOf(wwin
->main_window
);
1515 wapp
->last_workspace
= workspace
;
1518 wwin
->flags
.mapped
= 0;
1519 wSetFocusTo(scr
, NULL
);
1522 /* brought to current workspace. Map window */
1523 if (!wwin
->flags
.mapped
&&
1524 !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)) {
1528 if (!wwin
->window_flags
.omnipresent
) {
1529 wwin
->frame
->workspace
= workspace
;
1530 UpdateSwitchMenu(scr
, wwin
, ACTION_CHANGE_WORKSPACE
);
1533 XUnmapWindow(dpy
, wwin
->frame
->core
->window
);
1538 wWindowSynthConfigureNotify(WWindow
*wwin
)
1542 sevent
.type
= ConfigureNotify
;
1543 sevent
.xconfigure
.display
= dpy
;
1544 sevent
.xconfigure
.event
= wwin
->client_win
;
1545 sevent
.xconfigure
.window
= wwin
->client_win
;
1547 sevent
.xconfigure
.x
= wwin
->client
.x
;
1548 sevent
.xconfigure
.y
= wwin
->client
.y
;
1549 sevent
.xconfigure
.width
= wwin
->client
.width
;
1550 sevent
.xconfigure
.height
= wwin
->client
.height
;
1552 sevent
.xconfigure
.border_width
= wwin
->old_border_width
;
1553 if (wwin
->window_flags
.no_titlebar
)
1554 sevent
.xconfigure
.above
= None
;
1556 sevent
.xconfigure
.above
= wwin
->frame
->titlebar
->window
;
1558 sevent
.xconfigure
.override_redirect
= False
;
1559 XSendEvent(dpy
, wwin
->client_win
, False
, StructureNotifyMask
, &sevent
);
1565 *----------------------------------------------------------------------
1566 * wWindowConfigure--
1567 * Configures the frame, decorations and client window to the
1568 * specified geometry. The geometry is not checked for validity,
1569 * wWindowConstrainSize() must be used for that.
1570 * The size parameters are for the client window, but the position is
1572 * The client window receives a ConfigureNotify event, according
1573 * to what ICCCM says.
1579 * Window size and position are changed and client window receives
1580 * a ConfigureNotify event.
1581 *----------------------------------------------------------------------
1584 wWindowConfigure(wwin
, req_x
, req_y
, req_width
, req_height
)
1586 int req_x
, req_y
; /* new position of the frame */
1587 int req_width
, req_height
; /* new size of the client */
1589 int synth_notify
= False
;
1592 resize
= (req_width
!=wwin
->client
.width
1593 || req_height
!=wwin
->client
.height
);
1595 * if the window is being moved but not resized then
1596 * send a synthetic ConfigureNotify
1598 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
) && !resize
) {
1599 synth_notify
= True
;
1602 if (wwin
->window_flags
.dont_move_off
)
1603 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1604 req_width
, req_height
);
1606 if (req_width
< MIN_WINDOW_SIZE
)
1607 req_width
= MIN_WINDOW_SIZE
;
1608 if (req_height
< MIN_WINDOW_SIZE
)
1609 req_height
= MIN_WINDOW_SIZE
;
1611 /* If growing, resize inner part before frame,
1612 * if shrinking, resize frame before.
1613 * This will prevent the frame (that can have a different color)
1614 * to be exposed, causing flicker */
1615 if (req_height
> wwin
->frame
->core
->height
1616 || req_width
> wwin
->frame
->core
->width
)
1617 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1619 if (wwin
->flags
.shaded
) {
1620 wFrameWindowResize(wwin
->frame
, req_width
, wwin
->frame
->core
->height
);
1621 wwin
->old_geometry
.height
= req_height
;
1623 wFrameWindowResizeInternal(wwin
->frame
, req_width
, req_height
);
1626 if (!(req_height
> wwin
->frame
->core
->height
1627 || req_width
> wwin
->frame
->core
->width
))
1628 XResizeWindow(dpy
, wwin
->client_win
, req_width
, req_height
);
1630 wwin
->client
.x
= req_x
;
1631 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1632 wwin
->client
.width
= req_width
;
1633 wwin
->client
.height
= req_height
;
1635 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1637 wwin
->client
.x
= req_x
;
1638 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1640 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1642 wwin
->frame_x
= req_x
;
1643 wwin
->frame_y
= req_y
;
1646 if (wShapeSupported
&& wwin
->flags
.shaped
&& resize
) {
1647 wWindowSetShape(wwin
);
1652 wWindowSynthConfigureNotify(wwin
);
1658 wWindowMove(wwin
, req_x
, req_y
)
1660 int req_x
, req_y
; /* new position of the frame */
1662 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1663 int synth_notify
= False
;
1665 /* Send a synthetic ConfigureNotify event for every window movement. */
1666 if ((req_x
!=wwin
->frame_x
|| req_y
!=wwin
->frame_y
)) {
1667 synth_notify
= True
;
1670 /* A single synthetic ConfigureNotify event is sent at the end of
1671 * a completed (opaque) movement in moveres.c */
1674 if (wwin
->window_flags
.dont_move_off
)
1675 wScreenBringInside(wwin
->screen_ptr
, &req_x
, &req_y
,
1676 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1678 wwin
->client
.x
= req_x
;
1679 wwin
->client
.y
= req_y
+ wwin
->frame
->top_width
;
1681 XMoveWindow(dpy
, wwin
->frame
->core
->window
, req_x
, req_y
);
1683 wwin
->frame_x
= req_x
;
1684 wwin
->frame_y
= req_y
;
1686 #ifdef CONFIGURE_WINDOW_WHILE_MOVING
1688 wWindowSynthConfigureNotify(wwin
);
1694 wWindowUpdateButtonImages(WWindow
*wwin
)
1696 WScreen
*scr
= wwin
->screen_ptr
;
1697 Pixmap pixmap
, mask
;
1698 WFrameWindow
*fwin
= wwin
->frame
;
1700 if (wwin
->window_flags
.no_titlebar
)
1703 /* miniaturize button */
1705 if (!wwin
->window_flags
.no_miniaturize_button
) {
1706 if (wwin
->wm_gnustep_attr
1707 && wwin
->wm_gnustep_attr
->flags
& GSMiniaturizePixmapAttr
) {
1708 pixmap
= wwin
->wm_gnustep_attr
->miniaturize_pixmap
;
1710 if (wwin
->wm_gnustep_attr
->flags
&GSMiniaturizeMaskAttr
) {
1711 mask
= wwin
->wm_gnustep_attr
->miniaturize_mask
;
1716 if (fwin
->lbutton_image
1717 && (fwin
->lbutton_image
->image
!= pixmap
1718 || fwin
->lbutton_image
->mask
!= mask
)) {
1719 wPixmapDestroy(fwin
->lbutton_image
);
1720 fwin
->lbutton_image
= NULL
;
1723 if (!fwin
->lbutton_image
) {
1724 fwin
->lbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1725 fwin
->lbutton_image
->client_owned
= 1;
1726 fwin
->lbutton_image
->client_owned_mask
= 1;
1729 if (fwin
->lbutton_image
&& !fwin
->lbutton_image
->shared
) {
1730 wPixmapDestroy(fwin
->lbutton_image
);
1732 fwin
->lbutton_image
= scr
->b_pixmaps
[WBUT_ICONIFY
];
1738 if (!wwin
->window_flags
.no_close_button
) {
1739 if (wwin
->wm_gnustep_attr
1740 && wwin
->wm_gnustep_attr
->flags
&GSClosePixmapAttr
) {
1741 pixmap
= wwin
->wm_gnustep_attr
->close_pixmap
;
1743 if (wwin
->wm_gnustep_attr
->flags
&GSCloseMaskAttr
) {
1744 mask
= wwin
->wm_gnustep_attr
->close_mask
;
1749 if (fwin
->rbutton_image
1750 && (fwin
->rbutton_image
->image
!= pixmap
1751 || fwin
->rbutton_image
->mask
!= mask
)) {
1752 wPixmapDestroy(fwin
->rbutton_image
);
1753 fwin
->rbutton_image
= NULL
;
1756 if (!fwin
->rbutton_image
) {
1757 fwin
->rbutton_image
= wPixmapCreate(scr
, pixmap
, mask
);
1758 fwin
->rbutton_image
->client_owned
= 1;
1759 fwin
->rbutton_image
->client_owned_mask
= 1;
1761 } else if (wwin
->window_flags
.kill_close
) {
1762 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1763 wPixmapDestroy(fwin
->rbutton_image
);
1765 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_KILL
];
1766 } else if (wwin
->window_flags
.broken_close
) {
1767 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1768 wPixmapDestroy(fwin
->rbutton_image
);
1770 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_BROKENCLOSE
];
1772 if (fwin
->rbutton_image
&& !fwin
->rbutton_image
->shared
) {
1773 wPixmapDestroy(fwin
->rbutton_image
);
1775 fwin
->rbutton_image
= scr
->b_pixmaps
[WBUT_CLOSE
];
1779 /* force buttons to be redrawn */
1780 fwin
->flags
.need_texture_change
= 1;
1781 wFrameWindowPaint(fwin
);
1786 *---------------------------------------------------------------------------
1787 * wWindowConfigureBorders--
1788 * Update window border configuration according to window_flags
1790 *---------------------------------------------------------------------------
1793 wWindowConfigureBorders(WWindow
*wwin
)
1799 flags
= WFF_LEFT_BUTTON
|WFF_RIGHT_BUTTON
;
1800 if (!wwin
->window_flags
.no_titlebar
)
1801 flags
|= WFF_TITLEBAR
;
1802 if (!wwin
->window_flags
.no_resizebar
)
1803 flags
|= WFF_RESIZEBAR
;
1805 oldh
= wwin
->frame
->top_width
;
1806 wFrameWindowUpdateBorders(wwin
->frame
, flags
);
1807 if (oldh
!= wwin
->frame
->top_width
) {
1808 newy
= wwin
->frame_y
+ oldh
- wwin
->frame
->top_width
;
1810 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1811 wWindowConfigure(wwin
, wwin
->frame_x
, newy
,
1812 wwin
->client
.width
, wwin
->client
.height
);
1816 if (!wwin
->window_flags
.no_miniaturize_button
1817 && wwin
->frame
->flags
.hide_left_button
)
1818 flags
|= WFF_LEFT_BUTTON
;
1820 if (!wwin
->window_flags
.no_close_button
1821 && wwin
->frame
->flags
.hide_right_button
)
1822 flags
|= WFF_RIGHT_BUTTON
;
1825 wWindowUpdateButtonImages(wwin
);
1826 wFrameWindowShowButton(wwin
->frame
, flags
);
1830 if (wwin
->window_flags
.no_miniaturize_button
1831 && !wwin
->frame
->flags
.hide_left_button
)
1832 flags
|= WFF_LEFT_BUTTON
;
1834 if (wwin
->window_flags
.no_close_button
1835 && !wwin
->frame
->flags
.hide_right_button
)
1836 flags
|= WFF_RIGHT_BUTTON
;
1839 wFrameWindowHideButton(wwin
->frame
, flags
);
1842 if (wShapeSupported
&& wwin
->flags
.shaped
) {
1843 wWindowSetShape(wwin
);
1851 wWindowSaveState(WWindow
*wwin
)
1855 memset(data
, 0, sizeof(CARD32
)*9);
1856 data
[0] = wwin
->frame
->workspace
;
1857 data
[2] = wwin
->flags
.shaded
;
1858 data
[3] = wwin
->flags
.hidden
;
1860 XChangeProperty(dpy
, wwin
->client_win
, _XA_WINDOWMAKER_STATE
,
1861 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1862 (unsigned char *)data
, 9);
1867 getSavedState(Window window
, WSavedState
**state
)
1871 unsigned long nitems_ret
;
1872 unsigned long bytes_after_ret
;
1875 if (XGetWindowProperty(dpy
, window
, _XA_WINDOWMAKER_STATE
, 0, 9,
1876 True
, _XA_WINDOWMAKER_STATE
,
1877 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
1878 (unsigned char **)&data
)!=Success
|| !data
)
1881 *state
= malloc(sizeof(WSavedState
));
1884 (*state
)->workspace
= data
[0];
1885 (*state
)->miniaturized
= data
[1];
1886 (*state
)->shaded
= data
[2];
1887 (*state
)->hidden
= data
[3];
1888 (*state
)->use_geometry
= data
[4];
1889 (*state
)->x
= data
[5];
1890 (*state
)->y
= data
[6];
1891 (*state
)->w
= data
[7];
1892 (*state
)->h
= data
[8];
1896 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
1905 wWindowClearShape(WWindow
*wwin
)
1907 XShapeCombineMask(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
1908 0, wwin
->frame
->top_width
, None
, ShapeSet
);
1913 wWindowSetShape(WWindow
*wwin
)
1917 #ifdef OPTIMIZE_SHAPE
1922 /* only shape is the client's */
1923 if (wwin
->window_flags
.no_titlebar
&& wwin
->window_flags
.no_resizebar
) {
1927 /* Get array of rectangles describing the shape mask */
1928 rects
= XShapeGetRectangles(dpy
, wwin
->client_win
, ShapeBounding
,
1934 urec
= malloc(sizeof(XRectangle
)*(count
+2));
1940 /* insert our decoration rectangles in the rect list */
1941 memcpy(urec
, rects
, sizeof(XRectangle
)*count
);
1944 if (!wwin
->window_flags
.no_titlebar
) {
1946 urec
[count
].y
= -1 - wwin
->frame
->top_width
;
1947 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
1948 urec
[count
].height
= wwin
->frame
->top_width
+ 1;
1951 if (!wwin
->window_flags
.no_resizebar
) {
1953 urec
[count
].y
= wwin
->frame
->core
->height
1954 - wwin
->frame
->bottom_width
- wwin
->frame
->top_width
;
1955 urec
[count
].width
= wwin
->frame
->core
->width
+ 2;
1956 urec
[count
].height
= wwin
->frame
->bottom_width
+ 1;
1960 /* shape our frame window */
1961 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
1962 0, wwin
->frame
->top_width
, urec
, count
,
1963 ShapeSet
, Unsorted
);
1969 #endif /* OPTIMIZE_SHAPE */
1971 if (!wwin
->window_flags
.no_titlebar
) {
1974 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
1975 rect
[count
].height
= wwin
->frame
->top_width
+ 1;
1978 if (!wwin
->window_flags
.no_resizebar
) {
1980 rect
[count
].y
= wwin
->frame
->core
->height
- wwin
->frame
->bottom_width
;
1981 rect
[count
].width
= wwin
->frame
->core
->width
+ 2;
1982 rect
[count
].height
= wwin
->frame
->bottom_width
+ 1;
1986 XShapeCombineRectangles(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
1987 0, 0, rect
, count
, ShapeSet
, Unsorted
);
1989 XShapeCombineShape(dpy
, wwin
->frame
->core
->window
, ShapeBounding
,
1990 0, wwin
->frame
->top_width
, wwin
->client_win
,
1991 ShapeBounding
, (count
> 0 ? ShapeUnion
: ShapeSet
));
1996 /* ====================================================================== */
1999 getFocusMode(WWindow
*wwin
)
2003 if ((wwin
->wm_hints
) && (wwin
->wm_hints
->flags
& InputHint
)) {
2004 if (wwin
->wm_hints
->input
== True
) {
2005 if (wwin
->protocols
.TAKE_FOCUS
)
2006 mode
= WFM_LOCALLY_ACTIVE
;
2010 if (wwin
->protocols
.TAKE_FOCUS
)
2011 mode
= WFM_GLOBALLY_ACTIVE
;
2013 mode
= WFM_NO_INPUT
;
2023 wWindowSetKeyGrabs(WWindow
*wwin
)
2028 for (i
=0; i
<WKBD_LAST
; i
++) {
2029 key
= &wKeyBindings
[i
];
2031 if (key
->keycode
==0)
2033 if (key
->modifier
!=AnyModifier
) {
2034 XGrabKey(dpy
, key
->keycode
, key
->modifier
|LockMask
,
2035 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2037 /* Also grab all modifier combinations possible that include,
2038 * LockMask, ScrollLockMask and NumLockMask, so that keygrabs
2039 * work even if the NumLock/ScrollLock key is on.
2041 wHackedGrabKey(key
->keycode
, key
->modifier
,
2042 wwin
->frame
->core
->window
, True
, GrabModeAsync
,
2046 XGrabKey(dpy
, key
->keycode
, key
->modifier
,
2047 wwin
->frame
->core
->window
, True
, GrabModeAsync
, GrabModeAsync
);
2050 wRootMenuBindShortcuts(wwin
->frame
->core
->window
);
2056 wWindowResetMouseGrabs(WWindow
*wwin
)
2058 /* Mouse grabs can't be done on the client window because of
2059 * ICCCM and because clients that try to do the same will crash.
2061 * But there is a problem wich makes tbar buttons of unfocused
2062 * windows not usable as the click goes to the frame window instead
2063 * of the button itself. Must figure a way to fix that.
2066 XUngrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
);
2068 if (!wwin
->window_flags
.no_bind_mouse
) {
2069 /* grabs for Meta+drag */
2070 wHackedGrabButton(AnyButton
, MOD_MASK
, wwin
->client_win
,
2071 True
, ButtonPressMask
, GrabModeSync
,
2072 GrabModeAsync
, None
, None
);
2075 if (!wwin
->flags
.focused
) {
2076 /* the passive grabs to focus the window */
2077 if (wPreferences
.focus_mode
== WKF_CLICK
)
2078 XGrabButton(dpy
, AnyButton
, AnyModifier
, wwin
->client_win
,
2079 True
, ButtonPressMask
, GrabModeSync
, GrabModeAsync
,
2087 wWindowUpdateGNUstepAttr(WWindow
*wwin
, GNUstepWMAttributes
*attr
)
2090 if (attr
->flags
& GSExtraFlagsAttr
) {
2091 if (wwin
->window_flags
.broken_close
!=
2092 (attr
->extra_flags
& GSDocumentEditedFlag
)) {
2093 wwin
->window_flags
.broken_close
= !wwin
->window_flags
.broken_close
;
2095 wWindowUpdateButtonImages(wwin
);
2103 wWindowAddSavedState(char *instance
, char *class, char *command
,
2104 pid_t pid
, WSavedState
*state
)
2106 WWindowState
*wstate
;
2108 wstate
= malloc(sizeof(WWindowState
));
2112 memset(wstate
, 0, sizeof(WWindowState
));
2115 wstate
->instance
= wstrdup(instance
);
2117 wstate
->class = wstrdup(class);
2119 wstate
->command
= wstrdup(command
);
2120 wstate
->state
= state
;
2122 wstate
->next
= windowState
;
2123 windowState
= wstate
;
2126 printf("Added WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2134 #define SAME(x, y) (((x) && (y) && !strcmp((x), (y))) || (!(x) && !(y)))
2138 wWindowGetSavedState(Window win
)
2140 char *instance
, *class, *command
=NULL
;
2141 WWindowState
*wstate
= windowState
;
2148 if (XGetCommand(dpy
, win
, &argv
, &argc
)) {
2150 command
= FlattenStringList(argv
, argc
);
2151 XFreeStringList(argv
);
2156 if (PropGetWMClass(win
, &class, &instance
)) {
2158 if (SAME(instance
, wstate
->instance
) &&
2159 SAME(class, wstate
->class) &&
2160 SAME(command
, wstate
->command
)) {
2163 wstate
= wstate
->next
;
2170 printf("Read WindowState with ID %p, for %s.%s : \"%s\"\n", wstate
, instance
,
2174 if (command
) free(command
);
2175 if (instance
) XFree(instance
);
2176 if (class) XFree(class);
2183 wWindowDeleteSavedState(WMagicNumber id
)
2185 WWindowState
*tmp
, *wstate
=(WWindowState
*)id
;
2187 if (!wstate
|| !windowState
)
2192 windowState
= wstate
->next
;
2194 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2195 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2197 if (wstate
->instance
) free(wstate
->instance
);
2198 if (wstate
->class) free(wstate
->class);
2199 if (wstate
->command
) free(wstate
->command
);
2200 free(wstate
->state
);
2204 if (tmp
->next
==wstate
) {
2205 tmp
->next
=wstate
->next
;
2207 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2208 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2210 if (wstate
->instance
) free(wstate
->instance
);
2211 if (wstate
->class) free(wstate
->class);
2212 if (wstate
->command
) free(wstate
->command
);
2213 free(wstate
->state
);
2224 wWindowDeleteSavedStatesForPID(pid_t pid
)
2226 WWindowState
*tmp
, *wstate
;
2232 if (tmp
->pid
== pid
) {
2233 wstate
= windowState
;
2234 windowState
= tmp
->next
;
2236 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2237 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2239 if (wstate
->instance
) free(wstate
->instance
);
2240 if (wstate
->class) free(wstate
->class);
2241 if (wstate
->command
) free(wstate
->command
);
2242 free(wstate
->state
);
2246 if (tmp
->next
->pid
==pid
) {
2248 tmp
->next
= wstate
->next
;
2250 printf("Deleted WindowState with ID %p, for %s.%s : \"%s\"\n",
2251 wstate
, wstate
->instance
, wstate
->class, wstate
->command
);
2253 if (wstate
->instance
) free(wstate
->instance
);
2254 if (wstate
->class) free(wstate
->class);
2255 if (wstate
->command
) free(wstate
->command
);
2256 free(wstate
->state
);
2266 /* ====================================================================== */
2269 resizebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2271 WWindow
*wwin
= data
;
2273 #ifndef NUMLOCK_HACK
2274 if ((event
->xbutton
.state
& ValidModMask
)
2275 != (event
->xbutton
.state
& ~LockMask
)) {
2276 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2277 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2281 event
->xbutton
.state
&= ValidModMask
;
2283 CloseWindowMenu(wwin
->screen_ptr
);
2285 if (wPreferences
.focus_mode
==WKF_CLICK
2286 && !(event
->xbutton
.state
&ControlMask
)) {
2287 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2290 if (event
->xbutton
.button
== Button1
)
2291 wRaiseFrame(wwin
->frame
->core
);
2293 if (event
->xbutton
.window
!= wwin
->frame
->resizebar
->window
) {
2294 if (XGrabPointer(dpy
, wwin
->frame
->resizebar
->window
, True
,
2295 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2296 GrabModeAsync
, GrabModeAsync
, None
,
2297 None
, CurrentTime
)!=GrabSuccess
) {
2299 wwarning("pointer grab failed for window move");
2305 if (event
->xbutton
.state
& MOD_MASK
) {
2306 /* move the window */
2307 wMouseMoveWindow(wwin
, event
);
2308 XUngrabPointer(dpy
, CurrentTime
);
2310 wMouseResizeWindow(wwin
, event
);
2311 XUngrabPointer(dpy
, CurrentTime
);
2318 titlebarDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2320 WWindow
*wwin
= data
;
2322 event
->xbutton
.state
&= ValidModMask
;
2324 if (event
->xbutton
.button
==Button1
) {
2325 if (event
->xbutton
.state
== 0) {
2326 if (!wwin
->window_flags
.no_shadeable
) {
2328 if (wwin
->flags
.shaded
)
2329 wUnshadeWindow(wwin
);
2336 if (event
->xbutton
.state
& ControlMask
)
2337 dir
|= MAX_VERTICAL
;
2339 if (event
->xbutton
.state
& ShiftMask
) {
2340 dir
|= MAX_HORIZONTAL
;
2341 if (!(event
->xbutton
.state
& ControlMask
))
2342 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2345 /* maximize window */
2346 if (dir
!=0 && !wwin
->window_flags
.no_resizable
) {
2347 if (wwin
->flags
.maximized
)
2348 wUnmaximizeWindow(wwin
);
2350 wMaximizeWindow(wwin
, dir
);
2353 } else if (event
->xbutton
.button
==Button3
) {
2354 if (event
->xbutton
.state
& MOD_MASK
) {
2355 wHideOtherApplications(wwin
);
2357 } else if (event
->xbutton
.button
==Button2
) {
2358 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2364 frameMouseDown(WObjDescriptor
*desc
, XEvent
*event
)
2366 WWindow
*wwin
= desc
->parent
;
2368 event
->xbutton
.state
&= ValidModMask
;
2370 CloseWindowMenu(wwin
->screen_ptr
);
2372 if (wPreferences
.focus_mode
==WKF_CLICK
2373 && !(event
->xbutton
.state
&ControlMask
)) {
2374 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2376 if (event
->xbutton
.button
== Button1
) {
2377 wRaiseFrame(wwin
->frame
->core
);
2380 if (event
->xbutton
.state
& MOD_MASK
) {
2381 /* move the window */
2382 if (XGrabPointer(dpy
, wwin
->client_win
, False
,
2383 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2384 GrabModeAsync
, GrabModeAsync
, None
,
2385 None
, CurrentTime
)!=GrabSuccess
) {
2387 wwarning("pointer grab failed for window move");
2391 if (event
->xbutton
.button
== Button3
&& !wwin
->window_flags
.no_resizable
)
2392 wMouseResizeWindow(wwin
, event
);
2394 wMouseMoveWindow(wwin
, event
);
2395 XUngrabPointer(dpy
, CurrentTime
);
2401 titlebarMouseDown(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2403 WWindow
*wwin
= (WWindow
*)data
;
2405 #ifndef NUMLOCK_HACK
2406 if ((event
->xbutton
.state
& ValidModMask
)
2407 != (event
->xbutton
.state
& ~LockMask
)) {
2408 wwarning(_("the NumLock, ScrollLock or similar key seems to be turned on.\n"\
2409 "Turn it off or some mouse actions and keyboard shortcuts will not work."));
2412 event
->xbutton
.state
&= ValidModMask
;
2414 CloseWindowMenu(wwin
->screen_ptr
);
2416 if (wPreferences
.focus_mode
==WKF_CLICK
2417 && !(event
->xbutton
.state
&ControlMask
)) {
2418 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2421 if (event
->xbutton
.button
== Button1
2422 || event
->xbutton
.button
== Button2
) {
2424 if (event
->xbutton
.button
== Button1
) {
2425 if (event
->xbutton
.state
& MOD_MASK
) {
2426 wLowerFrame(wwin
->frame
->core
);
2428 wRaiseFrame(wwin
->frame
->core
);
2431 if ((event
->xbutton
.state
& ShiftMask
)
2432 && !(event
->xbutton
.state
& ControlMask
)) {
2433 wSelectWindow(wwin
, !wwin
->flags
.selected
);
2436 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2437 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2438 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2439 GrabModeAsync
, GrabModeAsync
, None
,
2440 None
, CurrentTime
)!=GrabSuccess
) {
2442 wwarning("pointer grab failed for window move");
2447 /* move the window */
2448 wMouseMoveWindow(wwin
, event
);
2450 XUngrabPointer(dpy
, CurrentTime
);
2451 } else if (event
->xbutton
.button
== Button3
&& event
->xbutton
.state
==0
2452 && !wwin
->flags
.internal_window
) {
2453 WObjDescriptor
*desc
;
2455 if (event
->xbutton
.window
!= wwin
->frame
->titlebar
->window
2456 && XGrabPointer(dpy
, wwin
->frame
->titlebar
->window
, False
,
2457 ButtonMotionMask
|ButtonReleaseMask
|ButtonPressMask
,
2458 GrabModeAsync
, GrabModeAsync
, None
,
2459 None
, CurrentTime
)!=GrabSuccess
) {
2461 wwarning("pointer grab failed for window move");
2466 OpenWindowMenu(wwin
, event
->xbutton
.x_root
,
2467 wwin
->frame_y
+wwin
->frame
->top_width
, False
);
2469 /* allow drag select */
2470 desc
= &wwin
->screen_ptr
->window_menu
->menu
->descriptor
;
2471 event
->xany
.send_event
= True
;
2472 (*desc
->handle_mousedown
)(desc
, event
);
2474 XUngrabPointer(dpy
, CurrentTime
);
2481 windowCloseClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2483 WWindow
*wwin
= data
;
2485 event
->xbutton
.state
&= ValidModMask
;
2487 CloseWindowMenu(wwin
->screen_ptr
);
2489 /* if control-click, kill the client */
2490 if (event
->xbutton
.state
& ControlMask
) {
2492 } else if (wwin
->protocols
.DELETE_WINDOW
&& event
->xbutton
.state
==0) {
2493 /* send delete message */
2494 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2500 windowCloseDblClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2502 WWindow
*wwin
= data
;
2504 CloseWindowMenu(wwin
->screen_ptr
);
2506 /* send delete message */
2507 if (wwin
->protocols
.DELETE_WINDOW
) {
2508 wClientSendProtocol(wwin
, _XA_WM_DELETE_WINDOW
, LastTimestamp
);
2516 windowIconifyClick(WCoreWindow
*sender
, void *data
, XEvent
*event
)
2518 WWindow
*wwin
= data
;
2520 event
->xbutton
.state
&= ValidModMask
;
2522 CloseWindowMenu(wwin
->screen_ptr
);
2524 if (wwin
->protocols
.MINIATURIZE_WINDOW
&& event
->xbutton
.state
==0) {
2525 wClientSendProtocol(wwin
, _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
,
2529 if ((event
->xbutton
.state
& ControlMask
) ||
2530 (event
->xbutton
.button
== Button3
)) {
2532 wapp
= wApplicationOf(wwin
->main_window
);
2533 if (wapp
&& !wwin
->window_flags
.no_appicon
)
2534 wHideApplication(wapp
);
2535 } else if (event
->xbutton
.state
==0) {
2536 wIconifyWindow(wwin
);