1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
6 * Copyright (c) 1998 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"
61 /****** Global Variables ******/
62 extern Time LastTimestamp
;
63 extern Time LastFocusChange
;
65 extern Cursor wCursor
[WCUR_LAST
];
67 extern WPreferences wPreferences
;
69 extern Atom _XA_WM_TAKE_FOCUS
;
72 /******* Local Variables *******/
77 {SHADE_STEPS_UF
, SHADE_DELAY_UF
},
78 {SHADE_STEPS_F
, SHADE_DELAY_F
},
79 {SHADE_STEPS_M
, SHADE_DELAY_M
},
80 {SHADE_STEPS_S
, SHADE_DELAY_S
},
81 {SHADE_STEPS_U
, SHADE_DELAY_U
}};
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
87 static int ignoreTimestamp
=0;
92 processEvents(int event_count
)
97 * This is a hack. When animations are enabled, processing of
98 * events ocurred during a animation are delayed until it's end.
99 * Calls that consider the TimeStamp, like XSetInputFocus(), will
100 * fail because the TimeStamp is too old. Then, for example, if
101 * the user changes window focus while a miniaturize animation is
102 * in course, the window will not get focus properly after the end
103 * of the animation. This tries to workaround it by passing CurrentTime
104 * as the TimeStamp for XSetInputFocus() for all events ocurred during
108 while (XPending(dpy
) && event_count
--) {
109 WMNextEvent(dpy
, &event
);
110 WMHandleEvent(&event
);
114 #endif /* ANIMATIONS */
119 *----------------------------------------------------------------------
121 * Changes the window focus to the one passed as argument.
122 * If the window to focus is not already focused, it will be brought
123 * to the head of the list of windows. Previously focused window is
127 * Window list may be reordered and the window focus is changed.
129 *----------------------------------------------------------------------
132 wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
134 static WScreen
*old_scr
=NULL
;
136 WWindow
*old_focused
;
137 WWindow
*focused
=scr
->focused_window
;
138 int timestamp
=LastTimestamp
;
139 WApplication
*oapp
=NULL
, *napp
=NULL
;
144 old_focused
=old_scr
->focused_window
;
146 LastFocusChange
= timestamp
;
149 * This is a hack, because XSetInputFocus() should have a proper
150 * timestamp instead of CurrentTime but it seems that some times
151 * clients will not receive focus properly that way.
154 timestamp
= CurrentTime
;
157 oapp
= wApplicationOf(old_focused
->main_window
);
160 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
162 wWindowUnfocus(old_focused
);
165 wAppMenuUnmap(oapp
->menu
);
167 wApplicationDeactivate(oapp
);
171 WMPostNotificationName(WMNChangedFocus
, NULL
, (void*)True
);
173 } else if (old_scr
!= scr
&& old_focused
) {
174 wWindowUnfocus(old_focused
);
177 wasfocused
= wwin
->flags
.focused
;
178 napp
= wApplicationOf(wwin
->main_window
);
180 /* remember last workspace where the app has been */
182 napp
->last_workspace
= wwin
->screen_ptr
->current_workspace
;
184 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
185 /* install colormap if colormap mode is lock mode */
186 if (wPreferences
.colormap_mode
==WCM_CLICK
)
187 wColormapInstallForWindow(scr
, wwin
);
189 /* set input focus */
190 switch (wwin
->focus_mode
) {
192 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
196 case WFM_LOCALLY_ACTIVE
:
197 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, timestamp
);
200 case WFM_GLOBALLY_ACTIVE
:
204 if (wwin
->protocols
.TAKE_FOCUS
) {
205 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
209 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
211 if (WFLAGP(wwin
, no_focusable
))
214 /* if this is not the focused window focus it */
216 /* change the focus window list order */
218 wwin
->prev
->next
= wwin
->next
;
221 wwin
->next
->prev
= wwin
->prev
;
223 wwin
->prev
= focused
;
224 focused
->next
= wwin
;
226 scr
->focused_window
= wwin
;
228 if (oapp
&& oapp
!= napp
) {
229 wAppMenuUnmap(oapp
->menu
);
231 wApplicationDeactivate(oapp
);
236 wWindowFocus(wwin
, focused
);
238 if (napp
&& !wasfocused
) {
240 wUserMenuRefreshInstances(napp
->menu
, wwin
);
241 #endif /* USER_MENU */
243 if (wwin
->flags
.mapped
)
244 wAppMenuMap(napp
->menu
, wwin
);
246 wApplicationActivate(napp
);
256 wShadeWindow(WWindow
*wwin
)
258 time_t time0
= time(NULL
);
263 if (wwin
->flags
.shaded
)
266 XLowerWindow(dpy
, wwin
->client_win
);
268 wSoundPlay(WSOUND_SHADE
);
271 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
272 && !wPreferences
.no_animations
) {
273 /* do the shading animation */
274 h
= wwin
->frame
->core
->height
;
277 w
= wwin
->frame
->core
->width
;
278 y
= wwin
->frame
->top_width
;
279 while (h
>wwin
->frame
->top_width
+1) {
280 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
281 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
284 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
288 wusleep(SHADE_DELAY
*1000L);
292 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
294 #endif /* ANIMATIONS */
296 wwin
->flags
.skip_next_animation
= 0;
297 wwin
->flags
.shaded
= 1;
298 wwin
->flags
.mapped
= 0;
299 /* prevent window withdrawal when getting UnmapNotify */
300 XSelectInput(dpy
, wwin
->client_win
,
301 wwin
->event_mask
& ~StructureNotifyMask
);
302 XUnmapWindow(dpy
, wwin
->client_win
);
303 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
305 /* for the client it's just like iconification */
306 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
307 wwin
->frame
->top_width
- 1);
309 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
310 + wwin
->frame
->top_width
;
311 wWindowSynthConfigureNotify(wwin
);
314 wClientSetState(wwin, IconicState, None);
317 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
320 if (!wwin
->screen_ptr
->flags
.startup
) {
321 /* Look at processEvents() for reason of this code. */
323 processEvents(XPending(dpy
));
330 wUnshadeWindow(WWindow
*wwin
)
332 time_t time0
= time(NULL
);
335 #endif /* ANIMATIONS */
338 if (!wwin
->flags
.shaded
)
341 wwin
->flags
.shaded
= 0;
342 wwin
->flags
.mapped
= 1;
343 XMapWindow(dpy
, wwin
->client_win
);
345 wSoundPlay(WSOUND_UNSHADE
);
348 if (!wPreferences
.no_animations
&& !wwin
->flags
.skip_next_animation
) {
349 /* do the shading animation */
350 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
351 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
352 s
= abs(y
)/SHADE_STEPS
;
354 w
= wwin
->frame
->core
->width
;
355 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
357 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
358 + wwin
->frame
->bottom_width
) {
359 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
360 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
363 wusleep(SHADE_DELAY
*2000L/3);
367 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
371 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
373 #endif /* ANIMATIONS */
375 wwin
->flags
.skip_next_animation
= 0;
376 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
377 wwin
->frame
->top_width
+ wwin
->client
.height
378 + wwin
->frame
->bottom_width
);
380 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
381 wWindowSynthConfigureNotify(wwin
);
384 wClientSetState(wwin, NormalState, None);
386 /* if the window is focused, set the focus again as it was disabled during
388 if (wwin
->flags
.focused
)
389 wSetFocusTo(wwin
->screen_ptr
, wwin
);
391 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
396 wMaximizeWindow(WWindow
*wwin
, int directions
)
398 int new_width
, new_height
, new_x
, new_y
;
399 WArea usableArea
= wwin
->screen_ptr
->totalUsableArea
;
403 if (WFLAGP(wwin
, no_resizable
))
408 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
409 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
412 if (wwin
->screen_ptr
->xine_count
> 0
413 && !(directions
& MAX_IGNORE_XINERAMA
)) {
414 WScreen
*scr
= wwin
->screen_ptr
;
417 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
418 totalArea
.x1
= rect
.pos
.x
;
419 totalArea
.y1
= rect
.pos
.y
;
420 totalArea
.x2
= totalArea
.x1
+ rect
.size
.width
;
421 totalArea
.y2
= totalArea
.y1
+ rect
.size
.height
;
423 usableArea
.x1
= WMAX(totalArea
.x1
, usableArea
.x1
);
424 usableArea
.y1
= WMAX(totalArea
.y1
, usableArea
.y1
);
425 usableArea
.x2
= WMIN(totalArea
.x2
, usableArea
.x2
);
426 usableArea
.y2
= WMIN(totalArea
.y2
, usableArea
.y2
);
428 #endif /* XINERAMA */
430 if (WFLAGP(wwin
, full_maximize
)) {
431 usableArea
= totalArea
;
434 if (wwin
->flags
.shaded
) {
435 wwin
->flags
.skip_next_animation
= 1;
436 wUnshadeWindow(wwin
);
438 wwin
->flags
.maximized
= directions
;
439 wwin
->old_geometry
.width
= wwin
->client
.width
;
440 wwin
->old_geometry
.height
= wwin
->client
.height
;
441 wwin
->old_geometry
.x
= wwin
->frame_x
;
442 wwin
->old_geometry
.y
= wwin
->frame_y
;
445 wKWMUpdateClientGeometryRestore(wwin
);
448 if (directions
& MAX_HORIZONTAL
) {
450 new_width
= (usableArea
.x2
-usableArea
.x1
)-FRAME_BORDER_WIDTH
*2;
451 new_x
= usableArea
.x1
;
455 new_x
= wwin
->frame_x
;
456 new_width
= wwin
->frame
->core
->width
;
460 if (directions
& MAX_VERTICAL
) {
462 new_height
= (usableArea
.y2
-usableArea
.y1
)-FRAME_BORDER_WIDTH
*2;
463 new_y
= usableArea
.y1
;
464 if (WFLAGP(wwin
, full_maximize
)) {
465 new_y
-= wwin
->frame
->top_width
;
466 new_height
+= wwin
->frame
->bottom_width
- 1;
469 new_y
= wwin
->frame_y
;
470 new_height
= wwin
->frame
->core
->height
;
473 if (!WFLAGP(wwin
, full_maximize
)) {
474 new_height
-= wwin
->frame
->top_width
+wwin
->frame
->bottom_width
;
477 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
479 wWindowCropSize(wwin
, usableArea
.x2
-usableArea
.x1
,
480 usableArea
.y2
-usableArea
.y1
,
481 &new_width
, &new_height
);
483 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
486 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
488 wSoundPlay(WSOUND_MAXIMIZE
);
493 wUnmaximizeWindow(WWindow
*wwin
)
495 int restore_x
, restore_y
;
497 if (!wwin
->flags
.maximized
)
500 if (wwin
->flags
.shaded
) {
501 wwin
->flags
.skip_next_animation
= 1;
502 wUnshadeWindow(wwin
);
504 restore_x
= (wwin
->flags
.maximized
& MAX_HORIZONTAL
) ?
505 wwin
->old_geometry
.x
: wwin
->frame_x
;
506 restore_y
= (wwin
->flags
.maximized
& MAX_VERTICAL
) ?
507 wwin
->old_geometry
.y
: wwin
->frame_y
;
508 wwin
->flags
.maximized
= 0;
509 wWindowConfigure(wwin
, restore_x
, restore_y
,
510 wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
512 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
514 wSoundPlay(WSOUND_UNMAXIMIZE
);
519 animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
,
520 int fx
, int fy
, int fw
, int fh
, int steps
)
522 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
523 float cx
, cy
, cw
, ch
;
524 float xstep
, ystep
, wstep
, hstep
;
527 float angle
, final_angle
, delta
;
529 xstep
= (float)(fx
-x
)/steps
;
530 ystep
= (float)(fy
-y
)/steps
;
531 wstep
= (float)(fw
-w
)/steps
;
532 hstep
= (float)(fh
-h
)/steps
;
539 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_F
;
540 delta
= (float)(final_angle
/FRAMES
);
541 for (angle
=0;; angle
+=delta
) {
542 if (angle
> final_angle
)
545 dx
= (cw
/10) - ((cw
/5) * sin(angle
));
546 dch
= (ch
/2) * cos(angle
);
549 points
[0].x
= cx
+ dx
; points
[0].y
= midy
- dch
;
550 points
[1].x
= cx
+ cw
- dx
; points
[1].y
= points
[0].y
;
551 points
[2].x
= cx
+ cw
+ dx
; points
[2].y
= midy
+ dch
;
552 points
[3].x
= cx
- dx
; points
[3].y
= points
[2].y
;
553 points
[4].x
= points
[0].x
; points
[4].y
= points
[0].y
;
556 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
558 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
559 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
562 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
568 if (angle
>= final_angle
)
578 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
,
579 int fx
, int fy
, int fw
, int fh
, int steps
)
581 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
582 float cx
, cy
, cw
, ch
;
583 float xstep
, ystep
, wstep
, hstep
;
585 float angle
, final_angle
, a
, d
, delta
;
592 xstep
= (float)(fx
-x
)/steps
;
593 ystep
= (float)(fy
-y
)/steps
;
594 wstep
= (float)(fw
-w
)/steps
;
595 hstep
= (float)(fh
-h
)/steps
;
602 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_T
;
603 delta
= (float)(final_angle
/FRAMES
);
604 for (angle
=0;; angle
+=delta
) {
605 if (angle
> final_angle
)
609 d
= sqrt((cw
/2)*(cw
/2)+(ch
/2)*(ch
/2));
611 points
[0].x
= cx
+cos(angle
-a
)*d
;
612 points
[0].y
= cy
+sin(angle
-a
)*d
;
613 points
[1].x
= cx
+cos(angle
+a
)*d
;
614 points
[1].y
= cy
+sin(angle
+a
)*d
;
615 points
[2].x
= cx
+cos(angle
-a
+WM_PI
)*d
;
616 points
[2].y
= cy
+sin(angle
-a
+WM_PI
)*d
;
617 points
[3].x
= cx
+cos(angle
+a
+WM_PI
)*d
;
618 points
[3].y
= cy
+sin(angle
+a
+WM_PI
)*d
;
619 points
[4].x
= cx
+cos(angle
-a
)*d
;
620 points
[4].y
= cy
+sin(angle
-a
)*d
;
622 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
624 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
625 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
628 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
634 if (angle
>= final_angle
)
644 animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
,
645 int fx
, int fy
, int fw
, int fh
, int steps
)
647 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
648 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
649 float xstep
, ystep
, wstep
, hstep
;
652 xstep
= (float)(fx
-x
)/steps
;
653 ystep
= (float)(fy
-y
)/steps
;
654 wstep
= (float)(fw
-w
)/steps
;
655 hstep
= (float)(fh
-h
)/steps
;
657 for (j
=0; j
<FRAMES
; j
++) {
664 for (i
=0; i
<steps
; i
++) {
665 for (j
=0; j
<FRAMES
; j
++) {
666 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
667 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
670 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
671 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
673 for (j
=0; j
<FRAMES
; j
++) {
674 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
675 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
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
]);
695 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
696 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
698 for (j
=0; j
<FRAMES
; j
++) {
699 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
700 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
709 animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
,
710 int fx
, int fy
, int fw
, int fh
, int hiding
)
712 int style
= wPreferences
.iconification_style
; /* Catch the value */
715 if (style
== WIS_NONE
)
718 if (style
== WIS_RANDOM
) {
722 k
= (hiding
? 2 : 3);
725 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
)/3;
727 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
730 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
)/3;
732 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
736 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
)/3;
738 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
742 #endif /* ANIMATIONS */
750 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
751 WMHandleEvent(&tmpev
);
756 unmapTransientsFor(WWindow
*wwin
)
761 tmp
= wwin
->screen_ptr
->focused_window
;
763 /* unmap the transients for this transient */
764 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
765 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
766 || tmp
->flags
.shaded
)) {
767 unmapTransientsFor(tmp
);
768 tmp
->flags
.miniaturized
= 1;
769 if (!tmp
->flags
.shaded
) {
772 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
775 if (!tmp->flags.shaded)
777 wClientSetState(tmp
, IconicState
, None
);
779 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
787 mapTransientsFor(WWindow
*wwin
)
791 tmp
= wwin
->screen_ptr
->focused_window
;
793 /* recursively map the transients for this transient */
794 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
795 && /*!tmp->flags.mapped*/ tmp
->flags
.miniaturized
796 && tmp
->icon
==NULL
) {
797 mapTransientsFor(tmp
);
798 tmp
->flags
.miniaturized
= 0;
799 if (!tmp
->flags
.shaded
) {
802 XMapWindow(dpy
, tmp
->frame
->core
->window
);
804 tmp
->flags
.semi_focused
= 0;
806 if (!tmp->flags.shaded)
808 wClientSetState(tmp
, NormalState
, None
);
810 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
818 setupIconGrabs(WIcon
*icon
)
820 /* setup passive grabs on the icon */
821 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
822 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
823 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
824 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
825 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
826 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
832 recursiveTransientFor(WWindow
*wwin
)
839 /* hackish way to detect transient_for cycle */
840 i
= wwin
->screen_ptr
->window_count
+1;
842 while (wwin
&& wwin
->transient_for
!= None
&& i
>0) {
843 wwin
= wWindowFor(wwin
->transient_for
);
847 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
857 removeIconGrabs(WIcon
*icon
)
859 /* remove passive grabs on the icon */
860 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
861 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
862 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
869 wIconifyWindow(WWindow
*wwin
)
871 XWindowAttributes attribs
;
875 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
876 /* the window doesn't exist anymore */
880 if (wwin
->flags
.miniaturized
) {
885 if (wwin
->transient_for
!=None
) {
886 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
888 if (owner
&& owner
->flags
.miniaturized
)
892 present
= wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
;
894 /* if the window is in another workspace, simplify process */
896 /* icon creation may take a while */
897 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
898 ButtonMotionMask
|ButtonReleaseMask
, GrabModeAsync
,
899 GrabModeAsync
, None
, None
, CurrentTime
);
902 if (!wPreferences
.disable_miniwindows
) {
903 if (!wwin
->flags
.icon_moved
) {
904 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
);
906 wwin
->icon
= wIconCreate(wwin
);
908 wwin
->icon
->mapped
= 1;
911 wwin
->flags
.miniaturized
= 1;
912 wwin
->flags
.mapped
= 0;
914 /* unmap transients */
916 unmapTransientsFor(wwin
);
919 wSoundPlay(WSOUND_ICONIFY
);
921 XUngrabPointer(dpy
, CurrentTime
);
923 /* let all Expose events arrive so that we can repaint
924 * something before the animation starts (and the server is grabbed) */
927 if (wPreferences
.disable_miniwindows
)
928 wClientSetState(wwin
, IconicState
, None
);
930 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
934 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
935 && !wPreferences
.no_animations
) {
938 if (!wPreferences
.disable_miniwindows
) {
941 iw
= wwin
->icon
->core
->width
;
942 ih
= wwin
->icon
->core
->height
;
947 if (wKWMGetIconGeometry(wwin
, &area
)) {
953 #endif /* KWM_HINTS */
957 iw
= wwin
->screen_ptr
->scr_width
;
958 ih
= wwin
->screen_ptr
->scr_height
;
961 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
962 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
963 ix
, iy
, iw
, ih
, False
);
968 wwin
->flags
.skip_next_animation
= 0;
970 if (!wPreferences
.disable_miniwindows
) {
972 if (wwin
->screen_ptr
->current_workspace
==wwin
->frame
->workspace
||
973 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
975 XMapWindow(dpy
, wwin
->icon
->core
->window
);
977 AddToStackList(wwin
->icon
->core
);
979 wLowerFrame(wwin
->icon
->core
);
983 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
986 * It doesn't seem to be working and causes button event hangup
987 * when deiconifying a transient window.
988 setupIconGrabs(wwin->icon);
990 if ((wwin
->flags
.focused
991 || (owner
&& wwin
->client_win
== owner
->client_win
))
992 && wPreferences
.focus_mode
==WKF_CLICK
) {
997 if (!WFLAGP(tmp
, no_focusable
)
998 && !(tmp
->flags
.hidden
||tmp
->flags
.miniaturized
)
999 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1003 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1004 } else if (wPreferences
.focus_mode
!=WKF_CLICK
) {
1005 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1009 if (!wwin
->screen_ptr
->flags
.startup
) {
1010 Window clientwin
= wwin
->client_win
;
1013 processEvents(XPending(dpy
));
1015 /* the window can disappear while doing the processEvents() */
1016 if (!wWindowFor(clientwin
))
1023 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
)
1024 wIconSelect(wwin
->icon
);
1026 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1033 wDeiconifyWindow(WWindow
*wwin
)
1035 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1037 if (!wwin
->flags
.miniaturized
)
1040 if (wwin
->transient_for
!= None
1041 && wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1042 WWindow
*owner
= recursiveTransientFor(wwin
);
1044 if (owner
&& owner
->flags
.miniaturized
) {
1045 wDeiconifyWindow(owner
);
1046 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1047 wRaiseFrame(wwin
->frame
->core
);
1052 wwin
->flags
.miniaturized
= 0;
1053 if (!wwin
->flags
.shaded
)
1054 wwin
->flags
.mapped
= 1;
1056 if (!wPreferences
.disable_miniwindows
) {
1057 if (wwin
->icon
->selected
)
1058 wIconSelect(wwin
->icon
);
1060 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1063 wSoundPlay(WSOUND_DEICONIFY
);
1065 /* if the window is in another workspace, do it silently */
1067 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1068 && !wwin
->flags
.skip_next_animation
) {
1071 if (!wPreferences
.disable_miniwindows
) {
1074 iw
= wwin
->icon
->core
->width
;
1075 ih
= wwin
->icon
->core
->height
;
1080 if (wKWMGetIconGeometry(wwin
, &area
)) {
1086 #endif /* KWM_HINTS */
1090 iw
= wwin
->screen_ptr
->scr_width
;
1091 ih
= wwin
->screen_ptr
->scr_height
;
1094 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1095 wwin
->frame_x
, wwin
->frame_y
,
1096 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1099 #endif /* ANIMATIONS */
1100 wwin
->flags
.skip_next_animation
= 0;
1102 if (!wwin
->flags
.shaded
) {
1103 XMapWindow(dpy
, wwin
->client_win
);
1105 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1106 wRaiseFrame(wwin
->frame
->core
);
1107 if (!wwin
->flags
.shaded
) {
1108 wClientSetState(wwin
, NormalState
, None
);
1110 mapTransientsFor(wwin
);
1112 if (!wPreferences
.disable_miniwindows
) {
1113 RemoveFromStackList(wwin
->icon
->core
);
1114 /* removeIconGrabs(wwin->icon);*/
1115 wIconDestroy(wwin
->icon
);
1120 if (wPreferences
.focus_mode
==WKF_CLICK
)
1121 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1124 if (!wwin
->screen_ptr
->flags
.startup
) {
1125 Window clientwin
= wwin
->client_win
;
1128 processEvents(XPending(dpy
));
1130 if (!wWindowFor(clientwin
))
1135 if (wPreferences
.auto_arrange_icons
) {
1136 wArrangeIcons(wwin
->screen_ptr
, True
);
1139 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1145 hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1147 if (wwin
->flags
.miniaturized
) {
1149 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1150 wwin
->icon
->mapped
= 0;
1152 wwin
->flags
.hidden
= 1;
1154 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1158 if (wwin
->flags
.inspector_open
) {
1159 wHideInspectorForWindow(wwin
);
1162 wwin
->flags
.hidden
= 1;
1165 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1167 wSoundPlay(WSOUND_HIDE
);
1169 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1170 !wwin
->flags
.skip_next_animation
&& animate
) {
1171 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1172 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1173 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
,
1177 wwin
->flags
.skip_next_animation
= 0;
1179 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1185 wHideOtherApplications(WWindow
*awin
)
1192 wwin
= awin
->screen_ptr
->focused_window
;
1197 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1198 && !(wwin
->flags
.miniaturized
||wwin
->flags
.hidden
)
1199 && !wwin
->flags
.internal_window
1200 && wGetWindowOfInspectorForWindow(wwin
) != awin
1201 && !WFLAGP(wwin
, no_hide_others
)) {
1203 if (wwin
->main_window
==None
|| WFLAGP(wwin
, no_appicon
)) {
1204 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1205 wwin
->flags
.skip_next_animation
= 1;
1206 wIconifyWindow(wwin
);
1208 } else if (wwin
->main_window
!=None
1209 && awin
->main_window
!= wwin
->main_window
) {
1210 tapp
= wApplicationOf(wwin
->main_window
);
1212 tapp
->flags
.skip_next_animation
= 1;
1213 wHideApplication(tapp
);
1215 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1216 wwin
->flags
.skip_next_animation
= 1;
1217 wIconifyWindow(wwin
);
1225 wSetFocusTo(awin->screen_ptr, awin);
1232 wHideApplication(WApplication
*wapp
)
1239 wwarning("trying to hide a non grouped window");
1242 if (!wapp
->main_window_desc
) {
1243 wwarning("group leader not found for window group");
1246 scr
= wapp
->main_window_desc
->screen_ptr
;
1248 wlist
= scr
->focused_window
;
1252 if (wlist
->main_window
== wapp
->main_window
)
1253 wapp
->last_focused
= wlist
;
1255 wapp
->last_focused
= NULL
;
1257 if (wlist
->main_window
== wapp
->main_window
) {
1258 if (wlist
->flags
.focused
) {
1262 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1263 wapp
->app_icon
->y_pos
, wlist
,
1264 !wapp
->flags
.skip_next_animation
);
1266 wlist
= wlist
->prev
;
1269 wapp
->flags
.skip_next_animation
= 0;
1272 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1273 wlist
= scr
->focused_window
;
1275 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1276 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1278 wlist
= wlist
->prev
;
1280 wSetFocusTo(scr
, wlist
);
1282 wSetFocusTo(scr
, NULL
);
1286 wapp
->flags
.hidden
= 1;
1288 if(wPreferences
.auto_arrange_icons
) {
1289 wArrangeIcons(scr
, True
);
1293 wAppIconPaint(wapp
->app_icon
);
1301 unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
,
1302 int bringToCurrentWS
)
1304 if (bringToCurrentWS
)
1305 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1307 wwin
->flags
.hidden
=0;
1308 wwin
->flags
.mapped
=1;
1310 wSoundPlay(WSOUND_UNHIDE
);
1312 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1314 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1315 icon
->core
->width
, icon
->core
->height
,
1316 wwin
->frame_x
, wwin
->frame_y
,
1317 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1321 wwin
->flags
.skip_next_animation
= 0;
1322 XMapWindow(dpy
, wwin
->client_win
);
1323 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1324 wClientSetState(wwin
, NormalState
, None
);
1325 wRaiseFrame(wwin
->frame
->core
);
1326 if (wwin
->flags
.inspector_open
) {
1327 wUnhideInspectorForWindow(wwin
);
1330 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1335 wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1338 WWindow
*wlist
, *next
;
1339 WWindow
*focused
=NULL
;
1344 scr
= wapp
->main_window_desc
->screen_ptr
;
1345 wlist
= scr
->focused_window
;
1347 /* goto beginning of list */
1349 wlist
= wlist
->prev
;
1354 if (wlist
->main_window
== wapp
->main_window
) {
1355 if (wlist
->flags
.focused
)
1357 else if (!focused
|| !focused
->flags
.focused
)
1360 if (wlist
->flags
.miniaturized
&& wlist
->icon
) {
1361 if (bringToCurrentWS
|| wPreferences
.sticky_icons
1362 || wlist
->frame
->workspace
== scr
->current_workspace
) {
1363 if (!wlist
->icon
->mapped
) {
1364 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1365 wlist
->icon
->mapped
= 1;
1367 wlist
->flags
.hidden
= 0;
1369 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1371 if (wlist
->frame
->workspace
!= scr
->current_workspace
)
1372 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1375 wDeiconifyWindow(wlist
);
1377 } else if (wlist
->flags
.hidden
) {
1378 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1379 wapp
->app_icon
->y_pos
, wlist
,
1380 !wapp
->flags
.skip_next_animation
,
1383 if (bringToCurrentWS
1384 && wlist
->frame
->workspace
!= scr
->current_workspace
) {
1385 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1387 wRaiseFrame(wlist
->frame
->core
);
1393 wapp
->flags
.skip_next_animation
= 0;
1394 wapp
->flags
.hidden
= 0;
1397 wSetFocusTo(scr
, focused
);
1398 else if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
)
1399 wSetFocusTo(scr
, wapp
->last_focused
);
1400 wapp
->last_focused
= NULL
;
1401 if (wPreferences
.auto_arrange_icons
) {
1402 wArrangeIcons(scr
, True
);
1405 wAppIconPaint(wapp
->app_icon
);
1412 wShowAllWindows(WScreen
*scr
)
1414 WWindow
*wwin
, *old_foc
;
1417 old_foc
= wwin
= scr
->focused_window
;
1419 if (!wwin
->flags
.internal_window
&&
1420 (scr
->current_workspace
== wwin
->frame
->workspace
1421 || IS_OMNIPRESENT(wwin
))) {
1422 if (wwin
->flags
.miniaturized
) {
1423 wwin
->flags
.skip_next_animation
= 1;
1424 wDeiconifyWindow(wwin
);
1425 } else if (wwin
->flags
.hidden
) {
1426 wapp
= wApplicationOf(wwin
->main_window
);
1428 wUnhideApplication(wapp
, False
, False
);
1430 wwin
->flags
.skip_next_animation
= 1;
1431 wDeiconifyWindow(wwin
);
1437 wSetFocusTo(scr
, old_foc
);
1438 /*wRaiseFrame(old_foc->frame->core);*/
1443 wRefreshDesktop(WScreen
*scr
)
1446 XSetWindowAttributes attr
;
1448 attr
.backing_store
= NotUseful
;
1449 attr
.save_under
= False
;
1450 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1451 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1452 (Visual
*)CopyFromParent
, CWBackingStore
|CWSaveUnder
,
1454 XMapRaised(dpy
, win
);
1455 XDestroyWindow(dpy
, win
);
1461 wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1465 int pf
; /* primary axis */
1466 int sf
; /* secondary axis */
1470 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1474 int isize
= wPreferences
.icon_size
;
1477 * Find out screen boundaries.
1481 sx2
= scr
->scr_width
;
1482 sy2
= scr
->scr_height
;
1484 if (scr
->dock
->on_right_side
)
1485 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1487 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1490 sw
= isize
* (scr
->scr_width
/isize
);
1491 sh
= isize
* (scr
->scr_height
/isize
);
1492 fullW
= (sx2
-sx1
)/isize
;
1493 fullH
= (sy2
-sy1
)/isize
;
1495 /* icon yard boundaries */
1496 if (wPreferences
.icon_yard
& IY_VERT
) {
1503 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1510 if (wPreferences
.icon_yard
& IY_TOP
) {
1518 /* arrange icons putting the most recently focused window
1519 * as the last icon */
1520 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1521 : xo + xs*(pi*isize))
1522 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1523 : yo + ys*(si*isize))
1525 /* arrange application icons */
1526 aicon
= scr
->app_icon_list
;
1527 /* reverse them to avoid unnecessarily sliding of icons */
1528 while (aicon
&& aicon
->next
)
1529 aicon
= aicon
->next
;
1534 if (!aicon
->docked
&& wAppIconIsFirstInstance(aicon
)) {
1535 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1537 if (!wPreferences
.no_animations
) {
1538 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
,
1541 #endif /* ANIMATIONS */
1543 wAppIconMove(aicon
, X
, Y
);
1546 /* we reversed the order so we use prev */
1547 aicon
= aicon
->prev
;
1554 /* arrange miniwindows */
1556 wwin
= scr
->focused_window
;
1557 /* reverse them to avoid unnecessarily shuffling */
1558 while (wwin
&& wwin
->prev
)
1562 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1563 (wwin
->frame
->workspace
==scr
->current_workspace
||
1564 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1566 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1567 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1569 if (wPreferences
.no_animations
) {
1570 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1572 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1573 wwin
->icon_y
, X
, Y
);
1576 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1577 #endif /* ANIMATIONS */
1585 wwin
->flags
.icon_moved
= 0;
1587 /* we reversed the order, so we use next */
1598 wSelectWindow(WWindow
*wwin
, Bool flag
)
1600 WScreen
*scr
= wwin
->screen_ptr
;
1603 wwin
->flags
.selected
= 1;
1604 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1606 if (WFLAGP(wwin
, no_border
)) {
1607 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
,
1608 FRAME_BORDER_WIDTH
);
1611 if (!scr
->selected_windows
)
1612 scr
->selected_windows
= WMCreateArray(4);
1613 WMAddToArray(scr
->selected_windows
, wwin
);
1615 wwin
->flags
.selected
= 0;
1616 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
,
1617 scr
->frame_border_pixel
);
1619 if (WFLAGP(wwin
, no_border
)) {
1620 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1623 if (scr
->selected_windows
) {
1624 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1631 wMakeWindowVisible(WWindow
*wwin
)
1633 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1634 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1636 if (wwin
->flags
.shaded
) {
1637 wUnshadeWindow(wwin
);
1639 if (wwin
->flags
.hidden
) {
1642 app
= wApplicationOf(wwin
->main_window
);
1644 wUnhideApplication(app
, False
, False
);
1645 } else if (wwin
->flags
.miniaturized
) {
1646 wDeiconifyWindow(wwin
);
1648 if (!WFLAGP(wwin
, no_focusable
))
1649 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1650 wRaiseFrame(wwin
->frame
->core
);