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 /******* Local Variables *******/
70 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
71 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
72 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
73 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
74 SHADE_STEPS_US
, SHADE_DELAY_US
}};
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1
, Time t2
)
87 return (diff
< 60000) ? 1 : -1;
91 *----------------------------------------------------------------------
93 * Changes the window focus to the one passed as argument.
94 * If the window to focus is not already focused, it will be brought
95 * to the head of the list of windows. Previously focused window is
99 * Window list may be reordered and the window focus is changed.
101 *----------------------------------------------------------------------
103 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
105 static WScreen
*old_scr
= NULL
;
107 WWindow
*old_focused
;
108 WWindow
*focused
= scr
->focused_window
;
109 Time timestamp
= LastTimestamp
;
110 WApplication
*oapp
= NULL
, *napp
= NULL
;
113 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
118 old_focused
= old_scr
->focused_window
;
120 LastFocusChange
= timestamp
;
123 oapp
= wApplicationOf(old_focused
->main_window
);
126 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
128 wWindowUnfocus(old_focused
);
131 wAppMenuUnmap(oapp
->menu
);
133 wApplicationDeactivate(oapp
);
137 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
139 } else if (old_scr
!= scr
&& old_focused
) {
140 wWindowUnfocus(old_focused
);
143 wasfocused
= wwin
->flags
.focused
;
144 napp
= wApplicationOf(wwin
->main_window
);
146 /* remember last workspace where the app has been */
148 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
149 napp
->last_workspace
= wwin
->frame
->workspace
;
152 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
153 /* install colormap if colormap mode is lock mode */
154 if (wPreferences
.colormap_mode
== WCM_CLICK
)
155 wColormapInstallForWindow(scr
, wwin
);
157 /* set input focus */
158 switch (wwin
->focus_mode
) {
160 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
164 case WFM_LOCALLY_ACTIVE
:
165 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
168 case WFM_GLOBALLY_ACTIVE
:
172 if (wwin
->protocols
.TAKE_FOCUS
) {
173 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
177 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
179 if (WFLAGP(wwin
, no_focusable
))
182 /* if this is not the focused window focus it */
183 if (focused
!= wwin
) {
184 /* change the focus window list order */
186 wwin
->prev
->next
= wwin
->next
;
189 wwin
->next
->prev
= wwin
->prev
;
191 wwin
->prev
= focused
;
192 focused
->next
= wwin
;
194 scr
->focused_window
= wwin
;
196 if (oapp
&& oapp
!= napp
) {
197 wAppMenuUnmap(oapp
->menu
);
199 wApplicationDeactivate(oapp
);
204 wWindowFocus(wwin
, focused
);
206 if (napp
&& !wasfocused
) {
208 wUserMenuRefreshInstances(napp
->menu
, wwin
);
209 #endif /* USER_MENU */
211 if (wwin
->flags
.mapped
)
212 wAppMenuMap(napp
->menu
, wwin
);
214 wApplicationActivate(napp
);
222 void wShadeWindow(WWindow
*wwin
)
225 if (wwin
->flags
.shaded
)
228 XLowerWindow(dpy
, wwin
->client_win
);
229 shade_animate(wwin
, SHADE
);
231 wwin
->flags
.skip_next_animation
= 0;
232 wwin
->flags
.shaded
= 1;
233 wwin
->flags
.mapped
= 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
236 XUnmapWindow(dpy
, wwin
->client_win
);
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
242 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
243 wWindowSynthConfigureNotify(wwin
);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
252 if (!wwin
->screen_ptr
->flags
.startup
) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
259 void wUnshadeWindow(WWindow
*wwin
)
262 if (!wwin
->flags
.shaded
)
265 wwin
->flags
.shaded
= 0;
266 wwin
->flags
.mapped
= 1;
267 XMapWindow(dpy
, wwin
->client_win
);
269 shade_animate(wwin
, UNSHADE
);
271 wwin
->flags
.skip_next_animation
= 0;
272 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
273 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
275 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
276 wWindowSynthConfigureNotify(wwin
);
279 wClientSetState(wwin, NormalState, None);
281 /* if the window is focused, set the focus again as it was disabled during
283 if (wwin
->flags
.focused
)
284 wSetFocusTo(wwin
->screen_ptr
, wwin
);
286 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
289 /* Set the old coordinates using the current values */
290 static void save_old_geometry(WWindow
*wwin
)
292 wwin
->old_geometry
.width
= wwin
->client
.width
;
293 wwin
->old_geometry
.height
= wwin
->client
.height
;
294 wwin
->old_geometry
.x
= wwin
->frame_x
;
295 wwin
->old_geometry
.y
= wwin
->frame_y
;
298 void wMaximizeWindow(WWindow
* wwin
, int directions
)
301 unsigned int new_width
, new_height
, half_scr_width
;
302 WArea usableArea
, totalArea
;
306 if (!IS_RESIZABLE(wwin
))
309 if (!HAS_BORDER(wwin
))
312 /* the size to adjust the geometry */
313 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
315 /* save old coordinates before we change the current values */
316 save_old_geometry(wwin
);
320 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
321 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
322 usableArea
= totalArea
;
324 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
325 WScreen
*scr
= wwin
->screen_ptr
;
328 if (directions
& MAX_KEYBOARD
)
329 head
= wGetHeadForWindow(wwin
);
331 head
= wGetHeadForPointerLocation(scr
);
333 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
336 /* Only save directions, not kbd or xinerama hints */
337 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
339 if (WFLAGP(wwin
, full_maximize
)) {
340 usableArea
= totalArea
;
342 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
344 if (wwin
->flags
.shaded
) {
345 wwin
->flags
.skip_next_animation
= 1;
346 wUnshadeWindow(wwin
);
349 if (directions
& MAX_HORIZONTAL
) {
350 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
351 new_x
= usableArea
.x1
;
352 } else if (directions
& MAX_LEFTHALF
) {
353 new_width
= half_scr_width
- adj_size
;
354 new_x
= usableArea
.x1
;
355 } else if (directions
& MAX_RIGHTHALF
) {
356 new_width
= half_scr_width
- adj_size
;
357 new_x
= usableArea
.x1
+ half_scr_width
;
359 new_x
= wwin
->frame_x
;
360 new_width
= wwin
->frame
->core
->width
;
363 if (directions
& MAX_VERTICAL
) {
364 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
365 new_y
= usableArea
.y1
;
366 if (WFLAGP(wwin
, full_maximize
)) {
367 new_y
-= wwin
->frame
->top_width
;
368 new_height
+= wwin
->frame
->bottom_width
- 1;
371 new_y
= wwin
->frame_y
;
372 new_height
= wwin
->frame
->core
->height
;
375 if (!WFLAGP(wwin
, full_maximize
)) {
376 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
379 if (directions
& MAX_MAXIMUS
) {
380 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
381 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
382 new_y
-= wwin
->frame
->top_width
;
383 new_height
+= wwin
->frame
->top_width
- 1;
387 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
389 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
390 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
392 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
394 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
396 /* set maximization state */
397 wwin
->flags
.maximized
= directions
;
401 * Maximus: tiled maximization (maximize without overlapping other windows)
403 * The window to be maximized will be denoted by w_0 (sub-index zero)
404 * while the windows which will stop the maximization of w_0 are denoted by w_j.
406 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
407 unsigned int *new_width
, unsigned int *new_height
)
410 int x_0
= wwin
->frame_x
;
411 int y_0
= wwin
->frame_y
;
412 int width_0
= wwin
->frame
->core
->width
;
413 int height_0
= wwin
->frame
->core
->height
;
414 int botton_0
= y_0
+ height_0
;
415 int right_border_0
= x_0
+ width_0
;
416 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
417 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
418 int x_intsect
, y_intsect
;
419 short int tbar_height_0
= 0, rbar_height_0
= 0;
420 short int bd_width_0
= 0, bd_width_j
= 0;
421 short int adjust_height
;
423 /* Try to fully maximize first, then readjust later */
424 new_x_0
= usableArea
.x1
;
425 new_y_0
= usableArea
.y1
;
426 new_botton_0
= usableArea
.y2
;
427 new_right_border_0
= usableArea
.x2
;
429 if (HAS_TITLEBAR(wwin
))
430 tbar_height_0
= TITLEBAR_HEIGHT
;
431 if (HAS_RESIZEBAR(wwin
))
432 rbar_height_0
= RESIZEBAR_HEIGHT
;
433 if (HAS_BORDER(wwin
))
434 bd_width_0
= FRAME_BORDER_WIDTH
;
436 /* the lengths to be subtracted if w_0 has titlebar, etc */
437 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
440 /* The focused window is always the last in the list */
442 /* ignore windows in other workspaces etc */
443 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
444 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
451 bd_width_j
= FRAME_BORDER_WIDTH
;
456 * Set the w_j window coordinates. It is convenient
457 * to not use "corrected" sizes for width and height,
458 * otherwise bottom_j and right_border_j would be
461 x_j
= tmp
->frame_x
- bd_width_j
;
462 y_j
= tmp
->frame_y
- bd_width_j
;
463 width_j
= tmp
->frame
->core
->width
;
464 height_j
= tmp
->frame
->core
->height
;
465 botton_j
= y_j
+ height_j
+ bd_width_j
;
466 top_j
= y_j
- bd_width_j
;
467 right_border_j
= x_j
+ width_j
+ bd_width_j
;
469 /* Try to maximize in the y direction first */
470 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
471 if (x_intsect
!= 0) {
472 /* TODO: Consider the case when coords are equal */
473 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
474 /* w_0 is below the botton of w_j */
477 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
478 /* The botton of w_0 is above the top of w_j */
479 new_botton_0
= top_j
;
486 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
487 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
494 bd_width_j
= FRAME_BORDER_WIDTH
;
498 /* set the w_j window coordinates */
499 x_j
= tmp
->frame_x
- bd_width_j
;
500 y_j
= tmp
->frame_y
- bd_width_j
;
501 width_j
= tmp
->frame
->core
->width
;
502 height_j
= tmp
->frame
->core
->height
;
503 botton_j
= y_j
+ height_j
+ bd_width_j
;
504 top_j
= y_j
- bd_width_j
;
505 right_border_j
= x_j
+ width_j
+ bd_width_j
;
508 * Use the updated y coordinates from the above step to account
509 * the possibility that the new value of y_0 will have different
510 * intersections with w_j
512 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
513 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
514 if (y_intsect
!= 0) {
515 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
516 /* w_0 is completely to the right of w_j */
517 new_x_0
= right_border_j
+ 1;
519 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
520 /* w_0 is completely to the left of w_j */
521 new_right_border_0
= x_j
- 1;
526 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
529 *new_height
= new_height_0
;
530 *new_width
= new_right_border_0
- new_x_0
;
533 void wUnmaximizeWindow(WWindow
* wwin
)
536 WMRect old_geom_rect
;
540 if (!wwin
->flags
.maximized
)
543 if (wwin
->flags
.shaded
) {
544 wwin
->flags
.skip_next_animation
= 1;
545 wUnshadeWindow(wwin
);
547 /* Use old coordinates if they are set, current values otherwise */
548 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
549 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
550 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
551 x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
552 y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
553 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
554 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
556 wwin
->flags
.maximized
= 0;
557 wWindowConfigure(wwin
, x
, y
, w
, h
);
559 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
562 void wFullscreenWindow(WWindow
* wwin
)
567 if (wwin
->flags
.fullscreen
)
570 wwin
->flags
.fullscreen
= True
;
572 wWindowConfigureBorders(wwin
);
574 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
576 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
577 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
578 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
579 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
581 head
= wGetHeadForWindow(wwin
);
582 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
583 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
585 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
588 void wUnfullscreenWindow(WWindow
* wwin
)
590 if (!wwin
->flags
.fullscreen
)
593 wwin
->flags
.fullscreen
= False
;
595 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
596 if (WFLAGP(wwin
, sunken
)) {
597 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
598 } else if (WFLAGP(wwin
, floating
)) {
599 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
601 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
605 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
606 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
608 wWindowConfigureBorders(wwin
);
610 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
611 wFrameWindowPaint(wwin->frame);
614 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
618 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
620 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
621 float cx
, cy
, cw
, ch
;
622 float xstep
, ystep
, wstep
, hstep
;
625 float angle
, final_angle
, delta
;
627 xstep
= (float)(fx
- x
) / steps
;
628 ystep
= (float)(fy
- y
) / steps
;
629 wstep
= (float)(fw
- w
) / steps
;
630 hstep
= (float)(fh
- h
) / steps
;
637 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
638 delta
= (float)(final_angle
/ FRAMES
);
639 for (angle
= 0;; angle
+= delta
) {
640 if (angle
> final_angle
)
643 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
644 dch
= (ch
/ 2) * cos(angle
);
645 midy
= cy
+ (ch
/ 2);
647 points
[0].x
= cx
+ dx
;
648 points
[0].y
= midy
- dch
;
649 points
[1].x
= cx
+ cw
- dx
;
650 points
[1].y
= points
[0].y
;
651 points
[2].x
= cx
+ cw
+ dx
;
652 points
[2].y
= midy
+ dch
;
653 points
[3].x
= cx
- dx
;
654 points
[3].y
= points
[2].y
;
655 points
[4].x
= points
[0].x
;
656 points
[4].y
= points
[0].y
;
659 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
661 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
662 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
667 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
673 if (angle
>= final_angle
)
683 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
685 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
686 float cx
, cy
, cw
, ch
;
687 float xstep
, ystep
, wstep
, hstep
;
689 float angle
, final_angle
, a
, d
, delta
;
696 xstep
= (float)(fx
- x
) / steps
;
697 ystep
= (float)(fy
- y
) / steps
;
698 wstep
= (float)(fw
- w
) / steps
;
699 hstep
= (float)(fh
- h
) / steps
;
706 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
707 delta
= (float)(final_angle
/ FRAMES
);
708 for (angle
= 0;; angle
+= delta
) {
709 if (angle
> final_angle
)
713 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
715 points
[0].x
= cx
+ cos(angle
- a
) * d
;
716 points
[0].y
= cy
+ sin(angle
- a
) * d
;
717 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
718 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
719 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
720 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
721 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
722 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
723 points
[4].x
= cx
+ cos(angle
- a
) * d
;
724 points
[4].y
= cy
+ sin(angle
- a
) * d
;
726 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
728 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
729 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
734 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
740 if (angle
>= final_angle
)
749 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
751 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
752 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
753 float xstep
, ystep
, wstep
, hstep
;
756 xstep
= (float)(fx
- x
) / steps
;
757 ystep
= (float)(fy
- y
) / steps
;
758 wstep
= (float)(fw
- w
) / steps
;
759 hstep
= (float)(fh
- h
) / steps
;
761 for (j
= 0; j
< FRAMES
; j
++) {
768 for (i
= 0; i
< steps
; i
++) {
769 for (j
= 0; j
< FRAMES
; j
++) {
770 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
771 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
774 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
775 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
779 for (j
= 0; j
< FRAMES
; j
++) {
780 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
781 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
782 if (j
< FRAMES
- 1) {
796 for (j
= 0; j
< FRAMES
; j
++) {
797 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
800 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
801 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
991 && !wwin
->flags
.net_handle_icon
994 if (!wwin
->flags
.icon_moved
) {
995 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
997 wwin
->icon
= wIconCreate(wwin
);
999 wwin
->icon
->mapped
= 1;
1002 wwin
->flags
.miniaturized
= 1;
1003 wwin
->flags
.mapped
= 0;
1005 /* unmap transients */
1007 unmapTransientsFor(wwin
);
1010 XUngrabPointer(dpy
, CurrentTime
);
1012 /* let all Expose events arrive so that we can repaint
1013 * something before the animation starts (and the server is grabbed) */
1016 if (wPreferences
.disable_miniwindows
1018 || wwin
->flags
.net_handle_icon
1021 wClientSetState(wwin
, IconicState
, None
);
1023 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1027 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1028 && !wPreferences
.no_animations
) {
1031 if (!wPreferences
.disable_miniwindows
1033 && !wwin
->flags
.net_handle_icon
1038 iw
= wwin
->icon
->core
->width
;
1039 ih
= wwin
->icon
->core
->height
;
1042 if (wwin
->flags
.net_handle_icon
) {
1052 iw
= wwin
->screen_ptr
->scr_width
;
1053 ih
= wwin
->screen_ptr
->scr_height
;
1056 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1057 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1062 wwin
->flags
.skip_next_animation
= 0;
1064 if (!wPreferences
.disable_miniwindows
1066 && !wwin
->flags
.net_handle_icon
1070 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1071 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1073 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1075 AddToStackList(wwin
->icon
->core
);
1077 wLowerFrame(wwin
->icon
->core
);
1081 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1084 * It doesn't seem to be working and causes button event hangup
1085 * when deiconifying a transient window.
1086 setupIconGrabs(wwin->icon);
1088 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1089 && wPreferences
.focus_mode
== WKF_CLICK
) {
1094 if (!WFLAGP(tmp
, no_focusable
)
1095 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1096 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1100 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1101 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1102 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1105 if (!wwin
->screen_ptr
->flags
.startup
) {
1106 /* Catch up with events not processed while animation was running */
1107 Window clientwin
= wwin
->client_win
;
1109 ProcessPendingEvents();
1111 /* the window can disappear while ProcessPendingEvents() runs */
1112 if (!wWindowFor(clientwin
)) {
1119 /* maybe we want to do this regardless of net_handle_icon
1120 * it seems to me we might break behaviour this way.
1122 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1124 && !wwin
->flags
.net_handle_icon
1127 wIconSelect(wwin
->icon
);
1129 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1131 if (wPreferences
.auto_arrange_icons
)
1132 wArrangeIcons(wwin
->screen_ptr
, True
);
1135 void wDeiconifyWindow(WWindow
* wwin
)
1138 /* we're hiding for show_desktop */
1139 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1140 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1142 int netwm_hidden
= False
;
1146 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1148 if (!wwin
->flags
.miniaturized
)
1151 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1152 WWindow
*owner
= recursiveTransientFor(wwin
);
1154 if (owner
&& owner
->flags
.miniaturized
) {
1155 wDeiconifyWindow(owner
);
1156 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1157 wRaiseFrame(wwin
->frame
->core
);
1162 wwin
->flags
.miniaturized
= 0;
1164 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1165 wwin
->flags
.mapped
= 1;
1168 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1169 /* maybe we want to do this regardless of net_handle_icon
1170 * it seems to me we might break behaviour this way.
1172 if (!wPreferences
.disable_miniwindows
1174 && !wwin
->flags
.net_handle_icon
1176 && wwin
->icon
!= NULL
) {
1177 if (wwin
->icon
->selected
)
1178 wIconSelect(wwin
->icon
);
1180 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1184 /* if the window is in another workspace, do it silently */
1185 if (!netwm_hidden
) {
1187 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1188 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1191 if (!wPreferences
.disable_miniwindows
1193 && !wwin
->flags
.net_handle_icon
1198 iw
= wwin
->icon
->core
->width
;
1199 ih
= wwin
->icon
->core
->height
;
1202 if (wwin
->flags
.net_handle_icon
) {
1212 iw
= wwin
->screen_ptr
->scr_width
;
1213 ih
= wwin
->screen_ptr
->scr_height
;
1216 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1217 wwin
->frame_x
, wwin
->frame_y
,
1218 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1220 #endif /* ANIMATIONS */
1221 wwin
->flags
.skip_next_animation
= 0;
1223 if (!wwin
->flags
.shaded
) {
1224 XMapWindow(dpy
, wwin
->client_win
);
1226 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1227 wRaiseFrame(wwin
->frame
->core
);
1228 if (!wwin
->flags
.shaded
) {
1229 wClientSetState(wwin
, NormalState
, None
);
1231 mapTransientsFor(wwin
);
1234 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1236 && !wwin
->flags
.net_handle_icon
1239 RemoveFromStackList(wwin
->icon
->core
);
1240 /* removeIconGrabs(wwin->icon); */
1241 wIconDestroy(wwin
->icon
);
1245 if (!netwm_hidden
) {
1248 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1251 if (!wwin
->screen_ptr
->flags
.startup
) {
1252 /* Catch up with events not processed while animation was running */
1253 Window clientwin
= wwin
->client_win
;
1255 ProcessPendingEvents();
1257 /* the window can disappear while ProcessPendingEvents() runs */
1258 if (!wWindowFor(clientwin
)) {
1265 if (wPreferences
.auto_arrange_icons
) {
1266 wArrangeIcons(wwin
->screen_ptr
, True
);
1269 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1271 /* In case we were shaded and iconified, also unshade */
1273 wUnshadeWindow(wwin
);
1276 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1278 if (wwin
->flags
.miniaturized
) {
1280 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1281 wwin
->icon
->mapped
= 0;
1283 wwin
->flags
.hidden
= 1;
1285 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1289 if (wwin
->flags
.inspector_open
) {
1290 wHideInspectorForWindow(wwin
);
1293 wwin
->flags
.hidden
= 1;
1296 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1300 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1301 !wwin
->flags
.skip_next_animation
&& animate
) {
1302 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1303 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1304 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1307 wwin
->flags
.skip_next_animation
= 0;
1309 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1312 void wHideOtherApplications(WWindow
* awin
)
1319 wwin
= awin
->screen_ptr
->focused_window
;
1323 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1324 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1325 && !wwin
->flags
.internal_window
1326 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1328 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1329 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1330 wwin
->flags
.skip_next_animation
= 1;
1331 wIconifyWindow(wwin
);
1333 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1334 tapp
= wApplicationOf(wwin
->main_window
);
1336 tapp
->flags
.skip_next_animation
= 1;
1337 wHideApplication(tapp
);
1339 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1340 wwin
->flags
.skip_next_animation
= 1;
1341 wIconifyWindow(wwin
);
1349 wSetFocusTo(awin->screen_ptr, awin);
1353 void wHideApplication(WApplication
* wapp
)
1361 wwarning("trying to hide a non grouped window");
1364 if (!wapp
->main_window_desc
) {
1365 wwarning("group leader not found for window group");
1368 scr
= wapp
->main_window_desc
->screen_ptr
;
1370 wlist
= scr
->focused_window
;
1374 if (wlist
->main_window
== wapp
->main_window
)
1375 wapp
->last_focused
= wlist
;
1377 wapp
->last_focused
= NULL
;
1379 animate
= !wapp
->flags
.skip_next_animation
;
1382 if (wlist
->main_window
== wapp
->main_window
) {
1383 if (wlist
->flags
.focused
) {
1386 if (wapp
->app_icon
) {
1387 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1388 wapp
->app_icon
->y_pos
, wlist
, animate
);
1392 wlist
= wlist
->prev
;
1395 wapp
->flags
.skip_next_animation
= 0;
1398 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1399 wlist
= scr
->focused_window
;
1401 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1402 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1404 wlist
= wlist
->prev
;
1406 wSetFocusTo(scr
, wlist
);
1408 wSetFocusTo(scr
, NULL
);
1412 wapp
->flags
.hidden
= 1;
1414 if (wPreferences
.auto_arrange_icons
) {
1415 wArrangeIcons(scr
, True
);
1419 wAppIconPaint(wapp
->app_icon
);
1423 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1425 if (bringToCurrentWS
)
1426 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1428 wwin
->flags
.hidden
= 0;
1431 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1432 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1433 icon
->core
->width
, icon
->core
->height
,
1434 wwin
->frame_x
, wwin
->frame_y
,
1435 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1438 wwin
->flags
.skip_next_animation
= 0;
1439 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1440 XMapWindow(dpy
, wwin
->client_win
);
1441 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1442 wClientSetState(wwin
, NormalState
, None
);
1443 wwin
->flags
.mapped
= 1;
1444 wRaiseFrame(wwin
->frame
->core
);
1446 if (wwin
->flags
.inspector_open
) {
1447 wUnhideInspectorForWindow(wwin
);
1450 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1453 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1456 WWindow
*wlist
, *next
;
1457 WWindow
*focused
= NULL
;
1463 scr
= wapp
->main_window_desc
->screen_ptr
;
1464 wlist
= scr
->focused_window
;
1468 /* goto beginning of list */
1470 wlist
= wlist
->prev
;
1472 animate
= !wapp
->flags
.skip_next_animation
;
1477 if (wlist
->main_window
== wapp
->main_window
) {
1478 if (wlist
->flags
.focused
)
1480 else if (!focused
|| !focused
->flags
.focused
)
1483 if (wlist
->flags
.miniaturized
) {
1484 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1485 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1486 if (!wlist
->icon
->mapped
) {
1489 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1490 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1491 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1495 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1496 wlist
->icon
->mapped
= 1;
1498 wRaiseFrame(wlist
->icon
->core
);
1500 if (bringToCurrentWS
)
1501 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1502 wlist
->flags
.hidden
= 0;
1503 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1504 wDeiconifyWindow(wlist
);
1506 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1507 } else if (wlist
->flags
.shaded
) {
1508 if (bringToCurrentWS
)
1509 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1510 wlist
->flags
.hidden
= 0;
1511 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1512 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1514 wUnshadeWindow(wlist
);
1515 wRaiseFrame(wlist
->frame
->core
);
1518 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1519 } else if (wlist
->flags
.hidden
) {
1520 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1521 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1524 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1525 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1527 wRaiseFrame(wlist
->frame
->core
);
1533 wapp
->flags
.skip_next_animation
= 0;
1534 wapp
->flags
.hidden
= 0;
1536 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1537 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1538 wSetFocusTo(scr
, wapp
->last_focused
);
1539 } else if (focused
) {
1540 wSetFocusTo(scr
, focused
);
1542 wapp
->last_focused
= NULL
;
1543 if (wPreferences
.auto_arrange_icons
) {
1544 wArrangeIcons(scr
, True
);
1547 wAppIconPaint(wapp
->app_icon
);
1551 void wShowAllWindows(WScreen
* scr
)
1553 WWindow
*wwin
, *old_foc
;
1556 old_foc
= wwin
= scr
->focused_window
;
1558 if (!wwin
->flags
.internal_window
&&
1559 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1560 if (wwin
->flags
.miniaturized
) {
1561 wwin
->flags
.skip_next_animation
= 1;
1562 wDeiconifyWindow(wwin
);
1563 } else if (wwin
->flags
.hidden
) {
1564 wapp
= wApplicationOf(wwin
->main_window
);
1566 wUnhideApplication(wapp
, False
, False
);
1568 wwin
->flags
.skip_next_animation
= 1;
1569 wDeiconifyWindow(wwin
);
1575 wSetFocusTo(scr
, old_foc
);
1576 /*wRaiseFrame(old_foc->frame->core); */
1579 void wRefreshDesktop(WScreen
* scr
)
1582 XSetWindowAttributes attr
;
1584 attr
.backing_store
= NotUseful
;
1585 attr
.save_under
= False
;
1586 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1587 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1588 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1589 XMapRaised(dpy
, win
);
1590 XDestroyWindow(dpy
, win
);
1594 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1600 const int heads
= wXineramaHeads(scr
);
1603 int pf
; /* primary axis */
1604 int sf
; /* secondary axis */
1608 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1614 int isize
= wPreferences
.icon_size
;
1616 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1618 for (head
= 0; head
< heads
; ++head
) {
1620 WMRect rect
= wGetRectForHead(scr
, head
);
1622 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1623 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1626 vars
[head
].pi
= vars
[head
].si
= 0;
1627 vars
[head
].sx1
= rect
.pos
.x
;
1628 vars
[head
].sy1
= rect
.pos
.y
;
1629 vars
[head
].sw
= rect
.size
.width
;
1630 vars
[head
].sh
= rect
.size
.height
;
1631 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1632 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1636 if (scr
->dock
->on_right_side
)
1637 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1639 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1643 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1644 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1645 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1646 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1648 /* icon yard boundaries */
1649 if (wPreferences
.icon_yard
& IY_VERT
) {
1650 vars
[head
].pf
= vars
[head
].fullH
;
1651 vars
[head
].sf
= vars
[head
].fullW
;
1653 vars
[head
].pf
= vars
[head
].fullW
;
1654 vars
[head
].sf
= vars
[head
].fullH
;
1656 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1657 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1660 vars
[head
].xo
= vars
[head
].sx1
;
1663 if (wPreferences
.icon_yard
& IY_TOP
) {
1664 vars
[head
].yo
= vars
[head
].sy1
;
1667 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1672 #define X ((wPreferences.icon_yard & IY_VERT) \
1673 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1674 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1676 #define Y ((wPreferences.icon_yard & IY_VERT) \
1677 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1678 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1680 /* arrange application icons */
1681 aicon
= scr
->app_icon_list
;
1682 /* reverse them to avoid unnecessarily sliding of icons */
1683 while (aicon
&& aicon
->next
)
1684 aicon
= aicon
->next
;
1687 if (!aicon
->docked
) {
1688 /* CHECK: can icon be NULL here ? */
1689 /* The intention here is to place the AppIcon on the head that
1690 * contains most of the applications _main_ window. */
1691 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1693 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1695 if (!wPreferences
.no_animations
) {
1696 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1698 #endif /* ANIMATIONS */
1700 wAppIconMove(aicon
, X
, Y
);
1702 if (vars
[head
].pi
>= vars
[head
].pf
) {
1707 aicon
= aicon
->prev
;
1710 /* arrange miniwindows */
1711 wwin
= scr
->focused_window
;
1712 /* reverse them to avoid unnecessarily shuffling */
1713 while (wwin
&& wwin
->prev
)
1717 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1718 (wwin
->frame
->workspace
== scr
->current_workspace
||
1719 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1721 head
= wGetHeadForWindow(wwin
);
1723 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1724 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1726 if (wPreferences
.no_animations
) {
1727 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1729 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1730 wwin
->icon_y
, X
, Y
);
1733 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1734 #endif /* ANIMATIONS */
1740 if (vars
[head
].pi
>= vars
[head
].pf
) {
1747 wwin
->flags
.icon_moved
= 0;
1749 /* we reversed the order, so we use next */
1757 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1761 int pf
; /* primary axis */
1762 int sf
; /* secondary axis */
1766 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1770 int isize
= wPreferences
.icon_size
;
1773 * Find out screen boundaries.
1777 * Allows each head to have miniwindows
1779 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1783 sw
= rect
.size
.width
;
1784 sh
= rect
.size
.height
;
1788 if (scr
->dock
->on_right_side
)
1789 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1791 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1794 sw
= isize
* (scr
->scr_width
/ isize
);
1795 sh
= isize
* (scr
->scr_height
/ isize
);
1797 sw
= isize
* (sw
/ isize
);
1798 sh
= isize
* (sh
/ isize
);
1800 fullW
= (sx2
- sx1
) / isize
;
1801 fullH
= (sy2
- sy1
) / isize
;
1803 /* icon yard boundaries */
1804 if (wPreferences
.icon_yard
& IY_VERT
) {
1811 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1818 if (wPreferences
.icon_yard
& IY_TOP
) {
1826 /* arrange icons putting the most recently focused window
1827 * as the last icon */
1828 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1829 : xo + xs*(pi*isize))
1830 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1831 : yo + ys*(si*isize))
1833 /* arrange application icons */
1834 aicon
= scr
->app_icon_list
;
1835 /* reverse them to avoid unnecessarily sliding of icons */
1836 while (aicon
&& aicon
->next
)
1837 aicon
= aicon
->next
;
1842 if (!aicon
->docked
) {
1843 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1845 if (!wPreferences
.no_animations
) {
1846 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1848 #endif /* ANIMATIONS */
1850 wAppIconMove(aicon
, X
, Y
);
1853 /* we reversed the order so we use prev */
1854 aicon
= aicon
->prev
;
1861 /* arrange miniwindows */
1863 wwin
= scr
->focused_window
;
1864 /* reverse them to avoid unnecessarily shuffling */
1865 while (wwin
&& wwin
->prev
)
1869 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1870 (wwin
->frame
->workspace
== scr
->current_workspace
||
1871 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1873 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1874 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1876 if (wPreferences
.no_animations
) {
1877 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1879 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1880 wwin
->icon_y
, X
, Y
);
1883 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1884 #endif /* ANIMATIONS */
1892 wwin
->flags
.icon_moved
= 0;
1894 /* we reversed the order, so we use next */
1904 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1906 WScreen
*scr
= wwin
->screen_ptr
;
1909 wwin
->flags
.selected
= 1;
1910 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1912 if (!HAS_BORDER(wwin
)) {
1913 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1916 if (!scr
->selected_windows
)
1917 scr
->selected_windows
= WMCreateArray(4);
1918 WMAddToArray(scr
->selected_windows
, wwin
);
1920 wwin
->flags
.selected
= 0;
1921 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1923 if (!HAS_BORDER(wwin
)) {
1924 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1927 if (scr
->selected_windows
) {
1928 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1933 void wMakeWindowVisible(WWindow
* wwin
)
1935 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1936 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1938 if (wwin
->flags
.shaded
) {
1939 wUnshadeWindow(wwin
);
1941 if (wwin
->flags
.hidden
) {
1944 app
= wApplicationOf(wwin
->main_window
);
1946 /* trick to get focus to this window */
1947 app
->last_focused
= wwin
;
1948 wUnhideApplication(app
, False
, False
);
1951 if (wwin
->flags
.miniaturized
) {
1952 wDeiconifyWindow(wwin
);
1954 if (!WFLAGP(wwin
, no_focusable
))
1955 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1956 wRaiseFrame(wwin
->frame
->core
);
1961 * Do the animation while shading (called with what = SHADE)
1962 * or unshading (what = UNSHADE).
1965 static void shade_animate(WWindow
*wwin
, Bool what
)
1968 time_t time0
= time(NULL
);
1970 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1975 if (!wwin
->screen_ptr
->flags
.startup
) {
1976 /* do the shading animation */
1977 h
= wwin
->frame
->core
->height
;
1978 s
= h
/ SHADE_STEPS
;
1981 w
= wwin
->frame
->core
->width
;
1982 y
= wwin
->frame
->top_width
;
1983 while (h
> wwin
->frame
->top_width
+ 1) {
1984 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1985 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1988 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1991 if (SHADE_DELAY
> 0) {
1992 wusleep(SHADE_DELAY
* 1000L);
1999 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2004 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2005 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2006 s
= abs(y
) / SHADE_STEPS
;
2009 w
= wwin
->frame
->core
->width
;
2010 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2012 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2013 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2014 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2016 if (SHADE_DELAY
> 0) {
2017 wusleep(SHADE_DELAY
* 2000L / 3);
2024 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2028 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2033 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
2034 #endif /* ANIMATIONS */