1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 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
;
416 if (WFLAGP(wwin
, no_resizable
))
421 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
422 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
425 if (wwin
->screen_ptr
->xine_count
> 0
426 && !(directions
& MAX_IGNORE_XINERAMA
)) {
427 WScreen
*scr
= wwin
->screen_ptr
;
430 rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
431 totalArea
.x1
= rect
.pos
.x
;
432 totalArea
.y1
= rect
.pos
.y
;
433 totalArea
.x2
= totalArea
.x1
+ rect
.size
.width
;
434 totalArea
.y2
= totalArea
.y1
+ rect
.size
.height
;
436 usableArea
.x1
= WMAX(totalArea
.x1
, usableArea
.x1
);
437 usableArea
.y1
= WMAX(totalArea
.y1
, usableArea
.y1
);
438 usableArea
.x2
= WMIN(totalArea
.x2
, usableArea
.x2
);
439 usableArea
.y2
= WMIN(totalArea
.y2
, usableArea
.y2
);
441 #endif /* XINERAMA */
443 if (WFLAGP(wwin
, full_maximize
)) {
444 usableArea
= totalArea
;
447 if (wwin
->flags
.shaded
) {
448 wwin
->flags
.skip_next_animation
= 1;
449 wUnshadeWindow(wwin
);
451 wwin
->flags
.maximized
= directions
;
452 wwin
->old_geometry
.width
= wwin
->client
.width
;
453 wwin
->old_geometry
.height
= wwin
->client
.height
;
454 wwin
->old_geometry
.x
= wwin
->frame_x
;
455 wwin
->old_geometry
.y
= wwin
->frame_y
;
458 wKWMUpdateClientGeometryRestore(wwin
);
461 if (directions
& MAX_HORIZONTAL
) {
463 new_width
= (usableArea
.x2
-usableArea
.x1
)-FRAME_BORDER_WIDTH
*2;
464 new_x
= usableArea
.x1
;
468 new_x
= wwin
->frame_x
;
469 new_width
= wwin
->frame
->core
->width
;
473 if (directions
& MAX_VERTICAL
) {
475 new_height
= (usableArea
.y2
-usableArea
.y1
)-FRAME_BORDER_WIDTH
*2;
476 new_y
= usableArea
.y1
;
477 if (WFLAGP(wwin
, full_maximize
)) {
478 new_y
-= wwin
->frame
->top_width
;
479 new_height
+= wwin
->frame
->bottom_width
- 1;
482 new_y
= wwin
->frame_y
;
483 new_height
= wwin
->frame
->core
->height
;
486 if (!WFLAGP(wwin
, full_maximize
)) {
487 new_height
-= wwin
->frame
->top_width
+wwin
->frame
->bottom_width
;
490 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
492 wWindowCropSize(wwin
, usableArea
.x2
-usableArea
.x1
,
493 usableArea
.y2
-usableArea
.y1
,
494 &new_width
, &new_height
);
496 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
499 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
501 wSoundPlay(WSOUND_MAXIMIZE
);
506 wUnmaximizeWindow(WWindow
*wwin
)
508 int restore_x
, restore_y
;
510 if (!wwin
->flags
.maximized
)
513 if (wwin
->flags
.shaded
) {
514 wwin
->flags
.skip_next_animation
= 1;
515 wUnshadeWindow(wwin
);
517 restore_x
= (wwin
->flags
.maximized
& MAX_HORIZONTAL
) ?
518 wwin
->old_geometry
.x
: wwin
->frame_x
;
519 restore_y
= (wwin
->flags
.maximized
& MAX_VERTICAL
) ?
520 wwin
->old_geometry
.y
: wwin
->frame_y
;
521 wwin
->flags
.maximized
= 0;
522 wWindowConfigure(wwin
, restore_x
, restore_y
,
523 wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
525 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
527 wSoundPlay(WSOUND_UNMAXIMIZE
);
532 animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
,
533 int fx
, int fy
, int fw
, int fh
, int steps
)
535 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
536 float cx
, cy
, cw
, ch
;
537 float xstep
, ystep
, wstep
, hstep
;
540 float angle
, final_angle
, delta
;
542 xstep
= (float)(fx
-x
)/steps
;
543 ystep
= (float)(fy
-y
)/steps
;
544 wstep
= (float)(fw
-w
)/steps
;
545 hstep
= (float)(fh
-h
)/steps
;
552 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_F
;
553 delta
= (float)(final_angle
/FRAMES
);
554 for (angle
=0;; angle
+=delta
) {
555 if (angle
> final_angle
)
558 dx
= (cw
/10) - ((cw
/5) * sin(angle
));
559 dch
= (ch
/2) * cos(angle
);
562 points
[0].x
= cx
+ dx
; points
[0].y
= midy
- dch
;
563 points
[1].x
= cx
+ cw
- dx
; points
[1].y
= points
[0].y
;
564 points
[2].x
= cx
+ cw
+ dx
; points
[2].y
= midy
+ dch
;
565 points
[3].x
= cx
- dx
; points
[3].y
= points
[2].y
;
566 points
[4].x
= points
[0].x
; points
[4].y
= points
[0].y
;
569 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
571 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
572 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
577 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
583 if (angle
>= final_angle
)
593 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
,
594 int fx
, int fy
, int fw
, int fh
, int steps
)
596 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
597 float cx
, cy
, cw
, ch
;
598 float xstep
, ystep
, wstep
, hstep
;
600 float angle
, final_angle
, a
, d
, delta
;
607 xstep
= (float)(fx
-x
)/steps
;
608 ystep
= (float)(fy
-y
)/steps
;
609 wstep
= (float)(fw
-w
)/steps
;
610 hstep
= (float)(fh
-h
)/steps
;
617 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_T
;
618 delta
= (float)(final_angle
/FRAMES
);
619 for (angle
=0;; angle
+=delta
) {
620 if (angle
> final_angle
)
624 d
= sqrt((cw
/2)*(cw
/2)+(ch
/2)*(ch
/2));
626 points
[0].x
= cx
+cos(angle
-a
)*d
;
627 points
[0].y
= cy
+sin(angle
-a
)*d
;
628 points
[1].x
= cx
+cos(angle
+a
)*d
;
629 points
[1].y
= cy
+sin(angle
+a
)*d
;
630 points
[2].x
= cx
+cos(angle
-a
+WM_PI
)*d
;
631 points
[2].y
= cy
+sin(angle
-a
+WM_PI
)*d
;
632 points
[3].x
= cx
+cos(angle
+a
+WM_PI
)*d
;
633 points
[3].y
= cy
+sin(angle
+a
+WM_PI
)*d
;
634 points
[4].x
= cx
+cos(angle
-a
)*d
;
635 points
[4].y
= cy
+sin(angle
-a
)*d
;
637 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
639 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
640 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
645 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
651 if (angle
>= final_angle
)
661 animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
,
662 int fx
, int fy
, int fw
, int fh
, int steps
)
664 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
665 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
666 float xstep
, ystep
, wstep
, hstep
;
669 xstep
= (float)(fx
-x
)/steps
;
670 ystep
= (float)(fy
-y
)/steps
;
671 wstep
= (float)(fw
-w
)/steps
;
672 hstep
= (float)(fh
-h
)/steps
;
674 for (j
=0; j
<FRAMES
; j
++) {
681 for (i
=0; i
<steps
; i
++) {
682 for (j
=0; j
<FRAMES
; j
++) {
683 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
684 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
687 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
688 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
692 for (j
=0; j
<FRAMES
; j
++) {
693 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
694 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
709 for (j
=0; j
<FRAMES
; j
++) {
710 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
711 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
714 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
715 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
719 for (j
=0; j
<FRAMES
; j
++) {
720 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
721 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
730 animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
,
731 int fx
, int fy
, int fw
, int fh
, int hiding
)
733 int style
= wPreferences
.iconification_style
; /* Catch the value */
736 if (style
== WIS_NONE
)
739 if (style
== WIS_RANDOM
) {
743 k
= (hiding
? 2 : 3);
746 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
)/3;
748 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
751 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
)/3;
753 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
757 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
)/3;
759 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
763 #endif /* ANIMATIONS */
771 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
772 WMHandleEvent(&tmpev
);
777 unmapTransientsFor(WWindow
*wwin
)
782 tmp
= wwin
->screen_ptr
->focused_window
;
784 /* unmap the transients for this transient */
785 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
786 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
787 || tmp
->flags
.shaded
)) {
788 unmapTransientsFor(tmp
);
789 tmp
->flags
.miniaturized
= 1;
790 if (!tmp
->flags
.shaded
) {
793 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
796 if (!tmp->flags.shaded)
798 wClientSetState(tmp
, IconicState
, None
);
800 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
808 mapTransientsFor(WWindow
*wwin
)
812 tmp
= wwin
->screen_ptr
->focused_window
;
814 /* recursively map the transients for this transient */
815 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
816 && /*!tmp->flags.mapped*/ tmp
->flags
.miniaturized
817 && tmp
->icon
==NULL
) {
818 mapTransientsFor(tmp
);
819 tmp
->flags
.miniaturized
= 0;
820 if (!tmp
->flags
.shaded
) {
823 XMapWindow(dpy
, tmp
->frame
->core
->window
);
825 tmp
->flags
.semi_focused
= 0;
827 if (!tmp->flags.shaded)
829 wClientSetState(tmp
, NormalState
, None
);
831 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
839 setupIconGrabs(WIcon
*icon
)
841 /* setup passive grabs on the icon */
842 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
843 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
844 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
845 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
846 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
847 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
853 recursiveTransientFor(WWindow
*wwin
)
860 /* hackish way to detect transient_for cycle */
861 i
= wwin
->screen_ptr
->window_count
+1;
863 while (wwin
&& wwin
->transient_for
!= None
&& i
>0) {
864 wwin
= wWindowFor(wwin
->transient_for
);
868 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
878 removeIconGrabs(WIcon
*icon
)
880 /* remove passive grabs on the icon */
881 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
882 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
883 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
890 wIconifyWindow(WWindow
*wwin
)
892 XWindowAttributes attribs
;
896 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
897 /* the window doesn't exist anymore */
901 if (wwin
->flags
.miniaturized
) {
905 if (wwin
->transient_for
!=None
&&
906 wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
907 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
909 if (owner
&& owner
->flags
.miniaturized
)
913 present
= wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
;
915 /* if the window is in another workspace, simplify process */
917 /* icon creation may take a while */
918 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
919 ButtonMotionMask
|ButtonReleaseMask
, GrabModeAsync
,
920 GrabModeAsync
, None
, None
, CurrentTime
);
923 if (!wPreferences
.disable_miniwindows
) {
924 if (!wwin
->flags
.icon_moved
) {
925 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
);
927 wwin
->icon
= wIconCreate(wwin
);
929 wwin
->icon
->mapped
= 1;
932 wwin
->flags
.miniaturized
= 1;
933 wwin
->flags
.mapped
= 0;
935 /* unmap transients */
937 unmapTransientsFor(wwin
);
940 wSoundPlay(WSOUND_ICONIFY
);
942 XUngrabPointer(dpy
, CurrentTime
);
944 /* let all Expose events arrive so that we can repaint
945 * something before the animation starts (and the server is grabbed) */
948 if (wPreferences
.disable_miniwindows
)
949 wClientSetState(wwin
, IconicState
, None
);
951 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
955 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
956 && !wPreferences
.no_animations
) {
959 if (!wPreferences
.disable_miniwindows
) {
962 iw
= wwin
->icon
->core
->width
;
963 ih
= wwin
->icon
->core
->height
;
968 if (wKWMGetIconGeometry(wwin
, &area
)) {
974 #endif /* KWM_HINTS */
978 iw
= wwin
->screen_ptr
->scr_width
;
979 ih
= wwin
->screen_ptr
->scr_height
;
982 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
983 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
984 ix
, iy
, iw
, ih
, False
);
989 wwin
->flags
.skip_next_animation
= 0;
991 if (!wPreferences
.disable_miniwindows
) {
993 if (wwin
->screen_ptr
->current_workspace
==wwin
->frame
->workspace
||
994 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
996 XMapWindow(dpy
, wwin
->icon
->core
->window
);
998 AddToStackList(wwin
->icon
->core
);
1000 wLowerFrame(wwin
->icon
->core
);
1004 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1007 * It doesn't seem to be working and causes button event hangup
1008 * when deiconifying a transient window.
1009 setupIconGrabs(wwin->icon);
1011 if ((wwin
->flags
.focused
1012 || (owner
&& wwin
->client_win
== owner
->client_win
))
1013 && wPreferences
.focus_mode
==WKF_CLICK
) {
1018 if (!WFLAGP(tmp
, no_focusable
)
1019 && !(tmp
->flags
.hidden
||tmp
->flags
.miniaturized
)
1020 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1024 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1025 } else if (wPreferences
.focus_mode
!=WKF_CLICK
) {
1026 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1030 if (!wwin
->screen_ptr
->flags
.startup
) {
1031 Window clientwin
= wwin
->client_win
;
1034 processEvents(XPending(dpy
));
1036 /* the window can disappear while doing the processEvents() */
1037 if (!wWindowFor(clientwin
))
1044 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
)
1045 wIconSelect(wwin
->icon
);
1047 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1054 wDeiconifyWindow(WWindow
*wwin
)
1056 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1058 if (!wwin
->flags
.miniaturized
)
1061 if (wwin
->transient_for
!= None
1062 && wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1063 WWindow
*owner
= recursiveTransientFor(wwin
);
1065 if (owner
&& owner
->flags
.miniaturized
) {
1066 wDeiconifyWindow(owner
);
1067 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1068 wRaiseFrame(wwin
->frame
->core
);
1073 wwin
->flags
.miniaturized
= 0;
1074 if (!wwin
->flags
.shaded
)
1075 wwin
->flags
.mapped
= 1;
1077 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
) {
1078 if (wwin
->icon
->selected
)
1079 wIconSelect(wwin
->icon
);
1081 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1084 wSoundPlay(WSOUND_DEICONIFY
);
1086 /* if the window is in another workspace, do it silently */
1088 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1089 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1092 if (!wPreferences
.disable_miniwindows
) {
1095 iw
= wwin
->icon
->core
->width
;
1096 ih
= wwin
->icon
->core
->height
;
1101 if (wKWMGetIconGeometry(wwin
, &area
)) {
1107 #endif /* KWM_HINTS */
1111 iw
= wwin
->screen_ptr
->scr_width
;
1112 ih
= wwin
->screen_ptr
->scr_height
;
1115 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1116 wwin
->frame_x
, wwin
->frame_y
,
1117 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1120 #endif /* ANIMATIONS */
1121 wwin
->flags
.skip_next_animation
= 0;
1123 if (!wwin
->flags
.shaded
) {
1124 XMapWindow(dpy
, wwin
->client_win
);
1126 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1127 wRaiseFrame(wwin
->frame
->core
);
1128 if (!wwin
->flags
.shaded
) {
1129 wClientSetState(wwin
, NormalState
, None
);
1131 mapTransientsFor(wwin
);
1133 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
) {
1134 RemoveFromStackList(wwin
->icon
->core
);
1135 /* removeIconGrabs(wwin->icon);*/
1136 wIconDestroy(wwin
->icon
);
1141 if (wPreferences
.focus_mode
==WKF_CLICK
)
1142 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1145 if (!wwin
->screen_ptr
->flags
.startup
) {
1146 Window clientwin
= wwin
->client_win
;
1149 processEvents(XPending(dpy
));
1151 if (!wWindowFor(clientwin
))
1156 if (wPreferences
.auto_arrange_icons
) {
1157 wArrangeIcons(wwin
->screen_ptr
, True
);
1160 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1162 /* In case we were shaded and iconified, also unshade */
1163 wUnshadeWindow(wwin
);
1169 hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1171 if (wwin
->flags
.miniaturized
) {
1173 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1174 wwin
->icon
->mapped
= 0;
1176 wwin
->flags
.hidden
= 1;
1178 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1182 if (wwin
->flags
.inspector_open
) {
1183 wHideInspectorForWindow(wwin
);
1186 wwin
->flags
.hidden
= 1;
1189 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1191 wSoundPlay(WSOUND_HIDE
);
1193 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1194 !wwin
->flags
.skip_next_animation
&& animate
) {
1195 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1196 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1197 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
,
1201 wwin
->flags
.skip_next_animation
= 0;
1203 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1209 wHideOtherApplications(WWindow
*awin
)
1216 wwin
= awin
->screen_ptr
->focused_window
;
1221 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1222 && !(wwin
->flags
.miniaturized
||wwin
->flags
.hidden
)
1223 && !wwin
->flags
.internal_window
1224 && wGetWindowOfInspectorForWindow(wwin
) != awin
1225 && !WFLAGP(wwin
, no_hide_others
)) {
1227 if (wwin
->main_window
==None
|| WFLAGP(wwin
, no_appicon
)) {
1228 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1229 wwin
->flags
.skip_next_animation
= 1;
1230 wIconifyWindow(wwin
);
1232 } else if (wwin
->main_window
!=None
1233 && awin
->main_window
!= wwin
->main_window
) {
1234 tapp
= wApplicationOf(wwin
->main_window
);
1236 tapp
->flags
.skip_next_animation
= 1;
1237 wHideApplication(tapp
);
1239 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1240 wwin
->flags
.skip_next_animation
= 1;
1241 wIconifyWindow(wwin
);
1249 wSetFocusTo(awin->screen_ptr, awin);
1256 wHideApplication(WApplication
*wapp
)
1263 wwarning("trying to hide a non grouped window");
1266 if (!wapp
->main_window_desc
) {
1267 wwarning("group leader not found for window group");
1270 scr
= wapp
->main_window_desc
->screen_ptr
;
1272 wlist
= scr
->focused_window
;
1276 if (wlist
->main_window
== wapp
->main_window
)
1277 wapp
->last_focused
= wlist
;
1279 wapp
->last_focused
= NULL
;
1281 if (wlist
->main_window
== wapp
->main_window
) {
1282 if (wlist
->flags
.focused
) {
1286 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1287 wapp
->app_icon
->y_pos
, wlist
,
1288 !wapp
->flags
.skip_next_animation
);
1290 wlist
= wlist
->prev
;
1293 wapp
->flags
.skip_next_animation
= 0;
1296 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1297 wlist
= scr
->focused_window
;
1299 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1300 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1302 wlist
= wlist
->prev
;
1304 wSetFocusTo(scr
, wlist
);
1306 wSetFocusTo(scr
, NULL
);
1310 wapp
->flags
.hidden
= 1;
1312 if(wPreferences
.auto_arrange_icons
) {
1313 wArrangeIcons(scr
, True
);
1317 wAppIconPaint(wapp
->app_icon
);
1325 unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
,
1326 int bringToCurrentWS
)
1328 if (bringToCurrentWS
)
1329 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1331 wwin
->flags
.hidden
=0;
1333 wSoundPlay(WSOUND_UNHIDE
);
1335 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1337 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1338 icon
->core
->width
, icon
->core
->height
,
1339 wwin
->frame_x
, wwin
->frame_y
,
1340 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1344 wwin
->flags
.skip_next_animation
= 0;
1345 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1346 XMapWindow(dpy
, wwin
->client_win
);
1347 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1348 wClientSetState(wwin
, NormalState
, None
);
1349 wwin
->flags
.mapped
=1;
1350 wRaiseFrame(wwin
->frame
->core
);
1352 if (wwin
->flags
.inspector_open
) {
1353 wUnhideInspectorForWindow(wwin
);
1356 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1361 wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1364 WWindow
*wlist
, *next
;
1365 WWindow
*focused
=NULL
;
1370 scr
= wapp
->main_window_desc
->screen_ptr
;
1371 wlist
= scr
->focused_window
;
1373 /* goto beginning of list */
1375 wlist
= wlist
->prev
;
1380 if (wlist
->main_window
== wapp
->main_window
) {
1381 if (wlist
->flags
.focused
)
1383 else if (!focused
|| !focused
->flags
.focused
)
1386 if (wlist
->flags
.miniaturized
&& wlist
->icon
) {
1387 if (bringToCurrentWS
|| wPreferences
.sticky_icons
1388 || wlist
->frame
->workspace
== scr
->current_workspace
) {
1389 if (!wlist
->icon
->mapped
) {
1390 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1391 wlist
->icon
->mapped
= 1;
1393 wlist
->flags
.hidden
= 0;
1395 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1397 if (wlist
->frame
->workspace
!= scr
->current_workspace
)
1398 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1401 wDeiconifyWindow(wlist
);
1403 } else if (wlist
->flags
.hidden
) {
1404 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1405 wapp
->app_icon
->y_pos
, wlist
,
1406 !wapp
->flags
.skip_next_animation
,
1409 if (bringToCurrentWS
1410 && wlist
->frame
->workspace
!= scr
->current_workspace
) {
1411 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1413 wRaiseFrame(wlist
->frame
->core
);
1419 wapp
->flags
.skip_next_animation
= 0;
1420 wapp
->flags
.hidden
= 0;
1423 wSetFocusTo(scr
, focused
);
1424 else if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
)
1425 wSetFocusTo(scr
, wapp
->last_focused
);
1426 wapp
->last_focused
= NULL
;
1427 if (wPreferences
.auto_arrange_icons
) {
1428 wArrangeIcons(scr
, True
);
1431 wAppIconPaint(wapp
->app_icon
);
1438 wShowAllWindows(WScreen
*scr
)
1440 WWindow
*wwin
, *old_foc
;
1443 old_foc
= wwin
= scr
->focused_window
;
1445 if (!wwin
->flags
.internal_window
&&
1446 (scr
->current_workspace
== wwin
->frame
->workspace
1447 || IS_OMNIPRESENT(wwin
))) {
1448 if (wwin
->flags
.miniaturized
) {
1449 wwin
->flags
.skip_next_animation
= 1;
1450 wDeiconifyWindow(wwin
);
1451 } else if (wwin
->flags
.hidden
) {
1452 wapp
= wApplicationOf(wwin
->main_window
);
1454 wUnhideApplication(wapp
, False
, False
);
1456 wwin
->flags
.skip_next_animation
= 1;
1457 wDeiconifyWindow(wwin
);
1463 wSetFocusTo(scr
, old_foc
);
1464 /*wRaiseFrame(old_foc->frame->core);*/
1469 wRefreshDesktop(WScreen
*scr
)
1472 XSetWindowAttributes attr
;
1474 attr
.backing_store
= NotUseful
;
1475 attr
.save_under
= False
;
1476 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1477 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1478 (Visual
*)CopyFromParent
, CWBackingStore
|CWSaveUnder
,
1480 XMapRaised(dpy
, win
);
1481 XDestroyWindow(dpy
, win
);
1487 wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1491 int pf
; /* primary axis */
1492 int sf
; /* secondary axis */
1496 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1500 int isize
= wPreferences
.icon_size
;
1503 * Find out screen boundaries.
1507 sx2
= scr
->scr_width
;
1508 sy2
= scr
->scr_height
;
1510 if (scr
->dock
->on_right_side
)
1511 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1513 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1516 sw
= isize
* (scr
->scr_width
/isize
);
1517 sh
= isize
* (scr
->scr_height
/isize
);
1518 fullW
= (sx2
-sx1
)/isize
;
1519 fullH
= (sy2
-sy1
)/isize
;
1521 /* icon yard boundaries */
1522 if (wPreferences
.icon_yard
& IY_VERT
) {
1529 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1536 if (wPreferences
.icon_yard
& IY_TOP
) {
1544 /* arrange icons putting the most recently focused window
1545 * as the last icon */
1546 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1547 : xo + xs*(pi*isize))
1548 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1549 : yo + ys*(si*isize))
1551 /* arrange application icons */
1552 aicon
= scr
->app_icon_list
;
1553 /* reverse them to avoid unnecessarily sliding of icons */
1554 while (aicon
&& aicon
->next
)
1555 aicon
= aicon
->next
;
1560 if (!aicon
->docked
) {
1561 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1563 if (!wPreferences
.no_animations
) {
1564 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
,
1567 #endif /* ANIMATIONS */
1569 wAppIconMove(aicon
, X
, Y
);
1572 /* we reversed the order so we use prev */
1573 aicon
= aicon
->prev
;
1580 /* arrange miniwindows */
1582 wwin
= scr
->focused_window
;
1583 /* reverse them to avoid unnecessarily shuffling */
1584 while (wwin
&& wwin
->prev
)
1588 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1589 (wwin
->frame
->workspace
==scr
->current_workspace
||
1590 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1592 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1593 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1595 if (wPreferences
.no_animations
) {
1596 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1598 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1599 wwin
->icon_y
, X
, Y
);
1602 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1603 #endif /* ANIMATIONS */
1611 wwin
->flags
.icon_moved
= 0;
1613 /* we reversed the order, so we use next */
1624 wSelectWindow(WWindow
*wwin
, Bool flag
)
1626 WScreen
*scr
= wwin
->screen_ptr
;
1629 wwin
->flags
.selected
= 1;
1630 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1632 if (WFLAGP(wwin
, no_border
)) {
1633 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
,
1634 FRAME_BORDER_WIDTH
);
1637 if (!scr
->selected_windows
)
1638 scr
->selected_windows
= WMCreateArray(4);
1639 WMAddToArray(scr
->selected_windows
, wwin
);
1641 wwin
->flags
.selected
= 0;
1642 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
,
1643 scr
->frame_border_pixel
);
1645 if (WFLAGP(wwin
, no_border
)) {
1646 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1649 if (scr
->selected_windows
) {
1650 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1657 wMakeWindowVisible(WWindow
*wwin
)
1659 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1660 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1662 if (wwin
->flags
.shaded
) {
1663 wUnshadeWindow(wwin
);
1665 if (wwin
->flags
.hidden
) {
1668 app
= wApplicationOf(wwin
->main_window
);
1670 wUnhideApplication(app
, False
, False
);
1671 } else if (wwin
->flags
.miniaturized
) {
1672 wDeiconifyWindow(wwin
);
1674 if (!WFLAGP(wwin
, no_focusable
))
1675 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1676 wRaiseFrame(wwin
->frame
->core
);