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
);
221 wWindowFocus(wwin
, focused
);
223 if (napp
&& !wasfocused
) {
225 wUserMenuRefreshInstances(napp
->menu
, wwin
);
226 #endif /* USER_MENU */
228 /* kix: Only menu map with mouse, not alt+tab! */
229 if (wwin
->flags
.mapped
)
230 wAppMenuMap(napp
->menu
, wwin
);
232 if (napp
&& wPreferences
.highlight_active_app
)
233 wApplicationActivate(napp
);
239 void wShadeWindow(WWindow
*wwin
)
242 if (wwin
->flags
.shaded
)
245 XLowerWindow(dpy
, wwin
->client_win
);
246 shade_animate(wwin
, SHADE
);
248 wwin
->flags
.skip_next_animation
= 0;
249 wwin
->flags
.shaded
= 1;
250 wwin
->flags
.mapped
= 0;
251 /* prevent window withdrawal when getting UnmapNotify */
252 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
253 XUnmapWindow(dpy
, wwin
->client_win
);
254 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
256 /* for the client it's just like iconification */
257 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
259 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
260 wWindowSynthConfigureNotify(wwin
);
263 wClientSetState(wwin, IconicState, None);
266 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
268 #ifdef USE_ANIMATIONS
269 if (!wwin
->screen_ptr
->flags
.startup
) {
270 /* Catch up with events not processed while animation was running */
271 ProcessPendingEvents();
276 void wUnshadeWindow(WWindow
*wwin
)
279 if (!wwin
->flags
.shaded
)
282 wwin
->flags
.shaded
= 0;
283 wwin
->flags
.mapped
= 1;
284 XMapWindow(dpy
, wwin
->client_win
);
286 shade_animate(wwin
, UNSHADE
);
288 wwin
->flags
.skip_next_animation
= 0;
289 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
290 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
292 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
293 wWindowSynthConfigureNotify(wwin
);
295 /* if the window is focused, set the focus again as it was disabled during
297 if (wwin
->flags
.focused
)
298 wSetFocusTo(wwin
->screen_ptr
, wwin
);
300 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
303 /* Set the old coordinates using the current values */
304 static void save_old_geometry(WWindow
*wwin
, int directions
)
306 /* never been saved? */
307 if (!wwin
->old_geometry
.width
)
308 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
309 if (!wwin
->old_geometry
.height
)
310 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
312 if (directions
& SAVE_GEOMETRY_X
)
313 wwin
->old_geometry
.x
= wwin
->frame_x
;
314 if (directions
& SAVE_GEOMETRY_Y
)
315 wwin
->old_geometry
.y
= wwin
->frame_y
;
316 if (directions
& SAVE_GEOMETRY_WIDTH
)
317 wwin
->old_geometry
.width
= wwin
->client
.width
;
318 if (directions
& SAVE_GEOMETRY_HEIGHT
)
319 wwin
->old_geometry
.height
= wwin
->client
.height
;
322 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
324 WMRect old_geom_rect
;
328 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
329 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
330 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
331 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
332 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
333 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
334 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
337 /* Remember geometry for unmaximizing */
338 void update_saved_geometry(WWindow
*wwin
)
340 /* NOT if we aren't already maximized
341 * we'll save geometry when maximizing */
342 if (!wwin
->flags
.maximized
)
345 /* NOT if we are fully maximized */
346 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
347 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
348 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
351 /* save the co-ordinate in the axis in which we AREN'T maximized */
352 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
353 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
354 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
355 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
358 void wMaximizeWindow(WWindow
*wwin
, int directions
)
360 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
365 unsigned int maximus_width
= 0;
366 unsigned int maximus_height
= 0;
367 WArea usableArea
, totalArea
;
370 WScreen
*scr
= wwin
->screen_ptr
;
372 if (!IS_RESIZABLE(wwin
))
375 if (!HAS_BORDER(wwin
))
378 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
379 wwin
->client_flags
.no_movable
= 1;
381 /* the size to adjust the geometry */
382 adj_size
= scr
->frame_border_width
* 2 * has_border
;
384 /* save old coordinates before we change the current values */
385 if (!wwin
->flags
.maximized
)
386 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
388 totalArea
.x2
= scr
->scr_width
;
389 totalArea
.y2
= scr
->scr_height
;
392 usableArea
= totalArea
;
394 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
395 WScreen
*scr
= wwin
->screen_ptr
;
398 if (directions
& MAX_KEYBOARD
)
399 head
= wGetHeadForWindow(wwin
);
401 head
= wGetHeadForPointerLocation(scr
);
403 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
407 /* Only save directions, not kbd or xinerama hints */
408 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
410 if (WFLAGP(wwin
, full_maximize
))
411 usableArea
= totalArea
;
412 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
413 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
415 if (wwin
->flags
.shaded
) {
416 wwin
->flags
.skip_next_animation
= 1;
417 wUnshadeWindow(wwin
);
420 if (directions
& MAX_MAXIMUS
) {
421 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
422 new_width
= maximus_width
- adj_size
;
423 new_height
= maximus_height
- adj_size
;
426 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
427 new_height
+= wwin
->frame
->bottom_width
- 1;
428 new_y
-= wwin
->frame
->top_width
;
431 wwin
->maximus_x
= new_x
;
432 wwin
->maximus_y
= new_y
;
433 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
435 /* set default values if no option set then */
436 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
437 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
438 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
440 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
441 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
442 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
445 /* left|right position */
446 if (directions
& MAX_LEFTHALF
) {
447 new_width
= half_scr_width
- adj_size
;
448 new_x
= usableArea
.x1
;
449 } else if (directions
& MAX_RIGHTHALF
) {
450 new_width
= half_scr_width
- adj_size
;
451 new_x
= usableArea
.x1
+ half_scr_width
;
453 /* top|bottom position */
454 if (directions
& MAX_TOPHALF
) {
455 new_height
= half_scr_height
- adj_size
;
456 new_y
= usableArea
.y1
;
457 } else if (directions
& MAX_BOTTOMHALF
) {
458 new_height
= half_scr_height
- adj_size
;
459 new_y
= usableArea
.y1
+ half_scr_height
;
462 /* vertical|horizontal position */
463 if (directions
& MAX_HORIZONTAL
) {
464 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
465 new_x
= usableArea
.x1
;
467 if (directions
& MAX_VERTICAL
) {
468 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
469 new_y
= usableArea
.y1
;
470 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
471 new_y
-= wwin
->frame
->top_width
;
475 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
476 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
478 /* set maximization state */
479 wwin
->flags
.maximized
= directions
;
480 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
481 wwin
->flags
.maximized
= MAX_MAXIMUS
;
483 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
485 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
486 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
488 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
489 wWindowSynthConfigureNotify(wwin
);
491 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
494 /* generic (un)maximizer */
495 void handleMaximize(WWindow
*wwin
, int directions
)
497 int current
= wwin
->flags
.maximized
;
498 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
499 int effective
= requested
^ current
;
500 int flags
= directions
& ~requested
;
503 /* allow wMaximizeWindow to restore the Maximusized size */
504 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
505 !(requested
& MAX_MAXIMUS
))
506 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
508 wUnmaximizeWindow(wwin
);
509 /* these alone mean vertical|horizontal toggle */
510 } else if ((effective
== MAX_LEFTHALF
) ||
511 (effective
== MAX_RIGHTHALF
) ||
512 (effective
== MAX_TOPHALF
) ||
513 (effective
== MAX_BOTTOMHALF
))
514 wUnmaximizeWindow(wwin
);
516 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
517 (requested
== MAX_MAXIMUS
))
518 effective
= requested
;
520 if (requested
& MAX_LEFTHALF
) {
521 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
522 effective
|= MAX_VERTICAL
;
524 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
525 effective
|= MAX_LEFTHALF
;
526 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
527 } else if (requested
& MAX_RIGHTHALF
) {
528 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
529 effective
|= MAX_VERTICAL
;
531 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
532 effective
|= MAX_RIGHTHALF
;
533 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
535 if (requested
& MAX_TOPHALF
) {
536 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
537 effective
|= MAX_HORIZONTAL
;
539 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
540 effective
|= MAX_TOPHALF
;
541 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
542 } else if (requested
& MAX_BOTTOMHALF
) {
543 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
544 effective
|= MAX_HORIZONTAL
;
546 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
547 effective
|= MAX_BOTTOMHALF
;
548 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
550 if (requested
& MAX_HORIZONTAL
)
551 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
552 if (requested
& MAX_VERTICAL
)
553 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
554 effective
&= ~MAX_MAXIMUS
;
556 wMaximizeWindow(wwin
, effective
| flags
);
560 /* the window boundary coordinates */
570 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
572 obs
->left
= wwin
->frame_x
;
573 obs
->top
= wwin
->frame_y
;
574 obs
->width
= wwin
->frame
->core
->width
;
575 obs
->height
= wwin
->frame
->core
->height
;
576 obs
->bottom
= obs
->top
+ obs
->height
;
577 obs
->right
= obs
->left
+ obs
->width
;
581 * Maximus: tiled maximization (maximize without overlapping other windows)
583 * The original window 'orig' will be maximized to new coordinates 'new'.
584 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
586 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
587 unsigned int *new_width
, unsigned int *new_height
)
590 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
591 short int adjust_height
;
592 int x_intsect
, y_intsect
;
593 /* the obstructing, original and new windows */
594 win_coords obs
, orig
, new;
596 /* set the original coordinate positions of the window to be Maximumized */
597 if (wwin
->flags
.maximized
) {
598 /* window is already maximized; consider original geometry */
599 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
600 orig
.bottom
= orig
.top
+ orig
.height
;
601 orig
.right
= orig
.left
+ orig
.width
;
603 set_window_coords(wwin
, &orig
);
605 /* Try to fully maximize first, then readjust later */
606 new.left
= usableArea
.x1
;
607 new.right
= usableArea
.x2
;
608 new.top
= usableArea
.y1
;
609 new.bottom
= usableArea
.y2
;
611 if (HAS_TITLEBAR(wwin
))
612 tbar_height_0
= TITLEBAR_HEIGHT
;
613 if (HAS_RESIZEBAR(wwin
))
614 rbar_height_0
= RESIZEBAR_HEIGHT
;
615 if (HAS_BORDER(wwin
))
616 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
618 /* the length to be subtracted if the window has titlebar, etc */
619 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
622 /* The focused window is always the last in the list */
624 /* ignore windows in other workspaces etc */
625 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
626 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
632 /* Set the coordinates of obstructing window */
633 set_window_coords(tmp
, &obs
);
635 /* Try to maximize in the y direction first */
636 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
637 if (x_intsect
!= 0) {
638 /* TODO: Consider the case when coords are equal */
639 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
640 /* w_0 is below the bottom of w_j */
641 new.top
= obs
.bottom
+ 1;
643 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
644 /* The bottom of w_0 is above the top of w_j */
645 new.bottom
= obs
.top
- 1;
652 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
653 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
659 set_window_coords(tmp
, &obs
);
662 * Use the new.top and new.height instead of original values
663 * as they may have different intersections with the obstructing windows
665 new.height
= new.bottom
- new.top
- adjust_height
;
666 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
667 if (y_intsect
!= 0) {
668 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
669 /* w_0 is completely to the right of w_j */
670 new.left
= obs
.right
+ 1;
672 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
673 /* w_0 is completely to the left of w_j */
674 new.right
= obs
.left
- 1;
681 /* xcalc needs -7 here, but other apps don't */
682 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
683 *new_width
= new.right
- new.left
;
686 void wUnmaximizeWindow(WWindow
*wwin
)
690 if (!wwin
->flags
.maximized
)
693 if (wwin
->flags
.shaded
) {
694 wwin
->flags
.skip_next_animation
= 1;
695 wUnshadeWindow(wwin
);
698 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
699 wwin
->client_flags
.no_movable
= 0;
701 /* Use old coordinates if they are set, current values otherwise */
702 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
704 /* unMaximusize relative to original position */
705 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
706 x
+= wwin
->frame_x
- wwin
->maximus_x
;
707 y
+= wwin
->frame_y
- wwin
->maximus_y
;
710 wwin
->flags
.maximized
= 0;
711 wwin
->flags
.old_maximized
= 0;
712 wWindowConfigure(wwin
, x
, y
, w
, h
);
713 wWindowSynthConfigureNotify(wwin
);
715 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
718 void wFullscreenWindow(WWindow
*wwin
)
723 if (wwin
->flags
.fullscreen
)
726 wwin
->flags
.fullscreen
= True
;
728 wWindowConfigureBorders(wwin
);
730 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
731 wRaiseFrame(wwin
->frame
->core
);
733 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
734 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
735 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
736 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
738 head
= wGetHeadForWindow(wwin
);
739 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
740 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
742 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
743 wSetFocusTo(wwin
->screen_ptr
, wwin
);
745 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
748 void wUnfullscreenWindow(WWindow
*wwin
)
750 if (!wwin
->flags
.fullscreen
)
753 wwin
->flags
.fullscreen
= False
;
755 if (WFLAGP(wwin
, sunken
))
756 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
757 else if (WFLAGP(wwin
, floating
))
758 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
760 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
761 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
763 wWindowConfigureBorders(wwin
);
765 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
766 wFrameWindowPaint(wwin->frame);
769 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
771 if (wwin
->screen_ptr
->bfs_focused_window
) {
772 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
773 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
777 #ifdef USE_ANIMATIONS
778 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
780 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
781 float cx
, cy
, cw
, ch
;
782 float xstep
, ystep
, wstep
, hstep
;
785 float angle
, final_angle
, delta
;
787 xstep
= (float)(fx
- x
) / steps
;
788 ystep
= (float)(fy
- y
) / steps
;
789 wstep
= (float)(fw
- w
) / steps
;
790 hstep
= (float)(fh
- h
) / steps
;
797 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
798 delta
= (float)(final_angle
/ FRAMES
);
799 for (angle
= 0;; angle
+= delta
) {
800 if (angle
> final_angle
)
803 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
804 dch
= (ch
/ 2) * cosf(angle
);
805 midy
= cy
+ (ch
/ 2);
807 points
[0].x
= cx
+ dx
;
808 points
[0].y
= midy
- dch
;
809 points
[1].x
= cx
+ cw
- dx
;
810 points
[1].y
= points
[0].y
;
811 points
[2].x
= cx
+ cw
+ dx
;
812 points
[2].y
= midy
+ dch
;
813 points
[3].x
= cx
- dx
;
814 points
[3].y
= points
[2].y
;
815 points
[4].x
= points
[0].x
;
816 points
[4].y
= points
[0].y
;
819 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
821 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
823 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
829 if (angle
>= final_angle
)
839 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
841 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
842 float cx
, cy
, cw
, ch
;
843 float xstep
, ystep
, wstep
, hstep
;
845 float angle
, final_angle
, a
, d
, delta
;
852 xstep
= (float)(fx
- x
) / steps
;
853 ystep
= (float)(fy
- y
) / steps
;
854 wstep
= (float)(fw
- w
) / steps
;
855 hstep
= (float)(fh
- h
) / steps
;
862 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
863 delta
= (float)(final_angle
/ FRAMES
);
864 for (angle
= 0;; angle
+= delta
) {
865 if (angle
> final_angle
)
869 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
871 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
872 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
873 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
874 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
875 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
876 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
877 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
878 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
879 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
880 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
882 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
884 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
886 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
892 if (angle
>= final_angle
)
901 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
903 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
904 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
905 float xstep
, ystep
, wstep
, hstep
;
908 xstep
= (float)(fx
- x
) / steps
;
909 ystep
= (float)(fy
- y
) / steps
;
910 wstep
= (float)(fw
- w
) / steps
;
911 hstep
= (float)(fh
- h
) / steps
;
913 for (j
= 0; j
< FRAMES
; j
++) {
920 for (i
= 0; i
< steps
; i
++) {
921 for (j
= 0; j
< FRAMES
; j
++) {
922 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
923 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
926 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
928 for (j
= 0; j
< FRAMES
; j
++) {
929 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
930 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
931 if (j
< FRAMES
- 1) {
945 for (j
= 0; j
< FRAMES
; j
++)
946 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
948 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
950 for (j
= 0; j
< FRAMES
; j
++)
951 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
958 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
960 int style
= wPreferences
.iconification_style
; /* Catch the value */
963 if (style
== WIS_NONE
)
966 if (style
== WIS_RANDOM
)
971 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
973 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
976 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
978 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
982 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
984 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
988 #endif /* USE_ANIMATIONS */
990 static void flushExpose(void)
994 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
995 WMHandleEvent(&tmpev
);
999 static void unmapTransientsFor(WWindow
*wwin
)
1003 tmp
= wwin
->screen_ptr
->focused_window
;
1005 /* unmap the transients for this transient */
1006 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1007 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1008 unmapTransientsFor(tmp
);
1009 tmp
->flags
.miniaturized
= 1;
1010 if (!tmp
->flags
.shaded
)
1013 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1015 if (!tmp->flags.shaded)
1017 wClientSetState(tmp
, IconicState
, None
);
1019 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1025 static void mapTransientsFor(WWindow
*wwin
)
1029 tmp
= wwin
->screen_ptr
->focused_window
;
1031 /* recursively map the transients for this transient */
1032 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1033 && tmp
->icon
== NULL
) {
1034 mapTransientsFor(tmp
);
1035 tmp
->flags
.miniaturized
= 0;
1036 if (!tmp
->flags
.shaded
)
1039 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1040 tmp
->flags
.semi_focused
= 0;
1042 if (!tmp->flags.shaded)
1044 wClientSetState(tmp
, NormalState
, None
);
1046 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1052 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1059 /* hackish way to detect transient_for cycle */
1060 i
= wwin
->screen_ptr
->window_count
+ 1;
1062 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1063 wwin
= wWindowFor(wwin
->transient_for
);
1066 if (i
== 0 && wwin
) {
1067 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1068 wwin
->frame
->title
);
1075 #ifdef USE_ANIMATIONS
1076 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1078 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1079 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1082 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1085 *iw
= wwin
->icon
->core
->width
;
1086 *ih
= wwin
->icon
->core
->height
;
1088 if (wwin
->flags
.net_handle_icon
) {
1096 *iw
= wwin
->screen_ptr
->scr_width
;
1097 *ih
= wwin
->screen_ptr
->scr_height
;
1102 #endif /* USE_ANIMATIONS */
1104 void wIconifyWindow(WWindow
*wwin
)
1106 XWindowAttributes attribs
;
1109 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1110 return; /* the window doesn't exist anymore */
1112 if (wwin
->flags
.miniaturized
)
1113 return; /* already miniaturized */
1115 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1116 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1118 if (owner
&& owner
->flags
.miniaturized
)
1122 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1124 /* if the window is in another workspace, simplify process */
1126 /* icon creation may take a while */
1127 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1128 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1129 GrabModeAsync
, None
, None
, CurrentTime
);
1132 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1133 if (!wwin
->flags
.icon_moved
)
1134 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1136 wwin
->icon
= icon_create_for_wwindow(wwin
);
1137 wwin
->icon
->mapped
= 1;
1139 /* extract the window screenshot every time, as the option can be enable anytime */
1140 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1141 RImage
*mini_preview
;
1147 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1148 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1153 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1154 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1156 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1157 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1159 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1161 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1162 XDestroyImage(pimg
);
1165 set_icon_minipreview(wwin
->icon
, mini_preview
);
1166 RReleaseImage(mini_preview
);
1171 if (wwin
->frame
->title
) {
1172 title
= wwin
->frame
->title
;
1174 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1177 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1183 wwin
->flags
.miniaturized
= 1;
1184 wwin
->flags
.mapped
= 0;
1186 /* unmap transients */
1187 unmapTransientsFor(wwin
);
1190 #ifdef USE_ANIMATIONS
1193 XUngrabPointer(dpy
, CurrentTime
);
1195 /* let all Expose events arrive so that we can repaint
1196 * something before the animation starts (and the server is grabbed) */
1199 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1200 wClientSetState(wwin
, IconicState
, None
);
1202 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1205 #ifdef USE_ANIMATIONS
1206 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1207 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1208 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1212 wwin
->flags
.skip_next_animation
= 0;
1214 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1215 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1216 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1217 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1219 AddToStackList(wwin
->icon
->core
);
1220 wLowerFrame(wwin
->icon
->core
);
1224 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1227 * It doesn't seem to be working and causes button event hangup
1228 * when deiconifying a transient window.
1229 setupIconGrabs(wwin->icon);
1231 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1232 && wPreferences
.focus_mode
== WKF_CLICK
) {
1237 if (!WFLAGP(tmp
, no_focusable
)
1238 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1239 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1243 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1244 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1245 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1247 #ifdef USE_ANIMATIONS
1248 if (!wwin
->screen_ptr
->flags
.startup
) {
1249 /* Catch up with events not processed while animation was running */
1250 Window clientwin
= wwin
->client_win
;
1252 ProcessPendingEvents();
1254 /* the window can disappear while ProcessPendingEvents() runs */
1255 if (!wWindowFor(clientwin
))
1261 /* maybe we want to do this regardless of net_handle_icon
1262 * it seems to me we might break behaviour this way.
1264 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1265 && !wwin
->flags
.net_handle_icon
)
1266 wIconSelect(wwin
->icon
);
1268 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1270 if (wPreferences
.auto_arrange_icons
)
1271 wArrangeIcons(wwin
->screen_ptr
, True
);
1274 void wDeiconifyWindow(WWindow
*wwin
)
1276 /* Let's avoid changing workspace while deiconifying */
1277 w_global
.ignore_workspace_change
= True
;
1279 /* we're hiding for show_desktop */
1280 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1281 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1284 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1286 if (!wwin
->flags
.miniaturized
) {
1287 w_global
.ignore_workspace_change
= False
;
1291 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1292 WWindow
*owner
= recursiveTransientFor(wwin
);
1294 if (owner
&& owner
->flags
.miniaturized
) {
1295 wDeiconifyWindow(owner
);
1296 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1297 wRaiseFrame(wwin
->frame
->core
);
1298 w_global
.ignore_workspace_change
= False
;
1303 wwin
->flags
.miniaturized
= 0;
1305 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1306 wwin
->flags
.mapped
= 1;
1308 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1309 /* maybe we want to do this regardless of net_handle_icon
1310 * it seems to me we might break behaviour this way.
1312 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1313 && wwin
->icon
!= NULL
) {
1314 if (wwin
->icon
->selected
)
1315 wIconSelect(wwin
->icon
);
1317 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1321 /* if the window is in another workspace, do it silently */
1322 if (!netwm_hidden
) {
1323 #ifdef USE_ANIMATIONS
1325 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1326 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1327 wwin
->frame_x
, wwin
->frame_y
,
1328 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1330 wwin
->flags
.skip_next_animation
= 0;
1332 if (!wwin
->flags
.shaded
)
1333 XMapWindow(dpy
, wwin
->client_win
);
1335 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1336 wRaiseFrame(wwin
->frame
->core
);
1337 if (!wwin
->flags
.shaded
)
1338 wClientSetState(wwin
, NormalState
, None
);
1340 mapTransientsFor(wwin
);
1343 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1344 && !wwin
->flags
.net_handle_icon
) {
1345 RemoveFromStackList(wwin
->icon
->core
);
1346 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1347 wIconDestroy(wwin
->icon
);
1351 if (!netwm_hidden
) {
1354 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1356 #ifdef USE_ANIMATIONS
1357 if (!wwin
->screen_ptr
->flags
.startup
) {
1358 /* Catch up with events not processed while animation was running */
1359 Window clientwin
= wwin
->client_win
;
1361 ProcessPendingEvents();
1363 /* the window can disappear while ProcessPendingEvents() runs */
1364 if (!wWindowFor(clientwin
)) {
1365 w_global
.ignore_workspace_change
= False
;
1372 if (wPreferences
.auto_arrange_icons
)
1373 wArrangeIcons(wwin
->screen_ptr
, True
);
1375 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1377 /* In case we were shaded and iconified, also unshade */
1379 wUnshadeWindow(wwin
);
1381 w_global
.ignore_workspace_change
= False
;
1384 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1386 if (wwin
->flags
.miniaturized
) {
1388 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1389 wwin
->icon
->mapped
= 0;
1391 wwin
->flags
.hidden
= 1;
1393 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1397 if (wwin
->flags
.inspector_open
)
1398 wHideInspectorForWindow(wwin
);
1400 wwin
->flags
.hidden
= 1;
1403 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1406 #ifdef USE_ANIMATIONS
1407 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1408 !wwin
->flags
.skip_next_animation
&& animate
) {
1409 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1410 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1411 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1414 /* Tell the compiler it is normal that those parameters are not used in this case */
1419 wwin
->flags
.skip_next_animation
= 0;
1421 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1424 void wHideAll(WScreen
*scr
)
1429 unsigned int wcount
= 0;
1435 menu
= scr
->switch_menu
;
1437 windows
= wmalloc(sizeof(WWindow
*));
1440 for (i
= 0; i
< menu
->entry_no
; i
++) {
1441 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1443 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1446 wwin
= scr
->focused_window
;
1449 windows
[wcount
] = wwin
;
1451 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1457 for (i
= 0; i
< wcount
; i
++) {
1459 if (wwin
->frame
->workspace
== scr
->current_workspace
1460 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1461 && !wwin
->flags
.internal_window
1462 && !WFLAGP(wwin
, no_miniaturizable
)
1464 wwin
->flags
.skip_next_animation
= 1;
1465 wIconifyWindow(wwin
);
1472 void wHideOtherApplications(WWindow
*awin
)
1479 wwin
= awin
->screen_ptr
->focused_window
;
1483 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1484 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1485 && !wwin
->flags
.internal_window
1486 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1488 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1489 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1490 wwin
->flags
.skip_next_animation
= 1;
1491 wIconifyWindow(wwin
);
1493 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1494 tapp
= wApplicationOf(wwin
->main_window
);
1496 tapp
->flags
.skip_next_animation
= 1;
1497 wHideApplication(tapp
);
1499 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1500 wwin
->flags
.skip_next_animation
= 1;
1501 wIconifyWindow(wwin
);
1509 wSetFocusTo(awin->screen_ptr, awin);
1513 void wHideApplication(WApplication
*wapp
)
1521 wwarning("trying to hide a non grouped window");
1524 if (!wapp
->main_window_desc
) {
1525 wwarning("group leader not found for window group");
1528 scr
= wapp
->main_window_desc
->screen_ptr
;
1530 wlist
= scr
->focused_window
;
1534 if (wlist
->main_window
== wapp
->main_window
)
1535 wapp
->last_focused
= wlist
;
1537 wapp
->last_focused
= NULL
;
1539 animate
= !wapp
->flags
.skip_next_animation
;
1542 if (wlist
->main_window
== wapp
->main_window
) {
1543 if (wlist
->flags
.focused
)
1545 if (wapp
->app_icon
) {
1546 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1547 wapp
->app_icon
->y_pos
, wlist
, animate
);
1551 wlist
= wlist
->prev
;
1554 wapp
->flags
.skip_next_animation
= 0;
1557 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1558 wlist
= scr
->focused_window
;
1560 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1561 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1563 wlist
= wlist
->prev
;
1565 wSetFocusTo(scr
, wlist
);
1567 wSetFocusTo(scr
, NULL
);
1571 wapp
->flags
.hidden
= 1;
1573 if (wPreferences
.auto_arrange_icons
)
1574 wArrangeIcons(scr
, True
);
1578 wAppIconPaint(wapp
->app_icon
);
1582 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1584 if (bringToCurrentWS
)
1585 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1587 wwin
->flags
.hidden
= 0;
1589 #ifdef USE_ANIMATIONS
1590 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1591 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1592 icon
->core
->width
, icon
->core
->height
,
1593 wwin
->frame_x
, wwin
->frame_y
,
1594 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1597 /* Tell the compiler it is normal that those parameters are not used in this case */
1603 wwin
->flags
.skip_next_animation
= 0;
1604 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1605 XMapWindow(dpy
, wwin
->client_win
);
1606 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1607 wClientSetState(wwin
, NormalState
, None
);
1608 wwin
->flags
.mapped
= 1;
1609 wRaiseFrame(wwin
->frame
->core
);
1611 if (wwin
->flags
.inspector_open
)
1612 wUnhideInspectorForWindow(wwin
);
1614 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1617 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1620 WWindow
*wlist
, *next
;
1621 WWindow
*focused
= NULL
;
1627 scr
= wapp
->main_window_desc
->screen_ptr
;
1628 wlist
= scr
->focused_window
;
1632 /* goto beginning of list */
1634 wlist
= wlist
->prev
;
1636 animate
= !wapp
->flags
.skip_next_animation
;
1641 if (wlist
->main_window
== wapp
->main_window
) {
1642 if (wlist
->flags
.focused
)
1644 else if (!focused
|| !focused
->flags
.focused
)
1647 if (wlist
->flags
.miniaturized
) {
1648 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1649 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1650 if (!wlist
->icon
->mapped
) {
1653 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1654 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1655 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1658 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1659 wlist
->icon
->mapped
= 1;
1661 wRaiseFrame(wlist
->icon
->core
);
1663 if (bringToCurrentWS
)
1664 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1665 wlist
->flags
.hidden
= 0;
1666 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1667 wDeiconifyWindow(wlist
);
1668 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1669 } else if (wlist
->flags
.shaded
) {
1670 if (bringToCurrentWS
)
1671 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1672 wlist
->flags
.hidden
= 0;
1673 wRaiseFrame(wlist
->frame
->core
);
1674 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1675 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1677 wUnshadeWindow(wlist
);
1679 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1680 } else if (wlist
->flags
.hidden
) {
1681 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1682 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1685 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1686 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1688 wRaiseFrame(wlist
->frame
->core
);
1694 wapp
->flags
.skip_next_animation
= 0;
1695 wapp
->flags
.hidden
= 0;
1697 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1698 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1699 wSetFocusTo(scr
, wapp
->last_focused
);
1700 } else if (focused
) {
1701 wSetFocusTo(scr
, focused
);
1703 wapp
->last_focused
= NULL
;
1704 if (wPreferences
.auto_arrange_icons
)
1705 wArrangeIcons(scr
, True
);
1708 wAppIconPaint(wapp
->app_icon
);
1712 void wShowAllWindows(WScreen
*scr
)
1714 WWindow
*wwin
, *old_foc
;
1717 old_foc
= wwin
= scr
->focused_window
;
1719 if (!wwin
->flags
.internal_window
&&
1720 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1721 if (wwin
->flags
.miniaturized
) {
1722 wwin
->flags
.skip_next_animation
= 1;
1723 wDeiconifyWindow(wwin
);
1724 } else if (wwin
->flags
.hidden
) {
1725 wapp
= wApplicationOf(wwin
->main_window
);
1727 wUnhideApplication(wapp
, False
, False
);
1729 wwin
->flags
.skip_next_animation
= 1;
1730 wDeiconifyWindow(wwin
);
1736 wSetFocusTo(scr
, old_foc
);
1737 /*wRaiseFrame(old_foc->frame->core); */
1740 void wRefreshDesktop(WScreen
*scr
)
1743 XSetWindowAttributes attr
;
1745 attr
.backing_store
= NotUseful
;
1746 attr
.save_under
= False
;
1747 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1748 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1749 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1750 XMapRaised(dpy
, win
);
1751 XDestroyWindow(dpy
, win
);
1755 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1761 const int heads
= wXineramaHeads(scr
);
1764 int pf
; /* primary axis */
1765 int sf
; /* secondary axis */
1769 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1775 int isize
= wPreferences
.icon_size
;
1777 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1779 for (head
= 0; head
< heads
; ++head
) {
1780 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1784 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1786 if (scr
->dock
->on_right_side
)
1792 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1794 vars
[head
].pi
= vars
[head
].si
= 0;
1795 vars
[head
].sx1
= rect
.pos
.x
;
1796 vars
[head
].sy1
= rect
.pos
.y
;
1797 vars
[head
].sw
= rect
.size
.width
;
1798 vars
[head
].sh
= rect
.size
.height
;
1799 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1800 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1801 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1802 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1803 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1804 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1806 /* icon yard boundaries */
1807 if (wPreferences
.icon_yard
& IY_VERT
) {
1808 vars
[head
].pf
= vars
[head
].fullH
;
1809 vars
[head
].sf
= vars
[head
].fullW
;
1811 vars
[head
].pf
= vars
[head
].fullW
;
1812 vars
[head
].sf
= vars
[head
].fullH
;
1814 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1815 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1818 vars
[head
].xo
= vars
[head
].sx1
;
1821 if (wPreferences
.icon_yard
& IY_TOP
) {
1822 vars
[head
].yo
= vars
[head
].sy1
;
1825 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1830 #define X ((wPreferences.icon_yard & IY_VERT) \
1831 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1832 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1834 #define Y ((wPreferences.icon_yard & IY_VERT) \
1835 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1836 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1838 /* arrange application icons */
1839 aicon
= scr
->app_icon_list
;
1840 /* reverse them to avoid unnecessarily sliding of icons */
1841 while (aicon
&& aicon
->next
)
1842 aicon
= aicon
->next
;
1845 if (!aicon
->docked
) {
1846 /* CHECK: can icon be NULL here ? */
1847 /* The intention here is to place the AppIcon on the head that
1848 * contains most of the applications _main_ window. */
1849 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1851 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1852 #ifdef USE_ANIMATIONS
1853 if (!wPreferences
.no_animations
)
1854 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1855 #endif /* USE_ANIMATIONS */
1857 wAppIconMove(aicon
, X
, Y
);
1859 if (vars
[head
].pi
>= vars
[head
].pf
) {
1864 aicon
= aicon
->prev
;
1867 /* arrange miniwindows */
1868 wwin
= scr
->focused_window
;
1869 /* reverse them to avoid unnecessarily shuffling */
1870 while (wwin
&& wwin
->prev
)
1874 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1875 (wwin
->frame
->workspace
== scr
->current_workspace
||
1876 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1878 head
= wGetHeadForWindow(wwin
);
1880 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1881 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1882 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1888 if (vars
[head
].pi
>= vars
[head
].pf
) {
1895 wwin
->flags
.icon_moved
= 0;
1896 /* we reversed the order, so we use next */
1903 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1905 WScreen
*scr
= wwin
->screen_ptr
;
1908 wwin
->flags
.selected
= 1;
1909 if (wwin
->frame
->selected_border_pixel
)
1910 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1912 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1914 if (!HAS_BORDER(wwin
))
1915 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1917 if (!scr
->selected_windows
)
1918 scr
->selected_windows
= WMCreateArray(4);
1919 WMAddToArray(scr
->selected_windows
, wwin
);
1921 wwin
->flags
.selected
= 0;
1922 if (wwin
->flags
.focused
) {
1923 if (wwin
->frame
->focused_border_pixel
)
1924 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1926 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1928 if (wwin
->frame
->border_pixel
)
1929 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1931 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1934 if (!HAS_BORDER(wwin
))
1935 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1937 if (scr
->selected_windows
)
1938 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1942 void wMakeWindowVisible(WWindow
*wwin
)
1944 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1945 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1947 if (wwin
->flags
.shaded
)
1948 wUnshadeWindow(wwin
);
1950 if (wwin
->flags
.hidden
) {
1953 app
= wApplicationOf(wwin
->main_window
);
1955 /* trick to get focus to this window */
1956 app
->last_focused
= wwin
;
1957 wUnhideApplication(app
, False
, False
);
1960 if (wwin
->flags
.miniaturized
) {
1961 wDeiconifyWindow(wwin
);
1963 if (!WFLAGP(wwin
, no_focusable
))
1964 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1965 wRaiseFrame(wwin
->frame
->core
);
1970 * Do the animation while shading (called with what = SHADE)
1971 * or unshading (what = UNSHADE).
1973 #ifdef USE_ANIMATIONS
1974 static void shade_animate(WWindow
*wwin
, Bool what
)
1977 time_t time0
= time(NULL
);
1979 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1984 if (!wwin
->screen_ptr
->flags
.startup
) {
1985 /* do the shading animation */
1986 h
= wwin
->frame
->core
->height
;
1987 s
= h
/ SHADE_STEPS
;
1990 w
= wwin
->frame
->core
->width
;
1991 y
= wwin
->frame
->top_width
;
1992 while (h
> wwin
->frame
->top_width
+ 1) {
1993 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1994 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1997 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2000 if (SHADE_DELAY
> 0)
2001 wusleep(SHADE_DELAY
* 1000L);
2007 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2012 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2013 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2014 s
= abs(y
) / SHADE_STEPS
;
2017 w
= wwin
->frame
->core
->width
;
2018 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2020 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2021 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2022 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2024 if (SHADE_DELAY
> 0)
2025 wusleep(SHADE_DELAY
* 2000L / 3);
2031 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2035 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);