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 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
56 unsigned int *new_width
, unsigned int *new_height
);
57 static void save_old_geometry(WWindow
*wwin
, int directions
);
59 /******* Local Variables *******/
65 { SHADE_STEPS_UF
, SHADE_DELAY_UF
},
66 { SHADE_STEPS_F
, SHADE_DELAY_F
},
67 { SHADE_STEPS_M
, SHADE_DELAY_M
},
68 { SHADE_STEPS_S
, SHADE_DELAY_S
},
69 { SHADE_STEPS_US
, SHADE_DELAY_US
}
72 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
73 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
79 static int compareTimes(Time t1
, Time t2
)
85 return (diff
< 60000) ? 1 : -1;
89 static void shade_animate(WWindow
*wwin
, Bool what
);
91 static inline void shade_animate(WWindow
*wwin
, Bool what
)
94 * This function is empty on purpose, so tell the compiler
95 * to not warn about parameters being not used
103 *----------------------------------------------------------------------
105 * Changes the window focus to the one passed as argument.
106 * If the window to focus is not already focused, it will be brought
107 * to the head of the list of windows. Previously focused window is
111 * Window list may be reordered and the window focus is changed.
113 *----------------------------------------------------------------------
115 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
117 static WScreen
*old_scr
= NULL
;
119 WWindow
*old_focused
;
120 WWindow
*focused
= scr
->focused_window
;
121 Time timestamp
= w_global
.timestamp
.last_event
;
122 WApplication
*oapp
= NULL
, *napp
= NULL
;
125 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
131 old_focused
= old_scr
->focused_window
;
133 w_global
.timestamp
.focus_change
= timestamp
;
136 oapp
= wApplicationOf(old_focused
->main_window
);
139 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
141 wWindowUnfocus(old_focused
);
144 wAppMenuUnmap(oapp
->menu
);
145 if (wPreferences
.highlight_active_app
)
146 wApplicationDeactivate(oapp
);
149 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
153 if (old_scr
!= scr
&& old_focused
)
154 wWindowUnfocus(old_focused
);
156 wasfocused
= wwin
->flags
.focused
;
157 napp
= wApplicationOf(wwin
->main_window
);
159 /* remember last workspace where the app has been */
161 napp
->last_workspace
= wwin
->frame
->workspace
;
163 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
164 /* install colormap if colormap mode is lock mode */
165 if (wPreferences
.colormap_mode
== WCM_CLICK
)
166 wColormapInstallForWindow(scr
, wwin
);
168 /* set input focus */
169 switch (wwin
->focus_mode
) {
171 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
174 case WFM_LOCALLY_ACTIVE
:
175 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
177 case WFM_GLOBALLY_ACTIVE
:
182 if (wwin
->protocols
.TAKE_FOCUS
)
183 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
187 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
190 if (WFLAGP(wwin
, no_focusable
))
193 /* if this is not the focused window focus it */
194 if (focused
!= wwin
) {
195 /* change the focus window list order */
197 wwin
->prev
->next
= wwin
->next
;
200 wwin
->next
->prev
= wwin
->prev
;
202 wwin
->prev
= focused
;
203 focused
->next
= wwin
;
205 scr
->focused_window
= wwin
;
207 if (oapp
&& oapp
!= napp
) {
208 wAppMenuUnmap(oapp
->menu
);
209 if (wPreferences
.highlight_active_app
)
210 wApplicationDeactivate(oapp
);
214 wWindowFocus(wwin
, focused
);
216 if (napp
&& !wasfocused
) {
218 wUserMenuRefreshInstances(napp
->menu
, wwin
);
219 #endif /* USER_MENU */
221 if (wwin
->flags
.mapped
)
222 wAppMenuMap(napp
->menu
, wwin
);
224 if (napp
&& wPreferences
.highlight_active_app
)
225 wApplicationActivate(napp
);
231 void wShadeWindow(WWindow
*wwin
)
234 if (wwin
->flags
.shaded
)
237 XLowerWindow(dpy
, wwin
->client_win
);
238 shade_animate(wwin
, SHADE
);
240 wwin
->flags
.skip_next_animation
= 0;
241 wwin
->flags
.shaded
= 1;
242 wwin
->flags
.mapped
= 0;
243 /* prevent window withdrawal when getting UnmapNotify */
244 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
245 XUnmapWindow(dpy
, wwin
->client_win
);
246 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
248 /* for the client it's just like iconification */
249 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
251 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
252 wWindowSynthConfigureNotify(wwin
);
255 wClientSetState(wwin, IconicState, None);
258 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
260 #ifdef USE_ANIMATIONS
261 if (!wwin
->screen_ptr
->flags
.startup
) {
262 /* Catch up with events not processed while animation was running */
263 ProcessPendingEvents();
268 void wUnshadeWindow(WWindow
*wwin
)
271 if (!wwin
->flags
.shaded
)
274 wwin
->flags
.shaded
= 0;
275 wwin
->flags
.mapped
= 1;
276 XMapWindow(dpy
, wwin
->client_win
);
278 shade_animate(wwin
, UNSHADE
);
280 wwin
->flags
.skip_next_animation
= 0;
281 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
282 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
284 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
285 wWindowSynthConfigureNotify(wwin
);
287 /* if the window is focused, set the focus again as it was disabled during
289 if (wwin
->flags
.focused
)
290 wSetFocusTo(wwin
->screen_ptr
, wwin
);
292 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
295 /* Set the old coordinates using the current values */
296 static void save_old_geometry(WWindow
*wwin
, int directions
)
298 /* never been saved? */
299 if (!wwin
->old_geometry
.width
)
300 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
301 if (!wwin
->old_geometry
.height
)
302 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
304 if (directions
& SAVE_GEOMETRY_X
)
305 wwin
->old_geometry
.x
= wwin
->frame_x
;
306 if (directions
& SAVE_GEOMETRY_Y
)
307 wwin
->old_geometry
.y
= wwin
->frame_y
;
308 if (directions
& SAVE_GEOMETRY_WIDTH
)
309 wwin
->old_geometry
.width
= wwin
->client
.width
;
310 if (directions
& SAVE_GEOMETRY_HEIGHT
)
311 wwin
->old_geometry
.height
= wwin
->client
.height
;
314 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
316 WMRect old_geom_rect
;
320 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
321 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
322 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
323 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
324 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
325 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
326 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
329 /* Remember geometry for unmaximizing */
330 void update_saved_geometry(WWindow
*wwin
)
332 /* NOT if we aren't already maximized
333 * we'll save geometry when maximizing */
334 if (!wwin
->flags
.maximized
)
337 /* NOT if we are fully maximized */
338 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
339 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
340 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
343 /* save the co-ordinate in the axis in which we AREN'T maximized */
344 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
345 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
346 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
347 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
350 void wMaximizeWindow(WWindow
*wwin
, int directions
)
352 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
357 unsigned int maximus_width
= 0;
358 unsigned int maximus_height
= 0;
359 WArea usableArea
, totalArea
;
362 WScreen
*scr
= wwin
->screen_ptr
;
364 if (!IS_RESIZABLE(wwin
))
367 if (!HAS_BORDER(wwin
))
370 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
371 wwin
->client_flags
.no_movable
= 1;
373 /* the size to adjust the geometry */
374 adj_size
= scr
->frame_border_width
* 2 * has_border
;
376 /* save old coordinates before we change the current values */
377 if (!wwin
->flags
.maximized
)
378 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
380 totalArea
.x2
= scr
->scr_width
;
381 totalArea
.y2
= scr
->scr_height
;
384 usableArea
= totalArea
;
386 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
387 WScreen
*scr
= wwin
->screen_ptr
;
390 if (directions
& MAX_KEYBOARD
)
391 head
= wGetHeadForWindow(wwin
);
393 head
= wGetHeadForPointerLocation(scr
);
395 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
399 /* Only save directions, not kbd or xinerama hints */
400 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
402 if (WFLAGP(wwin
, full_maximize
))
403 usableArea
= totalArea
;
404 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
405 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
407 if (wwin
->flags
.shaded
) {
408 wwin
->flags
.skip_next_animation
= 1;
409 wUnshadeWindow(wwin
);
412 if (directions
& MAX_MAXIMUS
) {
413 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
414 new_width
= maximus_width
- adj_size
;
415 new_height
= maximus_height
- adj_size
;
418 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
419 new_height
+= wwin
->frame
->bottom_width
- 1;
420 new_y
-= wwin
->frame
->top_width
;
423 wwin
->maximus_x
= new_x
;
424 wwin
->maximus_y
= new_y
;
425 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
427 /* set default values if no option set then */
428 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
429 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
430 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
432 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
433 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
434 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
437 /* left|right position */
438 if (directions
& MAX_LEFTHALF
) {
439 new_width
= half_scr_width
- adj_size
;
440 new_x
= usableArea
.x1
;
441 } else if (directions
& MAX_RIGHTHALF
) {
442 new_width
= half_scr_width
- adj_size
;
443 new_x
= usableArea
.x1
+ half_scr_width
;
445 /* top|bottom position */
446 if (directions
& MAX_TOPHALF
) {
447 new_height
= half_scr_height
- adj_size
;
448 new_y
= usableArea
.y1
;
449 } else if (directions
& MAX_BOTTOMHALF
) {
450 new_height
= half_scr_height
- adj_size
;
451 new_y
= usableArea
.y1
+ half_scr_height
;
454 /* vertical|horizontal position */
455 if (directions
& MAX_HORIZONTAL
) {
456 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
457 new_x
= usableArea
.x1
;
459 if (directions
& MAX_VERTICAL
) {
460 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
461 new_y
= usableArea
.y1
;
462 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
463 new_y
-= wwin
->frame
->top_width
;
467 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
468 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
470 /* set maximization state */
471 wwin
->flags
.maximized
= directions
;
472 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
473 wwin
->flags
.maximized
= MAX_MAXIMUS
;
475 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
477 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
478 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
480 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
481 wWindowSynthConfigureNotify(wwin
);
483 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
486 /* generic (un)maximizer */
487 void handleMaximize(WWindow
*wwin
, int directions
)
489 int current
= wwin
->flags
.maximized
;
490 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
491 int effective
= requested
^ current
;
492 int flags
= directions
& ~requested
;
495 /* allow wMaximizeWindow to restore the Maximusized size */
496 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
497 !(requested
& MAX_MAXIMUS
))
498 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
500 wUnmaximizeWindow(wwin
);
501 /* these alone mean vertical|horizontal toggle */
502 } else if ((effective
== MAX_LEFTHALF
) ||
503 (effective
== MAX_RIGHTHALF
) ||
504 (effective
== MAX_TOPHALF
) ||
505 (effective
== MAX_BOTTOMHALF
))
506 wUnmaximizeWindow(wwin
);
508 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
509 (requested
== MAX_MAXIMUS
))
510 effective
= requested
;
512 if (requested
& MAX_LEFTHALF
) {
513 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
514 effective
|= MAX_VERTICAL
;
516 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
517 effective
|= MAX_LEFTHALF
;
518 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
519 } else if (requested
& MAX_RIGHTHALF
) {
520 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
521 effective
|= MAX_VERTICAL
;
523 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
524 effective
|= MAX_RIGHTHALF
;
525 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
527 if (requested
& MAX_TOPHALF
) {
528 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
529 effective
|= MAX_HORIZONTAL
;
531 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
532 effective
|= MAX_TOPHALF
;
533 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
534 } else if (requested
& MAX_BOTTOMHALF
) {
535 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
536 effective
|= MAX_HORIZONTAL
;
538 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
539 effective
|= MAX_BOTTOMHALF
;
540 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
542 if (requested
& MAX_HORIZONTAL
)
543 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
544 if (requested
& MAX_VERTICAL
)
545 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
546 effective
&= ~MAX_MAXIMUS
;
548 wMaximizeWindow(wwin
, effective
| flags
);
552 /* the window boundary coordinates */
562 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
564 obs
->left
= wwin
->frame_x
;
565 obs
->top
= wwin
->frame_y
;
566 obs
->width
= wwin
->frame
->core
->width
;
567 obs
->height
= wwin
->frame
->core
->height
;
568 obs
->bottom
= obs
->top
+ obs
->height
;
569 obs
->right
= obs
->left
+ obs
->width
;
573 * Maximus: tiled maximization (maximize without overlapping other windows)
575 * The original window 'orig' will be maximized to new coordinates 'new'.
576 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
578 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
579 unsigned int *new_width
, unsigned int *new_height
)
582 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
583 short int adjust_height
;
584 int x_intsect
, y_intsect
;
585 /* the obstructing, original and new windows */
586 win_coords obs
, orig
, new;
588 /* set the original coordinate positions of the window to be Maximumized */
589 if (wwin
->flags
.maximized
) {
590 /* window is already maximized; consider original geometry */
591 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
592 orig
.bottom
= orig
.top
+ orig
.height
;
593 orig
.right
= orig
.left
+ orig
.width
;
595 set_window_coords(wwin
, &orig
);
597 /* Try to fully maximize first, then readjust later */
598 new.left
= usableArea
.x1
;
599 new.right
= usableArea
.x2
;
600 new.top
= usableArea
.y1
;
601 new.bottom
= usableArea
.y2
;
603 if (HAS_TITLEBAR(wwin
))
604 tbar_height_0
= TITLEBAR_HEIGHT
;
605 if (HAS_RESIZEBAR(wwin
))
606 rbar_height_0
= RESIZEBAR_HEIGHT
;
607 if (HAS_BORDER(wwin
))
608 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
610 /* the length to be subtracted if the window has titlebar, etc */
611 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
614 /* The focused window is always the last in the list */
616 /* ignore windows in other workspaces etc */
617 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
618 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
624 /* Set the coordinates of obstructing window */
625 set_window_coords(tmp
, &obs
);
627 /* Try to maximize in the y direction first */
628 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
629 if (x_intsect
!= 0) {
630 /* TODO: Consider the case when coords are equal */
631 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
632 /* w_0 is below the bottom of w_j */
633 new.top
= obs
.bottom
+ 1;
635 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
636 /* The bottom of w_0 is above the top of w_j */
637 new.bottom
= obs
.top
- 1;
644 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
645 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
651 set_window_coords(tmp
, &obs
);
654 * Use the new.top and new.height instead of original values
655 * as they may have different intersections with the obstructing windows
657 new.height
= new.bottom
- new.top
- adjust_height
;
658 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
659 if (y_intsect
!= 0) {
660 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
661 /* w_0 is completely to the right of w_j */
662 new.left
= obs
.right
+ 1;
664 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
665 /* w_0 is completely to the left of w_j */
666 new.right
= obs
.left
- 1;
673 /* xcalc needs -7 here, but other apps don't */
674 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
675 *new_width
= new.right
- new.left
;
678 void wUnmaximizeWindow(WWindow
*wwin
)
682 if (!wwin
->flags
.maximized
)
685 if (wwin
->flags
.shaded
) {
686 wwin
->flags
.skip_next_animation
= 1;
687 wUnshadeWindow(wwin
);
690 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
691 wwin
->client_flags
.no_movable
= 0;
693 /* Use old coordinates if they are set, current values otherwise */
694 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
696 /* unMaximusize relative to original position */
697 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
698 x
+= wwin
->frame_x
- wwin
->maximus_x
;
699 y
+= wwin
->frame_y
- wwin
->maximus_y
;
702 wwin
->flags
.maximized
= 0;
703 wwin
->flags
.old_maximized
= 0;
704 wWindowConfigure(wwin
, x
, y
, w
, h
);
705 wWindowSynthConfigureNotify(wwin
);
707 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
710 void wFullscreenWindow(WWindow
*wwin
)
715 if (wwin
->flags
.fullscreen
)
718 wwin
->flags
.fullscreen
= True
;
720 wWindowConfigureBorders(wwin
);
722 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
723 wRaiseFrame(wwin
->frame
->core
);
725 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
726 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
727 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
728 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
730 head
= wGetHeadForWindow(wwin
);
731 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
732 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
734 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
735 wSetFocusTo(wwin
->screen_ptr
, wwin
);
737 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
740 void wUnfullscreenWindow(WWindow
*wwin
)
742 if (!wwin
->flags
.fullscreen
)
745 wwin
->flags
.fullscreen
= False
;
747 if (WFLAGP(wwin
, sunken
))
748 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
749 else if (WFLAGP(wwin
, floating
))
750 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
752 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
753 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
755 wWindowConfigureBorders(wwin
);
757 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
758 wFrameWindowPaint(wwin->frame);
761 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
763 if (wwin
->screen_ptr
->bfs_focused_window
) {
764 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
765 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
769 #ifdef USE_ANIMATIONS
770 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
772 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
773 float cx
, cy
, cw
, ch
;
774 float xstep
, ystep
, wstep
, hstep
;
777 float angle
, final_angle
, delta
;
779 xstep
= (float)(fx
- x
) / steps
;
780 ystep
= (float)(fy
- y
) / steps
;
781 wstep
= (float)(fw
- w
) / steps
;
782 hstep
= (float)(fh
- h
) / steps
;
789 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
790 delta
= (float)(final_angle
/ FRAMES
);
791 for (angle
= 0;; angle
+= delta
) {
792 if (angle
> final_angle
)
795 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
796 dch
= (ch
/ 2) * cos(angle
);
797 midy
= cy
+ (ch
/ 2);
799 points
[0].x
= cx
+ dx
;
800 points
[0].y
= midy
- dch
;
801 points
[1].x
= cx
+ cw
- dx
;
802 points
[1].y
= points
[0].y
;
803 points
[2].x
= cx
+ cw
+ dx
;
804 points
[2].y
= midy
+ dch
;
805 points
[3].x
= cx
- dx
;
806 points
[3].y
= points
[2].y
;
807 points
[4].x
= points
[0].x
;
808 points
[4].y
= points
[0].y
;
811 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
813 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
815 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
821 if (angle
>= final_angle
)
831 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
833 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
834 float cx
, cy
, cw
, ch
;
835 float xstep
, ystep
, wstep
, hstep
;
837 float angle
, final_angle
, a
, d
, delta
;
844 xstep
= (float)(fx
- x
) / steps
;
845 ystep
= (float)(fy
- y
) / steps
;
846 wstep
= (float)(fw
- w
) / steps
;
847 hstep
= (float)(fh
- h
) / steps
;
854 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
855 delta
= (float)(final_angle
/ FRAMES
);
856 for (angle
= 0;; angle
+= delta
) {
857 if (angle
> final_angle
)
861 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
863 points
[0].x
= cx
+ cos(angle
- a
) * d
;
864 points
[0].y
= cy
+ sin(angle
- a
) * d
;
865 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
866 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
867 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
868 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
869 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
870 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
871 points
[4].x
= cx
+ cos(angle
- a
) * d
;
872 points
[4].y
= cy
+ sin(angle
- a
) * d
;
874 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
876 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
878 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
884 if (angle
>= final_angle
)
893 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
895 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
896 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
897 float xstep
, ystep
, wstep
, hstep
;
900 xstep
= (float)(fx
- x
) / steps
;
901 ystep
= (float)(fy
- y
) / steps
;
902 wstep
= (float)(fw
- w
) / steps
;
903 hstep
= (float)(fh
- h
) / steps
;
905 for (j
= 0; j
< FRAMES
; j
++) {
912 for (i
= 0; i
< steps
; i
++) {
913 for (j
= 0; j
< FRAMES
; j
++) {
914 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
915 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
918 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
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
]);
923 if (j
< FRAMES
- 1) {
937 for (j
= 0; j
< FRAMES
; j
++)
938 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
940 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
942 for (j
= 0; j
< FRAMES
; j
++)
943 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
950 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
952 int style
= wPreferences
.iconification_style
; /* Catch the value */
955 if (style
== WIS_NONE
)
958 if (style
== WIS_RANDOM
)
963 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
965 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
968 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
970 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
974 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
976 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
980 #endif /* USE_ANIMATIONS */
982 static void flushExpose(void)
986 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
987 WMHandleEvent(&tmpev
);
991 static void unmapTransientsFor(WWindow
*wwin
)
995 tmp
= wwin
->screen_ptr
->focused_window
;
997 /* unmap the transients for this transient */
998 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
999 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1000 unmapTransientsFor(tmp
);
1001 tmp
->flags
.miniaturized
= 1;
1002 if (!tmp
->flags
.shaded
)
1005 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1007 if (!tmp->flags.shaded)
1009 wClientSetState(tmp
, IconicState
, None
);
1011 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1017 static void mapTransientsFor(WWindow
*wwin
)
1021 tmp
= wwin
->screen_ptr
->focused_window
;
1023 /* recursively map the transients for this transient */
1024 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1025 && tmp
->icon
== NULL
) {
1026 mapTransientsFor(tmp
);
1027 tmp
->flags
.miniaturized
= 0;
1028 if (!tmp
->flags
.shaded
)
1031 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1032 tmp
->flags
.semi_focused
= 0;
1034 if (!tmp->flags.shaded)
1036 wClientSetState(tmp
, NormalState
, None
);
1038 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1044 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1051 /* hackish way to detect transient_for cycle */
1052 i
= wwin
->screen_ptr
->window_count
+ 1;
1054 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1055 wwin
= wWindowFor(wwin
->transient_for
);
1058 if (i
== 0 && wwin
) {
1059 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1060 wwin
->frame
->title
);
1067 #ifdef USE_ANIMATIONS
1068 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1070 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1071 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1074 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1077 *iw
= wwin
->icon
->core
->width
;
1078 *ih
= wwin
->icon
->core
->height
;
1080 if (wwin
->flags
.net_handle_icon
) {
1088 *iw
= wwin
->screen_ptr
->scr_width
;
1089 *ih
= wwin
->screen_ptr
->scr_height
;
1094 #endif /* USE_ANIMATIONS */
1096 void wIconifyWindow(WWindow
*wwin
)
1098 XWindowAttributes attribs
;
1101 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1102 return; /* the window doesn't exist anymore */
1104 if (wwin
->flags
.miniaturized
)
1105 return; /* already miniaturized */
1107 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1108 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1110 if (owner
&& owner
->flags
.miniaturized
)
1114 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1116 /* if the window is in another workspace, simplify process */
1118 /* icon creation may take a while */
1119 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1120 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1121 GrabModeAsync
, None
, None
, CurrentTime
);
1124 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1125 if (!wwin
->flags
.icon_moved
)
1126 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1128 wwin
->icon
= icon_create_for_wwindow(wwin
);
1129 wwin
->icon
->mapped
= 1;
1131 /* extract the window screenshot everytime, as the option can be enable anytime */
1132 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1133 RImage
*mini_preview
;
1139 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1140 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1145 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1146 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1148 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1149 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1151 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1153 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1154 XDestroyImage(pimg
);
1157 set_icon_minipreview(wwin
->icon
, mini_preview
);
1158 RReleaseImage(mini_preview
);
1163 if (wwin
->frame
->title
) {
1164 title
= wwin
->frame
->title
;
1166 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1169 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1175 wwin
->flags
.miniaturized
= 1;
1176 wwin
->flags
.mapped
= 0;
1178 /* unmap transients */
1179 unmapTransientsFor(wwin
);
1182 #ifdef USE_ANIMATIONS
1185 XUngrabPointer(dpy
, CurrentTime
);
1187 /* let all Expose events arrive so that we can repaint
1188 * something before the animation starts (and the server is grabbed) */
1191 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1192 wClientSetState(wwin
, IconicState
, None
);
1194 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1197 #ifdef USE_ANIMATIONS
1198 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1199 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1200 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1204 wwin
->flags
.skip_next_animation
= 0;
1206 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1207 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1208 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1209 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1211 AddToStackList(wwin
->icon
->core
);
1212 wLowerFrame(wwin
->icon
->core
);
1216 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1219 * It doesn't seem to be working and causes button event hangup
1220 * when deiconifying a transient window.
1221 setupIconGrabs(wwin->icon);
1223 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1224 && wPreferences
.focus_mode
== WKF_CLICK
) {
1229 if (!WFLAGP(tmp
, no_focusable
)
1230 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1231 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1235 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1236 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1237 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1239 #ifdef USE_ANIMATIONS
1240 if (!wwin
->screen_ptr
->flags
.startup
) {
1241 /* Catch up with events not processed while animation was running */
1242 Window clientwin
= wwin
->client_win
;
1244 ProcessPendingEvents();
1246 /* the window can disappear while ProcessPendingEvents() runs */
1247 if (!wWindowFor(clientwin
))
1253 /* maybe we want to do this regardless of net_handle_icon
1254 * it seems to me we might break behaviour this way.
1256 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1257 && !wwin
->flags
.net_handle_icon
)
1258 wIconSelect(wwin
->icon
);
1260 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1262 if (wPreferences
.auto_arrange_icons
)
1263 wArrangeIcons(wwin
->screen_ptr
, True
);
1266 void wDeiconifyWindow(WWindow
*wwin
)
1268 /* Let's avoid changing workspace while deiconifying */
1269 w_global
.ignore_workspace_change
= True
;
1271 /* we're hiding for show_desktop */
1272 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1273 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1276 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1278 if (!wwin
->flags
.miniaturized
) {
1279 w_global
.ignore_workspace_change
= False
;
1283 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1284 WWindow
*owner
= recursiveTransientFor(wwin
);
1286 if (owner
&& owner
->flags
.miniaturized
) {
1287 wDeiconifyWindow(owner
);
1288 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1289 wRaiseFrame(wwin
->frame
->core
);
1290 w_global
.ignore_workspace_change
= False
;
1295 wwin
->flags
.miniaturized
= 0;
1297 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1298 wwin
->flags
.mapped
= 1;
1300 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1301 /* maybe we want to do this regardless of net_handle_icon
1302 * it seems to me we might break behaviour this way.
1304 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1305 && wwin
->icon
!= NULL
) {
1306 if (wwin
->icon
->selected
)
1307 wIconSelect(wwin
->icon
);
1309 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1313 /* if the window is in another workspace, do it silently */
1314 if (!netwm_hidden
) {
1315 #ifdef USE_ANIMATIONS
1317 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1318 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1319 wwin
->frame_x
, wwin
->frame_y
,
1320 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1322 wwin
->flags
.skip_next_animation
= 0;
1324 if (!wwin
->flags
.shaded
)
1325 XMapWindow(dpy
, wwin
->client_win
);
1327 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1328 wRaiseFrame(wwin
->frame
->core
);
1329 if (!wwin
->flags
.shaded
)
1330 wClientSetState(wwin
, NormalState
, None
);
1332 mapTransientsFor(wwin
);
1335 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1336 && !wwin
->flags
.net_handle_icon
) {
1337 RemoveFromStackList(wwin
->icon
->core
);
1338 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1339 wIconDestroy(wwin
->icon
);
1343 if (!netwm_hidden
) {
1346 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1348 #ifdef USE_ANIMATIONS
1349 if (!wwin
->screen_ptr
->flags
.startup
) {
1350 /* Catch up with events not processed while animation was running */
1351 Window clientwin
= wwin
->client_win
;
1353 ProcessPendingEvents();
1355 /* the window can disappear while ProcessPendingEvents() runs */
1356 if (!wWindowFor(clientwin
)) {
1357 w_global
.ignore_workspace_change
= False
;
1364 if (wPreferences
.auto_arrange_icons
)
1365 wArrangeIcons(wwin
->screen_ptr
, True
);
1367 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1369 /* In case we were shaded and iconified, also unshade */
1371 wUnshadeWindow(wwin
);
1373 w_global
.ignore_workspace_change
= False
;
1376 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1378 if (wwin
->flags
.miniaturized
) {
1380 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1381 wwin
->icon
->mapped
= 0;
1383 wwin
->flags
.hidden
= 1;
1385 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1389 if (wwin
->flags
.inspector_open
)
1390 wHideInspectorForWindow(wwin
);
1392 wwin
->flags
.hidden
= 1;
1395 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1398 #ifdef USE_ANIMATIONS
1399 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1400 !wwin
->flags
.skip_next_animation
&& animate
) {
1401 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1402 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1403 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1406 /* Tell the compiler it is normal that those parameters are not used in this case */
1411 wwin
->flags
.skip_next_animation
= 0;
1413 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1416 void wHideAll(WScreen
*scr
)
1421 unsigned int wcount
= 0;
1427 menu
= scr
->switch_menu
;
1429 windows
= wmalloc(sizeof(WWindow
*));
1432 for (i
= 0; i
< menu
->entry_no
; i
++) {
1433 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1435 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1438 wwin
= scr
->focused_window
;
1441 windows
[wcount
] = wwin
;
1443 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1449 for (i
= 0; i
< wcount
; i
++) {
1451 if (wwin
->frame
->workspace
== scr
->current_workspace
1452 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1453 && !wwin
->flags
.internal_window
1454 && !WFLAGP(wwin
, no_miniaturizable
)
1456 wwin
->flags
.skip_next_animation
= 1;
1457 wIconifyWindow(wwin
);
1464 void wHideOtherApplications(WWindow
*awin
)
1471 wwin
= awin
->screen_ptr
->focused_window
;
1475 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1476 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1477 && !wwin
->flags
.internal_window
1478 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1480 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1481 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1482 wwin
->flags
.skip_next_animation
= 1;
1483 wIconifyWindow(wwin
);
1485 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1486 tapp
= wApplicationOf(wwin
->main_window
);
1488 tapp
->flags
.skip_next_animation
= 1;
1489 wHideApplication(tapp
);
1491 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1492 wwin
->flags
.skip_next_animation
= 1;
1493 wIconifyWindow(wwin
);
1501 wSetFocusTo(awin->screen_ptr, awin);
1505 void wHideApplication(WApplication
*wapp
)
1513 wwarning("trying to hide a non grouped window");
1516 if (!wapp
->main_window_desc
) {
1517 wwarning("group leader not found for window group");
1520 scr
= wapp
->main_window_desc
->screen_ptr
;
1522 wlist
= scr
->focused_window
;
1526 if (wlist
->main_window
== wapp
->main_window
)
1527 wapp
->last_focused
= wlist
;
1529 wapp
->last_focused
= NULL
;
1531 animate
= !wapp
->flags
.skip_next_animation
;
1534 if (wlist
->main_window
== wapp
->main_window
) {
1535 if (wlist
->flags
.focused
)
1537 if (wapp
->app_icon
) {
1538 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1539 wapp
->app_icon
->y_pos
, wlist
, animate
);
1543 wlist
= wlist
->prev
;
1546 wapp
->flags
.skip_next_animation
= 0;
1549 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1550 wlist
= scr
->focused_window
;
1552 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1553 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1555 wlist
= wlist
->prev
;
1557 wSetFocusTo(scr
, wlist
);
1559 wSetFocusTo(scr
, NULL
);
1563 wapp
->flags
.hidden
= 1;
1565 if (wPreferences
.auto_arrange_icons
)
1566 wArrangeIcons(scr
, True
);
1570 wAppIconPaint(wapp
->app_icon
);
1574 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1576 if (bringToCurrentWS
)
1577 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1579 wwin
->flags
.hidden
= 0;
1581 #ifdef USE_ANIMATIONS
1582 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1583 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1584 icon
->core
->width
, icon
->core
->height
,
1585 wwin
->frame_x
, wwin
->frame_y
,
1586 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1589 /* Tell the compiler it is normal that those parameters are not used in this case */
1595 wwin
->flags
.skip_next_animation
= 0;
1596 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1597 XMapWindow(dpy
, wwin
->client_win
);
1598 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1599 wClientSetState(wwin
, NormalState
, None
);
1600 wwin
->flags
.mapped
= 1;
1601 wRaiseFrame(wwin
->frame
->core
);
1603 if (wwin
->flags
.inspector_open
)
1604 wUnhideInspectorForWindow(wwin
);
1606 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1609 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1612 WWindow
*wlist
, *next
;
1613 WWindow
*focused
= NULL
;
1619 scr
= wapp
->main_window_desc
->screen_ptr
;
1620 wlist
= scr
->focused_window
;
1624 /* goto beginning of list */
1626 wlist
= wlist
->prev
;
1628 animate
= !wapp
->flags
.skip_next_animation
;
1633 if (wlist
->main_window
== wapp
->main_window
) {
1634 if (wlist
->flags
.focused
)
1636 else if (!focused
|| !focused
->flags
.focused
)
1639 if (wlist
->flags
.miniaturized
) {
1640 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1641 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1642 if (!wlist
->icon
->mapped
) {
1645 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1646 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1647 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1650 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1651 wlist
->icon
->mapped
= 1;
1653 wRaiseFrame(wlist
->icon
->core
);
1655 if (bringToCurrentWS
)
1656 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1657 wlist
->flags
.hidden
= 0;
1658 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1659 wDeiconifyWindow(wlist
);
1660 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1661 } else if (wlist
->flags
.shaded
) {
1662 if (bringToCurrentWS
)
1663 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1664 wlist
->flags
.hidden
= 0;
1665 wRaiseFrame(wlist
->frame
->core
);
1666 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1667 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1669 wUnshadeWindow(wlist
);
1671 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1672 } else if (wlist
->flags
.hidden
) {
1673 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1674 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1677 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1678 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1680 wRaiseFrame(wlist
->frame
->core
);
1686 wapp
->flags
.skip_next_animation
= 0;
1687 wapp
->flags
.hidden
= 0;
1689 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1690 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1691 wSetFocusTo(scr
, wapp
->last_focused
);
1692 } else if (focused
) {
1693 wSetFocusTo(scr
, focused
);
1695 wapp
->last_focused
= NULL
;
1696 if (wPreferences
.auto_arrange_icons
)
1697 wArrangeIcons(scr
, True
);
1700 wAppIconPaint(wapp
->app_icon
);
1704 void wShowAllWindows(WScreen
*scr
)
1706 WWindow
*wwin
, *old_foc
;
1709 old_foc
= wwin
= scr
->focused_window
;
1711 if (!wwin
->flags
.internal_window
&&
1712 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1713 if (wwin
->flags
.miniaturized
) {
1714 wwin
->flags
.skip_next_animation
= 1;
1715 wDeiconifyWindow(wwin
);
1716 } else if (wwin
->flags
.hidden
) {
1717 wapp
= wApplicationOf(wwin
->main_window
);
1719 wUnhideApplication(wapp
, False
, False
);
1721 wwin
->flags
.skip_next_animation
= 1;
1722 wDeiconifyWindow(wwin
);
1728 wSetFocusTo(scr
, old_foc
);
1729 /*wRaiseFrame(old_foc->frame->core); */
1732 void wRefreshDesktop(WScreen
*scr
)
1735 XSetWindowAttributes attr
;
1737 attr
.backing_store
= NotUseful
;
1738 attr
.save_under
= False
;
1739 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1740 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1741 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1742 XMapRaised(dpy
, win
);
1743 XDestroyWindow(dpy
, win
);
1747 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1753 const int heads
= wXineramaHeads(scr
);
1756 int pf
; /* primary axis */
1757 int sf
; /* secondary axis */
1761 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1767 int isize
= wPreferences
.icon_size
;
1769 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1771 for (head
= 0; head
< heads
; ++head
) {
1772 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1776 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1778 if (scr
->dock
->on_right_side
)
1784 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1786 vars
[head
].pi
= vars
[head
].si
= 0;
1787 vars
[head
].sx1
= rect
.pos
.x
;
1788 vars
[head
].sy1
= rect
.pos
.y
;
1789 vars
[head
].sw
= rect
.size
.width
;
1790 vars
[head
].sh
= rect
.size
.height
;
1791 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1792 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1793 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1794 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1795 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1796 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1798 /* icon yard boundaries */
1799 if (wPreferences
.icon_yard
& IY_VERT
) {
1800 vars
[head
].pf
= vars
[head
].fullH
;
1801 vars
[head
].sf
= vars
[head
].fullW
;
1803 vars
[head
].pf
= vars
[head
].fullW
;
1804 vars
[head
].sf
= vars
[head
].fullH
;
1806 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1807 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1810 vars
[head
].xo
= vars
[head
].sx1
;
1813 if (wPreferences
.icon_yard
& IY_TOP
) {
1814 vars
[head
].yo
= vars
[head
].sy1
;
1817 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1822 #define X ((wPreferences.icon_yard & IY_VERT) \
1823 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1824 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1826 #define Y ((wPreferences.icon_yard & IY_VERT) \
1827 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1828 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1830 /* arrange application icons */
1831 aicon
= scr
->app_icon_list
;
1832 /* reverse them to avoid unnecessarily sliding of icons */
1833 while (aicon
&& aicon
->next
)
1834 aicon
= aicon
->next
;
1837 if (!aicon
->docked
) {
1838 /* CHECK: can icon be NULL here ? */
1839 /* The intention here is to place the AppIcon on the head that
1840 * contains most of the applications _main_ window. */
1841 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1843 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1844 #ifdef USE_ANIMATIONS
1845 if (!wPreferences
.no_animations
)
1846 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1847 #endif /* USE_ANIMATIONS */
1849 wAppIconMove(aicon
, X
, Y
);
1851 if (vars
[head
].pi
>= vars
[head
].pf
) {
1856 aicon
= aicon
->prev
;
1859 /* arrange miniwindows */
1860 wwin
= scr
->focused_window
;
1861 /* reverse them to avoid unnecessarily shuffling */
1862 while (wwin
&& wwin
->prev
)
1866 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1867 (wwin
->frame
->workspace
== scr
->current_workspace
||
1868 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1870 head
= wGetHeadForWindow(wwin
);
1872 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1873 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1874 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1880 if (vars
[head
].pi
>= vars
[head
].pf
) {
1887 wwin
->flags
.icon_moved
= 0;
1888 /* we reversed the order, so we use next */
1895 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1897 WScreen
*scr
= wwin
->screen_ptr
;
1900 wwin
->flags
.selected
= 1;
1901 if (wwin
->frame
->selected_border_pixel
)
1902 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1904 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1906 if (!HAS_BORDER(wwin
))
1907 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1909 if (!scr
->selected_windows
)
1910 scr
->selected_windows
= WMCreateArray(4);
1911 WMAddToArray(scr
->selected_windows
, wwin
);
1913 wwin
->flags
.selected
= 0;
1914 if (wwin
->flags
.focused
) {
1915 if (wwin
->frame
->focused_border_pixel
)
1916 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1918 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1920 if (wwin
->frame
->border_pixel
)
1921 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1923 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1926 if (!HAS_BORDER(wwin
))
1927 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1929 if (scr
->selected_windows
)
1930 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1934 void wMakeWindowVisible(WWindow
*wwin
)
1936 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1937 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1939 if (wwin
->flags
.shaded
)
1940 wUnshadeWindow(wwin
);
1942 if (wwin
->flags
.hidden
) {
1945 app
= wApplicationOf(wwin
->main_window
);
1947 /* trick to get focus to this window */
1948 app
->last_focused
= wwin
;
1949 wUnhideApplication(app
, False
, False
);
1952 if (wwin
->flags
.miniaturized
) {
1953 wDeiconifyWindow(wwin
);
1955 if (!WFLAGP(wwin
, no_focusable
))
1956 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1957 wRaiseFrame(wwin
->frame
->core
);
1962 * Do the animation while shading (called with what = SHADE)
1963 * or unshading (what = UNSHADE).
1965 #ifdef USE_ANIMATIONS
1966 static void shade_animate(WWindow
*wwin
, Bool what
)
1969 time_t time0
= time(NULL
);
1971 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1976 if (!wwin
->screen_ptr
->flags
.startup
) {
1977 /* do the shading animation */
1978 h
= wwin
->frame
->core
->height
;
1979 s
= h
/ SHADE_STEPS
;
1982 w
= wwin
->frame
->core
->width
;
1983 y
= wwin
->frame
->top_width
;
1984 while (h
> wwin
->frame
->top_width
+ 1) {
1985 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1986 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1989 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1992 if (SHADE_DELAY
> 0)
1993 wusleep(SHADE_DELAY
* 1000L);
1999 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2004 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2005 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2006 s
= abs(y
) / SHADE_STEPS
;
2009 w
= wwin
->frame
->core
->width
;
2010 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2012 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2013 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2014 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2016 if (SHADE_DELAY
> 0)
2017 wusleep(SHADE_DELAY
* 2000L / 3);
2023 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2027 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);