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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
33 #include "WindowMaker.h"
39 #include "application.h"
45 #include "winspector.h"
46 #include "workspace.h"
49 /****** Global Variables ******/
51 int ignore_wks_change
= 0;
52 extern Time LastTimestamp
;
53 extern Time LastFocusChange
;
54 extern WPreferences wPreferences
;
55 extern Atom _XA_WM_TAKE_FOCUS
;
56 extern void ProcessPendingEvents();
57 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
59 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
60 unsigned int *new_width
, unsigned int *new_height
);
61 static void save_old_geometry(WWindow
*wwin
);
63 /******* Local Variables *******/
69 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
70 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
71 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
72 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
73 SHADE_STEPS_US
, SHADE_DELAY_US
}};
77 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
78 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
80 static int compareTimes(Time t1
, Time t2
)
86 return (diff
< 60000) ? 1 : -1;
90 static void shade_animate(WWindow
*wwin
, Bool what
);
92 static void shade_animate(WWindow
*wwin
, Bool what
) { }
96 *----------------------------------------------------------------------
98 * Changes the window focus to the one passed as argument.
99 * If the window to focus is not already focused, it will be brought
100 * to the head of the list of windows. Previously focused window is
104 * Window list may be reordered and the window focus is changed.
106 *----------------------------------------------------------------------
108 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
110 static WScreen
*old_scr
= NULL
;
112 WWindow
*old_focused
;
113 WWindow
*focused
= scr
->focused_window
;
114 Time timestamp
= LastTimestamp
;
115 WApplication
*oapp
= NULL
, *napp
= NULL
;
118 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
124 old_focused
= old_scr
->focused_window
;
126 LastFocusChange
= timestamp
;
129 oapp
= wApplicationOf(old_focused
->main_window
);
132 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
134 wWindowUnfocus(old_focused
);
137 wAppMenuUnmap(oapp
->menu
);
138 wApplicationDeactivate(oapp
);
141 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
145 if (old_scr
!= scr
&& old_focused
)
146 wWindowUnfocus(old_focused
);
148 wasfocused
= wwin
->flags
.focused
;
149 napp
= wApplicationOf(wwin
->main_window
);
151 /* remember last workspace where the app has been */
153 napp
->last_workspace
= wwin
->frame
->workspace
;
155 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
156 /* install colormap if colormap mode is lock mode */
157 if (wPreferences
.colormap_mode
== WCM_CLICK
)
158 wColormapInstallForWindow(scr
, wwin
);
160 /* set input focus */
161 switch (wwin
->focus_mode
) {
163 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
166 case WFM_LOCALLY_ACTIVE
:
167 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
169 case WFM_GLOBALLY_ACTIVE
:
174 if (wwin
->protocols
.TAKE_FOCUS
)
175 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
179 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
182 if (WFLAGP(wwin
, no_focusable
))
185 /* if this is not the focused window focus it */
186 if (focused
!= wwin
) {
187 /* change the focus window list order */
189 wwin
->prev
->next
= wwin
->next
;
192 wwin
->next
->prev
= wwin
->prev
;
194 wwin
->prev
= focused
;
195 focused
->next
= wwin
;
197 scr
->focused_window
= wwin
;
199 if (oapp
&& oapp
!= napp
) {
200 wAppMenuUnmap(oapp
->menu
);
201 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
);
216 wApplicationActivate(napp
);
222 void wShadeWindow(WWindow
*wwin
)
225 if (wwin
->flags
.shaded
)
228 XLowerWindow(dpy
, wwin
->client_win
);
229 shade_animate(wwin
, SHADE
);
231 wwin
->flags
.skip_next_animation
= 0;
232 wwin
->flags
.shaded
= 1;
233 wwin
->flags
.mapped
= 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
236 XUnmapWindow(dpy
, wwin
->client_win
);
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
242 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
243 wWindowSynthConfigureNotify(wwin
);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
252 if (!wwin
->screen_ptr
->flags
.startup
) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
259 void wUnshadeWindow(WWindow
*wwin
)
262 if (!wwin
->flags
.shaded
)
265 wwin
->flags
.shaded
= 0;
266 wwin
->flags
.mapped
= 1;
267 XMapWindow(dpy
, wwin
->client_win
);
269 shade_animate(wwin
, UNSHADE
);
271 wwin
->flags
.skip_next_animation
= 0;
272 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
273 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
275 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
276 wWindowSynthConfigureNotify(wwin
);
278 /* if the window is focused, set the focus again as it was disabled during
280 if (wwin
->flags
.focused
)
281 wSetFocusTo(wwin
->screen_ptr
, wwin
);
283 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
286 /* Set the old coordinates using the current values */
287 static void save_old_geometry(WWindow
*wwin
)
289 wwin
->old_geometry
.width
= wwin
->client
.width
;
290 wwin
->old_geometry
.height
= wwin
->client
.height
;
291 wwin
->old_geometry
.x
= wwin
->frame_x
;
292 wwin
->old_geometry
.y
= wwin
->frame_y
;
295 void wMaximizeWindow(WWindow
*wwin
, int directions
)
298 unsigned int new_width
, new_height
, half_scr_width
;
299 WArea usableArea
, totalArea
;
303 if (!IS_RESIZABLE(wwin
))
306 if (!HAS_BORDER(wwin
))
309 /* the size to adjust the geometry */
310 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
312 /* save old coordinates before we change the current values */
313 save_old_geometry(wwin
);
317 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
318 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
319 usableArea
= totalArea
;
321 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
322 WScreen
*scr
= wwin
->screen_ptr
;
325 if (directions
& MAX_KEYBOARD
)
326 head
= wGetHeadForWindow(wwin
);
328 head
= wGetHeadForPointerLocation(scr
);
330 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
333 /* Only save directions, not kbd or xinerama hints */
334 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
336 if (WFLAGP(wwin
, full_maximize
)) {
337 usableArea
= totalArea
;
339 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
341 if (wwin
->flags
.shaded
) {
342 wwin
->flags
.skip_next_animation
= 1;
343 wUnshadeWindow(wwin
);
346 if (directions
& MAX_HORIZONTAL
) {
347 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
348 new_x
= usableArea
.x1
;
349 } else if (directions
& MAX_LEFTHALF
) {
350 new_width
= half_scr_width
- adj_size
;
351 new_x
= usableArea
.x1
;
352 } else if (directions
& MAX_RIGHTHALF
) {
353 new_width
= half_scr_width
- adj_size
;
354 new_x
= usableArea
.x1
+ half_scr_width
;
356 new_x
= wwin
->frame_x
;
357 new_width
= wwin
->frame
->core
->width
;
360 if (directions
& MAX_VERTICAL
) {
361 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
362 new_y
= usableArea
.y1
;
363 if (WFLAGP(wwin
, full_maximize
)) {
364 new_y
-= wwin
->frame
->top_width
;
365 new_height
+= wwin
->frame
->bottom_width
- 1;
368 new_y
= wwin
->frame_y
;
369 new_height
= wwin
->frame
->core
->height
;
372 if (!WFLAGP(wwin
, full_maximize
)) {
373 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
376 if (directions
& MAX_MAXIMUS
) {
377 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
378 new_width
-= adj_size
;
379 new_height
-= adj_size
;
380 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
381 new_y
-= wwin
->frame
->top_width
;
382 new_height
+= wwin
->frame
->top_width
- 1;
386 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
388 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
389 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
391 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
392 wWindowSynthConfigureNotify(wwin
);
394 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
396 /* set maximization state */
397 wwin
->flags
.maximized
= directions
;
400 /* the window boundary coordinates */
410 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
412 obs
->left
= wwin
->frame_x
;
413 obs
->top
= wwin
->frame_y
;
414 obs
->width
= wwin
->frame
->core
->width
;
415 obs
->height
= wwin
->frame
->core
->height
;
416 obs
->bottom
= obs
->top
+ obs
->height
;
417 obs
->right
= obs
->left
+ obs
->width
;
421 * Maximus: tiled maximization (maximize without overlapping other windows)
423 * The original window 'orig' will be maximized to new coordinates 'new'.
424 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
426 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
427 unsigned int *new_width
, unsigned int *new_height
)
430 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
431 short int adjust_height
;
432 int x_intsect
, y_intsect
;
433 /* the obstructing, original and new windows */
434 win_coords obs
, orig
, new;
436 /* set the original coordinate positions of the window to be Maximumized */
437 set_window_coords(wwin
, &orig
);
439 /* Try to fully maximize first, then readjust later */
440 new.left
= usableArea
.x1
;
441 new.right
= usableArea
.x2
;
442 new.top
= usableArea
.y1
;
443 new.bottom
= usableArea
.y2
;
445 if (HAS_TITLEBAR(wwin
))
446 tbar_height_0
= TITLEBAR_HEIGHT
;
447 if (HAS_RESIZEBAR(wwin
))
448 rbar_height_0
= RESIZEBAR_HEIGHT
;
449 if (HAS_BORDER(wwin
))
450 bd_width_0
= FRAME_BORDER_WIDTH
;
452 /* the length to be subtracted if the window has titlebar, etc */
453 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
456 /* The focused window is always the last in the list */
458 /* ignore windows in other workspaces etc */
459 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
460 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
466 /* Set the coordinates of obstructing window */
467 set_window_coords(tmp
, &obs
);
469 /* Try to maximize in the y direction first */
470 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
471 if (x_intsect
!= 0) {
472 /* TODO: Consider the case when coords are equal */
473 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
474 /* w_0 is below the bottom of w_j */
475 new.top
= obs
.bottom
+ 1;
477 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
478 /* The bottom of w_0 is above the top of w_j */
479 new.bottom
= obs
.top
- 1;
486 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
487 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
493 set_window_coords(tmp
, &obs
);
496 * Use the new.top and new.height instead of original values
497 * as they may have different intersections with the obstructing windows
499 new.height
= new.bottom
- new.top
- adjust_height
;
500 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
501 if (y_intsect
!= 0) {
502 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
503 /* w_0 is completely to the right of w_j */
504 new.left
= obs
.right
+ 1;
506 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
507 /* w_0 is completely to the left of w_j */
508 new.right
= obs
.left
- 1;
515 /* xcalc needs -7 here, but other apps don't */
516 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
517 *new_width
= new.right
- new.left
;
520 void wUnmaximizeWindow(WWindow
*wwin
)
523 WMRect old_geom_rect
;
527 if (!wwin
->flags
.maximized
)
530 if (wwin
->flags
.shaded
) {
531 wwin
->flags
.skip_next_animation
= 1;
532 wUnshadeWindow(wwin
);
534 /* Use old coordinates if they are set, current values otherwise */
535 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
536 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
537 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
538 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
539 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
540 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
541 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
543 wwin
->flags
.maximized
= 0;
544 wWindowConfigure(wwin
, x
, y
, w
, h
);
545 wWindowSynthConfigureNotify(wwin
);
547 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
550 void wFullscreenWindow(WWindow
*wwin
)
555 if (wwin
->flags
.fullscreen
)
558 wwin
->flags
.fullscreen
= True
;
560 wWindowConfigureBorders(wwin
);
562 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
564 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
565 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
566 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
567 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
569 head
= wGetHeadForWindow(wwin
);
570 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
571 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
573 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
576 void wUnfullscreenWindow(WWindow
*wwin
)
578 if (!wwin
->flags
.fullscreen
)
581 wwin
->flags
.fullscreen
= False
;
583 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
584 if (WFLAGP(wwin
, sunken
)) {
585 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
586 } else if (WFLAGP(wwin
, floating
)) {
587 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
589 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
593 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
594 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
596 wWindowConfigureBorders(wwin
);
598 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
599 wFrameWindowPaint(wwin->frame);
602 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
606 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
608 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
609 float cx
, cy
, cw
, ch
;
610 float xstep
, ystep
, wstep
, hstep
;
613 float angle
, final_angle
, delta
;
615 xstep
= (float)(fx
- x
) / steps
;
616 ystep
= (float)(fy
- y
) / steps
;
617 wstep
= (float)(fw
- w
) / steps
;
618 hstep
= (float)(fh
- h
) / steps
;
625 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
626 delta
= (float)(final_angle
/ FRAMES
);
627 for (angle
= 0;; angle
+= delta
) {
628 if (angle
> final_angle
)
631 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
632 dch
= (ch
/ 2) * cos(angle
);
633 midy
= cy
+ (ch
/ 2);
635 points
[0].x
= cx
+ dx
;
636 points
[0].y
= midy
- dch
;
637 points
[1].x
= cx
+ cw
- dx
;
638 points
[1].y
= points
[0].y
;
639 points
[2].x
= cx
+ cw
+ dx
;
640 points
[2].y
= midy
+ dch
;
641 points
[3].x
= cx
- dx
;
642 points
[3].y
= points
[2].y
;
643 points
[4].x
= points
[0].x
;
644 points
[4].y
= points
[0].y
;
647 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
649 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
651 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
657 if (angle
>= final_angle
)
667 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
669 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
670 float cx
, cy
, cw
, ch
;
671 float xstep
, ystep
, wstep
, hstep
;
673 float angle
, final_angle
, a
, d
, delta
;
680 xstep
= (float)(fx
- x
) / steps
;
681 ystep
= (float)(fy
- y
) / steps
;
682 wstep
= (float)(fw
- w
) / steps
;
683 hstep
= (float)(fh
- h
) / steps
;
690 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
691 delta
= (float)(final_angle
/ FRAMES
);
692 for (angle
= 0;; angle
+= delta
) {
693 if (angle
> final_angle
)
697 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
699 points
[0].x
= cx
+ cos(angle
- a
) * d
;
700 points
[0].y
= cy
+ sin(angle
- a
) * d
;
701 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
702 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
703 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
704 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
705 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
706 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
707 points
[4].x
= cx
+ cos(angle
- a
) * d
;
708 points
[4].y
= cy
+ sin(angle
- a
) * d
;
710 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
712 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
714 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
720 if (angle
>= final_angle
)
729 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
731 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
732 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
733 float xstep
, ystep
, wstep
, hstep
;
736 xstep
= (float)(fx
- x
) / steps
;
737 ystep
= (float)(fy
- y
) / steps
;
738 wstep
= (float)(fw
- w
) / steps
;
739 hstep
= (float)(fh
- h
) / steps
;
741 for (j
= 0; j
< FRAMES
; j
++) {
748 for (i
= 0; i
< steps
; i
++) {
749 for (j
= 0; j
< FRAMES
; j
++) {
750 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
751 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
754 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
756 for (j
= 0; j
< FRAMES
; j
++) {
757 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
758 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
759 if (j
< FRAMES
- 1) {
773 for (j
= 0; j
< FRAMES
; j
++) {
774 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
777 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
779 for (j
= 0; j
< FRAMES
; j
++) {
780 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
788 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
790 int style
= wPreferences
.iconification_style
; /* Catch the value */
793 if (style
== WIS_NONE
)
796 if (style
== WIS_RANDOM
) {
802 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
804 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
807 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
809 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
813 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
815 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
819 #endif /* ANIMATIONS */
821 static void flushExpose(void)
825 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
826 WMHandleEvent(&tmpev
);
830 static void unmapTransientsFor(WWindow
*wwin
)
834 tmp
= wwin
->screen_ptr
->focused_window
;
836 /* unmap the transients for this transient */
837 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
838 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
839 unmapTransientsFor(tmp
);
840 tmp
->flags
.miniaturized
= 1;
841 if (!tmp
->flags
.shaded
) {
844 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
847 if (!tmp->flags.shaded)
849 wClientSetState(tmp
, IconicState
, None
);
851 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
857 static void mapTransientsFor(WWindow
*wwin
)
861 tmp
= wwin
->screen_ptr
->focused_window
;
863 /* recursively map the transients for this transient */
864 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
865 && tmp
->icon
== NULL
) {
866 mapTransientsFor(tmp
);
867 tmp
->flags
.miniaturized
= 0;
868 if (!tmp
->flags
.shaded
) {
871 XMapWindow(dpy
, tmp
->frame
->core
->window
);
873 tmp
->flags
.semi_focused
= 0;
875 if (!tmp->flags.shaded)
877 wClientSetState(tmp
, NormalState
, None
);
879 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
885 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
892 /* hackish way to detect transient_for cycle */
893 i
= wwin
->screen_ptr
->window_count
+ 1;
895 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
896 wwin
= wWindowFor(wwin
->transient_for
);
899 if (i
== 0 && wwin
) {
900 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
907 void wIconifyWindow(WWindow
* wwin
)
909 XWindowAttributes attribs
;
912 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
913 return; /* the window doesn't exist anymore */
915 if (wwin
->flags
.miniaturized
)
916 return; /* already miniaturized */
918 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
919 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
921 if (owner
&& owner
->flags
.miniaturized
)
925 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
927 /* if the window is in another workspace, simplify process */
929 /* icon creation may take a while */
930 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
931 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
932 GrabModeAsync
, None
, None
, CurrentTime
);
935 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
936 if (!wwin
->flags
.icon_moved
)
937 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
939 wwin
->icon
= wIconCreate(wwin
);
940 wwin
->icon
->mapped
= 1;
943 wwin
->flags
.miniaturized
= 1;
944 wwin
->flags
.mapped
= 0;
946 /* unmap transients */
947 unmapTransientsFor(wwin
);
950 XUngrabPointer(dpy
, CurrentTime
);
952 /* let all Expose events arrive so that we can repaint
953 * something before the animation starts (and the server is grabbed) */
956 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
957 wClientSetState(wwin
, IconicState
, None
);
959 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
963 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
964 && !wPreferences
.no_animations
) {
967 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
970 iw
= wwin
->icon
->core
->width
;
971 ih
= wwin
->icon
->core
->height
;
973 if (wwin
->flags
.net_handle_icon
) {
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
, ix
, iy
, iw
, ih
);
991 wwin
->flags
.skip_next_animation
= 0;
993 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
994 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
995 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
996 XMapWindow(dpy
, wwin
->icon
->core
->window
);
998 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
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1011 && wPreferences
.focus_mode
== WKF_CLICK
) {
1016 if (!WFLAGP(tmp
, no_focusable
)
1017 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1018 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1022 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1023 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1024 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1027 if (!wwin
->screen_ptr
->flags
.startup
) {
1028 /* Catch up with events not processed while animation was running */
1029 Window clientwin
= wwin
->client_win
;
1031 ProcessPendingEvents();
1033 /* the window can disappear while ProcessPendingEvents() runs */
1034 if (!wWindowFor(clientwin
)) {
1041 /* maybe we want to do this regardless of net_handle_icon
1042 * it seems to me we might break behaviour this way.
1044 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1045 && !wwin
->flags
.net_handle_icon
)
1046 wIconSelect(wwin
->icon
);
1048 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1050 if (wPreferences
.auto_arrange_icons
)
1051 wArrangeIcons(wwin
->screen_ptr
, True
);
1054 void wDeiconifyWindow(WWindow
*wwin
)
1056 /* Let's avoid changing workspace while deiconifying */
1057 ignore_wks_change
= 1;
1059 /* we're hiding for show_desktop */
1060 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1061 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1064 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1066 if (!wwin
->flags
.miniaturized
)
1069 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1070 WWindow
*owner
= recursiveTransientFor(wwin
);
1072 if (owner
&& owner
->flags
.miniaturized
) {
1073 wDeiconifyWindow(owner
);
1074 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1075 wRaiseFrame(wwin
->frame
->core
);
1080 wwin
->flags
.miniaturized
= 0;
1082 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1083 wwin
->flags
.mapped
= 1;
1085 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1086 /* maybe we want to do this regardless of net_handle_icon
1087 * it seems to me we might break behaviour this way.
1089 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1090 && wwin
->icon
!= NULL
) {
1091 if (wwin
->icon
->selected
)
1092 wIconSelect(wwin
->icon
);
1094 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1098 /* if the window is in another workspace, do it silently */
1099 if (!netwm_hidden
) {
1101 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1102 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1105 if (!wPreferences
.disable_miniwindows
1106 && !wwin
->flags
.net_handle_icon
) {
1109 iw
= wwin
->icon
->core
->width
;
1110 ih
= wwin
->icon
->core
->height
;
1112 if (wwin
->flags
.net_handle_icon
) {
1120 iw
= wwin
->screen_ptr
->scr_width
;
1121 ih
= wwin
->screen_ptr
->scr_height
;
1124 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1125 wwin
->frame_x
, wwin
->frame_y
,
1126 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1128 #endif /* ANIMATIONS */
1129 wwin
->flags
.skip_next_animation
= 0;
1131 if (!wwin
->flags
.shaded
)
1132 XMapWindow(dpy
, wwin
->client_win
);
1134 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1135 wRaiseFrame(wwin
->frame
->core
);
1136 if (!wwin
->flags
.shaded
)
1137 wClientSetState(wwin
, NormalState
, None
);
1139 mapTransientsFor(wwin
);
1142 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1143 && !wwin
->flags
.net_handle_icon
) {
1144 RemoveFromStackList(wwin
->icon
->core
);
1145 /* removeIconGrabs(wwin->icon); */
1146 wIconDestroy(wwin
->icon
);
1150 if (!netwm_hidden
) {
1153 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1156 if (!wwin
->screen_ptr
->flags
.startup
) {
1157 /* Catch up with events not processed while animation was running */
1158 Window clientwin
= wwin
->client_win
;
1160 ProcessPendingEvents();
1162 /* the window can disappear while ProcessPendingEvents() runs */
1163 if (!wWindowFor(clientwin
))
1169 if (wPreferences
.auto_arrange_icons
)
1170 wArrangeIcons(wwin
->screen_ptr
, True
);
1172 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1174 /* In case we were shaded and iconified, also unshade */
1176 wUnshadeWindow(wwin
);
1178 ignore_wks_change
= 0;
1181 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1183 if (wwin
->flags
.miniaturized
) {
1185 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1186 wwin
->icon
->mapped
= 0;
1188 wwin
->flags
.hidden
= 1;
1190 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1194 if (wwin
->flags
.inspector_open
) {
1195 wHideInspectorForWindow(wwin
);
1198 wwin
->flags
.hidden
= 1;
1201 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1205 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1206 !wwin
->flags
.skip_next_animation
&& animate
) {
1207 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1208 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1209 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1212 wwin
->flags
.skip_next_animation
= 0;
1214 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1217 void wHideAll(WScreen
*scr
)
1222 unsigned int wcount
= 0;
1228 menu
= scr
->switch_menu
;
1230 windows
= wmalloc(sizeof(WWindow
*));
1233 for (i
= 0; i
< menu
->entry_no
; i
++) {
1234 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1236 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1239 wwin
= scr
->focused_window
;
1242 windows
[wcount
] = wwin
;
1244 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1250 for (i
= 0; i
< wcount
; i
++) {
1252 if (wwin
->frame
->workspace
== scr
->current_workspace
1253 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1254 && !wwin
->flags
.internal_window
1255 && !WFLAGP(wwin
, no_miniaturizable
)
1257 wwin
->flags
.skip_next_animation
= 1;
1258 wIconifyWindow(wwin
);
1265 void wHideOtherApplications(WWindow
*awin
)
1272 wwin
= awin
->screen_ptr
->focused_window
;
1276 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1277 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1278 && !wwin
->flags
.internal_window
1279 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1281 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1282 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1283 wwin
->flags
.skip_next_animation
= 1;
1284 wIconifyWindow(wwin
);
1286 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1287 tapp
= wApplicationOf(wwin
->main_window
);
1289 tapp
->flags
.skip_next_animation
= 1;
1290 wHideApplication(tapp
);
1292 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1293 wwin
->flags
.skip_next_animation
= 1;
1294 wIconifyWindow(wwin
);
1302 wSetFocusTo(awin->screen_ptr, awin);
1306 void wHideApplication(WApplication
*wapp
)
1314 wwarning("trying to hide a non grouped window");
1317 if (!wapp
->main_window_desc
) {
1318 wwarning("group leader not found for window group");
1321 scr
= wapp
->main_window_desc
->screen_ptr
;
1323 wlist
= scr
->focused_window
;
1327 if (wlist
->main_window
== wapp
->main_window
)
1328 wapp
->last_focused
= wlist
;
1330 wapp
->last_focused
= NULL
;
1332 animate
= !wapp
->flags
.skip_next_animation
;
1335 if (wlist
->main_window
== wapp
->main_window
) {
1336 if (wlist
->flags
.focused
) {
1339 if (wapp
->app_icon
) {
1340 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1341 wapp
->app_icon
->y_pos
, wlist
, animate
);
1345 wlist
= wlist
->prev
;
1348 wapp
->flags
.skip_next_animation
= 0;
1351 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1352 wlist
= scr
->focused_window
;
1354 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1355 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1357 wlist
= wlist
->prev
;
1359 wSetFocusTo(scr
, wlist
);
1361 wSetFocusTo(scr
, NULL
);
1365 wapp
->flags
.hidden
= 1;
1367 if (wPreferences
.auto_arrange_icons
) {
1368 wArrangeIcons(scr
, True
);
1372 wAppIconPaint(wapp
->app_icon
);
1376 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1378 if (bringToCurrentWS
)
1379 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1381 wwin
->flags
.hidden
= 0;
1384 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1385 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1386 icon
->core
->width
, icon
->core
->height
,
1387 wwin
->frame_x
, wwin
->frame_y
,
1388 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1391 wwin
->flags
.skip_next_animation
= 0;
1392 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1393 XMapWindow(dpy
, wwin
->client_win
);
1394 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1395 wClientSetState(wwin
, NormalState
, None
);
1396 wwin
->flags
.mapped
= 1;
1397 wRaiseFrame(wwin
->frame
->core
);
1399 if (wwin
->flags
.inspector_open
) {
1400 wUnhideInspectorForWindow(wwin
);
1403 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1406 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1409 WWindow
*wlist
, *next
;
1410 WWindow
*focused
= NULL
;
1416 scr
= wapp
->main_window_desc
->screen_ptr
;
1417 wlist
= scr
->focused_window
;
1421 /* goto beginning of list */
1423 wlist
= wlist
->prev
;
1425 animate
= !wapp
->flags
.skip_next_animation
;
1430 if (wlist
->main_window
== wapp
->main_window
) {
1431 if (wlist
->flags
.focused
)
1433 else if (!focused
|| !focused
->flags
.focused
)
1436 if (wlist
->flags
.miniaturized
) {
1437 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1438 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1439 if (!wlist
->icon
->mapped
) {
1442 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1443 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1444 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1448 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1449 wlist
->icon
->mapped
= 1;
1451 wRaiseFrame(wlist
->icon
->core
);
1453 if (bringToCurrentWS
)
1454 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1455 wlist
->flags
.hidden
= 0;
1456 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1457 wDeiconifyWindow(wlist
);
1459 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1460 } else if (wlist
->flags
.shaded
) {
1461 if (bringToCurrentWS
)
1462 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1463 wlist
->flags
.hidden
= 0;
1464 wRaiseFrame(wlist
->frame
->core
);
1465 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1466 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1468 wUnshadeWindow(wlist
);
1471 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1472 } else if (wlist
->flags
.hidden
) {
1473 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1474 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1477 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1478 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1480 wRaiseFrame(wlist
->frame
->core
);
1486 wapp
->flags
.skip_next_animation
= 0;
1487 wapp
->flags
.hidden
= 0;
1489 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1490 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1491 wSetFocusTo(scr
, wapp
->last_focused
);
1492 } else if (focused
) {
1493 wSetFocusTo(scr
, focused
);
1495 wapp
->last_focused
= NULL
;
1496 if (wPreferences
.auto_arrange_icons
) {
1497 wArrangeIcons(scr
, True
);
1500 wAppIconPaint(wapp
->app_icon
);
1504 void wShowAllWindows(WScreen
*scr
)
1506 WWindow
*wwin
, *old_foc
;
1509 old_foc
= wwin
= scr
->focused_window
;
1511 if (!wwin
->flags
.internal_window
&&
1512 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1513 if (wwin
->flags
.miniaturized
) {
1514 wwin
->flags
.skip_next_animation
= 1;
1515 wDeiconifyWindow(wwin
);
1516 } else if (wwin
->flags
.hidden
) {
1517 wapp
= wApplicationOf(wwin
->main_window
);
1519 wUnhideApplication(wapp
, False
, False
);
1521 wwin
->flags
.skip_next_animation
= 1;
1522 wDeiconifyWindow(wwin
);
1528 wSetFocusTo(scr
, old_foc
);
1529 /*wRaiseFrame(old_foc->frame->core); */
1532 void wRefreshDesktop(WScreen
*scr
)
1535 XSetWindowAttributes attr
;
1537 attr
.backing_store
= NotUseful
;
1538 attr
.save_under
= False
;
1539 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1540 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1541 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1542 XMapRaised(dpy
, win
);
1543 XDestroyWindow(dpy
, win
);
1547 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1553 const int heads
= wXineramaHeads(scr
);
1556 int pf
; /* primary axis */
1557 int sf
; /* secondary axis */
1561 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1567 int isize
= wPreferences
.icon_size
;
1569 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1571 for (head
= 0; head
< heads
; ++head
) {
1572 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1573 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1574 vars
[head
].pi
= vars
[head
].si
= 0;
1575 vars
[head
].sx1
= rect
.pos
.x
;
1576 vars
[head
].sy1
= rect
.pos
.y
;
1577 vars
[head
].sw
= rect
.size
.width
;
1578 vars
[head
].sh
= rect
.size
.height
;
1579 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1580 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1581 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1582 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1583 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1584 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1586 /* icon yard boundaries */
1587 if (wPreferences
.icon_yard
& IY_VERT
) {
1588 vars
[head
].pf
= vars
[head
].fullH
;
1589 vars
[head
].sf
= vars
[head
].fullW
;
1591 vars
[head
].pf
= vars
[head
].fullW
;
1592 vars
[head
].sf
= vars
[head
].fullH
;
1594 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1595 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1598 vars
[head
].xo
= vars
[head
].sx1
;
1601 if (wPreferences
.icon_yard
& IY_TOP
) {
1602 vars
[head
].yo
= vars
[head
].sy1
;
1605 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1610 #define X ((wPreferences.icon_yard & IY_VERT) \
1611 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1612 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1614 #define Y ((wPreferences.icon_yard & IY_VERT) \
1615 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1616 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1618 /* arrange application icons */
1619 aicon
= scr
->app_icon_list
;
1620 /* reverse them to avoid unnecessarily sliding of icons */
1621 while (aicon
&& aicon
->next
)
1622 aicon
= aicon
->next
;
1625 if (!aicon
->docked
) {
1626 /* CHECK: can icon be NULL here ? */
1627 /* The intention here is to place the AppIcon on the head that
1628 * contains most of the applications _main_ window. */
1629 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1631 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1633 if (!wPreferences
.no_animations
) {
1634 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1636 #endif /* ANIMATIONS */
1638 wAppIconMove(aicon
, X
, Y
);
1640 if (vars
[head
].pi
>= vars
[head
].pf
) {
1645 aicon
= aicon
->prev
;
1648 /* arrange miniwindows */
1649 wwin
= scr
->focused_window
;
1650 /* reverse them to avoid unnecessarily shuffling */
1651 while (wwin
&& wwin
->prev
)
1655 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1656 (wwin
->frame
->workspace
== scr
->current_workspace
||
1657 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1659 head
= wGetHeadForWindow(wwin
);
1661 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1662 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1664 if (wPreferences
.no_animations
) {
1665 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1667 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1668 wwin
->icon_y
, X
, Y
);
1671 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1672 #endif /* ANIMATIONS */
1678 if (vars
[head
].pi
>= vars
[head
].pf
) {
1685 wwin
->flags
.icon_moved
= 0;
1687 /* we reversed the order, so we use next */
1694 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1696 WScreen
*scr
= wwin
->screen_ptr
;
1699 wwin
->flags
.selected
= 1;
1700 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1702 if (!HAS_BORDER(wwin
)) {
1703 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1706 if (!scr
->selected_windows
)
1707 scr
->selected_windows
= WMCreateArray(4);
1708 WMAddToArray(scr
->selected_windows
, wwin
);
1710 wwin
->flags
.selected
= 0;
1711 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1713 if (!HAS_BORDER(wwin
)) {
1714 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1717 if (scr
->selected_windows
) {
1718 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1723 void wMakeWindowVisible(WWindow
*wwin
)
1725 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1726 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1728 if (wwin
->flags
.shaded
) {
1729 wUnshadeWindow(wwin
);
1731 if (wwin
->flags
.hidden
) {
1734 app
= wApplicationOf(wwin
->main_window
);
1736 /* trick to get focus to this window */
1737 app
->last_focused
= wwin
;
1738 wUnhideApplication(app
, False
, False
);
1741 if (wwin
->flags
.miniaturized
) {
1742 wDeiconifyWindow(wwin
);
1744 if (!WFLAGP(wwin
, no_focusable
))
1745 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1746 wRaiseFrame(wwin
->frame
->core
);
1751 * Do the animation while shading (called with what = SHADE)
1752 * or unshading (what = UNSHADE).
1755 static void shade_animate(WWindow
*wwin
, Bool what
)
1758 time_t time0
= time(NULL
);
1760 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1765 if (!wwin
->screen_ptr
->flags
.startup
) {
1766 /* do the shading animation */
1767 h
= wwin
->frame
->core
->height
;
1768 s
= h
/ SHADE_STEPS
;
1771 w
= wwin
->frame
->core
->width
;
1772 y
= wwin
->frame
->top_width
;
1773 while (h
> wwin
->frame
->top_width
+ 1) {
1774 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1775 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1778 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1781 if (SHADE_DELAY
> 0) {
1782 wusleep(SHADE_DELAY
* 1000L);
1789 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1794 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1795 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1796 s
= abs(y
) / SHADE_STEPS
;
1799 w
= wwin
->frame
->core
->width
;
1800 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1802 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1803 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1804 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1806 if (SHADE_DELAY
> 0) {
1807 wusleep(SHADE_DELAY
* 2000L / 3);
1814 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1818 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);