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_US
, SHADE_DELAY_US
}};
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
)
263 if (wwin
->flags
.shaded
)
268 XLowerWindow(dpy
, wwin
->client_win
);
270 wSoundPlay(WSOUND_SHADE
);
273 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
274 && !wPreferences
.no_animations
) {
275 /* do the shading animation */
276 h
= wwin
->frame
->core
->height
;
279 w
= wwin
->frame
->core
->width
;
280 y
= wwin
->frame
->top_width
;
281 while (h
>wwin
->frame
->top_width
+1) {
282 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
283 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
286 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
289 if (SHADE_DELAY
> 0) {
290 wusleep(SHADE_DELAY
*1000L);
297 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
299 #endif /* ANIMATIONS */
301 wwin
->flags
.skip_next_animation
= 0;
302 wwin
->flags
.shaded
= 1;
303 wwin
->flags
.mapped
= 0;
304 /* prevent window withdrawal when getting UnmapNotify */
305 XSelectInput(dpy
, wwin
->client_win
,
306 wwin
->event_mask
& ~StructureNotifyMask
);
307 XUnmapWindow(dpy
, wwin
->client_win
);
308 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
310 /* for the client it's just like iconification */
311 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
312 wwin
->frame
->top_width
- 1);
314 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
315 + wwin
->frame
->top_width
;
316 wWindowSynthConfigureNotify(wwin
);
319 wClientSetState(wwin, IconicState, None);
322 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
325 if (!wwin
->screen_ptr
->flags
.startup
) {
326 /* Look at processEvents() for reason of this code. */
328 processEvents(XPending(dpy
));
335 wUnshadeWindow(WWindow
*wwin
)
340 #endif /* ANIMATIONS */
343 if (!wwin
->flags
.shaded
)
348 wwin
->flags
.shaded
= 0;
349 wwin
->flags
.mapped
= 1;
350 XMapWindow(dpy
, wwin
->client_win
);
352 wSoundPlay(WSOUND_UNSHADE
);
355 if (!wPreferences
.no_animations
&& !wwin
->flags
.skip_next_animation
) {
356 /* do the shading animation */
357 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
358 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
359 s
= abs(y
)/SHADE_STEPS
;
361 w
= wwin
->frame
->core
->width
;
362 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
364 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
365 + wwin
->frame
->bottom_width
) {
366 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
367 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
369 if (SHADE_DELAY
> 0) {
370 wusleep(SHADE_DELAY
*2000L/3);
377 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
381 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
383 #endif /* ANIMATIONS */
385 wwin
->flags
.skip_next_animation
= 0;
386 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
387 wwin
->frame
->top_width
+ wwin
->client
.height
388 + wwin
->frame
->bottom_width
);
390 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
391 wWindowSynthConfigureNotify(wwin
);
394 wClientSetState(wwin, NormalState, None);
396 /* if the window is focused, set the focus again as it was disabled during
398 if (wwin
->flags
.focused
)
399 wSetFocusTo(wwin
->screen_ptr
, wwin
);
401 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
406 wMaximizeWindow(WWindow
*wwin
, int directions
)
408 int new_width
, new_height
, new_x
, new_y
;
409 WArea usableArea
= wwin
->screen_ptr
->totalUsableArea
;
413 if (WFLAGP(wwin
, no_resizable
))
418 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
419 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
422 if (wwin
->screen_ptr
->xine_count
> 0
423 && !(directions
& MAX_IGNORE_XINERAMA
)) {
424 WScreen
*scr
= wwin
->screen_ptr
;
427 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
428 totalArea
.x1
= rect
.pos
.x
;
429 totalArea
.y1
= rect
.pos
.y
;
430 totalArea
.x2
= totalArea
.x1
+ rect
.size
.width
;
431 totalArea
.y2
= totalArea
.y1
+ rect
.size
.height
;
433 usableArea
.x1
= WMAX(totalArea
.x1
, usableArea
.x1
);
434 usableArea
.y1
= WMAX(totalArea
.y1
, usableArea
.y1
);
435 usableArea
.x2
= WMIN(totalArea
.x2
, usableArea
.x2
);
436 usableArea
.y2
= WMIN(totalArea
.y2
, usableArea
.y2
);
438 #endif /* XINERAMA */
440 if (WFLAGP(wwin
, full_maximize
)) {
441 usableArea
= totalArea
;
444 if (wwin
->flags
.shaded
) {
445 wwin
->flags
.skip_next_animation
= 1;
446 wUnshadeWindow(wwin
);
448 wwin
->flags
.maximized
= directions
;
449 wwin
->old_geometry
.width
= wwin
->client
.width
;
450 wwin
->old_geometry
.height
= wwin
->client
.height
;
451 wwin
->old_geometry
.x
= wwin
->frame_x
;
452 wwin
->old_geometry
.y
= wwin
->frame_y
;
455 wKWMUpdateClientGeometryRestore(wwin
);
458 if (directions
& MAX_HORIZONTAL
) {
460 new_width
= (usableArea
.x2
-usableArea
.x1
)-FRAME_BORDER_WIDTH
*2;
461 new_x
= usableArea
.x1
;
465 new_x
= wwin
->frame_x
;
466 new_width
= wwin
->frame
->core
->width
;
470 if (directions
& MAX_VERTICAL
) {
472 new_height
= (usableArea
.y2
-usableArea
.y1
)-FRAME_BORDER_WIDTH
*2;
473 new_y
= usableArea
.y1
;
474 if (WFLAGP(wwin
, full_maximize
)) {
475 new_y
-= wwin
->frame
->top_width
;
476 new_height
+= wwin
->frame
->bottom_width
- 1;
479 new_y
= wwin
->frame_y
;
480 new_height
= wwin
->frame
->core
->height
;
483 if (!WFLAGP(wwin
, full_maximize
)) {
484 new_height
-= wwin
->frame
->top_width
+wwin
->frame
->bottom_width
;
487 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
489 wWindowCropSize(wwin
, usableArea
.x2
-usableArea
.x1
,
490 usableArea
.y2
-usableArea
.y1
,
491 &new_width
, &new_height
);
493 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
496 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
498 wSoundPlay(WSOUND_MAXIMIZE
);
503 wUnmaximizeWindow(WWindow
*wwin
)
505 int restore_x
, restore_y
;
507 if (!wwin
->flags
.maximized
)
510 if (wwin
->flags
.shaded
) {
511 wwin
->flags
.skip_next_animation
= 1;
512 wUnshadeWindow(wwin
);
514 restore_x
= (wwin
->flags
.maximized
& MAX_HORIZONTAL
) ?
515 wwin
->old_geometry
.x
: wwin
->frame_x
;
516 restore_y
= (wwin
->flags
.maximized
& MAX_VERTICAL
) ?
517 wwin
->old_geometry
.y
: wwin
->frame_y
;
518 wwin
->flags
.maximized
= 0;
519 wWindowConfigure(wwin
, restore_x
, restore_y
,
520 wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
522 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
524 wSoundPlay(WSOUND_UNMAXIMIZE
);
529 animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
,
530 int fx
, int fy
, int fw
, int fh
, int steps
)
532 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
533 float cx
, cy
, cw
, ch
;
534 float xstep
, ystep
, wstep
, hstep
;
537 float angle
, final_angle
, delta
;
539 xstep
= (float)(fx
-x
)/steps
;
540 ystep
= (float)(fy
-y
)/steps
;
541 wstep
= (float)(fw
-w
)/steps
;
542 hstep
= (float)(fh
-h
)/steps
;
549 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_F
;
550 delta
= (float)(final_angle
/FRAMES
);
551 for (angle
=0;; angle
+=delta
) {
552 if (angle
> final_angle
)
555 dx
= (cw
/10) - ((cw
/5) * sin(angle
));
556 dch
= (ch
/2) * cos(angle
);
559 points
[0].x
= cx
+ dx
; points
[0].y
= midy
- dch
;
560 points
[1].x
= cx
+ cw
- dx
; points
[1].y
= points
[0].y
;
561 points
[2].x
= cx
+ cw
+ dx
; points
[2].y
= midy
+ dch
;
562 points
[3].x
= cx
- dx
; points
[3].y
= points
[2].y
;
563 points
[4].x
= points
[0].x
; points
[4].y
= points
[0].y
;
566 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
568 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
569 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
574 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
580 if (angle
>= final_angle
)
590 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
,
591 int fx
, int fy
, int fw
, int fh
, int steps
)
593 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
594 float cx
, cy
, cw
, ch
;
595 float xstep
, ystep
, wstep
, hstep
;
597 float angle
, final_angle
, a
, d
, delta
;
604 xstep
= (float)(fx
-x
)/steps
;
605 ystep
= (float)(fy
-y
)/steps
;
606 wstep
= (float)(fw
-w
)/steps
;
607 hstep
= (float)(fh
-h
)/steps
;
614 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_T
;
615 delta
= (float)(final_angle
/FRAMES
);
616 for (angle
=0;; angle
+=delta
) {
617 if (angle
> final_angle
)
621 d
= sqrt((cw
/2)*(cw
/2)+(ch
/2)*(ch
/2));
623 points
[0].x
= cx
+cos(angle
-a
)*d
;
624 points
[0].y
= cy
+sin(angle
-a
)*d
;
625 points
[1].x
= cx
+cos(angle
+a
)*d
;
626 points
[1].y
= cy
+sin(angle
+a
)*d
;
627 points
[2].x
= cx
+cos(angle
-a
+WM_PI
)*d
;
628 points
[2].y
= cy
+sin(angle
-a
+WM_PI
)*d
;
629 points
[3].x
= cx
+cos(angle
+a
+WM_PI
)*d
;
630 points
[3].y
= cy
+sin(angle
+a
+WM_PI
)*d
;
631 points
[4].x
= cx
+cos(angle
-a
)*d
;
632 points
[4].y
= cy
+sin(angle
-a
)*d
;
634 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
636 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
637 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
642 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
648 if (angle
>= final_angle
)
658 animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
,
659 int fx
, int fy
, int fw
, int fh
, int steps
)
661 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
662 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
663 float xstep
, ystep
, wstep
, hstep
;
666 xstep
= (float)(fx
-x
)/steps
;
667 ystep
= (float)(fy
-y
)/steps
;
668 wstep
= (float)(fw
-w
)/steps
;
669 hstep
= (float)(fh
-h
)/steps
;
671 for (j
=0; j
<FRAMES
; j
++) {
678 for (i
=0; i
<steps
; i
++) {
679 for (j
=0; j
<FRAMES
; j
++) {
680 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
681 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
684 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
685 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
689 for (j
=0; j
<FRAMES
; j
++) {
690 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
691 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
706 for (j
=0; j
<FRAMES
; j
++) {
707 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
708 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
711 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
712 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
716 for (j
=0; j
<FRAMES
; j
++) {
717 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
718 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
727 animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
,
728 int fx
, int fy
, int fw
, int fh
, int hiding
)
730 int style
= wPreferences
.iconification_style
; /* Catch the value */
733 if (style
== WIS_NONE
)
736 if (style
== WIS_RANDOM
) {
740 k
= (hiding
? 2 : 3);
743 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
)/3;
745 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
748 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
)/3;
750 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
754 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
)/3;
756 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
760 #endif /* ANIMATIONS */
768 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
769 WMHandleEvent(&tmpev
);
774 unmapTransientsFor(WWindow
*wwin
)
779 tmp
= wwin
->screen_ptr
->focused_window
;
781 /* unmap the transients for this transient */
782 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
783 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
784 || tmp
->flags
.shaded
)) {
785 unmapTransientsFor(tmp
);
786 tmp
->flags
.miniaturized
= 1;
787 if (!tmp
->flags
.shaded
) {
790 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
793 if (!tmp->flags.shaded)
795 wClientSetState(tmp
, IconicState
, None
);
797 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
805 mapTransientsFor(WWindow
*wwin
)
809 tmp
= wwin
->screen_ptr
->focused_window
;
811 /* recursively map the transients for this transient */
812 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
813 && /*!tmp->flags.mapped*/ tmp
->flags
.miniaturized
814 && tmp
->icon
==NULL
) {
815 mapTransientsFor(tmp
);
816 tmp
->flags
.miniaturized
= 0;
817 if (!tmp
->flags
.shaded
) {
820 XMapWindow(dpy
, tmp
->frame
->core
->window
);
822 tmp
->flags
.semi_focused
= 0;
824 if (!tmp->flags.shaded)
826 wClientSetState(tmp
, NormalState
, None
);
828 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
836 setupIconGrabs(WIcon
*icon
)
838 /* setup passive grabs on the icon */
839 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
840 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
841 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
842 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
843 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
844 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
850 recursiveTransientFor(WWindow
*wwin
)
857 /* hackish way to detect transient_for cycle */
858 i
= wwin
->screen_ptr
->window_count
+1;
860 while (wwin
&& wwin
->transient_for
!= None
&& i
>0) {
861 wwin
= wWindowFor(wwin
->transient_for
);
865 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
875 removeIconGrabs(WIcon
*icon
)
877 /* remove passive grabs on the icon */
878 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
879 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
880 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
887 wIconifyWindow(WWindow
*wwin
)
889 XWindowAttributes attribs
;
893 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
894 /* the window doesn't exist anymore */
898 if (wwin
->flags
.miniaturized
) {
902 if (wwin
->transient_for
!=None
&&
903 wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
904 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
906 if (owner
&& owner
->flags
.miniaturized
)
910 present
= wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
;
912 /* if the window is in another workspace, simplify process */
914 /* icon creation may take a while */
915 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
916 ButtonMotionMask
|ButtonReleaseMask
, GrabModeAsync
,
917 GrabModeAsync
, None
, None
, CurrentTime
);
920 if (!wPreferences
.disable_miniwindows
) {
921 if (!wwin
->flags
.icon_moved
) {
922 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
);
924 wwin
->icon
= wIconCreate(wwin
);
926 wwin
->icon
->mapped
= 1;
929 wwin
->flags
.miniaturized
= 1;
930 wwin
->flags
.mapped
= 0;
932 /* unmap transients */
934 unmapTransientsFor(wwin
);
937 wSoundPlay(WSOUND_ICONIFY
);
939 XUngrabPointer(dpy
, CurrentTime
);
941 /* let all Expose events arrive so that we can repaint
942 * something before the animation starts (and the server is grabbed) */
945 if (wPreferences
.disable_miniwindows
)
946 wClientSetState(wwin
, IconicState
, None
);
948 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
952 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
953 && !wPreferences
.no_animations
) {
956 if (!wPreferences
.disable_miniwindows
) {
959 iw
= wwin
->icon
->core
->width
;
960 ih
= wwin
->icon
->core
->height
;
965 if (wKWMGetIconGeometry(wwin
, &area
)) {
971 #endif /* KWM_HINTS */
975 iw
= wwin
->screen_ptr
->scr_width
;
976 ih
= wwin
->screen_ptr
->scr_height
;
979 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
980 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
981 ix
, iy
, iw
, ih
, False
);
986 wwin
->flags
.skip_next_animation
= 0;
988 if (!wPreferences
.disable_miniwindows
) {
990 if (wwin
->screen_ptr
->current_workspace
==wwin
->frame
->workspace
||
991 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
993 XMapWindow(dpy
, wwin
->icon
->core
->window
);
995 AddToStackList(wwin
->icon
->core
);
997 wLowerFrame(wwin
->icon
->core
);
1001 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1004 * It doesn't seem to be working and causes button event hangup
1005 * when deiconifying a transient window.
1006 setupIconGrabs(wwin->icon);
1008 if ((wwin
->flags
.focused
1009 || (owner
&& wwin
->client_win
== owner
->client_win
))
1010 && wPreferences
.focus_mode
==WKF_CLICK
) {
1015 if (!WFLAGP(tmp
, no_focusable
)
1016 && !(tmp
->flags
.hidden
||tmp
->flags
.miniaturized
)
1017 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1021 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1022 } else if (wPreferences
.focus_mode
!=WKF_CLICK
) {
1023 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1027 if (!wwin
->screen_ptr
->flags
.startup
) {
1028 Window clientwin
= wwin
->client_win
;
1031 processEvents(XPending(dpy
));
1033 /* the window can disappear while doing the processEvents() */
1034 if (!wWindowFor(clientwin
))
1041 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
)
1042 wIconSelect(wwin
->icon
);
1044 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1051 wDeiconifyWindow(WWindow
*wwin
)
1053 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1055 if (!wwin
->flags
.miniaturized
)
1058 if (wwin
->transient_for
!= None
1059 && wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1060 WWindow
*owner
= recursiveTransientFor(wwin
);
1062 if (owner
&& owner
->flags
.miniaturized
) {
1063 wDeiconifyWindow(owner
);
1064 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1065 wRaiseFrame(wwin
->frame
->core
);
1070 wwin
->flags
.miniaturized
= 0;
1071 if (!wwin
->flags
.shaded
)
1072 wwin
->flags
.mapped
= 1;
1074 if (!wPreferences
.disable_miniwindows
) {
1075 if (wwin
->icon
->selected
)
1076 wIconSelect(wwin
->icon
);
1078 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1081 wSoundPlay(WSOUND_DEICONIFY
);
1083 /* if the window is in another workspace, do it silently */
1085 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1086 && !wwin
->flags
.skip_next_animation
) {
1089 if (!wPreferences
.disable_miniwindows
) {
1092 iw
= wwin
->icon
->core
->width
;
1093 ih
= wwin
->icon
->core
->height
;
1098 if (wKWMGetIconGeometry(wwin
, &area
)) {
1104 #endif /* KWM_HINTS */
1108 iw
= wwin
->screen_ptr
->scr_width
;
1109 ih
= wwin
->screen_ptr
->scr_height
;
1112 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1113 wwin
->frame_x
, wwin
->frame_y
,
1114 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1117 #endif /* ANIMATIONS */
1118 wwin
->flags
.skip_next_animation
= 0;
1120 if (!wwin
->flags
.shaded
) {
1121 XMapWindow(dpy
, wwin
->client_win
);
1123 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1124 wRaiseFrame(wwin
->frame
->core
);
1125 if (!wwin
->flags
.shaded
) {
1126 wClientSetState(wwin
, NormalState
, None
);
1128 mapTransientsFor(wwin
);
1130 if (!wPreferences
.disable_miniwindows
) {
1131 RemoveFromStackList(wwin
->icon
->core
);
1132 /* removeIconGrabs(wwin->icon);*/
1133 wIconDestroy(wwin
->icon
);
1138 if (wPreferences
.focus_mode
==WKF_CLICK
)
1139 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1142 if (!wwin
->screen_ptr
->flags
.startup
) {
1143 Window clientwin
= wwin
->client_win
;
1146 processEvents(XPending(dpy
));
1148 if (!wWindowFor(clientwin
))
1153 if (wPreferences
.auto_arrange_icons
) {
1154 wArrangeIcons(wwin
->screen_ptr
, True
);
1157 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1159 /* In case we were shaded and iconified, also unshade */
1160 wUnshadeWindow(wwin
);
1166 hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1168 if (wwin
->flags
.miniaturized
) {
1170 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1171 wwin
->icon
->mapped
= 0;
1173 wwin
->flags
.hidden
= 1;
1175 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1179 if (wwin
->flags
.inspector_open
) {
1180 wHideInspectorForWindow(wwin
);
1183 wwin
->flags
.hidden
= 1;
1186 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1188 wSoundPlay(WSOUND_HIDE
);
1190 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1191 !wwin
->flags
.skip_next_animation
&& animate
) {
1192 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1193 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1194 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
,
1198 wwin
->flags
.skip_next_animation
= 0;
1200 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1206 wHideOtherApplications(WWindow
*awin
)
1213 wwin
= awin
->screen_ptr
->focused_window
;
1218 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1219 && !(wwin
->flags
.miniaturized
||wwin
->flags
.hidden
)
1220 && !wwin
->flags
.internal_window
1221 && wGetWindowOfInspectorForWindow(wwin
) != awin
1222 && !WFLAGP(wwin
, no_hide_others
)) {
1224 if (wwin
->main_window
==None
|| WFLAGP(wwin
, no_appicon
)) {
1225 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1226 wwin
->flags
.skip_next_animation
= 1;
1227 wIconifyWindow(wwin
);
1229 } else if (wwin
->main_window
!=None
1230 && awin
->main_window
!= wwin
->main_window
) {
1231 tapp
= wApplicationOf(wwin
->main_window
);
1233 tapp
->flags
.skip_next_animation
= 1;
1234 wHideApplication(tapp
);
1236 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1237 wwin
->flags
.skip_next_animation
= 1;
1238 wIconifyWindow(wwin
);
1246 wSetFocusTo(awin->screen_ptr, awin);
1253 wHideApplication(WApplication
*wapp
)
1260 wwarning("trying to hide a non grouped window");
1263 if (!wapp
->main_window_desc
) {
1264 wwarning("group leader not found for window group");
1267 scr
= wapp
->main_window_desc
->screen_ptr
;
1269 wlist
= scr
->focused_window
;
1273 if (wlist
->main_window
== wapp
->main_window
)
1274 wapp
->last_focused
= wlist
;
1276 wapp
->last_focused
= NULL
;
1278 if (wlist
->main_window
== wapp
->main_window
) {
1279 if (wlist
->flags
.focused
) {
1283 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1284 wapp
->app_icon
->y_pos
, wlist
,
1285 !wapp
->flags
.skip_next_animation
);
1287 wlist
= wlist
->prev
;
1290 wapp
->flags
.skip_next_animation
= 0;
1293 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1294 wlist
= scr
->focused_window
;
1296 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1297 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1299 wlist
= wlist
->prev
;
1301 wSetFocusTo(scr
, wlist
);
1303 wSetFocusTo(scr
, NULL
);
1307 wapp
->flags
.hidden
= 1;
1309 if(wPreferences
.auto_arrange_icons
) {
1310 wArrangeIcons(scr
, True
);
1314 wAppIconPaint(wapp
->app_icon
);
1322 unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
,
1323 int bringToCurrentWS
)
1325 if (bringToCurrentWS
)
1326 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1328 wwin
->flags
.hidden
=0;
1330 wSoundPlay(WSOUND_UNHIDE
);
1332 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1334 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1335 icon
->core
->width
, icon
->core
->height
,
1336 wwin
->frame_x
, wwin
->frame_y
,
1337 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1341 wwin
->flags
.skip_next_animation
= 0;
1342 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1343 XMapWindow(dpy
, wwin
->client_win
);
1344 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1345 wClientSetState(wwin
, NormalState
, None
);
1346 wwin
->flags
.mapped
=1;
1347 wRaiseFrame(wwin
->frame
->core
);
1349 if (wwin
->flags
.inspector_open
) {
1350 wUnhideInspectorForWindow(wwin
);
1353 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1358 wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1361 WWindow
*wlist
, *next
;
1362 WWindow
*focused
=NULL
;
1367 scr
= wapp
->main_window_desc
->screen_ptr
;
1368 wlist
= scr
->focused_window
;
1370 /* goto beginning of list */
1372 wlist
= wlist
->prev
;
1377 if (wlist
->main_window
== wapp
->main_window
) {
1378 if (wlist
->flags
.focused
)
1380 else if (!focused
|| !focused
->flags
.focused
)
1383 if (wlist
->flags
.miniaturized
&& wlist
->icon
) {
1384 if (bringToCurrentWS
|| wPreferences
.sticky_icons
1385 || wlist
->frame
->workspace
== scr
->current_workspace
) {
1386 if (!wlist
->icon
->mapped
) {
1387 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1388 wlist
->icon
->mapped
= 1;
1390 wlist
->flags
.hidden
= 0;
1392 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1394 if (wlist
->frame
->workspace
!= scr
->current_workspace
)
1395 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1398 wDeiconifyWindow(wlist
);
1400 } else if (wlist
->flags
.hidden
) {
1401 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1402 wapp
->app_icon
->y_pos
, wlist
,
1403 !wapp
->flags
.skip_next_animation
,
1406 if (bringToCurrentWS
1407 && wlist
->frame
->workspace
!= scr
->current_workspace
) {
1408 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1410 wRaiseFrame(wlist
->frame
->core
);
1416 wapp
->flags
.skip_next_animation
= 0;
1417 wapp
->flags
.hidden
= 0;
1420 wSetFocusTo(scr
, focused
);
1421 else if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
)
1422 wSetFocusTo(scr
, wapp
->last_focused
);
1423 wapp
->last_focused
= NULL
;
1424 if (wPreferences
.auto_arrange_icons
) {
1425 wArrangeIcons(scr
, True
);
1428 wAppIconPaint(wapp
->app_icon
);
1435 wShowAllWindows(WScreen
*scr
)
1437 WWindow
*wwin
, *old_foc
;
1440 old_foc
= wwin
= scr
->focused_window
;
1442 if (!wwin
->flags
.internal_window
&&
1443 (scr
->current_workspace
== wwin
->frame
->workspace
1444 || IS_OMNIPRESENT(wwin
))) {
1445 if (wwin
->flags
.miniaturized
) {
1446 wwin
->flags
.skip_next_animation
= 1;
1447 wDeiconifyWindow(wwin
);
1448 } else if (wwin
->flags
.hidden
) {
1449 wapp
= wApplicationOf(wwin
->main_window
);
1451 wUnhideApplication(wapp
, False
, False
);
1453 wwin
->flags
.skip_next_animation
= 1;
1454 wDeiconifyWindow(wwin
);
1460 wSetFocusTo(scr
, old_foc
);
1461 /*wRaiseFrame(old_foc->frame->core);*/
1466 wRefreshDesktop(WScreen
*scr
)
1469 XSetWindowAttributes attr
;
1471 attr
.backing_store
= NotUseful
;
1472 attr
.save_under
= False
;
1473 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1474 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1475 (Visual
*)CopyFromParent
, CWBackingStore
|CWSaveUnder
,
1477 XMapRaised(dpy
, win
);
1478 XDestroyWindow(dpy
, win
);
1484 wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1488 int pf
; /* primary axis */
1489 int sf
; /* secondary axis */
1493 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1497 int isize
= wPreferences
.icon_size
;
1500 * Find out screen boundaries.
1504 sx2
= scr
->scr_width
;
1505 sy2
= scr
->scr_height
;
1507 if (scr
->dock
->on_right_side
)
1508 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1510 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1513 sw
= isize
* (scr
->scr_width
/isize
);
1514 sh
= isize
* (scr
->scr_height
/isize
);
1515 fullW
= (sx2
-sx1
)/isize
;
1516 fullH
= (sy2
-sy1
)/isize
;
1518 /* icon yard boundaries */
1519 if (wPreferences
.icon_yard
& IY_VERT
) {
1526 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1533 if (wPreferences
.icon_yard
& IY_TOP
) {
1541 /* arrange icons putting the most recently focused window
1542 * as the last icon */
1543 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1544 : xo + xs*(pi*isize))
1545 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1546 : yo + ys*(si*isize))
1548 /* arrange application icons */
1549 aicon
= scr
->app_icon_list
;
1550 /* reverse them to avoid unnecessarily sliding of icons */
1551 while (aicon
&& aicon
->next
)
1552 aicon
= aicon
->next
;
1557 if (!aicon
->docked
) {
1558 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1560 if (!wPreferences
.no_animations
) {
1561 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
,
1564 #endif /* ANIMATIONS */
1566 wAppIconMove(aicon
, X
, Y
);
1569 /* we reversed the order so we use prev */
1570 aicon
= aicon
->prev
;
1577 /* arrange miniwindows */
1579 wwin
= scr
->focused_window
;
1580 /* reverse them to avoid unnecessarily shuffling */
1581 while (wwin
&& wwin
->prev
)
1585 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1586 (wwin
->frame
->workspace
==scr
->current_workspace
||
1587 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1589 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1590 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1592 if (wPreferences
.no_animations
) {
1593 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1595 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1596 wwin
->icon_y
, X
, Y
);
1599 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1600 #endif /* ANIMATIONS */
1608 wwin
->flags
.icon_moved
= 0;
1610 /* we reversed the order, so we use next */
1621 wSelectWindow(WWindow
*wwin
, Bool flag
)
1623 WScreen
*scr
= wwin
->screen_ptr
;
1626 wwin
->flags
.selected
= 1;
1627 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1629 if (WFLAGP(wwin
, no_border
)) {
1630 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
,
1631 FRAME_BORDER_WIDTH
);
1634 if (!scr
->selected_windows
)
1635 scr
->selected_windows
= WMCreateArray(4);
1636 WMAddToArray(scr
->selected_windows
, wwin
);
1638 wwin
->flags
.selected
= 0;
1639 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
,
1640 scr
->frame_border_pixel
);
1642 if (WFLAGP(wwin
, no_border
)) {
1643 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1646 if (scr
->selected_windows
) {
1647 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1654 wMakeWindowVisible(WWindow
*wwin
)
1656 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1657 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1659 if (wwin
->flags
.shaded
) {
1660 wUnshadeWindow(wwin
);
1662 if (wwin
->flags
.hidden
) {
1665 app
= wApplicationOf(wwin
->main_window
);
1667 wUnhideApplication(app
, False
, False
);
1668 } else if (wwin
->flags
.miniaturized
) {
1669 wDeiconifyWindow(wwin
);
1671 if (!WFLAGP(wwin
, no_focusable
))
1672 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1673 wRaiseFrame(wwin
->frame
->core
);