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 if (wwin
->flags
.mapped
)
229 wAppMenuMap(napp
->menu
, wwin
);
231 if (napp
&& wPreferences
.highlight_active_app
)
232 wApplicationActivate(napp
);
238 void wShadeWindow(WWindow
*wwin
)
241 if (wwin
->flags
.shaded
)
244 XLowerWindow(dpy
, wwin
->client_win
);
245 shade_animate(wwin
, SHADE
);
247 wwin
->flags
.skip_next_animation
= 0;
248 wwin
->flags
.shaded
= 1;
249 wwin
->flags
.mapped
= 0;
250 /* prevent window withdrawal when getting UnmapNotify */
251 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
252 XUnmapWindow(dpy
, wwin
->client_win
);
253 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
255 /* for the client it's just like iconification */
256 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
258 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
259 wWindowSynthConfigureNotify(wwin
);
262 wClientSetState(wwin, IconicState, None);
265 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
267 #ifdef USE_ANIMATIONS
268 if (!wwin
->screen_ptr
->flags
.startup
) {
269 /* Catch up with events not processed while animation was running */
270 ProcessPendingEvents();
275 void wUnshadeWindow(WWindow
*wwin
)
278 if (!wwin
->flags
.shaded
)
281 wwin
->flags
.shaded
= 0;
282 wwin
->flags
.mapped
= 1;
283 XMapWindow(dpy
, wwin
->client_win
);
285 shade_animate(wwin
, UNSHADE
);
287 wwin
->flags
.skip_next_animation
= 0;
288 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
289 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
291 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
292 wWindowSynthConfigureNotify(wwin
);
294 /* if the window is focused, set the focus again as it was disabled during
296 if (wwin
->flags
.focused
)
297 wSetFocusTo(wwin
->screen_ptr
, wwin
);
299 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
302 /* Set the old coordinates using the current values */
303 static void save_old_geometry(WWindow
*wwin
, int directions
)
305 /* never been saved? */
306 if (!wwin
->old_geometry
.width
)
307 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
308 if (!wwin
->old_geometry
.height
)
309 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
311 if (directions
& SAVE_GEOMETRY_X
)
312 wwin
->old_geometry
.x
= wwin
->frame_x
;
313 if (directions
& SAVE_GEOMETRY_Y
)
314 wwin
->old_geometry
.y
= wwin
->frame_y
;
315 if (directions
& SAVE_GEOMETRY_WIDTH
)
316 wwin
->old_geometry
.width
= wwin
->client
.width
;
317 if (directions
& SAVE_GEOMETRY_HEIGHT
)
318 wwin
->old_geometry
.height
= wwin
->client
.height
;
321 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
323 WMRect old_geom_rect
;
327 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
328 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
329 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
330 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
331 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
332 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
333 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
336 /* Remember geometry for unmaximizing */
337 void update_saved_geometry(WWindow
*wwin
)
339 /* NOT if we aren't already maximized
340 * we'll save geometry when maximizing */
341 if (!wwin
->flags
.maximized
)
344 /* NOT if we are fully maximized */
345 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
346 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
347 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
350 /* save the co-ordinate in the axis in which we AREN'T maximized */
351 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
352 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
353 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
354 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
357 void wMaximizeWindow(WWindow
*wwin
, int directions
)
359 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
364 unsigned int maximus_width
= 0;
365 unsigned int maximus_height
= 0;
366 WArea usableArea
, totalArea
;
369 WScreen
*scr
= wwin
->screen_ptr
;
371 if (!IS_RESIZABLE(wwin
))
374 if (!HAS_BORDER(wwin
))
377 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
378 wwin
->client_flags
.no_movable
= 1;
380 /* the size to adjust the geometry */
381 adj_size
= scr
->frame_border_width
* 2 * has_border
;
383 /* save old coordinates before we change the current values */
384 if (!wwin
->flags
.maximized
)
385 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
387 totalArea
.x2
= scr
->scr_width
;
388 totalArea
.y2
= scr
->scr_height
;
391 usableArea
= totalArea
;
393 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
394 WScreen
*scr
= wwin
->screen_ptr
;
397 if (directions
& MAX_KEYBOARD
)
398 head
= wGetHeadForWindow(wwin
);
400 head
= wGetHeadForPointerLocation(scr
);
402 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
406 /* Only save directions, not kbd or xinerama hints */
407 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
409 if (WFLAGP(wwin
, full_maximize
))
410 usableArea
= totalArea
;
411 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
412 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
414 if (wwin
->flags
.shaded
) {
415 wwin
->flags
.skip_next_animation
= 1;
416 wUnshadeWindow(wwin
);
419 if (directions
& MAX_MAXIMUS
) {
420 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
421 new_width
= maximus_width
- adj_size
;
422 new_height
= maximus_height
- adj_size
;
425 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
426 new_height
+= wwin
->frame
->bottom_width
- 1;
427 new_y
-= wwin
->frame
->top_width
;
430 wwin
->maximus_x
= new_x
;
431 wwin
->maximus_y
= new_y
;
432 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
434 /* set default values if no option set then */
435 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
436 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
437 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
439 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
440 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
441 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
444 /* left|right position */
445 if (directions
& MAX_LEFTHALF
) {
446 new_width
= half_scr_width
- adj_size
;
447 new_x
= usableArea
.x1
;
448 } else if (directions
& MAX_RIGHTHALF
) {
449 new_width
= half_scr_width
- adj_size
;
450 new_x
= usableArea
.x1
+ half_scr_width
;
452 /* top|bottom position */
453 if (directions
& MAX_TOPHALF
) {
454 new_height
= half_scr_height
- adj_size
;
455 new_y
= usableArea
.y1
;
456 } else if (directions
& MAX_BOTTOMHALF
) {
457 new_height
= half_scr_height
- adj_size
;
458 new_y
= usableArea
.y1
+ half_scr_height
;
461 /* vertical|horizontal position */
462 if (directions
& MAX_HORIZONTAL
) {
463 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
464 new_x
= usableArea
.x1
;
466 if (directions
& MAX_VERTICAL
) {
467 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
468 new_y
= usableArea
.y1
;
469 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
470 new_y
-= wwin
->frame
->top_width
;
474 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
475 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
477 /* set maximization state */
478 wwin
->flags
.maximized
= directions
;
479 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
480 wwin
->flags
.maximized
= MAX_MAXIMUS
;
482 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
484 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
485 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
487 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
488 wWindowSynthConfigureNotify(wwin
);
490 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
493 /* generic (un)maximizer */
494 void handleMaximize(WWindow
*wwin
, int directions
)
496 int current
= wwin
->flags
.maximized
;
497 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
498 int effective
= requested
^ current
;
499 int flags
= directions
& ~requested
;
502 /* allow wMaximizeWindow to restore the Maximusized size */
503 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
504 !(requested
& MAX_MAXIMUS
))
505 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
507 wUnmaximizeWindow(wwin
);
508 /* these alone mean vertical|horizontal toggle */
509 } else if ((effective
== MAX_LEFTHALF
) ||
510 (effective
== MAX_RIGHTHALF
) ||
511 (effective
== MAX_TOPHALF
) ||
512 (effective
== MAX_BOTTOMHALF
))
513 wUnmaximizeWindow(wwin
);
515 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
516 (requested
== MAX_MAXIMUS
))
517 effective
= requested
;
519 if (requested
& MAX_LEFTHALF
) {
520 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
521 effective
|= MAX_VERTICAL
;
523 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
524 effective
|= MAX_LEFTHALF
;
525 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
526 } else if (requested
& MAX_RIGHTHALF
) {
527 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
528 effective
|= MAX_VERTICAL
;
530 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
531 effective
|= MAX_RIGHTHALF
;
532 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
534 if (requested
& MAX_TOPHALF
) {
535 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
536 effective
|= MAX_HORIZONTAL
;
538 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
539 effective
|= MAX_TOPHALF
;
540 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
541 } else if (requested
& MAX_BOTTOMHALF
) {
542 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
543 effective
|= MAX_HORIZONTAL
;
545 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
546 effective
|= MAX_BOTTOMHALF
;
547 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
549 if (requested
& MAX_HORIZONTAL
)
550 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
551 if (requested
& MAX_VERTICAL
)
552 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
553 effective
&= ~MAX_MAXIMUS
;
555 wMaximizeWindow(wwin
, effective
| flags
);
559 /* the window boundary coordinates */
569 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
571 obs
->left
= wwin
->frame_x
;
572 obs
->top
= wwin
->frame_y
;
573 obs
->width
= wwin
->frame
->core
->width
;
574 obs
->height
= wwin
->frame
->core
->height
;
575 obs
->bottom
= obs
->top
+ obs
->height
;
576 obs
->right
= obs
->left
+ obs
->width
;
580 * Maximus: tiled maximization (maximize without overlapping other windows)
582 * The original window 'orig' will be maximized to new coordinates 'new'.
583 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
585 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
586 unsigned int *new_width
, unsigned int *new_height
)
589 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
590 short int adjust_height
;
591 int x_intsect
, y_intsect
;
592 /* the obstructing, original and new windows */
593 win_coords obs
, orig
, new;
595 /* set the original coordinate positions of the window to be Maximumized */
596 if (wwin
->flags
.maximized
) {
597 /* window is already maximized; consider original geometry */
598 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
599 orig
.bottom
= orig
.top
+ orig
.height
;
600 orig
.right
= orig
.left
+ orig
.width
;
602 set_window_coords(wwin
, &orig
);
604 /* Try to fully maximize first, then readjust later */
605 new.left
= usableArea
.x1
;
606 new.right
= usableArea
.x2
;
607 new.top
= usableArea
.y1
;
608 new.bottom
= usableArea
.y2
;
610 if (HAS_TITLEBAR(wwin
))
611 tbar_height_0
= TITLEBAR_HEIGHT
;
612 if (HAS_RESIZEBAR(wwin
))
613 rbar_height_0
= RESIZEBAR_HEIGHT
;
614 if (HAS_BORDER(wwin
))
615 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
617 /* the length to be subtracted if the window has titlebar, etc */
618 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
621 /* The focused window is always the last in the list */
623 /* ignore windows in other workspaces etc */
624 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
625 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
631 /* Set the coordinates of obstructing window */
632 set_window_coords(tmp
, &obs
);
634 /* Try to maximize in the y direction first */
635 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
636 if (x_intsect
!= 0) {
637 /* TODO: Consider the case when coords are equal */
638 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
639 /* w_0 is below the bottom of w_j */
640 new.top
= obs
.bottom
+ 1;
642 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
643 /* The bottom of w_0 is above the top of w_j */
644 new.bottom
= obs
.top
- 1;
651 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
652 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
658 set_window_coords(tmp
, &obs
);
661 * Use the new.top and new.height instead of original values
662 * as they may have different intersections with the obstructing windows
664 new.height
= new.bottom
- new.top
- adjust_height
;
665 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
666 if (y_intsect
!= 0) {
667 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
668 /* w_0 is completely to the right of w_j */
669 new.left
= obs
.right
+ 1;
671 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
672 /* w_0 is completely to the left of w_j */
673 new.right
= obs
.left
- 1;
680 /* xcalc needs -7 here, but other apps don't */
681 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
682 *new_width
= new.right
- new.left
;
685 void wUnmaximizeWindow(WWindow
*wwin
)
689 if (!wwin
->flags
.maximized
)
692 if (wwin
->flags
.shaded
) {
693 wwin
->flags
.skip_next_animation
= 1;
694 wUnshadeWindow(wwin
);
697 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
698 wwin
->client_flags
.no_movable
= 0;
700 /* Use old coordinates if they are set, current values otherwise */
701 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
703 /* unMaximusize relative to original position */
704 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
705 x
+= wwin
->frame_x
- wwin
->maximus_x
;
706 y
+= wwin
->frame_y
- wwin
->maximus_y
;
709 wwin
->flags
.maximized
= 0;
710 wwin
->flags
.old_maximized
= 0;
711 wWindowConfigure(wwin
, x
, y
, w
, h
);
712 wWindowSynthConfigureNotify(wwin
);
714 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
717 void wFullscreenWindow(WWindow
*wwin
)
722 if (wwin
->flags
.fullscreen
)
725 wwin
->flags
.fullscreen
= True
;
727 wWindowConfigureBorders(wwin
);
729 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
730 wRaiseFrame(wwin
->frame
->core
);
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 (WFLAGP(wwin
, sunken
))
755 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
756 else if (WFLAGP(wwin
, floating
))
757 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
759 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
760 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
762 wWindowConfigureBorders(wwin
);
764 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
765 wFrameWindowPaint(wwin->frame);
768 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
770 if (wwin
->screen_ptr
->bfs_focused_window
) {
771 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
772 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
776 #ifdef USE_ANIMATIONS
777 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
779 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
780 float cx
, cy
, cw
, ch
;
781 float xstep
, ystep
, wstep
, hstep
;
784 float angle
, final_angle
, delta
;
786 xstep
= (float)(fx
- x
) / steps
;
787 ystep
= (float)(fy
- y
) / steps
;
788 wstep
= (float)(fw
- w
) / steps
;
789 hstep
= (float)(fh
- h
) / steps
;
796 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
797 delta
= (float)(final_angle
/ FRAMES
);
798 for (angle
= 0;; angle
+= delta
) {
799 if (angle
> final_angle
)
802 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
803 dch
= (ch
/ 2) * cosf(angle
);
804 midy
= cy
+ (ch
/ 2);
806 points
[0].x
= cx
+ dx
;
807 points
[0].y
= midy
- dch
;
808 points
[1].x
= cx
+ cw
- dx
;
809 points
[1].y
= points
[0].y
;
810 points
[2].x
= cx
+ cw
+ dx
;
811 points
[2].y
= midy
+ dch
;
812 points
[3].x
= cx
- dx
;
813 points
[3].y
= points
[2].y
;
814 points
[4].x
= points
[0].x
;
815 points
[4].y
= points
[0].y
;
818 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
820 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
822 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
828 if (angle
>= final_angle
)
838 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
840 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
841 float cx
, cy
, cw
, ch
;
842 float xstep
, ystep
, wstep
, hstep
;
844 float angle
, final_angle
, a
, d
, delta
;
851 xstep
= (float)(fx
- x
) / steps
;
852 ystep
= (float)(fy
- y
) / steps
;
853 wstep
= (float)(fw
- w
) / steps
;
854 hstep
= (float)(fh
- h
) / steps
;
861 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
862 delta
= (float)(final_angle
/ FRAMES
);
863 for (angle
= 0;; angle
+= delta
) {
864 if (angle
> final_angle
)
868 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
870 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
871 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
872 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
873 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
874 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
875 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
876 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
877 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
878 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
879 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
881 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
883 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
885 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
891 if (angle
>= final_angle
)
900 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
902 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
903 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
904 float xstep
, ystep
, wstep
, hstep
;
907 xstep
= (float)(fx
- x
) / steps
;
908 ystep
= (float)(fy
- y
) / steps
;
909 wstep
= (float)(fw
- w
) / steps
;
910 hstep
= (float)(fh
- h
) / steps
;
912 for (j
= 0; j
< FRAMES
; j
++) {
919 for (i
= 0; i
< steps
; i
++) {
920 for (j
= 0; j
< FRAMES
; j
++) {
921 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
922 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
925 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
927 for (j
= 0; j
< FRAMES
; j
++) {
928 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
929 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
930 if (j
< FRAMES
- 1) {
944 for (j
= 0; j
< FRAMES
; j
++)
945 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
947 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
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
]);
957 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
959 int style
= wPreferences
.iconification_style
; /* Catch the value */
962 if (style
== WIS_NONE
)
965 if (style
== WIS_RANDOM
)
970 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
972 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
975 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
977 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
981 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
983 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
987 #endif /* USE_ANIMATIONS */
989 static void flushExpose(void)
993 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
994 WMHandleEvent(&tmpev
);
998 static void unmapTransientsFor(WWindow
*wwin
)
1002 tmp
= wwin
->screen_ptr
->focused_window
;
1004 /* unmap the transients for this transient */
1005 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1006 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1007 unmapTransientsFor(tmp
);
1008 tmp
->flags
.miniaturized
= 1;
1009 if (!tmp
->flags
.shaded
)
1012 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1014 if (!tmp->flags.shaded)
1016 wClientSetState(tmp
, IconicState
, None
);
1018 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1024 static void mapTransientsFor(WWindow
*wwin
)
1028 tmp
= wwin
->screen_ptr
->focused_window
;
1030 /* recursively map the transients for this transient */
1031 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1032 && tmp
->icon
== NULL
) {
1033 mapTransientsFor(tmp
);
1034 tmp
->flags
.miniaturized
= 0;
1035 if (!tmp
->flags
.shaded
)
1038 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1039 tmp
->flags
.semi_focused
= 0;
1041 if (!tmp->flags.shaded)
1043 wClientSetState(tmp
, NormalState
, None
);
1045 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1051 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1058 /* hackish way to detect transient_for cycle */
1059 i
= wwin
->screen_ptr
->window_count
+ 1;
1061 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1062 wwin
= wWindowFor(wwin
->transient_for
);
1065 if (i
== 0 && wwin
) {
1066 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1067 wwin
->frame
->title
);
1074 #ifdef USE_ANIMATIONS
1075 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1077 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1078 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1081 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1084 *iw
= wwin
->icon
->core
->width
;
1085 *ih
= wwin
->icon
->core
->height
;
1087 if (wwin
->flags
.net_handle_icon
) {
1095 *iw
= wwin
->screen_ptr
->scr_width
;
1096 *ih
= wwin
->screen_ptr
->scr_height
;
1101 #endif /* USE_ANIMATIONS */
1103 void wIconifyWindow(WWindow
*wwin
)
1105 XWindowAttributes attribs
;
1108 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1109 return; /* the window doesn't exist anymore */
1111 if (wwin
->flags
.miniaturized
)
1112 return; /* already miniaturized */
1114 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1115 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1117 if (owner
&& owner
->flags
.miniaturized
)
1121 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1123 /* if the window is in another workspace, simplify process */
1125 /* icon creation may take a while */
1126 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1127 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1128 GrabModeAsync
, None
, None
, CurrentTime
);
1131 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1132 if (!wwin
->flags
.icon_moved
)
1133 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1135 wwin
->icon
= icon_create_for_wwindow(wwin
);
1136 wwin
->icon
->mapped
= 1;
1138 /* extract the window screenshot everytime, as the option can be enable anytime */
1139 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1140 RImage
*mini_preview
;
1146 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1147 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1152 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1153 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1155 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1156 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1158 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1160 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1161 XDestroyImage(pimg
);
1164 set_icon_minipreview(wwin
->icon
, mini_preview
);
1165 RReleaseImage(mini_preview
);
1170 if (wwin
->frame
->title
) {
1171 title
= wwin
->frame
->title
;
1173 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1176 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1182 wwin
->flags
.miniaturized
= 1;
1183 wwin
->flags
.mapped
= 0;
1185 /* unmap transients */
1186 unmapTransientsFor(wwin
);
1189 #ifdef USE_ANIMATIONS
1192 XUngrabPointer(dpy
, CurrentTime
);
1194 /* let all Expose events arrive so that we can repaint
1195 * something before the animation starts (and the server is grabbed) */
1198 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1199 wClientSetState(wwin
, IconicState
, None
);
1201 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1204 #ifdef USE_ANIMATIONS
1205 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1206 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1207 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1211 wwin
->flags
.skip_next_animation
= 0;
1213 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1214 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1215 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1216 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1218 AddToStackList(wwin
->icon
->core
);
1219 wLowerFrame(wwin
->icon
->core
);
1223 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1226 * It doesn't seem to be working and causes button event hangup
1227 * when deiconifying a transient window.
1228 setupIconGrabs(wwin->icon);
1230 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1231 && wPreferences
.focus_mode
== WKF_CLICK
) {
1236 if (!WFLAGP(tmp
, no_focusable
)
1237 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1238 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1242 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1243 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1244 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1246 #ifdef USE_ANIMATIONS
1247 if (!wwin
->screen_ptr
->flags
.startup
) {
1248 /* Catch up with events not processed while animation was running */
1249 Window clientwin
= wwin
->client_win
;
1251 ProcessPendingEvents();
1253 /* the window can disappear while ProcessPendingEvents() runs */
1254 if (!wWindowFor(clientwin
))
1260 /* maybe we want to do this regardless of net_handle_icon
1261 * it seems to me we might break behaviour this way.
1263 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1264 && !wwin
->flags
.net_handle_icon
)
1265 wIconSelect(wwin
->icon
);
1267 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1269 if (wPreferences
.auto_arrange_icons
)
1270 wArrangeIcons(wwin
->screen_ptr
, True
);
1273 void wDeiconifyWindow(WWindow
*wwin
)
1275 /* Let's avoid changing workspace while deiconifying */
1276 w_global
.ignore_workspace_change
= True
;
1278 /* we're hiding for show_desktop */
1279 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1280 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1283 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1285 if (!wwin
->flags
.miniaturized
) {
1286 w_global
.ignore_workspace_change
= False
;
1290 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1291 WWindow
*owner
= recursiveTransientFor(wwin
);
1293 if (owner
&& owner
->flags
.miniaturized
) {
1294 wDeiconifyWindow(owner
);
1295 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1296 wRaiseFrame(wwin
->frame
->core
);
1297 w_global
.ignore_workspace_change
= False
;
1302 wwin
->flags
.miniaturized
= 0;
1304 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1305 wwin
->flags
.mapped
= 1;
1307 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1308 /* maybe we want to do this regardless of net_handle_icon
1309 * it seems to me we might break behaviour this way.
1311 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1312 && wwin
->icon
!= NULL
) {
1313 if (wwin
->icon
->selected
)
1314 wIconSelect(wwin
->icon
);
1316 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1320 /* if the window is in another workspace, do it silently */
1321 if (!netwm_hidden
) {
1322 #ifdef USE_ANIMATIONS
1324 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1325 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1326 wwin
->frame_x
, wwin
->frame_y
,
1327 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1329 wwin
->flags
.skip_next_animation
= 0;
1331 if (!wwin
->flags
.shaded
)
1332 XMapWindow(dpy
, wwin
->client_win
);
1334 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1335 wRaiseFrame(wwin
->frame
->core
);
1336 if (!wwin
->flags
.shaded
)
1337 wClientSetState(wwin
, NormalState
, None
);
1339 mapTransientsFor(wwin
);
1342 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1343 && !wwin
->flags
.net_handle_icon
) {
1344 RemoveFromStackList(wwin
->icon
->core
);
1345 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1346 wIconDestroy(wwin
->icon
);
1350 if (!netwm_hidden
) {
1353 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1355 #ifdef USE_ANIMATIONS
1356 if (!wwin
->screen_ptr
->flags
.startup
) {
1357 /* Catch up with events not processed while animation was running */
1358 Window clientwin
= wwin
->client_win
;
1360 ProcessPendingEvents();
1362 /* the window can disappear while ProcessPendingEvents() runs */
1363 if (!wWindowFor(clientwin
)) {
1364 w_global
.ignore_workspace_change
= False
;
1371 if (wPreferences
.auto_arrange_icons
)
1372 wArrangeIcons(wwin
->screen_ptr
, True
);
1374 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1376 /* In case we were shaded and iconified, also unshade */
1378 wUnshadeWindow(wwin
);
1380 w_global
.ignore_workspace_change
= False
;
1383 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1385 if (wwin
->flags
.miniaturized
) {
1387 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1388 wwin
->icon
->mapped
= 0;
1390 wwin
->flags
.hidden
= 1;
1392 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1396 if (wwin
->flags
.inspector_open
)
1397 wHideInspectorForWindow(wwin
);
1399 wwin
->flags
.hidden
= 1;
1402 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1405 #ifdef USE_ANIMATIONS
1406 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1407 !wwin
->flags
.skip_next_animation
&& animate
) {
1408 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1409 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1410 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1413 /* Tell the compiler it is normal that those parameters are not used in this case */
1418 wwin
->flags
.skip_next_animation
= 0;
1420 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1423 void wHideAll(WScreen
*scr
)
1428 unsigned int wcount
= 0;
1434 menu
= scr
->switch_menu
;
1436 windows
= wmalloc(sizeof(WWindow
*));
1439 for (i
= 0; i
< menu
->entry_no
; i
++) {
1440 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1442 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1445 wwin
= scr
->focused_window
;
1448 windows
[wcount
] = wwin
;
1450 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1456 for (i
= 0; i
< wcount
; i
++) {
1458 if (wwin
->frame
->workspace
== scr
->current_workspace
1459 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1460 && !wwin
->flags
.internal_window
1461 && !WFLAGP(wwin
, no_miniaturizable
)
1463 wwin
->flags
.skip_next_animation
= 1;
1464 wIconifyWindow(wwin
);
1471 void wHideOtherApplications(WWindow
*awin
)
1478 wwin
= awin
->screen_ptr
->focused_window
;
1482 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1483 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1484 && !wwin
->flags
.internal_window
1485 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1487 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1488 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1489 wwin
->flags
.skip_next_animation
= 1;
1490 wIconifyWindow(wwin
);
1492 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1493 tapp
= wApplicationOf(wwin
->main_window
);
1495 tapp
->flags
.skip_next_animation
= 1;
1496 wHideApplication(tapp
);
1498 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1499 wwin
->flags
.skip_next_animation
= 1;
1500 wIconifyWindow(wwin
);
1508 wSetFocusTo(awin->screen_ptr, awin);
1512 void wHideApplication(WApplication
*wapp
)
1520 wwarning("trying to hide a non grouped window");
1523 if (!wapp
->main_window_desc
) {
1524 wwarning("group leader not found for window group");
1527 scr
= wapp
->main_window_desc
->screen_ptr
;
1529 wlist
= scr
->focused_window
;
1533 if (wlist
->main_window
== wapp
->main_window
)
1534 wapp
->last_focused
= wlist
;
1536 wapp
->last_focused
= NULL
;
1538 animate
= !wapp
->flags
.skip_next_animation
;
1541 if (wlist
->main_window
== wapp
->main_window
) {
1542 if (wlist
->flags
.focused
)
1544 if (wapp
->app_icon
) {
1545 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1546 wapp
->app_icon
->y_pos
, wlist
, animate
);
1550 wlist
= wlist
->prev
;
1553 wapp
->flags
.skip_next_animation
= 0;
1556 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1557 wlist
= scr
->focused_window
;
1559 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1560 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1562 wlist
= wlist
->prev
;
1564 wSetFocusTo(scr
, wlist
);
1566 wSetFocusTo(scr
, NULL
);
1570 wapp
->flags
.hidden
= 1;
1572 if (wPreferences
.auto_arrange_icons
)
1573 wArrangeIcons(scr
, True
);
1577 wAppIconPaint(wapp
->app_icon
);
1581 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1583 if (bringToCurrentWS
)
1584 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1586 wwin
->flags
.hidden
= 0;
1588 #ifdef USE_ANIMATIONS
1589 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1590 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1591 icon
->core
->width
, icon
->core
->height
,
1592 wwin
->frame_x
, wwin
->frame_y
,
1593 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1596 /* Tell the compiler it is normal that those parameters are not used in this case */
1602 wwin
->flags
.skip_next_animation
= 0;
1603 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1604 XMapWindow(dpy
, wwin
->client_win
);
1605 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1606 wClientSetState(wwin
, NormalState
, None
);
1607 wwin
->flags
.mapped
= 1;
1608 wRaiseFrame(wwin
->frame
->core
);
1610 if (wwin
->flags
.inspector_open
)
1611 wUnhideInspectorForWindow(wwin
);
1613 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1616 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1619 WWindow
*wlist
, *next
;
1620 WWindow
*focused
= NULL
;
1626 scr
= wapp
->main_window_desc
->screen_ptr
;
1627 wlist
= scr
->focused_window
;
1631 /* goto beginning of list */
1633 wlist
= wlist
->prev
;
1635 animate
= !wapp
->flags
.skip_next_animation
;
1640 if (wlist
->main_window
== wapp
->main_window
) {
1641 if (wlist
->flags
.focused
)
1643 else if (!focused
|| !focused
->flags
.focused
)
1646 if (wlist
->flags
.miniaturized
) {
1647 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1648 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1649 if (!wlist
->icon
->mapped
) {
1652 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1653 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1654 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1657 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1658 wlist
->icon
->mapped
= 1;
1660 wRaiseFrame(wlist
->icon
->core
);
1662 if (bringToCurrentWS
)
1663 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1664 wlist
->flags
.hidden
= 0;
1665 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1666 wDeiconifyWindow(wlist
);
1667 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1668 } else if (wlist
->flags
.shaded
) {
1669 if (bringToCurrentWS
)
1670 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1671 wlist
->flags
.hidden
= 0;
1672 wRaiseFrame(wlist
->frame
->core
);
1673 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1674 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1676 wUnshadeWindow(wlist
);
1678 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1679 } else if (wlist
->flags
.hidden
) {
1680 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1681 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1684 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1685 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1687 wRaiseFrame(wlist
->frame
->core
);
1693 wapp
->flags
.skip_next_animation
= 0;
1694 wapp
->flags
.hidden
= 0;
1696 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1697 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1698 wSetFocusTo(scr
, wapp
->last_focused
);
1699 } else if (focused
) {
1700 wSetFocusTo(scr
, focused
);
1702 wapp
->last_focused
= NULL
;
1703 if (wPreferences
.auto_arrange_icons
)
1704 wArrangeIcons(scr
, True
);
1707 wAppIconPaint(wapp
->app_icon
);
1711 void wShowAllWindows(WScreen
*scr
)
1713 WWindow
*wwin
, *old_foc
;
1716 old_foc
= wwin
= scr
->focused_window
;
1718 if (!wwin
->flags
.internal_window
&&
1719 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1720 if (wwin
->flags
.miniaturized
) {
1721 wwin
->flags
.skip_next_animation
= 1;
1722 wDeiconifyWindow(wwin
);
1723 } else if (wwin
->flags
.hidden
) {
1724 wapp
= wApplicationOf(wwin
->main_window
);
1726 wUnhideApplication(wapp
, False
, False
);
1728 wwin
->flags
.skip_next_animation
= 1;
1729 wDeiconifyWindow(wwin
);
1735 wSetFocusTo(scr
, old_foc
);
1736 /*wRaiseFrame(old_foc->frame->core); */
1739 void wRefreshDesktop(WScreen
*scr
)
1742 XSetWindowAttributes attr
;
1744 attr
.backing_store
= NotUseful
;
1745 attr
.save_under
= False
;
1746 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1747 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1748 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1749 XMapRaised(dpy
, win
);
1750 XDestroyWindow(dpy
, win
);
1754 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1760 const int heads
= wXineramaHeads(scr
);
1763 int pf
; /* primary axis */
1764 int sf
; /* secondary axis */
1768 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1774 int isize
= wPreferences
.icon_size
;
1776 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1778 for (head
= 0; head
< heads
; ++head
) {
1779 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1783 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1785 if (scr
->dock
->on_right_side
)
1791 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1793 vars
[head
].pi
= vars
[head
].si
= 0;
1794 vars
[head
].sx1
= rect
.pos
.x
;
1795 vars
[head
].sy1
= rect
.pos
.y
;
1796 vars
[head
].sw
= rect
.size
.width
;
1797 vars
[head
].sh
= rect
.size
.height
;
1798 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1799 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1800 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1801 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1802 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1803 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1805 /* icon yard boundaries */
1806 if (wPreferences
.icon_yard
& IY_VERT
) {
1807 vars
[head
].pf
= vars
[head
].fullH
;
1808 vars
[head
].sf
= vars
[head
].fullW
;
1810 vars
[head
].pf
= vars
[head
].fullW
;
1811 vars
[head
].sf
= vars
[head
].fullH
;
1813 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1814 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1817 vars
[head
].xo
= vars
[head
].sx1
;
1820 if (wPreferences
.icon_yard
& IY_TOP
) {
1821 vars
[head
].yo
= vars
[head
].sy1
;
1824 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1829 #define X ((wPreferences.icon_yard & IY_VERT) \
1830 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1831 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1833 #define Y ((wPreferences.icon_yard & IY_VERT) \
1834 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1835 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1837 /* arrange application icons */
1838 aicon
= scr
->app_icon_list
;
1839 /* reverse them to avoid unnecessarily sliding of icons */
1840 while (aicon
&& aicon
->next
)
1841 aicon
= aicon
->next
;
1844 if (!aicon
->docked
) {
1845 /* CHECK: can icon be NULL here ? */
1846 /* The intention here is to place the AppIcon on the head that
1847 * contains most of the applications _main_ window. */
1848 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1850 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1851 #ifdef USE_ANIMATIONS
1852 if (!wPreferences
.no_animations
)
1853 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1854 #endif /* USE_ANIMATIONS */
1856 wAppIconMove(aicon
, X
, Y
);
1858 if (vars
[head
].pi
>= vars
[head
].pf
) {
1863 aicon
= aicon
->prev
;
1866 /* arrange miniwindows */
1867 wwin
= scr
->focused_window
;
1868 /* reverse them to avoid unnecessarily shuffling */
1869 while (wwin
&& wwin
->prev
)
1873 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1874 (wwin
->frame
->workspace
== scr
->current_workspace
||
1875 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1877 head
= wGetHeadForWindow(wwin
);
1879 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1880 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1881 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1887 if (vars
[head
].pi
>= vars
[head
].pf
) {
1894 wwin
->flags
.icon_moved
= 0;
1895 /* we reversed the order, so we use next */
1902 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1904 WScreen
*scr
= wwin
->screen_ptr
;
1907 wwin
->flags
.selected
= 1;
1908 if (wwin
->frame
->selected_border_pixel
)
1909 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1911 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1913 if (!HAS_BORDER(wwin
))
1914 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1916 if (!scr
->selected_windows
)
1917 scr
->selected_windows
= WMCreateArray(4);
1918 WMAddToArray(scr
->selected_windows
, wwin
);
1920 wwin
->flags
.selected
= 0;
1921 if (wwin
->flags
.focused
) {
1922 if (wwin
->frame
->focused_border_pixel
)
1923 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1925 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1927 if (wwin
->frame
->border_pixel
)
1928 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1930 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1933 if (!HAS_BORDER(wwin
))
1934 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1936 if (scr
->selected_windows
)
1937 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1941 void wMakeWindowVisible(WWindow
*wwin
)
1943 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1944 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1946 if (wwin
->flags
.shaded
)
1947 wUnshadeWindow(wwin
);
1949 if (wwin
->flags
.hidden
) {
1952 app
= wApplicationOf(wwin
->main_window
);
1954 /* trick to get focus to this window */
1955 app
->last_focused
= wwin
;
1956 wUnhideApplication(app
, False
, False
);
1959 if (wwin
->flags
.miniaturized
) {
1960 wDeiconifyWindow(wwin
);
1962 if (!WFLAGP(wwin
, no_focusable
))
1963 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1964 wRaiseFrame(wwin
->frame
->core
);
1969 * Do the animation while shading (called with what = SHADE)
1970 * or unshading (what = UNSHADE).
1972 #ifdef USE_ANIMATIONS
1973 static void shade_animate(WWindow
*wwin
, Bool what
)
1976 time_t time0
= time(NULL
);
1978 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1983 if (!wwin
->screen_ptr
->flags
.startup
) {
1984 /* do the shading animation */
1985 h
= wwin
->frame
->core
->height
;
1986 s
= h
/ SHADE_STEPS
;
1989 w
= wwin
->frame
->core
->width
;
1990 y
= wwin
->frame
->top_width
;
1991 while (h
> wwin
->frame
->top_width
+ 1) {
1992 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1993 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1996 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1999 if (SHADE_DELAY
> 0)
2000 wusleep(SHADE_DELAY
* 1000L);
2006 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2011 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2012 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2013 s
= abs(y
) / SHADE_STEPS
;
2016 w
= wwin
->frame
->core
->width
;
2017 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2019 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2020 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2021 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2023 if (SHADE_DELAY
> 0)
2024 wusleep(SHADE_DELAY
* 2000L / 3);
2030 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2034 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);