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
;
56 extern Cursor wCursor
[WCUR_LAST
];
58 extern WPreferences wPreferences
;
60 extern Atom _XA_WM_TAKE_FOCUS
;
62 extern void ProcessPendingEvents();
63 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
65 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
66 unsigned int *new_width
, unsigned int *new_height
);
67 static void save_old_geometry(WWindow
*wwin
);
69 /******* Local Variables *******/
75 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
76 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
77 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
78 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
79 SHADE_STEPS_US
, SHADE_DELAY_US
}};
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
86 static int compareTimes(Time t1
, Time t2
)
92 return (diff
< 60000) ? 1 : -1;
96 static void shade_animate(WWindow
*wwin
, Bool what
);
98 static void shade_animate(WWindow
*wwin
, Bool what
) { }
102 *----------------------------------------------------------------------
104 * Changes the window focus to the one passed as argument.
105 * If the window to focus is not already focused, it will be brought
106 * to the head of the list of windows. Previously focused window is
110 * Window list may be reordered and the window focus is changed.
112 *----------------------------------------------------------------------
114 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
116 static WScreen
*old_scr
= NULL
;
118 WWindow
*old_focused
;
119 WWindow
*focused
= scr
->focused_window
;
120 Time timestamp
= LastTimestamp
;
121 WApplication
*oapp
= NULL
, *napp
= NULL
;
124 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
129 old_focused
= old_scr
->focused_window
;
131 LastFocusChange
= timestamp
;
134 oapp
= wApplicationOf(old_focused
->main_window
);
137 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
139 wWindowUnfocus(old_focused
);
141 wAppMenuUnmap(oapp
->menu
);
143 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
145 } else if (old_scr
!= scr
&& old_focused
) {
146 wWindowUnfocus(old_focused
);
149 wasfocused
= wwin
->flags
.focused
;
150 napp
= wApplicationOf(wwin
->main_window
);
152 /* remember last workspace where the app has been */
154 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
155 napp
->last_workspace
= wwin
->frame
->workspace
;
158 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
159 /* install colormap if colormap mode is lock mode */
160 if (wPreferences
.colormap_mode
== WCM_CLICK
)
161 wColormapInstallForWindow(scr
, wwin
);
163 /* set input focus */
164 switch (wwin
->focus_mode
) {
166 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
170 case WFM_LOCALLY_ACTIVE
:
171 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
174 case WFM_GLOBALLY_ACTIVE
:
178 if (wwin
->protocols
.TAKE_FOCUS
) {
179 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
183 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
185 if (WFLAGP(wwin
, no_focusable
))
188 /* if this is not the focused window focus it */
189 if (focused
!= wwin
) {
190 /* change the focus window list order */
192 wwin
->prev
->next
= wwin
->next
;
195 wwin
->next
->prev
= wwin
->prev
;
197 wwin
->prev
= focused
;
198 focused
->next
= wwin
;
200 scr
->focused_window
= wwin
;
202 if (oapp
&& oapp
!= napp
)
203 wAppMenuUnmap(oapp
->menu
);
206 wWindowFocus(wwin
, focused
);
208 if (napp
&& !wasfocused
) {
210 wUserMenuRefreshInstances(napp
->menu
, wwin
);
211 #endif /* USER_MENU */
213 if (wwin
->flags
.mapped
)
214 wAppMenuMap(napp
->menu
, wwin
);
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
);
392 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
394 /* set maximization state */
395 wwin
->flags
.maximized
= directions
;
398 /* the window boundary coordinates */
408 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
410 obs
->left
= wwin
->frame_x
;
411 obs
->top
= wwin
->frame_y
;
412 obs
->width
= wwin
->frame
->core
->width
;
413 obs
->height
= wwin
->frame
->core
->height
;
414 obs
->bottom
= obs
->top
+ obs
->height
;
415 obs
->right
= obs
->left
+ obs
->width
;
419 * Maximus: tiled maximization (maximize without overlapping other windows)
421 * The original window 'orig' will be maximized to new coordinates 'new'.
422 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
424 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
425 unsigned int *new_width
, unsigned int *new_height
)
428 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
429 short int adjust_height
;
430 int x_intsect
, y_intsect
;
431 /* the obstructing, original and new windows */
432 win_coords obs
, orig
, new;
434 /* set the original coordinate positions of the window to be Maximumized */
435 set_window_coords(wwin
, &orig
);
437 /* Try to fully maximize first, then readjust later */
438 new.left
= usableArea
.x1
;
439 new.right
= usableArea
.x2
;
440 new.top
= usableArea
.y1
;
441 new.bottom
= usableArea
.y2
;
443 if (HAS_TITLEBAR(wwin
))
444 tbar_height_0
= TITLEBAR_HEIGHT
;
445 if (HAS_RESIZEBAR(wwin
))
446 rbar_height_0
= RESIZEBAR_HEIGHT
;
447 if (HAS_BORDER(wwin
))
448 bd_width_0
= FRAME_BORDER_WIDTH
;
450 /* the length to be subtracted if the window has titlebar, etc */
451 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
454 /* The focused window is always the last in the list */
456 /* ignore windows in other workspaces etc */
457 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
458 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
464 /* Set the coordinates of obstructing window */
465 set_window_coords(tmp
, &obs
);
467 /* Try to maximize in the y direction first */
468 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
469 if (x_intsect
!= 0) {
470 /* TODO: Consider the case when coords are equal */
471 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
472 /* w_0 is below the bottom of w_j */
473 new.top
= obs
.bottom
+ 1;
475 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
476 /* The bottom of w_0 is above the top of w_j */
477 new.bottom
= obs
.top
- 1;
484 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
485 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
491 set_window_coords(tmp
, &obs
);
494 * Use the new.top and new.height instead of original values
495 * as they may have different intersections with the obstructing windows
497 new.height
= new.bottom
- new.top
- adjust_height
;
498 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
499 if (y_intsect
!= 0) {
500 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
501 /* w_0 is completely to the right of w_j */
502 new.left
= obs
.right
+ 1;
504 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
505 /* w_0 is completely to the left of w_j */
506 new.right
= obs
.left
- 1;
513 /* xcalc needs -7 here, but other apps don't */
514 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
515 *new_width
= new.right
- new.left
;
518 void wUnmaximizeWindow(WWindow
*wwin
)
521 WMRect old_geom_rect
;
525 if (!wwin
->flags
.maximized
)
528 if (wwin
->flags
.shaded
) {
529 wwin
->flags
.skip_next_animation
= 1;
530 wUnshadeWindow(wwin
);
532 /* Use old coordinates if they are set, current values otherwise */
533 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
534 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
535 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
536 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
537 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
538 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
539 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
541 wwin
->flags
.maximized
= 0;
542 wWindowConfigure(wwin
, x
, y
, w
, h
);
544 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
547 void wFullscreenWindow(WWindow
*wwin
)
552 if (wwin
->flags
.fullscreen
)
555 wwin
->flags
.fullscreen
= True
;
557 wWindowConfigureBorders(wwin
);
559 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
561 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
562 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
563 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
564 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
566 head
= wGetHeadForWindow(wwin
);
567 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
568 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
570 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
573 void wUnfullscreenWindow(WWindow
*wwin
)
575 if (!wwin
->flags
.fullscreen
)
578 wwin
->flags
.fullscreen
= False
;
580 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
581 if (WFLAGP(wwin
, sunken
)) {
582 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
583 } else if (WFLAGP(wwin
, floating
)) {
584 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
586 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
590 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
591 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
593 wWindowConfigureBorders(wwin
);
595 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
596 wFrameWindowPaint(wwin->frame);
599 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
603 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
605 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
606 float cx
, cy
, cw
, ch
;
607 float xstep
, ystep
, wstep
, hstep
;
610 float angle
, final_angle
, delta
;
612 xstep
= (float)(fx
- x
) / steps
;
613 ystep
= (float)(fy
- y
) / steps
;
614 wstep
= (float)(fw
- w
) / steps
;
615 hstep
= (float)(fh
- h
) / steps
;
622 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
623 delta
= (float)(final_angle
/ FRAMES
);
624 for (angle
= 0;; angle
+= delta
) {
625 if (angle
> final_angle
)
628 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
629 dch
= (ch
/ 2) * cos(angle
);
630 midy
= cy
+ (ch
/ 2);
632 points
[0].x
= cx
+ dx
;
633 points
[0].y
= midy
- dch
;
634 points
[1].x
= cx
+ cw
- dx
;
635 points
[1].y
= points
[0].y
;
636 points
[2].x
= cx
+ cw
+ dx
;
637 points
[2].y
= midy
+ dch
;
638 points
[3].x
= cx
- dx
;
639 points
[3].y
= points
[2].y
;
640 points
[4].x
= points
[0].x
;
641 points
[4].y
= points
[0].y
;
644 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
646 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
648 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
654 if (angle
>= final_angle
)
664 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
666 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
667 float cx
, cy
, cw
, ch
;
668 float xstep
, ystep
, wstep
, hstep
;
670 float angle
, final_angle
, a
, d
, delta
;
677 xstep
= (float)(fx
- x
) / steps
;
678 ystep
= (float)(fy
- y
) / steps
;
679 wstep
= (float)(fw
- w
) / steps
;
680 hstep
= (float)(fh
- h
) / steps
;
687 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
688 delta
= (float)(final_angle
/ FRAMES
);
689 for (angle
= 0;; angle
+= delta
) {
690 if (angle
> final_angle
)
694 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
696 points
[0].x
= cx
+ cos(angle
- a
) * d
;
697 points
[0].y
= cy
+ sin(angle
- a
) * d
;
698 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
699 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
700 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
701 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
702 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
703 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
704 points
[4].x
= cx
+ cos(angle
- a
) * d
;
705 points
[4].y
= cy
+ sin(angle
- a
) * d
;
707 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
709 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
711 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
717 if (angle
>= final_angle
)
726 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
728 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
729 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
730 float xstep
, ystep
, wstep
, hstep
;
733 xstep
= (float)(fx
- x
) / steps
;
734 ystep
= (float)(fy
- y
) / steps
;
735 wstep
= (float)(fw
- w
) / steps
;
736 hstep
= (float)(fh
- h
) / steps
;
738 for (j
= 0; j
< FRAMES
; j
++) {
745 for (i
= 0; i
< steps
; i
++) {
746 for (j
= 0; j
< FRAMES
; j
++) {
747 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
748 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
751 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
753 for (j
= 0; j
< FRAMES
; j
++) {
754 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
755 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
756 if (j
< FRAMES
- 1) {
770 for (j
= 0; j
< FRAMES
; j
++) {
771 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
774 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
776 for (j
= 0; j
< FRAMES
; j
++) {
777 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
785 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
787 int style
= wPreferences
.iconification_style
; /* Catch the value */
790 if (style
== WIS_NONE
)
793 if (style
== WIS_RANDOM
) {
799 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
801 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
804 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
806 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
810 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
812 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
816 #endif /* ANIMATIONS */
818 static void flushExpose()
822 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
823 WMHandleEvent(&tmpev
);
827 static void unmapTransientsFor(WWindow
*wwin
)
831 tmp
= wwin
->screen_ptr
->focused_window
;
833 /* unmap the transients for this transient */
834 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
835 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
836 unmapTransientsFor(tmp
);
837 tmp
->flags
.miniaturized
= 1;
838 if (!tmp
->flags
.shaded
) {
841 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
844 if (!tmp->flags.shaded)
846 wClientSetState(tmp
, IconicState
, None
);
848 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
854 static void mapTransientsFor(WWindow
*wwin
)
858 tmp
= wwin
->screen_ptr
->focused_window
;
860 /* recursively map the transients for this transient */
861 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
862 && tmp
->icon
== NULL
) {
863 mapTransientsFor(tmp
);
864 tmp
->flags
.miniaturized
= 0;
865 if (!tmp
->flags
.shaded
) {
868 XMapWindow(dpy
, tmp
->frame
->core
->window
);
870 tmp
->flags
.semi_focused
= 0;
872 if (!tmp->flags.shaded)
874 wClientSetState(tmp
, NormalState
, None
);
876 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
882 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
889 /* hackish way to detect transient_for cycle */
890 i
= wwin
->screen_ptr
->window_count
+ 1;
892 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
893 wwin
= wWindowFor(wwin
->transient_for
);
896 if (i
== 0 && wwin
) {
897 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
904 void wIconifyWindow(WWindow
* wwin
)
906 XWindowAttributes attribs
;
909 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
910 /* the window doesn't exist anymore */
914 if (wwin
->flags
.miniaturized
) {
918 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
919 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
921 if (owner
&& owner
->flags
.miniaturized
)
925 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
927 /* if the window is in another workspace, simplify process */
929 /* icon creation may take a while */
930 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
931 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
932 GrabModeAsync
, None
, None
, CurrentTime
);
935 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
936 if (!wwin
->flags
.icon_moved
) {
937 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
939 wwin
->icon
= wIconCreate(wwin
);
941 wwin
->icon
->mapped
= 1;
944 wwin
->flags
.miniaturized
= 1;
945 wwin
->flags
.mapped
= 0;
947 /* unmap transients */
949 unmapTransientsFor(wwin
);
952 XUngrabPointer(dpy
, CurrentTime
);
954 /* let all Expose events arrive so that we can repaint
955 * something before the animation starts (and the server is grabbed) */
958 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
959 wClientSetState(wwin
, IconicState
, None
);
961 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
965 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
966 && !wPreferences
.no_animations
) {
969 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
972 iw
= wwin
->icon
->core
->width
;
973 ih
= wwin
->icon
->core
->height
;
975 if (wwin
->flags
.net_handle_icon
) {
983 iw
= wwin
->screen_ptr
->scr_width
;
984 ih
= wwin
->screen_ptr
->scr_height
;
987 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
988 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
993 wwin
->flags
.skip_next_animation
= 0;
995 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
996 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
997 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
999 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1001 AddToStackList(wwin
->icon
->core
);
1003 wLowerFrame(wwin
->icon
->core
);
1007 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1010 * It doesn't seem to be working and causes button event hangup
1011 * when deiconifying a transient window.
1012 setupIconGrabs(wwin->icon);
1014 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1015 && wPreferences
.focus_mode
== WKF_CLICK
) {
1020 if (!WFLAGP(tmp
, no_focusable
)
1021 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1022 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1026 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1027 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1028 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1031 if (!wwin
->screen_ptr
->flags
.startup
) {
1032 /* Catch up with events not processed while animation was running */
1033 Window clientwin
= wwin
->client_win
;
1035 ProcessPendingEvents();
1037 /* the window can disappear while ProcessPendingEvents() runs */
1038 if (!wWindowFor(clientwin
)) {
1045 /* maybe we want to do this regardless of net_handle_icon
1046 * it seems to me we might break behaviour this way.
1048 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1049 && !wwin
->flags
.net_handle_icon
)
1050 wIconSelect(wwin
->icon
);
1052 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1054 if (wPreferences
.auto_arrange_icons
)
1055 wArrangeIcons(wwin
->screen_ptr
, True
);
1058 void wDeiconifyWindow(WWindow
*wwin
)
1060 /* Let's avoid changing workspace while deiconifying */
1061 ignore_wks_change
= 1;
1063 /* we're hiding for show_desktop */
1064 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1065 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1068 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1070 if (!wwin
->flags
.miniaturized
)
1073 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1074 WWindow
*owner
= recursiveTransientFor(wwin
);
1076 if (owner
&& owner
->flags
.miniaturized
) {
1077 wDeiconifyWindow(owner
);
1078 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1079 wRaiseFrame(wwin
->frame
->core
);
1084 wwin
->flags
.miniaturized
= 0;
1086 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1087 wwin
->flags
.mapped
= 1;
1090 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1091 /* maybe we want to do this regardless of net_handle_icon
1092 * it seems to me we might break behaviour this way.
1094 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1095 && wwin
->icon
!= NULL
) {
1096 if (wwin
->icon
->selected
)
1097 wIconSelect(wwin
->icon
);
1099 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1103 /* if the window is in another workspace, do it silently */
1104 if (!netwm_hidden
) {
1106 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1107 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1110 if (!wPreferences
.disable_miniwindows
1111 && !wwin
->flags
.net_handle_icon
) {
1114 iw
= wwin
->icon
->core
->width
;
1115 ih
= wwin
->icon
->core
->height
;
1117 if (wwin
->flags
.net_handle_icon
) {
1125 iw
= wwin
->screen_ptr
->scr_width
;
1126 ih
= wwin
->screen_ptr
->scr_height
;
1129 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1130 wwin
->frame_x
, wwin
->frame_y
,
1131 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1133 #endif /* ANIMATIONS */
1134 wwin
->flags
.skip_next_animation
= 0;
1136 if (!wwin
->flags
.shaded
) {
1137 XMapWindow(dpy
, wwin
->client_win
);
1139 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1140 wRaiseFrame(wwin
->frame
->core
);
1141 if (!wwin
->flags
.shaded
) {
1142 wClientSetState(wwin
, NormalState
, None
);
1144 mapTransientsFor(wwin
);
1147 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1148 && !wwin
->flags
.net_handle_icon
) {
1149 RemoveFromStackList(wwin
->icon
->core
);
1150 /* removeIconGrabs(wwin->icon); */
1151 wIconDestroy(wwin
->icon
);
1155 if (!netwm_hidden
) {
1158 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1161 if (!wwin
->screen_ptr
->flags
.startup
) {
1162 /* Catch up with events not processed while animation was running */
1163 Window clientwin
= wwin
->client_win
;
1165 ProcessPendingEvents();
1167 /* the window can disappear while ProcessPendingEvents() runs */
1168 if (!wWindowFor(clientwin
)) {
1175 if (wPreferences
.auto_arrange_icons
) {
1176 wArrangeIcons(wwin
->screen_ptr
, True
);
1179 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1181 /* In case we were shaded and iconified, also unshade */
1183 wUnshadeWindow(wwin
);
1185 ignore_wks_change
= 0;
1188 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1190 if (wwin
->flags
.miniaturized
) {
1192 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1193 wwin
->icon
->mapped
= 0;
1195 wwin
->flags
.hidden
= 1;
1197 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1201 if (wwin
->flags
.inspector_open
) {
1202 wHideInspectorForWindow(wwin
);
1205 wwin
->flags
.hidden
= 1;
1208 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1212 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1213 !wwin
->flags
.skip_next_animation
&& animate
) {
1214 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1215 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1216 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1219 wwin
->flags
.skip_next_animation
= 0;
1221 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1224 void wHideOtherApplications(WWindow
*awin
)
1231 wwin
= awin
->screen_ptr
->focused_window
;
1235 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1236 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1237 && !wwin
->flags
.internal_window
1238 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1240 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1241 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1242 wwin
->flags
.skip_next_animation
= 1;
1243 wIconifyWindow(wwin
);
1245 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1246 tapp
= wApplicationOf(wwin
->main_window
);
1248 tapp
->flags
.skip_next_animation
= 1;
1249 wHideApplication(tapp
);
1251 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1252 wwin
->flags
.skip_next_animation
= 1;
1253 wIconifyWindow(wwin
);
1261 wSetFocusTo(awin->screen_ptr, awin);
1265 void wHideApplication(WApplication
*wapp
)
1273 wwarning("trying to hide a non grouped window");
1276 if (!wapp
->main_window_desc
) {
1277 wwarning("group leader not found for window group");
1280 scr
= wapp
->main_window_desc
->screen_ptr
;
1282 wlist
= scr
->focused_window
;
1286 if (wlist
->main_window
== wapp
->main_window
)
1287 wapp
->last_focused
= wlist
;
1289 wapp
->last_focused
= NULL
;
1291 animate
= !wapp
->flags
.skip_next_animation
;
1294 if (wlist
->main_window
== wapp
->main_window
) {
1295 if (wlist
->flags
.focused
) {
1298 if (wapp
->app_icon
) {
1299 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1300 wapp
->app_icon
->y_pos
, wlist
, animate
);
1304 wlist
= wlist
->prev
;
1307 wapp
->flags
.skip_next_animation
= 0;
1310 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1311 wlist
= scr
->focused_window
;
1313 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1314 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1316 wlist
= wlist
->prev
;
1318 wSetFocusTo(scr
, wlist
);
1320 wSetFocusTo(scr
, NULL
);
1324 wapp
->flags
.hidden
= 1;
1326 if (wPreferences
.auto_arrange_icons
) {
1327 wArrangeIcons(scr
, True
);
1331 wAppIconPaint(wapp
->app_icon
);
1335 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1337 if (bringToCurrentWS
)
1338 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1340 wwin
->flags
.hidden
= 0;
1343 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1344 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1345 icon
->core
->width
, icon
->core
->height
,
1346 wwin
->frame_x
, wwin
->frame_y
,
1347 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1350 wwin
->flags
.skip_next_animation
= 0;
1351 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1352 XMapWindow(dpy
, wwin
->client_win
);
1353 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1354 wClientSetState(wwin
, NormalState
, None
);
1355 wwin
->flags
.mapped
= 1;
1356 wRaiseFrame(wwin
->frame
->core
);
1358 if (wwin
->flags
.inspector_open
) {
1359 wUnhideInspectorForWindow(wwin
);
1362 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1365 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1368 WWindow
*wlist
, *next
;
1369 WWindow
*focused
= NULL
;
1375 scr
= wapp
->main_window_desc
->screen_ptr
;
1376 wlist
= scr
->focused_window
;
1380 /* goto beginning of list */
1382 wlist
= wlist
->prev
;
1384 animate
= !wapp
->flags
.skip_next_animation
;
1389 if (wlist
->main_window
== wapp
->main_window
) {
1390 if (wlist
->flags
.focused
)
1392 else if (!focused
|| !focused
->flags
.focused
)
1395 if (wlist
->flags
.miniaturized
) {
1396 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1397 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1398 if (!wlist
->icon
->mapped
) {
1401 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1402 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1403 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1407 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1408 wlist
->icon
->mapped
= 1;
1410 wRaiseFrame(wlist
->icon
->core
);
1412 if (bringToCurrentWS
)
1413 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1414 wlist
->flags
.hidden
= 0;
1415 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1416 wDeiconifyWindow(wlist
);
1418 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1419 } else if (wlist
->flags
.shaded
) {
1420 if (bringToCurrentWS
)
1421 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1422 wlist
->flags
.hidden
= 0;
1423 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1424 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1426 wUnshadeWindow(wlist
);
1427 wRaiseFrame(wlist
->frame
->core
);
1430 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1431 } else if (wlist
->flags
.hidden
) {
1432 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1433 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1436 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1437 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1439 wRaiseFrame(wlist
->frame
->core
);
1445 wapp
->flags
.skip_next_animation
= 0;
1446 wapp
->flags
.hidden
= 0;
1448 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1449 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1450 wSetFocusTo(scr
, wapp
->last_focused
);
1451 } else if (focused
) {
1452 wSetFocusTo(scr
, focused
);
1454 wapp
->last_focused
= NULL
;
1455 if (wPreferences
.auto_arrange_icons
) {
1456 wArrangeIcons(scr
, True
);
1459 wAppIconPaint(wapp
->app_icon
);
1463 void wShowAllWindows(WScreen
*scr
)
1465 WWindow
*wwin
, *old_foc
;
1468 old_foc
= wwin
= scr
->focused_window
;
1470 if (!wwin
->flags
.internal_window
&&
1471 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1472 if (wwin
->flags
.miniaturized
) {
1473 wwin
->flags
.skip_next_animation
= 1;
1474 wDeiconifyWindow(wwin
);
1475 } else if (wwin
->flags
.hidden
) {
1476 wapp
= wApplicationOf(wwin
->main_window
);
1478 wUnhideApplication(wapp
, False
, False
);
1480 wwin
->flags
.skip_next_animation
= 1;
1481 wDeiconifyWindow(wwin
);
1487 wSetFocusTo(scr
, old_foc
);
1488 /*wRaiseFrame(old_foc->frame->core); */
1491 void wRefreshDesktop(WScreen
*scr
)
1494 XSetWindowAttributes attr
;
1496 attr
.backing_store
= NotUseful
;
1497 attr
.save_under
= False
;
1498 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1499 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1500 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1501 XMapRaised(dpy
, win
);
1502 XDestroyWindow(dpy
, win
);
1506 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1512 const int heads
= wXineramaHeads(scr
);
1515 int pf
; /* primary axis */
1516 int sf
; /* secondary axis */
1520 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1526 int isize
= wPreferences
.icon_size
;
1528 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1530 for (head
= 0; head
< heads
; ++head
) {
1531 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1532 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1533 vars
[head
].pi
= vars
[head
].si
= 0;
1534 vars
[head
].sx1
= rect
.pos
.x
;
1535 vars
[head
].sy1
= rect
.pos
.y
;
1536 vars
[head
].sw
= rect
.size
.width
;
1537 vars
[head
].sh
= rect
.size
.height
;
1538 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1539 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1540 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1541 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1542 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1543 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1545 /* icon yard boundaries */
1546 if (wPreferences
.icon_yard
& IY_VERT
) {
1547 vars
[head
].pf
= vars
[head
].fullH
;
1548 vars
[head
].sf
= vars
[head
].fullW
;
1550 vars
[head
].pf
= vars
[head
].fullW
;
1551 vars
[head
].sf
= vars
[head
].fullH
;
1553 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1554 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1557 vars
[head
].xo
= vars
[head
].sx1
;
1560 if (wPreferences
.icon_yard
& IY_TOP
) {
1561 vars
[head
].yo
= vars
[head
].sy1
;
1564 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1569 #define X ((wPreferences.icon_yard & IY_VERT) \
1570 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1571 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1573 #define Y ((wPreferences.icon_yard & IY_VERT) \
1574 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1575 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1577 /* arrange application icons */
1578 aicon
= scr
->app_icon_list
;
1579 /* reverse them to avoid unnecessarily sliding of icons */
1580 while (aicon
&& aicon
->next
)
1581 aicon
= aicon
->next
;
1584 if (!aicon
->docked
) {
1585 /* CHECK: can icon be NULL here ? */
1586 /* The intention here is to place the AppIcon on the head that
1587 * contains most of the applications _main_ window. */
1588 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1590 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1592 if (!wPreferences
.no_animations
) {
1593 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1595 #endif /* ANIMATIONS */
1597 wAppIconMove(aicon
, X
, Y
);
1599 if (vars
[head
].pi
>= vars
[head
].pf
) {
1604 aicon
= aicon
->prev
;
1607 /* arrange miniwindows */
1608 wwin
= scr
->focused_window
;
1609 /* reverse them to avoid unnecessarily shuffling */
1610 while (wwin
&& wwin
->prev
)
1614 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1615 (wwin
->frame
->workspace
== scr
->current_workspace
||
1616 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1618 head
= wGetHeadForWindow(wwin
);
1620 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1621 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1623 if (wPreferences
.no_animations
) {
1624 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1626 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1627 wwin
->icon_y
, X
, Y
);
1630 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1631 #endif /* ANIMATIONS */
1637 if (vars
[head
].pi
>= vars
[head
].pf
) {
1644 wwin
->flags
.icon_moved
= 0;
1646 /* we reversed the order, so we use next */
1653 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1655 WScreen
*scr
= wwin
->screen_ptr
;
1658 wwin
->flags
.selected
= 1;
1659 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1661 if (!HAS_BORDER(wwin
)) {
1662 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1665 if (!scr
->selected_windows
)
1666 scr
->selected_windows
= WMCreateArray(4);
1667 WMAddToArray(scr
->selected_windows
, wwin
);
1669 wwin
->flags
.selected
= 0;
1670 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1672 if (!HAS_BORDER(wwin
)) {
1673 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1676 if (scr
->selected_windows
) {
1677 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1682 void wMakeWindowVisible(WWindow
*wwin
)
1684 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1685 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1687 if (wwin
->flags
.shaded
) {
1688 wUnshadeWindow(wwin
);
1690 if (wwin
->flags
.hidden
) {
1693 app
= wApplicationOf(wwin
->main_window
);
1695 /* trick to get focus to this window */
1696 app
->last_focused
= wwin
;
1697 wUnhideApplication(app
, False
, False
);
1700 if (wwin
->flags
.miniaturized
) {
1701 wDeiconifyWindow(wwin
);
1703 if (!WFLAGP(wwin
, no_focusable
))
1704 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1705 wRaiseFrame(wwin
->frame
->core
);
1710 * Do the animation while shading (called with what = SHADE)
1711 * or unshading (what = UNSHADE).
1714 static void shade_animate(WWindow
*wwin
, Bool what
)
1717 time_t time0
= time(NULL
);
1719 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1724 if (!wwin
->screen_ptr
->flags
.startup
) {
1725 /* do the shading animation */
1726 h
= wwin
->frame
->core
->height
;
1727 s
= h
/ SHADE_STEPS
;
1730 w
= wwin
->frame
->core
->width
;
1731 y
= wwin
->frame
->top_width
;
1732 while (h
> wwin
->frame
->top_width
+ 1) {
1733 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1734 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1737 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1740 if (SHADE_DELAY
> 0) {
1741 wusleep(SHADE_DELAY
* 1000L);
1748 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1753 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1754 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1755 s
= abs(y
) / SHADE_STEPS
;
1758 w
= wwin
->frame
->core
->width
;
1759 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1761 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1762 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1763 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1765 if (SHADE_DELAY
> 0) {
1766 wusleep(SHADE_DELAY
* 2000L / 3);
1773 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1777 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);