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
981 && !wwin
->flags
.net_handle_icon
984 if (!wwin
->flags
.icon_moved
) {
985 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
987 wwin
->icon
= wIconCreate(wwin
);
989 wwin
->icon
->mapped
= 1;
992 wwin
->flags
.miniaturized
= 1;
993 wwin
->flags
.mapped
= 0;
995 /* unmap transients */
997 unmapTransientsFor(wwin
);
1000 XUngrabPointer(dpy
, CurrentTime
);
1002 /* let all Expose events arrive so that we can repaint
1003 * something before the animation starts (and the server is grabbed) */
1006 if (wPreferences
.disable_miniwindows
1008 || wwin
->flags
.net_handle_icon
1011 wClientSetState(wwin
, IconicState
, None
);
1013 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1017 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1018 && !wPreferences
.no_animations
) {
1021 if (!wPreferences
.disable_miniwindows
1023 && !wwin
->flags
.net_handle_icon
1028 iw
= wwin
->icon
->core
->width
;
1029 ih
= wwin
->icon
->core
->height
;
1032 if (wwin
->flags
.net_handle_icon
) {
1042 iw
= wwin
->screen_ptr
->scr_width
;
1043 ih
= wwin
->screen_ptr
->scr_height
;
1046 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1047 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1052 wwin
->flags
.skip_next_animation
= 0;
1054 if (!wPreferences
.disable_miniwindows
1056 && !wwin
->flags
.net_handle_icon
1060 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1061 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1063 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1065 AddToStackList(wwin
->icon
->core
);
1067 wLowerFrame(wwin
->icon
->core
);
1071 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1074 * It doesn't seem to be working and causes button event hangup
1075 * when deiconifying a transient window.
1076 setupIconGrabs(wwin->icon);
1078 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1079 && wPreferences
.focus_mode
== WKF_CLICK
) {
1084 if (!WFLAGP(tmp
, no_focusable
)
1085 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1086 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1090 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1091 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1092 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1095 if (!wwin
->screen_ptr
->flags
.startup
) {
1096 /* Catch up with events not processed while animation was running */
1097 Window clientwin
= wwin
->client_win
;
1099 ProcessPendingEvents();
1101 /* the window can disappear while ProcessPendingEvents() runs */
1102 if (!wWindowFor(clientwin
)) {
1109 /* maybe we want to do this regardless of net_handle_icon
1110 * it seems to me we might break behaviour this way.
1112 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1114 && !wwin
->flags
.net_handle_icon
1117 wIconSelect(wwin
->icon
);
1119 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1121 if (wPreferences
.auto_arrange_icons
)
1122 wArrangeIcons(wwin
->screen_ptr
, True
);
1125 void wDeiconifyWindow(WWindow
* wwin
)
1128 /* we're hiding for show_desktop */
1129 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1130 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1132 int netwm_hidden
= False
;
1136 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1138 if (!wwin
->flags
.miniaturized
)
1141 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1142 WWindow
*owner
= recursiveTransientFor(wwin
);
1144 if (owner
&& owner
->flags
.miniaturized
) {
1145 wDeiconifyWindow(owner
);
1146 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1147 wRaiseFrame(wwin
->frame
->core
);
1152 wwin
->flags
.miniaturized
= 0;
1154 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1155 wwin
->flags
.mapped
= 1;
1158 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1159 /* maybe we want to do this regardless of net_handle_icon
1160 * it seems to me we might break behaviour this way.
1162 if (!wPreferences
.disable_miniwindows
1164 && !wwin
->flags
.net_handle_icon
1166 && wwin
->icon
!= NULL
) {
1167 if (wwin
->icon
->selected
)
1168 wIconSelect(wwin
->icon
);
1170 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1174 /* if the window is in another workspace, do it silently */
1175 if (!netwm_hidden
) {
1177 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1178 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1181 if (!wPreferences
.disable_miniwindows
1183 && !wwin
->flags
.net_handle_icon
1188 iw
= wwin
->icon
->core
->width
;
1189 ih
= wwin
->icon
->core
->height
;
1192 if (wwin
->flags
.net_handle_icon
) {
1202 iw
= wwin
->screen_ptr
->scr_width
;
1203 ih
= wwin
->screen_ptr
->scr_height
;
1206 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1207 wwin
->frame_x
, wwin
->frame_y
,
1208 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1210 #endif /* ANIMATIONS */
1211 wwin
->flags
.skip_next_animation
= 0;
1213 if (!wwin
->flags
.shaded
) {
1214 XMapWindow(dpy
, wwin
->client_win
);
1216 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1217 wRaiseFrame(wwin
->frame
->core
);
1218 if (!wwin
->flags
.shaded
) {
1219 wClientSetState(wwin
, NormalState
, None
);
1221 mapTransientsFor(wwin
);
1224 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1226 && !wwin
->flags
.net_handle_icon
1229 RemoveFromStackList(wwin
->icon
->core
);
1230 /* removeIconGrabs(wwin->icon); */
1231 wIconDestroy(wwin
->icon
);
1235 if (!netwm_hidden
) {
1238 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1241 if (!wwin
->screen_ptr
->flags
.startup
) {
1242 /* Catch up with events not processed while animation was running */
1243 Window clientwin
= wwin
->client_win
;
1245 ProcessPendingEvents();
1247 /* the window can disappear while ProcessPendingEvents() runs */
1248 if (!wWindowFor(clientwin
)) {
1255 if (wPreferences
.auto_arrange_icons
) {
1256 wArrangeIcons(wwin
->screen_ptr
, True
);
1259 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1261 /* In case we were shaded and iconified, also unshade */
1263 wUnshadeWindow(wwin
);
1266 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1268 if (wwin
->flags
.miniaturized
) {
1270 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1271 wwin
->icon
->mapped
= 0;
1273 wwin
->flags
.hidden
= 1;
1275 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1279 if (wwin
->flags
.inspector_open
) {
1280 wHideInspectorForWindow(wwin
);
1283 wwin
->flags
.hidden
= 1;
1286 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1290 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1291 !wwin
->flags
.skip_next_animation
&& animate
) {
1292 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1293 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1294 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1297 wwin
->flags
.skip_next_animation
= 0;
1299 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1302 void wHideOtherApplications(WWindow
* awin
)
1309 wwin
= awin
->screen_ptr
->focused_window
;
1313 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1314 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1315 && !wwin
->flags
.internal_window
1316 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1318 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1319 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1320 wwin
->flags
.skip_next_animation
= 1;
1321 wIconifyWindow(wwin
);
1323 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1324 tapp
= wApplicationOf(wwin
->main_window
);
1326 tapp
->flags
.skip_next_animation
= 1;
1327 wHideApplication(tapp
);
1329 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1330 wwin
->flags
.skip_next_animation
= 1;
1331 wIconifyWindow(wwin
);
1339 wSetFocusTo(awin->screen_ptr, awin);
1343 void wHideApplication(WApplication
* wapp
)
1351 wwarning("trying to hide a non grouped window");
1354 if (!wapp
->main_window_desc
) {
1355 wwarning("group leader not found for window group");
1358 scr
= wapp
->main_window_desc
->screen_ptr
;
1360 wlist
= scr
->focused_window
;
1364 if (wlist
->main_window
== wapp
->main_window
)
1365 wapp
->last_focused
= wlist
;
1367 wapp
->last_focused
= NULL
;
1369 animate
= !wapp
->flags
.skip_next_animation
;
1372 if (wlist
->main_window
== wapp
->main_window
) {
1373 if (wlist
->flags
.focused
) {
1376 if (wapp
->app_icon
) {
1377 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1378 wapp
->app_icon
->y_pos
, wlist
, animate
);
1382 wlist
= wlist
->prev
;
1385 wapp
->flags
.skip_next_animation
= 0;
1388 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1389 wlist
= scr
->focused_window
;
1391 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1392 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1394 wlist
= wlist
->prev
;
1396 wSetFocusTo(scr
, wlist
);
1398 wSetFocusTo(scr
, NULL
);
1402 wapp
->flags
.hidden
= 1;
1404 if (wPreferences
.auto_arrange_icons
) {
1405 wArrangeIcons(scr
, True
);
1409 wAppIconPaint(wapp
->app_icon
);
1413 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1415 if (bringToCurrentWS
)
1416 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1418 wwin
->flags
.hidden
= 0;
1421 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1422 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1423 icon
->core
->width
, icon
->core
->height
,
1424 wwin
->frame_x
, wwin
->frame_y
,
1425 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1428 wwin
->flags
.skip_next_animation
= 0;
1429 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1430 XMapWindow(dpy
, wwin
->client_win
);
1431 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1432 wClientSetState(wwin
, NormalState
, None
);
1433 wwin
->flags
.mapped
= 1;
1434 wRaiseFrame(wwin
->frame
->core
);
1436 if (wwin
->flags
.inspector_open
) {
1437 wUnhideInspectorForWindow(wwin
);
1440 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1443 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1446 WWindow
*wlist
, *next
;
1447 WWindow
*focused
= NULL
;
1453 scr
= wapp
->main_window_desc
->screen_ptr
;
1454 wlist
= scr
->focused_window
;
1458 /* goto beginning of list */
1460 wlist
= wlist
->prev
;
1462 animate
= !wapp
->flags
.skip_next_animation
;
1467 if (wlist
->main_window
== wapp
->main_window
) {
1468 if (wlist
->flags
.focused
)
1470 else if (!focused
|| !focused
->flags
.focused
)
1473 if (wlist
->flags
.miniaturized
) {
1474 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1475 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1476 if (!wlist
->icon
->mapped
) {
1479 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1480 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1481 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1485 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1486 wlist
->icon
->mapped
= 1;
1488 wRaiseFrame(wlist
->icon
->core
);
1490 if (bringToCurrentWS
)
1491 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1492 wlist
->flags
.hidden
= 0;
1493 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1494 wDeiconifyWindow(wlist
);
1496 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1497 } else if (wlist
->flags
.shaded
) {
1498 if (bringToCurrentWS
)
1499 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1500 wlist
->flags
.hidden
= 0;
1501 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1502 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1504 wUnshadeWindow(wlist
);
1505 wRaiseFrame(wlist
->frame
->core
);
1508 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1509 } else if (wlist
->flags
.hidden
) {
1510 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1511 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1514 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1515 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1517 wRaiseFrame(wlist
->frame
->core
);
1523 wapp
->flags
.skip_next_animation
= 0;
1524 wapp
->flags
.hidden
= 0;
1526 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1527 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1528 wSetFocusTo(scr
, wapp
->last_focused
);
1529 } else if (focused
) {
1530 wSetFocusTo(scr
, focused
);
1532 wapp
->last_focused
= NULL
;
1533 if (wPreferences
.auto_arrange_icons
) {
1534 wArrangeIcons(scr
, True
);
1537 wAppIconPaint(wapp
->app_icon
);
1541 void wShowAllWindows(WScreen
* scr
)
1543 WWindow
*wwin
, *old_foc
;
1546 old_foc
= wwin
= scr
->focused_window
;
1548 if (!wwin
->flags
.internal_window
&&
1549 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1550 if (wwin
->flags
.miniaturized
) {
1551 wwin
->flags
.skip_next_animation
= 1;
1552 wDeiconifyWindow(wwin
);
1553 } else if (wwin
->flags
.hidden
) {
1554 wapp
= wApplicationOf(wwin
->main_window
);
1556 wUnhideApplication(wapp
, False
, False
);
1558 wwin
->flags
.skip_next_animation
= 1;
1559 wDeiconifyWindow(wwin
);
1565 wSetFocusTo(scr
, old_foc
);
1566 /*wRaiseFrame(old_foc->frame->core); */
1569 void wRefreshDesktop(WScreen
* scr
)
1572 XSetWindowAttributes attr
;
1574 attr
.backing_store
= NotUseful
;
1575 attr
.save_under
= False
;
1576 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1577 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1578 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1579 XMapRaised(dpy
, win
);
1580 XDestroyWindow(dpy
, win
);
1584 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1590 const int heads
= wXineramaHeads(scr
);
1593 int pf
; /* primary axis */
1594 int sf
; /* secondary axis */
1598 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1604 int isize
= wPreferences
.icon_size
;
1606 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1608 for (head
= 0; head
< heads
; ++head
) {
1610 WMRect rect
= wGetRectForHead(scr
, head
);
1612 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1613 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1616 vars
[head
].pi
= vars
[head
].si
= 0;
1617 vars
[head
].sx1
= rect
.pos
.x
;
1618 vars
[head
].sy1
= rect
.pos
.y
;
1619 vars
[head
].sw
= rect
.size
.width
;
1620 vars
[head
].sh
= rect
.size
.height
;
1621 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1622 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1626 if (scr
->dock
->on_right_side
)
1627 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1629 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1633 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1634 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1635 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1636 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1638 /* icon yard boundaries */
1639 if (wPreferences
.icon_yard
& IY_VERT
) {
1640 vars
[head
].pf
= vars
[head
].fullH
;
1641 vars
[head
].sf
= vars
[head
].fullW
;
1643 vars
[head
].pf
= vars
[head
].fullW
;
1644 vars
[head
].sf
= vars
[head
].fullH
;
1646 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1647 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1650 vars
[head
].xo
= vars
[head
].sx1
;
1653 if (wPreferences
.icon_yard
& IY_TOP
) {
1654 vars
[head
].yo
= vars
[head
].sy1
;
1657 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1662 #define X ((wPreferences.icon_yard & IY_VERT) \
1663 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1664 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1666 #define Y ((wPreferences.icon_yard & IY_VERT) \
1667 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1668 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1670 /* arrange application icons */
1671 aicon
= scr
->app_icon_list
;
1672 /* reverse them to avoid unnecessarily sliding of icons */
1673 while (aicon
&& aicon
->next
)
1674 aicon
= aicon
->next
;
1677 if (!aicon
->docked
) {
1678 /* CHECK: can icon be NULL here ? */
1679 /* The intention here is to place the AppIcon on the head that
1680 * contains most of the applications _main_ window. */
1681 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1683 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1685 if (!wPreferences
.no_animations
) {
1686 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1688 #endif /* ANIMATIONS */
1690 wAppIconMove(aicon
, X
, Y
);
1692 if (vars
[head
].pi
>= vars
[head
].pf
) {
1697 aicon
= aicon
->prev
;
1700 /* arrange miniwindows */
1701 wwin
= scr
->focused_window
;
1702 /* reverse them to avoid unnecessarily shuffling */
1703 while (wwin
&& wwin
->prev
)
1707 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1708 (wwin
->frame
->workspace
== scr
->current_workspace
||
1709 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1711 head
= wGetHeadForWindow(wwin
);
1713 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1714 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1716 if (wPreferences
.no_animations
) {
1717 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1719 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1720 wwin
->icon_y
, X
, Y
);
1723 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1724 #endif /* ANIMATIONS */
1730 if (vars
[head
].pi
>= vars
[head
].pf
) {
1737 wwin
->flags
.icon_moved
= 0;
1739 /* we reversed the order, so we use next */
1747 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1751 int pf
; /* primary axis */
1752 int sf
; /* secondary axis */
1756 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1760 int isize
= wPreferences
.icon_size
;
1763 * Find out screen boundaries.
1767 * Allows each head to have miniwindows
1769 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1773 sw
= rect
.size
.width
;
1774 sh
= rect
.size
.height
;
1778 if (scr
->dock
->on_right_side
)
1779 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1781 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1784 sw
= isize
* (scr
->scr_width
/ isize
);
1785 sh
= isize
* (scr
->scr_height
/ isize
);
1787 sw
= isize
* (sw
/ isize
);
1788 sh
= isize
* (sh
/ isize
);
1790 fullW
= (sx2
- sx1
) / isize
;
1791 fullH
= (sy2
- sy1
) / isize
;
1793 /* icon yard boundaries */
1794 if (wPreferences
.icon_yard
& IY_VERT
) {
1801 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1808 if (wPreferences
.icon_yard
& IY_TOP
) {
1816 /* arrange icons putting the most recently focused window
1817 * as the last icon */
1818 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1819 : xo + xs*(pi*isize))
1820 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1821 : yo + ys*(si*isize))
1823 /* arrange application icons */
1824 aicon
= scr
->app_icon_list
;
1825 /* reverse them to avoid unnecessarily sliding of icons */
1826 while (aicon
&& aicon
->next
)
1827 aicon
= aicon
->next
;
1832 if (!aicon
->docked
) {
1833 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1835 if (!wPreferences
.no_animations
) {
1836 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1838 #endif /* ANIMATIONS */
1840 wAppIconMove(aicon
, X
, Y
);
1843 /* we reversed the order so we use prev */
1844 aicon
= aicon
->prev
;
1851 /* arrange miniwindows */
1853 wwin
= scr
->focused_window
;
1854 /* reverse them to avoid unnecessarily shuffling */
1855 while (wwin
&& wwin
->prev
)
1859 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1860 (wwin
->frame
->workspace
== scr
->current_workspace
||
1861 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1863 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1864 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1866 if (wPreferences
.no_animations
) {
1867 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1869 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1870 wwin
->icon_y
, X
, Y
);
1873 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1874 #endif /* ANIMATIONS */
1882 wwin
->flags
.icon_moved
= 0;
1884 /* we reversed the order, so we use next */
1894 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1896 WScreen
*scr
= wwin
->screen_ptr
;
1899 wwin
->flags
.selected
= 1;
1900 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1902 if (!HAS_BORDER(wwin
)) {
1903 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1906 if (!scr
->selected_windows
)
1907 scr
->selected_windows
= WMCreateArray(4);
1908 WMAddToArray(scr
->selected_windows
, wwin
);
1910 wwin
->flags
.selected
= 0;
1911 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1913 if (!HAS_BORDER(wwin
)) {
1914 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1917 if (scr
->selected_windows
) {
1918 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1923 void wMakeWindowVisible(WWindow
* wwin
)
1925 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1926 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1928 if (wwin
->flags
.shaded
) {
1929 wUnshadeWindow(wwin
);
1931 if (wwin
->flags
.hidden
) {
1934 app
= wApplicationOf(wwin
->main_window
);
1936 /* trick to get focus to this window */
1937 app
->last_focused
= wwin
;
1938 wUnhideApplication(app
, False
, False
);
1941 if (wwin
->flags
.miniaturized
) {
1942 wDeiconifyWindow(wwin
);
1944 if (!WFLAGP(wwin
, no_focusable
))
1945 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1946 wRaiseFrame(wwin
->frame
->core
);
1951 * Do the animation while shading (called with what = SHADE)
1952 * or unshading (what = UNSHADE).
1955 static void shade_animate(WWindow
*wwin
, Bool what
)
1958 time_t time0
= time(NULL
);
1960 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1965 if (!wwin
->screen_ptr
->flags
.startup
) {
1966 /* do the shading animation */
1967 h
= wwin
->frame
->core
->height
;
1968 s
= h
/ SHADE_STEPS
;
1971 w
= wwin
->frame
->core
->width
;
1972 y
= wwin
->frame
->top_width
;
1973 while (h
> wwin
->frame
->top_width
+ 1) {
1974 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1975 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1978 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1981 if (SHADE_DELAY
> 0) {
1982 wusleep(SHADE_DELAY
* 1000L);
1989 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1994 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1995 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1996 s
= abs(y
) / SHADE_STEPS
;
1999 w
= wwin
->frame
->core
->width
;
2000 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2002 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2003 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2004 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2006 if (SHADE_DELAY
> 0) {
2007 wusleep(SHADE_DELAY
* 2000L / 3);
2014 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2018 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2023 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
2024 #endif /* ANIMATIONS */