1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 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,
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
41 #include "application.h"
47 #include "winspector.h"
48 #include "workspace.h"
52 /****** Global Variables ******/
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
56 extern Cursor wCursor
[WCUR_LAST
];
58 extern WPreferences wPreferences
;
60 extern Atom _XA_WM_TAKE_FOCUS
;
62 extern void ProcessPendingEvents();
63 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
65 /******* Local Variables *******/
71 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
72 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
73 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
74 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
75 SHADE_STEPS_US
, SHADE_DELAY_US
}};
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
82 static int compareTimes(Time t1
, Time t2
)
88 return (diff
< 60000) ? 1 : -1;
92 *----------------------------------------------------------------------
94 * Changes the window focus to the one passed as argument.
95 * If the window to focus is not already focused, it will be brought
96 * to the head of the list of windows. Previously focused window is
100 * Window list may be reordered and the window focus is changed.
102 *----------------------------------------------------------------------
104 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
106 static WScreen
*old_scr
= NULL
;
108 WWindow
*old_focused
;
109 WWindow
*focused
= scr
->focused_window
;
110 Time timestamp
= LastTimestamp
;
111 WApplication
*oapp
= NULL
, *napp
= NULL
;
114 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
119 old_focused
= old_scr
->focused_window
;
121 LastFocusChange
= timestamp
;
124 oapp
= wApplicationOf(old_focused
->main_window
);
127 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
129 wWindowUnfocus(old_focused
);
132 wAppMenuUnmap(oapp
->menu
);
134 wApplicationDeactivate(oapp
);
138 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
140 } else if (old_scr
!= scr
&& old_focused
) {
141 wWindowUnfocus(old_focused
);
144 wasfocused
= wwin
->flags
.focused
;
145 napp
= wApplicationOf(wwin
->main_window
);
147 /* remember last workspace where the app has been */
149 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
150 napp
->last_workspace
= wwin
->frame
->workspace
;
153 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
154 /* install colormap if colormap mode is lock mode */
155 if (wPreferences
.colormap_mode
== WCM_CLICK
)
156 wColormapInstallForWindow(scr
, wwin
);
158 /* set input focus */
159 switch (wwin
->focus_mode
) {
161 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
165 case WFM_LOCALLY_ACTIVE
:
166 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
169 case WFM_GLOBALLY_ACTIVE
:
173 if (wwin
->protocols
.TAKE_FOCUS
) {
174 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
178 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
180 if (WFLAGP(wwin
, no_focusable
))
183 /* if this is not the focused window focus it */
184 if (focused
!= wwin
) {
185 /* change the focus window list order */
187 wwin
->prev
->next
= wwin
->next
;
190 wwin
->next
->prev
= wwin
->prev
;
192 wwin
->prev
= focused
;
193 focused
->next
= wwin
;
195 scr
->focused_window
= wwin
;
197 if (oapp
&& oapp
!= napp
) {
198 wAppMenuUnmap(oapp
->menu
);
200 wApplicationDeactivate(oapp
);
205 wWindowFocus(wwin
, focused
);
207 if (napp
&& !wasfocused
) {
209 wUserMenuRefreshInstances(napp
->menu
, wwin
);
210 #endif /* USER_MENU */
212 if (wwin
->flags
.mapped
)
213 wAppMenuMap(napp
->menu
, wwin
);
215 wApplicationActivate(napp
);
223 void wShadeWindow(WWindow
*wwin
)
226 if (wwin
->flags
.shaded
)
229 XLowerWindow(dpy
, wwin
->client_win
);
230 wSoundPlay(WSOUND_SHADE
);
231 shade_animate(wwin
, SHADE
);
233 wwin
->flags
.skip_next_animation
= 0;
234 wwin
->flags
.shaded
= 1;
235 wwin
->flags
.mapped
= 0;
236 /* prevent window withdrawal when getting UnmapNotify */
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
238 XUnmapWindow(dpy
, wwin
->client_win
);
239 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
241 /* for the client it's just like iconification */
242 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
244 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
245 wWindowSynthConfigureNotify(wwin
);
248 wClientSetState(wwin, IconicState, None);
251 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
254 if (!wwin
->screen_ptr
->flags
.startup
) {
255 /* Catch up with events not processed while animation was running */
256 ProcessPendingEvents();
261 void wUnshadeWindow(WWindow
*wwin
)
264 if (!wwin
->flags
.shaded
)
267 wwin
->flags
.shaded
= 0;
268 wwin
->flags
.mapped
= 1;
269 XMapWindow(dpy
, wwin
->client_win
);
271 wSoundPlay(WSOUND_UNSHADE
);
272 shade_animate(wwin
, UNSHADE
);
274 wwin
->flags
.skip_next_animation
= 0;
275 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
276 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
278 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
279 wWindowSynthConfigureNotify(wwin
);
282 wClientSetState(wwin, NormalState, None);
284 /* if the window is focused, set the focus again as it was disabled during
286 if (wwin
->flags
.focused
)
287 wSetFocusTo(wwin
->screen_ptr
, wwin
);
289 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
292 /* Set the old coordinates using the current values */
293 static void save_old_geometry(WWindow
*wwin
)
295 wwin
->old_geometry
.width
= wwin
->client
.width
;
296 wwin
->old_geometry
.height
= wwin
->client
.height
;
297 wwin
->old_geometry
.x
= wwin
->frame_x
;
298 wwin
->old_geometry
.y
= wwin
->frame_y
;
301 void wMaximizeWindow(WWindow
* wwin
, int directions
)
304 unsigned int new_width
, new_height
, half_scr_width
;
305 WArea usableArea
, totalArea
;
309 if (!IS_RESIZABLE(wwin
))
312 if (!HAS_BORDER(wwin
))
315 /* the size to adjust the geometry */
316 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
318 /* save old coordinates before we change the current values */
319 save_old_geometry(wwin
);
323 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
324 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
325 usableArea
= totalArea
;
327 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
328 WScreen
*scr
= wwin
->screen_ptr
;
331 if (directions
& MAX_KEYBOARD
)
332 head
= wGetHeadForWindow(wwin
);
334 head
= wGetHeadForPointerLocation(scr
);
336 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
339 /* Only save directions, not kbd or xinerama hints */
340 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
342 if (WFLAGP(wwin
, full_maximize
)) {
343 usableArea
= totalArea
;
345 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
347 if (wwin
->flags
.shaded
) {
348 wwin
->flags
.skip_next_animation
= 1;
349 wUnshadeWindow(wwin
);
352 if (directions
& MAX_HORIZONTAL
) {
353 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
354 new_x
= usableArea
.x1
;
355 } else if (directions
& MAX_LEFTHALF
) {
356 new_width
= half_scr_width
- adj_size
;
357 new_x
= usableArea
.x1
;
358 } else if (directions
& MAX_RIGHTHALF
) {
359 new_width
= half_scr_width
- adj_size
;
360 new_x
= usableArea
.x1
+ half_scr_width
;
362 new_x
= wwin
->frame_x
;
363 new_width
= wwin
->frame
->core
->width
;
366 if (directions
& MAX_VERTICAL
) {
367 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
368 new_y
= usableArea
.y1
;
369 if (WFLAGP(wwin
, full_maximize
)) {
370 new_y
-= wwin
->frame
->top_width
;
371 new_height
+= wwin
->frame
->bottom_width
- 1;
374 new_y
= wwin
->frame_y
;
375 new_height
= wwin
->frame
->core
->height
;
378 if (!WFLAGP(wwin
, full_maximize
)) {
379 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
382 if (directions
& MAX_MAXIMUS
) {
383 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
384 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
385 new_y
-= wwin
->frame
->top_width
;
386 new_height
+= wwin
->frame
->top_width
- 1;
390 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
392 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
393 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
395 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
397 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
399 wSoundPlay(WSOUND_MAXIMIZE
);
400 /* set maximization state */
401 wwin
->flags
.maximized
= directions
;
405 * Maximus: tiled maximization (maximize without overlapping other windows)
407 * The window to be maximized will be denoted by w_0 (sub-index zero)
408 * while the windows which will stop the maximization of w_0 are denoted by w_j.
410 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
411 unsigned int *new_width
, unsigned int *new_height
)
414 int x_0
= wwin
->frame_x
;
415 int y_0
= wwin
->frame_y
;
416 int width_0
= wwin
->frame
->core
->width
;
417 int height_0
= wwin
->frame
->core
->height
;
418 int botton_0
= y_0
+ height_0
;
419 int right_border_0
= x_0
+ width_0
;
420 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
421 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
422 int x_intsect
, y_intsect
;
423 /* Assume that the window w_0 has titlebar etc */
424 int has_titlebar
= 1, has_resizebar
= 1, has_border
= 1;
425 int adjust_height
, adjust_width
;
427 /* Try to fully maximize first, then readjust later */
428 new_x_0
= usableArea
.x1
;
429 new_y_0
= usableArea
.y1
;
430 new_botton_0
= usableArea
.y2
;
431 new_right_border_0
= usableArea
.x2
;
433 if (!HAS_TITLEBAR(wwin
))
435 if (!HAS_RESIZEBAR(wwin
))
437 if (!HAS_BORDER(wwin
))
440 /* the lengths to be subtracted if w_0 has titlebar, etc */
441 adjust_height
= TITLEBAR_HEIGHT
* has_titlebar
442 + 2 * FRAME_BORDER_WIDTH
* has_border
+ RESIZEBAR_HEIGHT
* has_resizebar
;
443 adjust_width
= 2 * FRAME_BORDER_WIDTH
* has_border
;
446 /* TODO: Is the focused window always the last in the list? */
448 /* ignore windows in other workspaces or minimized */
449 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
450 || tmp
->prev
->flags
.miniaturized
) {
456 /* set the w_j window coordinates */
459 width_j
= tmp
->frame
->core
->width
;
460 height_j
= tmp
->frame
->core
->height
;
461 botton_j
= y_j
+ height_j
;
463 right_border_j
= x_j
+ width_j
;
465 /* Try to maximize in the y direction first */
466 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
467 if (x_intsect
!= 0) {
468 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
469 /* w_0 is below the botton of w_j */
472 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
473 /* The botton of w_0 is above the top of w_j */
474 new_botton_0
= top_j
;
481 /* ignore windows in other workspaces or minimized */
482 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
483 || tmp
->prev
->flags
.miniaturized
) {
489 /* set the w_j window coordinates */
492 width_j
= tmp
->frame
->core
->width
;
493 height_j
= tmp
->frame
->core
->height
;
494 botton_j
= y_j
+ height_j
;
496 right_border_j
= x_j
+ width_j
;
499 * Use the updated y coordinates from the above step to account
500 * the possibility that the new value of y_0 will have different
501 * intersections with w_j
503 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
504 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
505 if (y_intsect
!= 0) {
506 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
507 /* w_0 is completely to the right of w_j */
508 new_x_0
= right_border_j
;
510 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
511 /* w_0 is completely to the left of w_j */
512 new_right_border_0
= x_j
;
517 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
520 *new_height
= new_height_0
;
521 *new_width
= new_right_border_0
- new_x_0
- adjust_width
;
524 void wUnmaximizeWindow(WWindow
* wwin
)
527 WMRect old_geom_rect
;
531 if (!wwin
->flags
.maximized
)
534 if (wwin
->flags
.shaded
) {
535 wwin
->flags
.skip_next_animation
= 1;
536 wUnshadeWindow(wwin
);
538 /* Use old coordinates if they are set, current values otherwise */
539 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
540 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
541 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
542 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
543 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
544 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
545 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
547 wwin
->flags
.maximized
= 0;
548 wWindowConfigure(wwin
, x
, y
, w
, h
);
550 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
552 wSoundPlay(WSOUND_UNMAXIMIZE
);
555 void wFullscreenWindow(WWindow
* wwin
)
560 if (wwin
->flags
.fullscreen
)
563 wwin
->flags
.fullscreen
= True
;
565 wWindowConfigureBorders(wwin
);
567 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
569 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
570 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
571 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
572 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
574 head
= wGetHeadForWindow(wwin
);
575 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
576 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
578 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
581 void wUnfullscreenWindow(WWindow
* wwin
)
583 if (!wwin
->flags
.fullscreen
)
586 wwin
->flags
.fullscreen
= False
;
588 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
589 if (WFLAGP(wwin
, sunken
)) {
590 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
591 } else if (WFLAGP(wwin
, floating
)) {
592 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
594 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
598 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
599 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
601 wWindowConfigureBorders(wwin
);
603 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
604 wFrameWindowPaint(wwin->frame);
607 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
611 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
613 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
614 float cx
, cy
, cw
, ch
;
615 float xstep
, ystep
, wstep
, hstep
;
618 float angle
, final_angle
, delta
;
620 xstep
= (float)(fx
- x
) / steps
;
621 ystep
= (float)(fy
- y
) / steps
;
622 wstep
= (float)(fw
- w
) / steps
;
623 hstep
= (float)(fh
- h
) / steps
;
630 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
631 delta
= (float)(final_angle
/ FRAMES
);
632 for (angle
= 0;; angle
+= delta
) {
633 if (angle
> final_angle
)
636 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
637 dch
= (ch
/ 2) * cos(angle
);
638 midy
= cy
+ (ch
/ 2);
640 points
[0].x
= cx
+ dx
;
641 points
[0].y
= midy
- dch
;
642 points
[1].x
= cx
+ cw
- dx
;
643 points
[1].y
= points
[0].y
;
644 points
[2].x
= cx
+ cw
+ dx
;
645 points
[2].y
= midy
+ dch
;
646 points
[3].x
= cx
- dx
;
647 points
[3].y
= points
[2].y
;
648 points
[4].x
= points
[0].x
;
649 points
[4].y
= points
[0].y
;
652 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
654 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
655 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
660 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
666 if (angle
>= final_angle
)
676 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
678 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
679 float cx
, cy
, cw
, ch
;
680 float xstep
, ystep
, wstep
, hstep
;
682 float angle
, final_angle
, a
, d
, delta
;
689 xstep
= (float)(fx
- x
) / steps
;
690 ystep
= (float)(fy
- y
) / steps
;
691 wstep
= (float)(fw
- w
) / steps
;
692 hstep
= (float)(fh
- h
) / steps
;
699 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
700 delta
= (float)(final_angle
/ FRAMES
);
701 for (angle
= 0;; angle
+= delta
) {
702 if (angle
> final_angle
)
706 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
708 points
[0].x
= cx
+ cos(angle
- a
) * d
;
709 points
[0].y
= cy
+ sin(angle
- a
) * d
;
710 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
711 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
712 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
713 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
714 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
715 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
716 points
[4].x
= cx
+ cos(angle
- a
) * d
;
717 points
[4].y
= cy
+ sin(angle
- a
) * d
;
719 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
721 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
722 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
727 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
733 if (angle
>= final_angle
)
742 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
744 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
745 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
746 float xstep
, ystep
, wstep
, hstep
;
749 xstep
= (float)(fx
- x
) / steps
;
750 ystep
= (float)(fy
- y
) / steps
;
751 wstep
= (float)(fw
- w
) / steps
;
752 hstep
= (float)(fh
- h
) / steps
;
754 for (j
= 0; j
< FRAMES
; j
++) {
761 for (i
= 0; i
< steps
; i
++) {
762 for (j
= 0; j
< FRAMES
; j
++) {
763 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
764 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
767 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
768 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
772 for (j
= 0; j
< FRAMES
; j
++) {
773 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
774 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
775 if (j
< FRAMES
- 1) {
789 for (j
= 0; j
< FRAMES
; j
++) {
790 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
793 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
794 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
798 for (j
= 0; j
< FRAMES
; j
++) {
799 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
807 void animateResize(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int hiding
)
809 int style
= wPreferences
.iconification_style
; /* Catch the value */
812 if (style
== WIS_NONE
)
815 if (style
== WIS_RANDOM
) {
819 k
= (hiding
? 2 : 3);
823 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
) / 3;
825 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
828 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
) / 3;
830 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
834 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
) / 3;
836 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
840 #endif /* ANIMATIONS */
842 static void flushExpose()
846 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
847 WMHandleEvent(&tmpev
);
851 static void unmapTransientsFor(WWindow
* wwin
)
855 tmp
= wwin
->screen_ptr
->focused_window
;
857 /* unmap the transients for this transient */
858 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
859 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
860 unmapTransientsFor(tmp
);
861 tmp
->flags
.miniaturized
= 1;
862 if (!tmp
->flags
.shaded
) {
865 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
868 if (!tmp->flags.shaded)
870 wClientSetState(tmp
, IconicState
, None
);
872 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
878 static void mapTransientsFor(WWindow
* wwin
)
882 tmp
= wwin
->screen_ptr
->focused_window
;
884 /* recursively map the transients for this transient */
885 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
886 && tmp
->icon
== NULL
) {
887 mapTransientsFor(tmp
);
888 tmp
->flags
.miniaturized
= 0;
889 if (!tmp
->flags
.shaded
) {
892 XMapWindow(dpy
, tmp
->frame
->core
->window
);
894 tmp
->flags
.semi_focused
= 0;
896 if (!tmp->flags.shaded)
898 wClientSetState(tmp
, NormalState
, None
);
900 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
907 static void setupIconGrabs(WIcon
* icon
)
909 /* setup passive grabs on the icon */
910 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
911 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
912 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
913 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
914 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
915 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
920 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
927 /* hackish way to detect transient_for cycle */
928 i
= wwin
->screen_ptr
->window_count
+ 1;
930 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
931 wwin
= wWindowFor(wwin
->transient_for
);
934 if (i
== 0 && wwin
) {
935 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
943 static void removeIconGrabs(WIcon
* icon
)
945 /* remove passive grabs on the icon */
946 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
947 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
948 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
953 void wIconifyWindow(WWindow
* wwin
)
955 XWindowAttributes attribs
;
958 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
959 /* the window doesn't exist anymore */
963 if (wwin
->flags
.miniaturized
) {
967 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
968 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
970 if (owner
&& owner
->flags
.miniaturized
)
974 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
976 /* if the window is in another workspace, simplify process */
978 /* icon creation may take a while */
979 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
980 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
981 GrabModeAsync
, None
, None
, CurrentTime
);
984 if (!wPreferences
.disable_miniwindows
986 && !wwin
->flags
.net_handle_icon
989 if (!wwin
->flags
.icon_moved
) {
990 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
992 wwin
->icon
= wIconCreate(wwin
);
994 wwin
->icon
->mapped
= 1;
997 wwin
->flags
.miniaturized
= 1;
998 wwin
->flags
.mapped
= 0;
1000 /* unmap transients */
1002 unmapTransientsFor(wwin
);
1005 wSoundPlay(WSOUND_ICONIFY
);
1007 XUngrabPointer(dpy
, CurrentTime
);
1009 /* let all Expose events arrive so that we can repaint
1010 * something before the animation starts (and the server is grabbed) */
1013 if (wPreferences
.disable_miniwindows
1015 || wwin
->flags
.net_handle_icon
1018 wClientSetState(wwin
, IconicState
, None
);
1020 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1024 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1025 && !wPreferences
.no_animations
) {
1028 if (!wPreferences
.disable_miniwindows
1030 && !wwin
->flags
.net_handle_icon
1035 iw
= wwin
->icon
->core
->width
;
1036 ih
= wwin
->icon
->core
->height
;
1039 if (wwin
->flags
.net_handle_icon
) {
1049 iw
= wwin
->screen_ptr
->scr_width
;
1050 ih
= wwin
->screen_ptr
->scr_height
;
1053 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1054 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
, False
);
1059 wwin
->flags
.skip_next_animation
= 0;
1061 if (!wPreferences
.disable_miniwindows
1063 && !wwin
->flags
.net_handle_icon
1067 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1068 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1070 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1072 AddToStackList(wwin
->icon
->core
);
1074 wLowerFrame(wwin
->icon
->core
);
1078 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1081 * It doesn't seem to be working and causes button event hangup
1082 * when deiconifying a transient window.
1083 setupIconGrabs(wwin->icon);
1085 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1086 && wPreferences
.focus_mode
== WKF_CLICK
) {
1091 if (!WFLAGP(tmp
, no_focusable
)
1092 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1093 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1097 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1098 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1099 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1102 if (!wwin
->screen_ptr
->flags
.startup
) {
1103 /* Catch up with events not processed while animation was running */
1104 Window clientwin
= wwin
->client_win
;
1106 ProcessPendingEvents();
1108 /* the window can disappear while ProcessPendingEvents() runs */
1109 if (!wWindowFor(clientwin
)) {
1116 /* maybe we want to do this regardless of net_handle_icon
1117 * it seems to me we might break behaviour this way.
1119 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1121 && !wwin
->flags
.net_handle_icon
1124 wIconSelect(wwin
->icon
);
1126 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1128 if (wPreferences
.auto_arrange_icons
)
1129 wArrangeIcons(wwin
->screen_ptr
, True
);
1132 void wDeiconifyWindow(WWindow
* wwin
)
1135 /* we're hiding for show_desktop */
1136 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1137 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1139 int netwm_hidden
= False
;
1143 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1145 if (!wwin
->flags
.miniaturized
)
1148 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1149 WWindow
*owner
= recursiveTransientFor(wwin
);
1151 if (owner
&& owner
->flags
.miniaturized
) {
1152 wDeiconifyWindow(owner
);
1153 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1154 wRaiseFrame(wwin
->frame
->core
);
1159 wwin
->flags
.miniaturized
= 0;
1161 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1162 wwin
->flags
.mapped
= 1;
1165 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1166 /* maybe we want to do this regardless of net_handle_icon
1167 * it seems to me we might break behaviour this way.
1169 if (!wPreferences
.disable_miniwindows
1171 && !wwin
->flags
.net_handle_icon
1173 && wwin
->icon
!= NULL
) {
1174 if (wwin
->icon
->selected
)
1175 wIconSelect(wwin
->icon
);
1177 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1182 wSoundPlay(WSOUND_DEICONIFY
);
1184 /* if the window is in another workspace, do it silently */
1185 if (!netwm_hidden
) {
1187 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1188 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1191 if (!wPreferences
.disable_miniwindows
1193 && !wwin
->flags
.net_handle_icon
1198 iw
= wwin
->icon
->core
->width
;
1199 ih
= wwin
->icon
->core
->height
;
1202 if (wwin
->flags
.net_handle_icon
) {
1212 iw
= wwin
->screen_ptr
->scr_width
;
1213 ih
= wwin
->screen_ptr
->scr_height
;
1216 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1217 wwin
->frame_x
, wwin
->frame_y
,
1218 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, False
);
1220 #endif /* ANIMATIONS */
1221 wwin
->flags
.skip_next_animation
= 0;
1223 if (!wwin
->flags
.shaded
) {
1224 XMapWindow(dpy
, wwin
->client_win
);
1226 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1227 wRaiseFrame(wwin
->frame
->core
);
1228 if (!wwin
->flags
.shaded
) {
1229 wClientSetState(wwin
, NormalState
, None
);
1231 mapTransientsFor(wwin
);
1234 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1236 && !wwin
->flags
.net_handle_icon
1239 RemoveFromStackList(wwin
->icon
->core
);
1240 /* removeIconGrabs(wwin->icon); */
1241 wIconDestroy(wwin
->icon
);
1245 if (!netwm_hidden
) {
1248 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1251 if (!wwin
->screen_ptr
->flags
.startup
) {
1252 /* Catch up with events not processed while animation was running */
1253 Window clientwin
= wwin
->client_win
;
1255 ProcessPendingEvents();
1257 /* the window can disappear while ProcessPendingEvents() runs */
1258 if (!wWindowFor(clientwin
)) {
1265 if (wPreferences
.auto_arrange_icons
) {
1266 wArrangeIcons(wwin
->screen_ptr
, True
);
1269 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1271 /* In case we were shaded and iconified, also unshade */
1273 wUnshadeWindow(wwin
);
1276 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1278 if (wwin
->flags
.miniaturized
) {
1280 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1281 wwin
->icon
->mapped
= 0;
1283 wwin
->flags
.hidden
= 1;
1285 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1289 if (wwin
->flags
.inspector_open
) {
1290 wHideInspectorForWindow(wwin
);
1293 wwin
->flags
.hidden
= 1;
1296 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1298 wSoundPlay(WSOUND_HIDE
);
1300 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1301 !wwin
->flags
.skip_next_animation
&& animate
) {
1302 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1303 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1304 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
, True
);
1307 wwin
->flags
.skip_next_animation
= 0;
1309 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1312 void wHideOtherApplications(WWindow
* awin
)
1319 wwin
= awin
->screen_ptr
->focused_window
;
1323 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1324 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1325 && !wwin
->flags
.internal_window
1326 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1328 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1329 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1330 wwin
->flags
.skip_next_animation
= 1;
1331 wIconifyWindow(wwin
);
1333 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1334 tapp
= wApplicationOf(wwin
->main_window
);
1336 tapp
->flags
.skip_next_animation
= 1;
1337 wHideApplication(tapp
);
1339 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1340 wwin
->flags
.skip_next_animation
= 1;
1341 wIconifyWindow(wwin
);
1349 wSetFocusTo(awin->screen_ptr, awin);
1353 void wHideApplication(WApplication
* wapp
)
1361 wwarning("trying to hide a non grouped window");
1364 if (!wapp
->main_window_desc
) {
1365 wwarning("group leader not found for window group");
1368 scr
= wapp
->main_window_desc
->screen_ptr
;
1370 wlist
= scr
->focused_window
;
1374 if (wlist
->main_window
== wapp
->main_window
)
1375 wapp
->last_focused
= wlist
;
1377 wapp
->last_focused
= NULL
;
1379 animate
= !wapp
->flags
.skip_next_animation
;
1382 if (wlist
->main_window
== wapp
->main_window
) {
1383 if (wlist
->flags
.focused
) {
1386 if (wapp
->app_icon
) {
1387 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1388 wapp
->app_icon
->y_pos
, wlist
, animate
);
1392 wlist
= wlist
->prev
;
1395 wapp
->flags
.skip_next_animation
= 0;
1398 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1399 wlist
= scr
->focused_window
;
1401 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1402 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1404 wlist
= wlist
->prev
;
1406 wSetFocusTo(scr
, wlist
);
1408 wSetFocusTo(scr
, NULL
);
1412 wapp
->flags
.hidden
= 1;
1414 if (wPreferences
.auto_arrange_icons
) {
1415 wArrangeIcons(scr
, True
);
1419 wAppIconPaint(wapp
->app_icon
);
1423 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1425 if (bringToCurrentWS
)
1426 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1428 wwin
->flags
.hidden
= 0;
1430 wSoundPlay(WSOUND_UNHIDE
);
1432 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1433 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1434 icon
->core
->width
, icon
->core
->height
,
1435 wwin
->frame_x
, wwin
->frame_y
,
1436 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, True
);
1439 wwin
->flags
.skip_next_animation
= 0;
1440 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1441 XMapWindow(dpy
, wwin
->client_win
);
1442 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1443 wClientSetState(wwin
, NormalState
, None
);
1444 wwin
->flags
.mapped
= 1;
1445 wRaiseFrame(wwin
->frame
->core
);
1447 if (wwin
->flags
.inspector_open
) {
1448 wUnhideInspectorForWindow(wwin
);
1451 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1454 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1457 WWindow
*wlist
, *next
;
1458 WWindow
*focused
= NULL
;
1464 scr
= wapp
->main_window_desc
->screen_ptr
;
1465 wlist
= scr
->focused_window
;
1469 /* goto beginning of list */
1471 wlist
= wlist
->prev
;
1473 animate
= !wapp
->flags
.skip_next_animation
;
1478 if (wlist
->main_window
== wapp
->main_window
) {
1479 if (wlist
->flags
.focused
)
1481 else if (!focused
|| !focused
->flags
.focused
)
1484 if (wlist
->flags
.miniaturized
) {
1485 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1486 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1487 if (!wlist
->icon
->mapped
) {
1490 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1491 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1492 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1496 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1497 wlist
->icon
->mapped
= 1;
1499 wRaiseFrame(wlist
->icon
->core
);
1501 if (bringToCurrentWS
)
1502 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1503 wlist
->flags
.hidden
= 0;
1504 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1505 wDeiconifyWindow(wlist
);
1507 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1508 } else if (wlist
->flags
.shaded
) {
1509 if (bringToCurrentWS
)
1510 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1511 wlist
->flags
.hidden
= 0;
1512 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1513 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1515 wUnshadeWindow(wlist
);
1516 wRaiseFrame(wlist
->frame
->core
);
1519 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1520 } else if (wlist
->flags
.hidden
) {
1521 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1522 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1525 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1526 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1528 wRaiseFrame(wlist
->frame
->core
);
1534 wapp
->flags
.skip_next_animation
= 0;
1535 wapp
->flags
.hidden
= 0;
1537 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1538 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1539 wSetFocusTo(scr
, wapp
->last_focused
);
1540 } else if (focused
) {
1541 wSetFocusTo(scr
, focused
);
1543 wapp
->last_focused
= NULL
;
1544 if (wPreferences
.auto_arrange_icons
) {
1545 wArrangeIcons(scr
, True
);
1548 wAppIconPaint(wapp
->app_icon
);
1552 void wShowAllWindows(WScreen
* scr
)
1554 WWindow
*wwin
, *old_foc
;
1557 old_foc
= wwin
= scr
->focused_window
;
1559 if (!wwin
->flags
.internal_window
&&
1560 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1561 if (wwin
->flags
.miniaturized
) {
1562 wwin
->flags
.skip_next_animation
= 1;
1563 wDeiconifyWindow(wwin
);
1564 } else if (wwin
->flags
.hidden
) {
1565 wapp
= wApplicationOf(wwin
->main_window
);
1567 wUnhideApplication(wapp
, False
, False
);
1569 wwin
->flags
.skip_next_animation
= 1;
1570 wDeiconifyWindow(wwin
);
1576 wSetFocusTo(scr
, old_foc
);
1577 /*wRaiseFrame(old_foc->frame->core); */
1580 void wRefreshDesktop(WScreen
* scr
)
1583 XSetWindowAttributes attr
;
1585 attr
.backing_store
= NotUseful
;
1586 attr
.save_under
= False
;
1587 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1588 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1589 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1590 XMapRaised(dpy
, win
);
1591 XDestroyWindow(dpy
, win
);
1595 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1601 const int heads
= wXineramaHeads(scr
);
1604 int pf
; /* primary axis */
1605 int sf
; /* secondary axis */
1609 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1615 int isize
= wPreferences
.icon_size
;
1617 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1619 for (head
= 0; head
< heads
; ++head
) {
1621 WMRect rect
= wGetRectForHead(scr
, head
);
1623 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1624 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1627 vars
[head
].pi
= vars
[head
].si
= 0;
1628 vars
[head
].sx1
= rect
.pos
.x
;
1629 vars
[head
].sy1
= rect
.pos
.y
;
1630 vars
[head
].sw
= rect
.size
.width
;
1631 vars
[head
].sh
= rect
.size
.height
;
1632 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1633 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1637 if (scr
->dock
->on_right_side
)
1638 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1640 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1644 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1645 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1646 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1647 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1649 /* icon yard boundaries */
1650 if (wPreferences
.icon_yard
& IY_VERT
) {
1651 vars
[head
].pf
= vars
[head
].fullH
;
1652 vars
[head
].sf
= vars
[head
].fullW
;
1654 vars
[head
].pf
= vars
[head
].fullW
;
1655 vars
[head
].sf
= vars
[head
].fullH
;
1657 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1658 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1661 vars
[head
].xo
= vars
[head
].sx1
;
1664 if (wPreferences
.icon_yard
& IY_TOP
) {
1665 vars
[head
].yo
= vars
[head
].sy1
;
1668 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1673 #define X ((wPreferences.icon_yard & IY_VERT) \
1674 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1675 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1677 #define Y ((wPreferences.icon_yard & IY_VERT) \
1678 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1679 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1681 /* arrange application icons */
1682 aicon
= scr
->app_icon_list
;
1683 /* reverse them to avoid unnecessarily sliding of icons */
1684 while (aicon
&& aicon
->next
)
1685 aicon
= aicon
->next
;
1688 if (!aicon
->docked
) {
1689 /* CHECK: can icon be NULL here ? */
1690 /* The intention here is to place the AppIcon on the head that
1691 * contains most of the applications _main_ window. */
1692 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1694 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1696 if (!wPreferences
.no_animations
) {
1697 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1699 #endif /* ANIMATIONS */
1701 wAppIconMove(aicon
, X
, Y
);
1703 if (vars
[head
].pi
>= vars
[head
].pf
) {
1708 aicon
= aicon
->prev
;
1711 /* arrange miniwindows */
1712 wwin
= scr
->focused_window
;
1713 /* reverse them to avoid unnecessarily shuffling */
1714 while (wwin
&& wwin
->prev
)
1718 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1719 (wwin
->frame
->workspace
== scr
->current_workspace
||
1720 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1722 head
= wGetHeadForWindow(wwin
);
1724 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1725 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1727 if (wPreferences
.no_animations
) {
1728 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1730 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1731 wwin
->icon_y
, X
, Y
);
1734 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1735 #endif /* ANIMATIONS */
1741 if (vars
[head
].pi
>= vars
[head
].pf
) {
1748 wwin
->flags
.icon_moved
= 0;
1750 /* we reversed the order, so we use next */
1758 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1762 int pf
; /* primary axis */
1763 int sf
; /* secondary axis */
1767 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1771 int isize
= wPreferences
.icon_size
;
1774 * Find out screen boundaries.
1778 * Allows each head to have miniwindows
1780 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1784 sw
= rect
.size
.width
;
1785 sh
= rect
.size
.height
;
1789 if (scr
->dock
->on_right_side
)
1790 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1792 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1795 sw
= isize
* (scr
->scr_width
/ isize
);
1796 sh
= isize
* (scr
->scr_height
/ isize
);
1798 sw
= isize
* (sw
/ isize
);
1799 sh
= isize
* (sh
/ isize
);
1801 fullW
= (sx2
- sx1
) / isize
;
1802 fullH
= (sy2
- sy1
) / isize
;
1804 /* icon yard boundaries */
1805 if (wPreferences
.icon_yard
& IY_VERT
) {
1812 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1819 if (wPreferences
.icon_yard
& IY_TOP
) {
1827 /* arrange icons putting the most recently focused window
1828 * as the last icon */
1829 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1830 : xo + xs*(pi*isize))
1831 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1832 : yo + ys*(si*isize))
1834 /* arrange application icons */
1835 aicon
= scr
->app_icon_list
;
1836 /* reverse them to avoid unnecessarily sliding of icons */
1837 while (aicon
&& aicon
->next
)
1838 aicon
= aicon
->next
;
1843 if (!aicon
->docked
) {
1844 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1846 if (!wPreferences
.no_animations
) {
1847 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1849 #endif /* ANIMATIONS */
1851 wAppIconMove(aicon
, X
, Y
);
1854 /* we reversed the order so we use prev */
1855 aicon
= aicon
->prev
;
1862 /* arrange miniwindows */
1864 wwin
= scr
->focused_window
;
1865 /* reverse them to avoid unnecessarily shuffling */
1866 while (wwin
&& wwin
->prev
)
1870 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1871 (wwin
->frame
->workspace
== scr
->current_workspace
||
1872 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1874 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1875 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1877 if (wPreferences
.no_animations
) {
1878 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1880 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1881 wwin
->icon_y
, X
, Y
);
1884 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1885 #endif /* ANIMATIONS */
1893 wwin
->flags
.icon_moved
= 0;
1895 /* we reversed the order, so we use next */
1905 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1907 WScreen
*scr
= wwin
->screen_ptr
;
1910 wwin
->flags
.selected
= 1;
1911 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1913 if (!HAS_BORDER(wwin
)) {
1914 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1917 if (!scr
->selected_windows
)
1918 scr
->selected_windows
= WMCreateArray(4);
1919 WMAddToArray(scr
->selected_windows
, wwin
);
1921 wwin
->flags
.selected
= 0;
1922 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1924 if (!HAS_BORDER(wwin
)) {
1925 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1928 if (scr
->selected_windows
) {
1929 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1934 void wMakeWindowVisible(WWindow
* wwin
)
1936 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1937 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1939 if (wwin
->flags
.shaded
) {
1940 wUnshadeWindow(wwin
);
1942 if (wwin
->flags
.hidden
) {
1945 app
= wApplicationOf(wwin
->main_window
);
1947 /* trick to get focus to this window */
1948 app
->last_focused
= wwin
;
1949 wUnhideApplication(app
, False
, False
);
1952 if (wwin
->flags
.miniaturized
) {
1953 wDeiconifyWindow(wwin
);
1955 if (!WFLAGP(wwin
, no_focusable
))
1956 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1957 wRaiseFrame(wwin
->frame
->core
);
1962 * Do the animation while shading (called with what = SHADE)
1963 * or unshading (what = UNSHADE).
1966 static void shade_animate(WWindow
*wwin
, Bool what
)
1969 time_t time0
= time(NULL
);
1971 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1976 if (!wwin
->screen_ptr
->flags
.startup
) {
1977 /* do the shading animation */
1978 h
= wwin
->frame
->core
->height
;
1979 s
= h
/ SHADE_STEPS
;
1982 w
= wwin
->frame
->core
->width
;
1983 y
= wwin
->frame
->top_width
;
1984 while (h
> wwin
->frame
->top_width
+ 1) {
1985 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1986 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1989 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1992 if (SHADE_DELAY
> 0) {
1993 wusleep(SHADE_DELAY
* 1000L);
2000 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2005 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2006 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2007 s
= abs(y
) / SHADE_STEPS
;
2010 w
= wwin
->frame
->core
->width
;
2011 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2013 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2014 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2015 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2017 if (SHADE_DELAY
> 0) {
2018 wusleep(SHADE_DELAY
* 2000L / 3);
2025 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2029 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2034 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
2035 #endif /* ANIMATIONS */