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
7 * Copyright (c) 2014 Window Maker Team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
40 #include "application.h"
46 #include "winspector.h"
47 #include "workspace.h"
50 #include "placement.h"
55 #ifndef HAVE_FLOAT_MATHFUNC
56 #define sinf(x) ((float)sin((double)(x)))
57 #define cosf(x) ((float)cos((double)(x)))
58 #define sqrtf(x) ((float)sqrt((double)(x)))
59 #define atan2f(y, x) ((float)atan((double)(y) / (double)(x)))
62 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
63 unsigned int *new_width
, unsigned int *new_height
);
64 static void save_old_geometry(WWindow
*wwin
, int directions
);
66 /******* Local Variables *******/
72 { SHADE_STEPS_UF
, SHADE_DELAY_UF
},
73 { SHADE_STEPS_F
, SHADE_DELAY_F
},
74 { SHADE_STEPS_M
, SHADE_DELAY_M
},
75 { SHADE_STEPS_S
, SHADE_DELAY_S
},
76 { SHADE_STEPS_US
, SHADE_DELAY_US
}
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
86 static int compareTimes(Time t1
, Time t2
)
92 return (diff
< 60000) ? 1 : -1;
96 static void shade_animate(WWindow
*wwin
, Bool what
);
98 static inline void shade_animate(WWindow
*wwin
, Bool what
)
101 * This function is empty on purpose, so tell the compiler
102 * to not warn about parameters being not used
110 *----------------------------------------------------------------------
112 * Changes the window focus to the one passed as argument.
113 * If the window to focus is not already focused, it will be brought
114 * to the head of the list of windows. Previously focused window is
118 * Window list may be reordered and the window focus is changed.
120 *----------------------------------------------------------------------
122 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
124 static WScreen
*old_scr
= NULL
;
126 WWindow
*old_focused
;
127 WWindow
*focused
= scr
->focused_window
;
128 Time timestamp
= w_global
.timestamp
.last_event
;
129 WApplication
*oapp
= NULL
, *napp
= NULL
;
132 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
138 old_focused
= old_scr
->focused_window
;
140 w_global
.timestamp
.focus_change
= timestamp
;
143 oapp
= wApplicationOf(old_focused
->main_window
);
146 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
148 wWindowUnfocus(old_focused
);
151 wAppMenuUnmap(oapp
->menu
);
152 if (wPreferences
.highlight_active_app
)
153 wApplicationDeactivate(oapp
);
156 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
160 if (old_scr
!= scr
&& old_focused
)
161 wWindowUnfocus(old_focused
);
163 wasfocused
= wwin
->flags
.focused
;
164 napp
= wApplicationOf(wwin
->main_window
);
166 /* remember last workspace where the app has been */
168 napp
->last_workspace
= wwin
->frame
->workspace
;
170 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
171 /* install colormap if colormap mode is lock mode */
172 if (wPreferences
.colormap_mode
== WCM_CLICK
)
173 wColormapInstallForWindow(scr
, wwin
);
175 /* set input focus */
176 switch (wwin
->focus_mode
) {
178 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
181 case WFM_LOCALLY_ACTIVE
:
182 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
184 case WFM_GLOBALLY_ACTIVE
:
189 if (wwin
->protocols
.TAKE_FOCUS
)
190 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
194 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
197 if (WFLAGP(wwin
, no_focusable
))
200 /* if this is not the focused window focus it */
201 if (focused
!= wwin
) {
202 /* change the focus window list order */
204 wwin
->prev
->next
= wwin
->next
;
207 wwin
->next
->prev
= wwin
->prev
;
209 wwin
->prev
= focused
;
210 focused
->next
= wwin
;
212 scr
->focused_window
= wwin
;
214 if (oapp
&& oapp
!= napp
) {
215 wAppMenuUnmap(oapp
->menu
);
216 if (wPreferences
.highlight_active_app
)
217 wApplicationDeactivate(oapp
);
220 /* reset fullscreen if temporarily removed due to lost focus*/
221 if (wwin
->flags
.fullscreen
)
222 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
225 wWindowFocus(wwin
, focused
);
227 if (napp
&& !wasfocused
) {
229 wUserMenuRefreshInstances(napp
->menu
, wwin
);
230 #endif /* USER_MENU */
232 /* kix: Only menu map with mouse, not alt+tab! */
233 if (wwin
->flags
.mapped
)
234 wAppMenuMap(napp
->menu
, wwin
);
236 if (napp
&& wPreferences
.highlight_active_app
)
237 wApplicationActivate(napp
);
243 void wShadeWindow(WWindow
*wwin
)
246 if (wwin
->flags
.shaded
)
249 XLowerWindow(dpy
, wwin
->client_win
);
250 shade_animate(wwin
, SHADE
);
252 wwin
->flags
.skip_next_animation
= 0;
253 wwin
->flags
.shaded
= 1;
254 wwin
->flags
.mapped
= 0;
255 /* prevent window withdrawal when getting UnmapNotify */
256 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
257 XUnmapWindow(dpy
, wwin
->client_win
);
258 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
260 /* for the client it's just like iconification */
261 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
263 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
264 wWindowSynthConfigureNotify(wwin
);
267 wClientSetState(wwin, IconicState, None);
270 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
272 #ifdef USE_ANIMATIONS
273 if (!wwin
->screen_ptr
->flags
.startup
) {
274 /* Catch up with events not processed while animation was running */
275 ProcessPendingEvents();
280 void wUnshadeWindow(WWindow
*wwin
)
283 if (!wwin
->flags
.shaded
)
286 wwin
->flags
.shaded
= 0;
287 wwin
->flags
.mapped
= 1;
288 XMapWindow(dpy
, wwin
->client_win
);
290 shade_animate(wwin
, UNSHADE
);
292 wwin
->flags
.skip_next_animation
= 0;
293 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
294 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
296 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
297 wWindowSynthConfigureNotify(wwin
);
299 /* if the window is focused, set the focus again as it was disabled during
301 if (wwin
->flags
.focused
)
302 wSetFocusTo(wwin
->screen_ptr
, wwin
);
304 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
307 /* Set the old coordinates using the current values */
308 static void save_old_geometry(WWindow
*wwin
, int directions
)
310 /* never been saved? */
311 if (!wwin
->old_geometry
.width
)
312 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
313 if (!wwin
->old_geometry
.height
)
314 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
316 if (directions
& SAVE_GEOMETRY_X
)
317 wwin
->old_geometry
.x
= wwin
->frame_x
;
318 if (directions
& SAVE_GEOMETRY_Y
)
319 wwin
->old_geometry
.y
= wwin
->frame_y
;
320 if (directions
& SAVE_GEOMETRY_WIDTH
)
321 wwin
->old_geometry
.width
= wwin
->client
.width
;
322 if (directions
& SAVE_GEOMETRY_HEIGHT
)
323 wwin
->old_geometry
.height
= wwin
->client
.height
;
326 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
328 WMRect old_geom_rect
;
332 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
333 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
334 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
335 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
336 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
337 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
338 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
341 /* Remember geometry for unmaximizing */
342 void update_saved_geometry(WWindow
*wwin
)
344 /* NOT if we aren't already maximized
345 * we'll save geometry when maximizing */
346 if (!wwin
->flags
.maximized
)
349 /* NOT if we are fully maximized */
350 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
351 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
352 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
355 /* save the co-ordinate in the axis in which we AREN'T maximized */
356 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
357 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
358 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
359 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
362 void wMaximizeWindow(WWindow
*wwin
, int directions
)
364 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
369 unsigned int maximus_width
= 0;
370 unsigned int maximus_height
= 0;
371 WArea usableArea
, totalArea
;
374 WScreen
*scr
= wwin
->screen_ptr
;
376 if (!IS_RESIZABLE(wwin
))
379 if (!HAS_BORDER(wwin
))
382 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
383 wwin
->client_flags
.no_movable
= 1;
385 /* the size to adjust the geometry */
386 adj_size
= scr
->frame_border_width
* 2 * has_border
;
388 /* save old coordinates before we change the current values */
389 if (!wwin
->flags
.maximized
)
390 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
392 totalArea
.x2
= scr
->scr_width
;
393 totalArea
.y2
= scr
->scr_height
;
396 usableArea
= totalArea
;
398 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
399 WScreen
*scr
= wwin
->screen_ptr
;
402 if (directions
& MAX_KEYBOARD
)
403 head
= wGetHeadForWindow(wwin
);
405 head
= wGetHeadForPointerLocation(scr
);
407 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
411 /* Only save directions, not kbd or xinerama hints */
412 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
414 if (WFLAGP(wwin
, full_maximize
))
415 usableArea
= totalArea
;
416 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
417 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
419 if (wwin
->flags
.shaded
) {
420 wwin
->flags
.skip_next_animation
= 1;
421 wUnshadeWindow(wwin
);
424 if (directions
& MAX_MAXIMUS
) {
425 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
426 new_width
= maximus_width
- adj_size
;
427 new_height
= maximus_height
- adj_size
;
430 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
431 new_height
+= wwin
->frame
->bottom_width
- 1;
432 new_y
-= wwin
->frame
->top_width
;
435 wwin
->maximus_x
= new_x
;
436 wwin
->maximus_y
= new_y
;
437 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
439 /* set default values if no option set then */
440 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
441 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
442 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
444 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
445 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
446 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
449 /* left|right position */
450 if (directions
& MAX_LEFTHALF
) {
451 new_width
= half_scr_width
- adj_size
;
452 new_x
= usableArea
.x1
;
453 } else if (directions
& MAX_RIGHTHALF
) {
454 new_width
= half_scr_width
- adj_size
;
455 new_x
= usableArea
.x1
+ half_scr_width
;
457 /* top|bottom position */
458 if (directions
& MAX_TOPHALF
) {
459 new_height
= half_scr_height
- adj_size
;
460 new_y
= usableArea
.y1
;
461 } else if (directions
& MAX_BOTTOMHALF
) {
462 new_height
= half_scr_height
- adj_size
;
463 new_y
= usableArea
.y1
+ half_scr_height
;
466 /* vertical|horizontal position */
467 if (directions
& MAX_HORIZONTAL
) {
468 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
469 new_x
= usableArea
.x1
;
471 if (directions
& MAX_VERTICAL
) {
472 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
473 new_y
= usableArea
.y1
;
474 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
475 new_y
-= wwin
->frame
->top_width
;
479 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
480 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
482 /* set maximization state */
483 wwin
->flags
.maximized
= directions
;
484 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
485 wwin
->flags
.maximized
= MAX_MAXIMUS
;
487 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
489 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
490 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
492 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
493 wWindowSynthConfigureNotify(wwin
);
495 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
498 /* generic (un)maximizer */
499 void handleMaximize(WWindow
*wwin
, int directions
)
501 int current
= wwin
->flags
.maximized
;
502 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
503 int effective
= requested
^ current
;
504 int flags
= directions
& ~requested
;
507 /* allow wMaximizeWindow to restore the Maximusized size */
508 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
509 !(requested
& MAX_MAXIMUS
))
510 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
512 wUnmaximizeWindow(wwin
);
513 /* these alone mean vertical|horizontal toggle */
514 } else if ((effective
== MAX_LEFTHALF
) ||
515 (effective
== MAX_RIGHTHALF
) ||
516 (effective
== MAX_TOPHALF
) ||
517 (effective
== MAX_BOTTOMHALF
))
518 wUnmaximizeWindow(wwin
);
520 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
521 (requested
== MAX_MAXIMUS
))
522 effective
= requested
;
524 if (requested
& MAX_LEFTHALF
) {
525 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
526 effective
|= MAX_VERTICAL
;
528 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
529 effective
|= MAX_LEFTHALF
;
530 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
531 } else if (requested
& MAX_RIGHTHALF
) {
532 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
533 effective
|= MAX_VERTICAL
;
535 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
536 effective
|= MAX_RIGHTHALF
;
537 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
539 if (requested
& MAX_TOPHALF
) {
540 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
541 effective
|= MAX_HORIZONTAL
;
543 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
544 effective
|= MAX_TOPHALF
;
545 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
546 } else if (requested
& MAX_BOTTOMHALF
) {
547 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
548 effective
|= MAX_HORIZONTAL
;
550 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
551 effective
|= MAX_BOTTOMHALF
;
552 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
554 if (requested
& MAX_HORIZONTAL
)
555 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
556 if (requested
& MAX_VERTICAL
)
557 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
558 effective
&= ~MAX_MAXIMUS
;
560 wMaximizeWindow(wwin
, effective
| flags
);
564 /* the window boundary coordinates */
574 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
576 obs
->left
= wwin
->frame_x
;
577 obs
->top
= wwin
->frame_y
;
578 obs
->width
= wwin
->frame
->core
->width
;
579 obs
->height
= wwin
->frame
->core
->height
;
580 obs
->bottom
= obs
->top
+ obs
->height
;
581 obs
->right
= obs
->left
+ obs
->width
;
585 * Maximus: tiled maximization (maximize without overlapping other windows)
587 * The original window 'orig' will be maximized to new coordinates 'new'.
588 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
590 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
591 unsigned int *new_width
, unsigned int *new_height
)
594 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
595 short int adjust_height
;
596 int x_intsect
, y_intsect
;
597 /* the obstructing, original and new windows */
598 win_coords obs
, orig
, new;
600 /* set the original coordinate positions of the window to be Maximumized */
601 if (wwin
->flags
.maximized
) {
602 /* window is already maximized; consider original geometry */
603 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
604 orig
.bottom
= orig
.top
+ orig
.height
;
605 orig
.right
= orig
.left
+ orig
.width
;
607 set_window_coords(wwin
, &orig
);
609 /* Try to fully maximize first, then readjust later */
610 new.left
= usableArea
.x1
;
611 new.right
= usableArea
.x2
;
612 new.top
= usableArea
.y1
;
613 new.bottom
= usableArea
.y2
;
615 if (HAS_TITLEBAR(wwin
))
616 tbar_height_0
= TITLEBAR_HEIGHT
;
617 if (HAS_RESIZEBAR(wwin
))
618 rbar_height_0
= RESIZEBAR_HEIGHT
;
619 if (HAS_BORDER(wwin
))
620 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
622 /* the length to be subtracted if the window has titlebar, etc */
623 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
626 /* The focused window is always the last in the list */
628 /* ignore windows in other workspaces etc */
629 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
630 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
636 /* Set the coordinates of obstructing window */
637 set_window_coords(tmp
, &obs
);
639 /* Try to maximize in the y direction first */
640 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
641 if (x_intsect
!= 0) {
642 /* TODO: Consider the case when coords are equal */
643 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
644 /* w_0 is below the bottom of w_j */
645 new.top
= obs
.bottom
+ 1;
647 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
648 /* The bottom of w_0 is above the top of w_j */
649 new.bottom
= obs
.top
- 1;
656 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
657 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
663 set_window_coords(tmp
, &obs
);
666 * Use the new.top and new.height instead of original values
667 * as they may have different intersections with the obstructing windows
669 new.height
= new.bottom
- new.top
- adjust_height
;
670 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
671 if (y_intsect
!= 0) {
672 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
673 /* w_0 is completely to the right of w_j */
674 new.left
= obs
.right
+ 1;
676 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
677 /* w_0 is completely to the left of w_j */
678 new.right
= obs
.left
- 1;
685 /* xcalc needs -7 here, but other apps don't */
686 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
687 *new_width
= new.right
- new.left
;
690 void wUnmaximizeWindow(WWindow
*wwin
)
694 if (!wwin
->flags
.maximized
)
697 if (wwin
->flags
.shaded
) {
698 wwin
->flags
.skip_next_animation
= 1;
699 wUnshadeWindow(wwin
);
702 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
703 wwin
->client_flags
.no_movable
= 0;
705 /* Use old coordinates if they are set, current values otherwise */
706 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
708 /* unMaximusize relative to original position */
709 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
710 x
+= wwin
->frame_x
- wwin
->maximus_x
;
711 y
+= wwin
->frame_y
- wwin
->maximus_y
;
714 wwin
->flags
.maximized
= 0;
715 wwin
->flags
.old_maximized
= 0;
716 wWindowConfigure(wwin
, x
, y
, w
, h
);
717 wWindowSynthConfigureNotify(wwin
);
719 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
722 void wFullscreenWindow(WWindow
*wwin
)
727 if (wwin
->flags
.fullscreen
)
730 wwin
->flags
.fullscreen
= True
;
732 wWindowConfigureBorders(wwin
);
734 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
736 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
737 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
738 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
739 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
741 head
= wGetHeadForWindow(wwin
);
742 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
743 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
745 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
746 wSetFocusTo(wwin
->screen_ptr
, wwin
);
748 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
751 void wUnfullscreenWindow(WWindow
*wwin
)
753 if (!wwin
->flags
.fullscreen
)
756 wwin
->flags
.fullscreen
= False
;
758 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
759 if (WFLAGP(wwin
, sunken
)) {
760 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
761 } else if (WFLAGP(wwin
, floating
)) {
762 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
764 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
768 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
769 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
771 wWindowConfigureBorders(wwin
);
773 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
774 wFrameWindowPaint(wwin->frame);
777 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
779 if (wwin
->screen_ptr
->bfs_focused_window
) {
780 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
781 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
785 #ifdef USE_ANIMATIONS
786 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
788 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
789 float cx
, cy
, cw
, ch
;
790 float xstep
, ystep
, wstep
, hstep
;
793 float angle
, final_angle
, delta
;
795 xstep
= (float)(fx
- x
) / steps
;
796 ystep
= (float)(fy
- y
) / steps
;
797 wstep
= (float)(fw
- w
) / steps
;
798 hstep
= (float)(fh
- h
) / steps
;
805 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
806 delta
= (float)(final_angle
/ FRAMES
);
807 for (angle
= 0;; angle
+= delta
) {
808 if (angle
> final_angle
)
811 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
812 dch
= (ch
/ 2) * cosf(angle
);
813 midy
= cy
+ (ch
/ 2);
815 points
[0].x
= cx
+ dx
;
816 points
[0].y
= midy
- dch
;
817 points
[1].x
= cx
+ cw
- dx
;
818 points
[1].y
= points
[0].y
;
819 points
[2].x
= cx
+ cw
+ dx
;
820 points
[2].y
= midy
+ dch
;
821 points
[3].x
= cx
- dx
;
822 points
[3].y
= points
[2].y
;
823 points
[4].x
= points
[0].x
;
824 points
[4].y
= points
[0].y
;
827 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
829 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
831 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
837 if (angle
>= final_angle
)
847 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
849 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
850 float cx
, cy
, cw
, ch
;
851 float xstep
, ystep
, wstep
, hstep
;
853 float angle
, final_angle
, a
, d
, delta
;
860 xstep
= (float)(fx
- x
) / steps
;
861 ystep
= (float)(fy
- y
) / steps
;
862 wstep
= (float)(fw
- w
) / steps
;
863 hstep
= (float)(fh
- h
) / steps
;
870 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
871 delta
= (float)(final_angle
/ FRAMES
);
872 for (angle
= 0;; angle
+= delta
) {
873 if (angle
> final_angle
)
877 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
879 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
880 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
881 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
882 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
883 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
884 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
885 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
886 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
887 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
888 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
890 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
892 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
894 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
900 if (angle
>= final_angle
)
909 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
911 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
912 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
913 float xstep
, ystep
, wstep
, hstep
;
916 xstep
= (float)(fx
- x
) / steps
;
917 ystep
= (float)(fy
- y
) / steps
;
918 wstep
= (float)(fw
- w
) / steps
;
919 hstep
= (float)(fh
- h
) / steps
;
921 for (j
= 0; j
< FRAMES
; j
++) {
928 for (i
= 0; i
< steps
; i
++) {
929 for (j
= 0; j
< FRAMES
; j
++) {
930 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
931 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
934 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
936 for (j
= 0; j
< FRAMES
; j
++) {
937 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
938 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
939 if (j
< FRAMES
- 1) {
953 for (j
= 0; j
< FRAMES
; j
++)
954 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
956 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
958 for (j
= 0; j
< FRAMES
; j
++)
959 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
966 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
968 int style
= wPreferences
.iconification_style
; /* Catch the value */
971 if (style
== WIS_NONE
)
974 if (style
== WIS_RANDOM
)
979 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
981 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
984 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
986 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
990 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
992 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
996 #endif /* USE_ANIMATIONS */
998 static void flushExpose(void)
1002 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
1003 WMHandleEvent(&tmpev
);
1007 static void unmapTransientsFor(WWindow
*wwin
)
1011 tmp
= wwin
->screen_ptr
->focused_window
;
1013 /* unmap the transients for this transient */
1014 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1015 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1016 unmapTransientsFor(tmp
);
1017 tmp
->flags
.miniaturized
= 1;
1018 if (!tmp
->flags
.shaded
)
1021 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1023 if (!tmp->flags.shaded)
1025 wClientSetState(tmp
, IconicState
, None
);
1027 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1033 static void mapTransientsFor(WWindow
*wwin
)
1037 tmp
= wwin
->screen_ptr
->focused_window
;
1039 /* recursively map the transients for this transient */
1040 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1041 && tmp
->icon
== NULL
) {
1042 mapTransientsFor(tmp
);
1043 tmp
->flags
.miniaturized
= 0;
1044 if (!tmp
->flags
.shaded
)
1047 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1048 tmp
->flags
.semi_focused
= 0;
1050 if (!tmp->flags.shaded)
1052 wClientSetState(tmp
, NormalState
, None
);
1054 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1060 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1067 /* hackish way to detect transient_for cycle */
1068 i
= wwin
->screen_ptr
->window_count
+ 1;
1070 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1071 wwin
= wWindowFor(wwin
->transient_for
);
1074 if (i
== 0 && wwin
) {
1075 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1076 wwin
->frame
->title
);
1083 #ifdef USE_ANIMATIONS
1084 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1086 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1087 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1090 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1093 *iw
= wwin
->icon
->core
->width
;
1094 *ih
= wwin
->icon
->core
->height
;
1096 if (wwin
->flags
.net_handle_icon
) {
1104 *iw
= wwin
->screen_ptr
->scr_width
;
1105 *ih
= wwin
->screen_ptr
->scr_height
;
1110 #endif /* USE_ANIMATIONS */
1112 void wIconifyWindow(WWindow
*wwin
)
1114 XWindowAttributes attribs
;
1117 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1118 return; /* the window doesn't exist anymore */
1120 if (wwin
->flags
.miniaturized
)
1121 return; /* already miniaturized */
1123 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1124 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1126 if (owner
&& owner
->flags
.miniaturized
)
1130 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1132 /* if the window is in another workspace, simplify process */
1134 /* icon creation may take a while */
1135 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1136 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1137 GrabModeAsync
, None
, None
, CurrentTime
);
1140 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1141 if (!wwin
->flags
.icon_moved
)
1142 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1144 wwin
->icon
= icon_create_for_wwindow(wwin
);
1145 wwin
->icon
->mapped
= 1;
1147 /* extract the window screenshot every time, as the option can be enable anytime */
1148 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1149 RImage
*mini_preview
;
1155 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1156 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1161 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1162 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1164 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1165 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1167 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1169 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1170 XDestroyImage(pimg
);
1173 set_icon_minipreview(wwin
->icon
, mini_preview
);
1174 RReleaseImage(mini_preview
);
1179 if (wwin
->frame
->title
) {
1180 title
= wwin
->frame
->title
;
1182 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1185 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1191 wwin
->flags
.miniaturized
= 1;
1192 wwin
->flags
.mapped
= 0;
1194 /* unmap transients */
1195 unmapTransientsFor(wwin
);
1198 #ifdef USE_ANIMATIONS
1201 XUngrabPointer(dpy
, CurrentTime
);
1203 /* let all Expose events arrive so that we can repaint
1204 * something before the animation starts (and the server is grabbed) */
1207 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1208 wClientSetState(wwin
, IconicState
, None
);
1210 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1213 #ifdef USE_ANIMATIONS
1214 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1215 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1216 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1220 wwin
->flags
.skip_next_animation
= 0;
1222 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1223 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1224 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1225 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1227 AddToStackList(wwin
->icon
->core
);
1228 wLowerFrame(wwin
->icon
->core
);
1232 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1235 * It doesn't seem to be working and causes button event hangup
1236 * when deiconifying a transient window.
1237 setupIconGrabs(wwin->icon);
1239 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1240 && wPreferences
.focus_mode
== WKF_CLICK
) {
1245 if (!WFLAGP(tmp
, no_focusable
)
1246 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1247 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1251 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1252 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1253 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1255 #ifdef USE_ANIMATIONS
1256 if (!wwin
->screen_ptr
->flags
.startup
) {
1257 /* Catch up with events not processed while animation was running */
1258 Window clientwin
= wwin
->client_win
;
1260 ProcessPendingEvents();
1262 /* the window can disappear while ProcessPendingEvents() runs */
1263 if (!wWindowFor(clientwin
))
1269 /* maybe we want to do this regardless of net_handle_icon
1270 * it seems to me we might break behaviour this way.
1272 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1273 && !wwin
->flags
.net_handle_icon
)
1274 wIconSelect(wwin
->icon
);
1276 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1278 if (wPreferences
.auto_arrange_icons
)
1279 wArrangeIcons(wwin
->screen_ptr
, True
);
1282 void wDeiconifyWindow(WWindow
*wwin
)
1284 /* Let's avoid changing workspace while deiconifying */
1285 w_global
.ignore_workspace_change
= True
;
1287 /* we're hiding for show_desktop */
1288 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1289 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1292 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1294 if (!wwin
->flags
.miniaturized
) {
1295 w_global
.ignore_workspace_change
= False
;
1299 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1300 WWindow
*owner
= recursiveTransientFor(wwin
);
1302 if (owner
&& owner
->flags
.miniaturized
) {
1303 wDeiconifyWindow(owner
);
1304 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1305 wRaiseFrame(wwin
->frame
->core
);
1306 w_global
.ignore_workspace_change
= False
;
1311 wwin
->flags
.miniaturized
= 0;
1313 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1314 wwin
->flags
.mapped
= 1;
1316 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1317 /* maybe we want to do this regardless of net_handle_icon
1318 * it seems to me we might break behaviour this way.
1320 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1321 && wwin
->icon
!= NULL
) {
1322 if (wwin
->icon
->selected
)
1323 wIconSelect(wwin
->icon
);
1325 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1329 /* if the window is in another workspace, do it silently */
1330 if (!netwm_hidden
) {
1331 #ifdef USE_ANIMATIONS
1333 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1334 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1335 wwin
->frame_x
, wwin
->frame_y
,
1336 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1338 wwin
->flags
.skip_next_animation
= 0;
1340 if (!wwin
->flags
.shaded
)
1341 XMapWindow(dpy
, wwin
->client_win
);
1343 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1344 wRaiseFrame(wwin
->frame
->core
);
1345 if (!wwin
->flags
.shaded
)
1346 wClientSetState(wwin
, NormalState
, None
);
1348 mapTransientsFor(wwin
);
1351 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1352 && !wwin
->flags
.net_handle_icon
) {
1353 RemoveFromStackList(wwin
->icon
->core
);
1354 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1355 wIconDestroy(wwin
->icon
);
1359 if (!netwm_hidden
) {
1362 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1364 #ifdef USE_ANIMATIONS
1365 if (!wwin
->screen_ptr
->flags
.startup
) {
1366 /* Catch up with events not processed while animation was running */
1367 Window clientwin
= wwin
->client_win
;
1369 ProcessPendingEvents();
1371 /* the window can disappear while ProcessPendingEvents() runs */
1372 if (!wWindowFor(clientwin
)) {
1373 w_global
.ignore_workspace_change
= False
;
1380 if (wPreferences
.auto_arrange_icons
)
1381 wArrangeIcons(wwin
->screen_ptr
, True
);
1383 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1385 /* In case we were shaded and iconified, also unshade */
1387 wUnshadeWindow(wwin
);
1389 w_global
.ignore_workspace_change
= False
;
1392 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1394 if (wwin
->flags
.miniaturized
) {
1396 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1397 wwin
->icon
->mapped
= 0;
1399 wwin
->flags
.hidden
= 1;
1401 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1405 if (wwin
->flags
.inspector_open
)
1406 wHideInspectorForWindow(wwin
);
1408 wwin
->flags
.hidden
= 1;
1411 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1414 #ifdef USE_ANIMATIONS
1415 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1416 !wwin
->flags
.skip_next_animation
&& animate
) {
1417 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1418 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1419 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1422 /* Tell the compiler it is normal that those parameters are not used in this case */
1427 wwin
->flags
.skip_next_animation
= 0;
1429 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1432 void wHideAll(WScreen
*scr
)
1437 unsigned int wcount
= 0;
1443 menu
= scr
->switch_menu
;
1445 windows
= wmalloc(sizeof(WWindow
*));
1448 for (i
= 0; i
< menu
->entry_no
; i
++) {
1449 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1451 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1454 wwin
= scr
->focused_window
;
1457 windows
[wcount
] = wwin
;
1459 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1465 for (i
= 0; i
< wcount
; i
++) {
1467 if (wwin
->frame
->workspace
== scr
->current_workspace
1468 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1469 && !wwin
->flags
.internal_window
1470 && !WFLAGP(wwin
, no_miniaturizable
)
1472 wwin
->flags
.skip_next_animation
= 1;
1473 wIconifyWindow(wwin
);
1480 void wHideOtherApplications(WWindow
*awin
)
1487 wwin
= awin
->screen_ptr
->focused_window
;
1491 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1492 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1493 && !wwin
->flags
.internal_window
1494 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1496 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1497 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1498 wwin
->flags
.skip_next_animation
= 1;
1499 wIconifyWindow(wwin
);
1501 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1502 tapp
= wApplicationOf(wwin
->main_window
);
1504 tapp
->flags
.skip_next_animation
= 1;
1505 wHideApplication(tapp
);
1507 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1508 wwin
->flags
.skip_next_animation
= 1;
1509 wIconifyWindow(wwin
);
1517 wSetFocusTo(awin->screen_ptr, awin);
1521 void wHideApplication(WApplication
*wapp
)
1529 wwarning("trying to hide a non grouped window");
1532 if (!wapp
->main_window_desc
) {
1533 wwarning("group leader not found for window group");
1536 scr
= wapp
->main_window_desc
->screen_ptr
;
1538 wlist
= scr
->focused_window
;
1542 if (wlist
->main_window
== wapp
->main_window
)
1543 wapp
->last_focused
= wlist
;
1545 wapp
->last_focused
= NULL
;
1547 animate
= !wapp
->flags
.skip_next_animation
;
1550 if (wlist
->main_window
== wapp
->main_window
) {
1551 if (wlist
->flags
.focused
)
1553 if (wapp
->app_icon
) {
1554 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1555 wapp
->app_icon
->y_pos
, wlist
, animate
);
1559 wlist
= wlist
->prev
;
1562 wapp
->flags
.skip_next_animation
= 0;
1565 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1566 wlist
= scr
->focused_window
;
1568 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1569 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1571 wlist
= wlist
->prev
;
1573 wSetFocusTo(scr
, wlist
);
1575 wSetFocusTo(scr
, NULL
);
1579 wapp
->flags
.hidden
= 1;
1581 if (wPreferences
.auto_arrange_icons
)
1582 wArrangeIcons(scr
, True
);
1586 wAppIconPaint(wapp
->app_icon
);
1590 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1592 if (bringToCurrentWS
)
1593 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1595 wwin
->flags
.hidden
= 0;
1597 #ifdef USE_ANIMATIONS
1598 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1599 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1600 icon
->core
->width
, icon
->core
->height
,
1601 wwin
->frame_x
, wwin
->frame_y
,
1602 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1605 /* Tell the compiler it is normal that those parameters are not used in this case */
1611 wwin
->flags
.skip_next_animation
= 0;
1612 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1613 XMapWindow(dpy
, wwin
->client_win
);
1614 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1615 wClientSetState(wwin
, NormalState
, None
);
1616 wwin
->flags
.mapped
= 1;
1617 wRaiseFrame(wwin
->frame
->core
);
1619 if (wwin
->flags
.inspector_open
)
1620 wUnhideInspectorForWindow(wwin
);
1622 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1625 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1628 WWindow
*wlist
, *next
;
1629 WWindow
*focused
= NULL
;
1635 scr
= wapp
->main_window_desc
->screen_ptr
;
1636 wlist
= scr
->focused_window
;
1640 /* goto beginning of list */
1642 wlist
= wlist
->prev
;
1644 animate
= !wapp
->flags
.skip_next_animation
;
1649 if (wlist
->main_window
== wapp
->main_window
) {
1650 if (wlist
->flags
.focused
)
1652 else if (!focused
|| !focused
->flags
.focused
)
1655 if (wlist
->flags
.miniaturized
) {
1656 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1657 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1658 if (!wlist
->icon
->mapped
) {
1661 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1662 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1663 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1666 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1667 wlist
->icon
->mapped
= 1;
1669 wRaiseFrame(wlist
->icon
->core
);
1671 if (bringToCurrentWS
)
1672 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1673 wlist
->flags
.hidden
= 0;
1674 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1675 wDeiconifyWindow(wlist
);
1676 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1677 } else if (wlist
->flags
.shaded
) {
1678 if (bringToCurrentWS
)
1679 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1680 wlist
->flags
.hidden
= 0;
1681 wRaiseFrame(wlist
->frame
->core
);
1682 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1683 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1685 wUnshadeWindow(wlist
);
1687 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1688 } else if (wlist
->flags
.hidden
) {
1689 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1690 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1693 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1694 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1696 wRaiseFrame(wlist
->frame
->core
);
1702 wapp
->flags
.skip_next_animation
= 0;
1703 wapp
->flags
.hidden
= 0;
1705 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1706 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1707 wSetFocusTo(scr
, wapp
->last_focused
);
1708 } else if (focused
) {
1709 wSetFocusTo(scr
, focused
);
1711 wapp
->last_focused
= NULL
;
1712 if (wPreferences
.auto_arrange_icons
)
1713 wArrangeIcons(scr
, True
);
1716 wAppIconPaint(wapp
->app_icon
);
1720 void wShowAllWindows(WScreen
*scr
)
1722 WWindow
*wwin
, *old_foc
;
1725 old_foc
= wwin
= scr
->focused_window
;
1727 if (!wwin
->flags
.internal_window
&&
1728 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1729 if (wwin
->flags
.miniaturized
) {
1730 wwin
->flags
.skip_next_animation
= 1;
1731 wDeiconifyWindow(wwin
);
1732 } else if (wwin
->flags
.hidden
) {
1733 wapp
= wApplicationOf(wwin
->main_window
);
1735 wUnhideApplication(wapp
, False
, False
);
1737 wwin
->flags
.skip_next_animation
= 1;
1738 wDeiconifyWindow(wwin
);
1744 wSetFocusTo(scr
, old_foc
);
1745 /*wRaiseFrame(old_foc->frame->core); */
1748 void wRefreshDesktop(WScreen
*scr
)
1751 XSetWindowAttributes attr
;
1753 attr
.backing_store
= NotUseful
;
1754 attr
.save_under
= False
;
1755 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1756 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1757 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1758 XMapRaised(dpy
, win
);
1759 XDestroyWindow(dpy
, win
);
1763 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1769 const int heads
= wXineramaHeads(scr
);
1772 int pf
; /* primary axis */
1773 int sf
; /* secondary axis */
1777 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1783 int isize
= wPreferences
.icon_size
;
1785 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1787 for (head
= 0; head
< heads
; ++head
) {
1788 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1792 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1794 if (scr
->dock
->on_right_side
)
1800 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1802 vars
[head
].pi
= vars
[head
].si
= 0;
1803 vars
[head
].sx1
= rect
.pos
.x
;
1804 vars
[head
].sy1
= rect
.pos
.y
;
1805 vars
[head
].sw
= rect
.size
.width
;
1806 vars
[head
].sh
= rect
.size
.height
;
1807 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1808 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1809 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1810 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1811 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1812 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1814 /* icon yard boundaries */
1815 if (wPreferences
.icon_yard
& IY_VERT
) {
1816 vars
[head
].pf
= vars
[head
].fullH
;
1817 vars
[head
].sf
= vars
[head
].fullW
;
1819 vars
[head
].pf
= vars
[head
].fullW
;
1820 vars
[head
].sf
= vars
[head
].fullH
;
1822 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1823 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1826 vars
[head
].xo
= vars
[head
].sx1
;
1829 if (wPreferences
.icon_yard
& IY_TOP
) {
1830 vars
[head
].yo
= vars
[head
].sy1
;
1833 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1838 #define X ((wPreferences.icon_yard & IY_VERT) \
1839 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1840 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1842 #define Y ((wPreferences.icon_yard & IY_VERT) \
1843 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1844 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1846 /* arrange application icons */
1847 aicon
= scr
->app_icon_list
;
1848 /* reverse them to avoid unnecessarily sliding of icons */
1849 while (aicon
&& aicon
->next
)
1850 aicon
= aicon
->next
;
1853 if (!aicon
->docked
) {
1854 /* CHECK: can icon be NULL here ? */
1855 /* The intention here is to place the AppIcon on the head that
1856 * contains most of the applications _main_ window. */
1857 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1859 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1860 #ifdef USE_ANIMATIONS
1861 if (!wPreferences
.no_animations
)
1862 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1863 #endif /* USE_ANIMATIONS */
1865 wAppIconMove(aicon
, X
, Y
);
1867 if (vars
[head
].pi
>= vars
[head
].pf
) {
1872 aicon
= aicon
->prev
;
1875 /* arrange miniwindows */
1876 wwin
= scr
->focused_window
;
1877 /* reverse them to avoid unnecessarily shuffling */
1878 while (wwin
&& wwin
->prev
)
1882 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1883 (wwin
->frame
->workspace
== scr
->current_workspace
||
1884 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1886 head
= wGetHeadForWindow(wwin
);
1888 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1889 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1890 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1896 if (vars
[head
].pi
>= vars
[head
].pf
) {
1903 wwin
->flags
.icon_moved
= 0;
1904 /* we reversed the order, so we use next */
1911 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1913 WScreen
*scr
= wwin
->screen_ptr
;
1916 wwin
->flags
.selected
= 1;
1917 if (wwin
->frame
->selected_border_pixel
)
1918 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1920 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1922 if (!HAS_BORDER(wwin
))
1923 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1925 if (!scr
->selected_windows
)
1926 scr
->selected_windows
= WMCreateArray(4);
1927 WMAddToArray(scr
->selected_windows
, wwin
);
1929 wwin
->flags
.selected
= 0;
1930 if (wwin
->flags
.focused
) {
1931 if (wwin
->frame
->focused_border_pixel
)
1932 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1934 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1936 if (wwin
->frame
->border_pixel
)
1937 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1939 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1942 if (!HAS_BORDER(wwin
))
1943 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1945 if (scr
->selected_windows
)
1946 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1950 void wMakeWindowVisible(WWindow
*wwin
)
1952 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1953 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1955 if (wwin
->flags
.shaded
)
1956 wUnshadeWindow(wwin
);
1958 if (wwin
->flags
.hidden
) {
1961 app
= wApplicationOf(wwin
->main_window
);
1963 /* trick to get focus to this window */
1964 app
->last_focused
= wwin
;
1965 wUnhideApplication(app
, False
, False
);
1968 if (wwin
->flags
.miniaturized
) {
1969 wDeiconifyWindow(wwin
);
1971 if (!WFLAGP(wwin
, no_focusable
))
1972 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1973 wRaiseFrame(wwin
->frame
->core
);
1978 * Do the animation while shading (called with what = SHADE)
1979 * or unshading (what = UNSHADE).
1981 #ifdef USE_ANIMATIONS
1982 static void shade_animate(WWindow
*wwin
, Bool what
)
1985 time_t time0
= time(NULL
);
1987 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1992 if (!wwin
->screen_ptr
->flags
.startup
) {
1993 /* do the shading animation */
1994 h
= wwin
->frame
->core
->height
;
1995 s
= h
/ SHADE_STEPS
;
1998 w
= wwin
->frame
->core
->width
;
1999 y
= wwin
->frame
->top_width
;
2000 while (h
> wwin
->frame
->top_width
+ 1) {
2001 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2002 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2005 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2008 if (SHADE_DELAY
> 0)
2009 wusleep(SHADE_DELAY
* 1000L);
2015 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2020 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2021 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2022 s
= abs(y
) / SHADE_STEPS
;
2025 w
= wwin
->frame
->core
->width
;
2026 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2028 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2029 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2030 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2032 if (SHADE_DELAY
> 0)
2033 wusleep(SHADE_DELAY
* 2000L / 3);
2039 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2043 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);