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)
123 old_focused
= old_scr
->focused_window
;
125 LastFocusChange
= timestamp
;
128 oapp
= wApplicationOf(old_focused
->main_window
);
131 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
133 wWindowUnfocus(old_focused
);
135 wAppMenuUnmap(oapp
->menu
);
136 wApplicationDeactivate(oapp
);
139 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
141 } else if (old_scr
!= scr
&& old_focused
) {
142 wWindowUnfocus(old_focused
);
145 wasfocused
= wwin
->flags
.focused
;
146 napp
= wApplicationOf(wwin
->main_window
);
148 /* remember last workspace where the app has been */
150 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
151 napp
->last_workspace
= wwin
->frame
->workspace
;
154 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
155 /* install colormap if colormap mode is lock mode */
156 if (wPreferences
.colormap_mode
== WCM_CLICK
)
157 wColormapInstallForWindow(scr
, wwin
);
159 /* set input focus */
160 switch (wwin
->focus_mode
) {
162 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
166 case WFM_LOCALLY_ACTIVE
:
167 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
170 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
);
181 if (WFLAGP(wwin
, no_focusable
))
184 /* if this is not the focused window focus it */
185 if (focused
!= wwin
) {
186 /* change the focus window list order */
188 wwin
->prev
->next
= wwin
->next
;
191 wwin
->next
->prev
= wwin
->prev
;
193 wwin
->prev
= focused
;
194 focused
->next
= wwin
;
196 scr
->focused_window
= wwin
;
198 if (oapp
&& oapp
!= napp
) {
199 wAppMenuUnmap(oapp
->menu
);
200 wApplicationDeactivate(oapp
);
204 wWindowFocus(wwin
, focused
);
206 if (napp
&& !wasfocused
) {
208 wUserMenuRefreshInstances(napp
->menu
, wwin
);
209 #endif /* USER_MENU */
211 if (wwin
->flags
.mapped
)
212 wAppMenuMap(napp
->menu
, wwin
);
215 wApplicationActivate(napp
);
221 void wShadeWindow(WWindow
*wwin
)
224 if (wwin
->flags
.shaded
)
227 XLowerWindow(dpy
, wwin
->client_win
);
228 shade_animate(wwin
, SHADE
);
230 wwin
->flags
.skip_next_animation
= 0;
231 wwin
->flags
.shaded
= 1;
232 wwin
->flags
.mapped
= 0;
233 /* prevent window withdrawal when getting UnmapNotify */
234 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
235 XUnmapWindow(dpy
, wwin
->client_win
);
236 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
238 /* for the client it's just like iconification */
239 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
241 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
242 wWindowSynthConfigureNotify(wwin
);
245 wClientSetState(wwin, IconicState, None);
248 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
251 if (!wwin
->screen_ptr
->flags
.startup
) {
252 /* Catch up with events not processed while animation was running */
253 ProcessPendingEvents();
258 void wUnshadeWindow(WWindow
*wwin
)
261 if (!wwin
->flags
.shaded
)
264 wwin
->flags
.shaded
= 0;
265 wwin
->flags
.mapped
= 1;
266 XMapWindow(dpy
, wwin
->client_win
);
268 shade_animate(wwin
, UNSHADE
);
270 wwin
->flags
.skip_next_animation
= 0;
271 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
272 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
274 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
275 wWindowSynthConfigureNotify(wwin
);
277 /* if the window is focused, set the focus again as it was disabled during
279 if (wwin
->flags
.focused
)
280 wSetFocusTo(wwin
->screen_ptr
, wwin
);
282 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
285 /* Set the old coordinates using the current values */
286 static void save_old_geometry(WWindow
*wwin
)
288 wwin
->old_geometry
.width
= wwin
->client
.width
;
289 wwin
->old_geometry
.height
= wwin
->client
.height
;
290 wwin
->old_geometry
.x
= wwin
->frame_x
;
291 wwin
->old_geometry
.y
= wwin
->frame_y
;
294 void wMaximizeWindow(WWindow
*wwin
, int directions
)
297 unsigned int new_width
, new_height
, half_scr_width
;
298 WArea usableArea
, totalArea
;
302 if (!IS_RESIZABLE(wwin
))
305 if (!HAS_BORDER(wwin
))
308 /* the size to adjust the geometry */
309 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
311 /* save old coordinates before we change the current values */
312 save_old_geometry(wwin
);
316 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
317 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
318 usableArea
= totalArea
;
320 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
321 WScreen
*scr
= wwin
->screen_ptr
;
324 if (directions
& MAX_KEYBOARD
)
325 head
= wGetHeadForWindow(wwin
);
327 head
= wGetHeadForPointerLocation(scr
);
329 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
332 /* Only save directions, not kbd or xinerama hints */
333 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
335 if (WFLAGP(wwin
, full_maximize
)) {
336 usableArea
= totalArea
;
338 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
340 if (wwin
->flags
.shaded
) {
341 wwin
->flags
.skip_next_animation
= 1;
342 wUnshadeWindow(wwin
);
345 if (directions
& MAX_HORIZONTAL
) {
346 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
347 new_x
= usableArea
.x1
;
348 } else if (directions
& MAX_LEFTHALF
) {
349 new_width
= half_scr_width
- adj_size
;
350 new_x
= usableArea
.x1
;
351 } else if (directions
& MAX_RIGHTHALF
) {
352 new_width
= half_scr_width
- adj_size
;
353 new_x
= usableArea
.x1
+ half_scr_width
;
355 new_x
= wwin
->frame_x
;
356 new_width
= wwin
->frame
->core
->width
;
359 if (directions
& MAX_VERTICAL
) {
360 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
361 new_y
= usableArea
.y1
;
362 if (WFLAGP(wwin
, full_maximize
)) {
363 new_y
-= wwin
->frame
->top_width
;
364 new_height
+= wwin
->frame
->bottom_width
- 1;
367 new_y
= wwin
->frame_y
;
368 new_height
= wwin
->frame
->core
->height
;
371 if (!WFLAGP(wwin
, full_maximize
)) {
372 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
375 if (directions
& MAX_MAXIMUS
) {
376 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
377 new_width
-= adj_size
;
378 new_height
-= adj_size
;
379 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
380 new_y
-= wwin
->frame
->top_width
;
381 new_height
+= wwin
->frame
->top_width
- 1;
385 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
387 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
388 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
390 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
391 wWindowSynthConfigureNotify(wwin
);
393 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
395 /* set maximization state */
396 wwin
->flags
.maximized
= directions
;
399 /* the window boundary coordinates */
409 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
411 obs
->left
= wwin
->frame_x
;
412 obs
->top
= wwin
->frame_y
;
413 obs
->width
= wwin
->frame
->core
->width
;
414 obs
->height
= wwin
->frame
->core
->height
;
415 obs
->bottom
= obs
->top
+ obs
->height
;
416 obs
->right
= obs
->left
+ obs
->width
;
420 * Maximus: tiled maximization (maximize without overlapping other windows)
422 * The original window 'orig' will be maximized to new coordinates 'new'.
423 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
425 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
426 unsigned int *new_width
, unsigned int *new_height
)
429 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
430 short int adjust_height
;
431 int x_intsect
, y_intsect
;
432 /* the obstructing, original and new windows */
433 win_coords obs
, orig
, new;
435 /* set the original coordinate positions of the window to be Maximumized */
436 set_window_coords(wwin
, &orig
);
438 /* Try to fully maximize first, then readjust later */
439 new.left
= usableArea
.x1
;
440 new.right
= usableArea
.x2
;
441 new.top
= usableArea
.y1
;
442 new.bottom
= usableArea
.y2
;
444 if (HAS_TITLEBAR(wwin
))
445 tbar_height_0
= TITLEBAR_HEIGHT
;
446 if (HAS_RESIZEBAR(wwin
))
447 rbar_height_0
= RESIZEBAR_HEIGHT
;
448 if (HAS_BORDER(wwin
))
449 bd_width_0
= FRAME_BORDER_WIDTH
;
451 /* the length to be subtracted if the window has titlebar, etc */
452 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
455 /* The focused window is always the last in the list */
457 /* ignore windows in other workspaces etc */
458 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
459 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
465 /* Set the coordinates of obstructing window */
466 set_window_coords(tmp
, &obs
);
468 /* Try to maximize in the y direction first */
469 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
470 if (x_intsect
!= 0) {
471 /* TODO: Consider the case when coords are equal */
472 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
473 /* w_0 is below the bottom of w_j */
474 new.top
= obs
.bottom
+ 1;
476 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
477 /* The bottom of w_0 is above the top of w_j */
478 new.bottom
= obs
.top
- 1;
485 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
486 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
492 set_window_coords(tmp
, &obs
);
495 * Use the new.top and new.height instead of original values
496 * as they may have different intersections with the obstructing windows
498 new.height
= new.bottom
- new.top
- adjust_height
;
499 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
500 if (y_intsect
!= 0) {
501 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
502 /* w_0 is completely to the right of w_j */
503 new.left
= obs
.right
+ 1;
505 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
506 /* w_0 is completely to the left of w_j */
507 new.right
= obs
.left
- 1;
514 /* xcalc needs -7 here, but other apps don't */
515 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
516 *new_width
= new.right
- new.left
;
519 void wUnmaximizeWindow(WWindow
*wwin
)
522 WMRect old_geom_rect
;
526 if (!wwin
->flags
.maximized
)
529 if (wwin
->flags
.shaded
) {
530 wwin
->flags
.skip_next_animation
= 1;
531 wUnshadeWindow(wwin
);
533 /* Use old coordinates if they are set, current values otherwise */
534 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
535 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
536 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
537 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
538 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
539 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
540 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
542 wwin
->flags
.maximized
= 0;
543 wWindowConfigure(wwin
, x
, y
, w
, h
);
544 wWindowSynthConfigureNotify(wwin
);
546 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
549 void wFullscreenWindow(WWindow
*wwin
)
554 if (wwin
->flags
.fullscreen
)
557 wwin
->flags
.fullscreen
= True
;
559 wWindowConfigureBorders(wwin
);
561 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
563 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
564 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
565 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
566 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
568 head
= wGetHeadForWindow(wwin
);
569 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
570 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
572 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
575 void wUnfullscreenWindow(WWindow
*wwin
)
577 if (!wwin
->flags
.fullscreen
)
580 wwin
->flags
.fullscreen
= False
;
582 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
583 if (WFLAGP(wwin
, sunken
)) {
584 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
585 } else if (WFLAGP(wwin
, floating
)) {
586 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
588 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
592 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
593 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
595 wWindowConfigureBorders(wwin
);
597 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
598 wFrameWindowPaint(wwin->frame);
601 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
605 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
607 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
608 float cx
, cy
, cw
, ch
;
609 float xstep
, ystep
, wstep
, hstep
;
612 float angle
, final_angle
, delta
;
614 xstep
= (float)(fx
- x
) / steps
;
615 ystep
= (float)(fy
- y
) / steps
;
616 wstep
= (float)(fw
- w
) / steps
;
617 hstep
= (float)(fh
- h
) / steps
;
624 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
625 delta
= (float)(final_angle
/ FRAMES
);
626 for (angle
= 0;; angle
+= delta
) {
627 if (angle
> final_angle
)
630 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
631 dch
= (ch
/ 2) * cos(angle
);
632 midy
= cy
+ (ch
/ 2);
634 points
[0].x
= cx
+ dx
;
635 points
[0].y
= midy
- dch
;
636 points
[1].x
= cx
+ cw
- dx
;
637 points
[1].y
= points
[0].y
;
638 points
[2].x
= cx
+ cw
+ dx
;
639 points
[2].y
= midy
+ dch
;
640 points
[3].x
= cx
- dx
;
641 points
[3].y
= points
[2].y
;
642 points
[4].x
= points
[0].x
;
643 points
[4].y
= points
[0].y
;
646 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
648 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
650 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
656 if (angle
>= final_angle
)
666 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
668 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
669 float cx
, cy
, cw
, ch
;
670 float xstep
, ystep
, wstep
, hstep
;
672 float angle
, final_angle
, a
, d
, delta
;
679 xstep
= (float)(fx
- x
) / steps
;
680 ystep
= (float)(fy
- y
) / steps
;
681 wstep
= (float)(fw
- w
) / steps
;
682 hstep
= (float)(fh
- h
) / steps
;
689 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
690 delta
= (float)(final_angle
/ FRAMES
);
691 for (angle
= 0;; angle
+= delta
) {
692 if (angle
> final_angle
)
696 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
698 points
[0].x
= cx
+ cos(angle
- a
) * d
;
699 points
[0].y
= cy
+ sin(angle
- a
) * d
;
700 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
701 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
702 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
703 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
704 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
705 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
706 points
[4].x
= cx
+ cos(angle
- a
) * d
;
707 points
[4].y
= cy
+ sin(angle
- a
) * d
;
709 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
711 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
713 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
719 if (angle
>= final_angle
)
728 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
730 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
731 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
732 float xstep
, ystep
, wstep
, hstep
;
735 xstep
= (float)(fx
- x
) / steps
;
736 ystep
= (float)(fy
- y
) / steps
;
737 wstep
= (float)(fw
- w
) / steps
;
738 hstep
= (float)(fh
- h
) / steps
;
740 for (j
= 0; j
< FRAMES
; j
++) {
747 for (i
= 0; i
< steps
; i
++) {
748 for (j
= 0; j
< FRAMES
; j
++) {
749 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
750 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
753 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
755 for (j
= 0; j
< FRAMES
; j
++) {
756 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
757 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
758 if (j
< FRAMES
- 1) {
772 for (j
= 0; j
< FRAMES
; j
++) {
773 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
776 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
778 for (j
= 0; j
< FRAMES
; j
++) {
779 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
787 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
789 int style
= wPreferences
.iconification_style
; /* Catch the value */
792 if (style
== WIS_NONE
)
795 if (style
== WIS_RANDOM
) {
801 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
803 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
806 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
808 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
812 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
814 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
818 #endif /* ANIMATIONS */
820 static void flushExpose(void)
824 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
825 WMHandleEvent(&tmpev
);
829 static void unmapTransientsFor(WWindow
*wwin
)
833 tmp
= wwin
->screen_ptr
->focused_window
;
835 /* unmap the transients for this transient */
836 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
837 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
838 unmapTransientsFor(tmp
);
839 tmp
->flags
.miniaturized
= 1;
840 if (!tmp
->flags
.shaded
) {
843 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
846 if (!tmp->flags.shaded)
848 wClientSetState(tmp
, IconicState
, None
);
850 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
856 static void mapTransientsFor(WWindow
*wwin
)
860 tmp
= wwin
->screen_ptr
->focused_window
;
862 /* recursively map the transients for this transient */
863 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
864 && tmp
->icon
== NULL
) {
865 mapTransientsFor(tmp
);
866 tmp
->flags
.miniaturized
= 0;
867 if (!tmp
->flags
.shaded
) {
870 XMapWindow(dpy
, tmp
->frame
->core
->window
);
872 tmp
->flags
.semi_focused
= 0;
874 if (!tmp->flags.shaded)
876 wClientSetState(tmp
, NormalState
, None
);
878 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
884 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
891 /* hackish way to detect transient_for cycle */
892 i
= wwin
->screen_ptr
->window_count
+ 1;
894 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
895 wwin
= wWindowFor(wwin
->transient_for
);
898 if (i
== 0 && wwin
) {
899 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
906 void wIconifyWindow(WWindow
* wwin
)
908 XWindowAttributes attribs
;
911 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
912 /* the window doesn't exist anymore */
916 if (wwin
->flags
.miniaturized
) {
920 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
921 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
923 if (owner
&& owner
->flags
.miniaturized
)
927 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
929 /* if the window is in another workspace, simplify process */
931 /* icon creation may take a while */
932 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
933 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
934 GrabModeAsync
, None
, None
, CurrentTime
);
937 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
938 if (!wwin
->flags
.icon_moved
) {
939 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
941 wwin
->icon
= wIconCreate(wwin
);
943 wwin
->icon
->mapped
= 1;
946 wwin
->flags
.miniaturized
= 1;
947 wwin
->flags
.mapped
= 0;
949 /* unmap transients */
951 unmapTransientsFor(wwin
);
954 XUngrabPointer(dpy
, CurrentTime
);
956 /* let all Expose events arrive so that we can repaint
957 * something before the animation starts (and the server is grabbed) */
960 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
961 wClientSetState(wwin
, IconicState
, None
);
963 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
967 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
968 && !wPreferences
.no_animations
) {
971 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
974 iw
= wwin
->icon
->core
->width
;
975 ih
= wwin
->icon
->core
->height
;
977 if (wwin
->flags
.net_handle_icon
) {
985 iw
= wwin
->screen_ptr
->scr_width
;
986 ih
= wwin
->screen_ptr
->scr_height
;
989 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
990 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
995 wwin
->flags
.skip_next_animation
= 0;
997 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
998 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
999 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1001 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1003 AddToStackList(wwin
->icon
->core
);
1005 wLowerFrame(wwin
->icon
->core
);
1009 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1012 * It doesn't seem to be working and causes button event hangup
1013 * when deiconifying a transient window.
1014 setupIconGrabs(wwin->icon);
1016 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1017 && wPreferences
.focus_mode
== WKF_CLICK
) {
1022 if (!WFLAGP(tmp
, no_focusable
)
1023 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1024 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1028 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1029 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1030 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1033 if (!wwin
->screen_ptr
->flags
.startup
) {
1034 /* Catch up with events not processed while animation was running */
1035 Window clientwin
= wwin
->client_win
;
1037 ProcessPendingEvents();
1039 /* the window can disappear while ProcessPendingEvents() runs */
1040 if (!wWindowFor(clientwin
)) {
1047 /* maybe we want to do this regardless of net_handle_icon
1048 * it seems to me we might break behaviour this way.
1050 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1051 && !wwin
->flags
.net_handle_icon
)
1052 wIconSelect(wwin
->icon
);
1054 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1056 if (wPreferences
.auto_arrange_icons
)
1057 wArrangeIcons(wwin
->screen_ptr
, True
);
1060 void wDeiconifyWindow(WWindow
*wwin
)
1062 /* Let's avoid changing workspace while deiconifying */
1063 ignore_wks_change
= 1;
1065 /* we're hiding for show_desktop */
1066 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1067 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1070 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1072 if (!wwin
->flags
.miniaturized
)
1075 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1076 WWindow
*owner
= recursiveTransientFor(wwin
);
1078 if (owner
&& owner
->flags
.miniaturized
) {
1079 wDeiconifyWindow(owner
);
1080 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1081 wRaiseFrame(wwin
->frame
->core
);
1086 wwin
->flags
.miniaturized
= 0;
1088 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1089 wwin
->flags
.mapped
= 1;
1092 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1093 /* maybe we want to do this regardless of net_handle_icon
1094 * it seems to me we might break behaviour this way.
1096 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1097 && wwin
->icon
!= NULL
) {
1098 if (wwin
->icon
->selected
)
1099 wIconSelect(wwin
->icon
);
1101 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1105 /* if the window is in another workspace, do it silently */
1106 if (!netwm_hidden
) {
1108 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1109 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1112 if (!wPreferences
.disable_miniwindows
1113 && !wwin
->flags
.net_handle_icon
) {
1116 iw
= wwin
->icon
->core
->width
;
1117 ih
= wwin
->icon
->core
->height
;
1119 if (wwin
->flags
.net_handle_icon
) {
1127 iw
= wwin
->screen_ptr
->scr_width
;
1128 ih
= wwin
->screen_ptr
->scr_height
;
1131 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1132 wwin
->frame_x
, wwin
->frame_y
,
1133 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1135 #endif /* ANIMATIONS */
1136 wwin
->flags
.skip_next_animation
= 0;
1138 if (!wwin
->flags
.shaded
) {
1139 XMapWindow(dpy
, wwin
->client_win
);
1141 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1142 wRaiseFrame(wwin
->frame
->core
);
1143 if (!wwin
->flags
.shaded
) {
1144 wClientSetState(wwin
, NormalState
, None
);
1146 mapTransientsFor(wwin
);
1149 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1150 && !wwin
->flags
.net_handle_icon
) {
1151 RemoveFromStackList(wwin
->icon
->core
);
1152 /* removeIconGrabs(wwin->icon); */
1153 wIconDestroy(wwin
->icon
);
1157 if (!netwm_hidden
) {
1160 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1163 if (!wwin
->screen_ptr
->flags
.startup
) {
1164 /* Catch up with events not processed while animation was running */
1165 Window clientwin
= wwin
->client_win
;
1167 ProcessPendingEvents();
1169 /* the window can disappear while ProcessPendingEvents() runs */
1170 if (!wWindowFor(clientwin
)) {
1177 if (wPreferences
.auto_arrange_icons
) {
1178 wArrangeIcons(wwin
->screen_ptr
, True
);
1181 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1183 /* In case we were shaded and iconified, also unshade */
1185 wUnshadeWindow(wwin
);
1187 ignore_wks_change
= 0;
1190 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1192 if (wwin
->flags
.miniaturized
) {
1194 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1195 wwin
->icon
->mapped
= 0;
1197 wwin
->flags
.hidden
= 1;
1199 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1203 if (wwin
->flags
.inspector_open
) {
1204 wHideInspectorForWindow(wwin
);
1207 wwin
->flags
.hidden
= 1;
1210 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1214 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1215 !wwin
->flags
.skip_next_animation
&& animate
) {
1216 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1217 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1218 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1221 wwin
->flags
.skip_next_animation
= 0;
1223 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1226 void wHideAll(WScreen
*scr
)
1231 unsigned int wcount
= 0;
1237 menu
= scr
->switch_menu
;
1239 windows
= malloc(sizeof(WWindow
*));
1242 for (i
= 0; i
< menu
->entry_no
; i
++) {
1243 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1245 windows
= realloc(windows
, sizeof(WWindow
*) * (wcount
+1));
1248 wwin
= scr
->focused_window
;
1251 windows
[wcount
] = wwin
;
1253 windows
= realloc(windows
, sizeof(WWindow
*) * (wcount
+1));
1259 for (i
= 0; i
< wcount
; i
++) {
1261 if (wwin
->frame
->workspace
== scr
->current_workspace
1262 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1263 && !wwin
->flags
.internal_window
1264 && !WFLAGP(wwin
, no_miniaturizable
)
1266 wwin
->flags
.skip_next_animation
= 1;
1267 wIconifyWindow(wwin
);
1272 void wHideOtherApplications(WWindow
*awin
)
1279 wwin
= awin
->screen_ptr
->focused_window
;
1283 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1284 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1285 && !wwin
->flags
.internal_window
1286 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1288 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1289 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1290 wwin
->flags
.skip_next_animation
= 1;
1291 wIconifyWindow(wwin
);
1293 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1294 tapp
= wApplicationOf(wwin
->main_window
);
1296 tapp
->flags
.skip_next_animation
= 1;
1297 wHideApplication(tapp
);
1299 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1300 wwin
->flags
.skip_next_animation
= 1;
1301 wIconifyWindow(wwin
);
1309 wSetFocusTo(awin->screen_ptr, awin);
1313 void wHideApplication(WApplication
*wapp
)
1321 wwarning("trying to hide a non grouped window");
1324 if (!wapp
->main_window_desc
) {
1325 wwarning("group leader not found for window group");
1328 scr
= wapp
->main_window_desc
->screen_ptr
;
1330 wlist
= scr
->focused_window
;
1334 if (wlist
->main_window
== wapp
->main_window
)
1335 wapp
->last_focused
= wlist
;
1337 wapp
->last_focused
= NULL
;
1339 animate
= !wapp
->flags
.skip_next_animation
;
1342 if (wlist
->main_window
== wapp
->main_window
) {
1343 if (wlist
->flags
.focused
) {
1346 if (wapp
->app_icon
) {
1347 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1348 wapp
->app_icon
->y_pos
, wlist
, animate
);
1352 wlist
= wlist
->prev
;
1355 wapp
->flags
.skip_next_animation
= 0;
1358 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1359 wlist
= scr
->focused_window
;
1361 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1362 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1364 wlist
= wlist
->prev
;
1366 wSetFocusTo(scr
, wlist
);
1368 wSetFocusTo(scr
, NULL
);
1372 wapp
->flags
.hidden
= 1;
1374 if (wPreferences
.auto_arrange_icons
) {
1375 wArrangeIcons(scr
, True
);
1379 wAppIconPaint(wapp
->app_icon
);
1383 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1385 if (bringToCurrentWS
)
1386 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1388 wwin
->flags
.hidden
= 0;
1391 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1392 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1393 icon
->core
->width
, icon
->core
->height
,
1394 wwin
->frame_x
, wwin
->frame_y
,
1395 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1398 wwin
->flags
.skip_next_animation
= 0;
1399 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1400 XMapWindow(dpy
, wwin
->client_win
);
1401 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1402 wClientSetState(wwin
, NormalState
, None
);
1403 wwin
->flags
.mapped
= 1;
1404 wRaiseFrame(wwin
->frame
->core
);
1406 if (wwin
->flags
.inspector_open
) {
1407 wUnhideInspectorForWindow(wwin
);
1410 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1413 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1416 WWindow
*wlist
, *next
;
1417 WWindow
*focused
= NULL
;
1423 scr
= wapp
->main_window_desc
->screen_ptr
;
1424 wlist
= scr
->focused_window
;
1428 /* goto beginning of list */
1430 wlist
= wlist
->prev
;
1432 animate
= !wapp
->flags
.skip_next_animation
;
1437 if (wlist
->main_window
== wapp
->main_window
) {
1438 if (wlist
->flags
.focused
)
1440 else if (!focused
|| !focused
->flags
.focused
)
1443 if (wlist
->flags
.miniaturized
) {
1444 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1445 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1446 if (!wlist
->icon
->mapped
) {
1449 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1450 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1451 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1455 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1456 wlist
->icon
->mapped
= 1;
1458 wRaiseFrame(wlist
->icon
->core
);
1460 if (bringToCurrentWS
)
1461 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1462 wlist
->flags
.hidden
= 0;
1463 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1464 wDeiconifyWindow(wlist
);
1466 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1467 } else if (wlist
->flags
.shaded
) {
1468 if (bringToCurrentWS
)
1469 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1470 wlist
->flags
.hidden
= 0;
1471 wRaiseFrame(wlist
->frame
->core
);
1472 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1473 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1475 wUnshadeWindow(wlist
);
1478 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1479 } else if (wlist
->flags
.hidden
) {
1480 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1481 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1484 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1485 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1487 wRaiseFrame(wlist
->frame
->core
);
1493 wapp
->flags
.skip_next_animation
= 0;
1494 wapp
->flags
.hidden
= 0;
1496 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1497 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1498 wSetFocusTo(scr
, wapp
->last_focused
);
1499 } else if (focused
) {
1500 wSetFocusTo(scr
, focused
);
1502 wapp
->last_focused
= NULL
;
1503 if (wPreferences
.auto_arrange_icons
) {
1504 wArrangeIcons(scr
, True
);
1507 wAppIconPaint(wapp
->app_icon
);
1511 void wShowAllWindows(WScreen
*scr
)
1513 WWindow
*wwin
, *old_foc
;
1516 old_foc
= wwin
= scr
->focused_window
;
1518 if (!wwin
->flags
.internal_window
&&
1519 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1520 if (wwin
->flags
.miniaturized
) {
1521 wwin
->flags
.skip_next_animation
= 1;
1522 wDeiconifyWindow(wwin
);
1523 } else if (wwin
->flags
.hidden
) {
1524 wapp
= wApplicationOf(wwin
->main_window
);
1526 wUnhideApplication(wapp
, False
, False
);
1528 wwin
->flags
.skip_next_animation
= 1;
1529 wDeiconifyWindow(wwin
);
1535 wSetFocusTo(scr
, old_foc
);
1536 /*wRaiseFrame(old_foc->frame->core); */
1539 void wRefreshDesktop(WScreen
*scr
)
1542 XSetWindowAttributes attr
;
1544 attr
.backing_store
= NotUseful
;
1545 attr
.save_under
= False
;
1546 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1547 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1548 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1549 XMapRaised(dpy
, win
);
1550 XDestroyWindow(dpy
, win
);
1554 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1560 const int heads
= wXineramaHeads(scr
);
1563 int pf
; /* primary axis */
1564 int sf
; /* secondary axis */
1568 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1574 int isize
= wPreferences
.icon_size
;
1576 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1578 for (head
= 0; head
< heads
; ++head
) {
1579 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1580 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1581 vars
[head
].pi
= vars
[head
].si
= 0;
1582 vars
[head
].sx1
= rect
.pos
.x
;
1583 vars
[head
].sy1
= rect
.pos
.y
;
1584 vars
[head
].sw
= rect
.size
.width
;
1585 vars
[head
].sh
= rect
.size
.height
;
1586 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1587 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1588 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1589 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1590 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1591 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1593 /* icon yard boundaries */
1594 if (wPreferences
.icon_yard
& IY_VERT
) {
1595 vars
[head
].pf
= vars
[head
].fullH
;
1596 vars
[head
].sf
= vars
[head
].fullW
;
1598 vars
[head
].pf
= vars
[head
].fullW
;
1599 vars
[head
].sf
= vars
[head
].fullH
;
1601 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1602 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1605 vars
[head
].xo
= vars
[head
].sx1
;
1608 if (wPreferences
.icon_yard
& IY_TOP
) {
1609 vars
[head
].yo
= vars
[head
].sy1
;
1612 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1617 #define X ((wPreferences.icon_yard & IY_VERT) \
1618 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1619 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1621 #define Y ((wPreferences.icon_yard & IY_VERT) \
1622 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1623 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1625 /* arrange application icons */
1626 aicon
= scr
->app_icon_list
;
1627 /* reverse them to avoid unnecessarily sliding of icons */
1628 while (aicon
&& aicon
->next
)
1629 aicon
= aicon
->next
;
1632 if (!aicon
->docked
) {
1633 /* CHECK: can icon be NULL here ? */
1634 /* The intention here is to place the AppIcon on the head that
1635 * contains most of the applications _main_ window. */
1636 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1638 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1640 if (!wPreferences
.no_animations
) {
1641 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1643 #endif /* ANIMATIONS */
1645 wAppIconMove(aicon
, X
, Y
);
1647 if (vars
[head
].pi
>= vars
[head
].pf
) {
1652 aicon
= aicon
->prev
;
1655 /* arrange miniwindows */
1656 wwin
= scr
->focused_window
;
1657 /* reverse them to avoid unnecessarily shuffling */
1658 while (wwin
&& wwin
->prev
)
1662 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1663 (wwin
->frame
->workspace
== scr
->current_workspace
||
1664 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1666 head
= wGetHeadForWindow(wwin
);
1668 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1669 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1671 if (wPreferences
.no_animations
) {
1672 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1674 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1675 wwin
->icon_y
, X
, Y
);
1678 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1679 #endif /* ANIMATIONS */
1685 if (vars
[head
].pi
>= vars
[head
].pf
) {
1692 wwin
->flags
.icon_moved
= 0;
1694 /* we reversed the order, so we use next */
1701 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1703 WScreen
*scr
= wwin
->screen_ptr
;
1706 wwin
->flags
.selected
= 1;
1707 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1709 if (!HAS_BORDER(wwin
)) {
1710 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1713 if (!scr
->selected_windows
)
1714 scr
->selected_windows
= WMCreateArray(4);
1715 WMAddToArray(scr
->selected_windows
, wwin
);
1717 wwin
->flags
.selected
= 0;
1718 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1720 if (!HAS_BORDER(wwin
)) {
1721 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1724 if (scr
->selected_windows
) {
1725 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1730 void wMakeWindowVisible(WWindow
*wwin
)
1732 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1733 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1735 if (wwin
->flags
.shaded
) {
1736 wUnshadeWindow(wwin
);
1738 if (wwin
->flags
.hidden
) {
1741 app
= wApplicationOf(wwin
->main_window
);
1743 /* trick to get focus to this window */
1744 app
->last_focused
= wwin
;
1745 wUnhideApplication(app
, False
, False
);
1748 if (wwin
->flags
.miniaturized
) {
1749 wDeiconifyWindow(wwin
);
1751 if (!WFLAGP(wwin
, no_focusable
))
1752 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1753 wRaiseFrame(wwin
->frame
->core
);
1758 * Do the animation while shading (called with what = SHADE)
1759 * or unshading (what = UNSHADE).
1762 static void shade_animate(WWindow
*wwin
, Bool what
)
1765 time_t time0
= time(NULL
);
1767 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1772 if (!wwin
->screen_ptr
->flags
.startup
) {
1773 /* do the shading animation */
1774 h
= wwin
->frame
->core
->height
;
1775 s
= h
/ SHADE_STEPS
;
1778 w
= wwin
->frame
->core
->width
;
1779 y
= wwin
->frame
->top_width
;
1780 while (h
> wwin
->frame
->top_width
+ 1) {
1781 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1782 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1785 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1788 if (SHADE_DELAY
> 0) {
1789 wusleep(SHADE_DELAY
* 1000L);
1796 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1801 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1802 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1803 s
= abs(y
) / SHADE_STEPS
;
1806 w
= wwin
->frame
->core
->width
;
1807 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1809 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1810 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1811 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1813 if (SHADE_DELAY
> 0) {
1814 wusleep(SHADE_DELAY
* 2000L / 3);
1821 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1825 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);