1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
40 #include "application.h"
46 #include "winspector.h"
47 #include "workspace.h"
50 /****** Global Variables ******/
52 int ignore_wks_change
= 0;
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
56 extern Cursor wCursor
[WCUR_LAST
];
58 extern WPreferences wPreferences
;
60 extern Atom _XA_WM_TAKE_FOCUS
;
62 extern void ProcessPendingEvents();
63 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
65 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
66 unsigned int *new_width
, unsigned int *new_height
);
67 static void save_old_geometry(WWindow
*wwin
);
69 /******* Local Variables *******/
75 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
76 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
77 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
78 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
79 SHADE_STEPS_US
, SHADE_DELAY_US
}};
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
86 static int compareTimes(Time t1
, Time t2
)
92 return (diff
< 60000) ? 1 : -1;
96 static void shade_animate(WWindow
*wwin
, Bool what
);
98 static void shade_animate(WWindow
*wwin
, Bool what
) { }
102 *----------------------------------------------------------------------
104 * Changes the window focus to the one passed as argument.
105 * If the window to focus is not already focused, it will be brought
106 * to the head of the list of windows. Previously focused window is
110 * Window list may be reordered and the window focus is changed.
112 *----------------------------------------------------------------------
114 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
116 static WScreen
*old_scr
= NULL
;
118 WWindow
*old_focused
;
119 WWindow
*focused
= scr
->focused_window
;
120 Time timestamp
= LastTimestamp
;
121 WApplication
*oapp
= NULL
, *napp
= NULL
;
124 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
129 old_focused
= old_scr
->focused_window
;
131 LastFocusChange
= timestamp
;
134 oapp
= wApplicationOf(old_focused
->main_window
);
137 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
139 wWindowUnfocus(old_focused
);
141 wAppMenuUnmap(oapp
->menu
);
143 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
145 } else if (old_scr
!= scr
&& old_focused
) {
146 wWindowUnfocus(old_focused
);
149 wasfocused
= wwin
->flags
.focused
;
150 napp
= wApplicationOf(wwin
->main_window
);
152 /* remember last workspace where the app has been */
154 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
155 napp
->last_workspace
= wwin
->frame
->workspace
;
158 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
159 /* install colormap if colormap mode is lock mode */
160 if (wPreferences
.colormap_mode
== WCM_CLICK
)
161 wColormapInstallForWindow(scr
, wwin
);
163 /* set input focus */
164 switch (wwin
->focus_mode
) {
166 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
170 case WFM_LOCALLY_ACTIVE
:
171 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
174 case WFM_GLOBALLY_ACTIVE
:
178 if (wwin
->protocols
.TAKE_FOCUS
) {
179 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
183 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
185 if (WFLAGP(wwin
, no_focusable
))
188 /* if this is not the focused window focus it */
189 if (focused
!= wwin
) {
190 /* change the focus window list order */
192 wwin
->prev
->next
= wwin
->next
;
195 wwin
->next
->prev
= wwin
->prev
;
197 wwin
->prev
= focused
;
198 focused
->next
= wwin
;
200 scr
->focused_window
= wwin
;
202 if (oapp
&& oapp
!= napp
)
203 wAppMenuUnmap(oapp
->menu
);
206 wWindowFocus(wwin
, focused
);
208 if (napp
&& !wasfocused
) {
210 wUserMenuRefreshInstances(napp
->menu
, wwin
);
211 #endif /* USER_MENU */
213 if (wwin
->flags
.mapped
)
214 wAppMenuMap(napp
->menu
, wwin
);
221 void wShadeWindow(WWindow
*wwin
)
224 if (wwin
->flags
.shaded
)
227 XLowerWindow(dpy
, wwin
->client_win
);
228 shade_animate(wwin
, SHADE
);
230 wwin
->flags
.skip_next_animation
= 0;
231 wwin
->flags
.shaded
= 1;
232 wwin
->flags
.mapped
= 0;
233 /* prevent window withdrawal when getting UnmapNotify */
234 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
235 XUnmapWindow(dpy
, wwin
->client_win
);
236 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
238 /* for the client it's just like iconification */
239 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
241 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
242 wWindowSynthConfigureNotify(wwin
);
245 wClientSetState(wwin, IconicState, None);
248 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
251 if (!wwin
->screen_ptr
->flags
.startup
) {
252 /* Catch up with events not processed while animation was running */
253 ProcessPendingEvents();
258 void wUnshadeWindow(WWindow
*wwin
)
261 if (!wwin
->flags
.shaded
)
264 wwin
->flags
.shaded
= 0;
265 wwin
->flags
.mapped
= 1;
266 XMapWindow(dpy
, wwin
->client_win
);
268 shade_animate(wwin
, UNSHADE
);
270 wwin
->flags
.skip_next_animation
= 0;
271 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
272 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
274 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
275 wWindowSynthConfigureNotify(wwin
);
277 /* if the window is focused, set the focus again as it was disabled during
279 if (wwin
->flags
.focused
)
280 wSetFocusTo(wwin
->screen_ptr
, wwin
);
282 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
285 /* Set the old coordinates using the current values */
286 static void save_old_geometry(WWindow
*wwin
)
288 wwin
->old_geometry
.width
= wwin
->client
.width
;
289 wwin
->old_geometry
.height
= wwin
->client
.height
;
290 wwin
->old_geometry
.x
= wwin
->frame_x
;
291 wwin
->old_geometry
.y
= wwin
->frame_y
;
294 void wMaximizeWindow(WWindow
*wwin
, int directions
)
297 unsigned int new_width
, new_height
, half_scr_width
;
298 WArea usableArea
, totalArea
;
302 if (!IS_RESIZABLE(wwin
))
305 if (!HAS_BORDER(wwin
))
308 /* the size to adjust the geometry */
309 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
311 /* save old coordinates before we change the current values */
312 save_old_geometry(wwin
);
316 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
317 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
318 usableArea
= totalArea
;
320 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
321 WScreen
*scr
= wwin
->screen_ptr
;
324 if (directions
& MAX_KEYBOARD
)
325 head
= wGetHeadForWindow(wwin
);
327 head
= wGetHeadForPointerLocation(scr
);
329 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
332 /* Only save directions, not kbd or xinerama hints */
333 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
335 if (WFLAGP(wwin
, full_maximize
)) {
336 usableArea
= totalArea
;
338 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
340 if (wwin
->flags
.shaded
) {
341 wwin
->flags
.skip_next_animation
= 1;
342 wUnshadeWindow(wwin
);
345 if (directions
& MAX_HORIZONTAL
) {
346 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
347 new_x
= usableArea
.x1
;
348 } else if (directions
& MAX_LEFTHALF
) {
349 new_width
= half_scr_width
- adj_size
;
350 new_x
= usableArea
.x1
;
351 } else if (directions
& MAX_RIGHTHALF
) {
352 new_width
= half_scr_width
- adj_size
;
353 new_x
= usableArea
.x1
+ half_scr_width
;
355 new_x
= wwin
->frame_x
;
356 new_width
= wwin
->frame
->core
->width
;
359 if (directions
& MAX_VERTICAL
) {
360 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
361 new_y
= usableArea
.y1
;
362 if (WFLAGP(wwin
, full_maximize
)) {
363 new_y
-= wwin
->frame
->top_width
;
364 new_height
+= wwin
->frame
->bottom_width
- 1;
367 new_y
= wwin
->frame_y
;
368 new_height
= wwin
->frame
->core
->height
;
371 if (!WFLAGP(wwin
, full_maximize
)) {
372 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
375 if (directions
& MAX_MAXIMUS
) {
376 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
377 new_width
-= adj_size
;
378 new_height
-= adj_size
;
379 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
380 new_y
-= wwin
->frame
->top_width
;
381 new_height
+= wwin
->frame
->top_width
- 1;
385 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
387 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
388 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
390 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
392 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
394 /* set maximization state */
395 wwin
->flags
.maximized
= directions
;
399 * Maximus: tiled maximization (maximize without overlapping other windows)
401 * The window to be maximized will be denoted by w_0 (sub-index zero)
402 * while the windows which will stop the maximization of w_0 are denoted by w_j.
404 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
405 unsigned int *new_width
, unsigned int *new_height
)
408 int x_0
= wwin
->frame_x
;
409 int y_0
= wwin
->frame_y
;
410 int width_0
= wwin
->frame
->core
->width
;
411 int height_0
= wwin
->frame
->core
->height
;
412 int bottom_0
= y_0
+ height_0
;
413 int right_border_0
= x_0
+ width_0
;
414 int new_x_0
, new_y_0
, new_bottom_0
, new_right_border_0
, new_height_0
;
415 int x_j
, y_j
, width_j
, height_j
, bottom_j
, top_j
, right_border_j
;
416 int x_intsect
, y_intsect
;
417 short int tbar_height_0
= 0, rbar_height_0
= 0;
418 short int bd_width_0
= 0;
419 short int adjust_height
;
421 /* Try to fully maximize first, then readjust later */
422 new_x_0
= usableArea
.x1
;
423 new_y_0
= usableArea
.y1
;
424 new_bottom_0
= usableArea
.y2
;
425 new_right_border_0
= usableArea
.x2
;
427 if (HAS_TITLEBAR(wwin
))
428 tbar_height_0
= TITLEBAR_HEIGHT
;
429 if (HAS_RESIZEBAR(wwin
))
430 rbar_height_0
= RESIZEBAR_HEIGHT
;
431 if (HAS_BORDER(wwin
))
432 bd_width_0
= FRAME_BORDER_WIDTH
;
434 /* the length to be subtracted if w_0 has titlebar, etc */
435 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
438 /* The focused window is always the last in the list */
440 /* ignore windows in other workspaces etc */
441 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
442 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
449 * Set the w_j window coordinates. It is convenient
450 * to not use "corrected" sizes for width and height,
451 * otherwise bottom_j and right_border_j would be
456 width_j
= tmp
->frame
->core
->width
;
457 height_j
= tmp
->frame
->core
->height
;
458 bottom_j
= y_j
+ height_j
;
460 right_border_j
= x_j
+ width_j
;
462 /* Try to maximize in the y direction first */
463 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
464 if (x_intsect
!= 0) {
465 /* TODO: Consider the case when coords are equal */
466 if (bottom_j
< y_0
&& bottom_j
> new_y_0
) {
467 /* w_0 is below the bottom of w_j */
468 new_y_0
= bottom_j
+ 1;
470 if (bottom_0
< top_j
&& top_j
< new_bottom_0
) {
471 /* The bottom of w_0 is above the top of w_j */
472 new_bottom_0
= top_j
- 1;
479 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
480 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
486 /* set the w_j window coordinates */
489 width_j
= tmp
->frame
->core
->width
;
490 height_j
= tmp
->frame
->core
->height
;
491 bottom_j
= y_j
+ height_j
;
493 right_border_j
= x_j
+ width_j
;
496 * Use the updated y coordinates from the above step to account
497 * the possibility that the new value of y_0 will have different
498 * intersections with w_j
500 new_height_0
= new_bottom_0
- new_y_0
- adjust_height
;
501 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
502 if (y_intsect
!= 0) {
503 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
504 /* w_0 is completely to the right of w_j */
505 new_x_0
= right_border_j
+ 1;
507 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
508 /* w_0 is completely to the left of w_j */
509 new_right_border_0
= x_j
- 1;
514 /* xcalc needs -7 here, but other apps don't */
515 new_height_0
= new_bottom_0
- new_y_0
- adjust_height
- 1;
518 *new_height
= new_height_0
;
519 *new_width
= new_right_border_0
- new_x_0
;
522 void wUnmaximizeWindow(WWindow
*wwin
)
525 WMRect old_geom_rect
;
529 if (!wwin
->flags
.maximized
)
532 if (wwin
->flags
.shaded
) {
533 wwin
->flags
.skip_next_animation
= 1;
534 wUnshadeWindow(wwin
);
536 /* Use old coordinates if they are set, current values otherwise */
537 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
538 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
539 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
540 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
541 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
542 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
543 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
545 wwin
->flags
.maximized
= 0;
546 wWindowConfigure(wwin
, x
, y
, w
, h
);
548 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
551 void wFullscreenWindow(WWindow
*wwin
)
556 if (wwin
->flags
.fullscreen
)
559 wwin
->flags
.fullscreen
= True
;
561 wWindowConfigureBorders(wwin
);
563 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
565 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
566 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
567 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
568 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
570 head
= wGetHeadForWindow(wwin
);
571 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
572 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
574 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
577 void wUnfullscreenWindow(WWindow
*wwin
)
579 if (!wwin
->flags
.fullscreen
)
582 wwin
->flags
.fullscreen
= False
;
584 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
585 if (WFLAGP(wwin
, sunken
)) {
586 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
587 } else if (WFLAGP(wwin
, floating
)) {
588 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
590 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
594 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
595 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
597 wWindowConfigureBorders(wwin
);
599 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
600 wFrameWindowPaint(wwin->frame);
603 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
607 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
609 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
610 float cx
, cy
, cw
, ch
;
611 float xstep
, ystep
, wstep
, hstep
;
614 float angle
, final_angle
, delta
;
616 xstep
= (float)(fx
- x
) / steps
;
617 ystep
= (float)(fy
- y
) / steps
;
618 wstep
= (float)(fw
- w
) / steps
;
619 hstep
= (float)(fh
- h
) / steps
;
626 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
627 delta
= (float)(final_angle
/ FRAMES
);
628 for (angle
= 0;; angle
+= delta
) {
629 if (angle
> final_angle
)
632 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
633 dch
= (ch
/ 2) * cos(angle
);
634 midy
= cy
+ (ch
/ 2);
636 points
[0].x
= cx
+ dx
;
637 points
[0].y
= midy
- dch
;
638 points
[1].x
= cx
+ cw
- dx
;
639 points
[1].y
= points
[0].y
;
640 points
[2].x
= cx
+ cw
+ dx
;
641 points
[2].y
= midy
+ dch
;
642 points
[3].x
= cx
- dx
;
643 points
[3].y
= points
[2].y
;
644 points
[4].x
= points
[0].x
;
645 points
[4].y
= points
[0].y
;
648 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
650 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
652 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
658 if (angle
>= final_angle
)
668 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
670 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
671 float cx
, cy
, cw
, ch
;
672 float xstep
, ystep
, wstep
, hstep
;
674 float angle
, final_angle
, a
, d
, delta
;
681 xstep
= (float)(fx
- x
) / steps
;
682 ystep
= (float)(fy
- y
) / steps
;
683 wstep
= (float)(fw
- w
) / steps
;
684 hstep
= (float)(fh
- h
) / steps
;
691 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
692 delta
= (float)(final_angle
/ FRAMES
);
693 for (angle
= 0;; angle
+= delta
) {
694 if (angle
> final_angle
)
698 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
700 points
[0].x
= cx
+ cos(angle
- a
) * d
;
701 points
[0].y
= cy
+ sin(angle
- a
) * d
;
702 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
703 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
704 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
705 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
706 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
707 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
708 points
[4].x
= cx
+ cos(angle
- a
) * d
;
709 points
[4].y
= cy
+ sin(angle
- a
) * d
;
711 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
713 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
715 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
721 if (angle
>= final_angle
)
730 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
732 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
733 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
734 float xstep
, ystep
, wstep
, hstep
;
737 xstep
= (float)(fx
- x
) / steps
;
738 ystep
= (float)(fy
- y
) / steps
;
739 wstep
= (float)(fw
- w
) / steps
;
740 hstep
= (float)(fh
- h
) / steps
;
742 for (j
= 0; j
< FRAMES
; j
++) {
749 for (i
= 0; i
< steps
; i
++) {
750 for (j
= 0; j
< FRAMES
; j
++) {
751 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
752 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
755 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
757 for (j
= 0; j
< FRAMES
; j
++) {
758 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
759 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
760 if (j
< FRAMES
- 1) {
774 for (j
= 0; j
< FRAMES
; j
++) {
775 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
778 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
780 for (j
= 0; j
< FRAMES
; j
++) {
781 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
789 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
791 int style
= wPreferences
.iconification_style
; /* Catch the value */
794 if (style
== WIS_NONE
)
797 if (style
== WIS_RANDOM
) {
803 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
805 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
808 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
810 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
814 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
816 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
820 #endif /* ANIMATIONS */
822 static void flushExpose()
826 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
827 WMHandleEvent(&tmpev
);
831 static void unmapTransientsFor(WWindow
*wwin
)
835 tmp
= wwin
->screen_ptr
->focused_window
;
837 /* unmap the transients for this transient */
838 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
839 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
840 unmapTransientsFor(tmp
);
841 tmp
->flags
.miniaturized
= 1;
842 if (!tmp
->flags
.shaded
) {
845 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
848 if (!tmp->flags.shaded)
850 wClientSetState(tmp
, IconicState
, None
);
852 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
858 static void mapTransientsFor(WWindow
*wwin
)
862 tmp
= wwin
->screen_ptr
->focused_window
;
864 /* recursively map the transients for this transient */
865 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
866 && tmp
->icon
== NULL
) {
867 mapTransientsFor(tmp
);
868 tmp
->flags
.miniaturized
= 0;
869 if (!tmp
->flags
.shaded
) {
872 XMapWindow(dpy
, tmp
->frame
->core
->window
);
874 tmp
->flags
.semi_focused
= 0;
876 if (!tmp->flags.shaded)
878 wClientSetState(tmp
, NormalState
, None
);
880 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
886 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
893 /* hackish way to detect transient_for cycle */
894 i
= wwin
->screen_ptr
->window_count
+ 1;
896 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
897 wwin
= wWindowFor(wwin
->transient_for
);
900 if (i
== 0 && wwin
) {
901 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
908 void wIconifyWindow(WWindow
* wwin
)
910 XWindowAttributes attribs
;
913 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
914 /* the window doesn't exist anymore */
918 if (wwin
->flags
.miniaturized
) {
922 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
923 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
925 if (owner
&& owner
->flags
.miniaturized
)
929 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
931 /* if the window is in another workspace, simplify process */
933 /* icon creation may take a while */
934 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
935 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
936 GrabModeAsync
, None
, None
, CurrentTime
);
939 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
940 if (!wwin
->flags
.icon_moved
) {
941 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
943 wwin
->icon
= wIconCreate(wwin
);
945 wwin
->icon
->mapped
= 1;
948 wwin
->flags
.miniaturized
= 1;
949 wwin
->flags
.mapped
= 0;
951 /* unmap transients */
953 unmapTransientsFor(wwin
);
956 XUngrabPointer(dpy
, CurrentTime
);
958 /* let all Expose events arrive so that we can repaint
959 * something before the animation starts (and the server is grabbed) */
962 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
963 wClientSetState(wwin
, IconicState
, None
);
965 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
969 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
970 && !wPreferences
.no_animations
) {
973 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
976 iw
= wwin
->icon
->core
->width
;
977 ih
= wwin
->icon
->core
->height
;
979 if (wwin
->flags
.net_handle_icon
) {
987 iw
= wwin
->screen_ptr
->scr_width
;
988 ih
= wwin
->screen_ptr
->scr_height
;
991 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
992 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
997 wwin
->flags
.skip_next_animation
= 0;
999 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1000 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1001 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1003 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1005 AddToStackList(wwin
->icon
->core
);
1007 wLowerFrame(wwin
->icon
->core
);
1011 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1014 * It doesn't seem to be working and causes button event hangup
1015 * when deiconifying a transient window.
1016 setupIconGrabs(wwin->icon);
1018 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1019 && wPreferences
.focus_mode
== WKF_CLICK
) {
1024 if (!WFLAGP(tmp
, no_focusable
)
1025 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1026 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1030 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1031 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1032 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1035 if (!wwin
->screen_ptr
->flags
.startup
) {
1036 /* Catch up with events not processed while animation was running */
1037 Window clientwin
= wwin
->client_win
;
1039 ProcessPendingEvents();
1041 /* the window can disappear while ProcessPendingEvents() runs */
1042 if (!wWindowFor(clientwin
)) {
1049 /* maybe we want to do this regardless of net_handle_icon
1050 * it seems to me we might break behaviour this way.
1052 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1053 && !wwin
->flags
.net_handle_icon
)
1054 wIconSelect(wwin
->icon
);
1056 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1058 if (wPreferences
.auto_arrange_icons
)
1059 wArrangeIcons(wwin
->screen_ptr
, True
);
1062 void wDeiconifyWindow(WWindow
*wwin
)
1064 /* Let's avoid changing workspace while deiconifying */
1065 ignore_wks_change
= 1;
1067 /* we're hiding for show_desktop */
1068 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1069 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1072 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1074 if (!wwin
->flags
.miniaturized
)
1077 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1078 WWindow
*owner
= recursiveTransientFor(wwin
);
1080 if (owner
&& owner
->flags
.miniaturized
) {
1081 wDeiconifyWindow(owner
);
1082 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1083 wRaiseFrame(wwin
->frame
->core
);
1088 wwin
->flags
.miniaturized
= 0;
1090 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1091 wwin
->flags
.mapped
= 1;
1094 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1095 /* maybe we want to do this regardless of net_handle_icon
1096 * it seems to me we might break behaviour this way.
1098 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1099 && wwin
->icon
!= NULL
) {
1100 if (wwin
->icon
->selected
)
1101 wIconSelect(wwin
->icon
);
1103 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1107 /* if the window is in another workspace, do it silently */
1108 if (!netwm_hidden
) {
1110 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1111 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1114 if (!wPreferences
.disable_miniwindows
1115 && !wwin
->flags
.net_handle_icon
) {
1118 iw
= wwin
->icon
->core
->width
;
1119 ih
= wwin
->icon
->core
->height
;
1121 if (wwin
->flags
.net_handle_icon
) {
1129 iw
= wwin
->screen_ptr
->scr_width
;
1130 ih
= wwin
->screen_ptr
->scr_height
;
1133 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1134 wwin
->frame_x
, wwin
->frame_y
,
1135 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1137 #endif /* ANIMATIONS */
1138 wwin
->flags
.skip_next_animation
= 0;
1140 if (!wwin
->flags
.shaded
) {
1141 XMapWindow(dpy
, wwin
->client_win
);
1143 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1144 wRaiseFrame(wwin
->frame
->core
);
1145 if (!wwin
->flags
.shaded
) {
1146 wClientSetState(wwin
, NormalState
, None
);
1148 mapTransientsFor(wwin
);
1151 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1152 && !wwin
->flags
.net_handle_icon
) {
1153 RemoveFromStackList(wwin
->icon
->core
);
1154 /* removeIconGrabs(wwin->icon); */
1155 wIconDestroy(wwin
->icon
);
1159 if (!netwm_hidden
) {
1162 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1165 if (!wwin
->screen_ptr
->flags
.startup
) {
1166 /* Catch up with events not processed while animation was running */
1167 Window clientwin
= wwin
->client_win
;
1169 ProcessPendingEvents();
1171 /* the window can disappear while ProcessPendingEvents() runs */
1172 if (!wWindowFor(clientwin
)) {
1179 if (wPreferences
.auto_arrange_icons
) {
1180 wArrangeIcons(wwin
->screen_ptr
, True
);
1183 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1185 /* In case we were shaded and iconified, also unshade */
1187 wUnshadeWindow(wwin
);
1189 ignore_wks_change
= 0;
1192 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1194 if (wwin
->flags
.miniaturized
) {
1196 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1197 wwin
->icon
->mapped
= 0;
1199 wwin
->flags
.hidden
= 1;
1201 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1205 if (wwin
->flags
.inspector_open
) {
1206 wHideInspectorForWindow(wwin
);
1209 wwin
->flags
.hidden
= 1;
1212 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1216 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1217 !wwin
->flags
.skip_next_animation
&& animate
) {
1218 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1219 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1220 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1223 wwin
->flags
.skip_next_animation
= 0;
1225 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1228 void wHideOtherApplications(WWindow
*awin
)
1235 wwin
= awin
->screen_ptr
->focused_window
;
1239 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1240 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1241 && !wwin
->flags
.internal_window
1242 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1244 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1245 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1246 wwin
->flags
.skip_next_animation
= 1;
1247 wIconifyWindow(wwin
);
1249 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1250 tapp
= wApplicationOf(wwin
->main_window
);
1252 tapp
->flags
.skip_next_animation
= 1;
1253 wHideApplication(tapp
);
1255 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1256 wwin
->flags
.skip_next_animation
= 1;
1257 wIconifyWindow(wwin
);
1265 wSetFocusTo(awin->screen_ptr, awin);
1269 void wHideApplication(WApplication
*wapp
)
1277 wwarning("trying to hide a non grouped window");
1280 if (!wapp
->main_window_desc
) {
1281 wwarning("group leader not found for window group");
1284 scr
= wapp
->main_window_desc
->screen_ptr
;
1286 wlist
= scr
->focused_window
;
1290 if (wlist
->main_window
== wapp
->main_window
)
1291 wapp
->last_focused
= wlist
;
1293 wapp
->last_focused
= NULL
;
1295 animate
= !wapp
->flags
.skip_next_animation
;
1298 if (wlist
->main_window
== wapp
->main_window
) {
1299 if (wlist
->flags
.focused
) {
1302 if (wapp
->app_icon
) {
1303 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1304 wapp
->app_icon
->y_pos
, wlist
, animate
);
1308 wlist
= wlist
->prev
;
1311 wapp
->flags
.skip_next_animation
= 0;
1314 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1315 wlist
= scr
->focused_window
;
1317 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1318 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1320 wlist
= wlist
->prev
;
1322 wSetFocusTo(scr
, wlist
);
1324 wSetFocusTo(scr
, NULL
);
1328 wapp
->flags
.hidden
= 1;
1330 if (wPreferences
.auto_arrange_icons
) {
1331 wArrangeIcons(scr
, True
);
1335 wAppIconPaint(wapp
->app_icon
);
1339 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1341 if (bringToCurrentWS
)
1342 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1344 wwin
->flags
.hidden
= 0;
1347 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1348 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1349 icon
->core
->width
, icon
->core
->height
,
1350 wwin
->frame_x
, wwin
->frame_y
,
1351 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1354 wwin
->flags
.skip_next_animation
= 0;
1355 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1356 XMapWindow(dpy
, wwin
->client_win
);
1357 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1358 wClientSetState(wwin
, NormalState
, None
);
1359 wwin
->flags
.mapped
= 1;
1360 wRaiseFrame(wwin
->frame
->core
);
1362 if (wwin
->flags
.inspector_open
) {
1363 wUnhideInspectorForWindow(wwin
);
1366 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1369 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1372 WWindow
*wlist
, *next
;
1373 WWindow
*focused
= NULL
;
1379 scr
= wapp
->main_window_desc
->screen_ptr
;
1380 wlist
= scr
->focused_window
;
1384 /* goto beginning of list */
1386 wlist
= wlist
->prev
;
1388 animate
= !wapp
->flags
.skip_next_animation
;
1393 if (wlist
->main_window
== wapp
->main_window
) {
1394 if (wlist
->flags
.focused
)
1396 else if (!focused
|| !focused
->flags
.focused
)
1399 if (wlist
->flags
.miniaturized
) {
1400 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1401 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1402 if (!wlist
->icon
->mapped
) {
1405 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1406 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1407 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1411 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1412 wlist
->icon
->mapped
= 1;
1414 wRaiseFrame(wlist
->icon
->core
);
1416 if (bringToCurrentWS
)
1417 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1418 wlist
->flags
.hidden
= 0;
1419 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1420 wDeiconifyWindow(wlist
);
1422 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1423 } else if (wlist
->flags
.shaded
) {
1424 if (bringToCurrentWS
)
1425 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1426 wlist
->flags
.hidden
= 0;
1427 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1428 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1430 wUnshadeWindow(wlist
);
1431 wRaiseFrame(wlist
->frame
->core
);
1434 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1435 } else if (wlist
->flags
.hidden
) {
1436 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1437 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1440 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1441 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1443 wRaiseFrame(wlist
->frame
->core
);
1449 wapp
->flags
.skip_next_animation
= 0;
1450 wapp
->flags
.hidden
= 0;
1452 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1453 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1454 wSetFocusTo(scr
, wapp
->last_focused
);
1455 } else if (focused
) {
1456 wSetFocusTo(scr
, focused
);
1458 wapp
->last_focused
= NULL
;
1459 if (wPreferences
.auto_arrange_icons
) {
1460 wArrangeIcons(scr
, True
);
1463 wAppIconPaint(wapp
->app_icon
);
1467 void wShowAllWindows(WScreen
*scr
)
1469 WWindow
*wwin
, *old_foc
;
1472 old_foc
= wwin
= scr
->focused_window
;
1474 if (!wwin
->flags
.internal_window
&&
1475 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1476 if (wwin
->flags
.miniaturized
) {
1477 wwin
->flags
.skip_next_animation
= 1;
1478 wDeiconifyWindow(wwin
);
1479 } else if (wwin
->flags
.hidden
) {
1480 wapp
= wApplicationOf(wwin
->main_window
);
1482 wUnhideApplication(wapp
, False
, False
);
1484 wwin
->flags
.skip_next_animation
= 1;
1485 wDeiconifyWindow(wwin
);
1491 wSetFocusTo(scr
, old_foc
);
1492 /*wRaiseFrame(old_foc->frame->core); */
1495 void wRefreshDesktop(WScreen
*scr
)
1498 XSetWindowAttributes attr
;
1500 attr
.backing_store
= NotUseful
;
1501 attr
.save_under
= False
;
1502 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1503 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1504 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1505 XMapRaised(dpy
, win
);
1506 XDestroyWindow(dpy
, win
);
1510 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1516 const int heads
= wXineramaHeads(scr
);
1519 int pf
; /* primary axis */
1520 int sf
; /* secondary axis */
1524 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1530 int isize
= wPreferences
.icon_size
;
1532 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1534 for (head
= 0; head
< heads
; ++head
) {
1535 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1536 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1537 vars
[head
].pi
= vars
[head
].si
= 0;
1538 vars
[head
].sx1
= rect
.pos
.x
;
1539 vars
[head
].sy1
= rect
.pos
.y
;
1540 vars
[head
].sw
= rect
.size
.width
;
1541 vars
[head
].sh
= rect
.size
.height
;
1542 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1543 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1544 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1545 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1546 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1547 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1549 /* icon yard boundaries */
1550 if (wPreferences
.icon_yard
& IY_VERT
) {
1551 vars
[head
].pf
= vars
[head
].fullH
;
1552 vars
[head
].sf
= vars
[head
].fullW
;
1554 vars
[head
].pf
= vars
[head
].fullW
;
1555 vars
[head
].sf
= vars
[head
].fullH
;
1557 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1558 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1561 vars
[head
].xo
= vars
[head
].sx1
;
1564 if (wPreferences
.icon_yard
& IY_TOP
) {
1565 vars
[head
].yo
= vars
[head
].sy1
;
1568 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1573 #define X ((wPreferences.icon_yard & IY_VERT) \
1574 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1575 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1577 #define Y ((wPreferences.icon_yard & IY_VERT) \
1578 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1579 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1581 /* arrange application icons */
1582 aicon
= scr
->app_icon_list
;
1583 /* reverse them to avoid unnecessarily sliding of icons */
1584 while (aicon
&& aicon
->next
)
1585 aicon
= aicon
->next
;
1588 if (!aicon
->docked
) {
1589 /* CHECK: can icon be NULL here ? */
1590 /* The intention here is to place the AppIcon on the head that
1591 * contains most of the applications _main_ window. */
1592 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1594 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1596 if (!wPreferences
.no_animations
) {
1597 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1599 #endif /* ANIMATIONS */
1601 wAppIconMove(aicon
, X
, Y
);
1603 if (vars
[head
].pi
>= vars
[head
].pf
) {
1608 aicon
= aicon
->prev
;
1611 /* arrange miniwindows */
1612 wwin
= scr
->focused_window
;
1613 /* reverse them to avoid unnecessarily shuffling */
1614 while (wwin
&& wwin
->prev
)
1618 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1619 (wwin
->frame
->workspace
== scr
->current_workspace
||
1620 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1622 head
= wGetHeadForWindow(wwin
);
1624 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1625 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1627 if (wPreferences
.no_animations
) {
1628 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1630 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1631 wwin
->icon_y
, X
, Y
);
1634 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1635 #endif /* ANIMATIONS */
1641 if (vars
[head
].pi
>= vars
[head
].pf
) {
1648 wwin
->flags
.icon_moved
= 0;
1650 /* we reversed the order, so we use next */
1657 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1659 WScreen
*scr
= wwin
->screen_ptr
;
1662 wwin
->flags
.selected
= 1;
1663 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1665 if (!HAS_BORDER(wwin
)) {
1666 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1669 if (!scr
->selected_windows
)
1670 scr
->selected_windows
= WMCreateArray(4);
1671 WMAddToArray(scr
->selected_windows
, wwin
);
1673 wwin
->flags
.selected
= 0;
1674 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1676 if (!HAS_BORDER(wwin
)) {
1677 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1680 if (scr
->selected_windows
) {
1681 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1686 void wMakeWindowVisible(WWindow
*wwin
)
1688 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1689 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1691 if (wwin
->flags
.shaded
) {
1692 wUnshadeWindow(wwin
);
1694 if (wwin
->flags
.hidden
) {
1697 app
= wApplicationOf(wwin
->main_window
);
1699 /* trick to get focus to this window */
1700 app
->last_focused
= wwin
;
1701 wUnhideApplication(app
, False
, False
);
1704 if (wwin
->flags
.miniaturized
) {
1705 wDeiconifyWindow(wwin
);
1707 if (!WFLAGP(wwin
, no_focusable
))
1708 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1709 wRaiseFrame(wwin
->frame
->core
);
1714 * Do the animation while shading (called with what = SHADE)
1715 * or unshading (what = UNSHADE).
1718 static void shade_animate(WWindow
*wwin
, Bool what
)
1721 time_t time0
= time(NULL
);
1723 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1728 if (!wwin
->screen_ptr
->flags
.startup
) {
1729 /* do the shading animation */
1730 h
= wwin
->frame
->core
->height
;
1731 s
= h
/ SHADE_STEPS
;
1734 w
= wwin
->frame
->core
->width
;
1735 y
= wwin
->frame
->top_width
;
1736 while (h
> wwin
->frame
->top_width
+ 1) {
1737 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1738 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1741 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1744 if (SHADE_DELAY
> 0) {
1745 wusleep(SHADE_DELAY
* 1000L);
1752 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1757 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1758 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1759 s
= abs(y
) / SHADE_STEPS
;
1762 w
= wwin
->frame
->core
->width
;
1763 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1765 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1766 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1767 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1769 if (SHADE_DELAY
> 0) {
1770 wusleep(SHADE_DELAY
* 2000L / 3);
1777 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1781 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);