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 new_width
-= adj_size
;
386 new_height
-= adj_size
;
387 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
388 new_y
-= wwin
->frame
->top_width
;
389 new_height
+= wwin
->frame
->top_width
- 1;
393 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
395 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
396 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
398 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
400 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
402 /* set maximization state */
403 wwin
->flags
.maximized
= directions
;
407 * Maximus: tiled maximization (maximize without overlapping other windows)
409 * The window to be maximized will be denoted by w_0 (sub-index zero)
410 * while the windows which will stop the maximization of w_0 are denoted by w_j.
412 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
413 unsigned int *new_width
, unsigned int *new_height
)
416 int x_0
= wwin
->frame_x
;
417 int y_0
= wwin
->frame_y
;
418 int width_0
= wwin
->frame
->core
->width
;
419 int height_0
= wwin
->frame
->core
->height
;
420 int botton_0
= y_0
+ height_0
;
421 int right_border_0
= x_0
+ width_0
;
422 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
423 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
424 int x_intsect
, y_intsect
;
425 short int tbar_height_0
= 0, rbar_height_0
= 0;
426 short int bd_width_0
= 0, bd_width_j
= 0;
427 short int adjust_height
;
429 /* Try to fully maximize first, then readjust later */
430 new_x_0
= usableArea
.x1
;
431 new_y_0
= usableArea
.y1
;
432 new_botton_0
= usableArea
.y2
;
433 new_right_border_0
= usableArea
.x2
;
435 if (HAS_TITLEBAR(wwin
))
436 tbar_height_0
= TITLEBAR_HEIGHT
;
437 if (HAS_RESIZEBAR(wwin
))
438 rbar_height_0
= RESIZEBAR_HEIGHT
;
439 if (HAS_BORDER(wwin
))
440 bd_width_0
= FRAME_BORDER_WIDTH
;
442 /* the lengths to be subtracted if w_0 has titlebar, etc */
443 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
446 /* The focused window is always the last in the list */
448 /* ignore windows in other workspaces etc */
449 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
450 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
457 bd_width_j
= FRAME_BORDER_WIDTH
;
462 * Set the w_j window coordinates. It is convenient
463 * to not use "corrected" sizes for width and height,
464 * otherwise bottom_j and right_border_j would be
467 x_j
= tmp
->frame_x
- bd_width_j
;
468 y_j
= tmp
->frame_y
- bd_width_j
;
469 width_j
= tmp
->frame
->core
->width
;
470 height_j
= tmp
->frame
->core
->height
;
471 botton_j
= y_j
+ height_j
+ bd_width_j
;
472 top_j
= y_j
- bd_width_j
;
473 right_border_j
= x_j
+ width_j
+ bd_width_j
;
475 /* Try to maximize in the y direction first */
476 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
477 if (x_intsect
!= 0) {
478 /* TODO: Consider the case when coords are equal */
479 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
480 /* w_0 is below the botton of w_j */
483 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
484 /* The botton of w_0 is above the top of w_j */
485 new_botton_0
= top_j
;
492 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
493 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
500 bd_width_j
= FRAME_BORDER_WIDTH
;
504 /* set the w_j window coordinates */
505 x_j
= tmp
->frame_x
- bd_width_j
;
506 y_j
= tmp
->frame_y
- bd_width_j
;
507 width_j
= tmp
->frame
->core
->width
;
508 height_j
= tmp
->frame
->core
->height
;
509 botton_j
= y_j
+ height_j
+ bd_width_j
;
510 top_j
= y_j
- bd_width_j
;
511 right_border_j
= x_j
+ width_j
+ bd_width_j
;
514 * Use the updated y coordinates from the above step to account
515 * the possibility that the new value of y_0 will have different
516 * intersections with w_j
518 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
519 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
520 if (y_intsect
!= 0) {
521 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
522 /* w_0 is completely to the right of w_j */
523 new_x_0
= right_border_j
+ 1;
525 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
526 /* w_0 is completely to the left of w_j */
527 new_right_border_0
= x_j
- 1;
532 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
535 *new_height
= new_height_0
;
536 *new_width
= new_right_border_0
- new_x_0
;
539 void wUnmaximizeWindow(WWindow
* wwin
)
542 WMRect old_geom_rect
;
546 if (!wwin
->flags
.maximized
)
549 if (wwin
->flags
.shaded
) {
550 wwin
->flags
.skip_next_animation
= 1;
551 wUnshadeWindow(wwin
);
553 /* Use old coordinates if they are set, current values otherwise */
554 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
555 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
556 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
557 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
558 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
559 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
560 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
562 wwin
->flags
.maximized
= 0;
563 wWindowConfigure(wwin
, x
, y
, w
, h
);
565 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
568 void wFullscreenWindow(WWindow
* wwin
)
573 if (wwin
->flags
.fullscreen
)
576 wwin
->flags
.fullscreen
= True
;
578 wWindowConfigureBorders(wwin
);
580 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
582 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
583 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
584 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
585 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
587 head
= wGetHeadForWindow(wwin
);
588 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
589 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
591 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
594 void wUnfullscreenWindow(WWindow
* wwin
)
596 if (!wwin
->flags
.fullscreen
)
599 wwin
->flags
.fullscreen
= False
;
601 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
602 if (WFLAGP(wwin
, sunken
)) {
603 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
604 } else if (WFLAGP(wwin
, floating
)) {
605 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
607 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
611 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
612 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
614 wWindowConfigureBorders(wwin
);
616 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
617 wFrameWindowPaint(wwin->frame);
620 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
624 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
626 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
627 float cx
, cy
, cw
, ch
;
628 float xstep
, ystep
, wstep
, hstep
;
631 float angle
, final_angle
, delta
;
633 xstep
= (float)(fx
- x
) / steps
;
634 ystep
= (float)(fy
- y
) / steps
;
635 wstep
= (float)(fw
- w
) / steps
;
636 hstep
= (float)(fh
- h
) / steps
;
643 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
644 delta
= (float)(final_angle
/ FRAMES
);
645 for (angle
= 0;; angle
+= delta
) {
646 if (angle
> final_angle
)
649 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
650 dch
= (ch
/ 2) * cos(angle
);
651 midy
= cy
+ (ch
/ 2);
653 points
[0].x
= cx
+ dx
;
654 points
[0].y
= midy
- dch
;
655 points
[1].x
= cx
+ cw
- dx
;
656 points
[1].y
= points
[0].y
;
657 points
[2].x
= cx
+ cw
+ dx
;
658 points
[2].y
= midy
+ dch
;
659 points
[3].x
= cx
- dx
;
660 points
[3].y
= points
[2].y
;
661 points
[4].x
= points
[0].x
;
662 points
[4].y
= points
[0].y
;
665 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
667 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
669 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
675 if (angle
>= final_angle
)
685 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
687 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
688 float cx
, cy
, cw
, ch
;
689 float xstep
, ystep
, wstep
, hstep
;
691 float angle
, final_angle
, a
, d
, delta
;
698 xstep
= (float)(fx
- x
) / steps
;
699 ystep
= (float)(fy
- y
) / steps
;
700 wstep
= (float)(fw
- w
) / steps
;
701 hstep
= (float)(fh
- h
) / steps
;
708 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
709 delta
= (float)(final_angle
/ FRAMES
);
710 for (angle
= 0;; angle
+= delta
) {
711 if (angle
> final_angle
)
715 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
717 points
[0].x
= cx
+ cos(angle
- a
) * d
;
718 points
[0].y
= cy
+ sin(angle
- a
) * d
;
719 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
720 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
721 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
722 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
723 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
724 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
725 points
[4].x
= cx
+ cos(angle
- a
) * d
;
726 points
[4].y
= cy
+ sin(angle
- a
) * d
;
728 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
730 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
732 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
738 if (angle
>= final_angle
)
747 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
749 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
750 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
751 float xstep
, ystep
, wstep
, hstep
;
754 xstep
= (float)(fx
- x
) / steps
;
755 ystep
= (float)(fy
- y
) / steps
;
756 wstep
= (float)(fw
- w
) / steps
;
757 hstep
= (float)(fh
- h
) / steps
;
759 for (j
= 0; j
< FRAMES
; j
++) {
766 for (i
= 0; i
< steps
; i
++) {
767 for (j
= 0; j
< FRAMES
; j
++) {
768 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
769 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
772 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
774 for (j
= 0; j
< FRAMES
; j
++) {
775 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
776 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
777 if (j
< FRAMES
- 1) {
791 for (j
= 0; j
< FRAMES
; j
++) {
792 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
795 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
797 for (j
= 0; j
< FRAMES
; j
++) {
798 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
806 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
808 int style
= wPreferences
.iconification_style
; /* Catch the value */
811 if (style
== WIS_NONE
)
814 if (style
== WIS_RANDOM
) {
820 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
822 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
825 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
827 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
831 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
833 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
837 #endif /* ANIMATIONS */
839 static void flushExpose()
843 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
844 WMHandleEvent(&tmpev
);
848 static void unmapTransientsFor(WWindow
* wwin
)
852 tmp
= wwin
->screen_ptr
->focused_window
;
854 /* unmap the transients for this transient */
855 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
856 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
857 unmapTransientsFor(tmp
);
858 tmp
->flags
.miniaturized
= 1;
859 if (!tmp
->flags
.shaded
) {
862 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
865 if (!tmp->flags.shaded)
867 wClientSetState(tmp
, IconicState
, None
);
869 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
875 static void mapTransientsFor(WWindow
* wwin
)
879 tmp
= wwin
->screen_ptr
->focused_window
;
881 /* recursively map the transients for this transient */
882 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
883 && tmp
->icon
== NULL
) {
884 mapTransientsFor(tmp
);
885 tmp
->flags
.miniaturized
= 0;
886 if (!tmp
->flags
.shaded
) {
889 XMapWindow(dpy
, tmp
->frame
->core
->window
);
891 tmp
->flags
.semi_focused
= 0;
893 if (!tmp->flags.shaded)
895 wClientSetState(tmp
, NormalState
, None
);
897 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
904 static void setupIconGrabs(WIcon
* icon
)
906 /* setup passive grabs on the icon */
907 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
908 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
909 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
910 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
911 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
912 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
917 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
924 /* hackish way to detect transient_for cycle */
925 i
= wwin
->screen_ptr
->window_count
+ 1;
927 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
928 wwin
= wWindowFor(wwin
->transient_for
);
931 if (i
== 0 && wwin
) {
932 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
940 static void removeIconGrabs(WIcon
* icon
)
942 /* remove passive grabs on the icon */
943 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
944 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
945 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
950 void wIconifyWindow(WWindow
* wwin
)
952 XWindowAttributes attribs
;
955 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
956 /* the window doesn't exist anymore */
960 if (wwin
->flags
.miniaturized
) {
964 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
965 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
967 if (owner
&& owner
->flags
.miniaturized
)
971 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
973 /* if the window is in another workspace, simplify process */
975 /* icon creation may take a while */
976 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
977 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
978 GrabModeAsync
, None
, None
, CurrentTime
);
981 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
982 if (!wwin
->flags
.icon_moved
) {
983 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
985 wwin
->icon
= wIconCreate(wwin
);
987 wwin
->icon
->mapped
= 1;
990 wwin
->flags
.miniaturized
= 1;
991 wwin
->flags
.mapped
= 0;
993 /* unmap transients */
995 unmapTransientsFor(wwin
);
998 XUngrabPointer(dpy
, CurrentTime
);
1000 /* let all Expose events arrive so that we can repaint
1001 * something before the animation starts (and the server is grabbed) */
1004 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1005 wClientSetState(wwin
, IconicState
, None
);
1007 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1011 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1012 && !wPreferences
.no_animations
) {
1015 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1018 iw
= wwin
->icon
->core
->width
;
1019 ih
= wwin
->icon
->core
->height
;
1021 if (wwin
->flags
.net_handle_icon
) {
1029 iw
= wwin
->screen_ptr
->scr_width
;
1030 ih
= wwin
->screen_ptr
->scr_height
;
1033 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1034 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1039 wwin
->flags
.skip_next_animation
= 0;
1041 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1042 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1043 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1045 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1047 AddToStackList(wwin
->icon
->core
);
1049 wLowerFrame(wwin
->icon
->core
);
1053 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1056 * It doesn't seem to be working and causes button event hangup
1057 * when deiconifying a transient window.
1058 setupIconGrabs(wwin->icon);
1060 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1061 && wPreferences
.focus_mode
== WKF_CLICK
) {
1066 if (!WFLAGP(tmp
, no_focusable
)
1067 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1068 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1072 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1073 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1074 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1077 if (!wwin
->screen_ptr
->flags
.startup
) {
1078 /* Catch up with events not processed while animation was running */
1079 Window clientwin
= wwin
->client_win
;
1081 ProcessPendingEvents();
1083 /* the window can disappear while ProcessPendingEvents() runs */
1084 if (!wWindowFor(clientwin
)) {
1091 /* maybe we want to do this regardless of net_handle_icon
1092 * it seems to me we might break behaviour this way.
1094 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1095 && !wwin
->flags
.net_handle_icon
)
1096 wIconSelect(wwin
->icon
);
1098 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1100 if (wPreferences
.auto_arrange_icons
)
1101 wArrangeIcons(wwin
->screen_ptr
, True
);
1104 void wDeiconifyWindow(WWindow
* wwin
)
1106 /* we're hiding for show_desktop */
1107 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1108 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1111 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1113 if (!wwin
->flags
.miniaturized
)
1116 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1117 WWindow
*owner
= recursiveTransientFor(wwin
);
1119 if (owner
&& owner
->flags
.miniaturized
) {
1120 wDeiconifyWindow(owner
);
1121 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1122 wRaiseFrame(wwin
->frame
->core
);
1127 wwin
->flags
.miniaturized
= 0;
1129 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1130 wwin
->flags
.mapped
= 1;
1133 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1134 /* maybe we want to do this regardless of net_handle_icon
1135 * it seems to me we might break behaviour this way.
1137 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1138 && wwin
->icon
!= NULL
) {
1139 if (wwin
->icon
->selected
)
1140 wIconSelect(wwin
->icon
);
1142 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1146 /* if the window is in another workspace, do it silently */
1147 if (!netwm_hidden
) {
1149 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1150 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1153 if (!wPreferences
.disable_miniwindows
1154 && !wwin
->flags
.net_handle_icon
) {
1157 iw
= wwin
->icon
->core
->width
;
1158 ih
= wwin
->icon
->core
->height
;
1160 if (wwin
->flags
.net_handle_icon
) {
1168 iw
= wwin
->screen_ptr
->scr_width
;
1169 ih
= wwin
->screen_ptr
->scr_height
;
1172 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1173 wwin
->frame_x
, wwin
->frame_y
,
1174 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1176 #endif /* ANIMATIONS */
1177 wwin
->flags
.skip_next_animation
= 0;
1179 if (!wwin
->flags
.shaded
) {
1180 XMapWindow(dpy
, wwin
->client_win
);
1182 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1183 wRaiseFrame(wwin
->frame
->core
);
1184 if (!wwin
->flags
.shaded
) {
1185 wClientSetState(wwin
, NormalState
, None
);
1187 mapTransientsFor(wwin
);
1190 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1191 && !wwin
->flags
.net_handle_icon
) {
1192 RemoveFromStackList(wwin
->icon
->core
);
1193 /* removeIconGrabs(wwin->icon); */
1194 wIconDestroy(wwin
->icon
);
1198 if (!netwm_hidden
) {
1201 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1204 if (!wwin
->screen_ptr
->flags
.startup
) {
1205 /* Catch up with events not processed while animation was running */
1206 Window clientwin
= wwin
->client_win
;
1208 ProcessPendingEvents();
1210 /* the window can disappear while ProcessPendingEvents() runs */
1211 if (!wWindowFor(clientwin
)) {
1218 if (wPreferences
.auto_arrange_icons
) {
1219 wArrangeIcons(wwin
->screen_ptr
, True
);
1222 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1224 /* In case we were shaded and iconified, also unshade */
1226 wUnshadeWindow(wwin
);
1229 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1231 if (wwin
->flags
.miniaturized
) {
1233 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1234 wwin
->icon
->mapped
= 0;
1236 wwin
->flags
.hidden
= 1;
1238 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1242 if (wwin
->flags
.inspector_open
) {
1243 wHideInspectorForWindow(wwin
);
1246 wwin
->flags
.hidden
= 1;
1249 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1253 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1254 !wwin
->flags
.skip_next_animation
&& animate
) {
1255 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1256 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1257 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1260 wwin
->flags
.skip_next_animation
= 0;
1262 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1265 void wHideOtherApplications(WWindow
* awin
)
1272 wwin
= awin
->screen_ptr
->focused_window
;
1276 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1277 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1278 && !wwin
->flags
.internal_window
1279 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1281 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1282 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1283 wwin
->flags
.skip_next_animation
= 1;
1284 wIconifyWindow(wwin
);
1286 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1287 tapp
= wApplicationOf(wwin
->main_window
);
1289 tapp
->flags
.skip_next_animation
= 1;
1290 wHideApplication(tapp
);
1292 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1293 wwin
->flags
.skip_next_animation
= 1;
1294 wIconifyWindow(wwin
);
1302 wSetFocusTo(awin->screen_ptr, awin);
1306 void wHideApplication(WApplication
* wapp
)
1314 wwarning("trying to hide a non grouped window");
1317 if (!wapp
->main_window_desc
) {
1318 wwarning("group leader not found for window group");
1321 scr
= wapp
->main_window_desc
->screen_ptr
;
1323 wlist
= scr
->focused_window
;
1327 if (wlist
->main_window
== wapp
->main_window
)
1328 wapp
->last_focused
= wlist
;
1330 wapp
->last_focused
= NULL
;
1332 animate
= !wapp
->flags
.skip_next_animation
;
1335 if (wlist
->main_window
== wapp
->main_window
) {
1336 if (wlist
->flags
.focused
) {
1339 if (wapp
->app_icon
) {
1340 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1341 wapp
->app_icon
->y_pos
, wlist
, animate
);
1345 wlist
= wlist
->prev
;
1348 wapp
->flags
.skip_next_animation
= 0;
1351 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1352 wlist
= scr
->focused_window
;
1354 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1355 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1357 wlist
= wlist
->prev
;
1359 wSetFocusTo(scr
, wlist
);
1361 wSetFocusTo(scr
, NULL
);
1365 wapp
->flags
.hidden
= 1;
1367 if (wPreferences
.auto_arrange_icons
) {
1368 wArrangeIcons(scr
, True
);
1372 wAppIconPaint(wapp
->app_icon
);
1376 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1378 if (bringToCurrentWS
)
1379 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1381 wwin
->flags
.hidden
= 0;
1384 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1385 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1386 icon
->core
->width
, icon
->core
->height
,
1387 wwin
->frame_x
, wwin
->frame_y
,
1388 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1391 wwin
->flags
.skip_next_animation
= 0;
1392 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1393 XMapWindow(dpy
, wwin
->client_win
);
1394 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1395 wClientSetState(wwin
, NormalState
, None
);
1396 wwin
->flags
.mapped
= 1;
1397 wRaiseFrame(wwin
->frame
->core
);
1399 if (wwin
->flags
.inspector_open
) {
1400 wUnhideInspectorForWindow(wwin
);
1403 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1406 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1409 WWindow
*wlist
, *next
;
1410 WWindow
*focused
= NULL
;
1416 scr
= wapp
->main_window_desc
->screen_ptr
;
1417 wlist
= scr
->focused_window
;
1421 /* goto beginning of list */
1423 wlist
= wlist
->prev
;
1425 animate
= !wapp
->flags
.skip_next_animation
;
1430 if (wlist
->main_window
== wapp
->main_window
) {
1431 if (wlist
->flags
.focused
)
1433 else if (!focused
|| !focused
->flags
.focused
)
1436 if (wlist
->flags
.miniaturized
) {
1437 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1438 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1439 if (!wlist
->icon
->mapped
) {
1442 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1443 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1444 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1448 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1449 wlist
->icon
->mapped
= 1;
1451 wRaiseFrame(wlist
->icon
->core
);
1453 if (bringToCurrentWS
)
1454 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1455 wlist
->flags
.hidden
= 0;
1456 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1457 wDeiconifyWindow(wlist
);
1459 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1460 } else if (wlist
->flags
.shaded
) {
1461 if (bringToCurrentWS
)
1462 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1463 wlist
->flags
.hidden
= 0;
1464 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1465 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1467 wUnshadeWindow(wlist
);
1468 wRaiseFrame(wlist
->frame
->core
);
1471 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1472 } else if (wlist
->flags
.hidden
) {
1473 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1474 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1477 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1478 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1480 wRaiseFrame(wlist
->frame
->core
);
1486 wapp
->flags
.skip_next_animation
= 0;
1487 wapp
->flags
.hidden
= 0;
1489 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1490 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1491 wSetFocusTo(scr
, wapp
->last_focused
);
1492 } else if (focused
) {
1493 wSetFocusTo(scr
, focused
);
1495 wapp
->last_focused
= NULL
;
1496 if (wPreferences
.auto_arrange_icons
) {
1497 wArrangeIcons(scr
, True
);
1500 wAppIconPaint(wapp
->app_icon
);
1504 void wShowAllWindows(WScreen
* scr
)
1506 WWindow
*wwin
, *old_foc
;
1509 old_foc
= wwin
= scr
->focused_window
;
1511 if (!wwin
->flags
.internal_window
&&
1512 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1513 if (wwin
->flags
.miniaturized
) {
1514 wwin
->flags
.skip_next_animation
= 1;
1515 wDeiconifyWindow(wwin
);
1516 } else if (wwin
->flags
.hidden
) {
1517 wapp
= wApplicationOf(wwin
->main_window
);
1519 wUnhideApplication(wapp
, False
, False
);
1521 wwin
->flags
.skip_next_animation
= 1;
1522 wDeiconifyWindow(wwin
);
1528 wSetFocusTo(scr
, old_foc
);
1529 /*wRaiseFrame(old_foc->frame->core); */
1532 void wRefreshDesktop(WScreen
* scr
)
1535 XSetWindowAttributes attr
;
1537 attr
.backing_store
= NotUseful
;
1538 attr
.save_under
= False
;
1539 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1540 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1541 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1542 XMapRaised(dpy
, win
);
1543 XDestroyWindow(dpy
, win
);
1547 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1553 const int heads
= wXineramaHeads(scr
);
1556 int pf
; /* primary axis */
1557 int sf
; /* secondary axis */
1561 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1567 int isize
= wPreferences
.icon_size
;
1569 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1571 for (head
= 0; head
< heads
; ++head
) {
1573 WMRect rect
= wGetRectForHead(scr
, head
);
1575 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1576 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1579 vars
[head
].pi
= vars
[head
].si
= 0;
1580 vars
[head
].sx1
= rect
.pos
.x
;
1581 vars
[head
].sy1
= rect
.pos
.y
;
1582 vars
[head
].sw
= rect
.size
.width
;
1583 vars
[head
].sh
= rect
.size
.height
;
1584 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1585 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1589 if (scr
->dock
->on_right_side
)
1590 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1592 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1596 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1597 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1598 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1599 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1601 /* icon yard boundaries */
1602 if (wPreferences
.icon_yard
& IY_VERT
) {
1603 vars
[head
].pf
= vars
[head
].fullH
;
1604 vars
[head
].sf
= vars
[head
].fullW
;
1606 vars
[head
].pf
= vars
[head
].fullW
;
1607 vars
[head
].sf
= vars
[head
].fullH
;
1609 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1610 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1613 vars
[head
].xo
= vars
[head
].sx1
;
1616 if (wPreferences
.icon_yard
& IY_TOP
) {
1617 vars
[head
].yo
= vars
[head
].sy1
;
1620 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1625 #define X ((wPreferences.icon_yard & IY_VERT) \
1626 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1627 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1629 #define Y ((wPreferences.icon_yard & IY_VERT) \
1630 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1631 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1633 /* arrange application icons */
1634 aicon
= scr
->app_icon_list
;
1635 /* reverse them to avoid unnecessarily sliding of icons */
1636 while (aicon
&& aicon
->next
)
1637 aicon
= aicon
->next
;
1640 if (!aicon
->docked
) {
1641 /* CHECK: can icon be NULL here ? */
1642 /* The intention here is to place the AppIcon on the head that
1643 * contains most of the applications _main_ window. */
1644 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1646 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1648 if (!wPreferences
.no_animations
) {
1649 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1651 #endif /* ANIMATIONS */
1653 wAppIconMove(aicon
, X
, Y
);
1655 if (vars
[head
].pi
>= vars
[head
].pf
) {
1660 aicon
= aicon
->prev
;
1663 /* arrange miniwindows */
1664 wwin
= scr
->focused_window
;
1665 /* reverse them to avoid unnecessarily shuffling */
1666 while (wwin
&& wwin
->prev
)
1670 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1671 (wwin
->frame
->workspace
== scr
->current_workspace
||
1672 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1674 head
= wGetHeadForWindow(wwin
);
1676 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1677 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1679 if (wPreferences
.no_animations
) {
1680 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1682 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1683 wwin
->icon_y
, X
, Y
);
1686 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1687 #endif /* ANIMATIONS */
1693 if (vars
[head
].pi
>= vars
[head
].pf
) {
1700 wwin
->flags
.icon_moved
= 0;
1702 /* we reversed the order, so we use next */
1709 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1711 WScreen
*scr
= wwin
->screen_ptr
;
1714 wwin
->flags
.selected
= 1;
1715 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1717 if (!HAS_BORDER(wwin
)) {
1718 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1721 if (!scr
->selected_windows
)
1722 scr
->selected_windows
= WMCreateArray(4);
1723 WMAddToArray(scr
->selected_windows
, wwin
);
1725 wwin
->flags
.selected
= 0;
1726 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1728 if (!HAS_BORDER(wwin
)) {
1729 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1732 if (scr
->selected_windows
) {
1733 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1738 void wMakeWindowVisible(WWindow
* wwin
)
1740 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1741 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1743 if (wwin
->flags
.shaded
) {
1744 wUnshadeWindow(wwin
);
1746 if (wwin
->flags
.hidden
) {
1749 app
= wApplicationOf(wwin
->main_window
);
1751 /* trick to get focus to this window */
1752 app
->last_focused
= wwin
;
1753 wUnhideApplication(app
, False
, False
);
1756 if (wwin
->flags
.miniaturized
) {
1757 wDeiconifyWindow(wwin
);
1759 if (!WFLAGP(wwin
, no_focusable
))
1760 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1761 wRaiseFrame(wwin
->frame
->core
);
1766 * Do the animation while shading (called with what = SHADE)
1767 * or unshading (what = UNSHADE).
1770 static void shade_animate(WWindow
*wwin
, Bool what
)
1773 time_t time0
= time(NULL
);
1775 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1780 if (!wwin
->screen_ptr
->flags
.startup
) {
1781 /* do the shading animation */
1782 h
= wwin
->frame
->core
->height
;
1783 s
= h
/ SHADE_STEPS
;
1786 w
= wwin
->frame
->core
->width
;
1787 y
= wwin
->frame
->top_width
;
1788 while (h
> wwin
->frame
->top_width
+ 1) {
1789 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1790 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1793 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1796 if (SHADE_DELAY
> 0) {
1797 wusleep(SHADE_DELAY
* 1000L);
1804 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1809 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1810 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1811 s
= abs(y
) / SHADE_STEPS
;
1814 w
= wwin
->frame
->core
->width
;
1815 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1817 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1818 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1819 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1821 if (SHADE_DELAY
> 0) {
1822 wusleep(SHADE_DELAY
* 2000L / 3);
1829 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1833 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1838 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
1839 #endif /* ANIMATIONS */