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
);
137 wApplicationDeactivate(oapp
);
140 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
142 } else if (old_scr
!= scr
&& old_focused
) {
143 wWindowUnfocus(old_focused
);
146 wasfocused
= wwin
->flags
.focused
;
147 napp
= wApplicationOf(wwin
->main_window
);
149 /* remember last workspace where the app has been */
151 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
152 napp
->last_workspace
= wwin
->frame
->workspace
;
155 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
156 /* install colormap if colormap mode is lock mode */
157 if (wPreferences
.colormap_mode
== WCM_CLICK
)
158 wColormapInstallForWindow(scr
, wwin
);
160 /* set input focus */
161 switch (wwin
->focus_mode
) {
163 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
167 case WFM_LOCALLY_ACTIVE
:
168 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
171 case WFM_GLOBALLY_ACTIVE
:
175 if (wwin
->protocols
.TAKE_FOCUS
) {
176 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
180 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
182 if (WFLAGP(wwin
, no_focusable
))
185 /* if this is not the focused window focus it */
186 if (focused
!= wwin
) {
187 /* change the focus window list order */
189 wwin
->prev
->next
= wwin
->next
;
192 wwin
->next
->prev
= wwin
->prev
;
194 wwin
->prev
= focused
;
195 focused
->next
= wwin
;
197 scr
->focused_window
= wwin
;
199 if (oapp
&& oapp
!= napp
) {
200 wAppMenuUnmap(oapp
->menu
);
201 wApplicationDeactivate(oapp
);
205 wWindowFocus(wwin
, focused
);
207 if (napp
&& !wasfocused
) {
209 wUserMenuRefreshInstances(napp
->menu
, wwin
);
210 #endif /* USER_MENU */
212 if (wwin
->flags
.mapped
)
213 wAppMenuMap(napp
->menu
, wwin
);
216 wApplicationActivate(napp
);
222 void wShadeWindow(WWindow
*wwin
)
225 if (wwin
->flags
.shaded
)
228 XLowerWindow(dpy
, wwin
->client_win
);
229 shade_animate(wwin
, SHADE
);
231 wwin
->flags
.skip_next_animation
= 0;
232 wwin
->flags
.shaded
= 1;
233 wwin
->flags
.mapped
= 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
236 XUnmapWindow(dpy
, wwin
->client_win
);
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
242 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
243 wWindowSynthConfigureNotify(wwin
);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
252 if (!wwin
->screen_ptr
->flags
.startup
) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
259 void wUnshadeWindow(WWindow
*wwin
)
262 if (!wwin
->flags
.shaded
)
265 wwin
->flags
.shaded
= 0;
266 wwin
->flags
.mapped
= 1;
267 XMapWindow(dpy
, wwin
->client_win
);
269 shade_animate(wwin
, UNSHADE
);
271 wwin
->flags
.skip_next_animation
= 0;
272 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
273 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
275 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
276 wWindowSynthConfigureNotify(wwin
);
278 /* if the window is focused, set the focus again as it was disabled during
280 if (wwin
->flags
.focused
)
281 wSetFocusTo(wwin
->screen_ptr
, wwin
);
283 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
286 /* Set the old coordinates using the current values */
287 static void save_old_geometry(WWindow
*wwin
)
289 wwin
->old_geometry
.width
= wwin
->client
.width
;
290 wwin
->old_geometry
.height
= wwin
->client
.height
;
291 wwin
->old_geometry
.x
= wwin
->frame_x
;
292 wwin
->old_geometry
.y
= wwin
->frame_y
;
295 void wMaximizeWindow(WWindow
*wwin
, int directions
)
298 unsigned int new_width
, new_height
, half_scr_width
;
299 WArea usableArea
, totalArea
;
303 if (!IS_RESIZABLE(wwin
))
306 if (!HAS_BORDER(wwin
))
309 /* the size to adjust the geometry */
310 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
312 /* save old coordinates before we change the current values */
313 save_old_geometry(wwin
);
317 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
318 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
319 usableArea
= totalArea
;
321 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
322 WScreen
*scr
= wwin
->screen_ptr
;
325 if (directions
& MAX_KEYBOARD
)
326 head
= wGetHeadForWindow(wwin
);
328 head
= wGetHeadForPointerLocation(scr
);
330 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
333 /* Only save directions, not kbd or xinerama hints */
334 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
336 if (WFLAGP(wwin
, full_maximize
)) {
337 usableArea
= totalArea
;
339 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
341 if (wwin
->flags
.shaded
) {
342 wwin
->flags
.skip_next_animation
= 1;
343 wUnshadeWindow(wwin
);
346 if (directions
& MAX_HORIZONTAL
) {
347 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
348 new_x
= usableArea
.x1
;
349 } else if (directions
& MAX_LEFTHALF
) {
350 new_width
= half_scr_width
- adj_size
;
351 new_x
= usableArea
.x1
;
352 } else if (directions
& MAX_RIGHTHALF
) {
353 new_width
= half_scr_width
- adj_size
;
354 new_x
= usableArea
.x1
+ half_scr_width
;
356 new_x
= wwin
->frame_x
;
357 new_width
= wwin
->frame
->core
->width
;
360 if (directions
& MAX_VERTICAL
) {
361 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
362 new_y
= usableArea
.y1
;
363 if (WFLAGP(wwin
, full_maximize
)) {
364 new_y
-= wwin
->frame
->top_width
;
365 new_height
+= wwin
->frame
->bottom_width
- 1;
368 new_y
= wwin
->frame_y
;
369 new_height
= wwin
->frame
->core
->height
;
372 if (!WFLAGP(wwin
, full_maximize
)) {
373 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
376 if (directions
& MAX_MAXIMUS
) {
377 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
378 new_width
-= adj_size
;
379 new_height
-= adj_size
;
380 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
381 new_y
-= wwin
->frame
->top_width
;
382 new_height
+= wwin
->frame
->top_width
- 1;
386 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
388 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
389 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
391 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
393 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
395 /* set maximization state */
396 wwin
->flags
.maximized
= directions
;
399 /* the window boundary coordinates */
409 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
411 obs
->left
= wwin
->frame_x
;
412 obs
->top
= wwin
->frame_y
;
413 obs
->width
= wwin
->frame
->core
->width
;
414 obs
->height
= wwin
->frame
->core
->height
;
415 obs
->bottom
= obs
->top
+ obs
->height
;
416 obs
->right
= obs
->left
+ obs
->width
;
420 * Maximus: tiled maximization (maximize without overlapping other windows)
422 * The original window 'orig' will be maximized to new coordinates 'new'.
423 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
425 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
426 unsigned int *new_width
, unsigned int *new_height
)
429 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
430 short int adjust_height
;
431 int x_intsect
, y_intsect
;
432 /* the obstructing, original and new windows */
433 win_coords obs
, orig
, new;
435 /* set the original coordinate positions of the window to be Maximumized */
436 set_window_coords(wwin
, &orig
);
438 /* Try to fully maximize first, then readjust later */
439 new.left
= usableArea
.x1
;
440 new.right
= usableArea
.x2
;
441 new.top
= usableArea
.y1
;
442 new.bottom
= usableArea
.y2
;
444 if (HAS_TITLEBAR(wwin
))
445 tbar_height_0
= TITLEBAR_HEIGHT
;
446 if (HAS_RESIZEBAR(wwin
))
447 rbar_height_0
= RESIZEBAR_HEIGHT
;
448 if (HAS_BORDER(wwin
))
449 bd_width_0
= FRAME_BORDER_WIDTH
;
451 /* the length to be subtracted if the window has titlebar, etc */
452 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
455 /* The focused window is always the last in the list */
457 /* ignore windows in other workspaces etc */
458 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
459 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
465 /* Set the coordinates of obstructing window */
466 set_window_coords(tmp
, &obs
);
468 /* Try to maximize in the y direction first */
469 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
470 if (x_intsect
!= 0) {
471 /* TODO: Consider the case when coords are equal */
472 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
473 /* w_0 is below the bottom of w_j */
474 new.top
= obs
.bottom
+ 1;
476 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
477 /* The bottom of w_0 is above the top of w_j */
478 new.bottom
= obs
.top
- 1;
485 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
486 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
492 set_window_coords(tmp
, &obs
);
495 * Use the new.top and new.height instead of original values
496 * as they may have different intersections with the obstructing windows
498 new.height
= new.bottom
- new.top
- adjust_height
;
499 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
500 if (y_intsect
!= 0) {
501 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
502 /* w_0 is completely to the right of w_j */
503 new.left
= obs
.right
+ 1;
505 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
506 /* w_0 is completely to the left of w_j */
507 new.right
= obs
.left
- 1;
514 /* xcalc needs -7 here, but other apps don't */
515 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
516 *new_width
= new.right
- new.left
;
519 void wUnmaximizeWindow(WWindow
*wwin
)
522 WMRect old_geom_rect
;
526 if (!wwin
->flags
.maximized
)
529 if (wwin
->flags
.shaded
) {
530 wwin
->flags
.skip_next_animation
= 1;
531 wUnshadeWindow(wwin
);
533 /* Use old coordinates if they are set, current values otherwise */
534 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
535 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
536 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
537 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
538 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
539 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
540 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
542 wwin
->flags
.maximized
= 0;
543 wWindowConfigure(wwin
, x
, y
, w
, h
);
545 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
548 void wFullscreenWindow(WWindow
*wwin
)
553 if (wwin
->flags
.fullscreen
)
556 wwin
->flags
.fullscreen
= True
;
558 wWindowConfigureBorders(wwin
);
560 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
562 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
563 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
564 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
565 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
567 head
= wGetHeadForWindow(wwin
);
568 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
569 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
571 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
574 void wUnfullscreenWindow(WWindow
*wwin
)
576 if (!wwin
->flags
.fullscreen
)
579 wwin
->flags
.fullscreen
= False
;
581 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
582 if (WFLAGP(wwin
, sunken
)) {
583 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
584 } else if (WFLAGP(wwin
, floating
)) {
585 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
587 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
591 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
592 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
594 wWindowConfigureBorders(wwin
);
596 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
597 wFrameWindowPaint(wwin->frame);
600 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
604 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
606 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
607 float cx
, cy
, cw
, ch
;
608 float xstep
, ystep
, wstep
, hstep
;
611 float angle
, final_angle
, delta
;
613 xstep
= (float)(fx
- x
) / steps
;
614 ystep
= (float)(fy
- y
) / steps
;
615 wstep
= (float)(fw
- w
) / steps
;
616 hstep
= (float)(fh
- h
) / steps
;
623 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
624 delta
= (float)(final_angle
/ FRAMES
);
625 for (angle
= 0;; angle
+= delta
) {
626 if (angle
> final_angle
)
629 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
630 dch
= (ch
/ 2) * cos(angle
);
631 midy
= cy
+ (ch
/ 2);
633 points
[0].x
= cx
+ dx
;
634 points
[0].y
= midy
- dch
;
635 points
[1].x
= cx
+ cw
- dx
;
636 points
[1].y
= points
[0].y
;
637 points
[2].x
= cx
+ cw
+ dx
;
638 points
[2].y
= midy
+ dch
;
639 points
[3].x
= cx
- dx
;
640 points
[3].y
= points
[2].y
;
641 points
[4].x
= points
[0].x
;
642 points
[4].y
= points
[0].y
;
645 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
647 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
649 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
655 if (angle
>= final_angle
)
665 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
667 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
668 float cx
, cy
, cw
, ch
;
669 float xstep
, ystep
, wstep
, hstep
;
671 float angle
, final_angle
, a
, d
, delta
;
678 xstep
= (float)(fx
- x
) / steps
;
679 ystep
= (float)(fy
- y
) / steps
;
680 wstep
= (float)(fw
- w
) / steps
;
681 hstep
= (float)(fh
- h
) / steps
;
688 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
689 delta
= (float)(final_angle
/ FRAMES
);
690 for (angle
= 0;; angle
+= delta
) {
691 if (angle
> final_angle
)
695 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
697 points
[0].x
= cx
+ cos(angle
- a
) * d
;
698 points
[0].y
= cy
+ sin(angle
- a
) * d
;
699 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
700 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
701 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
702 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
703 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
704 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
705 points
[4].x
= cx
+ cos(angle
- a
) * d
;
706 points
[4].y
= cy
+ sin(angle
- a
) * d
;
708 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
710 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
712 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
718 if (angle
>= final_angle
)
727 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
729 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
730 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
731 float xstep
, ystep
, wstep
, hstep
;
734 xstep
= (float)(fx
- x
) / steps
;
735 ystep
= (float)(fy
- y
) / steps
;
736 wstep
= (float)(fw
- w
) / steps
;
737 hstep
= (float)(fh
- h
) / steps
;
739 for (j
= 0; j
< FRAMES
; j
++) {
746 for (i
= 0; i
< steps
; i
++) {
747 for (j
= 0; j
< FRAMES
; j
++) {
748 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
749 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
752 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
754 for (j
= 0; j
< FRAMES
; j
++) {
755 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
756 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
757 if (j
< FRAMES
- 1) {
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
]);
775 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
777 for (j
= 0; j
< FRAMES
; j
++) {
778 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
786 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
788 int style
= wPreferences
.iconification_style
; /* Catch the value */
791 if (style
== WIS_NONE
)
794 if (style
== WIS_RANDOM
) {
800 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
802 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
805 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
807 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
811 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
813 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
817 #endif /* ANIMATIONS */
819 static void flushExpose(void)
823 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
824 WMHandleEvent(&tmpev
);
828 static void unmapTransientsFor(WWindow
*wwin
)
832 tmp
= wwin
->screen_ptr
->focused_window
;
834 /* unmap the transients for this transient */
835 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
836 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
837 unmapTransientsFor(tmp
);
838 tmp
->flags
.miniaturized
= 1;
839 if (!tmp
->flags
.shaded
) {
842 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
845 if (!tmp->flags.shaded)
847 wClientSetState(tmp
, IconicState
, None
);
849 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
855 static void mapTransientsFor(WWindow
*wwin
)
859 tmp
= wwin
->screen_ptr
->focused_window
;
861 /* recursively map the transients for this transient */
862 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
863 && tmp
->icon
== NULL
) {
864 mapTransientsFor(tmp
);
865 tmp
->flags
.miniaturized
= 0;
866 if (!tmp
->flags
.shaded
) {
869 XMapWindow(dpy
, tmp
->frame
->core
->window
);
871 tmp
->flags
.semi_focused
= 0;
873 if (!tmp->flags.shaded)
875 wClientSetState(tmp
, NormalState
, None
);
877 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
883 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
890 /* hackish way to detect transient_for cycle */
891 i
= wwin
->screen_ptr
->window_count
+ 1;
893 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
894 wwin
= wWindowFor(wwin
->transient_for
);
897 if (i
== 0 && wwin
) {
898 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
905 void wIconifyWindow(WWindow
* wwin
)
907 XWindowAttributes attribs
;
910 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
911 /* the window doesn't exist anymore */
915 if (wwin
->flags
.miniaturized
) {
919 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
920 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
922 if (owner
&& owner
->flags
.miniaturized
)
926 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
928 /* if the window is in another workspace, simplify process */
930 /* icon creation may take a while */
931 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
932 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
933 GrabModeAsync
, None
, None
, CurrentTime
);
936 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
937 if (!wwin
->flags
.icon_moved
) {
938 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
940 wwin
->icon
= wIconCreate(wwin
);
942 wwin
->icon
->mapped
= 1;
945 wwin
->flags
.miniaturized
= 1;
946 wwin
->flags
.mapped
= 0;
948 /* unmap transients */
950 unmapTransientsFor(wwin
);
953 XUngrabPointer(dpy
, CurrentTime
);
955 /* let all Expose events arrive so that we can repaint
956 * something before the animation starts (and the server is grabbed) */
959 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
960 wClientSetState(wwin
, IconicState
, None
);
962 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
966 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
967 && !wPreferences
.no_animations
) {
970 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
973 iw
= wwin
->icon
->core
->width
;
974 ih
= wwin
->icon
->core
->height
;
976 if (wwin
->flags
.net_handle_icon
) {
984 iw
= wwin
->screen_ptr
->scr_width
;
985 ih
= wwin
->screen_ptr
->scr_height
;
988 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
989 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
994 wwin
->flags
.skip_next_animation
= 0;
996 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
997 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
998 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1000 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1002 AddToStackList(wwin
->icon
->core
);
1004 wLowerFrame(wwin
->icon
->core
);
1008 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1011 * It doesn't seem to be working and causes button event hangup
1012 * when deiconifying a transient window.
1013 setupIconGrabs(wwin->icon);
1015 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1016 && wPreferences
.focus_mode
== WKF_CLICK
) {
1021 if (!WFLAGP(tmp
, no_focusable
)
1022 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1023 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1027 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1028 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1029 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1032 if (!wwin
->screen_ptr
->flags
.startup
) {
1033 /* Catch up with events not processed while animation was running */
1034 Window clientwin
= wwin
->client_win
;
1036 ProcessPendingEvents();
1038 /* the window can disappear while ProcessPendingEvents() runs */
1039 if (!wWindowFor(clientwin
)) {
1046 /* maybe we want to do this regardless of net_handle_icon
1047 * it seems to me we might break behaviour this way.
1049 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1050 && !wwin
->flags
.net_handle_icon
)
1051 wIconSelect(wwin
->icon
);
1053 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1055 if (wPreferences
.auto_arrange_icons
)
1056 wArrangeIcons(wwin
->screen_ptr
, True
);
1059 void wDeiconifyWindow(WWindow
*wwin
)
1061 /* Let's avoid changing workspace while deiconifying */
1062 ignore_wks_change
= 1;
1064 /* we're hiding for show_desktop */
1065 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1066 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1069 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1071 if (!wwin
->flags
.miniaturized
)
1074 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1075 WWindow
*owner
= recursiveTransientFor(wwin
);
1077 if (owner
&& owner
->flags
.miniaturized
) {
1078 wDeiconifyWindow(owner
);
1079 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1080 wRaiseFrame(wwin
->frame
->core
);
1085 wwin
->flags
.miniaturized
= 0;
1087 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1088 wwin
->flags
.mapped
= 1;
1091 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1092 /* maybe we want to do this regardless of net_handle_icon
1093 * it seems to me we might break behaviour this way.
1095 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1096 && wwin
->icon
!= NULL
) {
1097 if (wwin
->icon
->selected
)
1098 wIconSelect(wwin
->icon
);
1100 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1104 /* if the window is in another workspace, do it silently */
1105 if (!netwm_hidden
) {
1107 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1108 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1111 if (!wPreferences
.disable_miniwindows
1112 && !wwin
->flags
.net_handle_icon
) {
1115 iw
= wwin
->icon
->core
->width
;
1116 ih
= wwin
->icon
->core
->height
;
1118 if (wwin
->flags
.net_handle_icon
) {
1126 iw
= wwin
->screen_ptr
->scr_width
;
1127 ih
= wwin
->screen_ptr
->scr_height
;
1130 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1131 wwin
->frame_x
, wwin
->frame_y
,
1132 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1134 #endif /* ANIMATIONS */
1135 wwin
->flags
.skip_next_animation
= 0;
1137 if (!wwin
->flags
.shaded
) {
1138 XMapWindow(dpy
, wwin
->client_win
);
1140 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1141 wRaiseFrame(wwin
->frame
->core
);
1142 if (!wwin
->flags
.shaded
) {
1143 wClientSetState(wwin
, NormalState
, None
);
1145 mapTransientsFor(wwin
);
1148 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1149 && !wwin
->flags
.net_handle_icon
) {
1150 RemoveFromStackList(wwin
->icon
->core
);
1151 /* removeIconGrabs(wwin->icon); */
1152 wIconDestroy(wwin
->icon
);
1156 if (!netwm_hidden
) {
1159 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1162 if (!wwin
->screen_ptr
->flags
.startup
) {
1163 /* Catch up with events not processed while animation was running */
1164 Window clientwin
= wwin
->client_win
;
1166 ProcessPendingEvents();
1168 /* the window can disappear while ProcessPendingEvents() runs */
1169 if (!wWindowFor(clientwin
)) {
1176 if (wPreferences
.auto_arrange_icons
) {
1177 wArrangeIcons(wwin
->screen_ptr
, True
);
1180 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1182 /* In case we were shaded and iconified, also unshade */
1184 wUnshadeWindow(wwin
);
1186 ignore_wks_change
= 0;
1189 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1191 if (wwin
->flags
.miniaturized
) {
1193 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1194 wwin
->icon
->mapped
= 0;
1196 wwin
->flags
.hidden
= 1;
1198 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1202 if (wwin
->flags
.inspector_open
) {
1203 wHideInspectorForWindow(wwin
);
1206 wwin
->flags
.hidden
= 1;
1209 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1213 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1214 !wwin
->flags
.skip_next_animation
&& animate
) {
1215 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1216 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1217 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1220 wwin
->flags
.skip_next_animation
= 0;
1222 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1225 void wHideAll(WScreen
*scr
)
1231 unsigned int wcount
= 0;
1238 menu
= scr
->switch_menu
;
1240 windows
= malloc(sizeof(WWindow
*));
1243 for (i
= 0; i
< menu
->entry_no
; i
++) {
1244 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1246 windows
= realloc(windows
, sizeof(WWindow
*) * (wcount
+1));
1249 wwin
= scr
->focused_window
;
1252 windows
[wcount
] = wwin
;
1254 windows
= realloc(windows
, sizeof(WWindow
*) * (wcount
+1));
1260 for (i
= 0; i
< wcount
; i
++) {
1262 if (wwin
->frame
->workspace
== scr
->current_workspace
1263 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1264 && !wwin
->flags
.internal_window
1265 && !WFLAGP(wwin
, no_miniaturizable
)
1267 wwin
->flags
.skip_next_animation
= 1;
1268 wIconifyWindow(wwin
);
1273 void wHideOtherApplications(WWindow
*awin
)
1280 wwin
= awin
->screen_ptr
->focused_window
;
1284 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1285 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1286 && !wwin
->flags
.internal_window
1287 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1289 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1290 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1291 wwin
->flags
.skip_next_animation
= 1;
1292 wIconifyWindow(wwin
);
1294 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1295 tapp
= wApplicationOf(wwin
->main_window
);
1297 tapp
->flags
.skip_next_animation
= 1;
1298 wHideApplication(tapp
);
1300 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1301 wwin
->flags
.skip_next_animation
= 1;
1302 wIconifyWindow(wwin
);
1310 wSetFocusTo(awin->screen_ptr, awin);
1314 void wHideApplication(WApplication
*wapp
)
1322 wwarning("trying to hide a non grouped window");
1325 if (!wapp
->main_window_desc
) {
1326 wwarning("group leader not found for window group");
1329 scr
= wapp
->main_window_desc
->screen_ptr
;
1331 wlist
= scr
->focused_window
;
1335 if (wlist
->main_window
== wapp
->main_window
)
1336 wapp
->last_focused
= wlist
;
1338 wapp
->last_focused
= NULL
;
1340 animate
= !wapp
->flags
.skip_next_animation
;
1343 if (wlist
->main_window
== wapp
->main_window
) {
1344 if (wlist
->flags
.focused
) {
1347 if (wapp
->app_icon
) {
1348 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1349 wapp
->app_icon
->y_pos
, wlist
, animate
);
1353 wlist
= wlist
->prev
;
1356 wapp
->flags
.skip_next_animation
= 0;
1359 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1360 wlist
= scr
->focused_window
;
1362 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1363 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1365 wlist
= wlist
->prev
;
1367 wSetFocusTo(scr
, wlist
);
1369 wSetFocusTo(scr
, NULL
);
1373 wapp
->flags
.hidden
= 1;
1375 if (wPreferences
.auto_arrange_icons
) {
1376 wArrangeIcons(scr
, True
);
1380 wAppIconPaint(wapp
->app_icon
);
1384 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1386 if (bringToCurrentWS
)
1387 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1389 wwin
->flags
.hidden
= 0;
1392 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1393 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1394 icon
->core
->width
, icon
->core
->height
,
1395 wwin
->frame_x
, wwin
->frame_y
,
1396 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1399 wwin
->flags
.skip_next_animation
= 0;
1400 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1401 XMapWindow(dpy
, wwin
->client_win
);
1402 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1403 wClientSetState(wwin
, NormalState
, None
);
1404 wwin
->flags
.mapped
= 1;
1405 wRaiseFrame(wwin
->frame
->core
);
1407 if (wwin
->flags
.inspector_open
) {
1408 wUnhideInspectorForWindow(wwin
);
1411 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1414 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1417 WWindow
*wlist
, *next
;
1418 WWindow
*focused
= NULL
;
1424 scr
= wapp
->main_window_desc
->screen_ptr
;
1425 wlist
= scr
->focused_window
;
1429 /* goto beginning of list */
1431 wlist
= wlist
->prev
;
1433 animate
= !wapp
->flags
.skip_next_animation
;
1438 if (wlist
->main_window
== wapp
->main_window
) {
1439 if (wlist
->flags
.focused
)
1441 else if (!focused
|| !focused
->flags
.focused
)
1444 if (wlist
->flags
.miniaturized
) {
1445 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1446 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1447 if (!wlist
->icon
->mapped
) {
1450 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1451 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1452 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1456 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1457 wlist
->icon
->mapped
= 1;
1459 wRaiseFrame(wlist
->icon
->core
);
1461 if (bringToCurrentWS
)
1462 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1463 wlist
->flags
.hidden
= 0;
1464 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1465 wDeiconifyWindow(wlist
);
1467 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1468 } else if (wlist
->flags
.shaded
) {
1469 if (bringToCurrentWS
)
1470 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1471 wlist
->flags
.hidden
= 0;
1472 wRaiseFrame(wlist
->frame
->core
);
1473 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1474 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1476 wUnshadeWindow(wlist
);
1479 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1480 } else if (wlist
->flags
.hidden
) {
1481 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1482 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1485 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1486 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1488 wRaiseFrame(wlist
->frame
->core
);
1494 wapp
->flags
.skip_next_animation
= 0;
1495 wapp
->flags
.hidden
= 0;
1497 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1498 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1499 wSetFocusTo(scr
, wapp
->last_focused
);
1500 } else if (focused
) {
1501 wSetFocusTo(scr
, focused
);
1503 wapp
->last_focused
= NULL
;
1504 if (wPreferences
.auto_arrange_icons
) {
1505 wArrangeIcons(scr
, True
);
1508 wAppIconPaint(wapp
->app_icon
);
1512 void wShowAllWindows(WScreen
*scr
)
1514 WWindow
*wwin
, *old_foc
;
1517 old_foc
= wwin
= scr
->focused_window
;
1519 if (!wwin
->flags
.internal_window
&&
1520 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1521 if (wwin
->flags
.miniaturized
) {
1522 wwin
->flags
.skip_next_animation
= 1;
1523 wDeiconifyWindow(wwin
);
1524 } else if (wwin
->flags
.hidden
) {
1525 wapp
= wApplicationOf(wwin
->main_window
);
1527 wUnhideApplication(wapp
, False
, False
);
1529 wwin
->flags
.skip_next_animation
= 1;
1530 wDeiconifyWindow(wwin
);
1536 wSetFocusTo(scr
, old_foc
);
1537 /*wRaiseFrame(old_foc->frame->core); */
1540 void wRefreshDesktop(WScreen
*scr
)
1543 XSetWindowAttributes attr
;
1545 attr
.backing_store
= NotUseful
;
1546 attr
.save_under
= False
;
1547 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1548 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1549 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1550 XMapRaised(dpy
, win
);
1551 XDestroyWindow(dpy
, win
);
1555 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1561 const int heads
= wXineramaHeads(scr
);
1564 int pf
; /* primary axis */
1565 int sf
; /* secondary axis */
1569 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1575 int isize
= wPreferences
.icon_size
;
1577 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1579 for (head
= 0; head
< heads
; ++head
) {
1580 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1581 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1582 vars
[head
].pi
= vars
[head
].si
= 0;
1583 vars
[head
].sx1
= rect
.pos
.x
;
1584 vars
[head
].sy1
= rect
.pos
.y
;
1585 vars
[head
].sw
= rect
.size
.width
;
1586 vars
[head
].sh
= rect
.size
.height
;
1587 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1588 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1589 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1590 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1591 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1592 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1594 /* icon yard boundaries */
1595 if (wPreferences
.icon_yard
& IY_VERT
) {
1596 vars
[head
].pf
= vars
[head
].fullH
;
1597 vars
[head
].sf
= vars
[head
].fullW
;
1599 vars
[head
].pf
= vars
[head
].fullW
;
1600 vars
[head
].sf
= vars
[head
].fullH
;
1602 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1603 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1606 vars
[head
].xo
= vars
[head
].sx1
;
1609 if (wPreferences
.icon_yard
& IY_TOP
) {
1610 vars
[head
].yo
= vars
[head
].sy1
;
1613 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1618 #define X ((wPreferences.icon_yard & IY_VERT) \
1619 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1620 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1622 #define Y ((wPreferences.icon_yard & IY_VERT) \
1623 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1624 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1626 /* arrange application icons */
1627 aicon
= scr
->app_icon_list
;
1628 /* reverse them to avoid unnecessarily sliding of icons */
1629 while (aicon
&& aicon
->next
)
1630 aicon
= aicon
->next
;
1633 if (!aicon
->docked
) {
1634 /* CHECK: can icon be NULL here ? */
1635 /* The intention here is to place the AppIcon on the head that
1636 * contains most of the applications _main_ window. */
1637 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1639 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1641 if (!wPreferences
.no_animations
) {
1642 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1644 #endif /* ANIMATIONS */
1646 wAppIconMove(aicon
, X
, Y
);
1648 if (vars
[head
].pi
>= vars
[head
].pf
) {
1653 aicon
= aicon
->prev
;
1656 /* arrange miniwindows */
1657 wwin
= scr
->focused_window
;
1658 /* reverse them to avoid unnecessarily shuffling */
1659 while (wwin
&& wwin
->prev
)
1663 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1664 (wwin
->frame
->workspace
== scr
->current_workspace
||
1665 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1667 head
= wGetHeadForWindow(wwin
);
1669 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1670 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1672 if (wPreferences
.no_animations
) {
1673 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1675 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1676 wwin
->icon_y
, X
, Y
);
1679 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1680 #endif /* ANIMATIONS */
1686 if (vars
[head
].pi
>= vars
[head
].pf
) {
1693 wwin
->flags
.icon_moved
= 0;
1695 /* we reversed the order, so we use next */
1702 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1704 WScreen
*scr
= wwin
->screen_ptr
;
1707 wwin
->flags
.selected
= 1;
1708 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1710 if (!HAS_BORDER(wwin
)) {
1711 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1714 if (!scr
->selected_windows
)
1715 scr
->selected_windows
= WMCreateArray(4);
1716 WMAddToArray(scr
->selected_windows
, wwin
);
1718 wwin
->flags
.selected
= 0;
1719 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1721 if (!HAS_BORDER(wwin
)) {
1722 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1725 if (scr
->selected_windows
) {
1726 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1731 void wMakeWindowVisible(WWindow
*wwin
)
1733 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1734 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1736 if (wwin
->flags
.shaded
) {
1737 wUnshadeWindow(wwin
);
1739 if (wwin
->flags
.hidden
) {
1742 app
= wApplicationOf(wwin
->main_window
);
1744 /* trick to get focus to this window */
1745 app
->last_focused
= wwin
;
1746 wUnhideApplication(app
, False
, False
);
1749 if (wwin
->flags
.miniaturized
) {
1750 wDeiconifyWindow(wwin
);
1752 if (!WFLAGP(wwin
, no_focusable
))
1753 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1754 wRaiseFrame(wwin
->frame
->core
);
1759 * Do the animation while shading (called with what = SHADE)
1760 * or unshading (what = UNSHADE).
1763 static void shade_animate(WWindow
*wwin
, Bool what
)
1766 time_t time0
= time(NULL
);
1768 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1773 if (!wwin
->screen_ptr
->flags
.startup
) {
1774 /* do the shading animation */
1775 h
= wwin
->frame
->core
->height
;
1776 s
= h
/ SHADE_STEPS
;
1779 w
= wwin
->frame
->core
->width
;
1780 y
= wwin
->frame
->top_width
;
1781 while (h
> wwin
->frame
->top_width
+ 1) {
1782 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1783 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1786 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1789 if (SHADE_DELAY
> 0) {
1790 wusleep(SHADE_DELAY
* 1000L);
1797 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1802 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1803 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1804 s
= abs(y
) / SHADE_STEPS
;
1807 w
= wwin
->frame
->core
->width
;
1808 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1810 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1811 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1812 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1814 if (SHADE_DELAY
> 0) {
1815 wusleep(SHADE_DELAY
* 2000L / 3);
1822 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1826 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);