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"
52 /****** Global Variables ******/
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
56 extern Cursor wCursor
[WCUR_LAST
];
58 extern WPreferences wPreferences
;
60 extern Atom _XA_WM_TAKE_FOCUS
;
62 extern void ProcessPendingEvents();
63 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
65 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
,
66 int *new_y
, int *new_width
, int *new_height
);
68 /******* Local Variables *******/
74 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
75 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
76 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
77 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
78 SHADE_STEPS_US
, SHADE_DELAY_US
}};
82 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
83 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
85 static int compareTimes(Time t1
, Time t2
)
91 return (diff
< 60000) ? 1 : -1;
95 *----------------------------------------------------------------------
97 * Changes the window focus to the one passed as argument.
98 * If the window to focus is not already focused, it will be brought
99 * to the head of the list of windows. Previously focused window is
103 * Window list may be reordered and the window focus is changed.
105 *----------------------------------------------------------------------
107 void wSetFocusTo(WScreen
* scr
, WWindow
* wwin
)
109 static WScreen
*old_scr
= NULL
;
111 WWindow
*old_focused
;
112 WWindow
*focused
= scr
->focused_window
;
113 Time timestamp
= LastTimestamp
;
114 WApplication
*oapp
= NULL
, *napp
= NULL
;
117 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
122 old_focused
= old_scr
->focused_window
;
124 LastFocusChange
= timestamp
;
127 oapp
= wApplicationOf(old_focused
->main_window
);
130 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
132 wWindowUnfocus(old_focused
);
135 wAppMenuUnmap(oapp
->menu
);
137 wApplicationDeactivate(oapp
);
141 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
143 } else if (old_scr
!= scr
&& old_focused
) {
144 wWindowUnfocus(old_focused
);
147 wasfocused
= wwin
->flags
.focused
;
148 napp
= wApplicationOf(wwin
->main_window
);
150 /* remember last workspace where the app has been */
152 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
153 napp
->last_workspace
= wwin
->frame
->workspace
;
156 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
157 /* install colormap if colormap mode is lock mode */
158 if (wPreferences
.colormap_mode
== WCM_CLICK
)
159 wColormapInstallForWindow(scr
, wwin
);
161 /* set input focus */
162 switch (wwin
->focus_mode
) {
164 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
168 case WFM_LOCALLY_ACTIVE
:
169 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
172 case WFM_GLOBALLY_ACTIVE
:
176 if (wwin
->protocols
.TAKE_FOCUS
) {
177 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
181 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
183 if (WFLAGP(wwin
, no_focusable
))
186 /* if this is not the focused window focus it */
187 if (focused
!= wwin
) {
188 /* change the focus window list order */
190 wwin
->prev
->next
= wwin
->next
;
193 wwin
->next
->prev
= wwin
->prev
;
195 wwin
->prev
= focused
;
196 focused
->next
= wwin
;
198 scr
->focused_window
= wwin
;
200 if (oapp
&& oapp
!= napp
) {
201 wAppMenuUnmap(oapp
->menu
);
203 wApplicationDeactivate(oapp
);
208 wWindowFocus(wwin
, focused
);
210 if (napp
&& !wasfocused
) {
212 wUserMenuRefreshInstances(napp
->menu
, wwin
);
213 #endif /* USER_MENU */
215 if (wwin
->flags
.mapped
)
216 wAppMenuMap(napp
->menu
, wwin
);
218 wApplicationActivate(napp
);
226 void wShadeWindow(WWindow
*wwin
)
229 if (wwin
->flags
.shaded
)
232 XLowerWindow(dpy
, wwin
->client_win
);
233 wSoundPlay(WSOUND_SHADE
);
234 shade_animate(wwin
, SHADE
);
236 wwin
->flags
.skip_next_animation
= 0;
237 wwin
->flags
.shaded
= 1;
238 wwin
->flags
.mapped
= 0;
239 /* prevent window withdrawal when getting UnmapNotify */
240 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
241 XUnmapWindow(dpy
, wwin
->client_win
);
242 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
244 /* for the client it's just like iconification */
245 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
247 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
248 wWindowSynthConfigureNotify(wwin
);
251 wClientSetState(wwin, IconicState, None);
254 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
257 if (!wwin
->screen_ptr
->flags
.startup
) {
258 /* Catch up with events not processed while animation was running */
259 ProcessPendingEvents();
264 void wUnshadeWindow(WWindow
*wwin
)
267 if (!wwin
->flags
.shaded
)
270 wwin
->flags
.shaded
= 0;
271 wwin
->flags
.mapped
= 1;
272 XMapWindow(dpy
, wwin
->client_win
);
274 wSoundPlay(WSOUND_UNSHADE
);
275 shade_animate(wwin
, UNSHADE
);
277 wwin
->flags
.skip_next_animation
= 0;
278 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
279 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
281 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
282 wWindowSynthConfigureNotify(wwin
);
285 wClientSetState(wwin, NormalState, None);
287 /* if the window is focused, set the focus again as it was disabled during
289 if (wwin
->flags
.focused
)
290 wSetFocusTo(wwin
->screen_ptr
, wwin
);
292 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
295 void wMaximizeWindow(WWindow
* wwin
, int directions
)
298 unsigned int new_width
, new_height
, half_scr_width
;
299 int changed_h
, changed_v
, shrink_h
, shrink_v
;
300 WArea usableArea
, totalArea
;
302 if (!IS_RESIZABLE(wwin
))
307 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
308 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
309 usableArea
= totalArea
;
311 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
312 WScreen
*scr
= wwin
->screen_ptr
;
315 if (directions
& MAX_KEYBOARD
)
316 head
= wGetHeadForWindow(wwin
);
318 head
= wGetHeadForPointerLocation(scr
);
320 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
323 if (WFLAGP(wwin
, full_maximize
)) {
324 usableArea
= totalArea
;
326 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
328 if (wwin
->flags
.shaded
) {
329 wwin
->flags
.skip_next_animation
= 1;
330 wUnshadeWindow(wwin
);
332 /* Only save directions, not kbd or xinerama hints */
333 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
335 changed_h
= ((wwin
->flags
.maximized
^ directions
) & MAX_HORIZONTAL
);
336 changed_v
= ((wwin
->flags
.maximized
^ directions
) & MAX_VERTICAL
);
337 shrink_h
= (changed_h
&& (directions
& MAX_HORIZONTAL
) == 0);
338 shrink_v
= (changed_v
&& (directions
& MAX_VERTICAL
) == 0);
340 if (wwin
->flags
.maximized
) {
341 /* if already maximized in some direction, we only update the
342 * appropriate old x, old y coordinates. This is necessary to
343 * allow succesive maximizations in different directions without
344 * the need to first do an un-maximize (to avoid flicker).
346 if (!(wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
))) {
347 wwin
->old_geometry
.x
= wwin
->frame_x
;
349 if (!(wwin
->flags
.maximized
& MAX_VERTICAL
)) {
350 wwin
->old_geometry
.y
= wwin
->frame_y
;
353 wwin
->old_geometry
.width
= wwin
->client
.width
;
354 wwin
->old_geometry
.height
= wwin
->client
.height
;
355 wwin
->old_geometry
.x
= wwin
->frame_x
;
356 wwin
->old_geometry
.y
= wwin
->frame_y
;
358 wwin
->flags
.maximized
= directions
;
360 if (directions
& MAX_HORIZONTAL
) {
361 new_width
= usableArea
.x2
- usableArea
.x1
;
362 if (HAS_BORDER(wwin
))
363 new_width
-= FRAME_BORDER_WIDTH
* 2;
364 new_x
= usableArea
.x1
;
365 } else if (directions
& MAX_LEFTHALF
) {
366 new_width
= half_scr_width
;
367 if (HAS_BORDER(wwin
))
368 new_width
-= FRAME_BORDER_WIDTH
* 2;
369 new_x
= usableArea
.x1
;
370 } else if (directions
& MAX_RIGHTHALF
) {
371 new_width
= half_scr_width
;
372 if (HAS_BORDER(wwin
))
373 new_width
-= FRAME_BORDER_WIDTH
* 2;
374 new_x
= usableArea
.x1
+ half_scr_width
;
375 } else if (shrink_h
) {
376 new_x
= wwin
->old_geometry
.x
;
377 new_width
= wwin
->old_geometry
.width
;
379 new_x
= wwin
->frame_x
;
380 new_width
= wwin
->frame
->core
->width
;
383 if (directions
& MAX_VERTICAL
) {
384 new_height
= usableArea
.y2
- usableArea
.y1
;
385 if (HAS_BORDER(wwin
))
386 new_height
-= FRAME_BORDER_WIDTH
* 2;
387 new_y
= usableArea
.y1
;
388 if (WFLAGP(wwin
, full_maximize
)) {
389 new_y
-= wwin
->frame
->top_width
;
390 new_height
+= wwin
->frame
->bottom_width
- 1;
392 } else if (shrink_v
) {
393 new_y
= wwin
->old_geometry
.y
;
394 new_height
= wwin
->old_geometry
.height
;
396 new_y
= wwin
->frame_y
;
397 new_height
= wwin
->frame
->core
->height
;
400 if (!WFLAGP(wwin
, full_maximize
)) {
401 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
404 if (directions
& MAX_MAXIMUS
)
405 find_Maximus_geometry(wwin
, usableArea
, &new_x
, &new_y
, &new_width
, &new_height
);
407 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
409 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
410 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
412 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
414 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
416 wSoundPlay(WSOUND_MAXIMIZE
);
420 * Maximus: tiled maximization (maximize without overlapping other windows)
422 * The window to be maximized will be denoted by w_0 (sub-index zero)
423 * while the windows which will stop the maximization of w_0 are denoted by w_j.
425 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
426 int *new_width
, int *new_height
)
429 int x_0
= wwin
->frame_x
;
430 int y_0
= wwin
->frame_y
;
431 int width_0
= wwin
->frame
->core
->width
;
432 int height_0
= wwin
->frame
->core
->height
;
433 int botton_0
= y_0
+ height_0
;
434 int right_border_0
= x_0
+ width_0
;
435 int new_x_0
, new_y_0
, new_botton_0
, new_right_border_0
, new_height_0
;
436 int x_j
, y_j
, width_j
, height_j
, botton_j
, top_j
, right_border_j
;
437 int x_intsect
, y_intsect
;
438 /* Assume that the window w_0 has titlebar etc */
439 int has_titlebar
= 1, has_resizebar
= 1, has_border
= 1;
440 int adjust_height
, adjust_width
;
442 /* Try to fully maximize first, then readjust later */
443 new_x_0
= usableArea
.x1
;
444 new_y_0
= usableArea
.y1
;
445 new_botton_0
= usableArea
.y2
;
446 new_right_border_0
= usableArea
.x2
;
448 if (!HAS_TITLEBAR(wwin
))
450 if (!HAS_RESIZEBAR(wwin
))
452 if (!HAS_BORDER(wwin
))
455 /* the lengths to be subtracted if w_0 has titlebar, etc */
456 adjust_height
= TITLEBAR_HEIGHT
* has_titlebar
457 + 2 * FRAME_BORDER_WIDTH
* has_border
+ RESIZEBAR_HEIGHT
* has_resizebar
;
458 adjust_width
= 2 * FRAME_BORDER_WIDTH
* has_border
;
461 /* TODO: Is the focused window always the last in the list? */
463 /* ignore windows in other workspaces or minimized */
464 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
465 || tmp
->prev
->flags
.miniaturized
) {
471 /* set the w_j window coordinates */
474 width_j
= tmp
->frame
->core
->width
;
475 height_j
= tmp
->frame
->core
->height
;
476 botton_j
= y_j
+ height_j
;
478 right_border_j
= x_j
+ width_j
;
480 /* Try to maximize in the y direction first */
481 x_intsect
= calcIntersectionLength(x_0
, width_0
, x_j
, width_j
);
482 if (x_intsect
!= 0) {
483 if (botton_j
< y_0
&& botton_j
> new_y_0
) {
484 /* w_0 is below the botton of w_j */
487 if (botton_0
< top_j
&& top_j
< new_botton_0
) {
488 /* The botton of w_0 is above the top of w_j */
489 new_botton_0
= top_j
;
494 * Use the updated y coordinates from the above step to account
495 * the possibility that the new value of y_0 will have different
496 * intersections with w_j
498 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
499 y_intsect
= calcIntersectionLength(new_y_0
, new_height_0
, y_j
, height_j
);
500 if (y_intsect
!= 0) {
501 if (right_border_j
< x_0
&& right_border_j
> new_x_0
) {
502 /* w_0 is completely to the right of w_j */
503 new_x_0
= right_border_j
;
505 if (right_border_0
< x_j
&& x_j
< new_right_border_0
) {
506 /* w_0 is completely to the left of w_j */
507 new_right_border_0
= x_j
;
512 new_height_0
= new_botton_0
- new_y_0
- adjust_height
;
515 *new_height
= new_height_0
;
516 *new_width
= new_right_border_0
- new_x_0
- adjust_width
;
519 void wUnmaximizeWindow(WWindow
* wwin
)
523 if (!wwin
->flags
.maximized
)
526 if (wwin
->flags
.shaded
) {
527 wwin
->flags
.skip_next_animation
= 1;
528 wUnshadeWindow(wwin
);
530 x
= ((wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
)) && wwin
->old_geometry
.x
) ?
531 wwin
->old_geometry
.x
: wwin
->frame_x
;
532 y
= ((wwin
->flags
.maximized
& MAX_VERTICAL
) && wwin
->old_geometry
.y
) ?
533 wwin
->old_geometry
.y
: wwin
->frame_y
;
534 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
535 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
537 wwin
->flags
.maximized
= 0;
538 wWindowConfigure(wwin
, x
, y
, w
, h
);
540 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
542 wSoundPlay(WSOUND_UNMAXIMIZE
);
545 void wFullscreenWindow(WWindow
* wwin
)
550 if (wwin
->flags
.fullscreen
)
553 wwin
->flags
.fullscreen
= True
;
555 wWindowConfigureBorders(wwin
);
557 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
559 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
560 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
561 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
562 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
564 head
= wGetHeadForWindow(wwin
);
565 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
566 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
568 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
571 void wUnfullscreenWindow(WWindow
* wwin
)
573 if (!wwin
->flags
.fullscreen
)
576 wwin
->flags
.fullscreen
= False
;
578 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
579 if (WFLAGP(wwin
, sunken
)) {
580 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
581 } else if (WFLAGP(wwin
, floating
)) {
582 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
584 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
588 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
589 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
591 wWindowConfigureBorders(wwin
);
593 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
594 wFrameWindowPaint(wwin->frame);
597 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
601 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
603 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
604 float cx
, cy
, cw
, ch
;
605 float xstep
, ystep
, wstep
, hstep
;
608 float angle
, final_angle
, delta
;
610 xstep
= (float)(fx
- x
) / steps
;
611 ystep
= (float)(fy
- y
) / steps
;
612 wstep
= (float)(fw
- w
) / steps
;
613 hstep
= (float)(fh
- h
) / steps
;
620 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
621 delta
= (float)(final_angle
/ FRAMES
);
622 for (angle
= 0;; angle
+= delta
) {
623 if (angle
> final_angle
)
626 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
627 dch
= (ch
/ 2) * cos(angle
);
628 midy
= cy
+ (ch
/ 2);
630 points
[0].x
= cx
+ dx
;
631 points
[0].y
= midy
- dch
;
632 points
[1].x
= cx
+ cw
- dx
;
633 points
[1].y
= points
[0].y
;
634 points
[2].x
= cx
+ cw
+ dx
;
635 points
[2].y
= midy
+ dch
;
636 points
[3].x
= cx
- dx
;
637 points
[3].y
= points
[2].y
;
638 points
[4].x
= points
[0].x
;
639 points
[4].y
= points
[0].y
;
642 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
644 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
645 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
650 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
656 if (angle
>= final_angle
)
666 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
668 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
669 float cx
, cy
, cw
, ch
;
670 float xstep
, ystep
, wstep
, hstep
;
672 float angle
, final_angle
, a
, d
, delta
;
679 xstep
= (float)(fx
- x
) / steps
;
680 ystep
= (float)(fy
- y
) / steps
;
681 wstep
= (float)(fw
- w
) / steps
;
682 hstep
= (float)(fh
- h
) / steps
;
689 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
690 delta
= (float)(final_angle
/ FRAMES
);
691 for (angle
= 0;; angle
+= delta
) {
692 if (angle
> final_angle
)
696 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
698 points
[0].x
= cx
+ cos(angle
- a
) * d
;
699 points
[0].y
= cy
+ sin(angle
- a
) * d
;
700 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
701 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
702 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
703 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
704 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
705 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
706 points
[4].x
= cx
+ cos(angle
- a
) * d
;
707 points
[4].y
= cy
+ sin(angle
- a
) * d
;
709 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
711 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
712 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
717 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
723 if (angle
>= final_angle
)
732 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
734 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
735 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
736 float xstep
, ystep
, wstep
, hstep
;
739 xstep
= (float)(fx
- x
) / steps
;
740 ystep
= (float)(fy
- y
) / steps
;
741 wstep
= (float)(fw
- w
) / steps
;
742 hstep
= (float)(fh
- h
) / steps
;
744 for (j
= 0; j
< FRAMES
; j
++) {
751 for (i
= 0; i
< steps
; i
++) {
752 for (j
= 0; j
< FRAMES
; j
++) {
753 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
754 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
757 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
758 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
762 for (j
= 0; j
< FRAMES
; j
++) {
763 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
764 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
765 if (j
< FRAMES
- 1) {
779 for (j
= 0; j
< FRAMES
; j
++) {
780 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
783 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
784 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
788 for (j
= 0; j
< FRAMES
; j
++) {
789 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
797 void animateResize(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int hiding
)
799 int style
= wPreferences
.iconification_style
; /* Catch the value */
802 if (style
== WIS_NONE
)
805 if (style
== WIS_RANDOM
) {
809 k
= (hiding
? 2 : 3);
813 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
) / 3;
815 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
818 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
) / 3;
820 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
824 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
) / 3;
826 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
830 #endif /* ANIMATIONS */
832 static void flushExpose()
836 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
837 WMHandleEvent(&tmpev
);
841 static void unmapTransientsFor(WWindow
* wwin
)
845 tmp
= wwin
->screen_ptr
->focused_window
;
847 /* unmap the transients for this transient */
848 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
849 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
850 unmapTransientsFor(tmp
);
851 tmp
->flags
.miniaturized
= 1;
852 if (!tmp
->flags
.shaded
) {
855 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
858 if (!tmp->flags.shaded)
860 wClientSetState(tmp
, IconicState
, None
);
862 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
868 static void mapTransientsFor(WWindow
* wwin
)
872 tmp
= wwin
->screen_ptr
->focused_window
;
874 /* recursively map the transients for this transient */
875 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
876 && tmp
->icon
== NULL
) {
877 mapTransientsFor(tmp
);
878 tmp
->flags
.miniaturized
= 0;
879 if (!tmp
->flags
.shaded
) {
882 XMapWindow(dpy
, tmp
->frame
->core
->window
);
884 tmp
->flags
.semi_focused
= 0;
886 if (!tmp->flags.shaded)
888 wClientSetState(tmp
, NormalState
, None
);
890 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
897 static void setupIconGrabs(WIcon
* icon
)
899 /* setup passive grabs on the icon */
900 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
901 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
902 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
903 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
904 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
905 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
910 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
917 /* hackish way to detect transient_for cycle */
918 i
= wwin
->screen_ptr
->window_count
+ 1;
920 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
921 wwin
= wWindowFor(wwin
->transient_for
);
924 if (i
== 0 && wwin
) {
925 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
933 static void removeIconGrabs(WIcon
* icon
)
935 /* remove passive grabs on the icon */
936 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
937 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
938 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
943 void wIconifyWindow(WWindow
* wwin
)
945 XWindowAttributes attribs
;
948 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
949 /* the window doesn't exist anymore */
953 if (wwin
->flags
.miniaturized
) {
957 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
958 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
960 if (owner
&& owner
->flags
.miniaturized
)
964 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
966 /* if the window is in another workspace, simplify process */
968 /* icon creation may take a while */
969 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
970 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
971 GrabModeAsync
, None
, None
, CurrentTime
);
974 if (!wPreferences
.disable_miniwindows
976 && !wwin
->flags
.net_handle_icon
979 if (!wwin
->flags
.icon_moved
) {
980 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
982 wwin
->icon
= wIconCreate(wwin
);
984 wwin
->icon
->mapped
= 1;
987 wwin
->flags
.miniaturized
= 1;
988 wwin
->flags
.mapped
= 0;
990 /* unmap transients */
992 unmapTransientsFor(wwin
);
995 wSoundPlay(WSOUND_ICONIFY
);
997 XUngrabPointer(dpy
, CurrentTime
);
999 /* let all Expose events arrive so that we can repaint
1000 * something before the animation starts (and the server is grabbed) */
1003 if (wPreferences
.disable_miniwindows
1005 || wwin
->flags
.net_handle_icon
1008 wClientSetState(wwin
, IconicState
, None
);
1010 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1014 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1015 && !wPreferences
.no_animations
) {
1018 if (!wPreferences
.disable_miniwindows
1020 && !wwin
->flags
.net_handle_icon
1025 iw
= wwin
->icon
->core
->width
;
1026 ih
= wwin
->icon
->core
->height
;
1029 if (wwin
->flags
.net_handle_icon
) {
1039 iw
= wwin
->screen_ptr
->scr_width
;
1040 ih
= wwin
->screen_ptr
->scr_height
;
1043 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1044 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
, False
);
1049 wwin
->flags
.skip_next_animation
= 0;
1051 if (!wPreferences
.disable_miniwindows
1053 && !wwin
->flags
.net_handle_icon
1057 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1058 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1060 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1062 AddToStackList(wwin
->icon
->core
);
1064 wLowerFrame(wwin
->icon
->core
);
1068 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1071 * It doesn't seem to be working and causes button event hangup
1072 * when deiconifying a transient window.
1073 setupIconGrabs(wwin->icon);
1075 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1076 && wPreferences
.focus_mode
== WKF_CLICK
) {
1081 if (!WFLAGP(tmp
, no_focusable
)
1082 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1083 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1087 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1088 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1089 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1092 if (!wwin
->screen_ptr
->flags
.startup
) {
1093 /* Catch up with events not processed while animation was running */
1094 Window clientwin
= wwin
->client_win
;
1096 ProcessPendingEvents();
1098 /* the window can disappear while ProcessPendingEvents() runs */
1099 if (!wWindowFor(clientwin
)) {
1106 /* maybe we want to do this regardless of net_handle_icon
1107 * it seems to me we might break behaviour this way.
1109 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1111 && !wwin
->flags
.net_handle_icon
1114 wIconSelect(wwin
->icon
);
1116 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1119 void wDeiconifyWindow(WWindow
* wwin
)
1122 /* we're hiding for show_desktop */
1123 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1124 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1126 int netwm_hidden
= False
;
1130 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1132 if (!wwin
->flags
.miniaturized
)
1135 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1136 WWindow
*owner
= recursiveTransientFor(wwin
);
1138 if (owner
&& owner
->flags
.miniaturized
) {
1139 wDeiconifyWindow(owner
);
1140 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1141 wRaiseFrame(wwin
->frame
->core
);
1146 wwin
->flags
.miniaturized
= 0;
1148 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1149 wwin
->flags
.mapped
= 1;
1152 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1153 /* maybe we want to do this regardless of net_handle_icon
1154 * it seems to me we might break behaviour this way.
1156 if (!wPreferences
.disable_miniwindows
1158 && !wwin
->flags
.net_handle_icon
1160 && wwin
->icon
!= NULL
) {
1161 if (wwin
->icon
->selected
)
1162 wIconSelect(wwin
->icon
);
1164 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1169 wSoundPlay(WSOUND_DEICONIFY
);
1171 /* if the window is in another workspace, do it silently */
1172 if (!netwm_hidden
) {
1174 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1175 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1178 if (!wPreferences
.disable_miniwindows
1180 && !wwin
->flags
.net_handle_icon
1185 iw
= wwin
->icon
->core
->width
;
1186 ih
= wwin
->icon
->core
->height
;
1189 if (wwin
->flags
.net_handle_icon
) {
1199 iw
= wwin
->screen_ptr
->scr_width
;
1200 ih
= wwin
->screen_ptr
->scr_height
;
1203 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1204 wwin
->frame_x
, wwin
->frame_y
,
1205 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, False
);
1207 #endif /* ANIMATIONS */
1208 wwin
->flags
.skip_next_animation
= 0;
1210 if (!wwin
->flags
.shaded
) {
1211 XMapWindow(dpy
, wwin
->client_win
);
1213 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1214 wRaiseFrame(wwin
->frame
->core
);
1215 if (!wwin
->flags
.shaded
) {
1216 wClientSetState(wwin
, NormalState
, None
);
1218 mapTransientsFor(wwin
);
1221 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1223 && !wwin
->flags
.net_handle_icon
1226 RemoveFromStackList(wwin
->icon
->core
);
1227 /* removeIconGrabs(wwin->icon); */
1228 wIconDestroy(wwin
->icon
);
1232 if (!netwm_hidden
) {
1235 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1238 if (!wwin
->screen_ptr
->flags
.startup
) {
1239 /* Catch up with events not processed while animation was running */
1240 Window clientwin
= wwin
->client_win
;
1242 ProcessPendingEvents();
1244 /* the window can disappear while ProcessPendingEvents() runs */
1245 if (!wWindowFor(clientwin
)) {
1252 if (wPreferences
.auto_arrange_icons
) {
1253 wArrangeIcons(wwin
->screen_ptr
, True
);
1256 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1258 /* In case we were shaded and iconified, also unshade */
1260 wUnshadeWindow(wwin
);
1263 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1265 if (wwin
->flags
.miniaturized
) {
1267 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1268 wwin
->icon
->mapped
= 0;
1270 wwin
->flags
.hidden
= 1;
1272 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1276 if (wwin
->flags
.inspector_open
) {
1277 wHideInspectorForWindow(wwin
);
1280 wwin
->flags
.hidden
= 1;
1283 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1285 wSoundPlay(WSOUND_HIDE
);
1287 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1288 !wwin
->flags
.skip_next_animation
&& animate
) {
1289 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1290 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1291 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
, True
);
1294 wwin
->flags
.skip_next_animation
= 0;
1296 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1299 void wHideOtherApplications(WWindow
* awin
)
1306 wwin
= awin
->screen_ptr
->focused_window
;
1310 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1311 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1312 && !wwin
->flags
.internal_window
1313 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1315 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1316 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1317 wwin
->flags
.skip_next_animation
= 1;
1318 wIconifyWindow(wwin
);
1320 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1321 tapp
= wApplicationOf(wwin
->main_window
);
1323 tapp
->flags
.skip_next_animation
= 1;
1324 wHideApplication(tapp
);
1326 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1327 wwin
->flags
.skip_next_animation
= 1;
1328 wIconifyWindow(wwin
);
1336 wSetFocusTo(awin->screen_ptr, awin);
1340 void wHideApplication(WApplication
* wapp
)
1348 wwarning("trying to hide a non grouped window");
1351 if (!wapp
->main_window_desc
) {
1352 wwarning("group leader not found for window group");
1355 scr
= wapp
->main_window_desc
->screen_ptr
;
1357 wlist
= scr
->focused_window
;
1361 if (wlist
->main_window
== wapp
->main_window
)
1362 wapp
->last_focused
= wlist
;
1364 wapp
->last_focused
= NULL
;
1366 animate
= !wapp
->flags
.skip_next_animation
;
1369 if (wlist
->main_window
== wapp
->main_window
) {
1370 if (wlist
->flags
.focused
) {
1373 if (wapp
->app_icon
) {
1374 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1375 wapp
->app_icon
->y_pos
, wlist
, animate
);
1379 wlist
= wlist
->prev
;
1382 wapp
->flags
.skip_next_animation
= 0;
1385 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1386 wlist
= scr
->focused_window
;
1388 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1389 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1391 wlist
= wlist
->prev
;
1393 wSetFocusTo(scr
, wlist
);
1395 wSetFocusTo(scr
, NULL
);
1399 wapp
->flags
.hidden
= 1;
1401 if (wPreferences
.auto_arrange_icons
) {
1402 wArrangeIcons(scr
, True
);
1406 wAppIconPaint(wapp
->app_icon
);
1410 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1412 if (bringToCurrentWS
)
1413 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1415 wwin
->flags
.hidden
= 0;
1417 wSoundPlay(WSOUND_UNHIDE
);
1419 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1420 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1421 icon
->core
->width
, icon
->core
->height
,
1422 wwin
->frame_x
, wwin
->frame_y
,
1423 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, True
);
1426 wwin
->flags
.skip_next_animation
= 0;
1427 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1428 XMapWindow(dpy
, wwin
->client_win
);
1429 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1430 wClientSetState(wwin
, NormalState
, None
);
1431 wwin
->flags
.mapped
= 1;
1432 wRaiseFrame(wwin
->frame
->core
);
1434 if (wwin
->flags
.inspector_open
) {
1435 wUnhideInspectorForWindow(wwin
);
1438 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1441 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1444 WWindow
*wlist
, *next
;
1445 WWindow
*focused
= NULL
;
1451 scr
= wapp
->main_window_desc
->screen_ptr
;
1452 wlist
= scr
->focused_window
;
1456 /* goto beginning of list */
1458 wlist
= wlist
->prev
;
1460 animate
= !wapp
->flags
.skip_next_animation
;
1465 if (wlist
->main_window
== wapp
->main_window
) {
1466 if (wlist
->flags
.focused
)
1468 else if (!focused
|| !focused
->flags
.focused
)
1471 if (wlist
->flags
.miniaturized
) {
1472 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1473 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1474 if (!wlist
->icon
->mapped
) {
1477 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1478 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1479 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1483 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1484 wlist
->icon
->mapped
= 1;
1486 wRaiseFrame(wlist
->icon
->core
);
1488 if (bringToCurrentWS
)
1489 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1490 wlist
->flags
.hidden
= 0;
1491 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1492 wDeiconifyWindow(wlist
);
1494 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1495 } else if (wlist
->flags
.shaded
) {
1496 if (bringToCurrentWS
)
1497 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1498 wlist
->flags
.hidden
= 0;
1499 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1500 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1502 wUnshadeWindow(wlist
);
1503 wRaiseFrame(wlist
->frame
->core
);
1506 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1507 } else if (wlist
->flags
.hidden
) {
1508 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1509 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1512 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1513 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1515 wRaiseFrame(wlist
->frame
->core
);
1521 wapp
->flags
.skip_next_animation
= 0;
1522 wapp
->flags
.hidden
= 0;
1524 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1525 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1526 wSetFocusTo(scr
, wapp
->last_focused
);
1527 } else if (focused
) {
1528 wSetFocusTo(scr
, focused
);
1530 wapp
->last_focused
= NULL
;
1531 if (wPreferences
.auto_arrange_icons
) {
1532 wArrangeIcons(scr
, True
);
1535 wAppIconPaint(wapp
->app_icon
);
1539 void wShowAllWindows(WScreen
* scr
)
1541 WWindow
*wwin
, *old_foc
;
1544 old_foc
= wwin
= scr
->focused_window
;
1546 if (!wwin
->flags
.internal_window
&&
1547 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1548 if (wwin
->flags
.miniaturized
) {
1549 wwin
->flags
.skip_next_animation
= 1;
1550 wDeiconifyWindow(wwin
);
1551 } else if (wwin
->flags
.hidden
) {
1552 wapp
= wApplicationOf(wwin
->main_window
);
1554 wUnhideApplication(wapp
, False
, False
);
1556 wwin
->flags
.skip_next_animation
= 1;
1557 wDeiconifyWindow(wwin
);
1563 wSetFocusTo(scr
, old_foc
);
1564 /*wRaiseFrame(old_foc->frame->core); */
1567 void wRefreshDesktop(WScreen
* scr
)
1570 XSetWindowAttributes attr
;
1572 attr
.backing_store
= NotUseful
;
1573 attr
.save_under
= False
;
1574 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1575 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1576 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1577 XMapRaised(dpy
, win
);
1578 XDestroyWindow(dpy
, win
);
1582 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1588 const int heads
= wXineramaHeads(scr
);
1591 int pf
; /* primary axis */
1592 int sf
; /* secondary axis */
1596 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1602 int isize
= wPreferences
.icon_size
;
1604 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1606 for (head
= 0; head
< heads
; ++head
) {
1608 WMRect rect
= wGetRectForHead(scr
, head
);
1610 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1611 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1614 vars
[head
].pi
= vars
[head
].si
= 0;
1615 vars
[head
].sx1
= rect
.pos
.x
;
1616 vars
[head
].sy1
= rect
.pos
.y
;
1617 vars
[head
].sw
= rect
.size
.width
;
1618 vars
[head
].sh
= rect
.size
.height
;
1619 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1620 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1624 if (scr
->dock
->on_right_side
)
1625 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1627 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1631 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1632 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1633 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1634 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1636 /* icon yard boundaries */
1637 if (wPreferences
.icon_yard
& IY_VERT
) {
1638 vars
[head
].pf
= vars
[head
].fullH
;
1639 vars
[head
].sf
= vars
[head
].fullW
;
1641 vars
[head
].pf
= vars
[head
].fullW
;
1642 vars
[head
].sf
= vars
[head
].fullH
;
1644 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1645 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1648 vars
[head
].xo
= vars
[head
].sx1
;
1651 if (wPreferences
.icon_yard
& IY_TOP
) {
1652 vars
[head
].yo
= vars
[head
].sy1
;
1655 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1660 #define X ((wPreferences.icon_yard & IY_VERT) \
1661 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1662 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1664 #define Y ((wPreferences.icon_yard & IY_VERT) \
1665 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1666 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1668 /* arrange application icons */
1669 aicon
= scr
->app_icon_list
;
1670 /* reverse them to avoid unnecessarily sliding of icons */
1671 while (aicon
&& aicon
->next
)
1672 aicon
= aicon
->next
;
1675 if (!aicon
->docked
) {
1676 /* CHECK: can icon be NULL here ? */
1677 /* The intention here is to place the AppIcon on the head that
1678 * contains most of the applications _main_ window. */
1679 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1681 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1683 if (!wPreferences
.no_animations
) {
1684 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1686 #endif /* ANIMATIONS */
1688 wAppIconMove(aicon
, X
, Y
);
1690 if (vars
[head
].pi
>= vars
[head
].pf
) {
1695 aicon
= aicon
->prev
;
1698 /* arrange miniwindows */
1699 wwin
= scr
->focused_window
;
1700 /* reverse them to avoid unnecessarily shuffling */
1701 while (wwin
&& wwin
->prev
)
1705 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1706 (wwin
->frame
->workspace
== scr
->current_workspace
||
1707 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1709 head
= wGetHeadForWindow(wwin
);
1711 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1712 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1714 if (wPreferences
.no_animations
) {
1715 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1717 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1718 wwin
->icon_y
, X
, Y
);
1721 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1722 #endif /* ANIMATIONS */
1728 if (vars
[head
].pi
>= vars
[head
].pf
) {
1735 wwin
->flags
.icon_moved
= 0;
1737 /* we reversed the order, so we use next */
1745 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1749 int pf
; /* primary axis */
1750 int sf
; /* secondary axis */
1754 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1758 int isize
= wPreferences
.icon_size
;
1761 * Find out screen boundaries.
1765 * Allows each head to have miniwindows
1767 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1771 sw
= rect
.size
.width
;
1772 sh
= rect
.size
.height
;
1776 if (scr
->dock
->on_right_side
)
1777 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1779 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1782 sw
= isize
* (scr
->scr_width
/ isize
);
1783 sh
= isize
* (scr
->scr_height
/ isize
);
1785 sw
= isize
* (sw
/ isize
);
1786 sh
= isize
* (sh
/ isize
);
1788 fullW
= (sx2
- sx1
) / isize
;
1789 fullH
= (sy2
- sy1
) / isize
;
1791 /* icon yard boundaries */
1792 if (wPreferences
.icon_yard
& IY_VERT
) {
1799 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1806 if (wPreferences
.icon_yard
& IY_TOP
) {
1814 /* arrange icons putting the most recently focused window
1815 * as the last icon */
1816 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1817 : xo + xs*(pi*isize))
1818 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1819 : yo + ys*(si*isize))
1821 /* arrange application icons */
1822 aicon
= scr
->app_icon_list
;
1823 /* reverse them to avoid unnecessarily sliding of icons */
1824 while (aicon
&& aicon
->next
)
1825 aicon
= aicon
->next
;
1830 if (!aicon
->docked
) {
1831 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1833 if (!wPreferences
.no_animations
) {
1834 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1836 #endif /* ANIMATIONS */
1838 wAppIconMove(aicon
, X
, Y
);
1841 /* we reversed the order so we use prev */
1842 aicon
= aicon
->prev
;
1849 /* arrange miniwindows */
1851 wwin
= scr
->focused_window
;
1852 /* reverse them to avoid unnecessarily shuffling */
1853 while (wwin
&& wwin
->prev
)
1857 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1858 (wwin
->frame
->workspace
== scr
->current_workspace
||
1859 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1861 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1862 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1864 if (wPreferences
.no_animations
) {
1865 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1867 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1868 wwin
->icon_y
, X
, Y
);
1871 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1872 #endif /* ANIMATIONS */
1880 wwin
->flags
.icon_moved
= 0;
1882 /* we reversed the order, so we use next */
1892 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1894 WScreen
*scr
= wwin
->screen_ptr
;
1897 wwin
->flags
.selected
= 1;
1898 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1900 if (!HAS_BORDER(wwin
)) {
1901 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1904 if (!scr
->selected_windows
)
1905 scr
->selected_windows
= WMCreateArray(4);
1906 WMAddToArray(scr
->selected_windows
, wwin
);
1908 wwin
->flags
.selected
= 0;
1909 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1911 if (!HAS_BORDER(wwin
)) {
1912 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1915 if (scr
->selected_windows
) {
1916 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1921 void wMakeWindowVisible(WWindow
* wwin
)
1923 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1924 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1926 if (wwin
->flags
.shaded
) {
1927 wUnshadeWindow(wwin
);
1929 if (wwin
->flags
.hidden
) {
1932 app
= wApplicationOf(wwin
->main_window
);
1934 /* trick to get focus to this window */
1935 app
->last_focused
= wwin
;
1936 wUnhideApplication(app
, False
, False
);
1939 if (wwin
->flags
.miniaturized
) {
1940 wDeiconifyWindow(wwin
);
1942 if (!WFLAGP(wwin
, no_focusable
))
1943 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1944 wRaiseFrame(wwin
->frame
->core
);
1949 * Do the animation while shading (called with what = SHADE)
1950 * or unshading (what = UNSHADE).
1953 static void shade_animate(WWindow
*wwin
, Bool what
)
1956 time_t time0
= time(NULL
);
1958 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1963 if (!wwin
->screen_ptr
->flags
.startup
) {
1964 /* do the shading animation */
1965 h
= wwin
->frame
->core
->height
;
1966 s
= h
/ SHADE_STEPS
;
1969 w
= wwin
->frame
->core
->width
;
1970 y
= wwin
->frame
->top_width
;
1971 while (h
> wwin
->frame
->top_width
+ 1) {
1972 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1973 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1976 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1979 if (SHADE_DELAY
> 0) {
1980 wusleep(SHADE_DELAY
* 1000L);
1987 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1992 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1993 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1994 s
= abs(y
) / SHADE_STEPS
;
1997 w
= wwin
->frame
->core
->width
;
1998 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2000 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2001 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2002 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2004 if (SHADE_DELAY
> 0) {
2005 wusleep(SHADE_DELAY
* 2000L / 3);
2012 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2016 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2021 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
2022 #endif /* ANIMATIONS */