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"
40 #include "application.h"
46 #include "winspector.h"
47 #include "workspace.h"
50 /****** Global Variables ******/
52 int ignore_wks_change
= 0;
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
55 extern WPreferences wPreferences
;
56 extern Atom _XA_WM_TAKE_FOCUS
;
57 extern void ProcessPendingEvents();
58 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
60 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
61 unsigned int *new_width
, unsigned int *new_height
);
62 static void save_old_geometry(WWindow
*wwin
);
64 /******* Local Variables *******/
70 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
71 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
72 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
73 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
74 SHADE_STEPS_US
, SHADE_DELAY_US
}};
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1
, Time t2
)
87 return (diff
< 60000) ? 1 : -1;
91 static void shade_animate(WWindow
*wwin
, Bool what
);
93 static void shade_animate(WWindow
*wwin
, Bool what
) { }
97 *----------------------------------------------------------------------
99 * Changes the window focus to the one passed as argument.
100 * If the window to focus is not already focused, it will be brought
101 * to the head of the list of windows. Previously focused window is
105 * Window list may be reordered and the window focus is changed.
107 *----------------------------------------------------------------------
109 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
111 static WScreen
*old_scr
= NULL
;
113 WWindow
*old_focused
;
114 WWindow
*focused
= scr
->focused_window
;
115 Time timestamp
= LastTimestamp
;
116 WApplication
*oapp
= NULL
, *napp
= NULL
;
119 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
);
136 wAppMenuUnmap(oapp
->menu
);
138 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
140 } else if (old_scr
!= scr
&& old_focused
) {
141 wWindowUnfocus(old_focused
);
144 wasfocused
= wwin
->flags
.focused
;
145 napp
= wApplicationOf(wwin
->main_window
);
147 /* remember last workspace where the app has been */
149 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
150 napp
->last_workspace
= wwin
->frame
->workspace
;
153 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
154 /* install colormap if colormap mode is lock mode */
155 if (wPreferences
.colormap_mode
== WCM_CLICK
)
156 wColormapInstallForWindow(scr
, wwin
);
158 /* set input focus */
159 switch (wwin
->focus_mode
) {
161 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
165 case WFM_LOCALLY_ACTIVE
:
166 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
169 case WFM_GLOBALLY_ACTIVE
:
173 if (wwin
->protocols
.TAKE_FOCUS
) {
174 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
178 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
180 if (WFLAGP(wwin
, no_focusable
))
183 /* if this is not the focused window focus it */
184 if (focused
!= wwin
) {
185 /* change the focus window list order */
187 wwin
->prev
->next
= wwin
->next
;
190 wwin
->next
->prev
= wwin
->prev
;
192 wwin
->prev
= focused
;
193 focused
->next
= wwin
;
195 scr
->focused_window
= wwin
;
197 if (oapp
&& oapp
!= napp
)
198 wAppMenuUnmap(oapp
->menu
);
201 wWindowFocus(wwin
, focused
);
203 if (napp
&& !wasfocused
) {
205 wUserMenuRefreshInstances(napp
->menu
, wwin
);
206 #endif /* USER_MENU */
208 if (wwin
->flags
.mapped
)
209 wAppMenuMap(napp
->menu
, wwin
);
216 void wShadeWindow(WWindow
*wwin
)
219 if (wwin
->flags
.shaded
)
222 XLowerWindow(dpy
, wwin
->client_win
);
223 shade_animate(wwin
, SHADE
);
225 wwin
->flags
.skip_next_animation
= 0;
226 wwin
->flags
.shaded
= 1;
227 wwin
->flags
.mapped
= 0;
228 /* prevent window withdrawal when getting UnmapNotify */
229 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
230 XUnmapWindow(dpy
, wwin
->client_win
);
231 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
233 /* for the client it's just like iconification */
234 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
236 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
237 wWindowSynthConfigureNotify(wwin
);
240 wClientSetState(wwin, IconicState, None);
243 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
246 if (!wwin
->screen_ptr
->flags
.startup
) {
247 /* Catch up with events not processed while animation was running */
248 ProcessPendingEvents();
253 void wUnshadeWindow(WWindow
*wwin
)
256 if (!wwin
->flags
.shaded
)
259 wwin
->flags
.shaded
= 0;
260 wwin
->flags
.mapped
= 1;
261 XMapWindow(dpy
, wwin
->client_win
);
263 shade_animate(wwin
, UNSHADE
);
265 wwin
->flags
.skip_next_animation
= 0;
266 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
267 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
269 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
270 wWindowSynthConfigureNotify(wwin
);
272 /* if the window is focused, set the focus again as it was disabled during
274 if (wwin
->flags
.focused
)
275 wSetFocusTo(wwin
->screen_ptr
, wwin
);
277 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
280 /* Set the old coordinates using the current values */
281 static void save_old_geometry(WWindow
*wwin
)
283 wwin
->old_geometry
.width
= wwin
->client
.width
;
284 wwin
->old_geometry
.height
= wwin
->client
.height
;
285 wwin
->old_geometry
.x
= wwin
->frame_x
;
286 wwin
->old_geometry
.y
= wwin
->frame_y
;
289 void wMaximizeWindow(WWindow
*wwin
, int directions
)
292 unsigned int new_width
, new_height
, half_scr_width
;
293 WArea usableArea
, totalArea
;
297 if (!IS_RESIZABLE(wwin
))
300 if (!HAS_BORDER(wwin
))
303 /* the size to adjust the geometry */
304 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
306 /* save old coordinates before we change the current values */
307 save_old_geometry(wwin
);
311 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
312 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
313 usableArea
= totalArea
;
315 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
316 WScreen
*scr
= wwin
->screen_ptr
;
319 if (directions
& MAX_KEYBOARD
)
320 head
= wGetHeadForWindow(wwin
);
322 head
= wGetHeadForPointerLocation(scr
);
324 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
327 /* Only save directions, not kbd or xinerama hints */
328 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
330 if (WFLAGP(wwin
, full_maximize
)) {
331 usableArea
= totalArea
;
333 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
335 if (wwin
->flags
.shaded
) {
336 wwin
->flags
.skip_next_animation
= 1;
337 wUnshadeWindow(wwin
);
340 if (directions
& MAX_HORIZONTAL
) {
341 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
342 new_x
= usableArea
.x1
;
343 } else if (directions
& MAX_LEFTHALF
) {
344 new_width
= half_scr_width
- adj_size
;
345 new_x
= usableArea
.x1
;
346 } else if (directions
& MAX_RIGHTHALF
) {
347 new_width
= half_scr_width
- adj_size
;
348 new_x
= usableArea
.x1
+ half_scr_width
;
350 new_x
= wwin
->frame_x
;
351 new_width
= wwin
->frame
->core
->width
;
354 if (directions
& MAX_VERTICAL
) {
355 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
356 new_y
= usableArea
.y1
;
357 if (WFLAGP(wwin
, full_maximize
)) {
358 new_y
-= wwin
->frame
->top_width
;
359 new_height
+= wwin
->frame
->bottom_width
- 1;
362 new_y
= wwin
->frame_y
;
363 new_height
= wwin
->frame
->core
->height
;
366 if (!WFLAGP(wwin
, full_maximize
)) {
367 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
370 if (directions
& MAX_MAXIMUS
) {
371 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
372 new_width
-= adj_size
;
373 new_height
-= adj_size
;
374 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
375 new_y
-= wwin
->frame
->top_width
;
376 new_height
+= wwin
->frame
->top_width
- 1;
380 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
382 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
383 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
385 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
387 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
389 /* set maximization state */
390 wwin
->flags
.maximized
= directions
;
393 /* the window boundary coordinates */
403 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
405 obs
->left
= wwin
->frame_x
;
406 obs
->top
= wwin
->frame_y
;
407 obs
->width
= wwin
->frame
->core
->width
;
408 obs
->height
= wwin
->frame
->core
->height
;
409 obs
->bottom
= obs
->top
+ obs
->height
;
410 obs
->right
= obs
->left
+ obs
->width
;
414 * Maximus: tiled maximization (maximize without overlapping other windows)
416 * The original window 'orig' will be maximized to new coordinates 'new'.
417 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
419 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
420 unsigned int *new_width
, unsigned int *new_height
)
423 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
424 short int adjust_height
;
425 int x_intsect
, y_intsect
;
426 /* the obstructing, original and new windows */
427 win_coords obs
, orig
, new;
429 /* set the original coordinate positions of the window to be Maximumized */
430 set_window_coords(wwin
, &orig
);
432 /* Try to fully maximize first, then readjust later */
433 new.left
= usableArea
.x1
;
434 new.right
= usableArea
.x2
;
435 new.top
= usableArea
.y1
;
436 new.bottom
= usableArea
.y2
;
438 if (HAS_TITLEBAR(wwin
))
439 tbar_height_0
= TITLEBAR_HEIGHT
;
440 if (HAS_RESIZEBAR(wwin
))
441 rbar_height_0
= RESIZEBAR_HEIGHT
;
442 if (HAS_BORDER(wwin
))
443 bd_width_0
= FRAME_BORDER_WIDTH
;
445 /* the length to be subtracted if the window has titlebar, etc */
446 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
449 /* The focused window is always the last in the list */
451 /* ignore windows in other workspaces etc */
452 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
453 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
459 /* Set the coordinates of obstructing window */
460 set_window_coords(tmp
, &obs
);
462 /* Try to maximize in the y direction first */
463 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
464 if (x_intsect
!= 0) {
465 /* TODO: Consider the case when coords are equal */
466 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
467 /* w_0 is below the bottom of w_j */
468 new.top
= obs
.bottom
+ 1;
470 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
471 /* The bottom of w_0 is above the top of w_j */
472 new.bottom
= obs
.top
- 1;
479 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
480 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
486 set_window_coords(tmp
, &obs
);
489 * Use the new.top and new.height instead of original values
490 * as they may have different intersections with the obstructing windows
492 new.height
= new.bottom
- new.top
- adjust_height
;
493 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
494 if (y_intsect
!= 0) {
495 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
496 /* w_0 is completely to the right of w_j */
497 new.left
= obs
.right
+ 1;
499 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
500 /* w_0 is completely to the left of w_j */
501 new.right
= obs
.left
- 1;
508 /* xcalc needs -7 here, but other apps don't */
509 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
510 *new_width
= new.right
- new.left
;
513 void wUnmaximizeWindow(WWindow
*wwin
)
516 WMRect old_geom_rect
;
520 if (!wwin
->flags
.maximized
)
523 if (wwin
->flags
.shaded
) {
524 wwin
->flags
.skip_next_animation
= 1;
525 wUnshadeWindow(wwin
);
527 /* Use old coordinates if they are set, current values otherwise */
528 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
529 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
530 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
531 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
532 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
533 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
534 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
536 wwin
->flags
.maximized
= 0;
537 wWindowConfigure(wwin
, x
, y
, w
, h
);
539 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
542 void wFullscreenWindow(WWindow
*wwin
)
547 if (wwin
->flags
.fullscreen
)
550 wwin
->flags
.fullscreen
= True
;
552 wWindowConfigureBorders(wwin
);
554 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
556 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
557 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
558 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
559 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
561 head
= wGetHeadForWindow(wwin
);
562 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
563 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
565 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
568 void wUnfullscreenWindow(WWindow
*wwin
)
570 if (!wwin
->flags
.fullscreen
)
573 wwin
->flags
.fullscreen
= False
;
575 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
576 if (WFLAGP(wwin
, sunken
)) {
577 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
578 } else if (WFLAGP(wwin
, floating
)) {
579 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
581 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
585 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
586 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
588 wWindowConfigureBorders(wwin
);
590 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
591 wFrameWindowPaint(wwin->frame);
594 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
598 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
600 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
601 float cx
, cy
, cw
, ch
;
602 float xstep
, ystep
, wstep
, hstep
;
605 float angle
, final_angle
, delta
;
607 xstep
= (float)(fx
- x
) / steps
;
608 ystep
= (float)(fy
- y
) / steps
;
609 wstep
= (float)(fw
- w
) / steps
;
610 hstep
= (float)(fh
- h
) / steps
;
617 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
618 delta
= (float)(final_angle
/ FRAMES
);
619 for (angle
= 0;; angle
+= delta
) {
620 if (angle
> final_angle
)
623 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
624 dch
= (ch
/ 2) * cos(angle
);
625 midy
= cy
+ (ch
/ 2);
627 points
[0].x
= cx
+ dx
;
628 points
[0].y
= midy
- dch
;
629 points
[1].x
= cx
+ cw
- dx
;
630 points
[1].y
= points
[0].y
;
631 points
[2].x
= cx
+ cw
+ dx
;
632 points
[2].y
= midy
+ dch
;
633 points
[3].x
= cx
- dx
;
634 points
[3].y
= points
[2].y
;
635 points
[4].x
= points
[0].x
;
636 points
[4].y
= points
[0].y
;
639 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
641 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
643 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
649 if (angle
>= final_angle
)
659 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
661 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
662 float cx
, cy
, cw
, ch
;
663 float xstep
, ystep
, wstep
, hstep
;
665 float angle
, final_angle
, a
, d
, delta
;
672 xstep
= (float)(fx
- x
) / steps
;
673 ystep
= (float)(fy
- y
) / steps
;
674 wstep
= (float)(fw
- w
) / steps
;
675 hstep
= (float)(fh
- h
) / steps
;
682 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
683 delta
= (float)(final_angle
/ FRAMES
);
684 for (angle
= 0;; angle
+= delta
) {
685 if (angle
> final_angle
)
689 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
691 points
[0].x
= cx
+ cos(angle
- a
) * d
;
692 points
[0].y
= cy
+ sin(angle
- a
) * d
;
693 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
694 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
695 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
696 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
697 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
698 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
699 points
[4].x
= cx
+ cos(angle
- a
) * d
;
700 points
[4].y
= cy
+ sin(angle
- a
) * d
;
702 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
704 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
706 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
712 if (angle
>= final_angle
)
721 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
723 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
724 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
725 float xstep
, ystep
, wstep
, hstep
;
728 xstep
= (float)(fx
- x
) / steps
;
729 ystep
= (float)(fy
- y
) / steps
;
730 wstep
= (float)(fw
- w
) / steps
;
731 hstep
= (float)(fh
- h
) / steps
;
733 for (j
= 0; j
< FRAMES
; j
++) {
740 for (i
= 0; i
< steps
; i
++) {
741 for (j
= 0; j
< FRAMES
; j
++) {
742 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
743 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
746 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
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
]);
751 if (j
< FRAMES
- 1) {
765 for (j
= 0; j
< FRAMES
; j
++) {
766 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
769 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
771 for (j
= 0; j
< FRAMES
; j
++) {
772 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
780 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
782 int style
= wPreferences
.iconification_style
; /* Catch the value */
785 if (style
== WIS_NONE
)
788 if (style
== WIS_RANDOM
) {
794 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
796 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
799 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
801 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
805 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
807 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
811 #endif /* ANIMATIONS */
813 static void flushExpose(void)
817 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
818 WMHandleEvent(&tmpev
);
822 static void unmapTransientsFor(WWindow
*wwin
)
826 tmp
= wwin
->screen_ptr
->focused_window
;
828 /* unmap the transients for this transient */
829 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
830 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
831 unmapTransientsFor(tmp
);
832 tmp
->flags
.miniaturized
= 1;
833 if (!tmp
->flags
.shaded
) {
836 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
839 if (!tmp->flags.shaded)
841 wClientSetState(tmp
, IconicState
, None
);
843 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
849 static void mapTransientsFor(WWindow
*wwin
)
853 tmp
= wwin
->screen_ptr
->focused_window
;
855 /* recursively map the transients for this transient */
856 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
857 && tmp
->icon
== NULL
) {
858 mapTransientsFor(tmp
);
859 tmp
->flags
.miniaturized
= 0;
860 if (!tmp
->flags
.shaded
) {
863 XMapWindow(dpy
, tmp
->frame
->core
->window
);
865 tmp
->flags
.semi_focused
= 0;
867 if (!tmp->flags.shaded)
869 wClientSetState(tmp
, NormalState
, None
);
871 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
877 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
884 /* hackish way to detect transient_for cycle */
885 i
= wwin
->screen_ptr
->window_count
+ 1;
887 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
888 wwin
= wWindowFor(wwin
->transient_for
);
891 if (i
== 0 && wwin
) {
892 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
899 void wIconifyWindow(WWindow
* wwin
)
901 XWindowAttributes attribs
;
904 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
905 /* the window doesn't exist anymore */
909 if (wwin
->flags
.miniaturized
) {
913 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
914 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
916 if (owner
&& owner
->flags
.miniaturized
)
920 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
922 /* if the window is in another workspace, simplify process */
924 /* icon creation may take a while */
925 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
926 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
927 GrabModeAsync
, None
, None
, CurrentTime
);
930 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
931 if (!wwin
->flags
.icon_moved
) {
932 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
934 wwin
->icon
= wIconCreate(wwin
);
936 wwin
->icon
->mapped
= 1;
939 wwin
->flags
.miniaturized
= 1;
940 wwin
->flags
.mapped
= 0;
942 /* unmap transients */
944 unmapTransientsFor(wwin
);
947 XUngrabPointer(dpy
, CurrentTime
);
949 /* let all Expose events arrive so that we can repaint
950 * something before the animation starts (and the server is grabbed) */
953 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
954 wClientSetState(wwin
, IconicState
, None
);
956 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
960 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
961 && !wPreferences
.no_animations
) {
964 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
967 iw
= wwin
->icon
->core
->width
;
968 ih
= wwin
->icon
->core
->height
;
970 if (wwin
->flags
.net_handle_icon
) {
978 iw
= wwin
->screen_ptr
->scr_width
;
979 ih
= wwin
->screen_ptr
->scr_height
;
982 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
983 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
988 wwin
->flags
.skip_next_animation
= 0;
990 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
991 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
992 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
994 XMapWindow(dpy
, wwin
->icon
->core
->window
);
996 AddToStackList(wwin
->icon
->core
);
998 wLowerFrame(wwin
->icon
->core
);
1002 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1005 * It doesn't seem to be working and causes button event hangup
1006 * when deiconifying a transient window.
1007 setupIconGrabs(wwin->icon);
1009 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1010 && wPreferences
.focus_mode
== WKF_CLICK
) {
1015 if (!WFLAGP(tmp
, no_focusable
)
1016 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1017 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1021 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1022 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1023 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1026 if (!wwin
->screen_ptr
->flags
.startup
) {
1027 /* Catch up with events not processed while animation was running */
1028 Window clientwin
= wwin
->client_win
;
1030 ProcessPendingEvents();
1032 /* the window can disappear while ProcessPendingEvents() runs */
1033 if (!wWindowFor(clientwin
)) {
1040 /* maybe we want to do this regardless of net_handle_icon
1041 * it seems to me we might break behaviour this way.
1043 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1044 && !wwin
->flags
.net_handle_icon
)
1045 wIconSelect(wwin
->icon
);
1047 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1049 if (wPreferences
.auto_arrange_icons
)
1050 wArrangeIcons(wwin
->screen_ptr
, True
);
1053 void wDeiconifyWindow(WWindow
*wwin
)
1055 /* Let's avoid changing workspace while deiconifying */
1056 ignore_wks_change
= 1;
1058 /* we're hiding for show_desktop */
1059 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1060 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1063 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1065 if (!wwin
->flags
.miniaturized
)
1068 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1069 WWindow
*owner
= recursiveTransientFor(wwin
);
1071 if (owner
&& owner
->flags
.miniaturized
) {
1072 wDeiconifyWindow(owner
);
1073 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1074 wRaiseFrame(wwin
->frame
->core
);
1079 wwin
->flags
.miniaturized
= 0;
1081 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1082 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
)) {
1170 if (wPreferences
.auto_arrange_icons
) {
1171 wArrangeIcons(wwin
->screen_ptr
, True
);
1174 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1176 /* In case we were shaded and iconified, also unshade */
1178 wUnshadeWindow(wwin
);
1180 ignore_wks_change
= 0;
1183 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1185 if (wwin
->flags
.miniaturized
) {
1187 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1188 wwin
->icon
->mapped
= 0;
1190 wwin
->flags
.hidden
= 1;
1192 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1196 if (wwin
->flags
.inspector_open
) {
1197 wHideInspectorForWindow(wwin
);
1200 wwin
->flags
.hidden
= 1;
1203 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1207 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1208 !wwin
->flags
.skip_next_animation
&& animate
) {
1209 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1210 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1211 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1214 wwin
->flags
.skip_next_animation
= 0;
1216 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1219 void wHideOtherApplications(WWindow
*awin
)
1226 wwin
= awin
->screen_ptr
->focused_window
;
1230 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1231 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1232 && !wwin
->flags
.internal_window
1233 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1235 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1236 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1237 wwin
->flags
.skip_next_animation
= 1;
1238 wIconifyWindow(wwin
);
1240 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1241 tapp
= wApplicationOf(wwin
->main_window
);
1243 tapp
->flags
.skip_next_animation
= 1;
1244 wHideApplication(tapp
);
1246 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1247 wwin
->flags
.skip_next_animation
= 1;
1248 wIconifyWindow(wwin
);
1256 wSetFocusTo(awin->screen_ptr, awin);
1260 void wHideApplication(WApplication
*wapp
)
1268 wwarning("trying to hide a non grouped window");
1271 if (!wapp
->main_window_desc
) {
1272 wwarning("group leader not found for window group");
1275 scr
= wapp
->main_window_desc
->screen_ptr
;
1277 wlist
= scr
->focused_window
;
1281 if (wlist
->main_window
== wapp
->main_window
)
1282 wapp
->last_focused
= wlist
;
1284 wapp
->last_focused
= NULL
;
1286 animate
= !wapp
->flags
.skip_next_animation
;
1289 if (wlist
->main_window
== wapp
->main_window
) {
1290 if (wlist
->flags
.focused
) {
1293 if (wapp
->app_icon
) {
1294 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1295 wapp
->app_icon
->y_pos
, wlist
, animate
);
1299 wlist
= wlist
->prev
;
1302 wapp
->flags
.skip_next_animation
= 0;
1305 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1306 wlist
= scr
->focused_window
;
1308 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1309 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1311 wlist
= wlist
->prev
;
1313 wSetFocusTo(scr
, wlist
);
1315 wSetFocusTo(scr
, NULL
);
1319 wapp
->flags
.hidden
= 1;
1321 if (wPreferences
.auto_arrange_icons
) {
1322 wArrangeIcons(scr
, True
);
1326 wAppIconPaint(wapp
->app_icon
);
1330 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1332 if (bringToCurrentWS
)
1333 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1335 wwin
->flags
.hidden
= 0;
1338 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1339 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1340 icon
->core
->width
, icon
->core
->height
,
1341 wwin
->frame_x
, wwin
->frame_y
,
1342 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1345 wwin
->flags
.skip_next_animation
= 0;
1346 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1347 XMapWindow(dpy
, wwin
->client_win
);
1348 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1349 wClientSetState(wwin
, NormalState
, None
);
1350 wwin
->flags
.mapped
= 1;
1351 wRaiseFrame(wwin
->frame
->core
);
1353 if (wwin
->flags
.inspector_open
) {
1354 wUnhideInspectorForWindow(wwin
);
1357 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1360 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1363 WWindow
*wlist
, *next
;
1364 WWindow
*focused
= NULL
;
1370 scr
= wapp
->main_window_desc
->screen_ptr
;
1371 wlist
= scr
->focused_window
;
1375 /* goto beginning of list */
1377 wlist
= wlist
->prev
;
1379 animate
= !wapp
->flags
.skip_next_animation
;
1384 if (wlist
->main_window
== wapp
->main_window
) {
1385 if (wlist
->flags
.focused
)
1387 else if (!focused
|| !focused
->flags
.focused
)
1390 if (wlist
->flags
.miniaturized
) {
1391 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1392 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1393 if (!wlist
->icon
->mapped
) {
1396 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1397 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1398 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1402 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1403 wlist
->icon
->mapped
= 1;
1405 wRaiseFrame(wlist
->icon
->core
);
1407 if (bringToCurrentWS
)
1408 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1409 wlist
->flags
.hidden
= 0;
1410 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1411 wDeiconifyWindow(wlist
);
1413 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1414 } else if (wlist
->flags
.shaded
) {
1415 if (bringToCurrentWS
)
1416 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1417 wlist
->flags
.hidden
= 0;
1418 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1419 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1421 wUnshadeWindow(wlist
);
1422 wRaiseFrame(wlist
->frame
->core
);
1425 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1426 } else if (wlist
->flags
.hidden
) {
1427 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1428 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1431 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1432 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1434 wRaiseFrame(wlist
->frame
->core
);
1440 wapp
->flags
.skip_next_animation
= 0;
1441 wapp
->flags
.hidden
= 0;
1443 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1444 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1445 wSetFocusTo(scr
, wapp
->last_focused
);
1446 } else if (focused
) {
1447 wSetFocusTo(scr
, focused
);
1449 wapp
->last_focused
= NULL
;
1450 if (wPreferences
.auto_arrange_icons
) {
1451 wArrangeIcons(scr
, True
);
1454 wAppIconPaint(wapp
->app_icon
);
1458 void wShowAllWindows(WScreen
*scr
)
1460 WWindow
*wwin
, *old_foc
;
1463 old_foc
= wwin
= scr
->focused_window
;
1465 if (!wwin
->flags
.internal_window
&&
1466 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1467 if (wwin
->flags
.miniaturized
) {
1468 wwin
->flags
.skip_next_animation
= 1;
1469 wDeiconifyWindow(wwin
);
1470 } else if (wwin
->flags
.hidden
) {
1471 wapp
= wApplicationOf(wwin
->main_window
);
1473 wUnhideApplication(wapp
, False
, False
);
1475 wwin
->flags
.skip_next_animation
= 1;
1476 wDeiconifyWindow(wwin
);
1482 wSetFocusTo(scr
, old_foc
);
1483 /*wRaiseFrame(old_foc->frame->core); */
1486 void wRefreshDesktop(WScreen
*scr
)
1489 XSetWindowAttributes attr
;
1491 attr
.backing_store
= NotUseful
;
1492 attr
.save_under
= False
;
1493 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1494 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1495 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1496 XMapRaised(dpy
, win
);
1497 XDestroyWindow(dpy
, win
);
1501 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1507 const int heads
= wXineramaHeads(scr
);
1510 int pf
; /* primary axis */
1511 int sf
; /* secondary axis */
1515 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1521 int isize
= wPreferences
.icon_size
;
1523 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1525 for (head
= 0; head
< heads
; ++head
) {
1526 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1527 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1528 vars
[head
].pi
= vars
[head
].si
= 0;
1529 vars
[head
].sx1
= rect
.pos
.x
;
1530 vars
[head
].sy1
= rect
.pos
.y
;
1531 vars
[head
].sw
= rect
.size
.width
;
1532 vars
[head
].sh
= rect
.size
.height
;
1533 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1534 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1535 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1536 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1537 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1538 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1540 /* icon yard boundaries */
1541 if (wPreferences
.icon_yard
& IY_VERT
) {
1542 vars
[head
].pf
= vars
[head
].fullH
;
1543 vars
[head
].sf
= vars
[head
].fullW
;
1545 vars
[head
].pf
= vars
[head
].fullW
;
1546 vars
[head
].sf
= vars
[head
].fullH
;
1548 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1549 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1552 vars
[head
].xo
= vars
[head
].sx1
;
1555 if (wPreferences
.icon_yard
& IY_TOP
) {
1556 vars
[head
].yo
= vars
[head
].sy1
;
1559 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1564 #define X ((wPreferences.icon_yard & IY_VERT) \
1565 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1566 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1568 #define Y ((wPreferences.icon_yard & IY_VERT) \
1569 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1570 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1572 /* arrange application icons */
1573 aicon
= scr
->app_icon_list
;
1574 /* reverse them to avoid unnecessarily sliding of icons */
1575 while (aicon
&& aicon
->next
)
1576 aicon
= aicon
->next
;
1579 if (!aicon
->docked
) {
1580 /* CHECK: can icon be NULL here ? */
1581 /* The intention here is to place the AppIcon on the head that
1582 * contains most of the applications _main_ window. */
1583 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1585 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1587 if (!wPreferences
.no_animations
) {
1588 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1590 #endif /* ANIMATIONS */
1592 wAppIconMove(aicon
, X
, Y
);
1594 if (vars
[head
].pi
>= vars
[head
].pf
) {
1599 aicon
= aicon
->prev
;
1602 /* arrange miniwindows */
1603 wwin
= scr
->focused_window
;
1604 /* reverse them to avoid unnecessarily shuffling */
1605 while (wwin
&& wwin
->prev
)
1609 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1610 (wwin
->frame
->workspace
== scr
->current_workspace
||
1611 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1613 head
= wGetHeadForWindow(wwin
);
1615 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1616 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1618 if (wPreferences
.no_animations
) {
1619 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1621 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1622 wwin
->icon_y
, X
, Y
);
1625 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1626 #endif /* ANIMATIONS */
1632 if (vars
[head
].pi
>= vars
[head
].pf
) {
1639 wwin
->flags
.icon_moved
= 0;
1641 /* we reversed the order, so we use next */
1648 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1650 WScreen
*scr
= wwin
->screen_ptr
;
1653 wwin
->flags
.selected
= 1;
1654 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1656 if (!HAS_BORDER(wwin
)) {
1657 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1660 if (!scr
->selected_windows
)
1661 scr
->selected_windows
= WMCreateArray(4);
1662 WMAddToArray(scr
->selected_windows
, wwin
);
1664 wwin
->flags
.selected
= 0;
1665 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1667 if (!HAS_BORDER(wwin
)) {
1668 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1671 if (scr
->selected_windows
) {
1672 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1677 void wMakeWindowVisible(WWindow
*wwin
)
1679 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1680 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1682 if (wwin
->flags
.shaded
) {
1683 wUnshadeWindow(wwin
);
1685 if (wwin
->flags
.hidden
) {
1688 app
= wApplicationOf(wwin
->main_window
);
1690 /* trick to get focus to this window */
1691 app
->last_focused
= wwin
;
1692 wUnhideApplication(app
, False
, False
);
1695 if (wwin
->flags
.miniaturized
) {
1696 wDeiconifyWindow(wwin
);
1698 if (!WFLAGP(wwin
, no_focusable
))
1699 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1700 wRaiseFrame(wwin
->frame
->core
);
1705 * Do the animation while shading (called with what = SHADE)
1706 * or unshading (what = UNSHADE).
1709 static void shade_animate(WWindow
*wwin
, Bool what
)
1712 time_t time0
= time(NULL
);
1714 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1719 if (!wwin
->screen_ptr
->flags
.startup
) {
1720 /* do the shading animation */
1721 h
= wwin
->frame
->core
->height
;
1722 s
= h
/ SHADE_STEPS
;
1725 w
= wwin
->frame
->core
->width
;
1726 y
= wwin
->frame
->top_width
;
1727 while (h
> wwin
->frame
->top_width
+ 1) {
1728 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1729 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1732 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1735 if (SHADE_DELAY
> 0) {
1736 wusleep(SHADE_DELAY
* 1000L);
1743 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1748 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1749 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1750 s
= abs(y
) / SHADE_STEPS
;
1753 w
= wwin
->frame
->core
->width
;
1754 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1756 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1757 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1758 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1760 if (SHADE_DELAY
> 0) {
1761 wusleep(SHADE_DELAY
* 2000L / 3);
1768 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1772 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);