1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
41 #include "application.h"
47 #include "winspector.h"
48 #include "workspace.h"
52 /****** Global Variables ******/
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 /******* Local Variables *******/
71 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
72 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
73 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
74 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
75 SHADE_STEPS_US
, SHADE_DELAY_US
}};
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
82 static int compareTimes(Time t1
, Time t2
)
88 return (diff
< 60000) ? 1 : -1;
92 *----------------------------------------------------------------------
94 * Changes the window focus to the one passed as argument.
95 * If the window to focus is not already focused, it will be brought
96 * to the head of the list of windows. Previously focused window is
100 * Window list may be reordered and the window focus is changed.
102 *----------------------------------------------------------------------
104 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
106 static WScreen
*old_scr
= NULL
;
108 WWindow
*old_focused
;
109 WWindow
*focused
= scr
->focused_window
;
110 Time timestamp
= LastTimestamp
;
111 WApplication
*oapp
= NULL
, *napp
= NULL
;
114 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
119 old_focused
= old_scr
->focused_window
;
121 LastFocusChange
= timestamp
;
124 oapp
= wApplicationOf(old_focused
->main_window
);
127 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
129 wWindowUnfocus(old_focused
);
132 wAppMenuUnmap(oapp
->menu
);
134 wApplicationDeactivate(oapp
);
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
);
200 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
);
215 wApplicationActivate(napp
);
223 void wShadeWindow(WWindow
*wwin
)
226 if (wwin
->flags
.shaded
)
229 XLowerWindow(dpy
, wwin
->client_win
);
230 wSoundPlay(WSOUND_SHADE
);
231 shade_animate(wwin
, SHADE
);
233 wwin
->flags
.skip_next_animation
= 0;
234 wwin
->flags
.shaded
= 1;
235 wwin
->flags
.mapped
= 0;
236 /* prevent window withdrawal when getting UnmapNotify */
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
238 XUnmapWindow(dpy
, wwin
->client_win
);
239 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
241 /* for the client it's just like iconification */
242 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
244 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
245 wWindowSynthConfigureNotify(wwin
);
248 wClientSetState(wwin, IconicState, None);
251 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
254 if (!wwin
->screen_ptr
->flags
.startup
) {
255 /* Catch up with events not processed while animation was running */
256 ProcessPendingEvents();
261 void wUnshadeWindow(WWindow
*wwin
)
264 if (!wwin
->flags
.shaded
)
267 wwin
->flags
.shaded
= 0;
268 wwin
->flags
.mapped
= 1;
269 XMapWindow(dpy
, wwin
->client_win
);
271 wSoundPlay(WSOUND_UNSHADE
);
272 shade_animate(wwin
, UNSHADE
);
274 wwin
->flags
.skip_next_animation
= 0;
275 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
276 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
278 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
279 wWindowSynthConfigureNotify(wwin
);
282 wClientSetState(wwin, NormalState, None);
284 /* if the window is focused, set the focus again as it was disabled during
286 if (wwin
->flags
.focused
)
287 wSetFocusTo(wwin
->screen_ptr
, wwin
);
289 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
292 /* Set the old coordinates using the current values */
293 static void save_old_geometry(WWindow
*wwin
)
295 wwin
->old_geometry
.width
= wwin
->client
.width
;
296 wwin
->old_geometry
.height
= wwin
->client
.height
;
297 wwin
->old_geometry
.x
= wwin
->frame_x
;
298 wwin
->old_geometry
.y
= wwin
->frame_y
;
301 void wMaximizeWindow(WWindow
* wwin
, int directions
)
304 unsigned int new_width
, new_height
, half_scr_width
;
305 WArea usableArea
, totalArea
;
309 if (!IS_RESIZABLE(wwin
))
312 if (!HAS_BORDER(wwin
))
315 /* the size to adjust the geometry */
316 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
318 /* save old coordinates before we change the current values */
319 save_old_geometry(wwin
);
323 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
324 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
325 usableArea
= totalArea
;
327 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
328 WScreen
*scr
= wwin
->screen_ptr
;
331 if (directions
& MAX_KEYBOARD
)
332 head
= wGetHeadForWindow(wwin
);
334 head
= wGetHeadForPointerLocation(scr
);
336 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
339 /* Only save directions, not kbd or xinerama hints */
340 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
342 if (WFLAGP(wwin
, full_maximize
)) {
343 usableArea
= totalArea
;
345 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
347 if (wwin
->flags
.shaded
) {
348 wwin
->flags
.skip_next_animation
= 1;
349 wUnshadeWindow(wwin
);
352 if (directions
& MAX_HORIZONTAL
) {
353 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
354 new_x
= usableArea
.x1
;
355 } else if (directions
& MAX_LEFTHALF
) {
356 new_width
= half_scr_width
- adj_size
;
357 new_x
= usableArea
.x1
;
358 } else if (directions
& MAX_RIGHTHALF
) {
359 new_width
= half_scr_width
- adj_size
;
360 new_x
= usableArea
.x1
+ half_scr_width
;
362 new_x
= wwin
->frame_x
;
363 new_width
= wwin
->frame
->core
->width
;
366 if (directions
& MAX_VERTICAL
) {
367 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
368 new_y
= usableArea
.y1
;
369 if (WFLAGP(wwin
, full_maximize
)) {
370 new_y
-= wwin
->frame
->top_width
;
371 new_height
+= wwin
->frame
->bottom_width
- 1;
374 new_y
= wwin
->frame_y
;
375 new_height
= wwin
->frame
->core
->height
;
378 if (!WFLAGP(wwin
, full_maximize
)) {
379 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
382 if (directions
& MAX_MAXIMUS
) {
383 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
384 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
385 new_y
-= wwin
->frame
->top_width
;
386 new_height
+= wwin
->frame
->top_width
- 1;
390 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
392 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
393 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
395 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
397 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
399 wSoundPlay(WSOUND_MAXIMIZE
);
400 /* set maximization state */
401 wwin
->flags
.maximized
= directions
;
405 * Maximus: tiled maximization (maximize without overlapping other windows)
407 * The window to be maximized will be denoted by w_0 (sub-index zero)
408 * while the windows which will stop the maximization of w_0 are denoted by w_j.
410 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
411 unsigned int *new_width
, unsigned int *new_height
)
414 int x_0
= wwin
->frame_x
;
415 int y_0
= wwin
->frame_y
;
416 int width_0
= wwin
->frame
->core
->width
;
417 int height_0
= wwin
->frame
->core
->height
;
418 int botton_0
= y_0
+ height_0
;
419 int right_border_0
= x_0
+ width_0
;
420 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
421 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
422 int x_intsect
, y_intsect
;
423 /* Assume that the window w_0 has titlebar etc */
424 int has_titlebar
= 1, has_resizebar
= 1, has_border
= 1;
425 int adjust_height
, adjust_width
;
427 /* Try to fully maximize first, then readjust later */
428 new_x_0
= usableArea
.x1
;
429 new_y_0
= usableArea
.y1
;
430 new_botton_0
= usableArea
.y2
;
431 new_right_border_0
= usableArea
.x2
;
433 if (!HAS_TITLEBAR(wwin
))
435 if (!HAS_RESIZEBAR(wwin
))
437 if (!HAS_BORDER(wwin
))
440 /* the lengths to be subtracted if w_0 has titlebar, etc */
441 adjust_height
= TITLEBAR_HEIGHT
* has_titlebar
442 + 2 * FRAME_BORDER_WIDTH
* has_border
+ RESIZEBAR_HEIGHT
* has_resizebar
;
443 adjust_width
= 2 * FRAME_BORDER_WIDTH
* has_border
;
446 /* TODO: Is the focused window always the last in the list? */
448 /* ignore windows in other workspaces or minimized */
449 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
450 || tmp
->prev
->flags
.miniaturized
) {
456 /* set the w_j window coordinates */
459 width_j
= tmp
->frame
->core
->width
;
460 height_j
= tmp
->frame
->core
->height
;
461 botton_j
= y_j
+ height_j
;
463 right_border_j
= x_j
+ width_j
;
465 /* Try to maximize in the y direction first */
466 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
467 if (x_intsect
!= 0) {
468 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
469 /* w_0 is below the botton of w_j */
472 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
473 /* The botton of w_0 is above the top of w_j */
474 new_botton_0
= top_j
;
479 * Use the updated y coordinates from the above step to account
480 * the possibility that the new value of y_0 will have different
481 * intersections with w_j
483 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
484 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
485 if (y_intsect
!= 0) {
486 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
487 /* w_0 is completely to the right of w_j */
488 new_x_0
= right_border_j
;
490 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
491 /* w_0 is completely to the left of w_j */
492 new_right_border_0
= x_j
;
497 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
500 *new_height
= new_height_0
;
501 *new_width
= new_right_border_0
- new_x_0
- adjust_width
;
504 void wUnmaximizeWindow(WWindow
* wwin
)
507 WMRect old_geom_rect
;
511 if (!wwin
->flags
.maximized
)
514 if (wwin
->flags
.shaded
) {
515 wwin
->flags
.skip_next_animation
= 1;
516 wUnshadeWindow(wwin
);
518 /* Use old coordinates if they are set, current values otherwise */
519 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
520 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
521 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
522 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
523 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
524 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
525 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
527 wwin
->flags
.maximized
= 0;
528 wWindowConfigure(wwin
, x
, y
, w
, h
);
530 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
532 wSoundPlay(WSOUND_UNMAXIMIZE
);
535 void wFullscreenWindow(WWindow
* wwin
)
540 if (wwin
->flags
.fullscreen
)
543 wwin
->flags
.fullscreen
= True
;
545 wWindowConfigureBorders(wwin
);
547 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
549 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
550 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
551 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
552 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
554 head
= wGetHeadForWindow(wwin
);
555 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
556 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
558 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
561 void wUnfullscreenWindow(WWindow
* wwin
)
563 if (!wwin
->flags
.fullscreen
)
566 wwin
->flags
.fullscreen
= False
;
568 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
569 if (WFLAGP(wwin
, sunken
)) {
570 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
571 } else if (WFLAGP(wwin
, floating
)) {
572 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
574 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
578 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
579 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
581 wWindowConfigureBorders(wwin
);
583 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
584 wFrameWindowPaint(wwin->frame);
587 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
591 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
593 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
594 float cx
, cy
, cw
, ch
;
595 float xstep
, ystep
, wstep
, hstep
;
598 float angle
, final_angle
, delta
;
600 xstep
= (float)(fx
- x
) / steps
;
601 ystep
= (float)(fy
- y
) / steps
;
602 wstep
= (float)(fw
- w
) / steps
;
603 hstep
= (float)(fh
- h
) / steps
;
610 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
611 delta
= (float)(final_angle
/ FRAMES
);
612 for (angle
= 0;; angle
+= delta
) {
613 if (angle
> final_angle
)
616 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
617 dch
= (ch
/ 2) * cos(angle
);
618 midy
= cy
+ (ch
/ 2);
620 points
[0].x
= cx
+ dx
;
621 points
[0].y
= midy
- dch
;
622 points
[1].x
= cx
+ cw
- dx
;
623 points
[1].y
= points
[0].y
;
624 points
[2].x
= cx
+ cw
+ dx
;
625 points
[2].y
= midy
+ dch
;
626 points
[3].x
= cx
- dx
;
627 points
[3].y
= points
[2].y
;
628 points
[4].x
= points
[0].x
;
629 points
[4].y
= points
[0].y
;
632 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
634 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
635 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
640 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
646 if (angle
>= final_angle
)
656 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
658 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
659 float cx
, cy
, cw
, ch
;
660 float xstep
, ystep
, wstep
, hstep
;
662 float angle
, final_angle
, a
, d
, delta
;
669 xstep
= (float)(fx
- x
) / steps
;
670 ystep
= (float)(fy
- y
) / steps
;
671 wstep
= (float)(fw
- w
) / steps
;
672 hstep
= (float)(fh
- h
) / steps
;
679 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
680 delta
= (float)(final_angle
/ FRAMES
);
681 for (angle
= 0;; angle
+= delta
) {
682 if (angle
> final_angle
)
686 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
688 points
[0].x
= cx
+ cos(angle
- a
) * d
;
689 points
[0].y
= cy
+ sin(angle
- a
) * d
;
690 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
691 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
692 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
693 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
694 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
695 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
696 points
[4].x
= cx
+ cos(angle
- a
) * d
;
697 points
[4].y
= cy
+ sin(angle
- a
) * d
;
699 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
701 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
702 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
707 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
713 if (angle
>= final_angle
)
722 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
724 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
725 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
726 float xstep
, ystep
, wstep
, hstep
;
729 xstep
= (float)(fx
- x
) / steps
;
730 ystep
= (float)(fy
- y
) / steps
;
731 wstep
= (float)(fw
- w
) / steps
;
732 hstep
= (float)(fh
- h
) / steps
;
734 for (j
= 0; j
< FRAMES
; j
++) {
741 for (i
= 0; i
< steps
; i
++) {
742 for (j
= 0; j
< FRAMES
; j
++) {
743 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
744 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
747 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
748 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
752 for (j
= 0; j
< FRAMES
; j
++) {
753 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
754 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
755 if (j
< FRAMES
- 1) {
769 for (j
= 0; j
< FRAMES
; j
++) {
770 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
773 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
774 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
778 for (j
= 0; j
< FRAMES
; j
++) {
779 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
787 void animateResize(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int hiding
)
789 int style
= wPreferences
.iconification_style
; /* Catch the value */
792 if (style
== WIS_NONE
)
795 if (style
== WIS_RANDOM
) {
799 k
= (hiding
? 2 : 3);
803 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
) / 3;
805 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
808 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
) / 3;
810 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
814 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
) / 3;
816 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
820 #endif /* ANIMATIONS */
822 static void flushExpose()
826 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
827 WMHandleEvent(&tmpev
);
831 static void unmapTransientsFor(WWindow
* wwin
)
835 tmp
= wwin
->screen_ptr
->focused_window
;
837 /* unmap the transients for this transient */
838 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
839 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
840 unmapTransientsFor(tmp
);
841 tmp
->flags
.miniaturized
= 1;
842 if (!tmp
->flags
.shaded
) {
845 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
848 if (!tmp->flags.shaded)
850 wClientSetState(tmp
, IconicState
, None
);
852 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
858 static void mapTransientsFor(WWindow
* wwin
)
862 tmp
= wwin
->screen_ptr
->focused_window
;
864 /* recursively map the transients for this transient */
865 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
866 && tmp
->icon
== NULL
) {
867 mapTransientsFor(tmp
);
868 tmp
->flags
.miniaturized
= 0;
869 if (!tmp
->flags
.shaded
) {
872 XMapWindow(dpy
, tmp
->frame
->core
->window
);
874 tmp
->flags
.semi_focused
= 0;
876 if (!tmp->flags.shaded)
878 wClientSetState(tmp
, NormalState
, None
);
880 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
887 static void setupIconGrabs(WIcon
* icon
)
889 /* setup passive grabs on the icon */
890 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
891 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
892 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
893 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
894 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
895 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
900 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
907 /* hackish way to detect transient_for cycle */
908 i
= wwin
->screen_ptr
->window_count
+ 1;
910 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
911 wwin
= wWindowFor(wwin
->transient_for
);
914 if (i
== 0 && wwin
) {
915 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
923 static void removeIconGrabs(WIcon
* icon
)
925 /* remove passive grabs on the icon */
926 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
927 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
928 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
933 void wIconifyWindow(WWindow
* wwin
)
935 XWindowAttributes attribs
;
938 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
939 /* the window doesn't exist anymore */
943 if (wwin
->flags
.miniaturized
) {
947 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
948 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
950 if (owner
&& owner
->flags
.miniaturized
)
954 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
956 /* if the window is in another workspace, simplify process */
958 /* icon creation may take a while */
959 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
960 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
961 GrabModeAsync
, None
, None
, CurrentTime
);
964 if (!wPreferences
.disable_miniwindows
966 && !wwin
->flags
.net_handle_icon
969 if (!wwin
->flags
.icon_moved
) {
970 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
972 wwin
->icon
= wIconCreate(wwin
);
974 wwin
->icon
->mapped
= 1;
977 wwin
->flags
.miniaturized
= 1;
978 wwin
->flags
.mapped
= 0;
980 /* unmap transients */
982 unmapTransientsFor(wwin
);
985 wSoundPlay(WSOUND_ICONIFY
);
987 XUngrabPointer(dpy
, CurrentTime
);
989 /* let all Expose events arrive so that we can repaint
990 * something before the animation starts (and the server is grabbed) */
993 if (wPreferences
.disable_miniwindows
995 || wwin
->flags
.net_handle_icon
998 wClientSetState(wwin
, IconicState
, None
);
1000 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1004 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1005 && !wPreferences
.no_animations
) {
1008 if (!wPreferences
.disable_miniwindows
1010 && !wwin
->flags
.net_handle_icon
1015 iw
= wwin
->icon
->core
->width
;
1016 ih
= wwin
->icon
->core
->height
;
1019 if (wwin
->flags
.net_handle_icon
) {
1029 iw
= wwin
->screen_ptr
->scr_width
;
1030 ih
= wwin
->screen_ptr
->scr_height
;
1033 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1034 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
, False
);
1039 wwin
->flags
.skip_next_animation
= 0;
1041 if (!wPreferences
.disable_miniwindows
1043 && !wwin
->flags
.net_handle_icon
1047 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1048 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1050 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1052 AddToStackList(wwin
->icon
->core
);
1054 wLowerFrame(wwin
->icon
->core
);
1058 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1061 * It doesn't seem to be working and causes button event hangup
1062 * when deiconifying a transient window.
1063 setupIconGrabs(wwin->icon);
1065 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1066 && wPreferences
.focus_mode
== WKF_CLICK
) {
1071 if (!WFLAGP(tmp
, no_focusable
)
1072 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1073 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1077 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1078 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1079 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1082 if (!wwin
->screen_ptr
->flags
.startup
) {
1083 /* Catch up with events not processed while animation was running */
1084 Window clientwin
= wwin
->client_win
;
1086 ProcessPendingEvents();
1088 /* the window can disappear while ProcessPendingEvents() runs */
1089 if (!wWindowFor(clientwin
)) {
1096 /* maybe we want to do this regardless of net_handle_icon
1097 * it seems to me we might break behaviour this way.
1099 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1101 && !wwin
->flags
.net_handle_icon
1104 wIconSelect(wwin
->icon
);
1106 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1108 if (wPreferences
.auto_arrange_icons
)
1109 wArrangeIcons(wwin
->screen_ptr
, True
);
1112 void wDeiconifyWindow(WWindow
* wwin
)
1115 /* we're hiding for show_desktop */
1116 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1117 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1119 int netwm_hidden
= False
;
1123 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1125 if (!wwin
->flags
.miniaturized
)
1128 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1129 WWindow
*owner
= recursiveTransientFor(wwin
);
1131 if (owner
&& owner
->flags
.miniaturized
) {
1132 wDeiconifyWindow(owner
);
1133 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1134 wRaiseFrame(wwin
->frame
->core
);
1139 wwin
->flags
.miniaturized
= 0;
1141 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1142 wwin
->flags
.mapped
= 1;
1145 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1146 /* maybe we want to do this regardless of net_handle_icon
1147 * it seems to me we might break behaviour this way.
1149 if (!wPreferences
.disable_miniwindows
1151 && !wwin
->flags
.net_handle_icon
1153 && wwin
->icon
!= NULL
) {
1154 if (wwin
->icon
->selected
)
1155 wIconSelect(wwin
->icon
);
1157 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1162 wSoundPlay(WSOUND_DEICONIFY
);
1164 /* if the window is in another workspace, do it silently */
1165 if (!netwm_hidden
) {
1167 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1168 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1171 if (!wPreferences
.disable_miniwindows
1173 && !wwin
->flags
.net_handle_icon
1178 iw
= wwin
->icon
->core
->width
;
1179 ih
= wwin
->icon
->core
->height
;
1182 if (wwin
->flags
.net_handle_icon
) {
1192 iw
= wwin
->screen_ptr
->scr_width
;
1193 ih
= wwin
->screen_ptr
->scr_height
;
1196 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1197 wwin
->frame_x
, wwin
->frame_y
,
1198 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, False
);
1200 #endif /* ANIMATIONS */
1201 wwin
->flags
.skip_next_animation
= 0;
1203 if (!wwin
->flags
.shaded
) {
1204 XMapWindow(dpy
, wwin
->client_win
);
1206 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1207 wRaiseFrame(wwin
->frame
->core
);
1208 if (!wwin
->flags
.shaded
) {
1209 wClientSetState(wwin
, NormalState
, None
);
1211 mapTransientsFor(wwin
);
1214 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1216 && !wwin
->flags
.net_handle_icon
1219 RemoveFromStackList(wwin
->icon
->core
);
1220 /* removeIconGrabs(wwin->icon); */
1221 wIconDestroy(wwin
->icon
);
1225 if (!netwm_hidden
) {
1228 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1231 if (!wwin
->screen_ptr
->flags
.startup
) {
1232 /* Catch up with events not processed while animation was running */
1233 Window clientwin
= wwin
->client_win
;
1235 ProcessPendingEvents();
1237 /* the window can disappear while ProcessPendingEvents() runs */
1238 if (!wWindowFor(clientwin
)) {
1245 if (wPreferences
.auto_arrange_icons
) {
1246 wArrangeIcons(wwin
->screen_ptr
, True
);
1249 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1251 /* In case we were shaded and iconified, also unshade */
1253 wUnshadeWindow(wwin
);
1256 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1258 if (wwin
->flags
.miniaturized
) {
1260 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1261 wwin
->icon
->mapped
= 0;
1263 wwin
->flags
.hidden
= 1;
1265 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1269 if (wwin
->flags
.inspector_open
) {
1270 wHideInspectorForWindow(wwin
);
1273 wwin
->flags
.hidden
= 1;
1276 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1278 wSoundPlay(WSOUND_HIDE
);
1280 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1281 !wwin
->flags
.skip_next_animation
&& animate
) {
1282 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1283 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1284 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
, True
);
1287 wwin
->flags
.skip_next_animation
= 0;
1289 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1292 void wHideOtherApplications(WWindow
* awin
)
1299 wwin
= awin
->screen_ptr
->focused_window
;
1303 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1304 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1305 && !wwin
->flags
.internal_window
1306 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1308 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1309 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1310 wwin
->flags
.skip_next_animation
= 1;
1311 wIconifyWindow(wwin
);
1313 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1314 tapp
= wApplicationOf(wwin
->main_window
);
1316 tapp
->flags
.skip_next_animation
= 1;
1317 wHideApplication(tapp
);
1319 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1320 wwin
->flags
.skip_next_animation
= 1;
1321 wIconifyWindow(wwin
);
1329 wSetFocusTo(awin->screen_ptr, awin);
1333 void wHideApplication(WApplication
* wapp
)
1341 wwarning("trying to hide a non grouped window");
1344 if (!wapp
->main_window_desc
) {
1345 wwarning("group leader not found for window group");
1348 scr
= wapp
->main_window_desc
->screen_ptr
;
1350 wlist
= scr
->focused_window
;
1354 if (wlist
->main_window
== wapp
->main_window
)
1355 wapp
->last_focused
= wlist
;
1357 wapp
->last_focused
= NULL
;
1359 animate
= !wapp
->flags
.skip_next_animation
;
1362 if (wlist
->main_window
== wapp
->main_window
) {
1363 if (wlist
->flags
.focused
) {
1366 if (wapp
->app_icon
) {
1367 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1368 wapp
->app_icon
->y_pos
, wlist
, animate
);
1372 wlist
= wlist
->prev
;
1375 wapp
->flags
.skip_next_animation
= 0;
1378 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1379 wlist
= scr
->focused_window
;
1381 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1382 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1384 wlist
= wlist
->prev
;
1386 wSetFocusTo(scr
, wlist
);
1388 wSetFocusTo(scr
, NULL
);
1392 wapp
->flags
.hidden
= 1;
1394 if (wPreferences
.auto_arrange_icons
) {
1395 wArrangeIcons(scr
, True
);
1399 wAppIconPaint(wapp
->app_icon
);
1403 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1405 if (bringToCurrentWS
)
1406 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1408 wwin
->flags
.hidden
= 0;
1410 wSoundPlay(WSOUND_UNHIDE
);
1412 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1413 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1414 icon
->core
->width
, icon
->core
->height
,
1415 wwin
->frame_x
, wwin
->frame_y
,
1416 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, True
);
1419 wwin
->flags
.skip_next_animation
= 0;
1420 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1421 XMapWindow(dpy
, wwin
->client_win
);
1422 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1423 wClientSetState(wwin
, NormalState
, None
);
1424 wwin
->flags
.mapped
= 1;
1425 wRaiseFrame(wwin
->frame
->core
);
1427 if (wwin
->flags
.inspector_open
) {
1428 wUnhideInspectorForWindow(wwin
);
1431 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1434 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1437 WWindow
*wlist
, *next
;
1438 WWindow
*focused
= NULL
;
1444 scr
= wapp
->main_window_desc
->screen_ptr
;
1445 wlist
= scr
->focused_window
;
1449 /* goto beginning of list */
1451 wlist
= wlist
->prev
;
1453 animate
= !wapp
->flags
.skip_next_animation
;
1458 if (wlist
->main_window
== wapp
->main_window
) {
1459 if (wlist
->flags
.focused
)
1461 else if (!focused
|| !focused
->flags
.focused
)
1464 if (wlist
->flags
.miniaturized
) {
1465 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1466 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1467 if (!wlist
->icon
->mapped
) {
1470 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1471 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1472 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1476 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1477 wlist
->icon
->mapped
= 1;
1479 wRaiseFrame(wlist
->icon
->core
);
1481 if (bringToCurrentWS
)
1482 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1483 wlist
->flags
.hidden
= 0;
1484 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1485 wDeiconifyWindow(wlist
);
1487 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1488 } else if (wlist
->flags
.shaded
) {
1489 if (bringToCurrentWS
)
1490 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1491 wlist
->flags
.hidden
= 0;
1492 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1493 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1495 wUnshadeWindow(wlist
);
1496 wRaiseFrame(wlist
->frame
->core
);
1499 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1500 } else if (wlist
->flags
.hidden
) {
1501 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1502 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1505 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1506 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1508 wRaiseFrame(wlist
->frame
->core
);
1514 wapp
->flags
.skip_next_animation
= 0;
1515 wapp
->flags
.hidden
= 0;
1517 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1518 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1519 wSetFocusTo(scr
, wapp
->last_focused
);
1520 } else if (focused
) {
1521 wSetFocusTo(scr
, focused
);
1523 wapp
->last_focused
= NULL
;
1524 if (wPreferences
.auto_arrange_icons
) {
1525 wArrangeIcons(scr
, True
);
1528 wAppIconPaint(wapp
->app_icon
);
1532 void wShowAllWindows(WScreen
* scr
)
1534 WWindow
*wwin
, *old_foc
;
1537 old_foc
= wwin
= scr
->focused_window
;
1539 if (!wwin
->flags
.internal_window
&&
1540 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1541 if (wwin
->flags
.miniaturized
) {
1542 wwin
->flags
.skip_next_animation
= 1;
1543 wDeiconifyWindow(wwin
);
1544 } else if (wwin
->flags
.hidden
) {
1545 wapp
= wApplicationOf(wwin
->main_window
);
1547 wUnhideApplication(wapp
, False
, False
);
1549 wwin
->flags
.skip_next_animation
= 1;
1550 wDeiconifyWindow(wwin
);
1556 wSetFocusTo(scr
, old_foc
);
1557 /*wRaiseFrame(old_foc->frame->core); */
1560 void wRefreshDesktop(WScreen
* scr
)
1563 XSetWindowAttributes attr
;
1565 attr
.backing_store
= NotUseful
;
1566 attr
.save_under
= False
;
1567 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1568 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1569 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1570 XMapRaised(dpy
, win
);
1571 XDestroyWindow(dpy
, win
);
1575 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1581 const int heads
= wXineramaHeads(scr
);
1584 int pf
; /* primary axis */
1585 int sf
; /* secondary axis */
1589 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1595 int isize
= wPreferences
.icon_size
;
1597 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1599 for (head
= 0; head
< heads
; ++head
) {
1601 WMRect rect
= wGetRectForHead(scr
, head
);
1603 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1604 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1607 vars
[head
].pi
= vars
[head
].si
= 0;
1608 vars
[head
].sx1
= rect
.pos
.x
;
1609 vars
[head
].sy1
= rect
.pos
.y
;
1610 vars
[head
].sw
= rect
.size
.width
;
1611 vars
[head
].sh
= rect
.size
.height
;
1612 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1613 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1617 if (scr
->dock
->on_right_side
)
1618 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1620 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1624 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1625 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1626 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1627 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1629 /* icon yard boundaries */
1630 if (wPreferences
.icon_yard
& IY_VERT
) {
1631 vars
[head
].pf
= vars
[head
].fullH
;
1632 vars
[head
].sf
= vars
[head
].fullW
;
1634 vars
[head
].pf
= vars
[head
].fullW
;
1635 vars
[head
].sf
= vars
[head
].fullH
;
1637 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1638 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1641 vars
[head
].xo
= vars
[head
].sx1
;
1644 if (wPreferences
.icon_yard
& IY_TOP
) {
1645 vars
[head
].yo
= vars
[head
].sy1
;
1648 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1653 #define X ((wPreferences.icon_yard & IY_VERT) \
1654 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1655 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1657 #define Y ((wPreferences.icon_yard & IY_VERT) \
1658 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1659 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1661 /* arrange application icons */
1662 aicon
= scr
->app_icon_list
;
1663 /* reverse them to avoid unnecessarily sliding of icons */
1664 while (aicon
&& aicon
->next
)
1665 aicon
= aicon
->next
;
1668 if (!aicon
->docked
) {
1669 /* CHECK: can icon be NULL here ? */
1670 /* The intention here is to place the AppIcon on the head that
1671 * contains most of the applications _main_ window. */
1672 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1674 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1676 if (!wPreferences
.no_animations
) {
1677 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1679 #endif /* ANIMATIONS */
1681 wAppIconMove(aicon
, X
, Y
);
1683 if (vars
[head
].pi
>= vars
[head
].pf
) {
1688 aicon
= aicon
->prev
;
1691 /* arrange miniwindows */
1692 wwin
= scr
->focused_window
;
1693 /* reverse them to avoid unnecessarily shuffling */
1694 while (wwin
&& wwin
->prev
)
1698 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1699 (wwin
->frame
->workspace
== scr
->current_workspace
||
1700 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1702 head
= wGetHeadForWindow(wwin
);
1704 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1705 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1707 if (wPreferences
.no_animations
) {
1708 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1710 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1711 wwin
->icon_y
, X
, Y
);
1714 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1715 #endif /* ANIMATIONS */
1721 if (vars
[head
].pi
>= vars
[head
].pf
) {
1728 wwin
->flags
.icon_moved
= 0;
1730 /* we reversed the order, so we use next */
1738 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1742 int pf
; /* primary axis */
1743 int sf
; /* secondary axis */
1747 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1751 int isize
= wPreferences
.icon_size
;
1754 * Find out screen boundaries.
1758 * Allows each head to have miniwindows
1760 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1764 sw
= rect
.size
.width
;
1765 sh
= rect
.size
.height
;
1769 if (scr
->dock
->on_right_side
)
1770 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1772 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1775 sw
= isize
* (scr
->scr_width
/ isize
);
1776 sh
= isize
* (scr
->scr_height
/ isize
);
1778 sw
= isize
* (sw
/ isize
);
1779 sh
= isize
* (sh
/ isize
);
1781 fullW
= (sx2
- sx1
) / isize
;
1782 fullH
= (sy2
- sy1
) / isize
;
1784 /* icon yard boundaries */
1785 if (wPreferences
.icon_yard
& IY_VERT
) {
1792 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1799 if (wPreferences
.icon_yard
& IY_TOP
) {
1807 /* arrange icons putting the most recently focused window
1808 * as the last icon */
1809 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1810 : xo + xs*(pi*isize))
1811 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1812 : yo + ys*(si*isize))
1814 /* arrange application icons */
1815 aicon
= scr
->app_icon_list
;
1816 /* reverse them to avoid unnecessarily sliding of icons */
1817 while (aicon
&& aicon
->next
)
1818 aicon
= aicon
->next
;
1823 if (!aicon
->docked
) {
1824 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1826 if (!wPreferences
.no_animations
) {
1827 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1829 #endif /* ANIMATIONS */
1831 wAppIconMove(aicon
, X
, Y
);
1834 /* we reversed the order so we use prev */
1835 aicon
= aicon
->prev
;
1842 /* arrange miniwindows */
1844 wwin
= scr
->focused_window
;
1845 /* reverse them to avoid unnecessarily shuffling */
1846 while (wwin
&& wwin
->prev
)
1850 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1851 (wwin
->frame
->workspace
== scr
->current_workspace
||
1852 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1854 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1855 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1857 if (wPreferences
.no_animations
) {
1858 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1860 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1861 wwin
->icon_y
, X
, Y
);
1864 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1865 #endif /* ANIMATIONS */
1873 wwin
->flags
.icon_moved
= 0;
1875 /* we reversed the order, so we use next */
1885 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1887 WScreen
*scr
= wwin
->screen_ptr
;
1890 wwin
->flags
.selected
= 1;
1891 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1893 if (!HAS_BORDER(wwin
)) {
1894 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1897 if (!scr
->selected_windows
)
1898 scr
->selected_windows
= WMCreateArray(4);
1899 WMAddToArray(scr
->selected_windows
, wwin
);
1901 wwin
->flags
.selected
= 0;
1902 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1904 if (!HAS_BORDER(wwin
)) {
1905 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1908 if (scr
->selected_windows
) {
1909 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1914 void wMakeWindowVisible(WWindow
* wwin
)
1916 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1917 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1919 if (wwin
->flags
.shaded
) {
1920 wUnshadeWindow(wwin
);
1922 if (wwin
->flags
.hidden
) {
1925 app
= wApplicationOf(wwin
->main_window
);
1927 /* trick to get focus to this window */
1928 app
->last_focused
= wwin
;
1929 wUnhideApplication(app
, False
, False
);
1932 if (wwin
->flags
.miniaturized
) {
1933 wDeiconifyWindow(wwin
);
1935 if (!WFLAGP(wwin
, no_focusable
))
1936 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1937 wRaiseFrame(wwin
->frame
->core
);
1942 * Do the animation while shading (called with what = SHADE)
1943 * or unshading (what = UNSHADE).
1946 static void shade_animate(WWindow
*wwin
, Bool what
)
1949 time_t time0
= time(NULL
);
1951 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1956 if (!wwin
->screen_ptr
->flags
.startup
) {
1957 /* do the shading animation */
1958 h
= wwin
->frame
->core
->height
;
1959 s
= h
/ SHADE_STEPS
;
1962 w
= wwin
->frame
->core
->width
;
1963 y
= wwin
->frame
->top_width
;
1964 while (h
> wwin
->frame
->top_width
+ 1) {
1965 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1966 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1969 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1972 if (SHADE_DELAY
> 0) {
1973 wusleep(SHADE_DELAY
* 1000L);
1980 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1985 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1986 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1987 s
= abs(y
) / SHADE_STEPS
;
1990 w
= wwin
->frame
->core
->width
;
1991 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1993 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1994 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1995 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1997 if (SHADE_DELAY
> 0) {
1998 wusleep(SHADE_DELAY
* 2000L / 3);
2005 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2009 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2014 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
2015 #endif /* ANIMATIONS */