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 *******/
64 { SHADE_STEPS_UF
, SHADE_DELAY_UF
},
65 { SHADE_STEPS_F
, SHADE_DELAY_F
},
66 { SHADE_STEPS_M
, SHADE_DELAY_M
},
67 { SHADE_STEPS_S
, SHADE_DELAY_S
},
68 { SHADE_STEPS_US
, SHADE_DELAY_US
}
73 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
74 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
76 static int compareTimes(Time t1
, Time t2
)
82 return (diff
< 60000) ? 1 : -1;
86 static void shade_animate(WWindow
*wwin
, Bool what
);
88 static inline void shade_animate(WWindow
*wwin
, Bool what
)
91 * This function is empty on purpose, so tell the compiler
92 * to not warn about parameters being not used
100 *----------------------------------------------------------------------
102 * Changes the window focus to the one passed as argument.
103 * If the window to focus is not already focused, it will be brought
104 * to the head of the list of windows. Previously focused window is
108 * Window list may be reordered and the window focus is changed.
110 *----------------------------------------------------------------------
112 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
114 static WScreen
*old_scr
= NULL
;
116 WWindow
*old_focused
;
117 WWindow
*focused
= scr
->focused_window
;
118 Time timestamp
= w_global
.timestamp
.last_event
;
119 WApplication
*oapp
= NULL
, *napp
= NULL
;
122 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
128 old_focused
= old_scr
->focused_window
;
130 w_global
.timestamp
.focus_change
= timestamp
;
133 oapp
= wApplicationOf(old_focused
->main_window
);
136 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
138 wWindowUnfocus(old_focused
);
141 wAppMenuUnmap(oapp
->menu
);
142 if (wPreferences
.highlight_active_app
)
143 wApplicationDeactivate(oapp
);
146 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
150 if (old_scr
!= scr
&& old_focused
)
151 wWindowUnfocus(old_focused
);
153 wasfocused
= wwin
->flags
.focused
;
154 napp
= wApplicationOf(wwin
->main_window
);
156 /* remember last workspace where the app has been */
158 napp
->last_workspace
= wwin
->frame
->workspace
;
160 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
161 /* install colormap if colormap mode is lock mode */
162 if (wPreferences
.colormap_mode
== WCM_CLICK
)
163 wColormapInstallForWindow(scr
, wwin
);
165 /* set input focus */
166 switch (wwin
->focus_mode
) {
168 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
171 case WFM_LOCALLY_ACTIVE
:
172 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
174 case WFM_GLOBALLY_ACTIVE
:
179 if (wwin
->protocols
.TAKE_FOCUS
)
180 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
184 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
187 if (WFLAGP(wwin
, no_focusable
))
190 /* if this is not the focused window focus it */
191 if (focused
!= wwin
) {
192 /* change the focus window list order */
194 wwin
->prev
->next
= wwin
->next
;
197 wwin
->next
->prev
= wwin
->prev
;
199 wwin
->prev
= focused
;
200 focused
->next
= wwin
;
202 scr
->focused_window
= wwin
;
204 if (oapp
&& oapp
!= napp
) {
205 wAppMenuUnmap(oapp
->menu
);
206 if (wPreferences
.highlight_active_app
)
207 wApplicationDeactivate(oapp
);
211 wWindowFocus(wwin
, focused
);
213 if (napp
&& !wasfocused
) {
215 wUserMenuRefreshInstances(napp
->menu
, wwin
);
216 #endif /* USER_MENU */
218 if (wwin
->flags
.mapped
)
219 wAppMenuMap(napp
->menu
, wwin
);
221 if (napp
&& wPreferences
.highlight_active_app
)
222 wApplicationActivate(napp
);
228 void wShadeWindow(WWindow
*wwin
)
231 if (wwin
->flags
.shaded
)
234 XLowerWindow(dpy
, wwin
->client_win
);
235 shade_animate(wwin
, SHADE
);
237 wwin
->flags
.skip_next_animation
= 0;
238 wwin
->flags
.shaded
= 1;
239 wwin
->flags
.mapped
= 0;
240 /* prevent window withdrawal when getting UnmapNotify */
241 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
242 XUnmapWindow(dpy
, wwin
->client_win
);
243 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
245 /* for the client it's just like iconification */
246 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
248 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
249 wWindowSynthConfigureNotify(wwin
);
252 wClientSetState(wwin, IconicState, None);
255 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
258 if (!wwin
->screen_ptr
->flags
.startup
) {
259 /* Catch up with events not processed while animation was running */
260 ProcessPendingEvents();
265 void wUnshadeWindow(WWindow
*wwin
)
268 if (!wwin
->flags
.shaded
)
271 wwin
->flags
.shaded
= 0;
272 wwin
->flags
.mapped
= 1;
273 XMapWindow(dpy
, wwin
->client_win
);
275 shade_animate(wwin
, UNSHADE
);
277 wwin
->flags
.skip_next_animation
= 0;
278 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
279 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
281 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
282 wWindowSynthConfigureNotify(wwin
);
284 /* if the window is focused, set the focus again as it was disabled during
286 if (wwin
->flags
.focused
)
287 wSetFocusTo(wwin
->screen_ptr
, wwin
);
289 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
292 /* Set the old coordinates using the current values */
293 static void save_old_geometry(WWindow
*wwin
, int directions
)
295 /* never been saved? */
296 if (!wwin
->old_geometry
.width
)
297 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
298 if (!wwin
->old_geometry
.height
)
299 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
301 if (directions
& SAVE_GEOMETRY_X
)
302 wwin
->old_geometry
.x
= wwin
->frame_x
;
303 if (directions
& SAVE_GEOMETRY_Y
)
304 wwin
->old_geometry
.y
= wwin
->frame_y
;
305 if (directions
& SAVE_GEOMETRY_WIDTH
)
306 wwin
->old_geometry
.width
= wwin
->client
.width
;
307 if (directions
& SAVE_GEOMETRY_HEIGHT
)
308 wwin
->old_geometry
.height
= wwin
->client
.height
;
311 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
313 WMRect old_geom_rect
;
317 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
318 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
319 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
320 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
321 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
322 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
323 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
326 /* Remember geometry for unmaximizing */
327 void update_saved_geometry(WWindow
*wwin
)
329 /* NOT if we aren't already maximized
330 * we'll save geometry when maximizing */
331 if (!wwin
->flags
.maximized
)
334 /* NOT if we are fully maximized */
335 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
336 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
337 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
340 /* save the co-ordinate in the axis in which we AREN'T maximized */
341 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
342 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
343 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
344 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
347 void wMaximizeWindow(WWindow
*wwin
, int directions
)
349 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
354 unsigned int maximus_width
= 0;
355 unsigned int maximus_height
= 0;
356 WArea usableArea
, totalArea
;
359 WScreen
*scr
= wwin
->screen_ptr
;
361 if (!IS_RESIZABLE(wwin
))
364 if (!HAS_BORDER(wwin
))
367 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
368 wwin
->client_flags
.no_movable
= 1;
370 /* the size to adjust the geometry */
371 adj_size
= scr
->frame_border_width
* 2 * has_border
;
373 /* save old coordinates before we change the current values */
374 if (!wwin
->flags
.maximized
)
375 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
377 totalArea
.x2
= scr
->scr_width
;
378 totalArea
.y2
= scr
->scr_height
;
381 usableArea
= totalArea
;
383 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
384 WScreen
*scr
= wwin
->screen_ptr
;
387 if (directions
& MAX_KEYBOARD
)
388 head
= wGetHeadForWindow(wwin
);
390 head
= wGetHeadForPointerLocation(scr
);
392 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
396 /* Only save directions, not kbd or xinerama hints */
397 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
399 if (WFLAGP(wwin
, full_maximize
))
400 usableArea
= totalArea
;
401 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
402 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
404 if (wwin
->flags
.shaded
) {
405 wwin
->flags
.skip_next_animation
= 1;
406 wUnshadeWindow(wwin
);
409 if (directions
& MAX_MAXIMUS
) {
410 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
411 new_width
= maximus_width
- adj_size
;
412 new_height
= maximus_height
- adj_size
;
415 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
416 new_height
+= wwin
->frame
->bottom_width
- 1;
417 new_y
-= wwin
->frame
->top_width
;
420 wwin
->maximus_x
= new_x
;
421 wwin
->maximus_y
= new_y
;
422 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
424 /* set default values if no option set then */
425 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
426 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
427 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
429 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
430 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
431 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
434 /* left|right position */
435 if (directions
& MAX_LEFTHALF
) {
436 new_width
= half_scr_width
- adj_size
;
437 new_x
= usableArea
.x1
;
438 } else if (directions
& MAX_RIGHTHALF
) {
439 new_width
= half_scr_width
- adj_size
;
440 new_x
= usableArea
.x1
+ half_scr_width
;
442 /* top|bottom position */
443 if (directions
& MAX_TOPHALF
) {
444 new_height
= half_scr_height
- adj_size
;
445 new_y
= usableArea
.y1
;
446 } else if (directions
& MAX_BOTTOMHALF
) {
447 new_height
= half_scr_height
- adj_size
;
448 new_y
= usableArea
.y1
+ half_scr_height
;
451 /* vertical|horizontal position */
452 if (directions
& MAX_HORIZONTAL
) {
453 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
454 new_x
= usableArea
.x1
;
456 if (directions
& MAX_VERTICAL
) {
457 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
458 new_y
= usableArea
.y1
;
459 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
460 new_y
-= wwin
->frame
->top_width
;
464 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
465 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
467 /* set maximization state */
468 wwin
->flags
.maximized
= directions
;
469 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
470 wwin
->flags
.maximized
= MAX_MAXIMUS
;
472 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
474 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
475 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
477 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
478 wWindowSynthConfigureNotify(wwin
);
480 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
483 /* generic (un)maximizer */
484 void handleMaximize(WWindow
*wwin
, int directions
)
486 int current
= wwin
->flags
.maximized
;
487 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
488 int effective
= requested
^ current
;
489 int flags
= directions
& ~requested
;
492 /* allow wMaximizeWindow to restore the Maximusized size */
493 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
494 !(requested
& MAX_MAXIMUS
))
495 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
497 wUnmaximizeWindow(wwin
);
498 /* these alone mean vertical|horizontal toggle */
499 } else if ((effective
== MAX_LEFTHALF
) ||
500 (effective
== MAX_RIGHTHALF
) ||
501 (effective
== MAX_TOPHALF
) ||
502 (effective
== MAX_BOTTOMHALF
))
503 wUnmaximizeWindow(wwin
);
505 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
506 (requested
== MAX_MAXIMUS
))
507 effective
= requested
;
509 if (requested
& MAX_LEFTHALF
) {
510 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
511 effective
|= MAX_VERTICAL
;
513 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
514 effective
|= MAX_LEFTHALF
;
515 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
516 } else if (requested
& MAX_RIGHTHALF
) {
517 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
518 effective
|= MAX_VERTICAL
;
520 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
521 effective
|= MAX_RIGHTHALF
;
522 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
524 if (requested
& MAX_TOPHALF
) {
525 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
526 effective
|= MAX_HORIZONTAL
;
528 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
529 effective
|= MAX_TOPHALF
;
530 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
531 } else if (requested
& MAX_BOTTOMHALF
) {
532 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
533 effective
|= MAX_HORIZONTAL
;
535 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
536 effective
|= MAX_BOTTOMHALF
;
537 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
539 if (requested
& MAX_HORIZONTAL
)
540 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
541 if (requested
& MAX_VERTICAL
)
542 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
543 effective
&= ~MAX_MAXIMUS
;
545 wMaximizeWindow(wwin
, effective
| flags
);
549 /* the window boundary coordinates */
559 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
561 obs
->left
= wwin
->frame_x
;
562 obs
->top
= wwin
->frame_y
;
563 obs
->width
= wwin
->frame
->core
->width
;
564 obs
->height
= wwin
->frame
->core
->height
;
565 obs
->bottom
= obs
->top
+ obs
->height
;
566 obs
->right
= obs
->left
+ obs
->width
;
570 * Maximus: tiled maximization (maximize without overlapping other windows)
572 * The original window 'orig' will be maximized to new coordinates 'new'.
573 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
575 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
576 unsigned int *new_width
, unsigned int *new_height
)
579 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
580 short int adjust_height
;
581 int x_intsect
, y_intsect
;
582 /* the obstructing, original and new windows */
583 win_coords obs
, orig
, new;
585 /* set the original coordinate positions of the window to be Maximumized */
586 if (wwin
->flags
.maximized
) {
587 /* window is already maximized; consider original geometry */
588 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
589 orig
.bottom
= orig
.top
+ orig
.height
;
590 orig
.right
= orig
.left
+ orig
.width
;
592 set_window_coords(wwin
, &orig
);
594 /* Try to fully maximize first, then readjust later */
595 new.left
= usableArea
.x1
;
596 new.right
= usableArea
.x2
;
597 new.top
= usableArea
.y1
;
598 new.bottom
= usableArea
.y2
;
600 if (HAS_TITLEBAR(wwin
))
601 tbar_height_0
= TITLEBAR_HEIGHT
;
602 if (HAS_RESIZEBAR(wwin
))
603 rbar_height_0
= RESIZEBAR_HEIGHT
;
604 if (HAS_BORDER(wwin
))
605 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
607 /* the length to be subtracted if the window has titlebar, etc */
608 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
611 /* The focused window is always the last in the list */
613 /* ignore windows in other workspaces etc */
614 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
615 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
621 /* Set the coordinates of obstructing window */
622 set_window_coords(tmp
, &obs
);
624 /* Try to maximize in the y direction first */
625 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
626 if (x_intsect
!= 0) {
627 /* TODO: Consider the case when coords are equal */
628 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
629 /* w_0 is below the bottom of w_j */
630 new.top
= obs
.bottom
+ 1;
632 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
633 /* The bottom of w_0 is above the top of w_j */
634 new.bottom
= obs
.top
- 1;
641 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
642 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
648 set_window_coords(tmp
, &obs
);
651 * Use the new.top and new.height instead of original values
652 * as they may have different intersections with the obstructing windows
654 new.height
= new.bottom
- new.top
- adjust_height
;
655 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
656 if (y_intsect
!= 0) {
657 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
658 /* w_0 is completely to the right of w_j */
659 new.left
= obs
.right
+ 1;
661 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
662 /* w_0 is completely to the left of w_j */
663 new.right
= obs
.left
- 1;
670 /* xcalc needs -7 here, but other apps don't */
671 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
672 *new_width
= new.right
- new.left
;
675 void wUnmaximizeWindow(WWindow
*wwin
)
679 if (!wwin
->flags
.maximized
)
682 if (wwin
->flags
.shaded
) {
683 wwin
->flags
.skip_next_animation
= 1;
684 wUnshadeWindow(wwin
);
687 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
688 wwin
->client_flags
.no_movable
= 0;
690 /* Use old coordinates if they are set, current values otherwise */
691 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
693 /* unMaximusize relative to original position */
694 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
695 x
+= wwin
->frame_x
- wwin
->maximus_x
;
696 y
+= wwin
->frame_y
- wwin
->maximus_y
;
699 wwin
->flags
.maximized
= 0;
700 wwin
->flags
.old_maximized
= 0;
701 wWindowConfigure(wwin
, x
, y
, w
, h
);
702 wWindowSynthConfigureNotify(wwin
);
704 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
707 void wFullscreenWindow(WWindow
*wwin
)
712 if (wwin
->flags
.fullscreen
)
715 wwin
->flags
.fullscreen
= True
;
717 wWindowConfigureBorders(wwin
);
719 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
720 wRaiseFrame(wwin
->frame
->core
);
722 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
723 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
724 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
725 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
727 head
= wGetHeadForWindow(wwin
);
728 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
729 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
731 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
732 wSetFocusTo(wwin
->screen_ptr
, wwin
);
734 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
737 void wUnfullscreenWindow(WWindow
*wwin
)
739 if (!wwin
->flags
.fullscreen
)
742 wwin
->flags
.fullscreen
= False
;
744 if (WFLAGP(wwin
, sunken
))
745 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
746 else if (WFLAGP(wwin
, floating
))
747 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
749 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
750 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
752 wWindowConfigureBorders(wwin
);
754 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
755 wFrameWindowPaint(wwin->frame);
758 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
760 if (wwin
->screen_ptr
->bfs_focused_window
) {
761 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
762 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
767 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
769 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
770 float cx
, cy
, cw
, ch
;
771 float xstep
, ystep
, wstep
, hstep
;
774 float angle
, final_angle
, delta
;
776 xstep
= (float)(fx
- x
) / steps
;
777 ystep
= (float)(fy
- y
) / steps
;
778 wstep
= (float)(fw
- w
) / steps
;
779 hstep
= (float)(fh
- h
) / steps
;
786 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
787 delta
= (float)(final_angle
/ FRAMES
);
788 for (angle
= 0;; angle
+= delta
) {
789 if (angle
> final_angle
)
792 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
793 dch
= (ch
/ 2) * cos(angle
);
794 midy
= cy
+ (ch
/ 2);
796 points
[0].x
= cx
+ dx
;
797 points
[0].y
= midy
- dch
;
798 points
[1].x
= cx
+ cw
- dx
;
799 points
[1].y
= points
[0].y
;
800 points
[2].x
= cx
+ cw
+ dx
;
801 points
[2].y
= midy
+ dch
;
802 points
[3].x
= cx
- dx
;
803 points
[3].y
= points
[2].y
;
804 points
[4].x
= points
[0].x
;
805 points
[4].y
= points
[0].y
;
808 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
810 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
812 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
818 if (angle
>= final_angle
)
828 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
830 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
831 float cx
, cy
, cw
, ch
;
832 float xstep
, ystep
, wstep
, hstep
;
834 float angle
, final_angle
, a
, d
, delta
;
841 xstep
= (float)(fx
- x
) / steps
;
842 ystep
= (float)(fy
- y
) / steps
;
843 wstep
= (float)(fw
- w
) / steps
;
844 hstep
= (float)(fh
- h
) / steps
;
851 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
852 delta
= (float)(final_angle
/ FRAMES
);
853 for (angle
= 0;; angle
+= delta
) {
854 if (angle
> final_angle
)
858 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
860 points
[0].x
= cx
+ cos(angle
- a
) * d
;
861 points
[0].y
= cy
+ sin(angle
- a
) * d
;
862 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
863 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
864 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
865 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
866 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
867 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
868 points
[4].x
= cx
+ cos(angle
- a
) * d
;
869 points
[4].y
= cy
+ sin(angle
- a
) * d
;
871 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
873 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
875 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
881 if (angle
>= final_angle
)
890 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
892 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
893 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
894 float xstep
, ystep
, wstep
, hstep
;
897 xstep
= (float)(fx
- x
) / steps
;
898 ystep
= (float)(fy
- y
) / steps
;
899 wstep
= (float)(fw
- w
) / steps
;
900 hstep
= (float)(fh
- h
) / steps
;
902 for (j
= 0; j
< FRAMES
; j
++) {
909 for (i
= 0; i
< steps
; i
++) {
910 for (j
= 0; j
< FRAMES
; j
++) {
911 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
912 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
915 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
917 for (j
= 0; j
< FRAMES
; j
++) {
918 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
919 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
920 if (j
< FRAMES
- 1) {
934 for (j
= 0; j
< FRAMES
; j
++)
935 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
937 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
939 for (j
= 0; j
< FRAMES
; j
++)
940 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
947 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
949 int style
= wPreferences
.iconification_style
; /* Catch the value */
952 if (style
== WIS_NONE
)
955 if (style
== WIS_RANDOM
)
960 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
962 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
965 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
967 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
971 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
973 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
977 #endif /* ANIMATIONS */
979 static void flushExpose(void)
983 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
984 WMHandleEvent(&tmpev
);
988 static void unmapTransientsFor(WWindow
*wwin
)
992 tmp
= wwin
->screen_ptr
->focused_window
;
994 /* unmap the transients for this transient */
995 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
996 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
997 unmapTransientsFor(tmp
);
998 tmp
->flags
.miniaturized
= 1;
999 if (!tmp
->flags
.shaded
)
1002 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1004 if (!tmp->flags.shaded)
1006 wClientSetState(tmp
, IconicState
, None
);
1008 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1014 static void mapTransientsFor(WWindow
*wwin
)
1018 tmp
= wwin
->screen_ptr
->focused_window
;
1020 /* recursively map the transients for this transient */
1021 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1022 && tmp
->icon
== NULL
) {
1023 mapTransientsFor(tmp
);
1024 tmp
->flags
.miniaturized
= 0;
1025 if (!tmp
->flags
.shaded
)
1028 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1029 tmp
->flags
.semi_focused
= 0;
1031 if (!tmp->flags.shaded)
1033 wClientSetState(tmp
, NormalState
, None
);
1035 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1041 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1048 /* hackish way to detect transient_for cycle */
1049 i
= wwin
->screen_ptr
->window_count
+ 1;
1051 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1052 wwin
= wWindowFor(wwin
->transient_for
);
1055 if (i
== 0 && wwin
) {
1056 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1063 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1065 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1066 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1069 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1072 *iw
= wwin
->icon
->core
->width
;
1073 *ih
= wwin
->icon
->core
->height
;
1075 if (wwin
->flags
.net_handle_icon
) {
1083 *iw
= wwin
->screen_ptr
->scr_width
;
1084 *ih
= wwin
->screen_ptr
->scr_height
;
1090 void wIconifyWindow(WWindow
*wwin
)
1092 XWindowAttributes attribs
;
1095 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1096 return; /* the window doesn't exist anymore */
1098 if (wwin
->flags
.miniaturized
)
1099 return; /* already miniaturized */
1101 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1102 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1104 if (owner
&& owner
->flags
.miniaturized
)
1108 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1110 /* if the window is in another workspace, simplify process */
1112 /* icon creation may take a while */
1113 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1114 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1115 GrabModeAsync
, None
, None
, CurrentTime
);
1118 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1119 if (!wwin
->flags
.icon_moved
)
1120 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1122 wwin
->icon
= icon_create_for_wwindow(wwin
);
1123 wwin
->icon
->mapped
= 1;
1125 /* extract the window screenshot everytime, as the option can be enable anytime */
1126 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1127 RImage
*mini_preview
;
1133 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1134 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1139 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1140 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1142 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1143 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1145 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1147 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1148 XDestroyImage(pimg
);
1151 set_icon_minipreview(wwin
->icon
, mini_preview
);
1152 RReleaseImage(mini_preview
);
1154 wwarning(_("window mini-preview creation failed"));
1160 wwin
->flags
.miniaturized
= 1;
1161 wwin
->flags
.mapped
= 0;
1163 /* unmap transients */
1164 unmapTransientsFor(wwin
);
1170 XUngrabPointer(dpy
, CurrentTime
);
1172 /* let all Expose events arrive so that we can repaint
1173 * something before the animation starts (and the server is grabbed) */
1176 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1177 wClientSetState(wwin
, IconicState
, None
);
1179 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1183 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1184 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1185 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1189 wwin
->flags
.skip_next_animation
= 0;
1191 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1192 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1193 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1194 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1196 AddToStackList(wwin
->icon
->core
);
1197 wLowerFrame(wwin
->icon
->core
);
1201 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1204 * It doesn't seem to be working and causes button event hangup
1205 * when deiconifying a transient window.
1206 setupIconGrabs(wwin->icon);
1208 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1209 && wPreferences
.focus_mode
== WKF_CLICK
) {
1214 if (!WFLAGP(tmp
, no_focusable
)
1215 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1216 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1220 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1221 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1222 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1225 if (!wwin
->screen_ptr
->flags
.startup
) {
1226 /* Catch up with events not processed while animation was running */
1227 Window clientwin
= wwin
->client_win
;
1229 ProcessPendingEvents();
1231 /* the window can disappear while ProcessPendingEvents() runs */
1232 if (!wWindowFor(clientwin
))
1238 /* maybe we want to do this regardless of net_handle_icon
1239 * it seems to me we might break behaviour this way.
1241 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1242 && !wwin
->flags
.net_handle_icon
)
1243 wIconSelect(wwin
->icon
);
1245 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1247 if (wPreferences
.auto_arrange_icons
)
1248 wArrangeIcons(wwin
->screen_ptr
, True
);
1251 void wDeiconifyWindow(WWindow
*wwin
)
1253 /* Let's avoid changing workspace while deiconifying */
1254 w_global
.ignore_workspace_change
= True
;
1256 /* we're hiding for show_desktop */
1257 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1258 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1261 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1263 if (!wwin
->flags
.miniaturized
) {
1264 w_global
.ignore_workspace_change
= False
;
1268 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1269 WWindow
*owner
= recursiveTransientFor(wwin
);
1271 if (owner
&& owner
->flags
.miniaturized
) {
1272 wDeiconifyWindow(owner
);
1273 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1274 wRaiseFrame(wwin
->frame
->core
);
1275 w_global
.ignore_workspace_change
= False
;
1280 wwin
->flags
.miniaturized
= 0;
1282 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1283 wwin
->flags
.mapped
= 1;
1285 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1286 /* maybe we want to do this regardless of net_handle_icon
1287 * it seems to me we might break behaviour this way.
1289 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1290 && wwin
->icon
!= NULL
) {
1291 if (wwin
->icon
->selected
)
1292 wIconSelect(wwin
->icon
);
1294 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1298 /* if the window is in another workspace, do it silently */
1299 if (!netwm_hidden
) {
1302 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1303 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1304 wwin
->frame_x
, wwin
->frame_y
,
1305 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1307 wwin
->flags
.skip_next_animation
= 0;
1309 if (!wwin
->flags
.shaded
)
1310 XMapWindow(dpy
, wwin
->client_win
);
1312 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1313 wRaiseFrame(wwin
->frame
->core
);
1314 if (!wwin
->flags
.shaded
)
1315 wClientSetState(wwin
, NormalState
, None
);
1317 mapTransientsFor(wwin
);
1320 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1321 && !wwin
->flags
.net_handle_icon
) {
1322 RemoveFromStackList(wwin
->icon
->core
);
1323 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1324 wIconDestroy(wwin
->icon
);
1328 if (!netwm_hidden
) {
1331 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1334 if (!wwin
->screen_ptr
->flags
.startup
) {
1335 /* Catch up with events not processed while animation was running */
1336 Window clientwin
= wwin
->client_win
;
1338 ProcessPendingEvents();
1340 /* the window can disappear while ProcessPendingEvents() runs */
1341 if (!wWindowFor(clientwin
)) {
1342 w_global
.ignore_workspace_change
= False
;
1349 if (wPreferences
.auto_arrange_icons
)
1350 wArrangeIcons(wwin
->screen_ptr
, True
);
1352 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1354 /* In case we were shaded and iconified, also unshade */
1356 wUnshadeWindow(wwin
);
1358 w_global
.ignore_workspace_change
= False
;
1361 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1363 if (wwin
->flags
.miniaturized
) {
1365 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1366 wwin
->icon
->mapped
= 0;
1368 wwin
->flags
.hidden
= 1;
1370 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1374 if (wwin
->flags
.inspector_open
)
1375 wHideInspectorForWindow(wwin
);
1377 wwin
->flags
.hidden
= 1;
1380 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1384 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1385 !wwin
->flags
.skip_next_animation
&& animate
) {
1386 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1387 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1388 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1391 wwin
->flags
.skip_next_animation
= 0;
1393 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1396 void wHideAll(WScreen
*scr
)
1401 unsigned int wcount
= 0;
1407 menu
= scr
->switch_menu
;
1409 windows
= wmalloc(sizeof(WWindow
*));
1412 for (i
= 0; i
< menu
->entry_no
; i
++) {
1413 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1415 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1418 wwin
= scr
->focused_window
;
1421 windows
[wcount
] = wwin
;
1423 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1429 for (i
= 0; i
< wcount
; i
++) {
1431 if (wwin
->frame
->workspace
== scr
->current_workspace
1432 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1433 && !wwin
->flags
.internal_window
1434 && !WFLAGP(wwin
, no_miniaturizable
)
1436 wwin
->flags
.skip_next_animation
= 1;
1437 wIconifyWindow(wwin
);
1444 void wHideOtherApplications(WWindow
*awin
)
1451 wwin
= awin
->screen_ptr
->focused_window
;
1455 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1456 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1457 && !wwin
->flags
.internal_window
1458 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1460 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1461 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1462 wwin
->flags
.skip_next_animation
= 1;
1463 wIconifyWindow(wwin
);
1465 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1466 tapp
= wApplicationOf(wwin
->main_window
);
1468 tapp
->flags
.skip_next_animation
= 1;
1469 wHideApplication(tapp
);
1471 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1472 wwin
->flags
.skip_next_animation
= 1;
1473 wIconifyWindow(wwin
);
1481 wSetFocusTo(awin->screen_ptr, awin);
1485 void wHideApplication(WApplication
*wapp
)
1493 wwarning("trying to hide a non grouped window");
1496 if (!wapp
->main_window_desc
) {
1497 wwarning("group leader not found for window group");
1500 scr
= wapp
->main_window_desc
->screen_ptr
;
1502 wlist
= scr
->focused_window
;
1506 if (wlist
->main_window
== wapp
->main_window
)
1507 wapp
->last_focused
= wlist
;
1509 wapp
->last_focused
= NULL
;
1511 animate
= !wapp
->flags
.skip_next_animation
;
1514 if (wlist
->main_window
== wapp
->main_window
) {
1515 if (wlist
->flags
.focused
)
1517 if (wapp
->app_icon
) {
1518 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1519 wapp
->app_icon
->y_pos
, wlist
, animate
);
1523 wlist
= wlist
->prev
;
1526 wapp
->flags
.skip_next_animation
= 0;
1529 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1530 wlist
= scr
->focused_window
;
1532 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1533 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1535 wlist
= wlist
->prev
;
1537 wSetFocusTo(scr
, wlist
);
1539 wSetFocusTo(scr
, NULL
);
1543 wapp
->flags
.hidden
= 1;
1545 if (wPreferences
.auto_arrange_icons
)
1546 wArrangeIcons(scr
, True
);
1550 wAppIconPaint(wapp
->app_icon
);
1554 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1556 if (bringToCurrentWS
)
1557 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1559 wwin
->flags
.hidden
= 0;
1562 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1563 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1564 icon
->core
->width
, icon
->core
->height
,
1565 wwin
->frame_x
, wwin
->frame_y
,
1566 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1569 wwin
->flags
.skip_next_animation
= 0;
1570 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1571 XMapWindow(dpy
, wwin
->client_win
);
1572 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1573 wClientSetState(wwin
, NormalState
, None
);
1574 wwin
->flags
.mapped
= 1;
1575 wRaiseFrame(wwin
->frame
->core
);
1577 if (wwin
->flags
.inspector_open
)
1578 wUnhideInspectorForWindow(wwin
);
1580 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1583 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1586 WWindow
*wlist
, *next
;
1587 WWindow
*focused
= NULL
;
1593 scr
= wapp
->main_window_desc
->screen_ptr
;
1594 wlist
= scr
->focused_window
;
1598 /* goto beginning of list */
1600 wlist
= wlist
->prev
;
1602 animate
= !wapp
->flags
.skip_next_animation
;
1607 if (wlist
->main_window
== wapp
->main_window
) {
1608 if (wlist
->flags
.focused
)
1610 else if (!focused
|| !focused
->flags
.focused
)
1613 if (wlist
->flags
.miniaturized
) {
1614 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1615 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1616 if (!wlist
->icon
->mapped
) {
1619 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1620 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1621 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1624 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1625 wlist
->icon
->mapped
= 1;
1627 wRaiseFrame(wlist
->icon
->core
);
1629 if (bringToCurrentWS
)
1630 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1631 wlist
->flags
.hidden
= 0;
1632 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1633 wDeiconifyWindow(wlist
);
1634 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1635 } else if (wlist
->flags
.shaded
) {
1636 if (bringToCurrentWS
)
1637 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1638 wlist
->flags
.hidden
= 0;
1639 wRaiseFrame(wlist
->frame
->core
);
1640 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1641 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1643 wUnshadeWindow(wlist
);
1645 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1646 } else if (wlist
->flags
.hidden
) {
1647 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1648 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1651 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1652 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1654 wRaiseFrame(wlist
->frame
->core
);
1660 wapp
->flags
.skip_next_animation
= 0;
1661 wapp
->flags
.hidden
= 0;
1663 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1664 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1665 wSetFocusTo(scr
, wapp
->last_focused
);
1666 } else if (focused
) {
1667 wSetFocusTo(scr
, focused
);
1669 wapp
->last_focused
= NULL
;
1670 if (wPreferences
.auto_arrange_icons
)
1671 wArrangeIcons(scr
, True
);
1674 wAppIconPaint(wapp
->app_icon
);
1678 void wShowAllWindows(WScreen
*scr
)
1680 WWindow
*wwin
, *old_foc
;
1683 old_foc
= wwin
= scr
->focused_window
;
1685 if (!wwin
->flags
.internal_window
&&
1686 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1687 if (wwin
->flags
.miniaturized
) {
1688 wwin
->flags
.skip_next_animation
= 1;
1689 wDeiconifyWindow(wwin
);
1690 } else if (wwin
->flags
.hidden
) {
1691 wapp
= wApplicationOf(wwin
->main_window
);
1693 wUnhideApplication(wapp
, False
, False
);
1695 wwin
->flags
.skip_next_animation
= 1;
1696 wDeiconifyWindow(wwin
);
1702 wSetFocusTo(scr
, old_foc
);
1703 /*wRaiseFrame(old_foc->frame->core); */
1706 void wRefreshDesktop(WScreen
*scr
)
1709 XSetWindowAttributes attr
;
1711 attr
.backing_store
= NotUseful
;
1712 attr
.save_under
= False
;
1713 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1714 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1715 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1716 XMapRaised(dpy
, win
);
1717 XDestroyWindow(dpy
, win
);
1721 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1727 const int heads
= wXineramaHeads(scr
);
1730 int pf
; /* primary axis */
1731 int sf
; /* secondary axis */
1735 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1741 int isize
= wPreferences
.icon_size
;
1743 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1745 for (head
= 0; head
< heads
; ++head
) {
1746 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1750 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1752 if (scr
->dock
->on_right_side
)
1758 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1760 vars
[head
].pi
= vars
[head
].si
= 0;
1761 vars
[head
].sx1
= rect
.pos
.x
;
1762 vars
[head
].sy1
= rect
.pos
.y
;
1763 vars
[head
].sw
= rect
.size
.width
;
1764 vars
[head
].sh
= rect
.size
.height
;
1765 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1766 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1767 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1768 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1769 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1770 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1772 /* icon yard boundaries */
1773 if (wPreferences
.icon_yard
& IY_VERT
) {
1774 vars
[head
].pf
= vars
[head
].fullH
;
1775 vars
[head
].sf
= vars
[head
].fullW
;
1777 vars
[head
].pf
= vars
[head
].fullW
;
1778 vars
[head
].sf
= vars
[head
].fullH
;
1780 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1781 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1784 vars
[head
].xo
= vars
[head
].sx1
;
1787 if (wPreferences
.icon_yard
& IY_TOP
) {
1788 vars
[head
].yo
= vars
[head
].sy1
;
1791 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1796 #define X ((wPreferences.icon_yard & IY_VERT) \
1797 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1798 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1800 #define Y ((wPreferences.icon_yard & IY_VERT) \
1801 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1802 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1804 /* arrange application icons */
1805 aicon
= scr
->app_icon_list
;
1806 /* reverse them to avoid unnecessarily sliding of icons */
1807 while (aicon
&& aicon
->next
)
1808 aicon
= aicon
->next
;
1811 if (!aicon
->docked
) {
1812 /* CHECK: can icon be NULL here ? */
1813 /* The intention here is to place the AppIcon on the head that
1814 * contains most of the applications _main_ window. */
1815 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1817 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1819 if (!wPreferences
.no_animations
)
1820 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1821 #endif /* ANIMATIONS */
1823 wAppIconMove(aicon
, X
, Y
);
1825 if (vars
[head
].pi
>= vars
[head
].pf
) {
1830 aicon
= aicon
->prev
;
1833 /* arrange miniwindows */
1834 wwin
= scr
->focused_window
;
1835 /* reverse them to avoid unnecessarily shuffling */
1836 while (wwin
&& wwin
->prev
)
1840 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1841 (wwin
->frame
->workspace
== scr
->current_workspace
||
1842 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1844 head
= wGetHeadForWindow(wwin
);
1846 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1847 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1848 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1854 if (vars
[head
].pi
>= vars
[head
].pf
) {
1861 wwin
->flags
.icon_moved
= 0;
1862 /* we reversed the order, so we use next */
1869 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1871 WScreen
*scr
= wwin
->screen_ptr
;
1874 wwin
->flags
.selected
= 1;
1875 if (wwin
->frame
->selected_border_pixel
)
1876 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1878 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1880 if (!HAS_BORDER(wwin
))
1881 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1883 if (!scr
->selected_windows
)
1884 scr
->selected_windows
= WMCreateArray(4);
1885 WMAddToArray(scr
->selected_windows
, wwin
);
1887 wwin
->flags
.selected
= 0;
1888 if (wwin
->flags
.focused
) {
1889 if (wwin
->frame
->focused_border_pixel
)
1890 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1892 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1894 if (wwin
->frame
->border_pixel
)
1895 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1897 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1900 if (!HAS_BORDER(wwin
))
1901 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1903 if (scr
->selected_windows
)
1904 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1908 void wMakeWindowVisible(WWindow
*wwin
)
1910 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1911 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1913 if (wwin
->flags
.shaded
)
1914 wUnshadeWindow(wwin
);
1916 if (wwin
->flags
.hidden
) {
1919 app
= wApplicationOf(wwin
->main_window
);
1921 /* trick to get focus to this window */
1922 app
->last_focused
= wwin
;
1923 wUnhideApplication(app
, False
, False
);
1926 if (wwin
->flags
.miniaturized
) {
1927 wDeiconifyWindow(wwin
);
1929 if (!WFLAGP(wwin
, no_focusable
))
1930 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1931 wRaiseFrame(wwin
->frame
->core
);
1936 * Do the animation while shading (called with what = SHADE)
1937 * or unshading (what = UNSHADE).
1940 static void shade_animate(WWindow
*wwin
, Bool what
)
1943 time_t time0
= time(NULL
);
1945 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1950 if (!wwin
->screen_ptr
->flags
.startup
) {
1951 /* do the shading animation */
1952 h
= wwin
->frame
->core
->height
;
1953 s
= h
/ SHADE_STEPS
;
1956 w
= wwin
->frame
->core
->width
;
1957 y
= wwin
->frame
->top_width
;
1958 while (h
> wwin
->frame
->top_width
+ 1) {
1959 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1960 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1963 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1966 if (SHADE_DELAY
> 0)
1967 wusleep(SHADE_DELAY
* 1000L);
1973 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1978 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1979 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1980 s
= abs(y
) / SHADE_STEPS
;
1983 w
= wwin
->frame
->core
->width
;
1984 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1986 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1987 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1988 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1990 if (SHADE_DELAY
> 0)
1991 wusleep(SHADE_DELAY
* 2000L / 3);
1997 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2001 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);