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 static void shade_animate(WWindow
*wwin
, Bool what
);
97 static void shade_animate(WWindow
*wwin
, Bool what
) { }
101 *----------------------------------------------------------------------
103 * Changes the window focus to the one passed as argument.
104 * If the window to focus is not already focused, it will be brought
105 * to the head of the list of windows. Previously focused window is
109 * Window list may be reordered and the window focus is changed.
111 *----------------------------------------------------------------------
113 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
115 static WScreen
*old_scr
= NULL
;
117 WWindow
*old_focused
;
118 WWindow
*focused
= scr
->focused_window
;
119 Time timestamp
= LastTimestamp
;
120 WApplication
*oapp
= NULL
, *napp
= NULL
;
123 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
128 old_focused
= old_scr
->focused_window
;
130 LastFocusChange
= timestamp
;
133 oapp
= wApplicationOf(old_focused
->main_window
);
136 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
138 wWindowUnfocus(old_focused
);
141 wAppMenuUnmap(oapp
->menu
);
143 wApplicationDeactivate(oapp
);
147 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
149 } else if (old_scr
!= scr
&& old_focused
) {
150 wWindowUnfocus(old_focused
);
153 wasfocused
= wwin
->flags
.focused
;
154 napp
= wApplicationOf(wwin
->main_window
);
156 /* remember last workspace where the app has been */
158 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
159 napp
->last_workspace
= wwin
->frame
->workspace
;
162 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
163 /* install colormap if colormap mode is lock mode */
164 if (wPreferences
.colormap_mode
== WCM_CLICK
)
165 wColormapInstallForWindow(scr
, wwin
);
167 /* set input focus */
168 switch (wwin
->focus_mode
) {
170 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
174 case WFM_LOCALLY_ACTIVE
:
175 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
178 case WFM_GLOBALLY_ACTIVE
:
182 if (wwin
->protocols
.TAKE_FOCUS
) {
183 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
187 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
189 if (WFLAGP(wwin
, no_focusable
))
192 /* if this is not the focused window focus it */
193 if (focused
!= wwin
) {
194 /* change the focus window list order */
196 wwin
->prev
->next
= wwin
->next
;
199 wwin
->next
->prev
= wwin
->prev
;
201 wwin
->prev
= focused
;
202 focused
->next
= wwin
;
204 scr
->focused_window
= wwin
;
206 if (oapp
&& oapp
!= napp
) {
207 wAppMenuUnmap(oapp
->menu
);
209 wApplicationDeactivate(oapp
);
214 wWindowFocus(wwin
, focused
);
216 if (napp
&& !wasfocused
) {
218 wUserMenuRefreshInstances(napp
->menu
, wwin
);
219 #endif /* USER_MENU */
221 if (wwin
->flags
.mapped
)
222 wAppMenuMap(napp
->menu
, wwin
);
224 wApplicationActivate(napp
);
232 void wShadeWindow(WWindow
*wwin
)
235 if (wwin
->flags
.shaded
)
238 XLowerWindow(dpy
, wwin
->client_win
);
239 shade_animate(wwin
, SHADE
);
241 wwin
->flags
.skip_next_animation
= 0;
242 wwin
->flags
.shaded
= 1;
243 wwin
->flags
.mapped
= 0;
244 /* prevent window withdrawal when getting UnmapNotify */
245 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
246 XUnmapWindow(dpy
, wwin
->client_win
);
247 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
249 /* for the client it's just like iconification */
250 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
252 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
253 wWindowSynthConfigureNotify(wwin
);
256 wClientSetState(wwin, IconicState, None);
259 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
262 if (!wwin
->screen_ptr
->flags
.startup
) {
263 /* Catch up with events not processed while animation was running */
264 ProcessPendingEvents();
269 void wUnshadeWindow(WWindow
*wwin
)
272 if (!wwin
->flags
.shaded
)
275 wwin
->flags
.shaded
= 0;
276 wwin
->flags
.mapped
= 1;
277 XMapWindow(dpy
, wwin
->client_win
);
279 shade_animate(wwin
, UNSHADE
);
281 wwin
->flags
.skip_next_animation
= 0;
282 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
283 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
285 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
286 wWindowSynthConfigureNotify(wwin
);
289 wClientSetState(wwin, NormalState, None);
291 /* if the window is focused, set the focus again as it was disabled during
293 if (wwin
->flags
.focused
)
294 wSetFocusTo(wwin
->screen_ptr
, wwin
);
296 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
299 /* Set the old coordinates using the current values */
300 static void save_old_geometry(WWindow
*wwin
)
302 wwin
->old_geometry
.width
= wwin
->client
.width
;
303 wwin
->old_geometry
.height
= wwin
->client
.height
;
304 wwin
->old_geometry
.x
= wwin
->frame_x
;
305 wwin
->old_geometry
.y
= wwin
->frame_y
;
308 void wMaximizeWindow(WWindow
* wwin
, int directions
)
311 unsigned int new_width
, new_height
, half_scr_width
;
312 WArea usableArea
, totalArea
;
316 if (!IS_RESIZABLE(wwin
))
319 if (!HAS_BORDER(wwin
))
322 /* the size to adjust the geometry */
323 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
325 /* save old coordinates before we change the current values */
326 save_old_geometry(wwin
);
330 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
331 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
332 usableArea
= totalArea
;
334 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
335 WScreen
*scr
= wwin
->screen_ptr
;
338 if (directions
& MAX_KEYBOARD
)
339 head
= wGetHeadForWindow(wwin
);
341 head
= wGetHeadForPointerLocation(scr
);
343 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
346 /* Only save directions, not kbd or xinerama hints */
347 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
349 if (WFLAGP(wwin
, full_maximize
)) {
350 usableArea
= totalArea
;
352 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
354 if (wwin
->flags
.shaded
) {
355 wwin
->flags
.skip_next_animation
= 1;
356 wUnshadeWindow(wwin
);
359 if (directions
& MAX_HORIZONTAL
) {
360 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
361 new_x
= usableArea
.x1
;
362 } else if (directions
& MAX_LEFTHALF
) {
363 new_width
= half_scr_width
- adj_size
;
364 new_x
= usableArea
.x1
;
365 } else if (directions
& MAX_RIGHTHALF
) {
366 new_width
= half_scr_width
- adj_size
;
367 new_x
= usableArea
.x1
+ half_scr_width
;
369 new_x
= wwin
->frame_x
;
370 new_width
= wwin
->frame
->core
->width
;
373 if (directions
& MAX_VERTICAL
) {
374 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
375 new_y
= usableArea
.y1
;
376 if (WFLAGP(wwin
, full_maximize
)) {
377 new_y
-= wwin
->frame
->top_width
;
378 new_height
+= wwin
->frame
->bottom_width
- 1;
381 new_y
= wwin
->frame_y
;
382 new_height
= wwin
->frame
->core
->height
;
385 if (!WFLAGP(wwin
, full_maximize
)) {
386 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
389 if (directions
& MAX_MAXIMUS
) {
390 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
391 new_width
-= adj_size
;
392 new_height
-= adj_size
;
393 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
394 new_y
-= wwin
->frame
->top_width
;
395 new_height
+= wwin
->frame
->top_width
- 1;
399 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
401 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
402 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
404 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
406 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
408 /* set maximization state */
409 wwin
->flags
.maximized
= directions
;
413 * Maximus: tiled maximization (maximize without overlapping other windows)
415 * The window to be maximized will be denoted by w_0 (sub-index zero)
416 * while the windows which will stop the maximization of w_0 are denoted by w_j.
418 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
419 unsigned int *new_width
, unsigned int *new_height
)
422 int x_0
= wwin
->frame_x
;
423 int y_0
= wwin
->frame_y
;
424 int width_0
= wwin
->frame
->core
->width
;
425 int height_0
= wwin
->frame
->core
->height
;
426 int botton_0
= y_0
+ height_0
;
427 int right_border_0
= x_0
+ width_0
;
428 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
429 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
430 int x_intsect
, y_intsect
;
431 short int tbar_height_0
= 0, rbar_height_0
= 0;
432 short int bd_width_0
= 0, bd_width_j
= 0;
433 short int adjust_height
;
435 /* Try to fully maximize first, then readjust later */
436 new_x_0
= usableArea
.x1
;
437 new_y_0
= usableArea
.y1
;
438 new_botton_0
= usableArea
.y2
;
439 new_right_border_0
= usableArea
.x2
;
441 if (HAS_TITLEBAR(wwin
))
442 tbar_height_0
= TITLEBAR_HEIGHT
;
443 if (HAS_RESIZEBAR(wwin
))
444 rbar_height_0
= RESIZEBAR_HEIGHT
;
445 if (HAS_BORDER(wwin
))
446 bd_width_0
= FRAME_BORDER_WIDTH
;
448 /* the lengths to be subtracted if w_0 has titlebar, etc */
449 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
452 /* The focused window is always the last in the list */
454 /* ignore windows in other workspaces etc */
455 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
456 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
463 bd_width_j
= FRAME_BORDER_WIDTH
;
468 * Set the w_j window coordinates. It is convenient
469 * to not use "corrected" sizes for width and height,
470 * otherwise bottom_j and right_border_j would be
473 x_j
= tmp
->frame_x
- bd_width_j
;
474 y_j
= tmp
->frame_y
- bd_width_j
;
475 width_j
= tmp
->frame
->core
->width
;
476 height_j
= tmp
->frame
->core
->height
;
477 botton_j
= y_j
+ height_j
+ bd_width_j
;
478 top_j
= y_j
- bd_width_j
;
479 right_border_j
= x_j
+ width_j
+ bd_width_j
;
481 /* Try to maximize in the y direction first */
482 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
483 if (x_intsect
!= 0) {
484 /* TODO: Consider the case when coords are equal */
485 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
486 /* w_0 is below the botton of w_j */
489 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
490 /* The botton of w_0 is above the top of w_j */
491 new_botton_0
= top_j
;
498 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
499 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
506 bd_width_j
= FRAME_BORDER_WIDTH
;
510 /* set the w_j window coordinates */
511 x_j
= tmp
->frame_x
- bd_width_j
;
512 y_j
= tmp
->frame_y
- bd_width_j
;
513 width_j
= tmp
->frame
->core
->width
;
514 height_j
= tmp
->frame
->core
->height
;
515 botton_j
= y_j
+ height_j
+ bd_width_j
;
516 top_j
= y_j
- bd_width_j
;
517 right_border_j
= x_j
+ width_j
+ bd_width_j
;
520 * Use the updated y coordinates from the above step to account
521 * the possibility that the new value of y_0 will have different
522 * intersections with w_j
524 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
525 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
526 if (y_intsect
!= 0) {
527 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
528 /* w_0 is completely to the right of w_j */
529 new_x_0
= right_border_j
+ 1;
531 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
532 /* w_0 is completely to the left of w_j */
533 new_right_border_0
= x_j
- 1;
538 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
541 *new_height
= new_height_0
;
542 *new_width
= new_right_border_0
- new_x_0
;
545 void wUnmaximizeWindow(WWindow
* wwin
)
548 WMRect old_geom_rect
;
552 if (!wwin
->flags
.maximized
)
555 if (wwin
->flags
.shaded
) {
556 wwin
->flags
.skip_next_animation
= 1;
557 wUnshadeWindow(wwin
);
559 /* Use old coordinates if they are set, current values otherwise */
560 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
561 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
562 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
563 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
564 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
565 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
566 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
568 wwin
->flags
.maximized
= 0;
569 wWindowConfigure(wwin
, x
, y
, w
, h
);
571 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
574 void wFullscreenWindow(WWindow
* wwin
)
579 if (wwin
->flags
.fullscreen
)
582 wwin
->flags
.fullscreen
= True
;
584 wWindowConfigureBorders(wwin
);
586 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
588 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
589 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
590 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
591 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
593 head
= wGetHeadForWindow(wwin
);
594 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
595 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
597 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
600 void wUnfullscreenWindow(WWindow
* wwin
)
602 if (!wwin
->flags
.fullscreen
)
605 wwin
->flags
.fullscreen
= False
;
607 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
608 if (WFLAGP(wwin
, sunken
)) {
609 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
610 } else if (WFLAGP(wwin
, floating
)) {
611 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
613 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
617 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
618 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
620 wWindowConfigureBorders(wwin
);
622 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
623 wFrameWindowPaint(wwin->frame);
626 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
630 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
632 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
633 float cx
, cy
, cw
, ch
;
634 float xstep
, ystep
, wstep
, hstep
;
637 float angle
, final_angle
, delta
;
639 xstep
= (float)(fx
- x
) / steps
;
640 ystep
= (float)(fy
- y
) / steps
;
641 wstep
= (float)(fw
- w
) / steps
;
642 hstep
= (float)(fh
- h
) / steps
;
649 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
650 delta
= (float)(final_angle
/ FRAMES
);
651 for (angle
= 0;; angle
+= delta
) {
652 if (angle
> final_angle
)
655 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
656 dch
= (ch
/ 2) * cos(angle
);
657 midy
= cy
+ (ch
/ 2);
659 points
[0].x
= cx
+ dx
;
660 points
[0].y
= midy
- dch
;
661 points
[1].x
= cx
+ cw
- dx
;
662 points
[1].y
= points
[0].y
;
663 points
[2].x
= cx
+ cw
+ dx
;
664 points
[2].y
= midy
+ dch
;
665 points
[3].x
= cx
- dx
;
666 points
[3].y
= points
[2].y
;
667 points
[4].x
= points
[0].x
;
668 points
[4].y
= points
[0].y
;
671 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
673 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
675 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
681 if (angle
>= final_angle
)
691 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
693 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
694 float cx
, cy
, cw
, ch
;
695 float xstep
, ystep
, wstep
, hstep
;
697 float angle
, final_angle
, a
, d
, delta
;
704 xstep
= (float)(fx
- x
) / steps
;
705 ystep
= (float)(fy
- y
) / steps
;
706 wstep
= (float)(fw
- w
) / steps
;
707 hstep
= (float)(fh
- h
) / steps
;
714 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
715 delta
= (float)(final_angle
/ FRAMES
);
716 for (angle
= 0;; angle
+= delta
) {
717 if (angle
> final_angle
)
721 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
723 points
[0].x
= cx
+ cos(angle
- a
) * d
;
724 points
[0].y
= cy
+ sin(angle
- a
) * d
;
725 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
726 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
727 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
728 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
729 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
730 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
731 points
[4].x
= cx
+ cos(angle
- a
) * d
;
732 points
[4].y
= cy
+ sin(angle
- a
) * d
;
734 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
736 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
738 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
744 if (angle
>= final_angle
)
753 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
755 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
756 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
757 float xstep
, ystep
, wstep
, hstep
;
760 xstep
= (float)(fx
- x
) / steps
;
761 ystep
= (float)(fy
- y
) / steps
;
762 wstep
= (float)(fw
- w
) / steps
;
763 hstep
= (float)(fh
- h
) / steps
;
765 for (j
= 0; j
< FRAMES
; j
++) {
772 for (i
= 0; i
< steps
; i
++) {
773 for (j
= 0; j
< FRAMES
; j
++) {
774 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
775 (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
,
782 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
783 if (j
< FRAMES
- 1) {
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
]);
801 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
803 for (j
= 0; j
< FRAMES
; j
++) {
804 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
812 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
814 int style
= wPreferences
.iconification_style
; /* Catch the value */
817 if (style
== WIS_NONE
)
820 if (style
== WIS_RANDOM
) {
826 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
828 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
831 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
833 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
837 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
839 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
843 #endif /* ANIMATIONS */
845 static void flushExpose()
849 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
850 WMHandleEvent(&tmpev
);
854 static void unmapTransientsFor(WWindow
* wwin
)
858 tmp
= wwin
->screen_ptr
->focused_window
;
860 /* unmap the transients for this transient */
861 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
862 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
863 unmapTransientsFor(tmp
);
864 tmp
->flags
.miniaturized
= 1;
865 if (!tmp
->flags
.shaded
) {
868 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
871 if (!tmp->flags.shaded)
873 wClientSetState(tmp
, IconicState
, None
);
875 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
881 static void mapTransientsFor(WWindow
* wwin
)
885 tmp
= wwin
->screen_ptr
->focused_window
;
887 /* recursively map the transients for this transient */
888 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
889 && tmp
->icon
== NULL
) {
890 mapTransientsFor(tmp
);
891 tmp
->flags
.miniaturized
= 0;
892 if (!tmp
->flags
.shaded
) {
895 XMapWindow(dpy
, tmp
->frame
->core
->window
);
897 tmp
->flags
.semi_focused
= 0;
899 if (!tmp->flags.shaded)
901 wClientSetState(tmp
, NormalState
, None
);
903 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
910 static void setupIconGrabs(WIcon
* icon
)
912 /* setup passive grabs on the icon */
913 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
914 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
915 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
916 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
917 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
918 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
923 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
930 /* hackish way to detect transient_for cycle */
931 i
= wwin
->screen_ptr
->window_count
+ 1;
933 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
934 wwin
= wWindowFor(wwin
->transient_for
);
937 if (i
== 0 && wwin
) {
938 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
946 static void removeIconGrabs(WIcon
* icon
)
948 /* remove passive grabs on the icon */
949 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
950 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
951 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
956 void wIconifyWindow(WWindow
* wwin
)
958 XWindowAttributes attribs
;
961 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
962 /* the window doesn't exist anymore */
966 if (wwin
->flags
.miniaturized
) {
970 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
971 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
973 if (owner
&& owner
->flags
.miniaturized
)
977 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
979 /* if the window is in another workspace, simplify process */
981 /* icon creation may take a while */
982 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
983 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
984 GrabModeAsync
, None
, None
, CurrentTime
);
987 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
988 if (!wwin
->flags
.icon_moved
) {
989 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
991 wwin
->icon
= wIconCreate(wwin
);
993 wwin
->icon
->mapped
= 1;
996 wwin
->flags
.miniaturized
= 1;
997 wwin
->flags
.mapped
= 0;
999 /* unmap transients */
1001 unmapTransientsFor(wwin
);
1004 XUngrabPointer(dpy
, CurrentTime
);
1006 /* let all Expose events arrive so that we can repaint
1007 * something before the animation starts (and the server is grabbed) */
1010 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1011 wClientSetState(wwin
, IconicState
, None
);
1013 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1017 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1018 && !wPreferences
.no_animations
) {
1021 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1024 iw
= wwin
->icon
->core
->width
;
1025 ih
= wwin
->icon
->core
->height
;
1027 if (wwin
->flags
.net_handle_icon
) {
1035 iw
= wwin
->screen_ptr
->scr_width
;
1036 ih
= wwin
->screen_ptr
->scr_height
;
1039 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1040 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1045 wwin
->flags
.skip_next_animation
= 0;
1047 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1048 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1049 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1051 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1053 AddToStackList(wwin
->icon
->core
);
1055 wLowerFrame(wwin
->icon
->core
);
1059 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1062 * It doesn't seem to be working and causes button event hangup
1063 * when deiconifying a transient window.
1064 setupIconGrabs(wwin->icon);
1066 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1067 && wPreferences
.focus_mode
== WKF_CLICK
) {
1072 if (!WFLAGP(tmp
, no_focusable
)
1073 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1074 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1078 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1079 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1080 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1083 if (!wwin
->screen_ptr
->flags
.startup
) {
1084 /* Catch up with events not processed while animation was running */
1085 Window clientwin
= wwin
->client_win
;
1087 ProcessPendingEvents();
1089 /* the window can disappear while ProcessPendingEvents() runs */
1090 if (!wWindowFor(clientwin
)) {
1097 /* maybe we want to do this regardless of net_handle_icon
1098 * it seems to me we might break behaviour this way.
1100 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1101 && !wwin
->flags
.net_handle_icon
)
1102 wIconSelect(wwin
->icon
);
1104 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1106 if (wPreferences
.auto_arrange_icons
)
1107 wArrangeIcons(wwin
->screen_ptr
, True
);
1110 void wDeiconifyWindow(WWindow
* wwin
)
1112 /* we're hiding for show_desktop */
1113 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1114 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1117 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1119 if (!wwin
->flags
.miniaturized
)
1122 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1123 WWindow
*owner
= recursiveTransientFor(wwin
);
1125 if (owner
&& owner
->flags
.miniaturized
) {
1126 wDeiconifyWindow(owner
);
1127 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1128 wRaiseFrame(wwin
->frame
->core
);
1133 wwin
->flags
.miniaturized
= 0;
1135 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1136 wwin
->flags
.mapped
= 1;
1139 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1140 /* maybe we want to do this regardless of net_handle_icon
1141 * it seems to me we might break behaviour this way.
1143 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1144 && wwin
->icon
!= NULL
) {
1145 if (wwin
->icon
->selected
)
1146 wIconSelect(wwin
->icon
);
1148 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1152 /* if the window is in another workspace, do it silently */
1153 if (!netwm_hidden
) {
1155 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1156 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1159 if (!wPreferences
.disable_miniwindows
1160 && !wwin
->flags
.net_handle_icon
) {
1163 iw
= wwin
->icon
->core
->width
;
1164 ih
= wwin
->icon
->core
->height
;
1166 if (wwin
->flags
.net_handle_icon
) {
1174 iw
= wwin
->screen_ptr
->scr_width
;
1175 ih
= wwin
->screen_ptr
->scr_height
;
1178 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1179 wwin
->frame_x
, wwin
->frame_y
,
1180 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1182 #endif /* ANIMATIONS */
1183 wwin
->flags
.skip_next_animation
= 0;
1185 if (!wwin
->flags
.shaded
) {
1186 XMapWindow(dpy
, wwin
->client_win
);
1188 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1189 wRaiseFrame(wwin
->frame
->core
);
1190 if (!wwin
->flags
.shaded
) {
1191 wClientSetState(wwin
, NormalState
, None
);
1193 mapTransientsFor(wwin
);
1196 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1197 && !wwin
->flags
.net_handle_icon
) {
1198 RemoveFromStackList(wwin
->icon
->core
);
1199 /* removeIconGrabs(wwin->icon); */
1200 wIconDestroy(wwin
->icon
);
1204 if (!netwm_hidden
) {
1207 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1210 if (!wwin
->screen_ptr
->flags
.startup
) {
1211 /* Catch up with events not processed while animation was running */
1212 Window clientwin
= wwin
->client_win
;
1214 ProcessPendingEvents();
1216 /* the window can disappear while ProcessPendingEvents() runs */
1217 if (!wWindowFor(clientwin
)) {
1224 if (wPreferences
.auto_arrange_icons
) {
1225 wArrangeIcons(wwin
->screen_ptr
, True
);
1228 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1230 /* In case we were shaded and iconified, also unshade */
1232 wUnshadeWindow(wwin
);
1235 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1237 if (wwin
->flags
.miniaturized
) {
1239 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1240 wwin
->icon
->mapped
= 0;
1242 wwin
->flags
.hidden
= 1;
1244 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1248 if (wwin
->flags
.inspector_open
) {
1249 wHideInspectorForWindow(wwin
);
1252 wwin
->flags
.hidden
= 1;
1255 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1259 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1260 !wwin
->flags
.skip_next_animation
&& animate
) {
1261 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1262 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1263 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1266 wwin
->flags
.skip_next_animation
= 0;
1268 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1271 void wHideOtherApplications(WWindow
* awin
)
1278 wwin
= awin
->screen_ptr
->focused_window
;
1282 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1283 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1284 && !wwin
->flags
.internal_window
1285 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1287 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1288 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1289 wwin
->flags
.skip_next_animation
= 1;
1290 wIconifyWindow(wwin
);
1292 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1293 tapp
= wApplicationOf(wwin
->main_window
);
1295 tapp
->flags
.skip_next_animation
= 1;
1296 wHideApplication(tapp
);
1298 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1299 wwin
->flags
.skip_next_animation
= 1;
1300 wIconifyWindow(wwin
);
1308 wSetFocusTo(awin->screen_ptr, awin);
1312 void wHideApplication(WApplication
* wapp
)
1320 wwarning("trying to hide a non grouped window");
1323 if (!wapp
->main_window_desc
) {
1324 wwarning("group leader not found for window group");
1327 scr
= wapp
->main_window_desc
->screen_ptr
;
1329 wlist
= scr
->focused_window
;
1333 if (wlist
->main_window
== wapp
->main_window
)
1334 wapp
->last_focused
= wlist
;
1336 wapp
->last_focused
= NULL
;
1338 animate
= !wapp
->flags
.skip_next_animation
;
1341 if (wlist
->main_window
== wapp
->main_window
) {
1342 if (wlist
->flags
.focused
) {
1345 if (wapp
->app_icon
) {
1346 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1347 wapp
->app_icon
->y_pos
, wlist
, animate
);
1351 wlist
= wlist
->prev
;
1354 wapp
->flags
.skip_next_animation
= 0;
1357 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1358 wlist
= scr
->focused_window
;
1360 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1361 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1363 wlist
= wlist
->prev
;
1365 wSetFocusTo(scr
, wlist
);
1367 wSetFocusTo(scr
, NULL
);
1371 wapp
->flags
.hidden
= 1;
1373 if (wPreferences
.auto_arrange_icons
) {
1374 wArrangeIcons(scr
, True
);
1378 wAppIconPaint(wapp
->app_icon
);
1382 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1384 if (bringToCurrentWS
)
1385 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1387 wwin
->flags
.hidden
= 0;
1390 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1391 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1392 icon
->core
->width
, icon
->core
->height
,
1393 wwin
->frame_x
, wwin
->frame_y
,
1394 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1397 wwin
->flags
.skip_next_animation
= 0;
1398 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1399 XMapWindow(dpy
, wwin
->client_win
);
1400 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1401 wClientSetState(wwin
, NormalState
, None
);
1402 wwin
->flags
.mapped
= 1;
1403 wRaiseFrame(wwin
->frame
->core
);
1405 if (wwin
->flags
.inspector_open
) {
1406 wUnhideInspectorForWindow(wwin
);
1409 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1412 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1415 WWindow
*wlist
, *next
;
1416 WWindow
*focused
= NULL
;
1422 scr
= wapp
->main_window_desc
->screen_ptr
;
1423 wlist
= scr
->focused_window
;
1427 /* goto beginning of list */
1429 wlist
= wlist
->prev
;
1431 animate
= !wapp
->flags
.skip_next_animation
;
1436 if (wlist
->main_window
== wapp
->main_window
) {
1437 if (wlist
->flags
.focused
)
1439 else if (!focused
|| !focused
->flags
.focused
)
1442 if (wlist
->flags
.miniaturized
) {
1443 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1444 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1445 if (!wlist
->icon
->mapped
) {
1448 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1449 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1450 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1454 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1455 wlist
->icon
->mapped
= 1;
1457 wRaiseFrame(wlist
->icon
->core
);
1459 if (bringToCurrentWS
)
1460 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1461 wlist
->flags
.hidden
= 0;
1462 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1463 wDeiconifyWindow(wlist
);
1465 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1466 } else if (wlist
->flags
.shaded
) {
1467 if (bringToCurrentWS
)
1468 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1469 wlist
->flags
.hidden
= 0;
1470 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1471 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1473 wUnshadeWindow(wlist
);
1474 wRaiseFrame(wlist
->frame
->core
);
1477 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1478 } else if (wlist
->flags
.hidden
) {
1479 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1480 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1483 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1484 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1486 wRaiseFrame(wlist
->frame
->core
);
1492 wapp
->flags
.skip_next_animation
= 0;
1493 wapp
->flags
.hidden
= 0;
1495 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1496 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1497 wSetFocusTo(scr
, wapp
->last_focused
);
1498 } else if (focused
) {
1499 wSetFocusTo(scr
, focused
);
1501 wapp
->last_focused
= NULL
;
1502 if (wPreferences
.auto_arrange_icons
) {
1503 wArrangeIcons(scr
, True
);
1506 wAppIconPaint(wapp
->app_icon
);
1510 void wShowAllWindows(WScreen
* scr
)
1512 WWindow
*wwin
, *old_foc
;
1515 old_foc
= wwin
= scr
->focused_window
;
1517 if (!wwin
->flags
.internal_window
&&
1518 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1519 if (wwin
->flags
.miniaturized
) {
1520 wwin
->flags
.skip_next_animation
= 1;
1521 wDeiconifyWindow(wwin
);
1522 } else if (wwin
->flags
.hidden
) {
1523 wapp
= wApplicationOf(wwin
->main_window
);
1525 wUnhideApplication(wapp
, False
, False
);
1527 wwin
->flags
.skip_next_animation
= 1;
1528 wDeiconifyWindow(wwin
);
1534 wSetFocusTo(scr
, old_foc
);
1535 /*wRaiseFrame(old_foc->frame->core); */
1538 void wRefreshDesktop(WScreen
* scr
)
1541 XSetWindowAttributes attr
;
1543 attr
.backing_store
= NotUseful
;
1544 attr
.save_under
= False
;
1545 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1546 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1547 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1548 XMapRaised(dpy
, win
);
1549 XDestroyWindow(dpy
, win
);
1553 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1559 const int heads
= wXineramaHeads(scr
);
1562 int pf
; /* primary axis */
1563 int sf
; /* secondary axis */
1567 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1573 int isize
= wPreferences
.icon_size
;
1575 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1577 for (head
= 0; head
< heads
; ++head
) {
1579 WMRect rect
= wGetRectForHead(scr
, head
);
1581 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1582 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1585 vars
[head
].pi
= vars
[head
].si
= 0;
1586 vars
[head
].sx1
= rect
.pos
.x
;
1587 vars
[head
].sy1
= rect
.pos
.y
;
1588 vars
[head
].sw
= rect
.size
.width
;
1589 vars
[head
].sh
= rect
.size
.height
;
1590 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1591 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1595 if (scr
->dock
->on_right_side
)
1596 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1598 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1602 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1603 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1604 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1605 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1607 /* icon yard boundaries */
1608 if (wPreferences
.icon_yard
& IY_VERT
) {
1609 vars
[head
].pf
= vars
[head
].fullH
;
1610 vars
[head
].sf
= vars
[head
].fullW
;
1612 vars
[head
].pf
= vars
[head
].fullW
;
1613 vars
[head
].sf
= vars
[head
].fullH
;
1615 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1616 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1619 vars
[head
].xo
= vars
[head
].sx1
;
1622 if (wPreferences
.icon_yard
& IY_TOP
) {
1623 vars
[head
].yo
= vars
[head
].sy1
;
1626 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1631 #define X ((wPreferences.icon_yard & IY_VERT) \
1632 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1633 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1635 #define Y ((wPreferences.icon_yard & IY_VERT) \
1636 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1637 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1639 /* arrange application icons */
1640 aicon
= scr
->app_icon_list
;
1641 /* reverse them to avoid unnecessarily sliding of icons */
1642 while (aicon
&& aicon
->next
)
1643 aicon
= aicon
->next
;
1646 if (!aicon
->docked
) {
1647 /* CHECK: can icon be NULL here ? */
1648 /* The intention here is to place the AppIcon on the head that
1649 * contains most of the applications _main_ window. */
1650 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1652 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1654 if (!wPreferences
.no_animations
) {
1655 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1657 #endif /* ANIMATIONS */
1659 wAppIconMove(aicon
, X
, Y
);
1661 if (vars
[head
].pi
>= vars
[head
].pf
) {
1666 aicon
= aicon
->prev
;
1669 /* arrange miniwindows */
1670 wwin
= scr
->focused_window
;
1671 /* reverse them to avoid unnecessarily shuffling */
1672 while (wwin
&& wwin
->prev
)
1676 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1677 (wwin
->frame
->workspace
== scr
->current_workspace
||
1678 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1680 head
= wGetHeadForWindow(wwin
);
1682 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1683 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1685 if (wPreferences
.no_animations
) {
1686 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1688 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1689 wwin
->icon_y
, X
, Y
);
1692 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1693 #endif /* ANIMATIONS */
1699 if (vars
[head
].pi
>= vars
[head
].pf
) {
1706 wwin
->flags
.icon_moved
= 0;
1708 /* we reversed the order, so we use next */
1715 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1717 WScreen
*scr
= wwin
->screen_ptr
;
1720 wwin
->flags
.selected
= 1;
1721 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1723 if (!HAS_BORDER(wwin
)) {
1724 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1727 if (!scr
->selected_windows
)
1728 scr
->selected_windows
= WMCreateArray(4);
1729 WMAddToArray(scr
->selected_windows
, wwin
);
1731 wwin
->flags
.selected
= 0;
1732 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1734 if (!HAS_BORDER(wwin
)) {
1735 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1738 if (scr
->selected_windows
) {
1739 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1744 void wMakeWindowVisible(WWindow
* wwin
)
1746 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1747 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1749 if (wwin
->flags
.shaded
) {
1750 wUnshadeWindow(wwin
);
1752 if (wwin
->flags
.hidden
) {
1755 app
= wApplicationOf(wwin
->main_window
);
1757 /* trick to get focus to this window */
1758 app
->last_focused
= wwin
;
1759 wUnhideApplication(app
, False
, False
);
1762 if (wwin
->flags
.miniaturized
) {
1763 wDeiconifyWindow(wwin
);
1765 if (!WFLAGP(wwin
, no_focusable
))
1766 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1767 wRaiseFrame(wwin
->frame
->core
);
1772 * Do the animation while shading (called with what = SHADE)
1773 * or unshading (what = UNSHADE).
1776 static void shade_animate(WWindow
*wwin
, Bool what
)
1779 time_t time0
= time(NULL
);
1781 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1786 if (!wwin
->screen_ptr
->flags
.startup
) {
1787 /* do the shading animation */
1788 h
= wwin
->frame
->core
->height
;
1789 s
= h
/ SHADE_STEPS
;
1792 w
= wwin
->frame
->core
->width
;
1793 y
= wwin
->frame
->top_width
;
1794 while (h
> wwin
->frame
->top_width
+ 1) {
1795 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1796 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1799 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1802 if (SHADE_DELAY
> 0) {
1803 wusleep(SHADE_DELAY
* 1000L);
1810 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1815 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1816 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1817 s
= abs(y
) / SHADE_STEPS
;
1820 w
= wwin
->frame
->core
->width
;
1821 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1823 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1824 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1825 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1827 if (SHADE_DELAY
> 0) {
1828 wusleep(SHADE_DELAY
* 2000L / 3);
1835 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1839 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);