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"
51 /****** Global Variables ******/
53 int ignore_wks_change
= 0;
54 extern Time LastTimestamp
;
55 extern Time LastFocusChange
;
57 extern Cursor wCursor
[WCUR_LAST
];
59 extern WPreferences wPreferences
;
61 extern Atom _XA_WM_TAKE_FOCUS
;
63 extern void ProcessPendingEvents();
64 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
66 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
67 unsigned int *new_width
, unsigned int *new_height
);
68 static void save_old_geometry(WWindow
*wwin
);
70 /******* Local Variables *******/
76 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
77 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
78 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
79 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
80 SHADE_STEPS_US
, SHADE_DELAY_US
}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
87 static int compareTimes(Time t1
, Time t2
)
93 return (diff
< 60000) ? 1 : -1;
97 static void shade_animate(WWindow
*wwin
, Bool what
);
99 static void shade_animate(WWindow
*wwin
, Bool what
) { }
103 *----------------------------------------------------------------------
105 * Changes the window focus to the one passed as argument.
106 * If the window to focus is not already focused, it will be brought
107 * to the head of the list of windows. Previously focused window is
111 * Window list may be reordered and the window focus is changed.
113 *----------------------------------------------------------------------
115 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
117 static WScreen
*old_scr
= NULL
;
119 WWindow
*old_focused
;
120 WWindow
*focused
= scr
->focused_window
;
121 Time timestamp
= LastTimestamp
;
122 WApplication
*oapp
= NULL
, *napp
= NULL
;
125 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
130 old_focused
= old_scr
->focused_window
;
132 LastFocusChange
= timestamp
;
135 oapp
= wApplicationOf(old_focused
->main_window
);
138 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
140 wWindowUnfocus(old_focused
);
142 wAppMenuUnmap(oapp
->menu
);
144 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
146 } else if (old_scr
!= scr
&& old_focused
) {
147 wWindowUnfocus(old_focused
);
150 wasfocused
= wwin
->flags
.focused
;
151 napp
= wApplicationOf(wwin
->main_window
);
153 /* remember last workspace where the app has been */
155 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
156 napp
->last_workspace
= wwin
->frame
->workspace
;
159 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
160 /* install colormap if colormap mode is lock mode */
161 if (wPreferences
.colormap_mode
== WCM_CLICK
)
162 wColormapInstallForWindow(scr
, wwin
);
164 /* set input focus */
165 switch (wwin
->focus_mode
) {
167 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
171 case WFM_LOCALLY_ACTIVE
:
172 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
175 case WFM_GLOBALLY_ACTIVE
:
179 if (wwin
->protocols
.TAKE_FOCUS
) {
180 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
184 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
186 if (WFLAGP(wwin
, no_focusable
))
189 /* if this is not the focused window focus it */
190 if (focused
!= wwin
) {
191 /* change the focus window list order */
193 wwin
->prev
->next
= wwin
->next
;
196 wwin
->next
->prev
= wwin
->prev
;
198 wwin
->prev
= focused
;
199 focused
->next
= wwin
;
201 scr
->focused_window
= wwin
;
203 if (oapp
&& oapp
!= napp
)
204 wAppMenuUnmap(oapp
->menu
);
207 wWindowFocus(wwin
, focused
);
209 if (napp
&& !wasfocused
) {
211 wUserMenuRefreshInstances(napp
->menu
, wwin
);
212 #endif /* USER_MENU */
214 if (wwin
->flags
.mapped
)
215 wAppMenuMap(napp
->menu
, wwin
);
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
);
393 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
395 /* set maximization state */
396 wwin
->flags
.maximized
= directions
;
400 * Maximus: tiled maximization (maximize without overlapping other windows)
402 * The window to be maximized will be denoted by w_0 (sub-index zero)
403 * while the windows which will stop the maximization of w_0 are denoted by w_j.
405 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
406 unsigned int *new_width
, unsigned int *new_height
)
409 int x_0
= wwin
->frame_x
;
410 int y_0
= wwin
->frame_y
;
411 int width_0
= wwin
->frame
->core
->width
;
412 int height_0
= wwin
->frame
->core
->height
;
413 int bottom_0
= y_0
+ height_0
;
414 int right_border_0
= x_0
+ width_0
;
415 int new_x_0
, new_y_0
, new_bottom_0
, new_right_border_0
, new_height_0
;
416 int x_j
, y_j
, width_j
, height_j
, bottom_j
, top_j
, right_border_j
;
417 int x_intsect
, y_intsect
;
418 short int tbar_height_0
= 0, rbar_height_0
= 0;
419 short int bd_width_0
= 0;
420 short int adjust_height
;
422 /* Try to fully maximize first, then readjust later */
423 new_x_0
= usableArea
.x1
;
424 new_y_0
= usableArea
.y1
;
425 new_bottom_0
= usableArea
.y2
;
426 new_right_border_0
= usableArea
.x2
;
428 if (HAS_TITLEBAR(wwin
))
429 tbar_height_0
= TITLEBAR_HEIGHT
;
430 if (HAS_RESIZEBAR(wwin
))
431 rbar_height_0
= RESIZEBAR_HEIGHT
;
432 if (HAS_BORDER(wwin
))
433 bd_width_0
= FRAME_BORDER_WIDTH
;
435 /* the length to be subtracted if w_0 has titlebar, etc */
436 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
439 /* The focused window is always the last in the list */
441 /* ignore windows in other workspaces etc */
442 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
443 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
450 * Set the w_j window coordinates. It is convenient
451 * to not use "corrected" sizes for width and height,
452 * otherwise bottom_j and right_border_j would be
457 width_j
= tmp
->frame
->core
->width
;
458 height_j
= tmp
->frame
->core
->height
;
459 bottom_j
= y_j
+ height_j
;
461 right_border_j
= x_j
+ width_j
;
463 /* Try to maximize in the y direction first */
464 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
465 if (x_intsect
!= 0) {
466 /* TODO: Consider the case when coords are equal */
467 if (bottom_j
< y_0
&& bottom_j
> new_y_0
) {
468 /* w_0 is below the bottom of w_j */
469 new_y_0
= bottom_j
+ 1;
471 if (bottom_0
< top_j
&& top_j
< new_bottom_0
) {
472 /* The bottom of w_0 is above the top of w_j */
473 new_bottom_0
= top_j
- 1;
480 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
481 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
487 /* set the w_j window coordinates */
490 width_j
= tmp
->frame
->core
->width
;
491 height_j
= tmp
->frame
->core
->height
;
492 bottom_j
= y_j
+ height_j
;
494 right_border_j
= x_j
+ width_j
;
497 * Use the updated y coordinates from the above step to account
498 * the possibility that the new value of y_0 will have different
499 * intersections with w_j
501 new_height_0
= new_bottom_0
- new_y_0
- adjust_height
;
502 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
503 if (y_intsect
!= 0) {
504 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
505 /* w_0 is completely to the right of w_j */
506 new_x_0
= right_border_j
+ 1;
508 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
509 /* w_0 is completely to the left of w_j */
510 new_right_border_0
= x_j
- 1;
515 /* xcalc needs -7 here, but other apps don't */
516 new_height_0
= new_bottom_0
- new_y_0
- adjust_height
- 1;
519 *new_height
= new_height_0
;
520 *new_width
= new_right_border_0
- new_x_0
;
523 void wUnmaximizeWindow(WWindow
*wwin
)
526 WMRect old_geom_rect
;
530 if (!wwin
->flags
.maximized
)
533 if (wwin
->flags
.shaded
) {
534 wwin
->flags
.skip_next_animation
= 1;
535 wUnshadeWindow(wwin
);
537 /* Use old coordinates if they are set, current values otherwise */
538 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
539 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
540 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
541 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
542 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
543 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
544 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
546 wwin
->flags
.maximized
= 0;
547 wWindowConfigure(wwin
, x
, y
, w
, h
);
549 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
552 void wFullscreenWindow(WWindow
*wwin
)
557 if (wwin
->flags
.fullscreen
)
560 wwin
->flags
.fullscreen
= True
;
562 wWindowConfigureBorders(wwin
);
564 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
566 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
567 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
568 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
569 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
571 head
= wGetHeadForWindow(wwin
);
572 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
573 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
575 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
578 void wUnfullscreenWindow(WWindow
*wwin
)
580 if (!wwin
->flags
.fullscreen
)
583 wwin
->flags
.fullscreen
= False
;
585 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
586 if (WFLAGP(wwin
, sunken
)) {
587 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
588 } else if (WFLAGP(wwin
, floating
)) {
589 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
591 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
595 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
596 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
598 wWindowConfigureBorders(wwin
);
600 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
601 wFrameWindowPaint(wwin->frame);
604 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
608 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
610 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
611 float cx
, cy
, cw
, ch
;
612 float xstep
, ystep
, wstep
, hstep
;
615 float angle
, final_angle
, delta
;
617 xstep
= (float)(fx
- x
) / steps
;
618 ystep
= (float)(fy
- y
) / steps
;
619 wstep
= (float)(fw
- w
) / steps
;
620 hstep
= (float)(fh
- h
) / steps
;
627 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
628 delta
= (float)(final_angle
/ FRAMES
);
629 for (angle
= 0;; angle
+= delta
) {
630 if (angle
> final_angle
)
633 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
634 dch
= (ch
/ 2) * cos(angle
);
635 midy
= cy
+ (ch
/ 2);
637 points
[0].x
= cx
+ dx
;
638 points
[0].y
= midy
- dch
;
639 points
[1].x
= cx
+ cw
- dx
;
640 points
[1].y
= points
[0].y
;
641 points
[2].x
= cx
+ cw
+ dx
;
642 points
[2].y
= midy
+ dch
;
643 points
[3].x
= cx
- dx
;
644 points
[3].y
= points
[2].y
;
645 points
[4].x
= points
[0].x
;
646 points
[4].y
= points
[0].y
;
649 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
651 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
653 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
659 if (angle
>= final_angle
)
669 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
671 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
672 float cx
, cy
, cw
, ch
;
673 float xstep
, ystep
, wstep
, hstep
;
675 float angle
, final_angle
, a
, d
, delta
;
682 xstep
= (float)(fx
- x
) / steps
;
683 ystep
= (float)(fy
- y
) / steps
;
684 wstep
= (float)(fw
- w
) / steps
;
685 hstep
= (float)(fh
- h
) / steps
;
692 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
693 delta
= (float)(final_angle
/ FRAMES
);
694 for (angle
= 0;; angle
+= delta
) {
695 if (angle
> final_angle
)
699 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
701 points
[0].x
= cx
+ cos(angle
- a
) * d
;
702 points
[0].y
= cy
+ sin(angle
- a
) * d
;
703 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
704 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
705 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
706 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
707 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
708 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
709 points
[4].x
= cx
+ cos(angle
- a
) * d
;
710 points
[4].y
= cy
+ sin(angle
- a
) * d
;
712 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
714 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
716 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
722 if (angle
>= final_angle
)
731 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
733 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
734 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
735 float xstep
, ystep
, wstep
, hstep
;
738 xstep
= (float)(fx
- x
) / steps
;
739 ystep
= (float)(fy
- y
) / steps
;
740 wstep
= (float)(fw
- w
) / steps
;
741 hstep
= (float)(fh
- h
) / steps
;
743 for (j
= 0; j
< FRAMES
; j
++) {
750 for (i
= 0; i
< steps
; i
++) {
751 for (j
= 0; j
< FRAMES
; j
++) {
752 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
753 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
756 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
758 for (j
= 0; j
< FRAMES
; j
++) {
759 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
760 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
761 if (j
< FRAMES
- 1) {
775 for (j
= 0; j
< FRAMES
; j
++) {
776 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
779 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
781 for (j
= 0; j
< FRAMES
; j
++) {
782 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
790 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
792 int style
= wPreferences
.iconification_style
; /* Catch the value */
795 if (style
== WIS_NONE
)
798 if (style
== WIS_RANDOM
) {
804 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
806 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
809 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
811 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
815 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
817 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
821 #endif /* ANIMATIONS */
823 static void flushExpose()
827 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
828 WMHandleEvent(&tmpev
);
832 static void unmapTransientsFor(WWindow
*wwin
)
836 tmp
= wwin
->screen_ptr
->focused_window
;
838 /* unmap the transients for this transient */
839 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
840 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
841 unmapTransientsFor(tmp
);
842 tmp
->flags
.miniaturized
= 1;
843 if (!tmp
->flags
.shaded
) {
846 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
849 if (!tmp->flags.shaded)
851 wClientSetState(tmp
, IconicState
, None
);
853 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
859 static void mapTransientsFor(WWindow
*wwin
)
863 tmp
= wwin
->screen_ptr
->focused_window
;
865 /* recursively map the transients for this transient */
866 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
867 && tmp
->icon
== NULL
) {
868 mapTransientsFor(tmp
);
869 tmp
->flags
.miniaturized
= 0;
870 if (!tmp
->flags
.shaded
) {
873 XMapWindow(dpy
, tmp
->frame
->core
->window
);
875 tmp
->flags
.semi_focused
= 0;
877 if (!tmp->flags.shaded)
879 wClientSetState(tmp
, NormalState
, None
);
881 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
887 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
894 /* hackish way to detect transient_for cycle */
895 i
= wwin
->screen_ptr
->window_count
+ 1;
897 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
898 wwin
= wWindowFor(wwin
->transient_for
);
901 if (i
== 0 && wwin
) {
902 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
909 void wIconifyWindow(WWindow
* wwin
)
911 XWindowAttributes attribs
;
914 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
915 /* the window doesn't exist anymore */
919 if (wwin
->flags
.miniaturized
) {
923 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
924 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
926 if (owner
&& owner
->flags
.miniaturized
)
930 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
932 /* if the window is in another workspace, simplify process */
934 /* icon creation may take a while */
935 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
936 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
937 GrabModeAsync
, None
, None
, CurrentTime
);
940 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
941 if (!wwin
->flags
.icon_moved
) {
942 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
944 wwin
->icon
= wIconCreate(wwin
);
946 wwin
->icon
->mapped
= 1;
949 wwin
->flags
.miniaturized
= 1;
950 wwin
->flags
.mapped
= 0;
952 /* unmap transients */
954 unmapTransientsFor(wwin
);
957 XUngrabPointer(dpy
, CurrentTime
);
959 /* let all Expose events arrive so that we can repaint
960 * something before the animation starts (and the server is grabbed) */
963 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
964 wClientSetState(wwin
, IconicState
, None
);
966 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
970 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
971 && !wPreferences
.no_animations
) {
974 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
977 iw
= wwin
->icon
->core
->width
;
978 ih
= wwin
->icon
->core
->height
;
980 if (wwin
->flags
.net_handle_icon
) {
988 iw
= wwin
->screen_ptr
->scr_width
;
989 ih
= wwin
->screen_ptr
->scr_height
;
992 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
993 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
998 wwin
->flags
.skip_next_animation
= 0;
1000 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1001 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1002 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1004 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1006 AddToStackList(wwin
->icon
->core
);
1008 wLowerFrame(wwin
->icon
->core
);
1012 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1015 * It doesn't seem to be working and causes button event hangup
1016 * when deiconifying a transient window.
1017 setupIconGrabs(wwin->icon);
1019 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1020 && wPreferences
.focus_mode
== WKF_CLICK
) {
1025 if (!WFLAGP(tmp
, no_focusable
)
1026 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1027 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1031 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1032 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1033 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1036 if (!wwin
->screen_ptr
->flags
.startup
) {
1037 /* Catch up with events not processed while animation was running */
1038 Window clientwin
= wwin
->client_win
;
1040 ProcessPendingEvents();
1042 /* the window can disappear while ProcessPendingEvents() runs */
1043 if (!wWindowFor(clientwin
)) {
1050 /* maybe we want to do this regardless of net_handle_icon
1051 * it seems to me we might break behaviour this way.
1053 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1054 && !wwin
->flags
.net_handle_icon
)
1055 wIconSelect(wwin
->icon
);
1057 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1059 if (wPreferences
.auto_arrange_icons
)
1060 wArrangeIcons(wwin
->screen_ptr
, True
);
1063 void wDeiconifyWindow(WWindow
*wwin
)
1065 /* Let's avoid changing workspace while deiconifying */
1066 ignore_wks_change
= 1;
1068 /* we're hiding for show_desktop */
1069 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1070 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1073 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1075 if (!wwin
->flags
.miniaturized
)
1078 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1079 WWindow
*owner
= recursiveTransientFor(wwin
);
1081 if (owner
&& owner
->flags
.miniaturized
) {
1082 wDeiconifyWindow(owner
);
1083 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1084 wRaiseFrame(wwin
->frame
->core
);
1089 wwin
->flags
.miniaturized
= 0;
1091 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1092 wwin
->flags
.mapped
= 1;
1095 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1096 /* maybe we want to do this regardless of net_handle_icon
1097 * it seems to me we might break behaviour this way.
1099 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1100 && wwin
->icon
!= NULL
) {
1101 if (wwin
->icon
->selected
)
1102 wIconSelect(wwin
->icon
);
1104 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1108 /* if the window is in another workspace, do it silently */
1109 if (!netwm_hidden
) {
1111 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1112 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1115 if (!wPreferences
.disable_miniwindows
1116 && !wwin
->flags
.net_handle_icon
) {
1119 iw
= wwin
->icon
->core
->width
;
1120 ih
= wwin
->icon
->core
->height
;
1122 if (wwin
->flags
.net_handle_icon
) {
1130 iw
= wwin
->screen_ptr
->scr_width
;
1131 ih
= wwin
->screen_ptr
->scr_height
;
1134 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1135 wwin
->frame_x
, wwin
->frame_y
,
1136 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1138 #endif /* ANIMATIONS */
1139 wwin
->flags
.skip_next_animation
= 0;
1141 if (!wwin
->flags
.shaded
) {
1142 XMapWindow(dpy
, wwin
->client_win
);
1144 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1145 wRaiseFrame(wwin
->frame
->core
);
1146 if (!wwin
->flags
.shaded
) {
1147 wClientSetState(wwin
, NormalState
, None
);
1149 mapTransientsFor(wwin
);
1152 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1153 && !wwin
->flags
.net_handle_icon
) {
1154 RemoveFromStackList(wwin
->icon
->core
);
1155 /* removeIconGrabs(wwin->icon); */
1156 wIconDestroy(wwin
->icon
);
1160 if (!netwm_hidden
) {
1163 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1166 if (!wwin
->screen_ptr
->flags
.startup
) {
1167 /* Catch up with events not processed while animation was running */
1168 Window clientwin
= wwin
->client_win
;
1170 ProcessPendingEvents();
1172 /* the window can disappear while ProcessPendingEvents() runs */
1173 if (!wWindowFor(clientwin
)) {
1180 if (wPreferences
.auto_arrange_icons
) {
1181 wArrangeIcons(wwin
->screen_ptr
, True
);
1184 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1186 /* In case we were shaded and iconified, also unshade */
1188 wUnshadeWindow(wwin
);
1190 ignore_wks_change
= 0;
1193 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1195 if (wwin
->flags
.miniaturized
) {
1197 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1198 wwin
->icon
->mapped
= 0;
1200 wwin
->flags
.hidden
= 1;
1202 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1206 if (wwin
->flags
.inspector_open
) {
1207 wHideInspectorForWindow(wwin
);
1210 wwin
->flags
.hidden
= 1;
1213 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1217 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1218 !wwin
->flags
.skip_next_animation
&& animate
) {
1219 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1220 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1221 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1224 wwin
->flags
.skip_next_animation
= 0;
1226 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1229 void wHideOtherApplications(WWindow
*awin
)
1236 wwin
= awin
->screen_ptr
->focused_window
;
1240 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1241 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1242 && !wwin
->flags
.internal_window
1243 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1245 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1246 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1247 wwin
->flags
.skip_next_animation
= 1;
1248 wIconifyWindow(wwin
);
1250 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1251 tapp
= wApplicationOf(wwin
->main_window
);
1253 tapp
->flags
.skip_next_animation
= 1;
1254 wHideApplication(tapp
);
1256 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1257 wwin
->flags
.skip_next_animation
= 1;
1258 wIconifyWindow(wwin
);
1266 wSetFocusTo(awin->screen_ptr, awin);
1270 void wHideApplication(WApplication
*wapp
)
1278 wwarning("trying to hide a non grouped window");
1281 if (!wapp
->main_window_desc
) {
1282 wwarning("group leader not found for window group");
1285 scr
= wapp
->main_window_desc
->screen_ptr
;
1287 wlist
= scr
->focused_window
;
1291 if (wlist
->main_window
== wapp
->main_window
)
1292 wapp
->last_focused
= wlist
;
1294 wapp
->last_focused
= NULL
;
1296 animate
= !wapp
->flags
.skip_next_animation
;
1299 if (wlist
->main_window
== wapp
->main_window
) {
1300 if (wlist
->flags
.focused
) {
1303 if (wapp
->app_icon
) {
1304 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1305 wapp
->app_icon
->y_pos
, wlist
, animate
);
1309 wlist
= wlist
->prev
;
1312 wapp
->flags
.skip_next_animation
= 0;
1315 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1316 wlist
= scr
->focused_window
;
1318 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1319 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1321 wlist
= wlist
->prev
;
1323 wSetFocusTo(scr
, wlist
);
1325 wSetFocusTo(scr
, NULL
);
1329 wapp
->flags
.hidden
= 1;
1331 if (wPreferences
.auto_arrange_icons
) {
1332 wArrangeIcons(scr
, True
);
1336 wAppIconPaint(wapp
->app_icon
);
1340 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1342 if (bringToCurrentWS
)
1343 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1345 wwin
->flags
.hidden
= 0;
1348 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1349 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1350 icon
->core
->width
, icon
->core
->height
,
1351 wwin
->frame_x
, wwin
->frame_y
,
1352 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1355 wwin
->flags
.skip_next_animation
= 0;
1356 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1357 XMapWindow(dpy
, wwin
->client_win
);
1358 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1359 wClientSetState(wwin
, NormalState
, None
);
1360 wwin
->flags
.mapped
= 1;
1361 wRaiseFrame(wwin
->frame
->core
);
1363 if (wwin
->flags
.inspector_open
) {
1364 wUnhideInspectorForWindow(wwin
);
1367 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1370 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1373 WWindow
*wlist
, *next
;
1374 WWindow
*focused
= NULL
;
1380 scr
= wapp
->main_window_desc
->screen_ptr
;
1381 wlist
= scr
->focused_window
;
1385 /* goto beginning of list */
1387 wlist
= wlist
->prev
;
1389 animate
= !wapp
->flags
.skip_next_animation
;
1394 if (wlist
->main_window
== wapp
->main_window
) {
1395 if (wlist
->flags
.focused
)
1397 else if (!focused
|| !focused
->flags
.focused
)
1400 if (wlist
->flags
.miniaturized
) {
1401 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1402 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1403 if (!wlist
->icon
->mapped
) {
1406 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1407 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1408 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1412 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1413 wlist
->icon
->mapped
= 1;
1415 wRaiseFrame(wlist
->icon
->core
);
1417 if (bringToCurrentWS
)
1418 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1419 wlist
->flags
.hidden
= 0;
1420 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1421 wDeiconifyWindow(wlist
);
1423 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1424 } else if (wlist
->flags
.shaded
) {
1425 if (bringToCurrentWS
)
1426 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1427 wlist
->flags
.hidden
= 0;
1428 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1429 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1431 wUnshadeWindow(wlist
);
1432 wRaiseFrame(wlist
->frame
->core
);
1435 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1436 } else if (wlist
->flags
.hidden
) {
1437 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1438 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1441 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1442 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1444 wRaiseFrame(wlist
->frame
->core
);
1450 wapp
->flags
.skip_next_animation
= 0;
1451 wapp
->flags
.hidden
= 0;
1453 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1454 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1455 wSetFocusTo(scr
, wapp
->last_focused
);
1456 } else if (focused
) {
1457 wSetFocusTo(scr
, focused
);
1459 wapp
->last_focused
= NULL
;
1460 if (wPreferences
.auto_arrange_icons
) {
1461 wArrangeIcons(scr
, True
);
1464 wAppIconPaint(wapp
->app_icon
);
1468 void wShowAllWindows(WScreen
*scr
)
1470 WWindow
*wwin
, *old_foc
;
1473 old_foc
= wwin
= scr
->focused_window
;
1475 if (!wwin
->flags
.internal_window
&&
1476 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1477 if (wwin
->flags
.miniaturized
) {
1478 wwin
->flags
.skip_next_animation
= 1;
1479 wDeiconifyWindow(wwin
);
1480 } else if (wwin
->flags
.hidden
) {
1481 wapp
= wApplicationOf(wwin
->main_window
);
1483 wUnhideApplication(wapp
, False
, False
);
1485 wwin
->flags
.skip_next_animation
= 1;
1486 wDeiconifyWindow(wwin
);
1492 wSetFocusTo(scr
, old_foc
);
1493 /*wRaiseFrame(old_foc->frame->core); */
1496 void wRefreshDesktop(WScreen
*scr
)
1499 XSetWindowAttributes attr
;
1501 attr
.backing_store
= NotUseful
;
1502 attr
.save_under
= False
;
1503 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1504 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1505 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1506 XMapRaised(dpy
, win
);
1507 XDestroyWindow(dpy
, win
);
1511 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1517 const int heads
= wXineramaHeads(scr
);
1520 int pf
; /* primary axis */
1521 int sf
; /* secondary axis */
1525 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1531 int isize
= wPreferences
.icon_size
;
1533 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1535 for (head
= 0; head
< heads
; ++head
) {
1536 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1537 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1538 vars
[head
].pi
= vars
[head
].si
= 0;
1539 vars
[head
].sx1
= rect
.pos
.x
;
1540 vars
[head
].sy1
= rect
.pos
.y
;
1541 vars
[head
].sw
= rect
.size
.width
;
1542 vars
[head
].sh
= rect
.size
.height
;
1543 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1544 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1545 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1546 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1547 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1548 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1550 /* icon yard boundaries */
1551 if (wPreferences
.icon_yard
& IY_VERT
) {
1552 vars
[head
].pf
= vars
[head
].fullH
;
1553 vars
[head
].sf
= vars
[head
].fullW
;
1555 vars
[head
].pf
= vars
[head
].fullW
;
1556 vars
[head
].sf
= vars
[head
].fullH
;
1558 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1559 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1562 vars
[head
].xo
= vars
[head
].sx1
;
1565 if (wPreferences
.icon_yard
& IY_TOP
) {
1566 vars
[head
].yo
= vars
[head
].sy1
;
1569 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1574 #define X ((wPreferences.icon_yard & IY_VERT) \
1575 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1576 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1578 #define Y ((wPreferences.icon_yard & IY_VERT) \
1579 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1580 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1582 /* arrange application icons */
1583 aicon
= scr
->app_icon_list
;
1584 /* reverse them to avoid unnecessarily sliding of icons */
1585 while (aicon
&& aicon
->next
)
1586 aicon
= aicon
->next
;
1589 if (!aicon
->docked
) {
1590 /* CHECK: can icon be NULL here ? */
1591 /* The intention here is to place the AppIcon on the head that
1592 * contains most of the applications _main_ window. */
1593 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1595 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1597 if (!wPreferences
.no_animations
) {
1598 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1600 #endif /* ANIMATIONS */
1602 wAppIconMove(aicon
, X
, Y
);
1604 if (vars
[head
].pi
>= vars
[head
].pf
) {
1609 aicon
= aicon
->prev
;
1612 /* arrange miniwindows */
1613 wwin
= scr
->focused_window
;
1614 /* reverse them to avoid unnecessarily shuffling */
1615 while (wwin
&& wwin
->prev
)
1619 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1620 (wwin
->frame
->workspace
== scr
->current_workspace
||
1621 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1623 head
= wGetHeadForWindow(wwin
);
1625 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1626 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1628 if (wPreferences
.no_animations
) {
1629 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1631 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1632 wwin
->icon_y
, X
, Y
);
1635 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1636 #endif /* ANIMATIONS */
1642 if (vars
[head
].pi
>= vars
[head
].pf
) {
1649 wwin
->flags
.icon_moved
= 0;
1651 /* we reversed the order, so we use next */
1658 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1660 WScreen
*scr
= wwin
->screen_ptr
;
1663 wwin
->flags
.selected
= 1;
1664 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1666 if (!HAS_BORDER(wwin
)) {
1667 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1670 if (!scr
->selected_windows
)
1671 scr
->selected_windows
= WMCreateArray(4);
1672 WMAddToArray(scr
->selected_windows
, wwin
);
1674 wwin
->flags
.selected
= 0;
1675 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1677 if (!HAS_BORDER(wwin
)) {
1678 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1681 if (scr
->selected_windows
) {
1682 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1687 void wMakeWindowVisible(WWindow
*wwin
)
1689 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1690 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1692 if (wwin
->flags
.shaded
) {
1693 wUnshadeWindow(wwin
);
1695 if (wwin
->flags
.hidden
) {
1698 app
= wApplicationOf(wwin
->main_window
);
1700 /* trick to get focus to this window */
1701 app
->last_focused
= wwin
;
1702 wUnhideApplication(app
, False
, False
);
1705 if (wwin
->flags
.miniaturized
) {
1706 wDeiconifyWindow(wwin
);
1708 if (!WFLAGP(wwin
, no_focusable
))
1709 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1710 wRaiseFrame(wwin
->frame
->core
);
1715 * Do the animation while shading (called with what = SHADE)
1716 * or unshading (what = UNSHADE).
1719 static void shade_animate(WWindow
*wwin
, Bool what
)
1722 time_t time0
= time(NULL
);
1724 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1729 if (!wwin
->screen_ptr
->flags
.startup
) {
1730 /* do the shading animation */
1731 h
= wwin
->frame
->core
->height
;
1732 s
= h
/ SHADE_STEPS
;
1735 w
= wwin
->frame
->core
->width
;
1736 y
= wwin
->frame
->top_width
;
1737 while (h
> wwin
->frame
->top_width
+ 1) {
1738 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1739 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1742 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1745 if (SHADE_DELAY
> 0) {
1746 wusleep(SHADE_DELAY
* 1000L);
1753 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1758 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1759 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1760 s
= abs(y
) / SHADE_STEPS
;
1763 w
= wwin
->frame
->core
->width
;
1764 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1766 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1767 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1768 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1770 if (SHADE_DELAY
> 0) {
1771 wusleep(SHADE_DELAY
* 2000L / 3);
1778 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1782 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);