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();
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 wSoundPlay(WSOUND_SHADE
);
230 shade_animate(wwin
, SHADE
);
232 wwin
->flags
.skip_next_animation
= 0;
233 wwin
->flags
.shaded
= 1;
234 wwin
->flags
.mapped
= 0;
235 /* prevent window withdrawal when getting UnmapNotify */
236 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
237 XUnmapWindow(dpy
, wwin
->client_win
);
238 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
240 /* for the client it's just like iconification */
241 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
243 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
244 wWindowSynthConfigureNotify(wwin
);
247 wClientSetState(wwin, IconicState, None);
250 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
253 if (!wwin
->screen_ptr
->flags
.startup
) {
254 /* Catch up with events not processed while animation was running */
255 ProcessPendingEvents();
260 void wUnshadeWindow(WWindow
*wwin
)
263 if (!wwin
->flags
.shaded
)
266 wwin
->flags
.shaded
= 0;
267 wwin
->flags
.mapped
= 1;
268 XMapWindow(dpy
, wwin
->client_win
);
270 wSoundPlay(WSOUND_UNSHADE
);
271 shade_animate(wwin
, UNSHADE
);
273 wwin
->flags
.skip_next_animation
= 0;
274 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
275 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
277 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
278 wWindowSynthConfigureNotify(wwin
);
281 wClientSetState(wwin, NormalState, None);
283 /* if the window is focused, set the focus again as it was disabled during
285 if (wwin
->flags
.focused
)
286 wSetFocusTo(wwin
->screen_ptr
, wwin
);
288 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
291 void wMaximizeWindow(WWindow
* wwin
, int directions
)
294 unsigned int new_width
, new_height
;
295 int changed_h
, changed_v
, shrink_h
, shrink_v
;
296 WArea usableArea
, totalArea
;
298 if (!IS_RESIZABLE(wwin
))
303 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
304 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
305 usableArea
= totalArea
;
307 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
308 WScreen
*scr
= wwin
->screen_ptr
;
311 if (directions
& MAX_KEYBOARD
)
312 head
= wGetHeadForWindow(wwin
);
314 head
= wGetHeadForPointerLocation(scr
);
316 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
319 if (WFLAGP(wwin
, full_maximize
)) {
320 usableArea
= totalArea
;
323 if (wwin
->flags
.shaded
) {
324 wwin
->flags
.skip_next_animation
= 1;
325 wUnshadeWindow(wwin
);
327 /* Only save directions, not kbd or xinerama hints */
328 directions
&= (MAX_HORIZONTAL
|MAX_VERTICAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
);
330 changed_h
= ((wwin
->flags
.maximized
^ directions
) & MAX_HORIZONTAL
);
331 changed_v
= ((wwin
->flags
.maximized
^ directions
) & MAX_VERTICAL
);
332 shrink_h
= (changed_h
&& (directions
& MAX_HORIZONTAL
) == 0);
333 shrink_v
= (changed_v
&& (directions
& MAX_VERTICAL
) == 0);
335 if (wwin
->flags
.maximized
) {
336 /* if already maximized in some direction, we only update the
337 * appropriate old x, old y coordinates. This is necessary to
338 * allow succesive maximizations in different directions without
339 * the need to first do an un-maximize (to avoid flicker).
341 if (!(wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
))) {
342 wwin
->old_geometry
.x
= wwin
->frame_x
;
344 if (!(wwin
->flags
.maximized
& MAX_VERTICAL
)) {
345 wwin
->old_geometry
.y
= wwin
->frame_y
;
348 wwin
->old_geometry
.width
= wwin
->client
.width
;
349 wwin
->old_geometry
.height
= wwin
->client
.height
;
350 wwin
->old_geometry
.x
= wwin
->frame_x
;
351 wwin
->old_geometry
.y
= wwin
->frame_y
;
353 wwin
->flags
.maximized
= directions
;
355 if (directions
& MAX_HORIZONTAL
) {
356 new_width
= usableArea
.x2
- usableArea
.x1
;
357 if (HAS_BORDER(wwin
))
358 new_width
-= FRAME_BORDER_WIDTH
* 2;
359 new_x
= usableArea
.x1
;
360 } else if (directions
& MAX_LEFTHALF
) {
361 new_width
= (usableArea
.x2
- usableArea
.x1
)/2;
362 if (HAS_BORDER(wwin
))
363 new_width
-= FRAME_BORDER_WIDTH
* 2;
364 new_x
= usableArea
.x1
;
365 } else if (directions
& MAX_RIGHTHALF
) {
366 new_width
= (usableArea
.x2
- usableArea
.x1
)/2;
367 if (HAS_BORDER(wwin
))
368 new_width
-= FRAME_BORDER_WIDTH
* 2;
369 new_x
= usableArea
.x1
+((usableArea
.x2
- usableArea
.x1
)/2);
370 } else if (shrink_h
) {
371 new_x
= wwin
->old_geometry
.x
;
372 new_width
= wwin
->old_geometry
.width
;
374 new_x
= wwin
->frame_x
;
375 new_width
= wwin
->frame
->core
->width
;
378 if (directions
& MAX_VERTICAL
) {
379 new_height
= usableArea
.y2
- usableArea
.y1
;
380 if (HAS_BORDER(wwin
))
381 new_height
-= FRAME_BORDER_WIDTH
* 2;
382 new_y
= usableArea
.y1
;
383 if (WFLAGP(wwin
, full_maximize
)) {
384 new_y
-= wwin
->frame
->top_width
;
385 new_height
+= wwin
->frame
->bottom_width
- 1;
387 } else if (shrink_v
) {
388 new_y
= wwin
->old_geometry
.y
;
389 new_height
= wwin
->old_geometry
.height
;
391 new_y
= wwin
->frame_y
;
392 new_height
= wwin
->frame
->core
->height
;
395 if (!WFLAGP(wwin
, full_maximize
)) {
396 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
399 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
401 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
402 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
404 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
406 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
408 wSoundPlay(WSOUND_MAXIMIZE
);
411 void wUnmaximizeWindow(WWindow
* wwin
)
415 if (!wwin
->flags
.maximized
)
418 if (wwin
->flags
.shaded
) {
419 wwin
->flags
.skip_next_animation
= 1;
420 wUnshadeWindow(wwin
);
422 x
= ((wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
)) && wwin
->old_geometry
.x
) ?
423 wwin
->old_geometry
.x
: wwin
->frame_x
;
424 y
= ((wwin
->flags
.maximized
& MAX_VERTICAL
) && wwin
->old_geometry
.y
) ?
425 wwin
->old_geometry
.y
: wwin
->frame_y
;
426 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
427 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
429 wwin
->flags
.maximized
= 0;
430 wWindowConfigure(wwin
, x
, y
, w
, h
);
432 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
434 wSoundPlay(WSOUND_UNMAXIMIZE
);
437 void wFullscreenWindow(WWindow
* wwin
)
442 if (wwin
->flags
.fullscreen
)
445 wwin
->flags
.fullscreen
= True
;
447 wWindowConfigureBorders(wwin
);
449 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
451 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
452 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
453 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
454 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
456 head
= wGetHeadForWindow(wwin
);
457 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
458 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
460 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
463 void wUnfullscreenWindow(WWindow
* wwin
)
465 if (!wwin
->flags
.fullscreen
)
468 wwin
->flags
.fullscreen
= False
;
470 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
471 if (WFLAGP(wwin
, sunken
)) {
472 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
473 } else if (WFLAGP(wwin
, floating
)) {
474 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
476 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
480 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
481 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
483 wWindowConfigureBorders(wwin
);
485 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
486 wFrameWindowPaint(wwin->frame);
489 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
493 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
495 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
496 float cx
, cy
, cw
, ch
;
497 float xstep
, ystep
, wstep
, hstep
;
500 float angle
, final_angle
, delta
;
502 xstep
= (float)(fx
- x
) / steps
;
503 ystep
= (float)(fy
- y
) / steps
;
504 wstep
= (float)(fw
- w
) / steps
;
505 hstep
= (float)(fh
- h
) / steps
;
512 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
513 delta
= (float)(final_angle
/ FRAMES
);
514 for (angle
= 0;; angle
+= delta
) {
515 if (angle
> final_angle
)
518 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
519 dch
= (ch
/ 2) * cos(angle
);
520 midy
= cy
+ (ch
/ 2);
522 points
[0].x
= cx
+ dx
;
523 points
[0].y
= midy
- dch
;
524 points
[1].x
= cx
+ cw
- dx
;
525 points
[1].y
= points
[0].y
;
526 points
[2].x
= cx
+ cw
+ dx
;
527 points
[2].y
= midy
+ dch
;
528 points
[3].x
= cx
- dx
;
529 points
[3].y
= points
[2].y
;
530 points
[4].x
= points
[0].x
;
531 points
[4].y
= points
[0].y
;
534 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
536 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
537 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
542 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
548 if (angle
>= final_angle
)
558 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
560 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
561 float cx
, cy
, cw
, ch
;
562 float xstep
, ystep
, wstep
, hstep
;
564 float angle
, final_angle
, a
, d
, delta
;
571 xstep
= (float)(fx
- x
) / steps
;
572 ystep
= (float)(fy
- y
) / steps
;
573 wstep
= (float)(fw
- w
) / steps
;
574 hstep
= (float)(fh
- h
) / steps
;
581 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
582 delta
= (float)(final_angle
/ FRAMES
);
583 for (angle
= 0;; angle
+= delta
) {
584 if (angle
> final_angle
)
588 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
590 points
[0].x
= cx
+ cos(angle
- a
) * d
;
591 points
[0].y
= cy
+ sin(angle
- a
) * d
;
592 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
593 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
594 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
595 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
596 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
597 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
598 points
[4].x
= cx
+ cos(angle
- a
) * d
;
599 points
[4].y
= cy
+ sin(angle
- a
) * d
;
601 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
603 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
604 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
609 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
615 if (angle
>= final_angle
)
624 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
626 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
627 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
628 float xstep
, ystep
, wstep
, hstep
;
631 xstep
= (float)(fx
- x
) / steps
;
632 ystep
= (float)(fy
- y
) / steps
;
633 wstep
= (float)(fw
- w
) / steps
;
634 hstep
= (float)(fh
- h
) / steps
;
636 for (j
= 0; j
< FRAMES
; j
++) {
643 for (i
= 0; i
< steps
; i
++) {
644 for (j
= 0; j
< FRAMES
; j
++) {
645 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
646 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
649 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
650 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
654 for (j
= 0; j
< FRAMES
; j
++) {
655 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
656 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
657 if (j
< FRAMES
- 1) {
671 for (j
= 0; j
< FRAMES
; j
++) {
672 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
675 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
676 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
680 for (j
= 0; j
< FRAMES
; j
++) {
681 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
689 void animateResize(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int hiding
)
691 int style
= wPreferences
.iconification_style
; /* Catch the value */
694 if (style
== WIS_NONE
)
697 if (style
== WIS_RANDOM
) {
701 k
= (hiding
? 2 : 3);
705 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
) / 3;
707 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
710 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
) / 3;
712 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
716 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
) / 3;
718 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
722 #endif /* ANIMATIONS */
724 static void flushExpose()
728 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
729 WMHandleEvent(&tmpev
);
733 static void unmapTransientsFor(WWindow
* wwin
)
737 tmp
= wwin
->screen_ptr
->focused_window
;
739 /* unmap the transients for this transient */
740 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
741 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
742 unmapTransientsFor(tmp
);
743 tmp
->flags
.miniaturized
= 1;
744 if (!tmp
->flags
.shaded
) {
747 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
750 if (!tmp->flags.shaded)
752 wClientSetState(tmp
, IconicState
, None
);
754 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
760 static void mapTransientsFor(WWindow
* wwin
)
764 tmp
= wwin
->screen_ptr
->focused_window
;
766 /* recursively map the transients for this transient */
767 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
768 && tmp
->icon
== NULL
) {
769 mapTransientsFor(tmp
);
770 tmp
->flags
.miniaturized
= 0;
771 if (!tmp
->flags
.shaded
) {
774 XMapWindow(dpy
, tmp
->frame
->core
->window
);
776 tmp
->flags
.semi_focused
= 0;
778 if (!tmp->flags.shaded)
780 wClientSetState(tmp
, NormalState
, None
);
782 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
789 static void setupIconGrabs(WIcon
* icon
)
791 /* setup passive grabs on the icon */
792 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
793 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
794 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
795 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
796 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
797 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
802 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
809 /* hackish way to detect transient_for cycle */
810 i
= wwin
->screen_ptr
->window_count
+ 1;
812 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
813 wwin
= wWindowFor(wwin
->transient_for
);
816 if (i
== 0 && wwin
) {
817 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
825 static void removeIconGrabs(WIcon
* icon
)
827 /* remove passive grabs on the icon */
828 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
829 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
830 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
835 void wIconifyWindow(WWindow
* wwin
)
837 XWindowAttributes attribs
;
840 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
841 /* the window doesn't exist anymore */
845 if (wwin
->flags
.miniaturized
) {
849 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
850 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
852 if (owner
&& owner
->flags
.miniaturized
)
856 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
858 /* if the window is in another workspace, simplify process */
860 /* icon creation may take a while */
861 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
862 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
863 GrabModeAsync
, None
, None
, CurrentTime
);
866 if (!wPreferences
.disable_miniwindows
868 && !wwin
->flags
.net_handle_icon
871 if (!wwin
->flags
.icon_moved
) {
872 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
874 wwin
->icon
= wIconCreate(wwin
);
876 wwin
->icon
->mapped
= 1;
879 wwin
->flags
.miniaturized
= 1;
880 wwin
->flags
.mapped
= 0;
882 /* unmap transients */
884 unmapTransientsFor(wwin
);
887 wSoundPlay(WSOUND_ICONIFY
);
889 XUngrabPointer(dpy
, CurrentTime
);
891 /* let all Expose events arrive so that we can repaint
892 * something before the animation starts (and the server is grabbed) */
895 if (wPreferences
.disable_miniwindows
897 || wwin
->flags
.net_handle_icon
900 wClientSetState(wwin
, IconicState
, None
);
902 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
906 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
907 && !wPreferences
.no_animations
) {
910 if (!wPreferences
.disable_miniwindows
912 && !wwin
->flags
.net_handle_icon
917 iw
= wwin
->icon
->core
->width
;
918 ih
= wwin
->icon
->core
->height
;
921 if (wwin
->flags
.net_handle_icon
) {
931 iw
= wwin
->screen_ptr
->scr_width
;
932 ih
= wwin
->screen_ptr
->scr_height
;
935 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
936 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
, False
);
941 wwin
->flags
.skip_next_animation
= 0;
943 if (!wPreferences
.disable_miniwindows
945 && !wwin
->flags
.net_handle_icon
949 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
950 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
952 XMapWindow(dpy
, wwin
->icon
->core
->window
);
954 AddToStackList(wwin
->icon
->core
);
956 wLowerFrame(wwin
->icon
->core
);
960 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
963 * It doesn't seem to be working and causes button event hangup
964 * when deiconifying a transient window.
965 setupIconGrabs(wwin->icon);
967 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
968 && wPreferences
.focus_mode
== WKF_CLICK
) {
973 if (!WFLAGP(tmp
, no_focusable
)
974 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
975 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
979 wSetFocusTo(wwin
->screen_ptr
, tmp
);
980 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
981 wSetFocusTo(wwin
->screen_ptr
, NULL
);
984 if (!wwin
->screen_ptr
->flags
.startup
) {
985 /* Catch up with events not processed while animation was running */
986 Window clientwin
= wwin
->client_win
;
988 ProcessPendingEvents();
990 /* the window can disappear while ProcessPendingEvents() runs */
991 if (!wWindowFor(clientwin
)) {
998 /* maybe we want to do this regardless of net_handle_icon
999 * it seems to me we might break behaviour this way.
1001 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1003 && !wwin
->flags
.net_handle_icon
1006 wIconSelect(wwin
->icon
);
1008 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1011 void wDeiconifyWindow(WWindow
* wwin
)
1014 /* we're hiding for show_desktop */
1015 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1016 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1018 int netwm_hidden
= False
;
1022 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1024 if (!wwin
->flags
.miniaturized
)
1027 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1028 WWindow
*owner
= recursiveTransientFor(wwin
);
1030 if (owner
&& owner
->flags
.miniaturized
) {
1031 wDeiconifyWindow(owner
);
1032 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1033 wRaiseFrame(wwin
->frame
->core
);
1038 wwin
->flags
.miniaturized
= 0;
1040 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1041 wwin
->flags
.mapped
= 1;
1044 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1045 /* maybe we want to do this regardless of net_handle_icon
1046 * it seems to me we might break behaviour this way.
1048 if (!wPreferences
.disable_miniwindows
1050 && !wwin
->flags
.net_handle_icon
1052 && wwin
->icon
!= NULL
) {
1053 if (wwin
->icon
->selected
)
1054 wIconSelect(wwin
->icon
);
1056 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1061 wSoundPlay(WSOUND_DEICONIFY
);
1063 /* if the window is in another workspace, do it silently */
1064 if (!netwm_hidden
) {
1066 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1067 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1070 if (!wPreferences
.disable_miniwindows
1072 && !wwin
->flags
.net_handle_icon
1077 iw
= wwin
->icon
->core
->width
;
1078 ih
= wwin
->icon
->core
->height
;
1081 if (wwin
->flags
.net_handle_icon
) {
1091 iw
= wwin
->screen_ptr
->scr_width
;
1092 ih
= wwin
->screen_ptr
->scr_height
;
1095 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1096 wwin
->frame_x
, wwin
->frame_y
,
1097 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, False
);
1099 #endif /* ANIMATIONS */
1100 wwin
->flags
.skip_next_animation
= 0;
1102 if (!wwin
->flags
.shaded
) {
1103 XMapWindow(dpy
, wwin
->client_win
);
1105 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1106 wRaiseFrame(wwin
->frame
->core
);
1107 if (!wwin
->flags
.shaded
) {
1108 wClientSetState(wwin
, NormalState
, None
);
1110 mapTransientsFor(wwin
);
1113 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1115 && !wwin
->flags
.net_handle_icon
1118 RemoveFromStackList(wwin
->icon
->core
);
1119 /* removeIconGrabs(wwin->icon); */
1120 wIconDestroy(wwin
->icon
);
1124 if (!netwm_hidden
) {
1127 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1130 if (!wwin
->screen_ptr
->flags
.startup
) {
1131 /* Catch up with events not processed while animation was running */
1132 Window clientwin
= wwin
->client_win
;
1134 ProcessPendingEvents();
1136 /* the window can disappear while ProcessPendingEvents() runs */
1137 if (!wWindowFor(clientwin
)) {
1144 if (wPreferences
.auto_arrange_icons
) {
1145 wArrangeIcons(wwin
->screen_ptr
, True
);
1148 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1150 /* In case we were shaded and iconified, also unshade */
1152 wUnshadeWindow(wwin
);
1155 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1157 if (wwin
->flags
.miniaturized
) {
1159 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1160 wwin
->icon
->mapped
= 0;
1162 wwin
->flags
.hidden
= 1;
1164 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1168 if (wwin
->flags
.inspector_open
) {
1169 wHideInspectorForWindow(wwin
);
1172 wwin
->flags
.hidden
= 1;
1175 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1177 wSoundPlay(WSOUND_HIDE
);
1179 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1180 !wwin
->flags
.skip_next_animation
&& animate
) {
1181 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1182 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1183 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
, True
);
1186 wwin
->flags
.skip_next_animation
= 0;
1188 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1191 void wHideOtherApplications(WWindow
* awin
)
1198 wwin
= awin
->screen_ptr
->focused_window
;
1202 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1203 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1204 && !wwin
->flags
.internal_window
1205 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1207 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1208 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1209 wwin
->flags
.skip_next_animation
= 1;
1210 wIconifyWindow(wwin
);
1212 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1213 tapp
= wApplicationOf(wwin
->main_window
);
1215 tapp
->flags
.skip_next_animation
= 1;
1216 wHideApplication(tapp
);
1218 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1219 wwin
->flags
.skip_next_animation
= 1;
1220 wIconifyWindow(wwin
);
1228 wSetFocusTo(awin->screen_ptr, awin);
1232 void wHideApplication(WApplication
* wapp
)
1240 wwarning("trying to hide a non grouped window");
1243 if (!wapp
->main_window_desc
) {
1244 wwarning("group leader not found for window group");
1247 scr
= wapp
->main_window_desc
->screen_ptr
;
1249 wlist
= scr
->focused_window
;
1253 if (wlist
->main_window
== wapp
->main_window
)
1254 wapp
->last_focused
= wlist
;
1256 wapp
->last_focused
= NULL
;
1258 animate
= !wapp
->flags
.skip_next_animation
;
1261 if (wlist
->main_window
== wapp
->main_window
) {
1262 if (wlist
->flags
.focused
) {
1265 if (wapp
->app_icon
) {
1266 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1267 wapp
->app_icon
->y_pos
, wlist
, animate
);
1271 wlist
= wlist
->prev
;
1274 wapp
->flags
.skip_next_animation
= 0;
1277 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1278 wlist
= scr
->focused_window
;
1280 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1281 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1283 wlist
= wlist
->prev
;
1285 wSetFocusTo(scr
, wlist
);
1287 wSetFocusTo(scr
, NULL
);
1291 wapp
->flags
.hidden
= 1;
1293 if (wPreferences
.auto_arrange_icons
) {
1294 wArrangeIcons(scr
, True
);
1298 wAppIconPaint(wapp
->app_icon
);
1302 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1304 if (bringToCurrentWS
)
1305 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1307 wwin
->flags
.hidden
= 0;
1309 wSoundPlay(WSOUND_UNHIDE
);
1311 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1312 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1313 icon
->core
->width
, icon
->core
->height
,
1314 wwin
->frame_x
, wwin
->frame_y
,
1315 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, True
);
1318 wwin
->flags
.skip_next_animation
= 0;
1319 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1320 XMapWindow(dpy
, wwin
->client_win
);
1321 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1322 wClientSetState(wwin
, NormalState
, None
);
1323 wwin
->flags
.mapped
= 1;
1324 wRaiseFrame(wwin
->frame
->core
);
1326 if (wwin
->flags
.inspector_open
) {
1327 wUnhideInspectorForWindow(wwin
);
1330 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1333 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1336 WWindow
*wlist
, *next
;
1337 WWindow
*focused
= NULL
;
1343 scr
= wapp
->main_window_desc
->screen_ptr
;
1344 wlist
= scr
->focused_window
;
1348 /* goto beginning of list */
1350 wlist
= wlist
->prev
;
1352 animate
= !wapp
->flags
.skip_next_animation
;
1357 if (wlist
->main_window
== wapp
->main_window
) {
1358 if (wlist
->flags
.focused
)
1360 else if (!focused
|| !focused
->flags
.focused
)
1363 if (wlist
->flags
.miniaturized
) {
1364 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1365 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1366 if (!wlist
->icon
->mapped
) {
1369 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1370 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1371 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1375 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1376 wlist
->icon
->mapped
= 1;
1378 wRaiseFrame(wlist
->icon
->core
);
1380 if (bringToCurrentWS
)
1381 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1382 wlist
->flags
.hidden
= 0;
1383 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1384 wDeiconifyWindow(wlist
);
1386 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1387 } else if (wlist
->flags
.shaded
) {
1388 if (bringToCurrentWS
)
1389 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1390 wlist
->flags
.hidden
= 0;
1391 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1392 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1394 wUnshadeWindow(wlist
);
1395 wRaiseFrame(wlist
->frame
->core
);
1398 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1399 } else if (wlist
->flags
.hidden
) {
1400 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1401 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1404 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1405 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1407 wRaiseFrame(wlist
->frame
->core
);
1413 wapp
->flags
.skip_next_animation
= 0;
1414 wapp
->flags
.hidden
= 0;
1416 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1417 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1418 wSetFocusTo(scr
, wapp
->last_focused
);
1419 } else if (focused
) {
1420 wSetFocusTo(scr
, focused
);
1422 wapp
->last_focused
= NULL
;
1423 if (wPreferences
.auto_arrange_icons
) {
1424 wArrangeIcons(scr
, True
);
1427 wAppIconPaint(wapp
->app_icon
);
1431 void wShowAllWindows(WScreen
* scr
)
1433 WWindow
*wwin
, *old_foc
;
1436 old_foc
= wwin
= scr
->focused_window
;
1438 if (!wwin
->flags
.internal_window
&&
1439 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1440 if (wwin
->flags
.miniaturized
) {
1441 wwin
->flags
.skip_next_animation
= 1;
1442 wDeiconifyWindow(wwin
);
1443 } else if (wwin
->flags
.hidden
) {
1444 wapp
= wApplicationOf(wwin
->main_window
);
1446 wUnhideApplication(wapp
, False
, False
);
1448 wwin
->flags
.skip_next_animation
= 1;
1449 wDeiconifyWindow(wwin
);
1455 wSetFocusTo(scr
, old_foc
);
1456 /*wRaiseFrame(old_foc->frame->core); */
1459 void wRefreshDesktop(WScreen
* scr
)
1462 XSetWindowAttributes attr
;
1464 attr
.backing_store
= NotUseful
;
1465 attr
.save_under
= False
;
1466 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1467 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1468 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1469 XMapRaised(dpy
, win
);
1470 XDestroyWindow(dpy
, win
);
1474 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1480 const int heads
= wXineramaHeads(scr
);
1483 int pf
; /* primary axis */
1484 int sf
; /* secondary axis */
1488 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1494 int isize
= wPreferences
.icon_size
;
1496 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1498 for (head
= 0; head
< heads
; ++head
) {
1500 WMRect rect
= wGetRectForHead(scr
, head
);
1502 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1503 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1506 vars
[head
].pi
= vars
[head
].si
= 0;
1507 vars
[head
].sx1
= rect
.pos
.x
;
1508 vars
[head
].sy1
= rect
.pos
.y
;
1509 vars
[head
].sw
= rect
.size
.width
;
1510 vars
[head
].sh
= rect
.size
.height
;
1511 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1512 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1516 if (scr
->dock
->on_right_side
)
1517 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1519 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1523 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1524 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1525 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1526 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1528 /* icon yard boundaries */
1529 if (wPreferences
.icon_yard
& IY_VERT
) {
1530 vars
[head
].pf
= vars
[head
].fullH
;
1531 vars
[head
].sf
= vars
[head
].fullW
;
1533 vars
[head
].pf
= vars
[head
].fullW
;
1534 vars
[head
].sf
= vars
[head
].fullH
;
1536 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1537 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1540 vars
[head
].xo
= vars
[head
].sx1
;
1543 if (wPreferences
.icon_yard
& IY_TOP
) {
1544 vars
[head
].yo
= vars
[head
].sy1
;
1547 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1552 #define X ((wPreferences.icon_yard & IY_VERT) \
1553 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1554 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1556 #define Y ((wPreferences.icon_yard & IY_VERT) \
1557 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1558 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1560 /* arrange application icons */
1561 aicon
= scr
->app_icon_list
;
1562 /* reverse them to avoid unnecessarily sliding of icons */
1563 while (aicon
&& aicon
->next
)
1564 aicon
= aicon
->next
;
1567 if (!aicon
->docked
) {
1568 /* CHECK: can icon be NULL here ? */
1569 /* The intention here is to place the AppIcon on the head that
1570 * contains most of the applications _main_ window. */
1571 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1573 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1575 if (!wPreferences
.no_animations
) {
1576 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1578 #endif /* ANIMATIONS */
1580 wAppIconMove(aicon
, X
, Y
);
1582 if (vars
[head
].pi
>= vars
[head
].pf
) {
1587 aicon
= aicon
->prev
;
1590 /* arrange miniwindows */
1591 wwin
= scr
->focused_window
;
1592 /* reverse them to avoid unnecessarily shuffling */
1593 while (wwin
&& wwin
->prev
)
1597 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1598 (wwin
->frame
->workspace
== scr
->current_workspace
||
1599 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1601 head
= wGetHeadForWindow(wwin
);
1603 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1604 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1606 if (wPreferences
.no_animations
) {
1607 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1609 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1610 wwin
->icon_y
, X
, Y
);
1613 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1614 #endif /* ANIMATIONS */
1620 if (vars
[head
].pi
>= vars
[head
].pf
) {
1627 wwin
->flags
.icon_moved
= 0;
1629 /* we reversed the order, so we use next */
1637 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1641 int pf
; /* primary axis */
1642 int sf
; /* secondary axis */
1646 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1650 int isize
= wPreferences
.icon_size
;
1653 * Find out screen boundaries.
1657 * Allows each head to have miniwindows
1659 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1663 sw
= rect
.size
.width
;
1664 sh
= rect
.size
.height
;
1668 if (scr
->dock
->on_right_side
)
1669 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1671 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1674 sw
= isize
* (scr
->scr_width
/ isize
);
1675 sh
= isize
* (scr
->scr_height
/ isize
);
1677 sw
= isize
* (sw
/ isize
);
1678 sh
= isize
* (sh
/ isize
);
1680 fullW
= (sx2
- sx1
) / isize
;
1681 fullH
= (sy2
- sy1
) / isize
;
1683 /* icon yard boundaries */
1684 if (wPreferences
.icon_yard
& IY_VERT
) {
1691 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1698 if (wPreferences
.icon_yard
& IY_TOP
) {
1706 /* arrange icons putting the most recently focused window
1707 * as the last icon */
1708 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1709 : xo + xs*(pi*isize))
1710 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1711 : yo + ys*(si*isize))
1713 /* arrange application icons */
1714 aicon
= scr
->app_icon_list
;
1715 /* reverse them to avoid unnecessarily sliding of icons */
1716 while (aicon
&& aicon
->next
)
1717 aicon
= aicon
->next
;
1722 if (!aicon
->docked
) {
1723 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1725 if (!wPreferences
.no_animations
) {
1726 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1728 #endif /* ANIMATIONS */
1730 wAppIconMove(aicon
, X
, Y
);
1733 /* we reversed the order so we use prev */
1734 aicon
= aicon
->prev
;
1741 /* arrange miniwindows */
1743 wwin
= scr
->focused_window
;
1744 /* reverse them to avoid unnecessarily shuffling */
1745 while (wwin
&& wwin
->prev
)
1749 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1750 (wwin
->frame
->workspace
== scr
->current_workspace
||
1751 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1753 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1754 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1756 if (wPreferences
.no_animations
) {
1757 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1759 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1760 wwin
->icon_y
, X
, Y
);
1763 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1764 #endif /* ANIMATIONS */
1772 wwin
->flags
.icon_moved
= 0;
1774 /* we reversed the order, so we use next */
1784 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1786 WScreen
*scr
= wwin
->screen_ptr
;
1789 wwin
->flags
.selected
= 1;
1790 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1792 if (!HAS_BORDER(wwin
)) {
1793 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1796 if (!scr
->selected_windows
)
1797 scr
->selected_windows
= WMCreateArray(4);
1798 WMAddToArray(scr
->selected_windows
, wwin
);
1800 wwin
->flags
.selected
= 0;
1801 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1803 if (!HAS_BORDER(wwin
)) {
1804 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1807 if (scr
->selected_windows
) {
1808 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1813 void wMakeWindowVisible(WWindow
* wwin
)
1815 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1816 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1818 if (wwin
->flags
.shaded
) {
1819 wUnshadeWindow(wwin
);
1821 if (wwin
->flags
.hidden
) {
1824 app
= wApplicationOf(wwin
->main_window
);
1826 /* trick to get focus to this window */
1827 app
->last_focused
= wwin
;
1828 wUnhideApplication(app
, False
, False
);
1831 if (wwin
->flags
.miniaturized
) {
1832 wDeiconifyWindow(wwin
);
1834 if (!WFLAGP(wwin
, no_focusable
))
1835 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1836 wRaiseFrame(wwin
->frame
->core
);
1841 * Do the animation while shading (called with what = SHADE)
1842 * or unshading (what = UNSHADE).
1845 static void shade_animate(WWindow
*wwin
, Bool what
)
1848 time_t time0
= time(NULL
);
1850 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1855 if (!wwin
->screen_ptr
->flags
.startup
) {
1856 /* do the shading animation */
1857 h
= wwin
->frame
->core
->height
;
1858 s
= h
/ SHADE_STEPS
;
1861 w
= wwin
->frame
->core
->width
;
1862 y
= wwin
->frame
->top_width
;
1863 while (h
> wwin
->frame
->top_width
+ 1) {
1864 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1865 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1868 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1871 if (SHADE_DELAY
> 0) {
1872 wusleep(SHADE_DELAY
* 1000L);
1879 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1884 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1885 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1886 s
= abs(y
) / SHADE_STEPS
;
1889 w
= wwin
->frame
->core
->width
;
1890 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1892 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1893 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1894 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1896 if (SHADE_DELAY
> 0) {
1897 wusleep(SHADE_DELAY
* 2000L / 3);
1904 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1908 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1913 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
1914 #endif /* ANIMATIONS */