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 ******/
53 int ignore_wks_change
= 0;
54 extern Time LastTimestamp
;
55 extern Time LastFocusChange
;
57 extern Cursor wCursor
[WCUR_LAST
];
59 extern WPreferences wPreferences
;
61 extern Atom _XA_WM_TAKE_FOCUS
;
63 extern void ProcessPendingEvents();
64 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
66 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
67 unsigned int *new_width
, unsigned int *new_height
);
68 static void save_old_geometry(WWindow
*wwin
);
70 /******* Local Variables *******/
76 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
77 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
78 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
79 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
80 SHADE_STEPS_US
, SHADE_DELAY_US
}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
87 static int compareTimes(Time t1
, Time t2
)
93 return (diff
< 60000) ? 1 : -1;
97 static void shade_animate(WWindow
*wwin
, Bool what
);
99 static void shade_animate(WWindow
*wwin
, Bool what
) { }
103 *----------------------------------------------------------------------
105 * Changes the window focus to the one passed as argument.
106 * If the window to focus is not already focused, it will be brought
107 * to the head of the list of windows. Previously focused window is
111 * Window list may be reordered and the window focus is changed.
113 *----------------------------------------------------------------------
115 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
117 static WScreen
*old_scr
= NULL
;
119 WWindow
*old_focused
;
120 WWindow
*focused
= scr
->focused_window
;
121 Time timestamp
= LastTimestamp
;
122 WApplication
*oapp
= NULL
, *napp
= NULL
;
125 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
130 old_focused
= old_scr
->focused_window
;
132 LastFocusChange
= timestamp
;
135 oapp
= wApplicationOf(old_focused
->main_window
);
138 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
140 wWindowUnfocus(old_focused
);
143 wAppMenuUnmap(oapp
->menu
);
145 wApplicationDeactivate(oapp
);
149 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
151 } else if (old_scr
!= scr
&& old_focused
) {
152 wWindowUnfocus(old_focused
);
155 wasfocused
= wwin
->flags
.focused
;
156 napp
= wApplicationOf(wwin
->main_window
);
158 /* remember last workspace where the app has been */
160 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
161 napp
->last_workspace
= wwin
->frame
->workspace
;
164 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
165 /* install colormap if colormap mode is lock mode */
166 if (wPreferences
.colormap_mode
== WCM_CLICK
)
167 wColormapInstallForWindow(scr
, wwin
);
169 /* set input focus */
170 switch (wwin
->focus_mode
) {
172 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
176 case WFM_LOCALLY_ACTIVE
:
177 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
180 case WFM_GLOBALLY_ACTIVE
:
184 if (wwin
->protocols
.TAKE_FOCUS
) {
185 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
189 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
191 if (WFLAGP(wwin
, no_focusable
))
194 /* if this is not the focused window focus it */
195 if (focused
!= wwin
) {
196 /* change the focus window list order */
198 wwin
->prev
->next
= wwin
->next
;
201 wwin
->next
->prev
= wwin
->prev
;
203 wwin
->prev
= focused
;
204 focused
->next
= wwin
;
206 scr
->focused_window
= wwin
;
208 if (oapp
&& oapp
!= napp
) {
209 wAppMenuUnmap(oapp
->menu
);
211 wApplicationDeactivate(oapp
);
216 wWindowFocus(wwin
, focused
);
218 if (napp
&& !wasfocused
) {
220 wUserMenuRefreshInstances(napp
->menu
, wwin
);
221 #endif /* USER_MENU */
223 if (wwin
->flags
.mapped
)
224 wAppMenuMap(napp
->menu
, wwin
);
226 wApplicationActivate(napp
);
234 void wShadeWindow(WWindow
*wwin
)
237 if (wwin
->flags
.shaded
)
240 XLowerWindow(dpy
, wwin
->client_win
);
241 shade_animate(wwin
, SHADE
);
243 wwin
->flags
.skip_next_animation
= 0;
244 wwin
->flags
.shaded
= 1;
245 wwin
->flags
.mapped
= 0;
246 /* prevent window withdrawal when getting UnmapNotify */
247 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
248 XUnmapWindow(dpy
, wwin
->client_win
);
249 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
251 /* for the client it's just like iconification */
252 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
254 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
255 wWindowSynthConfigureNotify(wwin
);
258 wClientSetState(wwin, IconicState, None);
261 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
264 if (!wwin
->screen_ptr
->flags
.startup
) {
265 /* Catch up with events not processed while animation was running */
266 ProcessPendingEvents();
271 void wUnshadeWindow(WWindow
*wwin
)
274 if (!wwin
->flags
.shaded
)
277 wwin
->flags
.shaded
= 0;
278 wwin
->flags
.mapped
= 1;
279 XMapWindow(dpy
, wwin
->client_win
);
281 shade_animate(wwin
, UNSHADE
);
283 wwin
->flags
.skip_next_animation
= 0;
284 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
285 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
287 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
288 wWindowSynthConfigureNotify(wwin
);
291 wClientSetState(wwin, NormalState, None);
293 /* if the window is focused, set the focus again as it was disabled during
295 if (wwin
->flags
.focused
)
296 wSetFocusTo(wwin
->screen_ptr
, wwin
);
298 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
301 /* Set the old coordinates using the current values */
302 static void save_old_geometry(WWindow
*wwin
)
304 wwin
->old_geometry
.width
= wwin
->client
.width
;
305 wwin
->old_geometry
.height
= wwin
->client
.height
;
306 wwin
->old_geometry
.x
= wwin
->frame_x
;
307 wwin
->old_geometry
.y
= wwin
->frame_y
;
310 void wMaximizeWindow(WWindow
* wwin
, int directions
)
313 unsigned int new_width
, new_height
, half_scr_width
;
314 WArea usableArea
, totalArea
;
318 if (!IS_RESIZABLE(wwin
))
321 if (!HAS_BORDER(wwin
))
324 /* the size to adjust the geometry */
325 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
327 /* save old coordinates before we change the current values */
328 save_old_geometry(wwin
);
332 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
333 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
334 usableArea
= totalArea
;
336 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
337 WScreen
*scr
= wwin
->screen_ptr
;
340 if (directions
& MAX_KEYBOARD
)
341 head
= wGetHeadForWindow(wwin
);
343 head
= wGetHeadForPointerLocation(scr
);
345 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
348 /* Only save directions, not kbd or xinerama hints */
349 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
351 if (WFLAGP(wwin
, full_maximize
)) {
352 usableArea
= totalArea
;
354 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
356 if (wwin
->flags
.shaded
) {
357 wwin
->flags
.skip_next_animation
= 1;
358 wUnshadeWindow(wwin
);
361 if (directions
& MAX_HORIZONTAL
) {
362 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
363 new_x
= usableArea
.x1
;
364 } else if (directions
& MAX_LEFTHALF
) {
365 new_width
= half_scr_width
- adj_size
;
366 new_x
= usableArea
.x1
;
367 } else if (directions
& MAX_RIGHTHALF
) {
368 new_width
= half_scr_width
- adj_size
;
369 new_x
= usableArea
.x1
+ half_scr_width
;
371 new_x
= wwin
->frame_x
;
372 new_width
= wwin
->frame
->core
->width
;
375 if (directions
& MAX_VERTICAL
) {
376 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
377 new_y
= usableArea
.y1
;
378 if (WFLAGP(wwin
, full_maximize
)) {
379 new_y
-= wwin
->frame
->top_width
;
380 new_height
+= wwin
->frame
->bottom_width
- 1;
383 new_y
= wwin
->frame_y
;
384 new_height
= wwin
->frame
->core
->height
;
387 if (!WFLAGP(wwin
, full_maximize
)) {
388 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
391 if (directions
& MAX_MAXIMUS
) {
392 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
393 new_width
-= adj_size
;
394 new_height
-= adj_size
;
395 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
396 new_y
-= wwin
->frame
->top_width
;
397 new_height
+= wwin
->frame
->top_width
- 1;
401 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
403 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
404 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
406 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
408 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
410 /* set maximization state */
411 wwin
->flags
.maximized
= directions
;
415 * Maximus: tiled maximization (maximize without overlapping other windows)
417 * The window to be maximized will be denoted by w_0 (sub-index zero)
418 * while the windows which will stop the maximization of w_0 are denoted by w_j.
420 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
421 unsigned int *new_width
, unsigned int *new_height
)
424 int x_0
= wwin
->frame_x
;
425 int y_0
= wwin
->frame_y
;
426 int width_0
= wwin
->frame
->core
->width
;
427 int height_0
= wwin
->frame
->core
->height
;
428 int botton_0
= y_0
+ height_0
;
429 int right_border_0
= x_0
+ width_0
;
430 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
431 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
432 int x_intsect
, y_intsect
;
433 short int tbar_height_0
= 0, rbar_height_0
= 0;
434 short int bd_width_0
= 0, bd_width_j
= 0;
435 short int adjust_height
;
437 /* Try to fully maximize first, then readjust later */
438 new_x_0
= usableArea
.x1
;
439 new_y_0
= usableArea
.y1
;
440 new_botton_0
= usableArea
.y2
;
441 new_right_border_0
= usableArea
.x2
;
443 if (HAS_TITLEBAR(wwin
))
444 tbar_height_0
= TITLEBAR_HEIGHT
;
445 if (HAS_RESIZEBAR(wwin
))
446 rbar_height_0
= RESIZEBAR_HEIGHT
;
447 if (HAS_BORDER(wwin
))
448 bd_width_0
= FRAME_BORDER_WIDTH
;
450 /* the lengths to be subtracted if w_0 has titlebar, etc */
451 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
454 /* The focused window is always the last in the list */
456 /* ignore windows in other workspaces etc */
457 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
458 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
465 bd_width_j
= FRAME_BORDER_WIDTH
;
470 * Set the w_j window coordinates. It is convenient
471 * to not use "corrected" sizes for width and height,
472 * otherwise bottom_j and right_border_j would be
475 x_j
= tmp
->frame_x
- bd_width_j
;
476 y_j
= tmp
->frame_y
- bd_width_j
;
477 width_j
= tmp
->frame
->core
->width
;
478 height_j
= tmp
->frame
->core
->height
;
479 botton_j
= y_j
+ height_j
+ bd_width_j
;
480 top_j
= y_j
- bd_width_j
;
481 right_border_j
= x_j
+ width_j
+ bd_width_j
;
483 /* Try to maximize in the y direction first */
484 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
485 if (x_intsect
!= 0) {
486 /* TODO: Consider the case when coords are equal */
487 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
488 /* w_0 is below the botton of w_j */
491 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
492 /* The botton of w_0 is above the top of w_j */
493 new_botton_0
= top_j
;
500 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
501 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
508 bd_width_j
= FRAME_BORDER_WIDTH
;
512 /* set the w_j window coordinates */
513 x_j
= tmp
->frame_x
- bd_width_j
;
514 y_j
= tmp
->frame_y
- bd_width_j
;
515 width_j
= tmp
->frame
->core
->width
;
516 height_j
= tmp
->frame
->core
->height
;
517 botton_j
= y_j
+ height_j
+ bd_width_j
;
518 top_j
= y_j
- bd_width_j
;
519 right_border_j
= x_j
+ width_j
+ bd_width_j
;
522 * Use the updated y coordinates from the above step to account
523 * the possibility that the new value of y_0 will have different
524 * intersections with w_j
526 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
527 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
528 if (y_intsect
!= 0) {
529 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
530 /* w_0 is completely to the right of w_j */
531 new_x_0
= right_border_j
+ 1;
533 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
534 /* w_0 is completely to the left of w_j */
535 new_right_border_0
= x_j
- 1;
540 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
543 *new_height
= new_height_0
;
544 *new_width
= new_right_border_0
- new_x_0
;
547 void wUnmaximizeWindow(WWindow
* wwin
)
550 WMRect old_geom_rect
;
554 if (!wwin
->flags
.maximized
)
557 if (wwin
->flags
.shaded
) {
558 wwin
->flags
.skip_next_animation
= 1;
559 wUnshadeWindow(wwin
);
561 /* Use old coordinates if they are set, current values otherwise */
562 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
563 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
564 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
565 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
566 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
567 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
568 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
570 wwin
->flags
.maximized
= 0;
571 wWindowConfigure(wwin
, x
, y
, w
, h
);
573 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
576 void wFullscreenWindow(WWindow
* wwin
)
581 if (wwin
->flags
.fullscreen
)
584 wwin
->flags
.fullscreen
= True
;
586 wWindowConfigureBorders(wwin
);
588 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
590 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
591 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
592 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
593 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
595 head
= wGetHeadForWindow(wwin
);
596 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
597 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
599 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
602 void wUnfullscreenWindow(WWindow
* wwin
)
604 if (!wwin
->flags
.fullscreen
)
607 wwin
->flags
.fullscreen
= False
;
609 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
610 if (WFLAGP(wwin
, sunken
)) {
611 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
612 } else if (WFLAGP(wwin
, floating
)) {
613 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
615 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
619 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
620 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
622 wWindowConfigureBorders(wwin
);
624 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
625 wFrameWindowPaint(wwin->frame);
628 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
632 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
634 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
635 float cx
, cy
, cw
, ch
;
636 float xstep
, ystep
, wstep
, hstep
;
639 float angle
, final_angle
, delta
;
641 xstep
= (float)(fx
- x
) / steps
;
642 ystep
= (float)(fy
- y
) / steps
;
643 wstep
= (float)(fw
- w
) / steps
;
644 hstep
= (float)(fh
- h
) / steps
;
651 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
652 delta
= (float)(final_angle
/ FRAMES
);
653 for (angle
= 0;; angle
+= delta
) {
654 if (angle
> final_angle
)
657 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
658 dch
= (ch
/ 2) * cos(angle
);
659 midy
= cy
+ (ch
/ 2);
661 points
[0].x
= cx
+ dx
;
662 points
[0].y
= midy
- dch
;
663 points
[1].x
= cx
+ cw
- dx
;
664 points
[1].y
= points
[0].y
;
665 points
[2].x
= cx
+ cw
+ dx
;
666 points
[2].y
= midy
+ dch
;
667 points
[3].x
= cx
- dx
;
668 points
[3].y
= points
[2].y
;
669 points
[4].x
= points
[0].x
;
670 points
[4].y
= points
[0].y
;
673 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
675 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
677 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
683 if (angle
>= final_angle
)
693 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
695 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
696 float cx
, cy
, cw
, ch
;
697 float xstep
, ystep
, wstep
, hstep
;
699 float angle
, final_angle
, a
, d
, delta
;
706 xstep
= (float)(fx
- x
) / steps
;
707 ystep
= (float)(fy
- y
) / steps
;
708 wstep
= (float)(fw
- w
) / steps
;
709 hstep
= (float)(fh
- h
) / steps
;
716 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
717 delta
= (float)(final_angle
/ FRAMES
);
718 for (angle
= 0;; angle
+= delta
) {
719 if (angle
> final_angle
)
723 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
725 points
[0].x
= cx
+ cos(angle
- a
) * d
;
726 points
[0].y
= cy
+ sin(angle
- a
) * d
;
727 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
728 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
729 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
730 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
731 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
732 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
733 points
[4].x
= cx
+ cos(angle
- a
) * d
;
734 points
[4].y
= cy
+ sin(angle
- a
) * d
;
736 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
738 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
740 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
746 if (angle
>= final_angle
)
755 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
757 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
758 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
759 float xstep
, ystep
, wstep
, hstep
;
762 xstep
= (float)(fx
- x
) / steps
;
763 ystep
= (float)(fy
- y
) / steps
;
764 wstep
= (float)(fw
- w
) / steps
;
765 hstep
= (float)(fh
- h
) / steps
;
767 for (j
= 0; j
< FRAMES
; j
++) {
774 for (i
= 0; i
< steps
; i
++) {
775 for (j
= 0; j
< FRAMES
; j
++) {
776 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
777 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
780 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
782 for (j
= 0; j
< FRAMES
; j
++) {
783 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
784 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
785 if (j
< FRAMES
- 1) {
799 for (j
= 0; j
< FRAMES
; j
++) {
800 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
803 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
805 for (j
= 0; j
< FRAMES
; j
++) {
806 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
814 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
816 int style
= wPreferences
.iconification_style
; /* Catch the value */
819 if (style
== WIS_NONE
)
822 if (style
== WIS_RANDOM
) {
828 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
830 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
833 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
835 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
839 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
841 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
845 #endif /* ANIMATIONS */
847 static void flushExpose()
851 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
852 WMHandleEvent(&tmpev
);
856 static void unmapTransientsFor(WWindow
* wwin
)
860 tmp
= wwin
->screen_ptr
->focused_window
;
862 /* unmap the transients for this transient */
863 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
864 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
865 unmapTransientsFor(tmp
);
866 tmp
->flags
.miniaturized
= 1;
867 if (!tmp
->flags
.shaded
) {
870 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
873 if (!tmp->flags.shaded)
875 wClientSetState(tmp
, IconicState
, None
);
877 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
883 static void mapTransientsFor(WWindow
* wwin
)
887 tmp
= wwin
->screen_ptr
->focused_window
;
889 /* recursively map the transients for this transient */
890 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
891 && tmp
->icon
== NULL
) {
892 mapTransientsFor(tmp
);
893 tmp
->flags
.miniaturized
= 0;
894 if (!tmp
->flags
.shaded
) {
897 XMapWindow(dpy
, tmp
->frame
->core
->window
);
899 tmp
->flags
.semi_focused
= 0;
901 if (!tmp->flags.shaded)
903 wClientSetState(tmp
, NormalState
, None
);
905 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
912 static void setupIconGrabs(WIcon
* icon
)
914 /* setup passive grabs on the icon */
915 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
916 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
917 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
918 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
919 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
920 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
925 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
932 /* hackish way to detect transient_for cycle */
933 i
= wwin
->screen_ptr
->window_count
+ 1;
935 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
936 wwin
= wWindowFor(wwin
->transient_for
);
939 if (i
== 0 && wwin
) {
940 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
948 static void removeIconGrabs(WIcon
* icon
)
950 /* remove passive grabs on the icon */
951 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
952 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
953 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
958 void wIconifyWindow(WWindow
* wwin
)
960 XWindowAttributes attribs
;
963 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
964 /* the window doesn't exist anymore */
968 if (wwin
->flags
.miniaturized
) {
972 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
973 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
975 if (owner
&& owner
->flags
.miniaturized
)
979 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
981 /* if the window is in another workspace, simplify process */
983 /* icon creation may take a while */
984 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
985 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
986 GrabModeAsync
, None
, None
, CurrentTime
);
989 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
990 if (!wwin
->flags
.icon_moved
) {
991 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
993 wwin
->icon
= wIconCreate(wwin
);
995 wwin
->icon
->mapped
= 1;
998 wwin
->flags
.miniaturized
= 1;
999 wwin
->flags
.mapped
= 0;
1001 /* unmap transients */
1003 unmapTransientsFor(wwin
);
1006 XUngrabPointer(dpy
, CurrentTime
);
1008 /* let all Expose events arrive so that we can repaint
1009 * something before the animation starts (and the server is grabbed) */
1012 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1013 wClientSetState(wwin
, IconicState
, None
);
1015 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1019 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1020 && !wPreferences
.no_animations
) {
1023 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1026 iw
= wwin
->icon
->core
->width
;
1027 ih
= wwin
->icon
->core
->height
;
1029 if (wwin
->flags
.net_handle_icon
) {
1037 iw
= wwin
->screen_ptr
->scr_width
;
1038 ih
= wwin
->screen_ptr
->scr_height
;
1041 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1042 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1047 wwin
->flags
.skip_next_animation
= 0;
1049 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1050 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1051 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1053 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1055 AddToStackList(wwin
->icon
->core
);
1057 wLowerFrame(wwin
->icon
->core
);
1061 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1064 * It doesn't seem to be working and causes button event hangup
1065 * when deiconifying a transient window.
1066 setupIconGrabs(wwin->icon);
1068 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1069 && wPreferences
.focus_mode
== WKF_CLICK
) {
1074 if (!WFLAGP(tmp
, no_focusable
)
1075 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1076 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1080 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1081 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1082 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1085 if (!wwin
->screen_ptr
->flags
.startup
) {
1086 /* Catch up with events not processed while animation was running */
1087 Window clientwin
= wwin
->client_win
;
1089 ProcessPendingEvents();
1091 /* the window can disappear while ProcessPendingEvents() runs */
1092 if (!wWindowFor(clientwin
)) {
1099 /* maybe we want to do this regardless of net_handle_icon
1100 * it seems to me we might break behaviour this way.
1102 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1103 && !wwin
->flags
.net_handle_icon
)
1104 wIconSelect(wwin
->icon
);
1106 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1108 if (wPreferences
.auto_arrange_icons
)
1109 wArrangeIcons(wwin
->screen_ptr
, True
);
1112 void wDeiconifyWindow(WWindow
* wwin
)
1114 /* Let's avoid changing workspace while deiconifying */
1115 ignore_wks_change
= 1;
1117 /* we're hiding for show_desktop */
1118 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1119 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1122 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1124 if (!wwin
->flags
.miniaturized
)
1127 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1128 WWindow
*owner
= recursiveTransientFor(wwin
);
1130 if (owner
&& owner
->flags
.miniaturized
) {
1131 wDeiconifyWindow(owner
);
1132 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1133 wRaiseFrame(wwin
->frame
->core
);
1138 wwin
->flags
.miniaturized
= 0;
1140 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1141 wwin
->flags
.mapped
= 1;
1144 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1145 /* maybe we want to do this regardless of net_handle_icon
1146 * it seems to me we might break behaviour this way.
1148 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1149 && wwin
->icon
!= NULL
) {
1150 if (wwin
->icon
->selected
)
1151 wIconSelect(wwin
->icon
);
1153 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1157 /* if the window is in another workspace, do it silently */
1158 if (!netwm_hidden
) {
1160 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1161 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1164 if (!wPreferences
.disable_miniwindows
1165 && !wwin
->flags
.net_handle_icon
) {
1168 iw
= wwin
->icon
->core
->width
;
1169 ih
= wwin
->icon
->core
->height
;
1171 if (wwin
->flags
.net_handle_icon
) {
1179 iw
= wwin
->screen_ptr
->scr_width
;
1180 ih
= wwin
->screen_ptr
->scr_height
;
1183 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1184 wwin
->frame_x
, wwin
->frame_y
,
1185 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1187 #endif /* ANIMATIONS */
1188 wwin
->flags
.skip_next_animation
= 0;
1190 if (!wwin
->flags
.shaded
) {
1191 XMapWindow(dpy
, wwin
->client_win
);
1193 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1194 wRaiseFrame(wwin
->frame
->core
);
1195 if (!wwin
->flags
.shaded
) {
1196 wClientSetState(wwin
, NormalState
, None
);
1198 mapTransientsFor(wwin
);
1201 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1202 && !wwin
->flags
.net_handle_icon
) {
1203 RemoveFromStackList(wwin
->icon
->core
);
1204 /* removeIconGrabs(wwin->icon); */
1205 wIconDestroy(wwin
->icon
);
1209 if (!netwm_hidden
) {
1212 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1215 if (!wwin
->screen_ptr
->flags
.startup
) {
1216 /* Catch up with events not processed while animation was running */
1217 Window clientwin
= wwin
->client_win
;
1219 ProcessPendingEvents();
1221 /* the window can disappear while ProcessPendingEvents() runs */
1222 if (!wWindowFor(clientwin
)) {
1229 if (wPreferences
.auto_arrange_icons
) {
1230 wArrangeIcons(wwin
->screen_ptr
, True
);
1233 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1235 /* In case we were shaded and iconified, also unshade */
1237 wUnshadeWindow(wwin
);
1239 ignore_wks_change
= 0;
1242 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1244 if (wwin
->flags
.miniaturized
) {
1246 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1247 wwin
->icon
->mapped
= 0;
1249 wwin
->flags
.hidden
= 1;
1251 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1255 if (wwin
->flags
.inspector_open
) {
1256 wHideInspectorForWindow(wwin
);
1259 wwin
->flags
.hidden
= 1;
1262 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1266 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1267 !wwin
->flags
.skip_next_animation
&& animate
) {
1268 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1269 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1270 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1273 wwin
->flags
.skip_next_animation
= 0;
1275 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1278 void wHideOtherApplications(WWindow
* awin
)
1285 wwin
= awin
->screen_ptr
->focused_window
;
1289 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1290 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1291 && !wwin
->flags
.internal_window
1292 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1294 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1295 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1296 wwin
->flags
.skip_next_animation
= 1;
1297 wIconifyWindow(wwin
);
1299 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1300 tapp
= wApplicationOf(wwin
->main_window
);
1302 tapp
->flags
.skip_next_animation
= 1;
1303 wHideApplication(tapp
);
1305 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1306 wwin
->flags
.skip_next_animation
= 1;
1307 wIconifyWindow(wwin
);
1315 wSetFocusTo(awin->screen_ptr, awin);
1319 void wHideApplication(WApplication
* wapp
)
1327 wwarning("trying to hide a non grouped window");
1330 if (!wapp
->main_window_desc
) {
1331 wwarning("group leader not found for window group");
1334 scr
= wapp
->main_window_desc
->screen_ptr
;
1336 wlist
= scr
->focused_window
;
1340 if (wlist
->main_window
== wapp
->main_window
)
1341 wapp
->last_focused
= wlist
;
1343 wapp
->last_focused
= NULL
;
1345 animate
= !wapp
->flags
.skip_next_animation
;
1348 if (wlist
->main_window
== wapp
->main_window
) {
1349 if (wlist
->flags
.focused
) {
1352 if (wapp
->app_icon
) {
1353 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1354 wapp
->app_icon
->y_pos
, wlist
, animate
);
1358 wlist
= wlist
->prev
;
1361 wapp
->flags
.skip_next_animation
= 0;
1364 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1365 wlist
= scr
->focused_window
;
1367 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1368 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1370 wlist
= wlist
->prev
;
1372 wSetFocusTo(scr
, wlist
);
1374 wSetFocusTo(scr
, NULL
);
1378 wapp
->flags
.hidden
= 1;
1380 if (wPreferences
.auto_arrange_icons
) {
1381 wArrangeIcons(scr
, True
);
1385 wAppIconPaint(wapp
->app_icon
);
1389 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1391 if (bringToCurrentWS
)
1392 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1394 wwin
->flags
.hidden
= 0;
1397 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1398 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1399 icon
->core
->width
, icon
->core
->height
,
1400 wwin
->frame_x
, wwin
->frame_y
,
1401 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1404 wwin
->flags
.skip_next_animation
= 0;
1405 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1406 XMapWindow(dpy
, wwin
->client_win
);
1407 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1408 wClientSetState(wwin
, NormalState
, None
);
1409 wwin
->flags
.mapped
= 1;
1410 wRaiseFrame(wwin
->frame
->core
);
1412 if (wwin
->flags
.inspector_open
) {
1413 wUnhideInspectorForWindow(wwin
);
1416 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1419 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1422 WWindow
*wlist
, *next
;
1423 WWindow
*focused
= NULL
;
1429 scr
= wapp
->main_window_desc
->screen_ptr
;
1430 wlist
= scr
->focused_window
;
1434 /* goto beginning of list */
1436 wlist
= wlist
->prev
;
1438 animate
= !wapp
->flags
.skip_next_animation
;
1443 if (wlist
->main_window
== wapp
->main_window
) {
1444 if (wlist
->flags
.focused
)
1446 else if (!focused
|| !focused
->flags
.focused
)
1449 if (wlist
->flags
.miniaturized
) {
1450 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1451 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1452 if (!wlist
->icon
->mapped
) {
1455 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1456 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1457 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1461 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1462 wlist
->icon
->mapped
= 1;
1464 wRaiseFrame(wlist
->icon
->core
);
1466 if (bringToCurrentWS
)
1467 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1468 wlist
->flags
.hidden
= 0;
1469 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1470 wDeiconifyWindow(wlist
);
1472 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1473 } else if (wlist
->flags
.shaded
) {
1474 if (bringToCurrentWS
)
1475 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1476 wlist
->flags
.hidden
= 0;
1477 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1478 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1480 wUnshadeWindow(wlist
);
1481 wRaiseFrame(wlist
->frame
->core
);
1484 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1485 } else if (wlist
->flags
.hidden
) {
1486 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1487 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1490 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1491 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1493 wRaiseFrame(wlist
->frame
->core
);
1499 wapp
->flags
.skip_next_animation
= 0;
1500 wapp
->flags
.hidden
= 0;
1502 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1503 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1504 wSetFocusTo(scr
, wapp
->last_focused
);
1505 } else if (focused
) {
1506 wSetFocusTo(scr
, focused
);
1508 wapp
->last_focused
= NULL
;
1509 if (wPreferences
.auto_arrange_icons
) {
1510 wArrangeIcons(scr
, True
);
1513 wAppIconPaint(wapp
->app_icon
);
1517 void wShowAllWindows(WScreen
* scr
)
1519 WWindow
*wwin
, *old_foc
;
1522 old_foc
= wwin
= scr
->focused_window
;
1524 if (!wwin
->flags
.internal_window
&&
1525 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1526 if (wwin
->flags
.miniaturized
) {
1527 wwin
->flags
.skip_next_animation
= 1;
1528 wDeiconifyWindow(wwin
);
1529 } else if (wwin
->flags
.hidden
) {
1530 wapp
= wApplicationOf(wwin
->main_window
);
1532 wUnhideApplication(wapp
, False
, False
);
1534 wwin
->flags
.skip_next_animation
= 1;
1535 wDeiconifyWindow(wwin
);
1541 wSetFocusTo(scr
, old_foc
);
1542 /*wRaiseFrame(old_foc->frame->core); */
1545 void wRefreshDesktop(WScreen
* scr
)
1548 XSetWindowAttributes attr
;
1550 attr
.backing_store
= NotUseful
;
1551 attr
.save_under
= False
;
1552 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1553 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1554 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1555 XMapRaised(dpy
, win
);
1556 XDestroyWindow(dpy
, win
);
1560 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1566 const int heads
= wXineramaHeads(scr
);
1569 int pf
; /* primary axis */
1570 int sf
; /* secondary axis */
1574 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1580 int isize
= wPreferences
.icon_size
;
1582 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1584 for (head
= 0; head
< heads
; ++head
) {
1586 WMRect rect
= wGetRectForHead(scr
, head
);
1588 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1589 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1592 vars
[head
].pi
= vars
[head
].si
= 0;
1593 vars
[head
].sx1
= rect
.pos
.x
;
1594 vars
[head
].sy1
= rect
.pos
.y
;
1595 vars
[head
].sw
= rect
.size
.width
;
1596 vars
[head
].sh
= rect
.size
.height
;
1597 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1598 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1602 if (scr
->dock
->on_right_side
)
1603 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1605 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1609 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1610 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1611 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1612 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1614 /* icon yard boundaries */
1615 if (wPreferences
.icon_yard
& IY_VERT
) {
1616 vars
[head
].pf
= vars
[head
].fullH
;
1617 vars
[head
].sf
= vars
[head
].fullW
;
1619 vars
[head
].pf
= vars
[head
].fullW
;
1620 vars
[head
].sf
= vars
[head
].fullH
;
1622 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1623 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1626 vars
[head
].xo
= vars
[head
].sx1
;
1629 if (wPreferences
.icon_yard
& IY_TOP
) {
1630 vars
[head
].yo
= vars
[head
].sy1
;
1633 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1638 #define X ((wPreferences.icon_yard & IY_VERT) \
1639 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1640 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1642 #define Y ((wPreferences.icon_yard & IY_VERT) \
1643 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1644 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1646 /* arrange application icons */
1647 aicon
= scr
->app_icon_list
;
1648 /* reverse them to avoid unnecessarily sliding of icons */
1649 while (aicon
&& aicon
->next
)
1650 aicon
= aicon
->next
;
1653 if (!aicon
->docked
) {
1654 /* CHECK: can icon be NULL here ? */
1655 /* The intention here is to place the AppIcon on the head that
1656 * contains most of the applications _main_ window. */
1657 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1659 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1661 if (!wPreferences
.no_animations
) {
1662 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1664 #endif /* ANIMATIONS */
1666 wAppIconMove(aicon
, X
, Y
);
1668 if (vars
[head
].pi
>= vars
[head
].pf
) {
1673 aicon
= aicon
->prev
;
1676 /* arrange miniwindows */
1677 wwin
= scr
->focused_window
;
1678 /* reverse them to avoid unnecessarily shuffling */
1679 while (wwin
&& wwin
->prev
)
1683 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1684 (wwin
->frame
->workspace
== scr
->current_workspace
||
1685 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1687 head
= wGetHeadForWindow(wwin
);
1689 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1690 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1692 if (wPreferences
.no_animations
) {
1693 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1695 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1696 wwin
->icon_y
, X
, Y
);
1699 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1700 #endif /* ANIMATIONS */
1706 if (vars
[head
].pi
>= vars
[head
].pf
) {
1713 wwin
->flags
.icon_moved
= 0;
1715 /* we reversed the order, so we use next */
1722 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1724 WScreen
*scr
= wwin
->screen_ptr
;
1727 wwin
->flags
.selected
= 1;
1728 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1730 if (!HAS_BORDER(wwin
)) {
1731 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1734 if (!scr
->selected_windows
)
1735 scr
->selected_windows
= WMCreateArray(4);
1736 WMAddToArray(scr
->selected_windows
, wwin
);
1738 wwin
->flags
.selected
= 0;
1739 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1741 if (!HAS_BORDER(wwin
)) {
1742 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1745 if (scr
->selected_windows
) {
1746 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1751 void wMakeWindowVisible(WWindow
* wwin
)
1753 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1754 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1756 if (wwin
->flags
.shaded
) {
1757 wUnshadeWindow(wwin
);
1759 if (wwin
->flags
.hidden
) {
1762 app
= wApplicationOf(wwin
->main_window
);
1764 /* trick to get focus to this window */
1765 app
->last_focused
= wwin
;
1766 wUnhideApplication(app
, False
, False
);
1769 if (wwin
->flags
.miniaturized
) {
1770 wDeiconifyWindow(wwin
);
1772 if (!WFLAGP(wwin
, no_focusable
))
1773 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1774 wRaiseFrame(wwin
->frame
->core
);
1779 * Do the animation while shading (called with what = SHADE)
1780 * or unshading (what = UNSHADE).
1783 static void shade_animate(WWindow
*wwin
, Bool what
)
1786 time_t time0
= time(NULL
);
1788 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1793 if (!wwin
->screen_ptr
->flags
.startup
) {
1794 /* do the shading animation */
1795 h
= wwin
->frame
->core
->height
;
1796 s
= h
/ SHADE_STEPS
;
1799 w
= wwin
->frame
->core
->width
;
1800 y
= wwin
->frame
->top_width
;
1801 while (h
> wwin
->frame
->top_width
+ 1) {
1802 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1803 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1806 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1809 if (SHADE_DELAY
> 0) {
1810 wusleep(SHADE_DELAY
* 1000L);
1817 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1822 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1823 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1824 s
= abs(y
) / SHADE_STEPS
;
1827 w
= wwin
->frame
->core
->width
;
1828 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1830 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1831 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1832 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1834 if (SHADE_DELAY
> 0) {
1835 wusleep(SHADE_DELAY
* 2000L / 3);
1842 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1846 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);