1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
41 #include "application.h"
47 #include "winspector.h"
48 #include "workspace.h"
51 /****** Global Variables ******/
52 extern Time LastTimestamp
;
53 extern Time LastFocusChange
;
55 extern Cursor wCursor
[WCUR_LAST
];
57 extern WPreferences wPreferences
;
59 extern Atom _XA_WM_TAKE_FOCUS
;
61 extern void ProcessPendingEvents();
62 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
64 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
65 unsigned int *new_width
, unsigned int *new_height
);
66 static void save_old_geometry(WWindow
*wwin
);
68 /******* Local Variables *******/
74 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
75 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
76 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
77 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
78 SHADE_STEPS_US
, SHADE_DELAY_US
}};
82 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
83 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
85 static int compareTimes(Time t1
, Time t2
)
91 return (diff
< 60000) ? 1 : -1;
95 *----------------------------------------------------------------------
97 * Changes the window focus to the one passed as argument.
98 * If the window to focus is not already focused, it will be brought
99 * to the head of the list of windows. Previously focused window is
103 * Window list may be reordered and the window focus is changed.
105 *----------------------------------------------------------------------
107 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
109 static WScreen
*old_scr
= NULL
;
111 WWindow
*old_focused
;
112 WWindow
*focused
= scr
->focused_window
;
113 Time timestamp
= LastTimestamp
;
114 WApplication
*oapp
= NULL
, *napp
= NULL
;
117 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
122 old_focused
= old_scr
->focused_window
;
124 LastFocusChange
= timestamp
;
127 oapp
= wApplicationOf(old_focused
->main_window
);
130 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
132 wWindowUnfocus(old_focused
);
135 wAppMenuUnmap(oapp
->menu
);
137 wApplicationDeactivate(oapp
);
141 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
143 } else if (old_scr
!= scr
&& old_focused
) {
144 wWindowUnfocus(old_focused
);
147 wasfocused
= wwin
->flags
.focused
;
148 napp
= wApplicationOf(wwin
->main_window
);
150 /* remember last workspace where the app has been */
152 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
153 napp
->last_workspace
= wwin
->frame
->workspace
;
156 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
157 /* install colormap if colormap mode is lock mode */
158 if (wPreferences
.colormap_mode
== WCM_CLICK
)
159 wColormapInstallForWindow(scr
, wwin
);
161 /* set input focus */
162 switch (wwin
->focus_mode
) {
164 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
168 case WFM_LOCALLY_ACTIVE
:
169 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
172 case WFM_GLOBALLY_ACTIVE
:
176 if (wwin
->protocols
.TAKE_FOCUS
) {
177 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
181 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
183 if (WFLAGP(wwin
, no_focusable
))
186 /* if this is not the focused window focus it */
187 if (focused
!= wwin
) {
188 /* change the focus window list order */
190 wwin
->prev
->next
= wwin
->next
;
193 wwin
->next
->prev
= wwin
->prev
;
195 wwin
->prev
= focused
;
196 focused
->next
= wwin
;
198 scr
->focused_window
= wwin
;
200 if (oapp
&& oapp
!= napp
) {
201 wAppMenuUnmap(oapp
->menu
);
203 wApplicationDeactivate(oapp
);
208 wWindowFocus(wwin
, focused
);
210 if (napp
&& !wasfocused
) {
212 wUserMenuRefreshInstances(napp
->menu
, wwin
);
213 #endif /* USER_MENU */
215 if (wwin
->flags
.mapped
)
216 wAppMenuMap(napp
->menu
, wwin
);
218 wApplicationActivate(napp
);
226 void wShadeWindow(WWindow
*wwin
)
229 if (wwin
->flags
.shaded
)
232 XLowerWindow(dpy
, wwin
->client_win
);
233 shade_animate(wwin
, SHADE
);
235 wwin
->flags
.skip_next_animation
= 0;
236 wwin
->flags
.shaded
= 1;
237 wwin
->flags
.mapped
= 0;
238 /* prevent window withdrawal when getting UnmapNotify */
239 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
240 XUnmapWindow(dpy
, wwin
->client_win
);
241 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
243 /* for the client it's just like iconification */
244 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
246 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
247 wWindowSynthConfigureNotify(wwin
);
250 wClientSetState(wwin, IconicState, None);
253 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
256 if (!wwin
->screen_ptr
->flags
.startup
) {
257 /* Catch up with events not processed while animation was running */
258 ProcessPendingEvents();
263 void wUnshadeWindow(WWindow
*wwin
)
266 if (!wwin
->flags
.shaded
)
269 wwin
->flags
.shaded
= 0;
270 wwin
->flags
.mapped
= 1;
271 XMapWindow(dpy
, wwin
->client_win
);
273 shade_animate(wwin
, UNSHADE
);
275 wwin
->flags
.skip_next_animation
= 0;
276 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
277 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
279 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
280 wWindowSynthConfigureNotify(wwin
);
283 wClientSetState(wwin, NormalState, None);
285 /* if the window is focused, set the focus again as it was disabled during
287 if (wwin
->flags
.focused
)
288 wSetFocusTo(wwin
->screen_ptr
, wwin
);
290 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
293 /* Set the old coordinates using the current values */
294 static void save_old_geometry(WWindow
*wwin
)
296 wwin
->old_geometry
.width
= wwin
->client
.width
;
297 wwin
->old_geometry
.height
= wwin
->client
.height
;
298 wwin
->old_geometry
.x
= wwin
->frame_x
;
299 wwin
->old_geometry
.y
= wwin
->frame_y
;
302 void wMaximizeWindow(WWindow
* wwin
, int directions
)
305 unsigned int new_width
, new_height
, half_scr_width
;
306 WArea usableArea
, totalArea
;
310 if (!IS_RESIZABLE(wwin
))
313 if (!HAS_BORDER(wwin
))
316 /* the size to adjust the geometry */
317 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
319 /* save old coordinates before we change the current values */
320 save_old_geometry(wwin
);
324 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
325 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
326 usableArea
= totalArea
;
328 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
329 WScreen
*scr
= wwin
->screen_ptr
;
332 if (directions
& MAX_KEYBOARD
)
333 head
= wGetHeadForWindow(wwin
);
335 head
= wGetHeadForPointerLocation(scr
);
337 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
340 /* Only save directions, not kbd or xinerama hints */
341 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
343 if (WFLAGP(wwin
, full_maximize
)) {
344 usableArea
= totalArea
;
346 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
348 if (wwin
->flags
.shaded
) {
349 wwin
->flags
.skip_next_animation
= 1;
350 wUnshadeWindow(wwin
);
353 if (directions
& MAX_HORIZONTAL
) {
354 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
355 new_x
= usableArea
.x1
;
356 } else if (directions
& MAX_LEFTHALF
) {
357 new_width
= half_scr_width
- adj_size
;
358 new_x
= usableArea
.x1
;
359 } else if (directions
& MAX_RIGHTHALF
) {
360 new_width
= half_scr_width
- adj_size
;
361 new_x
= usableArea
.x1
+ half_scr_width
;
363 new_x
= wwin
->frame_x
;
364 new_width
= wwin
->frame
->core
->width
;
367 if (directions
& MAX_VERTICAL
) {
368 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
369 new_y
= usableArea
.y1
;
370 if (WFLAGP(wwin
, full_maximize
)) {
371 new_y
-= wwin
->frame
->top_width
;
372 new_height
+= wwin
->frame
->bottom_width
- 1;
375 new_y
= wwin
->frame_y
;
376 new_height
= wwin
->frame
->core
->height
;
379 if (!WFLAGP(wwin
, full_maximize
)) {
380 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
383 if (directions
& MAX_MAXIMUS
) {
384 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
385 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
386 new_y
-= wwin
->frame
->top_width
;
387 new_height
+= wwin
->frame
->top_width
- 1;
391 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
393 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
394 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
396 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
398 WMPostNotificationName(WMNChangedState
, wwin
, "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 short int tbar_height_0
= 0, rbar_height_0
= 0;
424 short int bd_width_0
= 0, bd_width_j
= 0;
425 short int adjust_height
;
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
))
434 tbar_height_0
= TITLEBAR_HEIGHT
;
435 if (HAS_RESIZEBAR(wwin
))
436 rbar_height_0
= RESIZEBAR_HEIGHT
;
437 if (HAS_BORDER(wwin
))
438 bd_width_0
= FRAME_BORDER_WIDTH
;
440 /* the lengths to be subtracted if w_0 has titlebar, etc */
441 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
444 /* The focused window is always the last in the list */
446 /* ignore windows in other workspaces etc */
447 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
448 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
455 bd_width_j
= FRAME_BORDER_WIDTH
;
460 * Set the w_j window coordinates. It is convenient
461 * to not use "corrected" sizes for width and height,
462 * otherwise bottom_j and right_border_j would be
465 x_j
= tmp
->frame_x
- bd_width_j
;
466 y_j
= tmp
->frame_y
- bd_width_j
;
467 width_j
= tmp
->frame
->core
->width
;
468 height_j
= tmp
->frame
->core
->height
;
469 botton_j
= y_j
+ height_j
+ bd_width_j
;
470 top_j
= y_j
- bd_width_j
;
471 right_border_j
= x_j
+ width_j
+ bd_width_j
;
473 /* Try to maximize in the y direction first */
474 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
475 if (x_intsect
!= 0) {
476 /* TODO: Consider the case when coords are equal */
477 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
478 /* w_0 is below the botton of w_j */
481 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
482 /* The botton of w_0 is above the top of w_j */
483 new_botton_0
= top_j
;
490 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
491 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
498 bd_width_j
= FRAME_BORDER_WIDTH
;
502 /* set the w_j window coordinates */
503 x_j
= tmp
->frame_x
- bd_width_j
;
504 y_j
= tmp
->frame_y
- bd_width_j
;
505 width_j
= tmp
->frame
->core
->width
;
506 height_j
= tmp
->frame
->core
->height
;
507 botton_j
= y_j
+ height_j
+ bd_width_j
;
508 top_j
= y_j
- bd_width_j
;
509 right_border_j
= x_j
+ width_j
+ bd_width_j
;
512 * Use the updated y coordinates from the above step to account
513 * the possibility that the new value of y_0 will have different
514 * intersections with w_j
516 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
517 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
518 if (y_intsect
!= 0) {
519 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
520 /* w_0 is completely to the right of w_j */
521 new_x_0
= right_border_j
+ 1;
523 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
524 /* w_0 is completely to the left of w_j */
525 new_right_border_0
= x_j
- 1;
530 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
533 *new_height
= new_height_0
;
534 *new_width
= new_right_border_0
- new_x_0
;
537 void wUnmaximizeWindow(WWindow
* wwin
)
540 WMRect old_geom_rect
;
544 if (!wwin
->flags
.maximized
)
547 if (wwin
->flags
.shaded
) {
548 wwin
->flags
.skip_next_animation
= 1;
549 wUnshadeWindow(wwin
);
551 /* Use old coordinates if they are set, current values otherwise */
552 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
553 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
554 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
555 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
556 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
557 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
558 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
560 wwin
->flags
.maximized
= 0;
561 wWindowConfigure(wwin
, x
, y
, w
, h
);
563 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
566 void wFullscreenWindow(WWindow
* wwin
)
571 if (wwin
->flags
.fullscreen
)
574 wwin
->flags
.fullscreen
= True
;
576 wWindowConfigureBorders(wwin
);
578 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
580 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
581 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
582 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
583 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
585 head
= wGetHeadForWindow(wwin
);
586 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
587 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
589 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
592 void wUnfullscreenWindow(WWindow
* wwin
)
594 if (!wwin
->flags
.fullscreen
)
597 wwin
->flags
.fullscreen
= False
;
599 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
600 if (WFLAGP(wwin
, sunken
)) {
601 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
602 } else if (WFLAGP(wwin
, floating
)) {
603 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
605 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
609 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
610 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
612 wWindowConfigureBorders(wwin
);
614 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
615 wFrameWindowPaint(wwin->frame);
618 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
622 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
624 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
625 float cx
, cy
, cw
, ch
;
626 float xstep
, ystep
, wstep
, hstep
;
629 float angle
, final_angle
, delta
;
631 xstep
= (float)(fx
- x
) / steps
;
632 ystep
= (float)(fy
- y
) / steps
;
633 wstep
= (float)(fw
- w
) / steps
;
634 hstep
= (float)(fh
- h
) / steps
;
641 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
642 delta
= (float)(final_angle
/ FRAMES
);
643 for (angle
= 0;; angle
+= delta
) {
644 if (angle
> final_angle
)
647 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
648 dch
= (ch
/ 2) * cos(angle
);
649 midy
= cy
+ (ch
/ 2);
651 points
[0].x
= cx
+ dx
;
652 points
[0].y
= midy
- dch
;
653 points
[1].x
= cx
+ cw
- dx
;
654 points
[1].y
= points
[0].y
;
655 points
[2].x
= cx
+ cw
+ dx
;
656 points
[2].y
= midy
+ dch
;
657 points
[3].x
= cx
- dx
;
658 points
[3].y
= points
[2].y
;
659 points
[4].x
= points
[0].x
;
660 points
[4].y
= points
[0].y
;
663 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
665 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
667 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
673 if (angle
>= final_angle
)
683 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
685 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
686 float cx
, cy
, cw
, ch
;
687 float xstep
, ystep
, wstep
, hstep
;
689 float angle
, final_angle
, a
, d
, delta
;
696 xstep
= (float)(fx
- x
) / steps
;
697 ystep
= (float)(fy
- y
) / steps
;
698 wstep
= (float)(fw
- w
) / steps
;
699 hstep
= (float)(fh
- h
) / steps
;
706 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
707 delta
= (float)(final_angle
/ FRAMES
);
708 for (angle
= 0;; angle
+= delta
) {
709 if (angle
> final_angle
)
713 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
715 points
[0].x
= cx
+ cos(angle
- a
) * d
;
716 points
[0].y
= cy
+ sin(angle
- a
) * d
;
717 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
718 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
719 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
720 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
721 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
722 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
723 points
[4].x
= cx
+ cos(angle
- a
) * d
;
724 points
[4].y
= cy
+ sin(angle
- a
) * d
;
726 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
728 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
730 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
736 if (angle
>= final_angle
)
745 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
747 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
748 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
749 float xstep
, ystep
, wstep
, hstep
;
752 xstep
= (float)(fx
- x
) / steps
;
753 ystep
= (float)(fy
- y
) / steps
;
754 wstep
= (float)(fw
- w
) / steps
;
755 hstep
= (float)(fh
- h
) / steps
;
757 for (j
= 0; j
< FRAMES
; j
++) {
764 for (i
= 0; i
< steps
; i
++) {
765 for (j
= 0; j
< FRAMES
; j
++) {
766 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
767 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
770 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
772 for (j
= 0; j
< FRAMES
; j
++) {
773 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
774 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
775 if (j
< FRAMES
- 1) {
789 for (j
= 0; j
< FRAMES
; j
++) {
790 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
793 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
795 for (j
= 0; j
< FRAMES
; j
++) {
796 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
804 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
806 int style
= wPreferences
.iconification_style
; /* Catch the value */
809 if (style
== WIS_NONE
)
812 if (style
== WIS_RANDOM
) {
818 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
820 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
823 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
825 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
829 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
831 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
835 #endif /* ANIMATIONS */
837 static void flushExpose()
841 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
842 WMHandleEvent(&tmpev
);
846 static void unmapTransientsFor(WWindow
* wwin
)
850 tmp
= wwin
->screen_ptr
->focused_window
;
852 /* unmap the transients for this transient */
853 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
854 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
855 unmapTransientsFor(tmp
);
856 tmp
->flags
.miniaturized
= 1;
857 if (!tmp
->flags
.shaded
) {
860 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
863 if (!tmp->flags.shaded)
865 wClientSetState(tmp
, IconicState
, None
);
867 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
873 static void mapTransientsFor(WWindow
* wwin
)
877 tmp
= wwin
->screen_ptr
->focused_window
;
879 /* recursively map the transients for this transient */
880 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
881 && tmp
->icon
== NULL
) {
882 mapTransientsFor(tmp
);
883 tmp
->flags
.miniaturized
= 0;
884 if (!tmp
->flags
.shaded
) {
887 XMapWindow(dpy
, tmp
->frame
->core
->window
);
889 tmp
->flags
.semi_focused
= 0;
891 if (!tmp->flags.shaded)
893 wClientSetState(tmp
, NormalState
, None
);
895 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
902 static void setupIconGrabs(WIcon
* icon
)
904 /* setup passive grabs on the icon */
905 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
906 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
907 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
908 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
909 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
910 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
915 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
922 /* hackish way to detect transient_for cycle */
923 i
= wwin
->screen_ptr
->window_count
+ 1;
925 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
926 wwin
= wWindowFor(wwin
->transient_for
);
929 if (i
== 0 && wwin
) {
930 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
938 static void removeIconGrabs(WIcon
* icon
)
940 /* remove passive grabs on the icon */
941 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
942 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
943 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
948 void wIconifyWindow(WWindow
* wwin
)
950 XWindowAttributes attribs
;
953 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
954 /* the window doesn't exist anymore */
958 if (wwin
->flags
.miniaturized
) {
962 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
963 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
965 if (owner
&& owner
->flags
.miniaturized
)
969 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
971 /* if the window is in another workspace, simplify process */
973 /* icon creation may take a while */
974 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
975 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
976 GrabModeAsync
, None
, None
, CurrentTime
);
979 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
980 if (!wwin
->flags
.icon_moved
) {
981 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
983 wwin
->icon
= wIconCreate(wwin
);
985 wwin
->icon
->mapped
= 1;
988 wwin
->flags
.miniaturized
= 1;
989 wwin
->flags
.mapped
= 0;
991 /* unmap transients */
993 unmapTransientsFor(wwin
);
996 XUngrabPointer(dpy
, CurrentTime
);
998 /* let all Expose events arrive so that we can repaint
999 * something before the animation starts (and the server is grabbed) */
1002 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1003 wClientSetState(wwin
, IconicState
, None
);
1005 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1009 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1010 && !wPreferences
.no_animations
) {
1013 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1016 iw
= wwin
->icon
->core
->width
;
1017 ih
= wwin
->icon
->core
->height
;
1019 if (wwin
->flags
.net_handle_icon
) {
1027 iw
= wwin
->screen_ptr
->scr_width
;
1028 ih
= wwin
->screen_ptr
->scr_height
;
1031 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1032 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1037 wwin
->flags
.skip_next_animation
= 0;
1039 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1040 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1041 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1043 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1045 AddToStackList(wwin
->icon
->core
);
1047 wLowerFrame(wwin
->icon
->core
);
1051 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1054 * It doesn't seem to be working and causes button event hangup
1055 * when deiconifying a transient window.
1056 setupIconGrabs(wwin->icon);
1058 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1059 && wPreferences
.focus_mode
== WKF_CLICK
) {
1064 if (!WFLAGP(tmp
, no_focusable
)
1065 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1066 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1070 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1071 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1072 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1075 if (!wwin
->screen_ptr
->flags
.startup
) {
1076 /* Catch up with events not processed while animation was running */
1077 Window clientwin
= wwin
->client_win
;
1079 ProcessPendingEvents();
1081 /* the window can disappear while ProcessPendingEvents() runs */
1082 if (!wWindowFor(clientwin
)) {
1089 /* maybe we want to do this regardless of net_handle_icon
1090 * it seems to me we might break behaviour this way.
1092 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1093 && !wwin
->flags
.net_handle_icon
)
1094 wIconSelect(wwin
->icon
);
1096 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1098 if (wPreferences
.auto_arrange_icons
)
1099 wArrangeIcons(wwin
->screen_ptr
, True
);
1102 void wDeiconifyWindow(WWindow
* wwin
)
1104 /* we're hiding for show_desktop */
1105 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1106 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1109 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1111 if (!wwin
->flags
.miniaturized
)
1114 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1115 WWindow
*owner
= recursiveTransientFor(wwin
);
1117 if (owner
&& owner
->flags
.miniaturized
) {
1118 wDeiconifyWindow(owner
);
1119 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1120 wRaiseFrame(wwin
->frame
->core
);
1125 wwin
->flags
.miniaturized
= 0;
1127 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1128 wwin
->flags
.mapped
= 1;
1131 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1132 /* maybe we want to do this regardless of net_handle_icon
1133 * it seems to me we might break behaviour this way.
1135 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1136 && wwin
->icon
!= NULL
) {
1137 if (wwin
->icon
->selected
)
1138 wIconSelect(wwin
->icon
);
1140 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1144 /* if the window is in another workspace, do it silently */
1145 if (!netwm_hidden
) {
1147 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1148 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1151 if (!wPreferences
.disable_miniwindows
1152 && !wwin
->flags
.net_handle_icon
) {
1155 iw
= wwin
->icon
->core
->width
;
1156 ih
= wwin
->icon
->core
->height
;
1158 if (wwin
->flags
.net_handle_icon
) {
1166 iw
= wwin
->screen_ptr
->scr_width
;
1167 ih
= wwin
->screen_ptr
->scr_height
;
1170 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1171 wwin
->frame_x
, wwin
->frame_y
,
1172 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1174 #endif /* ANIMATIONS */
1175 wwin
->flags
.skip_next_animation
= 0;
1177 if (!wwin
->flags
.shaded
) {
1178 XMapWindow(dpy
, wwin
->client_win
);
1180 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1181 wRaiseFrame(wwin
->frame
->core
);
1182 if (!wwin
->flags
.shaded
) {
1183 wClientSetState(wwin
, NormalState
, None
);
1185 mapTransientsFor(wwin
);
1188 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1189 && !wwin
->flags
.net_handle_icon
) {
1190 RemoveFromStackList(wwin
->icon
->core
);
1191 /* removeIconGrabs(wwin->icon); */
1192 wIconDestroy(wwin
->icon
);
1196 if (!netwm_hidden
) {
1199 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1202 if (!wwin
->screen_ptr
->flags
.startup
) {
1203 /* Catch up with events not processed while animation was running */
1204 Window clientwin
= wwin
->client_win
;
1206 ProcessPendingEvents();
1208 /* the window can disappear while ProcessPendingEvents() runs */
1209 if (!wWindowFor(clientwin
)) {
1216 if (wPreferences
.auto_arrange_icons
) {
1217 wArrangeIcons(wwin
->screen_ptr
, True
);
1220 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1222 /* In case we were shaded and iconified, also unshade */
1224 wUnshadeWindow(wwin
);
1227 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1229 if (wwin
->flags
.miniaturized
) {
1231 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1232 wwin
->icon
->mapped
= 0;
1234 wwin
->flags
.hidden
= 1;
1236 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1240 if (wwin
->flags
.inspector_open
) {
1241 wHideInspectorForWindow(wwin
);
1244 wwin
->flags
.hidden
= 1;
1247 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1251 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1252 !wwin
->flags
.skip_next_animation
&& animate
) {
1253 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1254 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1255 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1258 wwin
->flags
.skip_next_animation
= 0;
1260 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1263 void wHideOtherApplications(WWindow
* awin
)
1270 wwin
= awin
->screen_ptr
->focused_window
;
1274 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1275 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1276 && !wwin
->flags
.internal_window
1277 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1279 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1280 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1281 wwin
->flags
.skip_next_animation
= 1;
1282 wIconifyWindow(wwin
);
1284 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1285 tapp
= wApplicationOf(wwin
->main_window
);
1287 tapp
->flags
.skip_next_animation
= 1;
1288 wHideApplication(tapp
);
1290 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1291 wwin
->flags
.skip_next_animation
= 1;
1292 wIconifyWindow(wwin
);
1300 wSetFocusTo(awin->screen_ptr, awin);
1304 void wHideApplication(WApplication
* wapp
)
1312 wwarning("trying to hide a non grouped window");
1315 if (!wapp
->main_window_desc
) {
1316 wwarning("group leader not found for window group");
1319 scr
= wapp
->main_window_desc
->screen_ptr
;
1321 wlist
= scr
->focused_window
;
1325 if (wlist
->main_window
== wapp
->main_window
)
1326 wapp
->last_focused
= wlist
;
1328 wapp
->last_focused
= NULL
;
1330 animate
= !wapp
->flags
.skip_next_animation
;
1333 if (wlist
->main_window
== wapp
->main_window
) {
1334 if (wlist
->flags
.focused
) {
1337 if (wapp
->app_icon
) {
1338 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1339 wapp
->app_icon
->y_pos
, wlist
, animate
);
1343 wlist
= wlist
->prev
;
1346 wapp
->flags
.skip_next_animation
= 0;
1349 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1350 wlist
= scr
->focused_window
;
1352 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1353 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1355 wlist
= wlist
->prev
;
1357 wSetFocusTo(scr
, wlist
);
1359 wSetFocusTo(scr
, NULL
);
1363 wapp
->flags
.hidden
= 1;
1365 if (wPreferences
.auto_arrange_icons
) {
1366 wArrangeIcons(scr
, True
);
1370 wAppIconPaint(wapp
->app_icon
);
1374 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1376 if (bringToCurrentWS
)
1377 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1379 wwin
->flags
.hidden
= 0;
1382 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1383 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1384 icon
->core
->width
, icon
->core
->height
,
1385 wwin
->frame_x
, wwin
->frame_y
,
1386 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1389 wwin
->flags
.skip_next_animation
= 0;
1390 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1391 XMapWindow(dpy
, wwin
->client_win
);
1392 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1393 wClientSetState(wwin
, NormalState
, None
);
1394 wwin
->flags
.mapped
= 1;
1395 wRaiseFrame(wwin
->frame
->core
);
1397 if (wwin
->flags
.inspector_open
) {
1398 wUnhideInspectorForWindow(wwin
);
1401 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1404 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1407 WWindow
*wlist
, *next
;
1408 WWindow
*focused
= NULL
;
1414 scr
= wapp
->main_window_desc
->screen_ptr
;
1415 wlist
= scr
->focused_window
;
1419 /* goto beginning of list */
1421 wlist
= wlist
->prev
;
1423 animate
= !wapp
->flags
.skip_next_animation
;
1428 if (wlist
->main_window
== wapp
->main_window
) {
1429 if (wlist
->flags
.focused
)
1431 else if (!focused
|| !focused
->flags
.focused
)
1434 if (wlist
->flags
.miniaturized
) {
1435 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1436 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1437 if (!wlist
->icon
->mapped
) {
1440 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1441 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1442 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1446 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1447 wlist
->icon
->mapped
= 1;
1449 wRaiseFrame(wlist
->icon
->core
);
1451 if (bringToCurrentWS
)
1452 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1453 wlist
->flags
.hidden
= 0;
1454 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1455 wDeiconifyWindow(wlist
);
1457 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1458 } else if (wlist
->flags
.shaded
) {
1459 if (bringToCurrentWS
)
1460 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1461 wlist
->flags
.hidden
= 0;
1462 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1463 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1465 wUnshadeWindow(wlist
);
1466 wRaiseFrame(wlist
->frame
->core
);
1469 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1470 } else if (wlist
->flags
.hidden
) {
1471 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1472 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1475 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1476 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1478 wRaiseFrame(wlist
->frame
->core
);
1484 wapp
->flags
.skip_next_animation
= 0;
1485 wapp
->flags
.hidden
= 0;
1487 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1488 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1489 wSetFocusTo(scr
, wapp
->last_focused
);
1490 } else if (focused
) {
1491 wSetFocusTo(scr
, focused
);
1493 wapp
->last_focused
= NULL
;
1494 if (wPreferences
.auto_arrange_icons
) {
1495 wArrangeIcons(scr
, True
);
1498 wAppIconPaint(wapp
->app_icon
);
1502 void wShowAllWindows(WScreen
* scr
)
1504 WWindow
*wwin
, *old_foc
;
1507 old_foc
= wwin
= scr
->focused_window
;
1509 if (!wwin
->flags
.internal_window
&&
1510 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1511 if (wwin
->flags
.miniaturized
) {
1512 wwin
->flags
.skip_next_animation
= 1;
1513 wDeiconifyWindow(wwin
);
1514 } else if (wwin
->flags
.hidden
) {
1515 wapp
= wApplicationOf(wwin
->main_window
);
1517 wUnhideApplication(wapp
, False
, False
);
1519 wwin
->flags
.skip_next_animation
= 1;
1520 wDeiconifyWindow(wwin
);
1526 wSetFocusTo(scr
, old_foc
);
1527 /*wRaiseFrame(old_foc->frame->core); */
1530 void wRefreshDesktop(WScreen
* scr
)
1533 XSetWindowAttributes attr
;
1535 attr
.backing_store
= NotUseful
;
1536 attr
.save_under
= False
;
1537 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1538 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1539 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1540 XMapRaised(dpy
, win
);
1541 XDestroyWindow(dpy
, win
);
1545 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1551 const int heads
= wXineramaHeads(scr
);
1554 int pf
; /* primary axis */
1555 int sf
; /* secondary axis */
1559 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1565 int isize
= wPreferences
.icon_size
;
1567 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1569 for (head
= 0; head
< heads
; ++head
) {
1571 WMRect rect
= wGetRectForHead(scr
, head
);
1573 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1574 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1577 vars
[head
].pi
= vars
[head
].si
= 0;
1578 vars
[head
].sx1
= rect
.pos
.x
;
1579 vars
[head
].sy1
= rect
.pos
.y
;
1580 vars
[head
].sw
= rect
.size
.width
;
1581 vars
[head
].sh
= rect
.size
.height
;
1582 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1583 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1587 if (scr
->dock
->on_right_side
)
1588 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1590 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1594 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1595 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1596 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1597 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1599 /* icon yard boundaries */
1600 if (wPreferences
.icon_yard
& IY_VERT
) {
1601 vars
[head
].pf
= vars
[head
].fullH
;
1602 vars
[head
].sf
= vars
[head
].fullW
;
1604 vars
[head
].pf
= vars
[head
].fullW
;
1605 vars
[head
].sf
= vars
[head
].fullH
;
1607 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1608 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1611 vars
[head
].xo
= vars
[head
].sx1
;
1614 if (wPreferences
.icon_yard
& IY_TOP
) {
1615 vars
[head
].yo
= vars
[head
].sy1
;
1618 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1623 #define X ((wPreferences.icon_yard & IY_VERT) \
1624 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1625 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1627 #define Y ((wPreferences.icon_yard & IY_VERT) \
1628 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1629 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1631 /* arrange application icons */
1632 aicon
= scr
->app_icon_list
;
1633 /* reverse them to avoid unnecessarily sliding of icons */
1634 while (aicon
&& aicon
->next
)
1635 aicon
= aicon
->next
;
1638 if (!aicon
->docked
) {
1639 /* CHECK: can icon be NULL here ? */
1640 /* The intention here is to place the AppIcon on the head that
1641 * contains most of the applications _main_ window. */
1642 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1644 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1646 if (!wPreferences
.no_animations
) {
1647 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1649 #endif /* ANIMATIONS */
1651 wAppIconMove(aicon
, X
, Y
);
1653 if (vars
[head
].pi
>= vars
[head
].pf
) {
1658 aicon
= aicon
->prev
;
1661 /* arrange miniwindows */
1662 wwin
= scr
->focused_window
;
1663 /* reverse them to avoid unnecessarily shuffling */
1664 while (wwin
&& wwin
->prev
)
1668 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1669 (wwin
->frame
->workspace
== scr
->current_workspace
||
1670 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1672 head
= wGetHeadForWindow(wwin
);
1674 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1675 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1677 if (wPreferences
.no_animations
) {
1678 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1680 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1681 wwin
->icon_y
, X
, Y
);
1684 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1685 #endif /* ANIMATIONS */
1691 if (vars
[head
].pi
>= vars
[head
].pf
) {
1698 wwin
->flags
.icon_moved
= 0;
1700 /* we reversed the order, so we use next */
1707 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1709 WScreen
*scr
= wwin
->screen_ptr
;
1712 wwin
->flags
.selected
= 1;
1713 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1715 if (!HAS_BORDER(wwin
)) {
1716 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1719 if (!scr
->selected_windows
)
1720 scr
->selected_windows
= WMCreateArray(4);
1721 WMAddToArray(scr
->selected_windows
, wwin
);
1723 wwin
->flags
.selected
= 0;
1724 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1726 if (!HAS_BORDER(wwin
)) {
1727 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1730 if (scr
->selected_windows
) {
1731 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1736 void wMakeWindowVisible(WWindow
* wwin
)
1738 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1739 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1741 if (wwin
->flags
.shaded
) {
1742 wUnshadeWindow(wwin
);
1744 if (wwin
->flags
.hidden
) {
1747 app
= wApplicationOf(wwin
->main_window
);
1749 /* trick to get focus to this window */
1750 app
->last_focused
= wwin
;
1751 wUnhideApplication(app
, False
, False
);
1754 if (wwin
->flags
.miniaturized
) {
1755 wDeiconifyWindow(wwin
);
1757 if (!WFLAGP(wwin
, no_focusable
))
1758 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1759 wRaiseFrame(wwin
->frame
->core
);
1764 * Do the animation while shading (called with what = SHADE)
1765 * or unshading (what = UNSHADE).
1768 static void shade_animate(WWindow
*wwin
, Bool what
)
1771 time_t time0
= time(NULL
);
1773 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1778 if (!wwin
->screen_ptr
->flags
.startup
) {
1779 /* do the shading animation */
1780 h
= wwin
->frame
->core
->height
;
1781 s
= h
/ SHADE_STEPS
;
1784 w
= wwin
->frame
->core
->width
;
1785 y
= wwin
->frame
->top_width
;
1786 while (h
> wwin
->frame
->top_width
+ 1) {
1787 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1788 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1791 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1794 if (SHADE_DELAY
> 0) {
1795 wusleep(SHADE_DELAY
* 1000L);
1802 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1807 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1808 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1809 s
= abs(y
) / SHADE_STEPS
;
1812 w
= wwin
->frame
->core
->width
;
1813 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1815 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1816 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1817 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1819 if (SHADE_DELAY
> 0) {
1820 wusleep(SHADE_DELAY
* 2000L / 3);
1827 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1831 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1836 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
1837 #endif /* ANIMATIONS */