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
;
415 if (WFLAGP(wwin
, no_resizable
))
420 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
421 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
423 if (wwin
->screen_ptr
->xine_count
> 0
424 && !(directions
& MAX_IGNORE_XINERAMA
)) {
425 WScreen
*scr
= wwin
->screen_ptr
;
431 rect.pos.x = wwin->frame_x;
432 rect.pos.y = wwin->frame_y;
433 rect.size.width = wwin->frame->core->width;
434 rect.size.height = wwin->frame->core->height;
436 head = wGetHeadForRect(scr, rect);
439 head
= wGetHeadForPointerLocation(scr
);
441 rect
= wGetRectForHead(scr
, head
);
443 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
);
446 if (WFLAGP(wwin
, full_maximize
)) {
447 usableArea
= totalArea
;
450 if (wwin
->flags
.shaded
) {
451 wwin
->flags
.skip_next_animation
= 1;
452 wUnshadeWindow(wwin
);
454 wwin
->flags
.maximized
= directions
;
455 wwin
->old_geometry
.width
= wwin
->client
.width
;
456 wwin
->old_geometry
.height
= wwin
->client
.height
;
457 wwin
->old_geometry
.x
= wwin
->frame_x
;
458 wwin
->old_geometry
.y
= wwin
->frame_y
;
461 wKWMUpdateClientGeometryRestore(wwin
);
464 if (directions
& MAX_HORIZONTAL
) {
466 new_width
= (usableArea
.x2
-usableArea
.x1
)-FRAME_BORDER_WIDTH
*2;
467 new_x
= usableArea
.x1
;
471 new_x
= wwin
->frame_x
;
472 new_width
= wwin
->frame
->core
->width
;
476 if (directions
& MAX_VERTICAL
) {
478 new_height
= (usableArea
.y2
-usableArea
.y1
)-FRAME_BORDER_WIDTH
*2;
479 new_y
= usableArea
.y1
;
480 if (WFLAGP(wwin
, full_maximize
)) {
481 new_y
-= wwin
->frame
->top_width
;
482 new_height
+= wwin
->frame
->bottom_width
- 1;
485 new_y
= wwin
->frame_y
;
486 new_height
= wwin
->frame
->core
->height
;
489 if (!WFLAGP(wwin
, full_maximize
)) {
490 new_height
-= wwin
->frame
->top_width
+wwin
->frame
->bottom_width
;
493 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
495 wWindowCropSize(wwin
, usableArea
.x2
-usableArea
.x1
,
496 usableArea
.y2
-usableArea
.y1
,
497 &new_width
, &new_height
);
499 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
502 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
504 wSoundPlay(WSOUND_MAXIMIZE
);
509 wUnmaximizeWindow(WWindow
*wwin
)
511 int restore_x
, restore_y
;
513 if (!wwin
->flags
.maximized
)
516 if (wwin
->flags
.shaded
) {
517 wwin
->flags
.skip_next_animation
= 1;
518 wUnshadeWindow(wwin
);
520 restore_x
= (wwin
->flags
.maximized
& MAX_HORIZONTAL
) ?
521 wwin
->old_geometry
.x
: wwin
->frame_x
;
522 restore_y
= (wwin
->flags
.maximized
& MAX_VERTICAL
) ?
523 wwin
->old_geometry
.y
: wwin
->frame_y
;
524 wwin
->flags
.maximized
= 0;
525 wWindowConfigure(wwin
, restore_x
, restore_y
,
526 wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
528 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
530 wSoundPlay(WSOUND_UNMAXIMIZE
);
535 animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
,
536 int fx
, int fy
, int fw
, int fh
, int steps
)
538 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
539 float cx
, cy
, cw
, ch
;
540 float xstep
, ystep
, wstep
, hstep
;
543 float angle
, final_angle
, delta
;
545 xstep
= (float)(fx
-x
)/steps
;
546 ystep
= (float)(fy
-y
)/steps
;
547 wstep
= (float)(fw
-w
)/steps
;
548 hstep
= (float)(fh
-h
)/steps
;
555 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_F
;
556 delta
= (float)(final_angle
/FRAMES
);
557 for (angle
=0;; angle
+=delta
) {
558 if (angle
> final_angle
)
561 dx
= (cw
/10) - ((cw
/5) * sin(angle
));
562 dch
= (ch
/2) * cos(angle
);
565 points
[0].x
= cx
+ dx
; points
[0].y
= midy
- dch
;
566 points
[1].x
= cx
+ cw
- dx
; points
[1].y
= points
[0].y
;
567 points
[2].x
= cx
+ cw
+ dx
; points
[2].y
= midy
+ dch
;
568 points
[3].x
= cx
- dx
; points
[3].y
= points
[2].y
;
569 points
[4].x
= points
[0].x
; points
[4].y
= points
[0].y
;
572 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
574 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
575 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
580 XDrawLines(dpy
,scr
->root_win
,scr
->frame_gc
,points
, 5, CoordModeOrigin
);
586 if (angle
>= final_angle
)
596 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
,
597 int fx
, int fy
, int fw
, int fh
, int steps
)
599 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
600 float cx
, cy
, cw
, ch
;
601 float xstep
, ystep
, wstep
, hstep
;
603 float angle
, final_angle
, a
, d
, delta
;
610 xstep
= (float)(fx
-x
)/steps
;
611 ystep
= (float)(fy
-y
)/steps
;
612 wstep
= (float)(fw
-w
)/steps
;
613 hstep
= (float)(fh
-h
)/steps
;
620 final_angle
= 2*WM_PI
*MINIATURIZE_ANIMATION_TWIST_T
;
621 delta
= (float)(final_angle
/FRAMES
);
622 for (angle
=0;; angle
+=delta
) {
623 if (angle
> final_angle
)
627 d
= sqrt((cw
/2)*(cw
/2)+(ch
/2)*(ch
/2));
629 points
[0].x
= cx
+cos(angle
-a
)*d
;
630 points
[0].y
= cy
+sin(angle
-a
)*d
;
631 points
[1].x
= cx
+cos(angle
+a
)*d
;
632 points
[1].y
= cy
+sin(angle
+a
)*d
;
633 points
[2].x
= cx
+cos(angle
-a
+WM_PI
)*d
;
634 points
[2].y
= cy
+sin(angle
-a
+WM_PI
)*d
;
635 points
[3].x
= cx
+cos(angle
+a
+WM_PI
)*d
;
636 points
[3].y
= cy
+sin(angle
+a
+WM_PI
)*d
;
637 points
[4].x
= cx
+cos(angle
-a
)*d
;
638 points
[4].y
= cy
+sin(angle
-a
)*d
;
640 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
642 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
643 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
648 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
654 if (angle
>= final_angle
)
664 animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
,
665 int fx
, int fy
, int fw
, int fh
, int steps
)
667 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
668 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
669 float xstep
, ystep
, wstep
, hstep
;
672 xstep
= (float)(fx
-x
)/steps
;
673 ystep
= (float)(fy
-y
)/steps
;
674 wstep
= (float)(fw
-w
)/steps
;
675 hstep
= (float)(fh
-h
)/steps
;
677 for (j
=0; j
<FRAMES
; j
++) {
684 for (i
=0; i
<steps
; i
++) {
685 for (j
=0; j
<FRAMES
; j
++) {
686 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
687 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
690 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
691 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
695 for (j
=0; j
<FRAMES
; j
++) {
696 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
697 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
712 for (j
=0; j
<FRAMES
; j
++) {
713 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
714 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
717 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
718 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
722 for (j
=0; j
<FRAMES
; j
++) {
723 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
724 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
733 animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
,
734 int fx
, int fy
, int fw
, int fh
, int hiding
)
736 int style
= wPreferences
.iconification_style
; /* Catch the value */
739 if (style
== WIS_NONE
)
742 if (style
== WIS_RANDOM
) {
746 k
= (hiding
? 2 : 3);
749 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
)/3;
751 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
754 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
)/3;
756 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
760 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
)/3;
762 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
766 #endif /* ANIMATIONS */
774 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
775 WMHandleEvent(&tmpev
);
780 unmapTransientsFor(WWindow
*wwin
)
785 tmp
= wwin
->screen_ptr
->focused_window
;
787 /* unmap the transients for this transient */
788 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
789 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
790 || tmp
->flags
.shaded
)) {
791 unmapTransientsFor(tmp
);
792 tmp
->flags
.miniaturized
= 1;
793 if (!tmp
->flags
.shaded
) {
796 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
799 if (!tmp->flags.shaded)
801 wClientSetState(tmp
, IconicState
, None
);
803 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
811 mapTransientsFor(WWindow
*wwin
)
815 tmp
= wwin
->screen_ptr
->focused_window
;
817 /* recursively map the transients for this transient */
818 if (tmp
!=wwin
&& tmp
->transient_for
== wwin
->client_win
819 && /*!tmp->flags.mapped*/ tmp
->flags
.miniaturized
820 && tmp
->icon
==NULL
) {
821 mapTransientsFor(tmp
);
822 tmp
->flags
.miniaturized
= 0;
823 if (!tmp
->flags
.shaded
) {
826 XMapWindow(dpy
, tmp
->frame
->core
->window
);
828 tmp
->flags
.semi_focused
= 0;
830 if (!tmp->flags.shaded)
832 wClientSetState(tmp
, NormalState
, None
);
834 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
842 setupIconGrabs(WIcon
*icon
)
844 /* setup passive grabs on the icon */
845 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
846 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
847 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
848 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
849 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
850 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
856 recursiveTransientFor(WWindow
*wwin
)
863 /* hackish way to detect transient_for cycle */
864 i
= wwin
->screen_ptr
->window_count
+1;
866 while (wwin
&& wwin
->transient_for
!= None
&& i
>0) {
867 wwin
= wWindowFor(wwin
->transient_for
);
871 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
881 removeIconGrabs(WIcon
*icon
)
883 /* remove passive grabs on the icon */
884 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
885 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
886 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
893 wIconifyWindow(WWindow
*wwin
)
895 XWindowAttributes attribs
;
899 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
900 /* the window doesn't exist anymore */
904 if (wwin
->flags
.miniaturized
) {
908 if (wwin
->transient_for
!=None
&&
909 wwin
->transient_for
!=wwin
->screen_ptr
->root_win
) {
910 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
912 if (owner
&& owner
->flags
.miniaturized
)
916 present
= wwin
->frame
->workspace
==wwin
->screen_ptr
->current_workspace
;
918 /* if the window is in another workspace, simplify process */
920 /* icon creation may take a while */
921 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
922 ButtonMotionMask
|ButtonReleaseMask
, GrabModeAsync
,
923 GrabModeAsync
, None
, None
, CurrentTime
);
926 if (!wPreferences
.disable_miniwindows
) {
927 if (!wwin
->flags
.icon_moved
) {
928 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
);
930 wwin
->icon
= wIconCreate(wwin
);
932 wwin
->icon
->mapped
= 1;
935 wwin
->flags
.miniaturized
= 1;
936 wwin
->flags
.mapped
= 0;
938 /* unmap transients */
940 unmapTransientsFor(wwin
);
943 wSoundPlay(WSOUND_ICONIFY
);
945 XUngrabPointer(dpy
, CurrentTime
);
947 /* let all Expose events arrive so that we can repaint
948 * something before the animation starts (and the server is grabbed) */
951 if (wPreferences
.disable_miniwindows
)
952 wClientSetState(wwin
, IconicState
, None
);
954 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
958 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
959 && !wPreferences
.no_animations
) {
962 if (!wPreferences
.disable_miniwindows
) {
965 iw
= wwin
->icon
->core
->width
;
966 ih
= wwin
->icon
->core
->height
;
971 if (wKWMGetIconGeometry(wwin
, &area
)) {
977 #endif /* KWM_HINTS */
981 iw
= wwin
->screen_ptr
->scr_width
;
982 ih
= wwin
->screen_ptr
->scr_height
;
985 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
986 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
987 ix
, iy
, iw
, ih
, False
);
992 wwin
->flags
.skip_next_animation
= 0;
994 if (!wPreferences
.disable_miniwindows
) {
996 if (wwin
->screen_ptr
->current_workspace
==wwin
->frame
->workspace
||
997 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
999 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1001 AddToStackList(wwin
->icon
->core
);
1003 wLowerFrame(wwin
->icon
->core
);
1007 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1010 * It doesn't seem to be working and causes button event hangup
1011 * when deiconifying a transient window.
1012 setupIconGrabs(wwin->icon);
1014 if ((wwin
->flags
.focused
1015 || (owner
&& wwin
->client_win
== owner
->client_win
))
1016 && wPreferences
.focus_mode
==WKF_CLICK
) {
1021 if (!WFLAGP(tmp
, no_focusable
)
1022 && !(tmp
->flags
.hidden
||tmp
->flags
.miniaturized
)
1023 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1027 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1028 } else if (wPreferences
.focus_mode
!=WKF_CLICK
) {
1029 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1033 if (!wwin
->screen_ptr
->flags
.startup
) {
1034 Window clientwin
= wwin
->client_win
;
1037 processEvents(XPending(dpy
));
1039 /* the window can disappear while doing the processEvents() */
1040 if (!wWindowFor(clientwin
))
1047 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
)
1048 wIconSelect(wwin
->icon
);
1050 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1057 wDeiconifyWindow(WWindow
*wwin
)
1059 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1061 if (!wwin
->flags
.miniaturized
)
1064 if (wwin
->transient_for
!= None
1065 && wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1066 WWindow
*owner
= recursiveTransientFor(wwin
);
1068 if (owner
&& owner
->flags
.miniaturized
) {
1069 wDeiconifyWindow(owner
);
1070 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1071 wRaiseFrame(wwin
->frame
->core
);
1076 wwin
->flags
.miniaturized
= 0;
1077 if (!wwin
->flags
.shaded
)
1078 wwin
->flags
.mapped
= 1;
1080 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
) {
1081 if (wwin
->icon
->selected
)
1082 wIconSelect(wwin
->icon
);
1084 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1087 wSoundPlay(WSOUND_DEICONIFY
);
1089 /* if the window is in another workspace, do it silently */
1091 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1092 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1095 if (!wPreferences
.disable_miniwindows
) {
1098 iw
= wwin
->icon
->core
->width
;
1099 ih
= wwin
->icon
->core
->height
;
1104 if (wKWMGetIconGeometry(wwin
, &area
)) {
1110 #endif /* KWM_HINTS */
1114 iw
= wwin
->screen_ptr
->scr_width
;
1115 ih
= wwin
->screen_ptr
->scr_height
;
1118 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1119 wwin
->frame_x
, wwin
->frame_y
,
1120 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1123 #endif /* ANIMATIONS */
1124 wwin
->flags
.skip_next_animation
= 0;
1126 if (!wwin
->flags
.shaded
) {
1127 XMapWindow(dpy
, wwin
->client_win
);
1129 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1130 wRaiseFrame(wwin
->frame
->core
);
1131 if (!wwin
->flags
.shaded
) {
1132 wClientSetState(wwin
, NormalState
, None
);
1134 mapTransientsFor(wwin
);
1136 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
) {
1137 RemoveFromStackList(wwin
->icon
->core
);
1138 /* removeIconGrabs(wwin->icon);*/
1139 wIconDestroy(wwin
->icon
);
1144 if (wPreferences
.focus_mode
==WKF_CLICK
)
1145 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1148 if (!wwin
->screen_ptr
->flags
.startup
) {
1149 Window clientwin
= wwin
->client_win
;
1152 processEvents(XPending(dpy
));
1154 if (!wWindowFor(clientwin
))
1159 if (wPreferences
.auto_arrange_icons
) {
1160 wArrangeIcons(wwin
->screen_ptr
, True
);
1163 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1165 /* In case we were shaded and iconified, also unshade */
1166 wUnshadeWindow(wwin
);
1172 hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1174 if (wwin
->flags
.miniaturized
) {
1176 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1177 wwin
->icon
->mapped
= 0;
1179 wwin
->flags
.hidden
= 1;
1181 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1185 if (wwin
->flags
.inspector_open
) {
1186 wHideInspectorForWindow(wwin
);
1189 wwin
->flags
.hidden
= 1;
1192 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1194 wSoundPlay(WSOUND_HIDE
);
1196 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1197 !wwin
->flags
.skip_next_animation
&& animate
) {
1198 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1199 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1200 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
,
1204 wwin
->flags
.skip_next_animation
= 0;
1206 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1212 wHideOtherApplications(WWindow
*awin
)
1219 wwin
= awin
->screen_ptr
->focused_window
;
1224 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1225 && !(wwin
->flags
.miniaturized
||wwin
->flags
.hidden
)
1226 && !wwin
->flags
.internal_window
1227 && wGetWindowOfInspectorForWindow(wwin
) != awin
1228 && !WFLAGP(wwin
, no_hide_others
)) {
1230 if (wwin
->main_window
==None
|| WFLAGP(wwin
, no_appicon
)) {
1231 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1232 wwin
->flags
.skip_next_animation
= 1;
1233 wIconifyWindow(wwin
);
1235 } else if (wwin
->main_window
!=None
1236 && awin
->main_window
!= wwin
->main_window
) {
1237 tapp
= wApplicationOf(wwin
->main_window
);
1239 tapp
->flags
.skip_next_animation
= 1;
1240 wHideApplication(tapp
);
1242 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1243 wwin
->flags
.skip_next_animation
= 1;
1244 wIconifyWindow(wwin
);
1252 wSetFocusTo(awin->screen_ptr, awin);
1259 wHideApplication(WApplication
*wapp
)
1266 wwarning("trying to hide a non grouped window");
1269 if (!wapp
->main_window_desc
) {
1270 wwarning("group leader not found for window group");
1273 scr
= wapp
->main_window_desc
->screen_ptr
;
1275 wlist
= scr
->focused_window
;
1279 if (wlist
->main_window
== wapp
->main_window
)
1280 wapp
->last_focused
= wlist
;
1282 wapp
->last_focused
= NULL
;
1284 if (wlist
->main_window
== wapp
->main_window
) {
1285 if (wlist
->flags
.focused
) {
1289 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1290 wapp
->app_icon
->y_pos
, wlist
,
1291 !wapp
->flags
.skip_next_animation
);
1293 wlist
= wlist
->prev
;
1296 wapp
->flags
.skip_next_animation
= 0;
1299 if (wPreferences
.focus_mode
==WKF_CLICK
) {
1300 wlist
= scr
->focused_window
;
1302 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1303 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1305 wlist
= wlist
->prev
;
1307 wSetFocusTo(scr
, wlist
);
1309 wSetFocusTo(scr
, NULL
);
1313 wapp
->flags
.hidden
= 1;
1315 if(wPreferences
.auto_arrange_icons
) {
1316 wArrangeIcons(scr
, True
);
1320 wAppIconPaint(wapp
->app_icon
);
1328 unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
,
1329 int bringToCurrentWS
)
1331 if (bringToCurrentWS
)
1332 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1334 wwin
->flags
.hidden
=0;
1336 wSoundPlay(WSOUND_UNHIDE
);
1338 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1340 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1341 icon
->core
->width
, icon
->core
->height
,
1342 wwin
->frame_x
, wwin
->frame_y
,
1343 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1347 wwin
->flags
.skip_next_animation
= 0;
1348 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1349 XMapWindow(dpy
, wwin
->client_win
);
1350 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1351 wClientSetState(wwin
, NormalState
, None
);
1352 wwin
->flags
.mapped
=1;
1353 wRaiseFrame(wwin
->frame
->core
);
1355 if (wwin
->flags
.inspector_open
) {
1356 wUnhideInspectorForWindow(wwin
);
1359 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1364 wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1367 WWindow
*wlist
, *next
;
1368 WWindow
*focused
=NULL
;
1373 scr
= wapp
->main_window_desc
->screen_ptr
;
1374 wlist
= scr
->focused_window
;
1376 /* goto beginning of list */
1378 wlist
= wlist
->prev
;
1383 if (wlist
->main_window
== wapp
->main_window
) {
1384 if (wlist
->flags
.focused
)
1386 else if (!focused
|| !focused
->flags
.focused
)
1389 if (wlist
->flags
.miniaturized
&& wlist
->icon
) {
1390 if (bringToCurrentWS
|| wPreferences
.sticky_icons
1391 || wlist
->frame
->workspace
== scr
->current_workspace
) {
1392 if (!wlist
->icon
->mapped
) {
1393 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1394 wlist
->icon
->mapped
= 1;
1396 wlist
->flags
.hidden
= 0;
1398 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1400 if (wlist
->frame
->workspace
!= scr
->current_workspace
)
1401 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1404 wDeiconifyWindow(wlist
);
1406 } else if (wlist
->flags
.hidden
) {
1407 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1408 wapp
->app_icon
->y_pos
, wlist
,
1409 !wapp
->flags
.skip_next_animation
,
1412 if (bringToCurrentWS
1413 && wlist
->frame
->workspace
!= scr
->current_workspace
) {
1414 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1416 wRaiseFrame(wlist
->frame
->core
);
1422 wapp
->flags
.skip_next_animation
= 0;
1423 wapp
->flags
.hidden
= 0;
1426 wSetFocusTo(scr
, focused
);
1427 else if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
)
1428 wSetFocusTo(scr
, wapp
->last_focused
);
1429 wapp
->last_focused
= NULL
;
1430 if (wPreferences
.auto_arrange_icons
) {
1431 wArrangeIcons(scr
, True
);
1434 wAppIconPaint(wapp
->app_icon
);
1441 wShowAllWindows(WScreen
*scr
)
1443 WWindow
*wwin
, *old_foc
;
1446 old_foc
= wwin
= scr
->focused_window
;
1448 if (!wwin
->flags
.internal_window
&&
1449 (scr
->current_workspace
== wwin
->frame
->workspace
1450 || IS_OMNIPRESENT(wwin
))) {
1451 if (wwin
->flags
.miniaturized
) {
1452 wwin
->flags
.skip_next_animation
= 1;
1453 wDeiconifyWindow(wwin
);
1454 } else if (wwin
->flags
.hidden
) {
1455 wapp
= wApplicationOf(wwin
->main_window
);
1457 wUnhideApplication(wapp
, False
, False
);
1459 wwin
->flags
.skip_next_animation
= 1;
1460 wDeiconifyWindow(wwin
);
1466 wSetFocusTo(scr
, old_foc
);
1467 /*wRaiseFrame(old_foc->frame->core);*/
1472 wRefreshDesktop(WScreen
*scr
)
1475 XSetWindowAttributes attr
;
1477 attr
.backing_store
= NotUseful
;
1478 attr
.save_under
= False
;
1479 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1480 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1481 (Visual
*)CopyFromParent
, CWBackingStore
|CWSaveUnder
,
1483 XMapRaised(dpy
, win
);
1484 XDestroyWindow(dpy
, win
);
1490 wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1494 int pf
; /* primary axis */
1495 int sf
; /* secondary axis */
1499 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1503 int isize
= wPreferences
.icon_size
;
1506 * Find out screen boundaries.
1510 * Allows each head to have miniwindows
1512 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1516 sw
= rect
.size
.width
;
1517 sh
= rect
.size
.height
;
1521 if (scr
->dock
->on_right_side
)
1522 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1524 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1528 sw
= isize
* (scr
->scr_width
/isize
);
1529 sh
= isize
* (scr
->scr_height
/isize
);
1531 sw
= isize
* (sw
/isize
);
1532 sh
= isize
* (sh
/isize
);
1534 fullW
= (sx2
-sx1
)/isize
;
1535 fullW
= (sx2
-sx1
)/isize
;
1536 fullH
= (sy2
-sy1
)/isize
;
1538 /* icon yard boundaries */
1539 if (wPreferences
.icon_yard
& IY_VERT
) {
1546 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1553 if (wPreferences
.icon_yard
& IY_TOP
) {
1561 /* arrange icons putting the most recently focused window
1562 * as the last icon */
1563 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1564 : xo + xs*(pi*isize))
1565 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1566 : yo + ys*(si*isize))
1568 /* arrange application icons */
1569 aicon
= scr
->app_icon_list
;
1570 /* reverse them to avoid unnecessarily sliding of icons */
1571 while (aicon
&& aicon
->next
)
1572 aicon
= aicon
->next
;
1577 if (!aicon
->docked
) {
1578 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1580 if (!wPreferences
.no_animations
) {
1581 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
,
1584 #endif /* ANIMATIONS */
1586 wAppIconMove(aicon
, X
, Y
);
1589 /* we reversed the order so we use prev */
1590 aicon
= aicon
->prev
;
1597 /* arrange miniwindows */
1599 wwin
= scr
->focused_window
;
1600 /* reverse them to avoid unnecessarily shuffling */
1601 while (wwin
&& wwin
->prev
)
1605 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1606 (wwin
->frame
->workspace
==scr
->current_workspace
||
1607 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1609 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1610 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1612 if (wPreferences
.no_animations
) {
1613 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1615 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1616 wwin
->icon_y
, X
, Y
);
1619 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1620 #endif /* ANIMATIONS */
1628 wwin
->flags
.icon_moved
= 0;
1630 /* we reversed the order, so we use next */
1641 wSelectWindow(WWindow
*wwin
, Bool flag
)
1643 WScreen
*scr
= wwin
->screen_ptr
;
1646 wwin
->flags
.selected
= 1;
1647 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1649 if (WFLAGP(wwin
, no_border
)) {
1650 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
,
1651 FRAME_BORDER_WIDTH
);
1654 if (!scr
->selected_windows
)
1655 scr
->selected_windows
= WMCreateArray(4);
1656 WMAddToArray(scr
->selected_windows
, wwin
);
1658 wwin
->flags
.selected
= 0;
1659 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
,
1660 scr
->frame_border_pixel
);
1662 if (WFLAGP(wwin
, no_border
)) {
1663 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1666 if (scr
->selected_windows
) {
1667 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1674 wMakeWindowVisible(WWindow
*wwin
)
1676 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1677 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1679 if (wwin
->flags
.shaded
) {
1680 wUnshadeWindow(wwin
);
1682 if (wwin
->flags
.hidden
) {
1685 app
= wApplicationOf(wwin
->main_window
);
1687 wUnhideApplication(app
, False
, False
);
1688 } else if (wwin
->flags
.miniaturized
) {
1689 wDeiconifyWindow(wwin
);
1691 if (!WFLAGP(wwin
, no_focusable
))
1692 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1693 wRaiseFrame(wwin
->frame
->core
);