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
, WMFullscreenLevel
);
732 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
733 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
734 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
735 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
737 head
= wGetHeadForWindow(wwin
);
738 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
739 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
741 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
742 wSetFocusTo(wwin
->screen_ptr
, wwin
);
744 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
747 void wUnfullscreenWindow(WWindow
*wwin
)
749 if (!wwin
->flags
.fullscreen
)
752 wwin
->flags
.fullscreen
= False
;
754 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
755 if (WFLAGP(wwin
, sunken
)) {
756 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
757 } else if (WFLAGP(wwin
, floating
)) {
758 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
760 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
764 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
765 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
767 wWindowConfigureBorders(wwin
);
769 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
770 wFrameWindowPaint(wwin->frame);
773 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
775 if (wwin
->screen_ptr
->bfs_focused_window
) {
776 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
777 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
781 #ifdef USE_ANIMATIONS
782 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
784 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
785 float cx
, cy
, cw
, ch
;
786 float xstep
, ystep
, wstep
, hstep
;
789 float angle
, final_angle
, delta
;
791 xstep
= (float)(fx
- x
) / steps
;
792 ystep
= (float)(fy
- y
) / steps
;
793 wstep
= (float)(fw
- w
) / steps
;
794 hstep
= (float)(fh
- h
) / steps
;
801 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
802 delta
= (float)(final_angle
/ FRAMES
);
803 for (angle
= 0;; angle
+= delta
) {
804 if (angle
> final_angle
)
807 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
808 dch
= (ch
/ 2) * cosf(angle
);
809 midy
= cy
+ (ch
/ 2);
811 points
[0].x
= cx
+ dx
;
812 points
[0].y
= midy
- dch
;
813 points
[1].x
= cx
+ cw
- dx
;
814 points
[1].y
= points
[0].y
;
815 points
[2].x
= cx
+ cw
+ dx
;
816 points
[2].y
= midy
+ dch
;
817 points
[3].x
= cx
- dx
;
818 points
[3].y
= points
[2].y
;
819 points
[4].x
= points
[0].x
;
820 points
[4].y
= points
[0].y
;
823 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
825 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
827 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
833 if (angle
>= final_angle
)
843 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
845 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
846 float cx
, cy
, cw
, ch
;
847 float xstep
, ystep
, wstep
, hstep
;
849 float angle
, final_angle
, a
, d
, delta
;
856 xstep
= (float)(fx
- x
) / steps
;
857 ystep
= (float)(fy
- y
) / steps
;
858 wstep
= (float)(fw
- w
) / steps
;
859 hstep
= (float)(fh
- h
) / steps
;
866 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
867 delta
= (float)(final_angle
/ FRAMES
);
868 for (angle
= 0;; angle
+= delta
) {
869 if (angle
> final_angle
)
873 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
875 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
876 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
877 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
878 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
879 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
880 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
881 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
882 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
883 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
884 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
886 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
888 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
890 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
896 if (angle
>= final_angle
)
905 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
907 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
908 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
909 float xstep
, ystep
, wstep
, hstep
;
912 xstep
= (float)(fx
- x
) / steps
;
913 ystep
= (float)(fy
- y
) / steps
;
914 wstep
= (float)(fw
- w
) / steps
;
915 hstep
= (float)(fh
- h
) / steps
;
917 for (j
= 0; j
< FRAMES
; j
++) {
924 for (i
= 0; i
< steps
; i
++) {
925 for (j
= 0; j
< FRAMES
; j
++) {
926 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
927 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
930 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
932 for (j
= 0; j
< FRAMES
; j
++) {
933 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
934 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
935 if (j
< FRAMES
- 1) {
949 for (j
= 0; j
< FRAMES
; j
++)
950 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
952 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
954 for (j
= 0; j
< FRAMES
; j
++)
955 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
962 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
964 int style
= wPreferences
.iconification_style
; /* Catch the value */
967 if (style
== WIS_NONE
)
970 if (style
== WIS_RANDOM
)
975 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
977 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
980 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
982 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
986 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
988 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
992 #endif /* USE_ANIMATIONS */
994 static void flushExpose(void)
998 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
999 WMHandleEvent(&tmpev
);
1003 static void unmapTransientsFor(WWindow
*wwin
)
1007 tmp
= wwin
->screen_ptr
->focused_window
;
1009 /* unmap the transients for this transient */
1010 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1011 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1012 unmapTransientsFor(tmp
);
1013 tmp
->flags
.miniaturized
= 1;
1014 if (!tmp
->flags
.shaded
)
1017 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1019 if (!tmp->flags.shaded)
1021 wClientSetState(tmp
, IconicState
, None
);
1023 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1029 static void mapTransientsFor(WWindow
*wwin
)
1033 tmp
= wwin
->screen_ptr
->focused_window
;
1035 /* recursively map the transients for this transient */
1036 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1037 && tmp
->icon
== NULL
) {
1038 mapTransientsFor(tmp
);
1039 tmp
->flags
.miniaturized
= 0;
1040 if (!tmp
->flags
.shaded
)
1043 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1044 tmp
->flags
.semi_focused
= 0;
1046 if (!tmp->flags.shaded)
1048 wClientSetState(tmp
, NormalState
, None
);
1050 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1056 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1063 /* hackish way to detect transient_for cycle */
1064 i
= wwin
->screen_ptr
->window_count
+ 1;
1066 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1067 wwin
= wWindowFor(wwin
->transient_for
);
1070 if (i
== 0 && wwin
) {
1071 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1072 wwin
->frame
->title
);
1079 #ifdef USE_ANIMATIONS
1080 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1082 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1083 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1086 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1089 *iw
= wwin
->icon
->core
->width
;
1090 *ih
= wwin
->icon
->core
->height
;
1092 if (wwin
->flags
.net_handle_icon
) {
1100 *iw
= wwin
->screen_ptr
->scr_width
;
1101 *ih
= wwin
->screen_ptr
->scr_height
;
1106 #endif /* USE_ANIMATIONS */
1108 void wIconifyWindow(WWindow
*wwin
)
1110 XWindowAttributes attribs
;
1113 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1114 return; /* the window doesn't exist anymore */
1116 if (wwin
->flags
.miniaturized
)
1117 return; /* already miniaturized */
1119 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1120 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1122 if (owner
&& owner
->flags
.miniaturized
)
1126 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1128 /* if the window is in another workspace, simplify process */
1130 /* icon creation may take a while */
1131 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1132 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1133 GrabModeAsync
, None
, None
, CurrentTime
);
1136 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1137 if (!wwin
->flags
.icon_moved
)
1138 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1140 wwin
->icon
= icon_create_for_wwindow(wwin
);
1141 wwin
->icon
->mapped
= 1;
1143 /* extract the window screenshot every time, as the option can be enable anytime */
1144 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1145 RImage
*mini_preview
;
1151 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1152 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1157 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1158 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1160 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1161 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1163 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1165 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1166 XDestroyImage(pimg
);
1169 set_icon_minipreview(wwin
->icon
, mini_preview
);
1170 RReleaseImage(mini_preview
);
1175 if (wwin
->frame
->title
) {
1176 title
= wwin
->frame
->title
;
1178 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1181 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1187 wwin
->flags
.miniaturized
= 1;
1188 wwin
->flags
.mapped
= 0;
1190 /* unmap transients */
1191 unmapTransientsFor(wwin
);
1194 #ifdef USE_ANIMATIONS
1197 XUngrabPointer(dpy
, CurrentTime
);
1199 /* let all Expose events arrive so that we can repaint
1200 * something before the animation starts (and the server is grabbed) */
1203 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1204 wClientSetState(wwin
, IconicState
, None
);
1206 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1209 #ifdef USE_ANIMATIONS
1210 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1211 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1212 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1216 wwin
->flags
.skip_next_animation
= 0;
1218 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1219 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1220 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1221 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1223 AddToStackList(wwin
->icon
->core
);
1224 wLowerFrame(wwin
->icon
->core
);
1228 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1231 * It doesn't seem to be working and causes button event hangup
1232 * when deiconifying a transient window.
1233 setupIconGrabs(wwin->icon);
1235 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1236 && wPreferences
.focus_mode
== WKF_CLICK
) {
1241 if (!WFLAGP(tmp
, no_focusable
)
1242 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1243 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1247 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1248 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1249 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1251 #ifdef USE_ANIMATIONS
1252 if (!wwin
->screen_ptr
->flags
.startup
) {
1253 /* Catch up with events not processed while animation was running */
1254 Window clientwin
= wwin
->client_win
;
1256 ProcessPendingEvents();
1258 /* the window can disappear while ProcessPendingEvents() runs */
1259 if (!wWindowFor(clientwin
))
1265 /* maybe we want to do this regardless of net_handle_icon
1266 * it seems to me we might break behaviour this way.
1268 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1269 && !wwin
->flags
.net_handle_icon
)
1270 wIconSelect(wwin
->icon
);
1272 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1274 if (wPreferences
.auto_arrange_icons
)
1275 wArrangeIcons(wwin
->screen_ptr
, True
);
1278 void wDeiconifyWindow(WWindow
*wwin
)
1280 /* Let's avoid changing workspace while deiconifying */
1281 w_global
.ignore_workspace_change
= True
;
1283 /* we're hiding for show_desktop */
1284 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1285 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1288 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1290 if (!wwin
->flags
.miniaturized
) {
1291 w_global
.ignore_workspace_change
= False
;
1295 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1296 WWindow
*owner
= recursiveTransientFor(wwin
);
1298 if (owner
&& owner
->flags
.miniaturized
) {
1299 wDeiconifyWindow(owner
);
1300 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1301 wRaiseFrame(wwin
->frame
->core
);
1302 w_global
.ignore_workspace_change
= False
;
1307 wwin
->flags
.miniaturized
= 0;
1309 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1310 wwin
->flags
.mapped
= 1;
1312 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1313 /* maybe we want to do this regardless of net_handle_icon
1314 * it seems to me we might break behaviour this way.
1316 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1317 && wwin
->icon
!= NULL
) {
1318 if (wwin
->icon
->selected
)
1319 wIconSelect(wwin
->icon
);
1321 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1325 /* if the window is in another workspace, do it silently */
1326 if (!netwm_hidden
) {
1327 #ifdef USE_ANIMATIONS
1329 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1330 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1331 wwin
->frame_x
, wwin
->frame_y
,
1332 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1334 wwin
->flags
.skip_next_animation
= 0;
1336 if (!wwin
->flags
.shaded
)
1337 XMapWindow(dpy
, wwin
->client_win
);
1339 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1340 wRaiseFrame(wwin
->frame
->core
);
1341 if (!wwin
->flags
.shaded
)
1342 wClientSetState(wwin
, NormalState
, None
);
1344 mapTransientsFor(wwin
);
1347 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1348 && !wwin
->flags
.net_handle_icon
) {
1349 RemoveFromStackList(wwin
->icon
->core
);
1350 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1351 wIconDestroy(wwin
->icon
);
1355 if (!netwm_hidden
) {
1358 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1360 #ifdef USE_ANIMATIONS
1361 if (!wwin
->screen_ptr
->flags
.startup
) {
1362 /* Catch up with events not processed while animation was running */
1363 Window clientwin
= wwin
->client_win
;
1365 ProcessPendingEvents();
1367 /* the window can disappear while ProcessPendingEvents() runs */
1368 if (!wWindowFor(clientwin
)) {
1369 w_global
.ignore_workspace_change
= False
;
1376 if (wPreferences
.auto_arrange_icons
)
1377 wArrangeIcons(wwin
->screen_ptr
, True
);
1379 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1381 /* In case we were shaded and iconified, also unshade */
1383 wUnshadeWindow(wwin
);
1385 w_global
.ignore_workspace_change
= False
;
1388 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1390 if (wwin
->flags
.miniaturized
) {
1392 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1393 wwin
->icon
->mapped
= 0;
1395 wwin
->flags
.hidden
= 1;
1397 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1401 if (wwin
->flags
.inspector_open
)
1402 wHideInspectorForWindow(wwin
);
1404 wwin
->flags
.hidden
= 1;
1407 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1410 #ifdef USE_ANIMATIONS
1411 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1412 !wwin
->flags
.skip_next_animation
&& animate
) {
1413 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1414 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1415 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1418 /* Tell the compiler it is normal that those parameters are not used in this case */
1423 wwin
->flags
.skip_next_animation
= 0;
1425 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1428 void wHideAll(WScreen
*scr
)
1433 unsigned int wcount
= 0;
1439 menu
= scr
->switch_menu
;
1441 windows
= wmalloc(sizeof(WWindow
*));
1444 for (i
= 0; i
< menu
->entry_no
; i
++) {
1445 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1447 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1450 wwin
= scr
->focused_window
;
1453 windows
[wcount
] = wwin
;
1455 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1461 for (i
= 0; i
< wcount
; i
++) {
1463 if (wwin
->frame
->workspace
== scr
->current_workspace
1464 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1465 && !wwin
->flags
.internal_window
1466 && !WFLAGP(wwin
, no_miniaturizable
)
1468 wwin
->flags
.skip_next_animation
= 1;
1469 wIconifyWindow(wwin
);
1476 void wHideOtherApplications(WWindow
*awin
)
1483 wwin
= awin
->screen_ptr
->focused_window
;
1487 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1488 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1489 && !wwin
->flags
.internal_window
1490 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1492 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1493 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1494 wwin
->flags
.skip_next_animation
= 1;
1495 wIconifyWindow(wwin
);
1497 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1498 tapp
= wApplicationOf(wwin
->main_window
);
1500 tapp
->flags
.skip_next_animation
= 1;
1501 wHideApplication(tapp
);
1503 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1504 wwin
->flags
.skip_next_animation
= 1;
1505 wIconifyWindow(wwin
);
1513 wSetFocusTo(awin->screen_ptr, awin);
1517 void wHideApplication(WApplication
*wapp
)
1525 wwarning("trying to hide a non grouped window");
1528 if (!wapp
->main_window_desc
) {
1529 wwarning("group leader not found for window group");
1532 scr
= wapp
->main_window_desc
->screen_ptr
;
1534 wlist
= scr
->focused_window
;
1538 if (wlist
->main_window
== wapp
->main_window
)
1539 wapp
->last_focused
= wlist
;
1541 wapp
->last_focused
= NULL
;
1543 animate
= !wapp
->flags
.skip_next_animation
;
1546 if (wlist
->main_window
== wapp
->main_window
) {
1547 if (wlist
->flags
.focused
)
1549 if (wapp
->app_icon
) {
1550 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1551 wapp
->app_icon
->y_pos
, wlist
, animate
);
1555 wlist
= wlist
->prev
;
1558 wapp
->flags
.skip_next_animation
= 0;
1561 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1562 wlist
= scr
->focused_window
;
1564 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1565 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1567 wlist
= wlist
->prev
;
1569 wSetFocusTo(scr
, wlist
);
1571 wSetFocusTo(scr
, NULL
);
1575 wapp
->flags
.hidden
= 1;
1577 if (wPreferences
.auto_arrange_icons
)
1578 wArrangeIcons(scr
, True
);
1582 wAppIconPaint(wapp
->app_icon
);
1586 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1588 if (bringToCurrentWS
)
1589 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1591 wwin
->flags
.hidden
= 0;
1593 #ifdef USE_ANIMATIONS
1594 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1595 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1596 icon
->core
->width
, icon
->core
->height
,
1597 wwin
->frame_x
, wwin
->frame_y
,
1598 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1601 /* Tell the compiler it is normal that those parameters are not used in this case */
1607 wwin
->flags
.skip_next_animation
= 0;
1608 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1609 XMapWindow(dpy
, wwin
->client_win
);
1610 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1611 wClientSetState(wwin
, NormalState
, None
);
1612 wwin
->flags
.mapped
= 1;
1613 wRaiseFrame(wwin
->frame
->core
);
1615 if (wwin
->flags
.inspector_open
)
1616 wUnhideInspectorForWindow(wwin
);
1618 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1621 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1624 WWindow
*wlist
, *next
;
1625 WWindow
*focused
= NULL
;
1631 scr
= wapp
->main_window_desc
->screen_ptr
;
1632 wlist
= scr
->focused_window
;
1636 /* goto beginning of list */
1638 wlist
= wlist
->prev
;
1640 animate
= !wapp
->flags
.skip_next_animation
;
1645 if (wlist
->main_window
== wapp
->main_window
) {
1646 if (wlist
->flags
.focused
)
1648 else if (!focused
|| !focused
->flags
.focused
)
1651 if (wlist
->flags
.miniaturized
) {
1652 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1653 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1654 if (!wlist
->icon
->mapped
) {
1657 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1658 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1659 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1662 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1663 wlist
->icon
->mapped
= 1;
1665 wRaiseFrame(wlist
->icon
->core
);
1667 if (bringToCurrentWS
)
1668 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1669 wlist
->flags
.hidden
= 0;
1670 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1671 wDeiconifyWindow(wlist
);
1672 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1673 } else if (wlist
->flags
.shaded
) {
1674 if (bringToCurrentWS
)
1675 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1676 wlist
->flags
.hidden
= 0;
1677 wRaiseFrame(wlist
->frame
->core
);
1678 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1679 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1681 wUnshadeWindow(wlist
);
1683 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1684 } else if (wlist
->flags
.hidden
) {
1685 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1686 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1689 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1690 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1692 wRaiseFrame(wlist
->frame
->core
);
1698 wapp
->flags
.skip_next_animation
= 0;
1699 wapp
->flags
.hidden
= 0;
1701 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1702 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1703 wSetFocusTo(scr
, wapp
->last_focused
);
1704 } else if (focused
) {
1705 wSetFocusTo(scr
, focused
);
1707 wapp
->last_focused
= NULL
;
1708 if (wPreferences
.auto_arrange_icons
)
1709 wArrangeIcons(scr
, True
);
1712 wAppIconPaint(wapp
->app_icon
);
1716 void wShowAllWindows(WScreen
*scr
)
1718 WWindow
*wwin
, *old_foc
;
1721 old_foc
= wwin
= scr
->focused_window
;
1723 if (!wwin
->flags
.internal_window
&&
1724 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1725 if (wwin
->flags
.miniaturized
) {
1726 wwin
->flags
.skip_next_animation
= 1;
1727 wDeiconifyWindow(wwin
);
1728 } else if (wwin
->flags
.hidden
) {
1729 wapp
= wApplicationOf(wwin
->main_window
);
1731 wUnhideApplication(wapp
, False
, False
);
1733 wwin
->flags
.skip_next_animation
= 1;
1734 wDeiconifyWindow(wwin
);
1740 wSetFocusTo(scr
, old_foc
);
1741 /*wRaiseFrame(old_foc->frame->core); */
1744 void wRefreshDesktop(WScreen
*scr
)
1747 XSetWindowAttributes attr
;
1749 attr
.backing_store
= NotUseful
;
1750 attr
.save_under
= False
;
1751 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1752 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1753 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1754 XMapRaised(dpy
, win
);
1755 XDestroyWindow(dpy
, win
);
1759 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1765 const int heads
= wXineramaHeads(scr
);
1768 int pf
; /* primary axis */
1769 int sf
; /* secondary axis */
1773 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1779 int isize
= wPreferences
.icon_size
;
1781 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1783 for (head
= 0; head
< heads
; ++head
) {
1784 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1788 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1790 if (scr
->dock
->on_right_side
)
1796 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1798 vars
[head
].pi
= vars
[head
].si
= 0;
1799 vars
[head
].sx1
= rect
.pos
.x
;
1800 vars
[head
].sy1
= rect
.pos
.y
;
1801 vars
[head
].sw
= rect
.size
.width
;
1802 vars
[head
].sh
= rect
.size
.height
;
1803 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1804 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1805 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1806 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1807 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1808 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1810 /* icon yard boundaries */
1811 if (wPreferences
.icon_yard
& IY_VERT
) {
1812 vars
[head
].pf
= vars
[head
].fullH
;
1813 vars
[head
].sf
= vars
[head
].fullW
;
1815 vars
[head
].pf
= vars
[head
].fullW
;
1816 vars
[head
].sf
= vars
[head
].fullH
;
1818 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1819 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1822 vars
[head
].xo
= vars
[head
].sx1
;
1825 if (wPreferences
.icon_yard
& IY_TOP
) {
1826 vars
[head
].yo
= vars
[head
].sy1
;
1829 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1834 #define X ((wPreferences.icon_yard & IY_VERT) \
1835 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1836 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1838 #define Y ((wPreferences.icon_yard & IY_VERT) \
1839 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1840 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1842 /* arrange application icons */
1843 aicon
= scr
->app_icon_list
;
1844 /* reverse them to avoid unnecessarily sliding of icons */
1845 while (aicon
&& aicon
->next
)
1846 aicon
= aicon
->next
;
1849 if (!aicon
->docked
) {
1850 /* CHECK: can icon be NULL here ? */
1851 /* The intention here is to place the AppIcon on the head that
1852 * contains most of the applications _main_ window. */
1853 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1855 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1856 #ifdef USE_ANIMATIONS
1857 if (!wPreferences
.no_animations
)
1858 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1859 #endif /* USE_ANIMATIONS */
1861 wAppIconMove(aicon
, X
, Y
);
1863 if (vars
[head
].pi
>= vars
[head
].pf
) {
1868 aicon
= aicon
->prev
;
1871 /* arrange miniwindows */
1872 wwin
= scr
->focused_window
;
1873 /* reverse them to avoid unnecessarily shuffling */
1874 while (wwin
&& wwin
->prev
)
1878 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1879 (wwin
->frame
->workspace
== scr
->current_workspace
||
1880 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1882 head
= wGetHeadForWindow(wwin
);
1884 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1885 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1886 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1892 if (vars
[head
].pi
>= vars
[head
].pf
) {
1899 wwin
->flags
.icon_moved
= 0;
1900 /* we reversed the order, so we use next */
1907 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1909 WScreen
*scr
= wwin
->screen_ptr
;
1912 wwin
->flags
.selected
= 1;
1913 if (wwin
->frame
->selected_border_pixel
)
1914 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1916 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1918 if (!HAS_BORDER(wwin
))
1919 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1921 if (!scr
->selected_windows
)
1922 scr
->selected_windows
= WMCreateArray(4);
1923 WMAddToArray(scr
->selected_windows
, wwin
);
1925 wwin
->flags
.selected
= 0;
1926 if (wwin
->flags
.focused
) {
1927 if (wwin
->frame
->focused_border_pixel
)
1928 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1930 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1932 if (wwin
->frame
->border_pixel
)
1933 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1935 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1938 if (!HAS_BORDER(wwin
))
1939 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1941 if (scr
->selected_windows
)
1942 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1946 void wMakeWindowVisible(WWindow
*wwin
)
1948 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1949 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1951 if (wwin
->flags
.shaded
)
1952 wUnshadeWindow(wwin
);
1954 if (wwin
->flags
.hidden
) {
1957 app
= wApplicationOf(wwin
->main_window
);
1959 /* trick to get focus to this window */
1960 app
->last_focused
= wwin
;
1961 wUnhideApplication(app
, False
, False
);
1964 if (wwin
->flags
.miniaturized
) {
1965 wDeiconifyWindow(wwin
);
1967 if (!WFLAGP(wwin
, no_focusable
))
1968 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1969 wRaiseFrame(wwin
->frame
->core
);
1974 * Do the animation while shading (called with what = SHADE)
1975 * or unshading (what = UNSHADE).
1977 #ifdef USE_ANIMATIONS
1978 static void shade_animate(WWindow
*wwin
, Bool what
)
1981 time_t time0
= time(NULL
);
1983 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1988 if (!wwin
->screen_ptr
->flags
.startup
) {
1989 /* do the shading animation */
1990 h
= wwin
->frame
->core
->height
;
1991 s
= h
/ SHADE_STEPS
;
1994 w
= wwin
->frame
->core
->width
;
1995 y
= wwin
->frame
->top_width
;
1996 while (h
> wwin
->frame
->top_width
+ 1) {
1997 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1998 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2001 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2004 if (SHADE_DELAY
> 0)
2005 wusleep(SHADE_DELAY
* 1000L);
2011 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2016 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2017 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2018 s
= abs(y
) / SHADE_STEPS
;
2021 w
= wwin
->frame
->core
->width
;
2022 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2024 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2025 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2026 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2028 if (SHADE_DELAY
> 0)
2029 wusleep(SHADE_DELAY
* 2000L / 3);
2035 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2039 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);