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
, half_scr_width
;
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
;
322 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
324 if (wwin
->flags
.shaded
) {
325 wwin
->flags
.skip_next_animation
= 1;
326 wUnshadeWindow(wwin
);
328 /* Only save directions, not kbd or xinerama hints */
329 directions
&= (MAX_HORIZONTAL
|MAX_VERTICAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
);
331 changed_h
= ((wwin
->flags
.maximized
^ directions
) & MAX_HORIZONTAL
);
332 changed_v
= ((wwin
->flags
.maximized
^ directions
) & MAX_VERTICAL
);
333 shrink_h
= (changed_h
&& (directions
& MAX_HORIZONTAL
) == 0);
334 shrink_v
= (changed_v
&& (directions
& MAX_VERTICAL
) == 0);
336 if (wwin
->flags
.maximized
) {
337 /* if already maximized in some direction, we only update the
338 * appropriate old x, old y coordinates. This is necessary to
339 * allow succesive maximizations in different directions without
340 * the need to first do an un-maximize (to avoid flicker).
342 if (!(wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
))) {
343 wwin
->old_geometry
.x
= wwin
->frame_x
;
345 if (!(wwin
->flags
.maximized
& MAX_VERTICAL
)) {
346 wwin
->old_geometry
.y
= wwin
->frame_y
;
349 wwin
->old_geometry
.width
= wwin
->client
.width
;
350 wwin
->old_geometry
.height
= wwin
->client
.height
;
351 wwin
->old_geometry
.x
= wwin
->frame_x
;
352 wwin
->old_geometry
.y
= wwin
->frame_y
;
354 wwin
->flags
.maximized
= directions
;
356 if (directions
& MAX_HORIZONTAL
) {
357 new_width
= usableArea
.x2
- usableArea
.x1
;
358 if (HAS_BORDER(wwin
))
359 new_width
-= FRAME_BORDER_WIDTH
* 2;
360 new_x
= usableArea
.x1
;
361 } else if (directions
& MAX_LEFTHALF
) {
362 new_width
= half_scr_width
;
363 if (HAS_BORDER(wwin
))
364 new_width
-= FRAME_BORDER_WIDTH
* 2;
365 new_x
= usableArea
.x1
;
366 } else if (directions
& MAX_RIGHTHALF
) {
367 new_width
= half_scr_width
;
368 if (HAS_BORDER(wwin
))
369 new_width
-= FRAME_BORDER_WIDTH
* 2;
370 new_x
= usableArea
.x1
+ half_scr_width
;
371 } else if (shrink_h
) {
372 new_x
= wwin
->old_geometry
.x
;
373 new_width
= wwin
->old_geometry
.width
;
375 new_x
= wwin
->frame_x
;
376 new_width
= wwin
->frame
->core
->width
;
379 if (directions
& MAX_VERTICAL
) {
380 new_height
= usableArea
.y2
- usableArea
.y1
;
381 if (HAS_BORDER(wwin
))
382 new_height
-= FRAME_BORDER_WIDTH
* 2;
383 new_y
= usableArea
.y1
;
384 if (WFLAGP(wwin
, full_maximize
)) {
385 new_y
-= wwin
->frame
->top_width
;
386 new_height
+= wwin
->frame
->bottom_width
- 1;
388 } else if (shrink_v
) {
389 new_y
= wwin
->old_geometry
.y
;
390 new_height
= wwin
->old_geometry
.height
;
392 new_y
= wwin
->frame_y
;
393 new_height
= wwin
->frame
->core
->height
;
396 if (!WFLAGP(wwin
, full_maximize
)) {
397 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
400 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
402 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
403 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
405 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
407 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
409 wSoundPlay(WSOUND_MAXIMIZE
);
412 void wUnmaximizeWindow(WWindow
* wwin
)
416 if (!wwin
->flags
.maximized
)
419 if (wwin
->flags
.shaded
) {
420 wwin
->flags
.skip_next_animation
= 1;
421 wUnshadeWindow(wwin
);
423 x
= ((wwin
->flags
.maximized
& (MAX_HORIZONTAL
|MAX_LEFTHALF
|MAX_RIGHTHALF
)) && wwin
->old_geometry
.x
) ?
424 wwin
->old_geometry
.x
: wwin
->frame_x
;
425 y
= ((wwin
->flags
.maximized
& MAX_VERTICAL
) && wwin
->old_geometry
.y
) ?
426 wwin
->old_geometry
.y
: wwin
->frame_y
;
427 w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
428 h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
430 wwin
->flags
.maximized
= 0;
431 wWindowConfigure(wwin
, x
, y
, w
, h
);
433 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
435 wSoundPlay(WSOUND_UNMAXIMIZE
);
438 void wFullscreenWindow(WWindow
* wwin
)
443 if (wwin
->flags
.fullscreen
)
446 wwin
->flags
.fullscreen
= True
;
448 wWindowConfigureBorders(wwin
);
450 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
452 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
453 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
454 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
455 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
457 head
= wGetHeadForWindow(wwin
);
458 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
459 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
461 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
464 void wUnfullscreenWindow(WWindow
* wwin
)
466 if (!wwin
->flags
.fullscreen
)
469 wwin
->flags
.fullscreen
= False
;
471 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
472 if (WFLAGP(wwin
, sunken
)) {
473 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
474 } else if (WFLAGP(wwin
, floating
)) {
475 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
477 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
481 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
482 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
484 wWindowConfigureBorders(wwin
);
486 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
487 wFrameWindowPaint(wwin->frame);
490 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
494 static void animateResizeFlip(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
496 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
497 float cx
, cy
, cw
, ch
;
498 float xstep
, ystep
, wstep
, hstep
;
501 float angle
, final_angle
, delta
;
503 xstep
= (float)(fx
- x
) / steps
;
504 ystep
= (float)(fy
- y
) / steps
;
505 wstep
= (float)(fw
- w
) / steps
;
506 hstep
= (float)(fh
- h
) / steps
;
513 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
514 delta
= (float)(final_angle
/ FRAMES
);
515 for (angle
= 0;; angle
+= delta
) {
516 if (angle
> final_angle
)
519 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
520 dch
= (ch
/ 2) * cos(angle
);
521 midy
= cy
+ (ch
/ 2);
523 points
[0].x
= cx
+ dx
;
524 points
[0].y
= midy
- dch
;
525 points
[1].x
= cx
+ cw
- dx
;
526 points
[1].y
= points
[0].y
;
527 points
[2].x
= cx
+ cw
+ dx
;
528 points
[2].y
= midy
+ dch
;
529 points
[3].x
= cx
- dx
;
530 points
[3].y
= points
[2].y
;
531 points
[4].x
= points
[0].x
;
532 points
[4].y
= points
[0].y
;
535 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
537 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
538 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
543 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
549 if (angle
>= final_angle
)
559 animateResizeTwist(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
561 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
562 float cx
, cy
, cw
, ch
;
563 float xstep
, ystep
, wstep
, hstep
;
565 float angle
, final_angle
, a
, d
, delta
;
572 xstep
= (float)(fx
- x
) / steps
;
573 ystep
= (float)(fy
- y
) / steps
;
574 wstep
= (float)(fw
- w
) / steps
;
575 hstep
= (float)(fh
- h
) / steps
;
582 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
583 delta
= (float)(final_angle
/ FRAMES
);
584 for (angle
= 0;; angle
+= delta
) {
585 if (angle
> final_angle
)
589 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
591 points
[0].x
= cx
+ cos(angle
- a
) * d
;
592 points
[0].y
= cy
+ sin(angle
- a
) * d
;
593 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
594 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
595 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
596 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
597 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
598 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
599 points
[4].x
= cx
+ cos(angle
- a
) * d
;
600 points
[4].y
= cy
+ sin(angle
- a
) * d
;
602 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
604 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
605 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
610 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
616 if (angle
>= final_angle
)
625 static void animateResizeZoom(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
627 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
628 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
629 float xstep
, ystep
, wstep
, hstep
;
632 xstep
= (float)(fx
- x
) / steps
;
633 ystep
= (float)(fy
- y
) / steps
;
634 wstep
= (float)(fw
- w
) / steps
;
635 hstep
= (float)(fh
- h
) / steps
;
637 for (j
= 0; j
< FRAMES
; j
++) {
644 for (i
= 0; i
< steps
; i
++) {
645 for (j
= 0; j
< FRAMES
; j
++) {
646 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
647 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
650 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
651 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
655 for (j
= 0; j
< FRAMES
; j
++) {
656 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
657 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
658 if (j
< FRAMES
- 1) {
672 for (j
= 0; j
< FRAMES
; j
++) {
673 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
676 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
677 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
681 for (j
= 0; j
< FRAMES
; j
++) {
682 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
690 void animateResize(WScreen
* scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int hiding
)
692 int style
= wPreferences
.iconification_style
; /* Catch the value */
695 if (style
== WIS_NONE
)
698 if (style
== WIS_RANDOM
) {
702 k
= (hiding
? 2 : 3);
706 steps
= (MINIATURIZE_ANIMATION_STEPS_T
* k
) / 3;
708 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
711 steps
= (MINIATURIZE_ANIMATION_STEPS_F
* k
) / 3;
713 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
717 steps
= (MINIATURIZE_ANIMATION_STEPS_Z
* k
) / 3;
719 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
723 #endif /* ANIMATIONS */
725 static void flushExpose()
729 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
730 WMHandleEvent(&tmpev
);
734 static void unmapTransientsFor(WWindow
* wwin
)
738 tmp
= wwin
->screen_ptr
->focused_window
;
740 /* unmap the transients for this transient */
741 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
742 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
743 unmapTransientsFor(tmp
);
744 tmp
->flags
.miniaturized
= 1;
745 if (!tmp
->flags
.shaded
) {
748 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
751 if (!tmp->flags.shaded)
753 wClientSetState(tmp
, IconicState
, None
);
755 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
761 static void mapTransientsFor(WWindow
* wwin
)
765 tmp
= wwin
->screen_ptr
->focused_window
;
767 /* recursively map the transients for this transient */
768 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
769 && tmp
->icon
== NULL
) {
770 mapTransientsFor(tmp
);
771 tmp
->flags
.miniaturized
= 0;
772 if (!tmp
->flags
.shaded
) {
775 XMapWindow(dpy
, tmp
->frame
->core
->window
);
777 tmp
->flags
.semi_focused
= 0;
779 if (!tmp->flags.shaded)
781 wClientSetState(tmp
, NormalState
, None
);
783 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
790 static void setupIconGrabs(WIcon
* icon
)
792 /* setup passive grabs on the icon */
793 XGrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
, True
,
794 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
795 XGrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
, True
,
796 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
797 XGrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
, True
,
798 ButtonPressMask
, GrabModeSync
, GrabModeAsync
, None
, None
);
803 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
810 /* hackish way to detect transient_for cycle */
811 i
= wwin
->screen_ptr
->window_count
+ 1;
813 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
814 wwin
= wWindowFor(wwin
->transient_for
);
817 if (i
== 0 && wwin
) {
818 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
826 static void removeIconGrabs(WIcon
* icon
)
828 /* remove passive grabs on the icon */
829 XUngrabButton(dpy
, Button1
, AnyModifier
, icon
->core
->window
);
830 XUngrabButton(dpy
, Button2
, AnyModifier
, icon
->core
->window
);
831 XUngrabButton(dpy
, Button3
, AnyModifier
, icon
->core
->window
);
836 void wIconifyWindow(WWindow
* wwin
)
838 XWindowAttributes attribs
;
841 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
)) {
842 /* the window doesn't exist anymore */
846 if (wwin
->flags
.miniaturized
) {
850 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
851 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
853 if (owner
&& owner
->flags
.miniaturized
)
857 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
859 /* if the window is in another workspace, simplify process */
861 /* icon creation may take a while */
862 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
863 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
864 GrabModeAsync
, None
, None
, CurrentTime
);
867 if (!wPreferences
.disable_miniwindows
869 && !wwin
->flags
.net_handle_icon
872 if (!wwin
->flags
.icon_moved
) {
873 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
875 wwin
->icon
= wIconCreate(wwin
);
877 wwin
->icon
->mapped
= 1;
880 wwin
->flags
.miniaturized
= 1;
881 wwin
->flags
.mapped
= 0;
883 /* unmap transients */
885 unmapTransientsFor(wwin
);
888 wSoundPlay(WSOUND_ICONIFY
);
890 XUngrabPointer(dpy
, CurrentTime
);
892 /* let all Expose events arrive so that we can repaint
893 * something before the animation starts (and the server is grabbed) */
896 if (wPreferences
.disable_miniwindows
898 || wwin
->flags
.net_handle_icon
901 wClientSetState(wwin
, IconicState
, None
);
903 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
907 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
908 && !wPreferences
.no_animations
) {
911 if (!wPreferences
.disable_miniwindows
913 && !wwin
->flags
.net_handle_icon
918 iw
= wwin
->icon
->core
->width
;
919 ih
= wwin
->icon
->core
->height
;
922 if (wwin
->flags
.net_handle_icon
) {
932 iw
= wwin
->screen_ptr
->scr_width
;
933 ih
= wwin
->screen_ptr
->scr_height
;
936 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
937 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
, False
);
942 wwin
->flags
.skip_next_animation
= 0;
944 if (!wPreferences
.disable_miniwindows
946 && !wwin
->flags
.net_handle_icon
950 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
951 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
953 XMapWindow(dpy
, wwin
->icon
->core
->window
);
955 AddToStackList(wwin
->icon
->core
);
957 wLowerFrame(wwin
->icon
->core
);
961 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
964 * It doesn't seem to be working and causes button event hangup
965 * when deiconifying a transient window.
966 setupIconGrabs(wwin->icon);
968 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
969 && wPreferences
.focus_mode
== WKF_CLICK
) {
974 if (!WFLAGP(tmp
, no_focusable
)
975 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
976 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
980 wSetFocusTo(wwin
->screen_ptr
, tmp
);
981 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
982 wSetFocusTo(wwin
->screen_ptr
, NULL
);
985 if (!wwin
->screen_ptr
->flags
.startup
) {
986 /* Catch up with events not processed while animation was running */
987 Window clientwin
= wwin
->client_win
;
989 ProcessPendingEvents();
991 /* the window can disappear while ProcessPendingEvents() runs */
992 if (!wWindowFor(clientwin
)) {
999 /* maybe we want to do this regardless of net_handle_icon
1000 * it seems to me we might break behaviour this way.
1002 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1004 && !wwin
->flags
.net_handle_icon
1007 wIconSelect(wwin
->icon
);
1009 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1012 void wDeiconifyWindow(WWindow
* wwin
)
1015 /* we're hiding for show_desktop */
1016 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1017 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1019 int netwm_hidden
= False
;
1023 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1025 if (!wwin
->flags
.miniaturized
)
1028 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1029 WWindow
*owner
= recursiveTransientFor(wwin
);
1031 if (owner
&& owner
->flags
.miniaturized
) {
1032 wDeiconifyWindow(owner
);
1033 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1034 wRaiseFrame(wwin
->frame
->core
);
1039 wwin
->flags
.miniaturized
= 0;
1041 if (!netwm_hidden
&& !wwin
->flags
.shaded
) {
1042 wwin
->flags
.mapped
= 1;
1045 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1046 /* maybe we want to do this regardless of net_handle_icon
1047 * it seems to me we might break behaviour this way.
1049 if (!wPreferences
.disable_miniwindows
1051 && !wwin
->flags
.net_handle_icon
1053 && wwin
->icon
!= NULL
) {
1054 if (wwin
->icon
->selected
)
1055 wIconSelect(wwin
->icon
);
1057 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1062 wSoundPlay(WSOUND_DEICONIFY
);
1064 /* if the window is in another workspace, do it silently */
1065 if (!netwm_hidden
) {
1067 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1068 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1071 if (!wPreferences
.disable_miniwindows
1073 && !wwin
->flags
.net_handle_icon
1078 iw
= wwin
->icon
->core
->width
;
1079 ih
= wwin
->icon
->core
->height
;
1082 if (wwin
->flags
.net_handle_icon
) {
1092 iw
= wwin
->screen_ptr
->scr_width
;
1093 ih
= wwin
->screen_ptr
->scr_height
;
1096 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1097 wwin
->frame_x
, wwin
->frame_y
,
1098 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, False
);
1100 #endif /* ANIMATIONS */
1101 wwin
->flags
.skip_next_animation
= 0;
1103 if (!wwin
->flags
.shaded
) {
1104 XMapWindow(dpy
, wwin
->client_win
);
1106 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1107 wRaiseFrame(wwin
->frame
->core
);
1108 if (!wwin
->flags
.shaded
) {
1109 wClientSetState(wwin
, NormalState
, None
);
1111 mapTransientsFor(wwin
);
1114 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1116 && !wwin
->flags
.net_handle_icon
1119 RemoveFromStackList(wwin
->icon
->core
);
1120 /* removeIconGrabs(wwin->icon); */
1121 wIconDestroy(wwin
->icon
);
1125 if (!netwm_hidden
) {
1128 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1131 if (!wwin
->screen_ptr
->flags
.startup
) {
1132 /* Catch up with events not processed while animation was running */
1133 Window clientwin
= wwin
->client_win
;
1135 ProcessPendingEvents();
1137 /* the window can disappear while ProcessPendingEvents() runs */
1138 if (!wWindowFor(clientwin
)) {
1145 if (wPreferences
.auto_arrange_icons
) {
1146 wArrangeIcons(wwin
->screen_ptr
, True
);
1149 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1151 /* In case we were shaded and iconified, also unshade */
1153 wUnshadeWindow(wwin
);
1156 static void hideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
)
1158 if (wwin
->flags
.miniaturized
) {
1160 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1161 wwin
->icon
->mapped
= 0;
1163 wwin
->flags
.hidden
= 1;
1165 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1169 if (wwin
->flags
.inspector_open
) {
1170 wHideInspectorForWindow(wwin
);
1173 wwin
->flags
.hidden
= 1;
1176 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1178 wSoundPlay(WSOUND_HIDE
);
1180 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1181 !wwin
->flags
.skip_next_animation
&& animate
) {
1182 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1183 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1184 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
, True
);
1187 wwin
->flags
.skip_next_animation
= 0;
1189 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1192 void wHideOtherApplications(WWindow
* awin
)
1199 wwin
= awin
->screen_ptr
->focused_window
;
1203 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1204 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1205 && !wwin
->flags
.internal_window
1206 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1208 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1209 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1210 wwin
->flags
.skip_next_animation
= 1;
1211 wIconifyWindow(wwin
);
1213 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1214 tapp
= wApplicationOf(wwin
->main_window
);
1216 tapp
->flags
.skip_next_animation
= 1;
1217 wHideApplication(tapp
);
1219 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1220 wwin
->flags
.skip_next_animation
= 1;
1221 wIconifyWindow(wwin
);
1229 wSetFocusTo(awin->screen_ptr, awin);
1233 void wHideApplication(WApplication
* wapp
)
1241 wwarning("trying to hide a non grouped window");
1244 if (!wapp
->main_window_desc
) {
1245 wwarning("group leader not found for window group");
1248 scr
= wapp
->main_window_desc
->screen_ptr
;
1250 wlist
= scr
->focused_window
;
1254 if (wlist
->main_window
== wapp
->main_window
)
1255 wapp
->last_focused
= wlist
;
1257 wapp
->last_focused
= NULL
;
1259 animate
= !wapp
->flags
.skip_next_animation
;
1262 if (wlist
->main_window
== wapp
->main_window
) {
1263 if (wlist
->flags
.focused
) {
1266 if (wapp
->app_icon
) {
1267 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1268 wapp
->app_icon
->y_pos
, wlist
, animate
);
1272 wlist
= wlist
->prev
;
1275 wapp
->flags
.skip_next_animation
= 0;
1278 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1279 wlist
= scr
->focused_window
;
1281 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1282 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1284 wlist
= wlist
->prev
;
1286 wSetFocusTo(scr
, wlist
);
1288 wSetFocusTo(scr
, NULL
);
1292 wapp
->flags
.hidden
= 1;
1294 if (wPreferences
.auto_arrange_icons
) {
1295 wArrangeIcons(scr
, True
);
1299 wAppIconPaint(wapp
->app_icon
);
1303 static void unhideWindow(WIcon
* icon
, int icon_x
, int icon_y
, WWindow
* wwin
, int animate
, int bringToCurrentWS
)
1305 if (bringToCurrentWS
)
1306 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1308 wwin
->flags
.hidden
= 0;
1310 wSoundPlay(WSOUND_UNHIDE
);
1312 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1313 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1314 icon
->core
->width
, icon
->core
->height
,
1315 wwin
->frame_x
, wwin
->frame_y
,
1316 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, True
);
1319 wwin
->flags
.skip_next_animation
= 0;
1320 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1321 XMapWindow(dpy
, wwin
->client_win
);
1322 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1323 wClientSetState(wwin
, NormalState
, None
);
1324 wwin
->flags
.mapped
= 1;
1325 wRaiseFrame(wwin
->frame
->core
);
1327 if (wwin
->flags
.inspector_open
) {
1328 wUnhideInspectorForWindow(wwin
);
1331 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1334 void wUnhideApplication(WApplication
* wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1337 WWindow
*wlist
, *next
;
1338 WWindow
*focused
= NULL
;
1344 scr
= wapp
->main_window_desc
->screen_ptr
;
1345 wlist
= scr
->focused_window
;
1349 /* goto beginning of list */
1351 wlist
= wlist
->prev
;
1353 animate
= !wapp
->flags
.skip_next_animation
;
1358 if (wlist
->main_window
== wapp
->main_window
) {
1359 if (wlist
->flags
.focused
)
1361 else if (!focused
|| !focused
->flags
.focused
)
1364 if (wlist
->flags
.miniaturized
) {
1365 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1366 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1367 if (!wlist
->icon
->mapped
) {
1370 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1371 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1372 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1376 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1377 wlist
->icon
->mapped
= 1;
1379 wRaiseFrame(wlist
->icon
->core
);
1381 if (bringToCurrentWS
)
1382 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1383 wlist
->flags
.hidden
= 0;
1384 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1385 wDeiconifyWindow(wlist
);
1387 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1388 } else if (wlist
->flags
.shaded
) {
1389 if (bringToCurrentWS
)
1390 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1391 wlist
->flags
.hidden
= 0;
1392 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1393 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1395 wUnshadeWindow(wlist
);
1396 wRaiseFrame(wlist
->frame
->core
);
1399 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1400 } else if (wlist
->flags
.hidden
) {
1401 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1402 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1405 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1406 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1408 wRaiseFrame(wlist
->frame
->core
);
1414 wapp
->flags
.skip_next_animation
= 0;
1415 wapp
->flags
.hidden
= 0;
1417 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1418 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1419 wSetFocusTo(scr
, wapp
->last_focused
);
1420 } else if (focused
) {
1421 wSetFocusTo(scr
, focused
);
1423 wapp
->last_focused
= NULL
;
1424 if (wPreferences
.auto_arrange_icons
) {
1425 wArrangeIcons(scr
, True
);
1428 wAppIconPaint(wapp
->app_icon
);
1432 void wShowAllWindows(WScreen
* scr
)
1434 WWindow
*wwin
, *old_foc
;
1437 old_foc
= wwin
= scr
->focused_window
;
1439 if (!wwin
->flags
.internal_window
&&
1440 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1441 if (wwin
->flags
.miniaturized
) {
1442 wwin
->flags
.skip_next_animation
= 1;
1443 wDeiconifyWindow(wwin
);
1444 } else if (wwin
->flags
.hidden
) {
1445 wapp
= wApplicationOf(wwin
->main_window
);
1447 wUnhideApplication(wapp
, False
, False
);
1449 wwin
->flags
.skip_next_animation
= 1;
1450 wDeiconifyWindow(wwin
);
1456 wSetFocusTo(scr
, old_foc
);
1457 /*wRaiseFrame(old_foc->frame->core); */
1460 void wRefreshDesktop(WScreen
* scr
)
1463 XSetWindowAttributes attr
;
1465 attr
.backing_store
= NotUseful
;
1466 attr
.save_under
= False
;
1467 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1468 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1469 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1470 XMapRaised(dpy
, win
);
1471 XDestroyWindow(dpy
, win
);
1475 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1481 const int heads
= wXineramaHeads(scr
);
1484 int pf
; /* primary axis */
1485 int sf
; /* secondary axis */
1489 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1495 int isize
= wPreferences
.icon_size
;
1497 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1499 for (head
= 0; head
< heads
; ++head
) {
1501 WMRect rect
= wGetRectForHead(scr
, head
);
1503 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1504 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1507 vars
[head
].pi
= vars
[head
].si
= 0;
1508 vars
[head
].sx1
= rect
.pos
.x
;
1509 vars
[head
].sy1
= rect
.pos
.y
;
1510 vars
[head
].sw
= rect
.size
.width
;
1511 vars
[head
].sh
= rect
.size
.height
;
1512 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1513 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1517 if (scr
->dock
->on_right_side
)
1518 vars
[head
].sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1520 vars
[head
].sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1524 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1525 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1526 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1527 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1529 /* icon yard boundaries */
1530 if (wPreferences
.icon_yard
& IY_VERT
) {
1531 vars
[head
].pf
= vars
[head
].fullH
;
1532 vars
[head
].sf
= vars
[head
].fullW
;
1534 vars
[head
].pf
= vars
[head
].fullW
;
1535 vars
[head
].sf
= vars
[head
].fullH
;
1537 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1538 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1541 vars
[head
].xo
= vars
[head
].sx1
;
1544 if (wPreferences
.icon_yard
& IY_TOP
) {
1545 vars
[head
].yo
= vars
[head
].sy1
;
1548 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1553 #define X ((wPreferences.icon_yard & IY_VERT) \
1554 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1555 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1557 #define Y ((wPreferences.icon_yard & IY_VERT) \
1558 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1559 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1561 /* arrange application icons */
1562 aicon
= scr
->app_icon_list
;
1563 /* reverse them to avoid unnecessarily sliding of icons */
1564 while (aicon
&& aicon
->next
)
1565 aicon
= aicon
->next
;
1568 if (!aicon
->docked
) {
1569 /* CHECK: can icon be NULL here ? */
1570 /* The intention here is to place the AppIcon on the head that
1571 * contains most of the applications _main_ window. */
1572 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1574 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1576 if (!wPreferences
.no_animations
) {
1577 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1579 #endif /* ANIMATIONS */
1581 wAppIconMove(aicon
, X
, Y
);
1583 if (vars
[head
].pi
>= vars
[head
].pf
) {
1588 aicon
= aicon
->prev
;
1591 /* arrange miniwindows */
1592 wwin
= scr
->focused_window
;
1593 /* reverse them to avoid unnecessarily shuffling */
1594 while (wwin
&& wwin
->prev
)
1598 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1599 (wwin
->frame
->workspace
== scr
->current_workspace
||
1600 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1602 head
= wGetHeadForWindow(wwin
);
1604 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1605 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1607 if (wPreferences
.no_animations
) {
1608 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1610 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1611 wwin
->icon_y
, X
, Y
);
1614 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1615 #endif /* ANIMATIONS */
1621 if (vars
[head
].pi
>= vars
[head
].pf
) {
1628 wwin
->flags
.icon_moved
= 0;
1630 /* we reversed the order, so we use next */
1638 void wArrangeIcons(WScreen
* scr
, Bool arrangeAll
)
1642 int pf
; /* primary axis */
1643 int sf
; /* secondary axis */
1647 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1651 int isize
= wPreferences
.icon_size
;
1654 * Find out screen boundaries.
1658 * Allows each head to have miniwindows
1660 WMRect rect
= wGetRectForHead(scr
, wGetHeadForPointerLocation(scr
));
1664 sw
= rect
.size
.width
;
1665 sh
= rect
.size
.height
;
1669 if (scr
->dock
->on_right_side
)
1670 sx2
-= isize
+ DOCK_EXTRA_SPACE
;
1672 sx1
+= isize
+ DOCK_EXTRA_SPACE
;
1675 sw
= isize
* (scr
->scr_width
/ isize
);
1676 sh
= isize
* (scr
->scr_height
/ isize
);
1678 sw
= isize
* (sw
/ isize
);
1679 sh
= isize
* (sh
/ isize
);
1681 fullW
= (sx2
- sx1
) / isize
;
1682 fullH
= (sy2
- sy1
) / isize
;
1684 /* icon yard boundaries */
1685 if (wPreferences
.icon_yard
& IY_VERT
) {
1692 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1699 if (wPreferences
.icon_yard
& IY_TOP
) {
1707 /* arrange icons putting the most recently focused window
1708 * as the last icon */
1709 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1710 : xo + xs*(pi*isize))
1711 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1712 : yo + ys*(si*isize))
1714 /* arrange application icons */
1715 aicon
= scr
->app_icon_list
;
1716 /* reverse them to avoid unnecessarily sliding of icons */
1717 while (aicon
&& aicon
->next
)
1718 aicon
= aicon
->next
;
1723 if (!aicon
->docked
) {
1724 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1726 if (!wPreferences
.no_animations
) {
1727 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1729 #endif /* ANIMATIONS */
1731 wAppIconMove(aicon
, X
, Y
);
1734 /* we reversed the order so we use prev */
1735 aicon
= aicon
->prev
;
1742 /* arrange miniwindows */
1744 wwin
= scr
->focused_window
;
1745 /* reverse them to avoid unnecessarily shuffling */
1746 while (wwin
&& wwin
->prev
)
1750 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1751 (wwin
->frame
->workspace
== scr
->current_workspace
||
1752 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1754 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1755 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1757 if (wPreferences
.no_animations
) {
1758 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1760 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1761 wwin
->icon_y
, X
, Y
);
1764 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1765 #endif /* ANIMATIONS */
1773 wwin
->flags
.icon_moved
= 0;
1775 /* we reversed the order, so we use next */
1785 void wSelectWindow(WWindow
* wwin
, Bool flag
)
1787 WScreen
*scr
= wwin
->screen_ptr
;
1790 wwin
->flags
.selected
= 1;
1791 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1793 if (!HAS_BORDER(wwin
)) {
1794 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1797 if (!scr
->selected_windows
)
1798 scr
->selected_windows
= WMCreateArray(4);
1799 WMAddToArray(scr
->selected_windows
, wwin
);
1801 wwin
->flags
.selected
= 0;
1802 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1804 if (!HAS_BORDER(wwin
)) {
1805 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1808 if (scr
->selected_windows
) {
1809 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1814 void wMakeWindowVisible(WWindow
* wwin
)
1816 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1817 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1819 if (wwin
->flags
.shaded
) {
1820 wUnshadeWindow(wwin
);
1822 if (wwin
->flags
.hidden
) {
1825 app
= wApplicationOf(wwin
->main_window
);
1827 /* trick to get focus to this window */
1828 app
->last_focused
= wwin
;
1829 wUnhideApplication(app
, False
, False
);
1832 if (wwin
->flags
.miniaturized
) {
1833 wDeiconifyWindow(wwin
);
1835 if (!WFLAGP(wwin
, no_focusable
))
1836 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1837 wRaiseFrame(wwin
->frame
->core
);
1842 * Do the animation while shading (called with what = SHADE)
1843 * or unshading (what = UNSHADE).
1846 static void shade_animate(WWindow
*wwin
, Bool what
)
1849 time_t time0
= time(NULL
);
1851 if (wwin
->flags
.skip_next_animation
&& wPreferences
.no_animations
)
1856 if (!wwin
->screen_ptr
->flags
.startup
) {
1857 /* do the shading animation */
1858 h
= wwin
->frame
->core
->height
;
1859 s
= h
/ SHADE_STEPS
;
1862 w
= wwin
->frame
->core
->width
;
1863 y
= wwin
->frame
->top_width
;
1864 while (h
> wwin
->frame
->top_width
+ 1) {
1865 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1866 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1869 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1872 if (SHADE_DELAY
> 0) {
1873 wusleep(SHADE_DELAY
* 1000L);
1880 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1885 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1886 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1887 s
= abs(y
) / SHADE_STEPS
;
1890 w
= wwin
->frame
->core
->width
;
1891 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1893 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1894 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1895 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1897 if (SHADE_DELAY
> 0) {
1898 wusleep(SHADE_DELAY
* 2000L / 3);
1905 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1909 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1914 static void shade_animate(WWindow
*wwin
, Bool what
) { return; }
1915 #endif /* ANIMATIONS */