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");
257 #ifdef USE_ANIMATIONS
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
;
766 #ifdef USE_ANIMATIONS
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 /* USE_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(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1057 wwin
->frame
->title
);
1064 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1066 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1067 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1070 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1073 *iw
= wwin
->icon
->core
->width
;
1074 *ih
= wwin
->icon
->core
->height
;
1076 if (wwin
->flags
.net_handle_icon
) {
1084 *iw
= wwin
->screen_ptr
->scr_width
;
1085 *ih
= wwin
->screen_ptr
->scr_height
;
1091 void wIconifyWindow(WWindow
*wwin
)
1093 XWindowAttributes attribs
;
1096 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1097 return; /* the window doesn't exist anymore */
1099 if (wwin
->flags
.miniaturized
)
1100 return; /* already miniaturized */
1102 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1103 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1105 if (owner
&& owner
->flags
.miniaturized
)
1109 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1111 /* if the window is in another workspace, simplify process */
1113 /* icon creation may take a while */
1114 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1115 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1116 GrabModeAsync
, None
, None
, CurrentTime
);
1119 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1120 if (!wwin
->flags
.icon_moved
)
1121 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1123 wwin
->icon
= icon_create_for_wwindow(wwin
);
1124 wwin
->icon
->mapped
= 1;
1126 /* extract the window screenshot everytime, as the option can be enable anytime */
1127 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1128 RImage
*mini_preview
;
1134 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1135 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1140 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1141 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1143 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1144 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1146 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1148 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1149 XDestroyImage(pimg
);
1152 set_icon_minipreview(wwin
->icon
, mini_preview
);
1153 RReleaseImage(mini_preview
);
1158 if (wwin
->frame
->title
) {
1159 title
= wwin
->frame
->title
;
1161 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1164 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1170 wwin
->flags
.miniaturized
= 1;
1171 wwin
->flags
.mapped
= 0;
1173 /* unmap transients */
1174 unmapTransientsFor(wwin
);
1177 #ifdef USE_ANIMATIONS
1180 XUngrabPointer(dpy
, CurrentTime
);
1182 /* let all Expose events arrive so that we can repaint
1183 * something before the animation starts (and the server is grabbed) */
1186 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1187 wClientSetState(wwin
, IconicState
, None
);
1189 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1192 #ifdef USE_ANIMATIONS
1193 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1194 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1195 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1199 wwin
->flags
.skip_next_animation
= 0;
1201 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1202 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1203 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1204 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1206 AddToStackList(wwin
->icon
->core
);
1207 wLowerFrame(wwin
->icon
->core
);
1211 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1214 * It doesn't seem to be working and causes button event hangup
1215 * when deiconifying a transient window.
1216 setupIconGrabs(wwin->icon);
1218 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1219 && wPreferences
.focus_mode
== WKF_CLICK
) {
1224 if (!WFLAGP(tmp
, no_focusable
)
1225 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1226 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1230 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1231 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1232 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1234 #ifdef USE_ANIMATIONS
1235 if (!wwin
->screen_ptr
->flags
.startup
) {
1236 /* Catch up with events not processed while animation was running */
1237 Window clientwin
= wwin
->client_win
;
1239 ProcessPendingEvents();
1241 /* the window can disappear while ProcessPendingEvents() runs */
1242 if (!wWindowFor(clientwin
))
1248 /* maybe we want to do this regardless of net_handle_icon
1249 * it seems to me we might break behaviour this way.
1251 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1252 && !wwin
->flags
.net_handle_icon
)
1253 wIconSelect(wwin
->icon
);
1255 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1257 if (wPreferences
.auto_arrange_icons
)
1258 wArrangeIcons(wwin
->screen_ptr
, True
);
1261 void wDeiconifyWindow(WWindow
*wwin
)
1263 /* Let's avoid changing workspace while deiconifying */
1264 w_global
.ignore_workspace_change
= True
;
1266 /* we're hiding for show_desktop */
1267 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1268 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1271 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1273 if (!wwin
->flags
.miniaturized
) {
1274 w_global
.ignore_workspace_change
= False
;
1278 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1279 WWindow
*owner
= recursiveTransientFor(wwin
);
1281 if (owner
&& owner
->flags
.miniaturized
) {
1282 wDeiconifyWindow(owner
);
1283 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1284 wRaiseFrame(wwin
->frame
->core
);
1285 w_global
.ignore_workspace_change
= False
;
1290 wwin
->flags
.miniaturized
= 0;
1292 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1293 wwin
->flags
.mapped
= 1;
1295 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1296 /* maybe we want to do this regardless of net_handle_icon
1297 * it seems to me we might break behaviour this way.
1299 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1300 && wwin
->icon
!= NULL
) {
1301 if (wwin
->icon
->selected
)
1302 wIconSelect(wwin
->icon
);
1304 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1308 /* if the window is in another workspace, do it silently */
1309 if (!netwm_hidden
) {
1310 #ifdef USE_ANIMATIONS
1312 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1313 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1314 wwin
->frame_x
, wwin
->frame_y
,
1315 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1317 wwin
->flags
.skip_next_animation
= 0;
1319 if (!wwin
->flags
.shaded
)
1320 XMapWindow(dpy
, wwin
->client_win
);
1322 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1323 wRaiseFrame(wwin
->frame
->core
);
1324 if (!wwin
->flags
.shaded
)
1325 wClientSetState(wwin
, NormalState
, None
);
1327 mapTransientsFor(wwin
);
1330 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1331 && !wwin
->flags
.net_handle_icon
) {
1332 RemoveFromStackList(wwin
->icon
->core
);
1333 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1334 wIconDestroy(wwin
->icon
);
1338 if (!netwm_hidden
) {
1341 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1343 #ifdef USE_ANIMATIONS
1344 if (!wwin
->screen_ptr
->flags
.startup
) {
1345 /* Catch up with events not processed while animation was running */
1346 Window clientwin
= wwin
->client_win
;
1348 ProcessPendingEvents();
1350 /* the window can disappear while ProcessPendingEvents() runs */
1351 if (!wWindowFor(clientwin
)) {
1352 w_global
.ignore_workspace_change
= False
;
1359 if (wPreferences
.auto_arrange_icons
)
1360 wArrangeIcons(wwin
->screen_ptr
, True
);
1362 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1364 /* In case we were shaded and iconified, also unshade */
1366 wUnshadeWindow(wwin
);
1368 w_global
.ignore_workspace_change
= False
;
1371 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1373 if (wwin
->flags
.miniaturized
) {
1375 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1376 wwin
->icon
->mapped
= 0;
1378 wwin
->flags
.hidden
= 1;
1380 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1384 if (wwin
->flags
.inspector_open
)
1385 wHideInspectorForWindow(wwin
);
1387 wwin
->flags
.hidden
= 1;
1390 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1393 #ifdef USE_ANIMATIONS
1394 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1395 !wwin
->flags
.skip_next_animation
&& animate
) {
1396 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1397 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1398 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1401 wwin
->flags
.skip_next_animation
= 0;
1403 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1406 void wHideAll(WScreen
*scr
)
1411 unsigned int wcount
= 0;
1417 menu
= scr
->switch_menu
;
1419 windows
= wmalloc(sizeof(WWindow
*));
1422 for (i
= 0; i
< menu
->entry_no
; i
++) {
1423 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1425 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1428 wwin
= scr
->focused_window
;
1431 windows
[wcount
] = wwin
;
1433 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1439 for (i
= 0; i
< wcount
; i
++) {
1441 if (wwin
->frame
->workspace
== scr
->current_workspace
1442 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1443 && !wwin
->flags
.internal_window
1444 && !WFLAGP(wwin
, no_miniaturizable
)
1446 wwin
->flags
.skip_next_animation
= 1;
1447 wIconifyWindow(wwin
);
1454 void wHideOtherApplications(WWindow
*awin
)
1461 wwin
= awin
->screen_ptr
->focused_window
;
1465 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1466 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1467 && !wwin
->flags
.internal_window
1468 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1470 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1471 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1472 wwin
->flags
.skip_next_animation
= 1;
1473 wIconifyWindow(wwin
);
1475 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1476 tapp
= wApplicationOf(wwin
->main_window
);
1478 tapp
->flags
.skip_next_animation
= 1;
1479 wHideApplication(tapp
);
1481 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1482 wwin
->flags
.skip_next_animation
= 1;
1483 wIconifyWindow(wwin
);
1491 wSetFocusTo(awin->screen_ptr, awin);
1495 void wHideApplication(WApplication
*wapp
)
1503 wwarning("trying to hide a non grouped window");
1506 if (!wapp
->main_window_desc
) {
1507 wwarning("group leader not found for window group");
1510 scr
= wapp
->main_window_desc
->screen_ptr
;
1512 wlist
= scr
->focused_window
;
1516 if (wlist
->main_window
== wapp
->main_window
)
1517 wapp
->last_focused
= wlist
;
1519 wapp
->last_focused
= NULL
;
1521 animate
= !wapp
->flags
.skip_next_animation
;
1524 if (wlist
->main_window
== wapp
->main_window
) {
1525 if (wlist
->flags
.focused
)
1527 if (wapp
->app_icon
) {
1528 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1529 wapp
->app_icon
->y_pos
, wlist
, animate
);
1533 wlist
= wlist
->prev
;
1536 wapp
->flags
.skip_next_animation
= 0;
1539 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1540 wlist
= scr
->focused_window
;
1542 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1543 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1545 wlist
= wlist
->prev
;
1547 wSetFocusTo(scr
, wlist
);
1549 wSetFocusTo(scr
, NULL
);
1553 wapp
->flags
.hidden
= 1;
1555 if (wPreferences
.auto_arrange_icons
)
1556 wArrangeIcons(scr
, True
);
1560 wAppIconPaint(wapp
->app_icon
);
1564 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1566 if (bringToCurrentWS
)
1567 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1569 wwin
->flags
.hidden
= 0;
1571 #ifdef USE_ANIMATIONS
1572 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1573 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1574 icon
->core
->width
, icon
->core
->height
,
1575 wwin
->frame_x
, wwin
->frame_y
,
1576 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1579 wwin
->flags
.skip_next_animation
= 0;
1580 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1581 XMapWindow(dpy
, wwin
->client_win
);
1582 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1583 wClientSetState(wwin
, NormalState
, None
);
1584 wwin
->flags
.mapped
= 1;
1585 wRaiseFrame(wwin
->frame
->core
);
1587 if (wwin
->flags
.inspector_open
)
1588 wUnhideInspectorForWindow(wwin
);
1590 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1593 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1596 WWindow
*wlist
, *next
;
1597 WWindow
*focused
= NULL
;
1603 scr
= wapp
->main_window_desc
->screen_ptr
;
1604 wlist
= scr
->focused_window
;
1608 /* goto beginning of list */
1610 wlist
= wlist
->prev
;
1612 animate
= !wapp
->flags
.skip_next_animation
;
1617 if (wlist
->main_window
== wapp
->main_window
) {
1618 if (wlist
->flags
.focused
)
1620 else if (!focused
|| !focused
->flags
.focused
)
1623 if (wlist
->flags
.miniaturized
) {
1624 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1625 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1626 if (!wlist
->icon
->mapped
) {
1629 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1630 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1631 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1634 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1635 wlist
->icon
->mapped
= 1;
1637 wRaiseFrame(wlist
->icon
->core
);
1639 if (bringToCurrentWS
)
1640 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1641 wlist
->flags
.hidden
= 0;
1642 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1643 wDeiconifyWindow(wlist
);
1644 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1645 } else if (wlist
->flags
.shaded
) {
1646 if (bringToCurrentWS
)
1647 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1648 wlist
->flags
.hidden
= 0;
1649 wRaiseFrame(wlist
->frame
->core
);
1650 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1651 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1653 wUnshadeWindow(wlist
);
1655 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1656 } else if (wlist
->flags
.hidden
) {
1657 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1658 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1661 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1662 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1664 wRaiseFrame(wlist
->frame
->core
);
1670 wapp
->flags
.skip_next_animation
= 0;
1671 wapp
->flags
.hidden
= 0;
1673 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1674 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1675 wSetFocusTo(scr
, wapp
->last_focused
);
1676 } else if (focused
) {
1677 wSetFocusTo(scr
, focused
);
1679 wapp
->last_focused
= NULL
;
1680 if (wPreferences
.auto_arrange_icons
)
1681 wArrangeIcons(scr
, True
);
1684 wAppIconPaint(wapp
->app_icon
);
1688 void wShowAllWindows(WScreen
*scr
)
1690 WWindow
*wwin
, *old_foc
;
1693 old_foc
= wwin
= scr
->focused_window
;
1695 if (!wwin
->flags
.internal_window
&&
1696 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1697 if (wwin
->flags
.miniaturized
) {
1698 wwin
->flags
.skip_next_animation
= 1;
1699 wDeiconifyWindow(wwin
);
1700 } else if (wwin
->flags
.hidden
) {
1701 wapp
= wApplicationOf(wwin
->main_window
);
1703 wUnhideApplication(wapp
, False
, False
);
1705 wwin
->flags
.skip_next_animation
= 1;
1706 wDeiconifyWindow(wwin
);
1712 wSetFocusTo(scr
, old_foc
);
1713 /*wRaiseFrame(old_foc->frame->core); */
1716 void wRefreshDesktop(WScreen
*scr
)
1719 XSetWindowAttributes attr
;
1721 attr
.backing_store
= NotUseful
;
1722 attr
.save_under
= False
;
1723 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1724 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1725 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1726 XMapRaised(dpy
, win
);
1727 XDestroyWindow(dpy
, win
);
1731 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1737 const int heads
= wXineramaHeads(scr
);
1740 int pf
; /* primary axis */
1741 int sf
; /* secondary axis */
1745 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1751 int isize
= wPreferences
.icon_size
;
1753 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1755 for (head
= 0; head
< heads
; ++head
) {
1756 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1760 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1762 if (scr
->dock
->on_right_side
)
1768 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1770 vars
[head
].pi
= vars
[head
].si
= 0;
1771 vars
[head
].sx1
= rect
.pos
.x
;
1772 vars
[head
].sy1
= rect
.pos
.y
;
1773 vars
[head
].sw
= rect
.size
.width
;
1774 vars
[head
].sh
= rect
.size
.height
;
1775 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1776 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1777 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1778 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1779 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1780 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1782 /* icon yard boundaries */
1783 if (wPreferences
.icon_yard
& IY_VERT
) {
1784 vars
[head
].pf
= vars
[head
].fullH
;
1785 vars
[head
].sf
= vars
[head
].fullW
;
1787 vars
[head
].pf
= vars
[head
].fullW
;
1788 vars
[head
].sf
= vars
[head
].fullH
;
1790 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1791 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1794 vars
[head
].xo
= vars
[head
].sx1
;
1797 if (wPreferences
.icon_yard
& IY_TOP
) {
1798 vars
[head
].yo
= vars
[head
].sy1
;
1801 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1806 #define X ((wPreferences.icon_yard & IY_VERT) \
1807 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1808 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1810 #define Y ((wPreferences.icon_yard & IY_VERT) \
1811 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1812 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1814 /* arrange application icons */
1815 aicon
= scr
->app_icon_list
;
1816 /* reverse them to avoid unnecessarily sliding of icons */
1817 while (aicon
&& aicon
->next
)
1818 aicon
= aicon
->next
;
1821 if (!aicon
->docked
) {
1822 /* CHECK: can icon be NULL here ? */
1823 /* The intention here is to place the AppIcon on the head that
1824 * contains most of the applications _main_ window. */
1825 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1827 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1828 #ifdef USE_ANIMATIONS
1829 if (!wPreferences
.no_animations
)
1830 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1831 #endif /* USE_ANIMATIONS */
1833 wAppIconMove(aicon
, X
, Y
);
1835 if (vars
[head
].pi
>= vars
[head
].pf
) {
1840 aicon
= aicon
->prev
;
1843 /* arrange miniwindows */
1844 wwin
= scr
->focused_window
;
1845 /* reverse them to avoid unnecessarily shuffling */
1846 while (wwin
&& wwin
->prev
)
1850 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1851 (wwin
->frame
->workspace
== scr
->current_workspace
||
1852 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1854 head
= wGetHeadForWindow(wwin
);
1856 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1857 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1858 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1864 if (vars
[head
].pi
>= vars
[head
].pf
) {
1871 wwin
->flags
.icon_moved
= 0;
1872 /* we reversed the order, so we use next */
1879 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1881 WScreen
*scr
= wwin
->screen_ptr
;
1884 wwin
->flags
.selected
= 1;
1885 if (wwin
->frame
->selected_border_pixel
)
1886 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1888 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1890 if (!HAS_BORDER(wwin
))
1891 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1893 if (!scr
->selected_windows
)
1894 scr
->selected_windows
= WMCreateArray(4);
1895 WMAddToArray(scr
->selected_windows
, wwin
);
1897 wwin
->flags
.selected
= 0;
1898 if (wwin
->flags
.focused
) {
1899 if (wwin
->frame
->focused_border_pixel
)
1900 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1902 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1904 if (wwin
->frame
->border_pixel
)
1905 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1907 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1910 if (!HAS_BORDER(wwin
))
1911 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1913 if (scr
->selected_windows
)
1914 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1918 void wMakeWindowVisible(WWindow
*wwin
)
1920 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1921 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1923 if (wwin
->flags
.shaded
)
1924 wUnshadeWindow(wwin
);
1926 if (wwin
->flags
.hidden
) {
1929 app
= wApplicationOf(wwin
->main_window
);
1931 /* trick to get focus to this window */
1932 app
->last_focused
= wwin
;
1933 wUnhideApplication(app
, False
, False
);
1936 if (wwin
->flags
.miniaturized
) {
1937 wDeiconifyWindow(wwin
);
1939 if (!WFLAGP(wwin
, no_focusable
))
1940 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1941 wRaiseFrame(wwin
->frame
->core
);
1946 * Do the animation while shading (called with what = SHADE)
1947 * or unshading (what = UNSHADE).
1949 #ifdef USE_ANIMATIONS
1950 static void shade_animate(WWindow
*wwin
, Bool what
)
1953 time_t time0
= time(NULL
);
1955 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1960 if (!wwin
->screen_ptr
->flags
.startup
) {
1961 /* do the shading animation */
1962 h
= wwin
->frame
->core
->height
;
1963 s
= h
/ SHADE_STEPS
;
1966 w
= wwin
->frame
->core
->width
;
1967 y
= wwin
->frame
->top_width
;
1968 while (h
> wwin
->frame
->top_width
+ 1) {
1969 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1970 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1973 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1976 if (SHADE_DELAY
> 0)
1977 wusleep(SHADE_DELAY
* 1000L);
1983 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1988 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1989 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1990 s
= abs(y
) / SHADE_STEPS
;
1993 w
= wwin
->frame
->core
->width
;
1994 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1996 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1997 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1998 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2000 if (SHADE_DELAY
> 0)
2001 wusleep(SHADE_DELAY
* 2000L / 3);
2007 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2011 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);