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"
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;*/
183 napp
->last_workspace
= wwin
->frame
->workspace
;
186 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
187 /* install colormap if colormap mode is lock mode */
188 if (wPreferences
.colormap_mode
==WCM_CLICK
)
189 wColormapInstallForWindow(scr
, wwin
);
191 /* set input focus */
192 switch (wwin
->focus_mode
) {
194 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
198 case WFM_LOCALLY_ACTIVE
:
199 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, timestamp
);
202 case WFM_GLOBALLY_ACTIVE
:
206 if (wwin
->protocols
.TAKE_FOCUS
) {
207 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
211 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, timestamp
);
213 if (WFLAGP(wwin
, no_focusable
))
216 /* if this is not the focused window focus it */
218 /* change the focus window list order */
220 wwin
->prev
->next
= wwin
->next
;
223 wwin
->next
->prev
= wwin
->prev
;
225 wwin
->prev
= focused
;
226 focused
->next
= wwin
;
228 scr
->focused_window
= wwin
;
230 if (oapp
&& oapp
!= napp
) {
231 wAppMenuUnmap(oapp
->menu
);
233 wApplicationDeactivate(oapp
);
238 wWindowFocus(wwin
, focused
);
240 if (napp
&& !wasfocused
) {
242 wUserMenuRefreshInstances(napp
->menu
, wwin
);
243 #endif /* USER_MENU */
245 if (wwin
->flags
.mapped
)
246 wAppMenuMap(napp
->menu
, wwin
);
248 wApplicationActivate(napp
);
258 wShadeWindow(WWindow
*wwin
)
265 if (wwin
->flags
.shaded
)
270 XLowerWindow(dpy
, wwin
->client_win
);
272 wSoundPlay(WSOUND_SHADE
);
275 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
276 && !wPreferences
.no_animations
) {
277 /* do the shading animation */
278 h
= wwin
->frame
->core
->height
;
281 w
= wwin
->frame
->core
->width
;
282 y
= wwin
->frame
->top_width
;
283 while (h
>wwin
->frame
->top_width
+1) {
284 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
285 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
288 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
291 if (SHADE_DELAY
> 0) {
292 wusleep(SHADE_DELAY
*1000L);
299 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
301 #endif /* ANIMATIONS */
303 wwin
->flags
.skip_next_animation
= 0;
304 wwin
->flags
.shaded
= 1;
305 wwin
->flags
.mapped
= 0;
306 /* prevent window withdrawal when getting UnmapNotify */
307 XSelectInput(dpy
, wwin
->client_win
,
308 wwin
->event_mask
& ~StructureNotifyMask
);
309 XUnmapWindow(dpy
, wwin
->client_win
);
310 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
312 /* for the client it's just like iconification */
313 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
314 wwin
->frame
->top_width
- 1);
316 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
317 + wwin
->frame
->top_width
;
318 wWindowSynthConfigureNotify(wwin
);
321 wClientSetState(wwin, IconicState, None);
324 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
327 if (!wwin
->screen_ptr
->flags
.startup
) {
328 /* Look at processEvents() for reason of this code. */
330 processEvents(XPending(dpy
));
337 wUnshadeWindow(WWindow
*wwin
)
342 #endif /* ANIMATIONS */
345 if (!wwin
->flags
.shaded
)
350 wwin
->flags
.shaded
= 0;
351 wwin
->flags
.mapped
= 1;
352 XMapWindow(dpy
, wwin
->client_win
);
354 wSoundPlay(WSOUND_UNSHADE
);
357 if (!wPreferences
.no_animations
&& !wwin
->flags
.skip_next_animation
) {
358 /* do the shading animation */
359 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
360 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
361 s
= abs(y
)/SHADE_STEPS
;
363 w
= wwin
->frame
->core
->width
;
364 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
366 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
367 + wwin
->frame
->bottom_width
) {
368 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
369 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
371 if (SHADE_DELAY
> 0) {
372 wusleep(SHADE_DELAY
*2000L/3);
379 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
383 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
385 #endif /* ANIMATIONS */
387 wwin
->flags
.skip_next_animation
= 0;
388 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
389 wwin
->frame
->top_width
+ wwin
->client
.height
390 + wwin
->frame
->bottom_width
);
392 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
393 wWindowSynthConfigureNotify(wwin
);
396 wClientSetState(wwin, NormalState, None);
398 /* if the window is focused, set the focus again as it was disabled during
400 if (wwin
->flags
.focused
)
401 wSetFocusTo(wwin
->screen_ptr
, wwin
);
403 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
408 wMaximizeWindow(WWindow
*wwin
, int directions
)
410 int new_width
, new_height
, new_x
, new_y
;
411 WArea usableArea
= wwin
->screen_ptr
->totalUsableArea
;
415 if (WFLAGP(wwin
, no_resizable
))
420 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
421 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
424 if (wwin
->screen_ptr
->xine_count
> 0
425 && !(directions
& MAX_IGNORE_XINERAMA
)) {
426 WScreen
*scr
= wwin
->screen_ptr
;
429 rect
= wGetRectForHead(scr
, wGetHeadForWindow(wwin
));
430 totalArea
.x1
= rect
.pos
.x
;
431 totalArea
.y1
= rect
.pos
.y
;
432 totalArea
.x2
= totalArea
.x1
+ rect
.size
.width
;
433 totalArea
.y2
= totalArea
.y1
+ rect
.size
.height
;
435 usableArea
.x1
= WMAX(totalArea
.x1
, usableArea
.x1
);
436 usableArea
.y1
= WMAX(totalArea
.y1
, usableArea
.y1
);
437 usableArea
.x2
= WMIN(totalArea
.x2
, usableArea
.x2
);
438 usableArea
.y2
= WMIN(totalArea
.y2
, usableArea
.y2
);
440 #endif /* XINERAMA */
442 if (WFLAGP(wwin
, full_maximize
)) {
443 usableArea
= totalArea
;
446 if (wwin
->flags
.shaded
) {
447 wwin
->flags
.skip_next_animation
= 1;
448 wUnshadeWindow(wwin
);
450 wwin
->flags
.maximized
= directions
;
451 wwin
->old_geometry
.width
= wwin
->client
.width
;
452 wwin
->old_geometry
.height
= wwin
->client
.height
;
453 wwin
->old_geometry
.x
= wwin
->frame_x
;
454 wwin
->old_geometry
.y
= wwin
->frame_y
;
457 wKWMUpdateClientGeometryRestore(wwin
);
460 if (directions
& MAX_HORIZONTAL
) {
462 new_width
= (usableArea
.x2
-usableArea
.x1
)-FRAME_BORDER_WIDTH
*2;
463 new_x
= usableArea
.x1
;
467 new_x
= wwin
->frame_x
;
468 new_width
= wwin
->frame
->core
->width
;
472 if (directions
& MAX_VERTICAL
) {
474 new_height
= (usableArea
.y2
-usableArea
.y1
)-FRAME_BORDER_WIDTH
*2;
475 new_y
= usableArea
.y1
;
476 if (WFLAGP(wwin
, full_maximize
)) {
477 new_y
-= wwin
->frame
->top_width
;
478 new_height
+= wwin
->frame
->bottom_width
- 1;
481 new_y
= wwin
->frame_y
;
482 new_height
= wwin
->frame
->core
->height
;
485 if (!WFLAGP(wwin
, full_maximize
)) {
486 new_height
-= wwin
->frame
->top_width
+wwin
->frame
->bottom_width
;
489 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
491 wWindowCropSize(wwin
, usableArea
.x2
-usableArea
.x1
,
492 usableArea
.y2
-usableArea
.y1
,
493 &new_width
, &new_height
);
495 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
498 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
500 wSoundPlay(WSOUND_MAXIMIZE
);
505 wUnmaximizeWindow(WWindow
*wwin
)
507 int restore_x
, restore_y
;
509 if (!wwin
->flags
.maximized
)
512 if (wwin
->flags
.shaded
) {
513 wwin
->flags
.skip_next_animation
= 1;
514 wUnshadeWindow(wwin
);
516 restore_x
= (wwin
->flags
.maximized
& MAX_HORIZONTAL
) ?
517 wwin
->old_geometry
.x
: wwin
->frame_x
;
518 restore_y
= (wwin
->flags
.maximized
& MAX_VERTICAL
) ?
519 wwin
->old_geometry
.y
: wwin
->frame_y
;
520 wwin
->flags
.maximized
= 0;
521 wWindowConfigure(wwin
, restore_x
, restore_y
,
522 wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
524 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
526 wSoundPlay(WSOUND_UNMAXIMIZE
);
531 animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
,
532 int fx
, int fy
, int fw
, int fh
, int steps
)
534 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
535 float cx
, cy
, cw
, ch
;
536 float xstep
, ystep
, wstep
, hstep
;
539 float angle
, final_angle
, delta
;
541 xstep
= (float)(fx
-x
)/steps
;
542 ystep
= (float)(fy
-y
)/steps
;
543 wstep
= (float)(fw
-w
)/steps
;
544 hstep
= (float)(fh
-h
)/steps
;
551 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_F
;
552 delta
= (float)(final_angle
/FRAMES
);
553 for (angle
=0;; angle
+=delta
) {
554 if (angle
> final_angle
)
557 dx
= (cw
/10) - ((cw
/5) * sin(angle
));
558 dch
= (ch
/2) * cos(angle
);
561 points
[0].x
= cx
+ dx
; points
[0].y
= midy
- dch
;
562 points
[1].x
= cx
+ cw
- dx
; points
[1].y
= points
[0].y
;
563 points
[2].x
= cx
+ cw
+ dx
; points
[2].y
= midy
+ dch
;
564 points
[3].x
= cx
- dx
; points
[3].y
= points
[2].y
;
565 points
[4].x
= points
[0].x
; points
[4].y
= points
[0].y
;
568 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
570 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
571 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
576 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
582 if (angle
>= final_angle
)
592 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
,
593 int fx
, int fy
, int fw
, int fh
, int steps
)
595 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
596 float cx
, cy
, cw
, ch
;
597 float xstep
, ystep
, wstep
, hstep
;
599 float angle
, final_angle
, a
, d
, delta
;
606 xstep
= (float)(fx
-x
)/steps
;
607 ystep
= (float)(fy
-y
)/steps
;
608 wstep
= (float)(fw
-w
)/steps
;
609 hstep
= (float)(fh
-h
)/steps
;
616 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_T
;
617 delta
= (float)(final_angle
/FRAMES
);
618 for (angle
=0;; angle
+=delta
) {
619 if (angle
> final_angle
)
623 d
= sqrt((cw
/2)*(cw
/2)+(ch
/2)*(ch
/2));
625 points
[0].x
= cx
+cos(angle
-a
)*d
;
626 points
[0].y
= cy
+sin(angle
-a
)*d
;
627 points
[1].x
= cx
+cos(angle
+a
)*d
;
628 points
[1].y
= cy
+sin(angle
+a
)*d
;
629 points
[2].x
= cx
+cos(angle
-a
+WM_PI
)*d
;
630 points
[2].y
= cy
+sin(angle
-a
+WM_PI
)*d
;
631 points
[3].x
= cx
+cos(angle
+a
+WM_PI
)*d
;
632 points
[3].y
= cy
+sin(angle
+a
+WM_PI
)*d
;
633 points
[4].x
= cx
+cos(angle
-a
)*d
;
634 points
[4].y
= cy
+sin(angle
-a
)*d
;
636 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
638 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
639 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
644 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
650 if (angle
>= final_angle
)
660 animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
,
661 int fx
, int fy
, int fw
, int fh
, int steps
)
663 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
664 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
665 float xstep
, ystep
, wstep
, hstep
;
668 xstep
= (float)(fx
-x
)/steps
;
669 ystep
= (float)(fy
-y
)/steps
;
670 wstep
= (float)(fw
-w
)/steps
;
671 hstep
= (float)(fh
-h
)/steps
;
673 for (j
=0; j
<FRAMES
; j
++) {
680 for (i
=0; i
<steps
; i
++) {
681 for (j
=0; j
<FRAMES
; j
++) {
682 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
683 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
686 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
687 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
691 for (j
=0; j
<FRAMES
; j
++) {
692 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
693 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
708 for (j
=0; j
<FRAMES
; j
++) {
709 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
710 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
713 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
714 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
718 for (j
=0; j
<FRAMES
; j
++) {
719 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
720 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
729 animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
,
730 int fx
, int fy
, int fw
, int fh
, int hiding
)
732 int style
= wPreferences
.iconification_style
; /* Catch the value */
735 if (style
== WIS_NONE
)
738 if (style
== WIS_RANDOM
) {
742 k
= (hiding
? 2 : 3);
745 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
)/3;
747 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
750 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
)/3;
752 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
756 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
)/3;
758 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
762 #endif /* ANIMATIONS */
770 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
771 WMHandleEvent(&tmpev
);
776 unmapTransientsFor(WWindow
*wwin
)
781 tmp
= wwin
->screen_ptr
->focused_window
;
783 /* unmap the transients for this transient */
784 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
785 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
786 || tmp
->flags
.shaded
)) {
787 unmapTransientsFor(tmp
);
788 tmp
->flags
.miniaturized
= 1;
789 if (!tmp
->flags
.shaded
) {
792 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
795 if (!tmp->flags.shaded)
797 wClientSetState(tmp
, IconicState
, None
);
799 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
807 mapTransientsFor(WWindow
*wwin
)
811 tmp
= wwin
->screen_ptr
->focused_window
;
813 /* recursively map the transients for this transient */
814 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
815 && /*!tmp->flags.mapped*/ tmp
->flags
.miniaturized
816 && tmp
->icon
==NULL
) {
817 mapTransientsFor(tmp
);
818 tmp
->flags
.miniaturized
= 0;
819 if (!tmp
->flags
.shaded
) {
822 XMapWindow(dpy
, tmp
->frame
->core
->window
);
824 tmp
->flags
.semi_focused
= 0;
826 if (!tmp->flags.shaded)
828 wClientSetState(tmp
, NormalState
, None
);
830 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
838 setupIconGrabs(WIcon
*icon
)
840 /* setup passive grabs on the icon */
841 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
842 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
843 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
844 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
845 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
846 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
852 recursiveTransientFor(WWindow
*wwin
)
859 /* hackish way to detect transient_for cycle */
860 i
= wwin
->screen_ptr
->window_count
+1;
862 while (wwin
&& wwin
->transient_for
!= None
&& i
>0) {
863 wwin
= wWindowFor(wwin
->transient_for
);
867 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
877 removeIconGrabs(WIcon
*icon
)
879 /* remove passive grabs on the icon */
880 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
881 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
882 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
889 wIconifyWindow(WWindow
*wwin
)
891 XWindowAttributes attribs
;
895 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
896 /* the window doesn't exist anymore */
900 if (wwin
->flags
.miniaturized
) {
904 if (wwin
->transient_for
!=None
&&
905 wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
906 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
908 if (owner
&& owner
->flags
.miniaturized
)
912 present
= wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
;
914 /* if the window is in another workspace, simplify process */
916 /* icon creation may take a while */
917 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
918 ButtonMotionMask
|ButtonReleaseMask
, GrabModeAsync
,
919 GrabModeAsync
, None
, None
, CurrentTime
);
922 if (!wPreferences
.disable_miniwindows
) {
923 if (!wwin
->flags
.icon_moved
) {
924 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
);
926 wwin
->icon
= wIconCreate(wwin
);
928 wwin
->icon
->mapped
= 1;
931 wwin
->flags
.miniaturized
= 1;
932 wwin
->flags
.mapped
= 0;
934 /* unmap transients */
936 unmapTransientsFor(wwin
);
939 wSoundPlay(WSOUND_ICONIFY
);
941 XUngrabPointer(dpy
, CurrentTime
);
943 /* let all Expose events arrive so that we can repaint
944 * something before the animation starts (and the server is grabbed) */
947 if (wPreferences
.disable_miniwindows
)
948 wClientSetState(wwin
, IconicState
, None
);
950 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
954 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
955 && !wPreferences
.no_animations
) {
958 if (!wPreferences
.disable_miniwindows
) {
961 iw
= wwin
->icon
->core
->width
;
962 ih
= wwin
->icon
->core
->height
;
967 if (wKWMGetIconGeometry(wwin
, &area
)) {
973 #endif /* KWM_HINTS */
977 iw
= wwin
->screen_ptr
->scr_width
;
978 ih
= wwin
->screen_ptr
->scr_height
;
981 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
982 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
983 ix
, iy
, iw
, ih
, False
);
988 wwin
->flags
.skip_next_animation
= 0;
990 if (!wPreferences
.disable_miniwindows
) {
992 if (wwin
->screen_ptr
->current_workspace
==wwin
->frame
->workspace
||
993 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
995 XMapWindow(dpy
, wwin
->icon
->core
->window
);
997 AddToStackList(wwin
->icon
->core
);
999 wLowerFrame(wwin
->icon
->core
);
1003 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1006 * It doesn't seem to be working and causes button event hangup
1007 * when deiconifying a transient window.
1008 setupIconGrabs(wwin->icon);
1010 if ((wwin
->flags
.focused
1011 || (owner
&& wwin
->client_win
== owner
->client_win
))
1012 && wPreferences
.focus_mode
==WKF_CLICK
) {
1017 if (!WFLAGP(tmp
, no_focusable
)
1018 && !(tmp
->flags
.hidden
||tmp
->flags
.miniaturized
)
1019 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1023 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1024 } else if (wPreferences
.focus_mode
!=WKF_CLICK
) {
1025 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1029 if (!wwin
->screen_ptr
->flags
.startup
) {
1030 Window clientwin
= wwin
->client_win
;
1033 processEvents(XPending(dpy
));
1035 /* the window can disappear while doing the processEvents() */
1036 if (!wWindowFor(clientwin
))
1043 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
)
1044 wIconSelect(wwin
->icon
);
1046 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1053 wDeiconifyWindow(WWindow
*wwin
)
1055 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1057 if (!wwin
->flags
.miniaturized
)
1060 if (wwin
->transient_for
!= None
1061 && wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1062 WWindow
*owner
= recursiveTransientFor(wwin
);
1064 if (owner
&& owner
->flags
.miniaturized
) {
1065 wDeiconifyWindow(owner
);
1066 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1067 wRaiseFrame(wwin
->frame
->core
);
1072 wwin
->flags
.miniaturized
= 0;
1073 if (!wwin
->flags
.shaded
)
1074 wwin
->flags
.mapped
= 1;
1076 if (!wPreferences
.disable_miniwindows
) {
1077 if (wwin
->icon
->selected
)
1078 wIconSelect(wwin
->icon
);
1080 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1083 wSoundPlay(WSOUND_DEICONIFY
);
1085 /* if the window is in another workspace, do it silently */
1087 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1088 && !wwin
->flags
.skip_next_animation
) {
1091 if (!wPreferences
.disable_miniwindows
) {
1094 iw
= wwin
->icon
->core
->width
;
1095 ih
= wwin
->icon
->core
->height
;
1100 if (wKWMGetIconGeometry(wwin
, &area
)) {
1106 #endif /* KWM_HINTS */
1110 iw
= wwin
->screen_ptr
->scr_width
;
1111 ih
= wwin
->screen_ptr
->scr_height
;
1114 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1115 wwin
->frame_x
, wwin
->frame_y
,
1116 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1119 #endif /* ANIMATIONS */
1120 wwin
->flags
.skip_next_animation
= 0;
1122 if (!wwin
->flags
.shaded
) {
1123 XMapWindow(dpy
, wwin
->client_win
);
1125 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1126 wRaiseFrame(wwin
->frame
->core
);
1127 if (!wwin
->flags
.shaded
) {
1128 wClientSetState(wwin
, NormalState
, None
);
1130 mapTransientsFor(wwin
);
1132 if (!wPreferences
.disable_miniwindows
) {
1133 RemoveFromStackList(wwin
->icon
->core
);
1134 /* removeIconGrabs(wwin->icon);*/
1135 wIconDestroy(wwin
->icon
);
1140 if (wPreferences
.focus_mode
==WKF_CLICK
)
1141 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1144 if (!wwin
->screen_ptr
->flags
.startup
) {
1145 Window clientwin
= wwin
->client_win
;
1148 processEvents(XPending(dpy
));
1150 if (!wWindowFor(clientwin
))
1155 if (wPreferences
.auto_arrange_icons
) {
1156 wArrangeIcons(wwin
->screen_ptr
, True
);
1159 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1161 /* In case we were shaded and iconified, also unshade */
1162 wUnshadeWindow(wwin
);
1168 hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1170 if (wwin
->flags
.miniaturized
) {
1172 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1173 wwin
->icon
->mapped
= 0;
1175 wwin
->flags
.hidden
= 1;
1177 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1181 if (wwin
->flags
.inspector_open
) {
1182 wHideInspectorForWindow(wwin
);
1185 wwin
->flags
.hidden
= 1;
1188 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1190 wSoundPlay(WSOUND_HIDE
);
1192 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1193 !wwin
->flags
.skip_next_animation
&& animate
) {
1194 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1195 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1196 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
,
1200 wwin
->flags
.skip_next_animation
= 0;
1202 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1208 wHideOtherApplications(WWindow
*awin
)
1215 wwin
= awin
->screen_ptr
->focused_window
;
1220 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1221 && !(wwin
->flags
.miniaturized
||wwin
->flags
.hidden
)
1222 && !wwin
->flags
.internal_window
1223 && wGetWindowOfInspectorForWindow(wwin
) != awin
1224 && !WFLAGP(wwin
, no_hide_others
)) {
1226 if (wwin
->main_window
==None
|| WFLAGP(wwin
, no_appicon
)) {
1227 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1228 wwin
->flags
.skip_next_animation
= 1;
1229 wIconifyWindow(wwin
);
1231 } else if (wwin
->main_window
!=None
1232 && awin
->main_window
!= wwin
->main_window
) {
1233 tapp
= wApplicationOf(wwin
->main_window
);
1235 tapp
->flags
.skip_next_animation
= 1;
1236 wHideApplication(tapp
);
1238 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1239 wwin
->flags
.skip_next_animation
= 1;
1240 wIconifyWindow(wwin
);
1248 wSetFocusTo(awin->screen_ptr, awin);
1255 wHideApplication(WApplication
*wapp
)
1262 wwarning("trying to hide a non grouped window");
1265 if (!wapp
->main_window_desc
) {
1266 wwarning("group leader not found for window group");
1269 scr
= wapp
->main_window_desc
->screen_ptr
;
1271 wlist
= scr
->focused_window
;
1275 if (wlist
->main_window
== wapp
->main_window
)
1276 wapp
->last_focused
= wlist
;
1278 wapp
->last_focused
= NULL
;
1280 if (wlist
->main_window
== wapp
->main_window
) {
1281 if (wlist
->flags
.focused
) {
1285 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1286 wapp
->app_icon
->y_pos
, wlist
,
1287 !wapp
->flags
.skip_next_animation
);
1289 wlist
= wlist
->prev
;
1292 wapp
->flags
.skip_next_animation
= 0;
1295 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1296 wlist
= scr
->focused_window
;
1298 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1299 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1301 wlist
= wlist
->prev
;
1303 wSetFocusTo(scr
, wlist
);
1305 wSetFocusTo(scr
, NULL
);
1309 wapp
->flags
.hidden
= 1;
1311 if(wPreferences
.auto_arrange_icons
) {
1312 wArrangeIcons(scr
, True
);
1316 wAppIconPaint(wapp
->app_icon
);
1324 unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
,
1325 int bringToCurrentWS
)
1327 if (bringToCurrentWS
)
1328 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1330 wwin
->flags
.hidden
=0;
1332 wSoundPlay(WSOUND_UNHIDE
);
1334 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1336 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1337 icon
->core
->width
, icon
->core
->height
,
1338 wwin
->frame_x
, wwin
->frame_y
,
1339 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1343 wwin
->flags
.skip_next_animation
= 0;
1344 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1345 XMapWindow(dpy
, wwin
->client_win
);
1346 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1347 wClientSetState(wwin
, NormalState
, None
);
1348 wwin
->flags
.mapped
=1;
1349 wRaiseFrame(wwin
->frame
->core
);
1351 if (wwin
->flags
.inspector_open
) {
1352 wUnhideInspectorForWindow(wwin
);
1355 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1360 wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1363 WWindow
*wlist
, *next
;
1364 WWindow
*focused
=NULL
;
1369 scr
= wapp
->main_window_desc
->screen_ptr
;
1370 wlist
= scr
->focused_window
;
1372 /* goto beginning of list */
1374 wlist
= wlist
->prev
;
1379 if (wlist
->main_window
== wapp
->main_window
) {
1380 if (wlist
->flags
.focused
)
1382 else if (!focused
|| !focused
->flags
.focused
)
1385 if (wlist
->flags
.miniaturized
&& wlist
->icon
) {
1386 if (bringToCurrentWS
|| wPreferences
.sticky_icons
1387 || wlist
->frame
->workspace
== scr
->current_workspace
) {
1388 if (!wlist
->icon
->mapped
) {
1389 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1390 wlist
->icon
->mapped
= 1;
1392 wlist
->flags
.hidden
= 0;
1394 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1396 if (wlist
->frame
->workspace
!= scr
->current_workspace
)
1397 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1400 wDeiconifyWindow(wlist
);
1402 } else if (wlist
->flags
.hidden
) {
1403 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1404 wapp
->app_icon
->y_pos
, wlist
,
1405 !wapp
->flags
.skip_next_animation
,
1408 if (bringToCurrentWS
1409 && wlist
->frame
->workspace
!= scr
->current_workspace
) {
1410 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1412 wRaiseFrame(wlist
->frame
->core
);
1418 wapp
->flags
.skip_next_animation
= 0;
1419 wapp
->flags
.hidden
= 0;
1422 wSetFocusTo(scr
, focused
);
1423 else if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
)
1424 wSetFocusTo(scr
, wapp
->last_focused
);
1425 wapp
->last_focused
= NULL
;
1426 if (wPreferences
.auto_arrange_icons
) {
1427 wArrangeIcons(scr
, True
);
1430 wAppIconPaint(wapp
->app_icon
);
1437 wShowAllWindows(WScreen
*scr
)
1439 WWindow
*wwin
, *old_foc
;
1442 old_foc
= wwin
= scr
->focused_window
;
1444 if (!wwin
->flags
.internal_window
&&
1445 (scr
->current_workspace
== wwin
->frame
->workspace
1446 || IS_OMNIPRESENT(wwin
))) {
1447 if (wwin
->flags
.miniaturized
) {
1448 wwin
->flags
.skip_next_animation
= 1;
1449 wDeiconifyWindow(wwin
);
1450 } else if (wwin
->flags
.hidden
) {
1451 wapp
= wApplicationOf(wwin
->main_window
);
1453 wUnhideApplication(wapp
, False
, False
);
1455 wwin
->flags
.skip_next_animation
= 1;
1456 wDeiconifyWindow(wwin
);
1462 wSetFocusTo(scr
, old_foc
);
1463 /*wRaiseFrame(old_foc->frame->core);*/
1468 wRefreshDesktop(WScreen
*scr
)
1471 XSetWindowAttributes attr
;
1473 attr
.backing_store
= NotUseful
;
1474 attr
.save_under
= False
;
1475 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1476 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1477 (Visual
*)CopyFromParent
, CWBackingStore
|CWSaveUnder
,
1479 XMapRaised(dpy
, win
);
1480 XDestroyWindow(dpy
, win
);
1486 wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1490 int pf
; /* primary axis */
1491 int sf
; /* secondary axis */
1495 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1499 int isize
= wPreferences
.icon_size
;
1502 * Find out screen boundaries.
1506 sx2
= scr
->scr_width
;
1507 sy2
= scr
->scr_height
;
1509 if (scr
->dock
->on_right_side
)
1510 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1512 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1515 sw
= isize
* (scr
->scr_width
/isize
);
1516 sh
= isize
* (scr
->scr_height
/isize
);
1517 fullW
= (sx2
-sx1
)/isize
;
1518 fullH
= (sy2
-sy1
)/isize
;
1520 /* icon yard boundaries */
1521 if (wPreferences
.icon_yard
& IY_VERT
) {
1528 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1535 if (wPreferences
.icon_yard
& IY_TOP
) {
1543 /* arrange icons putting the most recently focused window
1544 * as the last icon */
1545 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1546 : xo + xs*(pi*isize))
1547 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1548 : yo + ys*(si*isize))
1550 /* arrange application icons */
1551 aicon
= scr
->app_icon_list
;
1552 /* reverse them to avoid unnecessarily sliding of icons */
1553 while (aicon
&& aicon
->next
)
1554 aicon
= aicon
->next
;
1559 if (!aicon
->docked
) {
1560 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1562 if (!wPreferences
.no_animations
) {
1563 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
,
1566 #endif /* ANIMATIONS */
1568 wAppIconMove(aicon
, X
, Y
);
1571 /* we reversed the order so we use prev */
1572 aicon
= aicon
->prev
;
1579 /* arrange miniwindows */
1581 wwin
= scr
->focused_window
;
1582 /* reverse them to avoid unnecessarily shuffling */
1583 while (wwin
&& wwin
->prev
)
1587 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1588 (wwin
->frame
->workspace
==scr
->current_workspace
||
1589 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1591 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1592 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1594 if (wPreferences
.no_animations
) {
1595 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1597 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1598 wwin
->icon_y
, X
, Y
);
1601 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1602 #endif /* ANIMATIONS */
1610 wwin
->flags
.icon_moved
= 0;
1612 /* we reversed the order, so we use next */
1623 wSelectWindow(WWindow
*wwin
, Bool flag
)
1625 WScreen
*scr
= wwin
->screen_ptr
;
1628 wwin
->flags
.selected
= 1;
1629 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1631 if (WFLAGP(wwin
, no_border
)) {
1632 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
,
1633 FRAME_BORDER_WIDTH
);
1636 if (!scr
->selected_windows
)
1637 scr
->selected_windows
= WMCreateArray(4);
1638 WMAddToArray(scr
->selected_windows
, wwin
);
1640 wwin
->flags
.selected
= 0;
1641 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
,
1642 scr
->frame_border_pixel
);
1644 if (WFLAGP(wwin
, no_border
)) {
1645 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1648 if (scr
->selected_windows
) {
1649 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1656 wMakeWindowVisible(WWindow
*wwin
)
1658 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1659 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1661 if (wwin
->flags
.shaded
) {
1662 wUnshadeWindow(wwin
);
1664 if (wwin
->flags
.hidden
) {
1667 app
= wApplicationOf(wwin
->main_window
);
1669 wUnhideApplication(app
, False
, False
);
1670 } else if (wwin
->flags
.miniaturized
) {
1671 wDeiconifyWindow(wwin
);
1673 if (!WFLAGP(wwin
, no_focusable
))
1674 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1675 wRaiseFrame(wwin
->frame
->core
);