1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include <X11/Xutil.h>
35 #include "WindowMaker.h"
42 #include "application.h"
48 #include "winspector.h"
49 #include "workspace.h"
62 /****** Global Variables ******/
63 extern Time LastTimestamp
;
64 extern Time LastFocusChange
;
66 extern Cursor wCursor
[WCUR_LAST
];
68 extern WPreferences wPreferences
;
70 extern Atom _XA_WM_TAKE_FOCUS
;
73 /******* Local Variables *******/
78 {SHADE_STEPS_UF
, SHADE_DELAY_UF
},
79 {SHADE_STEPS_F
, SHADE_DELAY_F
},
80 {SHADE_STEPS_M
, SHADE_DELAY_M
},
81 {SHADE_STEPS_S
, SHADE_DELAY_S
},
82 {SHADE_STEPS_US
, SHADE_DELAY_US
}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
88 static int ignoreTimestamp
=0;
93 processEvents(int event_count
)
98 * This is a hack. When animations are enabled, processing of
99 * events ocurred during a animation are delayed until it's end.
100 * Calls that consider the TimeStamp, like XSetInputFocus(), will
101 * fail because the TimeStamp is too old. Then, for example, if
102 * the user changes window focus while a miniaturize animation is
103 * in course, the window will not get focus properly after the end
104 * of the animation. This tries to workaround it by passing CurrentTime
105 * as the TimeStamp for XSetInputFocus() for all events ocurred during
109 while (XPending(dpy
) && event_count
--) {
110 WMNextEvent(dpy
, &event
);
111 WMHandleEvent(&event
);
115 #endif /* ANIMATIONS */
120 *----------------------------------------------------------------------
122 * Changes the window focus to the one passed as argument.
123 * If the window to focus is not already focused, it will be brought
124 * to the head of the list of windows. Previously focused window is
128 * Window list may be reordered and the window focus is changed.
130 *----------------------------------------------------------------------
133 wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
135 static WScreen
*old_scr
=NULL
;
137 WWindow
*old_focused
;
138 WWindow
*focused
=scr
->focused_window
;
139 int timestamp
=LastTimestamp
;
140 WApplication
*oapp
=NULL
, *napp
=NULL
;
145 old_focused
=old_scr
->focused_window
;
147 LastFocusChange
= timestamp
;
150 * This is a hack, because XSetInputFocus() should have a proper
151 * timestamp instead of CurrentTime but it seems that some times
152 * clients will not receive focus properly that way.
155 timestamp
= CurrentTime
;
158 oapp
= wApplicationOf(old_focused
->main_window
);
161 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
163 wWindowUnfocus(old_focused
);
166 wAppMenuUnmap(oapp
->menu
);
168 wApplicationDeactivate(oapp
);
172 WMPostNotificationName(WMNChangedFocus
, NULL
, (void*)True
);
174 } else if (old_scr
!= scr
&& old_focused
) {
175 wWindowUnfocus(old_focused
);
178 wasfocused
= wwin
->flags
.focused
;
179 napp
= wApplicationOf(wwin
->main_window
);
181 /* remember last workspace where the app has been */
183 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
184 napp
->last_workspace
= wwin
->frame
->workspace
;
187 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
188 /* install colormap if colormap mode is lock mode */
189 if (wPreferences
.colormap_mode
==WCM_CLICK
)
190 wColormapInstallForWindow(scr
, wwin
);
192 /* set input focus */
193 switch (wwin
->focus_mode
) {
195 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
199 case WFM_LOCALLY_ACTIVE
:
200 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, timestamp
);
203 case WFM_GLOBALLY_ACTIVE
:
207 if (wwin
->protocols
.TAKE_FOCUS
) {
208 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
212 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
214 if (WFLAGP(wwin
, no_focusable
))
217 /* if this is not the focused window focus it */
219 /* change the focus window list order */
221 wwin
->prev
->next
= wwin
->next
;
224 wwin
->next
->prev
= wwin
->prev
;
226 wwin
->prev
= focused
;
227 focused
->next
= wwin
;
229 scr
->focused_window
= wwin
;
231 if (oapp
&& oapp
!= napp
) {
232 wAppMenuUnmap(oapp
->menu
);
234 wApplicationDeactivate(oapp
);
239 wWindowFocus(wwin
, focused
);
241 if (napp
&& !wasfocused
) {
243 wUserMenuRefreshInstances(napp
->menu
, wwin
);
244 #endif /* USER_MENU */
246 if (wwin
->flags
.mapped
)
247 wAppMenuMap(napp
->menu
, wwin
);
249 wApplicationActivate(napp
);
259 wShadeWindow(WWindow
*wwin
)
266 if (wwin
->flags
.shaded
)
271 XLowerWindow(dpy
, wwin
->client_win
);
273 wSoundPlay(WSOUND_SHADE
);
276 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
277 && !wPreferences
.no_animations
) {
278 /* do the shading animation */
279 h
= wwin
->frame
->core
->height
;
282 w
= wwin
->frame
->core
->width
;
283 y
= wwin
->frame
->top_width
;
284 while (h
>wwin
->frame
->top_width
+1) {
285 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
286 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
289 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
292 if (SHADE_DELAY
> 0) {
293 wusleep(SHADE_DELAY
*1000L);
300 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
302 #endif /* ANIMATIONS */
304 wwin
->flags
.skip_next_animation
= 0;
305 wwin
->flags
.shaded
= 1;
306 wwin
->flags
.mapped
= 0;
307 /* prevent window withdrawal when getting UnmapNotify */
308 XSelectInput(dpy
, wwin
->client_win
,
309 wwin
->event_mask
& ~StructureNotifyMask
);
310 XUnmapWindow(dpy
, wwin
->client_win
);
311 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
313 /* for the client it's just like iconification */
314 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
315 wwin
->frame
->top_width
- 1);
317 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
318 + wwin
->frame
->top_width
;
319 wWindowSynthConfigureNotify(wwin
);
322 wClientSetState(wwin, IconicState, None);
325 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
328 if (!wwin
->screen_ptr
->flags
.startup
) {
329 /* Look at processEvents() for reason of this code. */
331 processEvents(XPending(dpy
));
338 wUnshadeWindow(WWindow
*wwin
)
343 #endif /* ANIMATIONS */
346 if (!wwin
->flags
.shaded
)
351 wwin
->flags
.shaded
= 0;
352 wwin
->flags
.mapped
= 1;
353 XMapWindow(dpy
, wwin
->client_win
);
355 wSoundPlay(WSOUND_UNSHADE
);
358 if (!wPreferences
.no_animations
&& !wwin
->flags
.skip_next_animation
) {
359 /* do the shading animation */
360 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
361 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
362 s
= abs(y
)/SHADE_STEPS
;
364 w
= wwin
->frame
->core
->width
;
365 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
367 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
368 + wwin
->frame
->bottom_width
) {
369 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
370 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
372 if (SHADE_DELAY
> 0) {
373 wusleep(SHADE_DELAY
*2000L/3);
380 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
384 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
386 #endif /* ANIMATIONS */
388 wwin
->flags
.skip_next_animation
= 0;
389 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
390 wwin
->frame
->top_width
+ wwin
->client
.height
391 + wwin
->frame
->bottom_width
);
393 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
394 wWindowSynthConfigureNotify(wwin
);
397 wClientSetState(wwin, NormalState, None);
399 /* if the window is focused, set the focus again as it was disabled during
401 if (wwin
->flags
.focused
)
402 wSetFocusTo(wwin
->screen_ptr
, wwin
);
404 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
409 wMaximizeWindow(WWindow
*wwin
, int directions
)
411 int new_width
, new_height
, new_x
, new_y
;
412 WArea usableArea
= wwin
->screen_ptr
->totalUsableArea
;
415 if (WFLAGP(wwin
, no_resizable
))
420 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
421 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
423 if (wwin
->screen_ptr
->xine_count
> 0
424 && !(directions
& MAX_IGNORE_XINERAMA
)) {
425 WScreen
*scr
= wwin
->screen_ptr
;
431 rect.pos.x = wwin->frame_x;
432 rect.pos.y = wwin->frame_y;
433 rect.size.width = wwin->frame->core->width;
434 rect.size.height = wwin->frame->core->height;
436 head = wGetHeadForRect(scr, rect);
439 head
= wGetHeadForPointerLocation(scr
);
441 rect
= wGetRectForHead(scr
, head
);
443 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
);
446 if (WFLAGP(wwin
, full_maximize
)) {
447 usableArea
= totalArea
;
450 if (wwin
->flags
.shaded
) {
451 wwin
->flags
.skip_next_animation
= 1;
452 wUnshadeWindow(wwin
);
454 wwin
->flags
.maximized
= directions
;
455 wwin
->old_geometry
.width
= wwin
->client
.width
;
456 wwin
->old_geometry
.height
= wwin
->client
.height
;
457 wwin
->old_geometry
.x
= wwin
->frame_x
;
458 wwin
->old_geometry
.y
= wwin
->frame_y
;
461 wKWMUpdateClientGeometryRestore(wwin
);
464 if (directions
& MAX_HORIZONTAL
) {
465 new_width
= (usableArea
.x2
-usableArea
.x1
)-FRAME_BORDER_WIDTH
*2;
466 new_x
= usableArea
.x1
;
468 new_x
= wwin
->frame_x
;
469 new_width
= wwin
->frame
->core
->width
;
472 if (directions
& MAX_VERTICAL
) {
473 new_height
= (usableArea
.y2
-usableArea
.y1
)-FRAME_BORDER_WIDTH
*2;
474 new_y
= usableArea
.y1
;
475 if (WFLAGP(wwin
, full_maximize
)) {
476 new_y
-= wwin
->frame
->top_width
;
477 new_height
+= wwin
->frame
->bottom_width
- 1;
480 new_y
= wwin
->frame_y
;
481 new_height
= wwin
->frame
->core
->height
;
484 if (!WFLAGP(wwin
, full_maximize
)) {
485 new_height
-= wwin
->frame
->top_width
+wwin
->frame
->bottom_width
;
488 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
490 wWindowCropSize(wwin
, usableArea
.x2
-usableArea
.x1
,
491 usableArea
.y2
-usableArea
.y1
,
492 &new_width
, &new_height
);
494 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
497 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
499 wSoundPlay(WSOUND_MAXIMIZE
);
504 wUnmaximizeWindow(WWindow
*wwin
)
506 int restore_x
, restore_y
;
508 if (!wwin
->flags
.maximized
)
511 if (wwin
->flags
.shaded
) {
512 wwin
->flags
.skip_next_animation
= 1;
513 wUnshadeWindow(wwin
);
515 restore_x
= (wwin
->flags
.maximized
& MAX_HORIZONTAL
) ?
516 wwin
->old_geometry
.x
: wwin
->frame_x
;
517 restore_y
= (wwin
->flags
.maximized
& MAX_VERTICAL
) ?
518 wwin
->old_geometry
.y
: wwin
->frame_y
;
519 wwin
->flags
.maximized
= 0;
520 wWindowConfigure(wwin
, restore_x
, restore_y
,
521 wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
523 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
525 wSoundPlay(WSOUND_UNMAXIMIZE
);
530 animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
,
531 int fx
, int fy
, int fw
, int fh
, int steps
)
533 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
534 float cx
, cy
, cw
, ch
;
535 float xstep
, ystep
, wstep
, hstep
;
538 float angle
, final_angle
, delta
;
540 xstep
= (float)(fx
-x
)/steps
;
541 ystep
= (float)(fy
-y
)/steps
;
542 wstep
= (float)(fw
-w
)/steps
;
543 hstep
= (float)(fh
-h
)/steps
;
550 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_F
;
551 delta
= (float)(final_angle
/FRAMES
);
552 for (angle
=0;; angle
+=delta
) {
553 if (angle
> final_angle
)
556 dx
= (cw
/10) - ((cw
/5) * sin(angle
));
557 dch
= (ch
/2) * cos(angle
);
560 points
[0].x
= cx
+ dx
; points
[0].y
= midy
- dch
;
561 points
[1].x
= cx
+ cw
- dx
; points
[1].y
= points
[0].y
;
562 points
[2].x
= cx
+ cw
+ dx
; points
[2].y
= midy
+ dch
;
563 points
[3].x
= cx
- dx
; points
[3].y
= points
[2].y
;
564 points
[4].x
= points
[0].x
; points
[4].y
= points
[0].y
;
567 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
569 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
570 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
575 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
581 if (angle
>= final_angle
)
591 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
,
592 int fx
, int fy
, int fw
, int fh
, int steps
)
594 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
595 float cx
, cy
, cw
, ch
;
596 float xstep
, ystep
, wstep
, hstep
;
598 float angle
, final_angle
, a
, d
, delta
;
605 xstep
= (float)(fx
-x
)/steps
;
606 ystep
= (float)(fy
-y
)/steps
;
607 wstep
= (float)(fw
-w
)/steps
;
608 hstep
= (float)(fh
-h
)/steps
;
615 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_T
;
616 delta
= (float)(final_angle
/FRAMES
);
617 for (angle
=0;; angle
+=delta
) {
618 if (angle
> final_angle
)
622 d
= sqrt((cw
/2)*(cw
/2)+(ch
/2)*(ch
/2));
624 points
[0].x
= cx
+cos(angle
-a
)*d
;
625 points
[0].y
= cy
+sin(angle
-a
)*d
;
626 points
[1].x
= cx
+cos(angle
+a
)*d
;
627 points
[1].y
= cy
+sin(angle
+a
)*d
;
628 points
[2].x
= cx
+cos(angle
-a
+WM_PI
)*d
;
629 points
[2].y
= cy
+sin(angle
-a
+WM_PI
)*d
;
630 points
[3].x
= cx
+cos(angle
+a
+WM_PI
)*d
;
631 points
[3].y
= cy
+sin(angle
+a
+WM_PI
)*d
;
632 points
[4].x
= cx
+cos(angle
-a
)*d
;
633 points
[4].y
= cy
+sin(angle
-a
)*d
;
635 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
637 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
638 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
643 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
649 if (angle
>= final_angle
)
659 animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
,
660 int fx
, int fy
, int fw
, int fh
, int steps
)
662 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
663 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
664 float xstep
, ystep
, wstep
, hstep
;
667 xstep
= (float)(fx
-x
)/steps
;
668 ystep
= (float)(fy
-y
)/steps
;
669 wstep
= (float)(fw
-w
)/steps
;
670 hstep
= (float)(fh
-h
)/steps
;
672 for (j
=0; j
<FRAMES
; j
++) {
679 for (i
=0; i
<steps
; i
++) {
680 for (j
=0; j
<FRAMES
; j
++) {
681 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
682 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
685 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
686 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
690 for (j
=0; j
<FRAMES
; j
++) {
691 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
692 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
707 for (j
=0; j
<FRAMES
; j
++) {
708 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
709 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
712 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
713 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
717 for (j
=0; j
<FRAMES
; j
++) {
718 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
719 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
728 animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
,
729 int fx
, int fy
, int fw
, int fh
, int hiding
)
731 int style
= wPreferences
.iconification_style
; /* Catch the value */
734 if (style
== WIS_NONE
)
737 if (style
== WIS_RANDOM
) {
741 k
= (hiding
? 2 : 3);
744 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
)/3;
746 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
749 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
)/3;
751 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
755 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
)/3;
757 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
761 #endif /* ANIMATIONS */
769 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
770 WMHandleEvent(&tmpev
);
775 unmapTransientsFor(WWindow
*wwin
)
780 tmp
= wwin
->screen_ptr
->focused_window
;
782 /* unmap the transients for this transient */
783 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
784 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
785 || tmp
->flags
.shaded
)) {
786 unmapTransientsFor(tmp
);
787 tmp
->flags
.miniaturized
= 1;
788 if (!tmp
->flags
.shaded
) {
791 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
794 if (!tmp->flags.shaded)
796 wClientSetState(tmp
, IconicState
, None
);
798 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
806 mapTransientsFor(WWindow
*wwin
)
810 tmp
= wwin
->screen_ptr
->focused_window
;
812 /* recursively map the transients for this transient */
813 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
814 && /*!tmp->flags.mapped*/ tmp
->flags
.miniaturized
815 && tmp
->icon
==NULL
) {
816 mapTransientsFor(tmp
);
817 tmp
->flags
.miniaturized
= 0;
818 if (!tmp
->flags
.shaded
) {
821 XMapWindow(dpy
, tmp
->frame
->core
->window
);
823 tmp
->flags
.semi_focused
= 0;
825 if (!tmp->flags.shaded)
827 wClientSetState(tmp
, NormalState
, None
);
829 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
837 setupIconGrabs(WIcon
*icon
)
839 /* setup passive grabs on the icon */
840 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
841 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
842 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
843 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
844 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
845 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
851 recursiveTransientFor(WWindow
*wwin
)
858 /* hackish way to detect transient_for cycle */
859 i
= wwin
->screen_ptr
->window_count
+1;
861 while (wwin
&& wwin
->transient_for
!= None
&& i
>0) {
862 wwin
= wWindowFor(wwin
->transient_for
);
866 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
876 removeIconGrabs(WIcon
*icon
)
878 /* remove passive grabs on the icon */
879 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
880 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
881 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
888 wIconifyWindow(WWindow
*wwin
)
890 XWindowAttributes attribs
;
894 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
895 /* the window doesn't exist anymore */
899 if (wwin
->flags
.miniaturized
) {
903 if (wwin
->transient_for
!=None
&&
904 wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
905 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
907 if (owner
&& owner
->flags
.miniaturized
)
911 present
= wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
;
913 /* if the window is in another workspace, simplify process */
915 /* icon creation may take a while */
916 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
917 ButtonMotionMask
|ButtonReleaseMask
, GrabModeAsync
,
918 GrabModeAsync
, None
, None
, CurrentTime
);
921 if (!wPreferences
.disable_miniwindows
) {
922 if (!wwin
->flags
.icon_moved
) {
923 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
);
925 wwin
->icon
= wIconCreate(wwin
);
927 wwin
->icon
->mapped
= 1;
930 wwin
->flags
.miniaturized
= 1;
931 wwin
->flags
.mapped
= 0;
933 /* unmap transients */
935 unmapTransientsFor(wwin
);
938 wSoundPlay(WSOUND_ICONIFY
);
940 XUngrabPointer(dpy
, CurrentTime
);
942 /* let all Expose events arrive so that we can repaint
943 * something before the animation starts (and the server is grabbed) */
946 if (wPreferences
.disable_miniwindows
)
947 wClientSetState(wwin
, IconicState
, None
);
949 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
953 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
954 && !wPreferences
.no_animations
) {
957 if (!wPreferences
.disable_miniwindows
) {
960 iw
= wwin
->icon
->core
->width
;
961 ih
= wwin
->icon
->core
->height
;
966 if (wKWMGetIconGeometry(wwin
, &area
)) {
972 #endif /* KWM_HINTS */
976 iw
= wwin
->screen_ptr
->scr_width
;
977 ih
= wwin
->screen_ptr
->scr_height
;
980 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
981 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
982 ix
, iy
, iw
, ih
, False
);
987 wwin
->flags
.skip_next_animation
= 0;
989 if (!wPreferences
.disable_miniwindows
) {
991 if (wwin
->screen_ptr
->current_workspace
==wwin
->frame
->workspace
||
992 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
994 XMapWindow(dpy
, wwin
->icon
->core
->window
);
996 AddToStackList(wwin
->icon
->core
);
998 wLowerFrame(wwin
->icon
->core
);
1002 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1005 * It doesn't seem to be working and causes button event hangup
1006 * when deiconifying a transient window.
1007 setupIconGrabs(wwin->icon);
1009 if ((wwin
->flags
.focused
1010 || (owner
&& wwin
->client_win
== owner
->client_win
))
1011 && wPreferences
.focus_mode
==WKF_CLICK
) {
1016 if (!WFLAGP(tmp
, no_focusable
)
1017 && !(tmp
->flags
.hidden
||tmp
->flags
.miniaturized
)
1018 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1022 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1023 } else if (wPreferences
.focus_mode
!=WKF_CLICK
) {
1024 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1028 if (!wwin
->screen_ptr
->flags
.startup
) {
1029 Window clientwin
= wwin
->client_win
;
1032 processEvents(XPending(dpy
));
1034 /* the window can disappear while doing the processEvents() */
1035 if (!wWindowFor(clientwin
))
1042 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
)
1043 wIconSelect(wwin
->icon
);
1045 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1052 wDeiconifyWindow(WWindow
*wwin
)
1054 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1056 if (!wwin
->flags
.miniaturized
)
1059 if (wwin
->transient_for
!= None
1060 && wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1061 WWindow
*owner
= recursiveTransientFor(wwin
);
1063 if (owner
&& owner
->flags
.miniaturized
) {
1064 wDeiconifyWindow(owner
);
1065 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1066 wRaiseFrame(wwin
->frame
->core
);
1071 wwin
->flags
.miniaturized
= 0;
1072 if (!wwin
->flags
.shaded
)
1073 wwin
->flags
.mapped
= 1;
1075 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
) {
1076 if (wwin
->icon
->selected
)
1077 wIconSelect(wwin
->icon
);
1079 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1082 wSoundPlay(WSOUND_DEICONIFY
);
1084 /* if the window is in another workspace, do it silently */
1086 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1087 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1090 if (!wPreferences
.disable_miniwindows
) {
1093 iw
= wwin
->icon
->core
->width
;
1094 ih
= wwin
->icon
->core
->height
;
1099 if (wKWMGetIconGeometry(wwin
, &area
)) {
1105 #endif /* KWM_HINTS */
1109 iw
= wwin
->screen_ptr
->scr_width
;
1110 ih
= wwin
->screen_ptr
->scr_height
;
1113 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1114 wwin
->frame_x
, wwin
->frame_y
,
1115 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1118 #endif /* ANIMATIONS */
1119 wwin
->flags
.skip_next_animation
= 0;
1121 if (!wwin
->flags
.shaded
) {
1122 XMapWindow(dpy
, wwin
->client_win
);
1124 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1125 wRaiseFrame(wwin
->frame
->core
);
1126 if (!wwin
->flags
.shaded
) {
1127 wClientSetState(wwin
, NormalState
, None
);
1129 mapTransientsFor(wwin
);
1131 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
) {
1132 RemoveFromStackList(wwin
->icon
->core
);
1133 /* removeIconGrabs(wwin->icon);*/
1134 wIconDestroy(wwin
->icon
);
1139 if (wPreferences
.focus_mode
==WKF_CLICK
)
1140 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1143 if (!wwin
->screen_ptr
->flags
.startup
) {
1144 Window clientwin
= wwin
->client_win
;
1147 processEvents(XPending(dpy
));
1149 if (!wWindowFor(clientwin
))
1154 if (wPreferences
.auto_arrange_icons
) {
1155 wArrangeIcons(wwin
->screen_ptr
, True
);
1158 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1160 /* In case we were shaded and iconified, also unshade */
1161 wUnshadeWindow(wwin
);
1167 hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1169 if (wwin
->flags
.miniaturized
) {
1171 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1172 wwin
->icon
->mapped
= 0;
1174 wwin
->flags
.hidden
= 1;
1176 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1180 if (wwin
->flags
.inspector_open
) {
1181 wHideInspectorForWindow(wwin
);
1184 wwin
->flags
.hidden
= 1;
1187 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1189 wSoundPlay(WSOUND_HIDE
);
1191 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1192 !wwin
->flags
.skip_next_animation
&& animate
) {
1193 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1194 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1195 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
,
1199 wwin
->flags
.skip_next_animation
= 0;
1201 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1207 wHideOtherApplications(WWindow
*awin
)
1214 wwin
= awin
->screen_ptr
->focused_window
;
1219 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1220 && !(wwin
->flags
.miniaturized
||wwin
->flags
.hidden
)
1221 && !wwin
->flags
.internal_window
1222 && wGetWindowOfInspectorForWindow(wwin
) != awin
1223 && !WFLAGP(wwin
, no_hide_others
)) {
1225 if (wwin
->main_window
==None
|| WFLAGP(wwin
, no_appicon
)) {
1226 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1227 wwin
->flags
.skip_next_animation
= 1;
1228 wIconifyWindow(wwin
);
1230 } else if (wwin
->main_window
!=None
1231 && awin
->main_window
!= wwin
->main_window
) {
1232 tapp
= wApplicationOf(wwin
->main_window
);
1234 tapp
->flags
.skip_next_animation
= 1;
1235 wHideApplication(tapp
);
1237 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1238 wwin
->flags
.skip_next_animation
= 1;
1239 wIconifyWindow(wwin
);
1247 wSetFocusTo(awin->screen_ptr, awin);
1254 wHideApplication(WApplication
*wapp
)
1261 wwarning("trying to hide a non grouped window");
1264 if (!wapp
->main_window_desc
) {
1265 wwarning("group leader not found for window group");
1268 scr
= wapp
->main_window_desc
->screen_ptr
;
1270 wlist
= scr
->focused_window
;
1274 if (wlist
->main_window
== wapp
->main_window
)
1275 wapp
->last_focused
= wlist
;
1277 wapp
->last_focused
= NULL
;
1279 if (wlist
->main_window
== wapp
->main_window
) {
1280 if (wlist
->flags
.focused
) {
1284 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1285 wapp
->app_icon
->y_pos
, wlist
,
1286 !wapp
->flags
.skip_next_animation
);
1288 wlist
= wlist
->prev
;
1291 wapp
->flags
.skip_next_animation
= 0;
1294 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1295 wlist
= scr
->focused_window
;
1297 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1298 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1300 wlist
= wlist
->prev
;
1302 wSetFocusTo(scr
, wlist
);
1304 wSetFocusTo(scr
, NULL
);
1308 wapp
->flags
.hidden
= 1;
1310 if(wPreferences
.auto_arrange_icons
) {
1311 wArrangeIcons(scr
, True
);
1315 wAppIconPaint(wapp
->app_icon
);
1323 unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
,
1324 int bringToCurrentWS
)
1326 if (bringToCurrentWS
)
1327 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1329 wwin
->flags
.hidden
=0;
1331 wSoundPlay(WSOUND_UNHIDE
);
1333 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1335 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1336 icon
->core
->width
, icon
->core
->height
,
1337 wwin
->frame_x
, wwin
->frame_y
,
1338 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1342 wwin
->flags
.skip_next_animation
= 0;
1343 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1344 XMapWindow(dpy
, wwin
->client_win
);
1345 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1346 wClientSetState(wwin
, NormalState
, None
);
1347 wwin
->flags
.mapped
=1;
1348 wRaiseFrame(wwin
->frame
->core
);
1350 if (wwin
->flags
.inspector_open
) {
1351 wUnhideInspectorForWindow(wwin
);
1354 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1359 wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1362 WWindow
*wlist
, *next
;
1363 WWindow
*focused
=NULL
;
1368 scr
= wapp
->main_window_desc
->screen_ptr
;
1369 wlist
= scr
->focused_window
;
1371 /* goto beginning of list */
1373 wlist
= wlist
->prev
;
1378 if (wlist
->main_window
== wapp
->main_window
) {
1379 if (wlist
->flags
.focused
)
1381 else if (!focused
|| !focused
->flags
.focused
)
1384 if (wlist
->flags
.miniaturized
&& wlist
->icon
) {
1385 if (bringToCurrentWS
|| wPreferences
.sticky_icons
1386 || wlist
->frame
->workspace
== scr
->current_workspace
) {
1387 if (!wlist
->icon
->mapped
) {
1388 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1389 wlist
->icon
->mapped
= 1;
1391 wlist
->flags
.hidden
= 0;
1393 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1395 if (wlist
->frame
->workspace
!= scr
->current_workspace
)
1396 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1399 wDeiconifyWindow(wlist
);
1401 } else if (wlist
->flags
.hidden
) {
1402 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1403 wapp
->app_icon
->y_pos
, wlist
,
1404 !wapp
->flags
.skip_next_animation
,
1407 if (bringToCurrentWS
1408 && wlist
->frame
->workspace
!= scr
->current_workspace
) {
1409 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1411 wRaiseFrame(wlist
->frame
->core
);
1417 wapp
->flags
.skip_next_animation
= 0;
1418 wapp
->flags
.hidden
= 0;
1421 wSetFocusTo(scr
, focused
);
1422 else if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
)
1423 wSetFocusTo(scr
, wapp
->last_focused
);
1424 wapp
->last_focused
= NULL
;
1425 if (wPreferences
.auto_arrange_icons
) {
1426 wArrangeIcons(scr
, True
);
1429 wAppIconPaint(wapp
->app_icon
);
1436 wShowAllWindows(WScreen
*scr
)
1438 WWindow
*wwin
, *old_foc
;
1441 old_foc
= wwin
= scr
->focused_window
;
1443 if (!wwin
->flags
.internal_window
&&
1444 (scr
->current_workspace
== wwin
->frame
->workspace
1445 || IS_OMNIPRESENT(wwin
))) {
1446 if (wwin
->flags
.miniaturized
) {
1447 wwin
->flags
.skip_next_animation
= 1;
1448 wDeiconifyWindow(wwin
);
1449 } else if (wwin
->flags
.hidden
) {
1450 wapp
= wApplicationOf(wwin
->main_window
);
1452 wUnhideApplication(wapp
, False
, False
);
1454 wwin
->flags
.skip_next_animation
= 1;
1455 wDeiconifyWindow(wwin
);
1461 wSetFocusTo(scr
, old_foc
);
1462 /*wRaiseFrame(old_foc->frame->core);*/
1467 wRefreshDesktop(WScreen
*scr
)
1470 XSetWindowAttributes attr
;
1472 attr
.backing_store
= NotUseful
;
1473 attr
.save_under
= False
;
1474 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1475 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1476 (Visual
*)CopyFromParent
, CWBackingStore
|CWSaveUnder
,
1478 XMapRaised(dpy
, win
);
1479 XDestroyWindow(dpy
, win
);
1485 wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1489 int pf
; /* primary axis */
1490 int sf
; /* secondary axis */
1494 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1498 int isize
= wPreferences
.icon_size
;
1501 * Find out screen boundaries.
1505 * Allows each head to have miniwindows
1507 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1511 sw
= rect
.size
.width
;
1512 sh
= rect
.size
.height
;
1516 if (scr
->dock
->on_right_side
)
1517 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1519 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1523 sw
= isize
* (scr
->scr_width
/isize
);
1524 sh
= isize
* (scr
->scr_height
/isize
);
1526 sw
= isize
* (sw
/isize
);
1527 sh
= isize
* (sh
/isize
);
1529 fullW
= (sx2
-sx1
)/isize
;
1530 fullW
= (sx2
-sx1
)/isize
;
1531 fullH
= (sy2
-sy1
)/isize
;
1533 /* icon yard boundaries */
1534 if (wPreferences
.icon_yard
& IY_VERT
) {
1541 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1548 if (wPreferences
.icon_yard
& IY_TOP
) {
1556 /* arrange icons putting the most recently focused window
1557 * as the last icon */
1558 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1559 : xo + xs*(pi*isize))
1560 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1561 : yo + ys*(si*isize))
1563 /* arrange application icons */
1564 aicon
= scr
->app_icon_list
;
1565 /* reverse them to avoid unnecessarily sliding of icons */
1566 while (aicon
&& aicon
->next
)
1567 aicon
= aicon
->next
;
1572 if (!aicon
->docked
) {
1573 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1575 if (!wPreferences
.no_animations
) {
1576 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
,
1579 #endif /* ANIMATIONS */
1581 wAppIconMove(aicon
, X
, Y
);
1584 /* we reversed the order so we use prev */
1585 aicon
= aicon
->prev
;
1592 /* arrange miniwindows */
1594 wwin
= scr
->focused_window
;
1595 /* reverse them to avoid unnecessarily shuffling */
1596 while (wwin
&& wwin
->prev
)
1600 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1601 (wwin
->frame
->workspace
==scr
->current_workspace
||
1602 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1604 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1605 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1607 if (wPreferences
.no_animations
) {
1608 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1610 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1611 wwin
->icon_y
, X
, Y
);
1614 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1615 #endif /* ANIMATIONS */
1623 wwin
->flags
.icon_moved
= 0;
1625 /* we reversed the order, so we use next */
1636 wSelectWindow(WWindow
*wwin
, Bool flag
)
1638 WScreen
*scr
= wwin
->screen_ptr
;
1641 wwin
->flags
.selected
= 1;
1642 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1644 if (WFLAGP(wwin
, no_border
)) {
1645 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
,
1646 FRAME_BORDER_WIDTH
);
1649 if (!scr
->selected_windows
)
1650 scr
->selected_windows
= WMCreateArray(4);
1651 WMAddToArray(scr
->selected_windows
, wwin
);
1653 wwin
->flags
.selected
= 0;
1654 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
,
1655 scr
->frame_border_pixel
);
1657 if (WFLAGP(wwin
, no_border
)) {
1658 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1661 if (scr
->selected_windows
) {
1662 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1669 wMakeWindowVisible(WWindow
*wwin
)
1671 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1672 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1674 if (wwin
->flags
.shaded
) {
1675 wUnshadeWindow(wwin
);
1677 if (wwin
->flags
.hidden
) {
1680 app
= wApplicationOf(wwin
->main_window
);
1682 wUnhideApplication(app
, False
, False
);
1683 } else if (wwin
->flags
.miniaturized
) {
1684 wDeiconifyWindow(wwin
);
1686 if (!WFLAGP(wwin
, no_focusable
))
1687 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1688 wRaiseFrame(wwin
->frame
->core
);