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
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
33 #include "WindowMaker.h"
39 #include "application.h"
45 #include "winspector.h"
46 #include "workspace.h"
49 #include "placement.h"
54 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
55 unsigned int *new_width
, unsigned int *new_height
);
56 static void save_old_geometry(WWindow
*wwin
, int directions
);
58 /******* 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
}};
72 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
73 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
75 static int compareTimes(Time t1
, Time t2
)
81 return (diff
< 60000) ? 1 : -1;
85 static void shade_animate(WWindow
*wwin
, Bool what
);
87 static inline void shade_animate(WWindow
*wwin
, Bool what
) {
89 * This function is empty on purpose, so tell the compiler
90 * to not warn about parameters being not used
98 *----------------------------------------------------------------------
100 * Changes the window focus to the one passed as argument.
101 * If the window to focus is not already focused, it will be brought
102 * to the head of the list of windows. Previously focused window is
106 * Window list may be reordered and the window focus is changed.
108 *----------------------------------------------------------------------
110 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
112 static WScreen
*old_scr
= NULL
;
114 WWindow
*old_focused
;
115 WWindow
*focused
= scr
->focused_window
;
116 Time timestamp
= w_global
.timestamp
.last_event
;
117 WApplication
*oapp
= NULL
, *napp
= NULL
;
120 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
126 old_focused
= old_scr
->focused_window
;
128 w_global
.timestamp
.focus_change
= timestamp
;
131 oapp
= wApplicationOf(old_focused
->main_window
);
134 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
136 wWindowUnfocus(old_focused
);
139 wAppMenuUnmap(oapp
->menu
);
140 if (wPreferences
.highlight_active_app
)
141 wApplicationDeactivate(oapp
);
144 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
148 if (old_scr
!= scr
&& old_focused
)
149 wWindowUnfocus(old_focused
);
151 wasfocused
= wwin
->flags
.focused
;
152 napp
= wApplicationOf(wwin
->main_window
);
154 /* remember last workspace where the app has been */
156 napp
->last_workspace
= wwin
->frame
->workspace
;
158 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
159 /* install colormap if colormap mode is lock mode */
160 if (wPreferences
.colormap_mode
== WCM_CLICK
)
161 wColormapInstallForWindow(scr
, wwin
);
163 /* set input focus */
164 switch (wwin
->focus_mode
) {
166 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
169 case WFM_LOCALLY_ACTIVE
:
170 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
172 case WFM_GLOBALLY_ACTIVE
:
177 if (wwin
->protocols
.TAKE_FOCUS
)
178 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
182 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
185 if (WFLAGP(wwin
, no_focusable
))
188 /* if this is not the focused window focus it */
189 if (focused
!= wwin
) {
190 /* change the focus window list order */
192 wwin
->prev
->next
= wwin
->next
;
195 wwin
->next
->prev
= wwin
->prev
;
197 wwin
->prev
= focused
;
198 focused
->next
= wwin
;
200 scr
->focused_window
= wwin
;
202 if (oapp
&& oapp
!= napp
) {
203 wAppMenuUnmap(oapp
->menu
);
204 if (wPreferences
.highlight_active_app
)
205 wApplicationDeactivate(oapp
);
209 wWindowFocus(wwin
, focused
);
211 if (napp
&& !wasfocused
) {
213 wUserMenuRefreshInstances(napp
->menu
, wwin
);
214 #endif /* USER_MENU */
216 if (wwin
->flags
.mapped
)
217 wAppMenuMap(napp
->menu
, wwin
);
219 if (napp
&& wPreferences
.highlight_active_app
)
220 wApplicationActivate(napp
);
226 void wShadeWindow(WWindow
*wwin
)
229 if (wwin
->flags
.shaded
)
232 XLowerWindow(dpy
, wwin
->client_win
);
233 shade_animate(wwin
, SHADE
);
235 wwin
->flags
.skip_next_animation
= 0;
236 wwin
->flags
.shaded
= 1;
237 wwin
->flags
.mapped
= 0;
238 /* prevent window withdrawal when getting UnmapNotify */
239 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
240 XUnmapWindow(dpy
, wwin
->client_win
);
241 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
243 /* for the client it's just like iconification */
244 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
246 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
247 wWindowSynthConfigureNotify(wwin
);
250 wClientSetState(wwin, IconicState, None);
253 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
256 if (!wwin
->screen_ptr
->flags
.startup
) {
257 /* Catch up with events not processed while animation was running */
258 ProcessPendingEvents();
263 void wUnshadeWindow(WWindow
*wwin
)
266 if (!wwin
->flags
.shaded
)
269 wwin
->flags
.shaded
= 0;
270 wwin
->flags
.mapped
= 1;
271 XMapWindow(dpy
, wwin
->client_win
);
273 shade_animate(wwin
, UNSHADE
);
275 wwin
->flags
.skip_next_animation
= 0;
276 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
277 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
279 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
280 wWindowSynthConfigureNotify(wwin
);
282 /* if the window is focused, set the focus again as it was disabled during
284 if (wwin
->flags
.focused
)
285 wSetFocusTo(wwin
->screen_ptr
, wwin
);
287 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
290 /* Set the old coordinates using the current values */
291 static void save_old_geometry(WWindow
*wwin
, int directions
)
293 /* never been saved? */
294 if (! wwin
->old_geometry
.width
)
295 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
296 if (! wwin
->old_geometry
.height
)
297 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
299 if (directions
& SAVE_GEOMETRY_X
)
300 wwin
->old_geometry
.x
= wwin
->frame_x
;
301 if (directions
& SAVE_GEOMETRY_Y
)
302 wwin
->old_geometry
.y
= wwin
->frame_y
;
303 if (directions
& SAVE_GEOMETRY_WIDTH
)
304 wwin
->old_geometry
.width
= wwin
->client
.width
;
305 if (directions
& SAVE_GEOMETRY_HEIGHT
)
306 wwin
->old_geometry
.height
= wwin
->client
.height
;
309 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
311 WMRect old_geom_rect
;
315 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
316 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
317 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
318 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
319 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
320 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
321 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
324 /* Remember geometry for unmaximizing */
325 void update_saved_geometry(WWindow
*wwin
)
327 /* NOT if we aren't already maximized
328 * we'll save geometry when maximizing */
329 if (!wwin
->flags
.maximized
)
332 /* NOT if we are fully maximized */
333 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
334 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
335 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
338 /* save the co-ordinate in the axis in which we AREN'T maximized */
339 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
340 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
341 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
342 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
345 void wMaximizeWindow(WWindow
*wwin
, int directions
)
347 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
352 unsigned int maximus_width
= 0;
353 unsigned int maximus_height
= 0;
354 WArea usableArea
, totalArea
;
357 WScreen
*scr
= wwin
->screen_ptr
;
359 if (!IS_RESIZABLE(wwin
))
362 if (!HAS_BORDER(wwin
))
365 /* the size to adjust the geometry */
366 adj_size
= scr
->frame_border_width
* 2 * has_border
;
368 /* save old coordinates before we change the current values */
369 if (!wwin
->flags
.maximized
)
370 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
372 totalArea
.x2
= scr
->scr_width
;
373 totalArea
.y2
= scr
->scr_height
;
376 usableArea
= totalArea
;
378 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
379 WScreen
*scr
= wwin
->screen_ptr
;
382 if (directions
& MAX_KEYBOARD
)
383 head
= wGetHeadForWindow(wwin
);
385 head
= wGetHeadForPointerLocation(scr
);
387 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
391 /* Only save directions, not kbd or xinerama hints */
392 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
394 if (WFLAGP(wwin
, full_maximize
)) {
395 usableArea
= totalArea
;
397 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
398 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
400 if (wwin
->flags
.shaded
) {
401 wwin
->flags
.skip_next_animation
= 1;
402 wUnshadeWindow(wwin
);
405 if (directions
& MAX_MAXIMUS
) {
406 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
407 new_width
= maximus_width
- adj_size
;
408 new_height
= maximus_height
- adj_size
;
411 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
412 new_height
+= wwin
->frame
->bottom_width
- 1;
413 new_y
-= wwin
->frame
->top_width
;
416 wwin
->maximus_x
= new_x
;
417 wwin
->maximus_y
= new_y
;
418 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
420 /* set default values if no option set then */
421 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
422 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
423 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
425 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
426 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
427 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
430 /* left|right position */
431 if (directions
& MAX_LEFTHALF
) {
432 new_width
= half_scr_width
- adj_size
;
433 new_x
= usableArea
.x1
;
434 } else if (directions
& MAX_RIGHTHALF
) {
435 new_width
= half_scr_width
- adj_size
;
436 new_x
= usableArea
.x1
+ half_scr_width
;
438 /* top|bottom position */
439 if (directions
& MAX_TOPHALF
) {
440 new_height
= half_scr_height
- adj_size
;
441 new_y
= usableArea
.y1
;
442 } else if (directions
& MAX_BOTTOMHALF
) {
443 new_height
= half_scr_height
- adj_size
;
444 new_y
= usableArea
.y1
+ half_scr_height
;
447 /* vertical|horizontal position */
448 if (directions
& MAX_HORIZONTAL
) {
449 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
450 new_x
= usableArea
.x1
;
452 if (directions
& MAX_VERTICAL
) {
453 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
454 new_y
= usableArea
.y1
;
455 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
456 new_y
-= wwin
->frame
->top_width
;
460 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
461 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
463 /* set maximization state */
464 wwin
->flags
.maximized
= directions
;
465 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
466 wwin
->flags
.maximized
= MAX_MAXIMUS
;
468 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
470 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
471 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
473 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
474 wWindowSynthConfigureNotify(wwin
);
476 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
479 /* generic (un)maximizer */
480 void handleMaximize(WWindow
*wwin
, int directions
)
482 int current
= wwin
->flags
.maximized
;
483 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
484 int effective
= requested
^ current
;
485 int flags
= directions
& ~requested
;
488 /* allow wMaximizeWindow to restore the Maximusized size */
489 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
490 !(requested
& MAX_MAXIMUS
))
491 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
493 wUnmaximizeWindow(wwin
);
494 /* these alone mean vertical|horizontal toggle */
495 } else if ((effective
== MAX_LEFTHALF
) ||
496 (effective
== MAX_RIGHTHALF
) ||
497 (effective
== MAX_TOPHALF
) ||
498 (effective
== MAX_BOTTOMHALF
))
499 wUnmaximizeWindow(wwin
);
501 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
502 (requested
== MAX_MAXIMUS
))
503 effective
= requested
;
505 if (requested
& MAX_LEFTHALF
) {
506 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
507 effective
|= MAX_VERTICAL
;
509 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
510 effective
|= MAX_LEFTHALF
;
511 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
512 } else if (requested
& MAX_RIGHTHALF
) {
513 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
514 effective
|= MAX_VERTICAL
;
516 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
517 effective
|= MAX_RIGHTHALF
;
518 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
520 if (requested
& MAX_TOPHALF
) {
521 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
522 effective
|= MAX_HORIZONTAL
;
524 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
525 effective
|= MAX_TOPHALF
;
526 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
527 } else if (requested
& MAX_BOTTOMHALF
) {
528 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
529 effective
|= MAX_HORIZONTAL
;
531 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
532 effective
|= MAX_BOTTOMHALF
;
533 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
535 if (requested
& MAX_HORIZONTAL
)
536 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
537 if (requested
& MAX_VERTICAL
)
538 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
539 effective
&= ~MAX_MAXIMUS
;
541 wMaximizeWindow(wwin
, effective
| flags
);
545 /* the window boundary coordinates */
555 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
557 obs
->left
= wwin
->frame_x
;
558 obs
->top
= wwin
->frame_y
;
559 obs
->width
= wwin
->frame
->core
->width
;
560 obs
->height
= wwin
->frame
->core
->height
;
561 obs
->bottom
= obs
->top
+ obs
->height
;
562 obs
->right
= obs
->left
+ obs
->width
;
566 * Maximus: tiled maximization (maximize without overlapping other windows)
568 * The original window 'orig' will be maximized to new coordinates 'new'.
569 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
571 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
572 unsigned int *new_width
, unsigned int *new_height
)
575 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
576 short int adjust_height
;
577 int x_intsect
, y_intsect
;
578 /* the obstructing, original and new windows */
579 win_coords obs
, orig
, new;
581 /* set the original coordinate positions of the window to be Maximumized */
582 if (wwin
->flags
.maximized
) {
583 /* window is already maximized; consider original geometry */
584 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
585 orig
.bottom
= orig
.top
+ orig
.height
;
586 orig
.right
= orig
.left
+ orig
.width
;
589 set_window_coords(wwin
, &orig
);
591 /* Try to fully maximize first, then readjust later */
592 new.left
= usableArea
.x1
;
593 new.right
= usableArea
.x2
;
594 new.top
= usableArea
.y1
;
595 new.bottom
= usableArea
.y2
;
597 if (HAS_TITLEBAR(wwin
))
598 tbar_height_0
= TITLEBAR_HEIGHT
;
599 if (HAS_RESIZEBAR(wwin
))
600 rbar_height_0
= RESIZEBAR_HEIGHT
;
601 if (HAS_BORDER(wwin
))
602 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
604 /* the length to be subtracted if the window has titlebar, etc */
605 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
608 /* The focused window is always the last in the list */
610 /* ignore windows in other workspaces etc */
611 if (tmp
->prev
->frame
->workspace
!= w_global
.workspace
.current
||
612 tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
618 /* Set the coordinates of obstructing window */
619 set_window_coords(tmp
, &obs
);
621 /* Try to maximize in the y direction first */
622 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
623 if (x_intsect
!= 0) {
624 /* TODO: Consider the case when coords are equal */
625 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
626 /* w_0 is below the bottom of w_j */
627 new.top
= obs
.bottom
+ 1;
629 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
630 /* The bottom of w_0 is above the top of w_j */
631 new.bottom
= obs
.top
- 1;
638 if (tmp
->prev
->frame
->workspace
!= w_global
.workspace
.current
||
639 tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
645 set_window_coords(tmp
, &obs
);
648 * Use the new.top and new.height instead of original values
649 * as they may have different intersections with the obstructing windows
651 new.height
= new.bottom
- new.top
- adjust_height
;
652 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
653 if (y_intsect
!= 0) {
654 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
655 /* w_0 is completely to the right of w_j */
656 new.left
= obs
.right
+ 1;
658 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
659 /* w_0 is completely to the left of w_j */
660 new.right
= obs
.left
- 1;
667 /* xcalc needs -7 here, but other apps don't */
668 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
669 *new_width
= new.right
- new.left
;
672 void wUnmaximizeWindow(WWindow
*wwin
)
676 if (!wwin
->flags
.maximized
)
679 if (wwin
->flags
.shaded
) {
680 wwin
->flags
.skip_next_animation
= 1;
681 wUnshadeWindow(wwin
);
684 /* Use old coordinates if they are set, current values otherwise */
685 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
687 /* unMaximusize relative to original position */
688 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
689 x
+= wwin
->frame_x
- wwin
->maximus_x
;
690 y
+= wwin
->frame_y
- wwin
->maximus_y
;
693 wwin
->flags
.maximized
= 0;
694 wwin
->flags
.old_maximized
= 0;
695 wWindowConfigure(wwin
, x
, y
, w
, h
);
696 wWindowSynthConfigureNotify(wwin
);
698 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
701 void wFullscreenWindow(WWindow
*wwin
)
706 if (wwin
->flags
.fullscreen
)
709 wwin
->flags
.fullscreen
= True
;
711 wWindowConfigureBorders(wwin
);
713 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
714 wRaiseFrame(wwin
->frame
->core
);
716 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
717 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
718 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
719 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
721 head
= wGetHeadForWindow(wwin
);
722 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
723 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
725 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
726 wSetFocusTo(wwin
->screen_ptr
, wwin
);
728 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
731 void wUnfullscreenWindow(WWindow
*wwin
)
733 if (!wwin
->flags
.fullscreen
)
736 wwin
->flags
.fullscreen
= False
;
738 if (WFLAGP(wwin
, sunken
)) {
739 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
740 } else if (WFLAGP(wwin
, floating
)) {
741 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
744 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
745 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
747 wWindowConfigureBorders(wwin
);
749 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
750 wFrameWindowPaint(wwin->frame);
753 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
755 if (wwin
->screen_ptr
->bfs_focused_window
) {
756 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
757 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
762 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
764 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
765 float cx
, cy
, cw
, ch
;
766 float xstep
, ystep
, wstep
, hstep
;
769 float angle
, final_angle
, delta
;
771 xstep
= (float)(fx
- x
) / steps
;
772 ystep
= (float)(fy
- y
) / steps
;
773 wstep
= (float)(fw
- w
) / steps
;
774 hstep
= (float)(fh
- h
) / steps
;
781 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
782 delta
= (float)(final_angle
/ FRAMES
);
783 for (angle
= 0;; angle
+= delta
) {
784 if (angle
> final_angle
)
787 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
788 dch
= (ch
/ 2) * cos(angle
);
789 midy
= cy
+ (ch
/ 2);
791 points
[0].x
= cx
+ dx
;
792 points
[0].y
= midy
- dch
;
793 points
[1].x
= cx
+ cw
- dx
;
794 points
[1].y
= points
[0].y
;
795 points
[2].x
= cx
+ cw
+ dx
;
796 points
[2].y
= midy
+ dch
;
797 points
[3].x
= cx
- dx
;
798 points
[3].y
= points
[2].y
;
799 points
[4].x
= points
[0].x
;
800 points
[4].y
= points
[0].y
;
803 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
805 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
807 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
813 if (angle
>= final_angle
)
823 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
825 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
826 float cx
, cy
, cw
, ch
;
827 float xstep
, ystep
, wstep
, hstep
;
829 float angle
, final_angle
, a
, d
, delta
;
836 xstep
= (float)(fx
- x
) / steps
;
837 ystep
= (float)(fy
- y
) / steps
;
838 wstep
= (float)(fw
- w
) / steps
;
839 hstep
= (float)(fh
- h
) / steps
;
846 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
847 delta
= (float)(final_angle
/ FRAMES
);
848 for (angle
= 0;; angle
+= delta
) {
849 if (angle
> final_angle
)
853 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
855 points
[0].x
= cx
+ cos(angle
- a
) * d
;
856 points
[0].y
= cy
+ sin(angle
- a
) * d
;
857 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
858 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
859 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
860 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
861 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
862 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
863 points
[4].x
= cx
+ cos(angle
- a
) * d
;
864 points
[4].y
= cy
+ sin(angle
- a
) * d
;
866 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
868 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
870 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
876 if (angle
>= final_angle
)
885 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
887 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
888 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
889 float xstep
, ystep
, wstep
, hstep
;
892 xstep
= (float)(fx
- x
) / steps
;
893 ystep
= (float)(fy
- y
) / steps
;
894 wstep
= (float)(fw
- w
) / steps
;
895 hstep
= (float)(fh
- h
) / steps
;
897 for (j
= 0; j
< FRAMES
; j
++) {
904 for (i
= 0; i
< steps
; i
++) {
905 for (j
= 0; j
< FRAMES
; j
++) {
906 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
907 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
910 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
912 for (j
= 0; j
< FRAMES
; j
++) {
913 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
914 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
915 if (j
< FRAMES
- 1) {
929 for (j
= 0; j
< FRAMES
; j
++) {
930 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
933 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
935 for (j
= 0; j
< FRAMES
; j
++) {
936 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
944 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
946 int style
= wPreferences
.iconification_style
; /* Catch the value */
949 if (style
== WIS_NONE
)
952 if (style
== WIS_RANDOM
) {
958 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
960 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
963 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
965 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
969 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
971 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
975 #endif /* ANIMATIONS */
977 static void flushExpose(void)
981 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
982 WMHandleEvent(&tmpev
);
986 static void unmapTransientsFor(WWindow
*wwin
)
990 tmp
= wwin
->screen_ptr
->focused_window
;
992 /* unmap the transients for this transient */
993 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
994 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
995 unmapTransientsFor(tmp
);
996 tmp
->flags
.miniaturized
= 1;
997 if (!tmp
->flags
.shaded
) {
1000 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1003 if (!tmp->flags.shaded)
1005 wClientSetState(tmp
, IconicState
, None
);
1007 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1013 static void mapTransientsFor(WWindow
*wwin
)
1017 tmp
= wwin
->screen_ptr
->focused_window
;
1019 /* recursively map the transients for this transient */
1020 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1021 && tmp
->icon
== NULL
) {
1022 mapTransientsFor(tmp
);
1023 tmp
->flags
.miniaturized
= 0;
1024 if (!tmp
->flags
.shaded
) {
1027 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 void wIconifyWindow(WWindow
* wwin
)
1065 XWindowAttributes attribs
;
1068 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1069 return; /* the window doesn't exist anymore */
1071 if (wwin
->flags
.miniaturized
)
1072 return; /* already miniaturized */
1074 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1075 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1077 if (owner
&& owner
->flags
.miniaturized
)
1081 present
= wwin
->frame
->workspace
== w_global
.workspace
.current
;
1083 /* if the window is in another workspace, simplify process */
1085 /* icon creation may take a while */
1086 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1087 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1088 GrabModeAsync
, None
, None
, CurrentTime
);
1091 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1092 if (!wwin
->flags
.icon_moved
)
1093 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1095 wwin
->icon
= icon_create_for_wwindow(wwin
);
1096 wwin
->icon
->mapped
= 1;
1098 /* extract the window screenshot everytime, as the option can be enable anytime */
1099 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1106 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1107 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1112 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1113 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1115 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1116 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1118 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1120 apercu
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1121 XDestroyImage(pimg
);
1124 set_icon_apercu(wwin
->icon
, apercu
);
1125 RReleaseImage(apercu
);
1127 wwarning("window apercu creation failed");
1133 wwin
->flags
.miniaturized
= 1;
1134 wwin
->flags
.mapped
= 0;
1136 /* unmap transients */
1137 unmapTransientsFor(wwin
);
1140 XUngrabPointer(dpy
, CurrentTime
);
1142 /* let all Expose events arrive so that we can repaint
1143 * something before the animation starts (and the server is grabbed) */
1146 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1147 wClientSetState(wwin
, IconicState
, None
);
1149 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1153 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1154 && !wPreferences
.no_animations
) {
1157 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1160 iw
= wwin
->icon
->core
->width
;
1161 ih
= wwin
->icon
->core
->height
;
1163 if (wwin
->flags
.net_handle_icon
) {
1171 iw
= wwin
->screen_ptr
->scr_width
;
1172 ih
= wwin
->screen_ptr
->scr_height
;
1175 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1176 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1181 wwin
->flags
.skip_next_animation
= 0;
1183 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1184 if (w_global
.workspace
.current
== wwin
->frame
->workspace
||
1185 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1186 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1188 AddToStackList(wwin
->icon
->core
);
1189 wLowerFrame(wwin
->icon
->core
);
1193 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1196 * It doesn't seem to be working and causes button event hangup
1197 * when deiconifying a transient window.
1198 setupIconGrabs(wwin->icon);
1200 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1201 && wPreferences
.focus_mode
== WKF_CLICK
) {
1206 if (!WFLAGP(tmp
, no_focusable
)
1207 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1208 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1212 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1213 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1214 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1217 if (!wwin
->screen_ptr
->flags
.startup
) {
1218 /* Catch up with events not processed while animation was running */
1219 Window clientwin
= wwin
->client_win
;
1221 ProcessPendingEvents();
1223 /* the window can disappear while ProcessPendingEvents() runs */
1224 if (!wWindowFor(clientwin
)) {
1231 /* maybe we want to do this regardless of net_handle_icon
1232 * it seems to me we might break behaviour this way.
1234 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1235 && !wwin
->flags
.net_handle_icon
)
1236 wIconSelect(wwin
->icon
);
1238 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1240 if (wPreferences
.auto_arrange_icons
)
1241 wArrangeIcons(wwin
->screen_ptr
, True
);
1244 void wDeiconifyWindow(WWindow
*wwin
)
1246 /* Let's avoid changing workspace while deiconifying */
1247 w_global
.workspace
.ignore_change
= True
;
1249 /* we're hiding for show_desktop */
1250 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1251 wwin
->frame
->workspace
!= w_global
.workspace
.current
;
1254 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1256 if (!wwin
->flags
.miniaturized
) {
1257 w_global
.workspace
.ignore_change
= False
;
1261 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1262 WWindow
*owner
= recursiveTransientFor(wwin
);
1264 if (owner
&& owner
->flags
.miniaturized
) {
1265 wDeiconifyWindow(owner
);
1266 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1267 wRaiseFrame(wwin
->frame
->core
);
1268 w_global
.workspace
.ignore_change
= False
;
1273 wwin
->flags
.miniaturized
= 0;
1275 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1276 wwin
->flags
.mapped
= 1;
1278 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1279 /* maybe we want to do this regardless of net_handle_icon
1280 * it seems to me we might break behaviour this way.
1282 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1283 && wwin
->icon
!= NULL
) {
1284 if (wwin
->icon
->selected
)
1285 wIconSelect(wwin
->icon
);
1287 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1291 /* if the window is in another workspace, do it silently */
1292 if (!netwm_hidden
) {
1294 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1295 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1298 if (!wPreferences
.disable_miniwindows
1299 && !wwin
->flags
.net_handle_icon
) {
1302 iw
= wwin
->icon
->core
->width
;
1303 ih
= wwin
->icon
->core
->height
;
1305 if (wwin
->flags
.net_handle_icon
) {
1313 iw
= wwin
->screen_ptr
->scr_width
;
1314 ih
= wwin
->screen_ptr
->scr_height
;
1317 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1318 wwin
->frame_x
, wwin
->frame_y
,
1319 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1321 #endif /* ANIMATIONS */
1322 wwin
->flags
.skip_next_animation
= 0;
1324 if (!wwin
->flags
.shaded
)
1325 XMapWindow(dpy
, wwin
->client_win
);
1327 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1328 wRaiseFrame(wwin
->frame
->core
);
1329 if (!wwin
->flags
.shaded
)
1330 wClientSetState(wwin
, NormalState
, None
);
1332 mapTransientsFor(wwin
);
1335 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1336 && !wwin
->flags
.net_handle_icon
) {
1337 RemoveFromStackList(wwin
->icon
->core
);
1338 /* removeIconGrabs(wwin->icon); */
1339 wIconDestroy(wwin
->icon
);
1343 if (!netwm_hidden
) {
1346 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1349 if (!wwin
->screen_ptr
->flags
.startup
) {
1350 /* Catch up with events not processed while animation was running */
1351 Window clientwin
= wwin
->client_win
;
1353 ProcessPendingEvents();
1355 /* the window can disappear while ProcessPendingEvents() runs */
1356 if (!wWindowFor(clientwin
)) {
1357 w_global
.workspace
.ignore_change
= False
;
1364 if (wPreferences
.auto_arrange_icons
)
1365 wArrangeIcons(wwin
->screen_ptr
, True
);
1367 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1369 /* In case we were shaded and iconified, also unshade */
1371 wUnshadeWindow(wwin
);
1373 w_global
.workspace
.ignore_change
= False
;
1376 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1378 if (wwin
->flags
.miniaturized
) {
1380 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1381 wwin
->icon
->mapped
= 0;
1383 wwin
->flags
.hidden
= 1;
1385 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1389 if (wwin
->flags
.inspector_open
) {
1390 wHideInspectorForWindow(wwin
);
1393 wwin
->flags
.hidden
= 1;
1396 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1400 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1401 !wwin
->flags
.skip_next_animation
&& animate
) {
1402 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1403 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1404 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1407 wwin
->flags
.skip_next_animation
= 0;
1409 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1412 void wHideAll(WScreen
*scr
)
1417 unsigned int wcount
= 0;
1423 menu
= scr
->switch_menu
;
1425 windows
= wmalloc(sizeof(WWindow
*));
1428 for (i
= 0; i
< menu
->entry_no
; i
++) {
1429 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1431 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1434 wwin
= scr
->focused_window
;
1437 windows
[wcount
] = wwin
;
1439 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1445 for (i
= 0; i
< wcount
; i
++) {
1447 if (wwin
->frame
->workspace
== w_global
.workspace
.current
1448 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1449 && !wwin
->flags
.internal_window
1450 && !WFLAGP(wwin
, no_miniaturizable
)
1452 wwin
->flags
.skip_next_animation
= 1;
1453 wIconifyWindow(wwin
);
1460 void wHideOtherApplications(WWindow
*awin
)
1467 wwin
= awin
->screen_ptr
->focused_window
;
1471 && wwin
->frame
->workspace
== w_global
.workspace
.current
1472 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1473 && !wwin
->flags
.internal_window
1474 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1476 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1477 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1478 wwin
->flags
.skip_next_animation
= 1;
1479 wIconifyWindow(wwin
);
1481 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1482 tapp
= wApplicationOf(wwin
->main_window
);
1484 tapp
->flags
.skip_next_animation
= 1;
1485 wHideApplication(tapp
);
1487 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1488 wwin
->flags
.skip_next_animation
= 1;
1489 wIconifyWindow(wwin
);
1497 wSetFocusTo(awin->screen_ptr, awin);
1501 void wHideApplication(WApplication
*wapp
)
1509 wwarning("trying to hide a non grouped window");
1512 if (!wapp
->main_window_desc
) {
1513 wwarning("group leader not found for window group");
1516 scr
= wapp
->main_window_desc
->screen_ptr
;
1518 wlist
= scr
->focused_window
;
1522 if (wlist
->main_window
== wapp
->main_window
)
1523 wapp
->last_focused
= wlist
;
1525 wapp
->last_focused
= NULL
;
1527 animate
= !wapp
->flags
.skip_next_animation
;
1530 if (wlist
->main_window
== wapp
->main_window
) {
1531 if (wlist
->flags
.focused
) {
1534 if (wapp
->app_icon
) {
1535 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1536 wapp
->app_icon
->y_pos
, wlist
, animate
);
1540 wlist
= wlist
->prev
;
1543 wapp
->flags
.skip_next_animation
= 0;
1546 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1547 wlist
= scr
->focused_window
;
1549 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1550 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1552 wlist
= wlist
->prev
;
1554 wSetFocusTo(scr
, wlist
);
1556 wSetFocusTo(scr
, NULL
);
1560 wapp
->flags
.hidden
= 1;
1562 if (wPreferences
.auto_arrange_icons
)
1563 wArrangeIcons(scr
, True
);
1567 wAppIconPaint(wapp
->app_icon
);
1571 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1573 if (bringToCurrentWS
)
1574 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1576 wwin
->flags
.hidden
= 0;
1579 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1580 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1581 icon
->core
->width
, icon
->core
->height
,
1582 wwin
->frame_x
, wwin
->frame_y
,
1583 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1586 wwin
->flags
.skip_next_animation
= 0;
1587 if (w_global
.workspace
.current
== wwin
->frame
->workspace
) {
1588 XMapWindow(dpy
, wwin
->client_win
);
1589 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1590 wClientSetState(wwin
, NormalState
, None
);
1591 wwin
->flags
.mapped
= 1;
1592 wRaiseFrame(wwin
->frame
->core
);
1594 if (wwin
->flags
.inspector_open
) {
1595 wUnhideInspectorForWindow(wwin
);
1598 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1601 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1604 WWindow
*wlist
, *next
;
1605 WWindow
*focused
= NULL
;
1611 scr
= wapp
->main_window_desc
->screen_ptr
;
1612 wlist
= scr
->focused_window
;
1616 /* goto beginning of list */
1618 wlist
= wlist
->prev
;
1620 animate
= !wapp
->flags
.skip_next_animation
;
1625 if (wlist
->main_window
== wapp
->main_window
) {
1626 if (wlist
->flags
.focused
)
1628 else if (!focused
|| !focused
->flags
.focused
)
1631 if (wlist
->flags
.miniaturized
) {
1632 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1633 wlist
->frame
->workspace
== w_global
.workspace
.current
) && wlist
->icon
) {
1634 if (!wlist
->icon
->mapped
) {
1637 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1638 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1639 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1643 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1644 wlist
->icon
->mapped
= 1;
1646 wRaiseFrame(wlist
->icon
->core
);
1648 if (bringToCurrentWS
)
1649 wWindowChangeWorkspace(wlist
, w_global
.workspace
.current
);
1650 wlist
->flags
.hidden
= 0;
1651 if (miniwindows
&& wlist
->frame
->workspace
== w_global
.workspace
.current
) {
1652 wDeiconifyWindow(wlist
);
1654 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1655 } else if (wlist
->flags
.shaded
) {
1656 if (bringToCurrentWS
)
1657 wWindowChangeWorkspace(wlist
, w_global
.workspace
.current
);
1658 wlist
->flags
.hidden
= 0;
1659 wRaiseFrame(wlist
->frame
->core
);
1660 if (wlist
->frame
->workspace
== w_global
.workspace
.current
) {
1661 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1663 wUnshadeWindow(wlist
);
1666 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1667 } else if (wlist
->flags
.hidden
) {
1668 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1669 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1672 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= w_global
.workspace
.current
)
1673 wWindowChangeWorkspace(wlist
, w_global
.workspace
.current
);
1675 wRaiseFrame(wlist
->frame
->core
);
1681 wapp
->flags
.skip_next_animation
= 0;
1682 wapp
->flags
.hidden
= 0;
1684 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1685 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1686 wSetFocusTo(scr
, wapp
->last_focused
);
1687 } else if (focused
) {
1688 wSetFocusTo(scr
, focused
);
1690 wapp
->last_focused
= NULL
;
1691 if (wPreferences
.auto_arrange_icons
)
1692 wArrangeIcons(scr
, True
);
1695 wAppIconPaint(wapp
->app_icon
);
1699 void wShowAllWindows(WScreen
*scr
)
1701 WWindow
*wwin
, *old_foc
;
1704 old_foc
= wwin
= scr
->focused_window
;
1706 if (!wwin
->flags
.internal_window
&&
1707 (w_global
.workspace
.current
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1708 if (wwin
->flags
.miniaturized
) {
1709 wwin
->flags
.skip_next_animation
= 1;
1710 wDeiconifyWindow(wwin
);
1711 } else if (wwin
->flags
.hidden
) {
1712 wapp
= wApplicationOf(wwin
->main_window
);
1714 wUnhideApplication(wapp
, False
, False
);
1716 wwin
->flags
.skip_next_animation
= 1;
1717 wDeiconifyWindow(wwin
);
1723 wSetFocusTo(scr
, old_foc
);
1724 /*wRaiseFrame(old_foc->frame->core); */
1727 void wRefreshDesktop(WScreen
*scr
)
1730 XSetWindowAttributes attr
;
1732 attr
.backing_store
= NotUseful
;
1733 attr
.save_under
= False
;
1734 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1735 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1736 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1737 XMapRaised(dpy
, win
);
1738 XDestroyWindow(dpy
, win
);
1742 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1748 const int heads
= wXineramaHeads(scr
);
1751 int pf
; /* primary axis */
1752 int sf
; /* secondary axis */
1756 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1762 int isize
= wPreferences
.icon_size
;
1764 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1766 for (head
= 0; head
< heads
; ++head
) {
1767 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1771 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1773 if (scr
->dock
->on_right_side
)
1779 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1781 vars
[head
].pi
= vars
[head
].si
= 0;
1782 vars
[head
].sx1
= rect
.pos
.x
;
1783 vars
[head
].sy1
= rect
.pos
.y
;
1784 vars
[head
].sw
= rect
.size
.width
;
1785 vars
[head
].sh
= rect
.size
.height
;
1786 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1787 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1788 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1789 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1790 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1791 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1793 /* icon yard boundaries */
1794 if (wPreferences
.icon_yard
& IY_VERT
) {
1795 vars
[head
].pf
= vars
[head
].fullH
;
1796 vars
[head
].sf
= vars
[head
].fullW
;
1798 vars
[head
].pf
= vars
[head
].fullW
;
1799 vars
[head
].sf
= vars
[head
].fullH
;
1801 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1802 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1805 vars
[head
].xo
= vars
[head
].sx1
;
1808 if (wPreferences
.icon_yard
& IY_TOP
) {
1809 vars
[head
].yo
= vars
[head
].sy1
;
1812 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1817 #define X ((wPreferences.icon_yard & IY_VERT) \
1818 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1819 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1821 #define Y ((wPreferences.icon_yard & IY_VERT) \
1822 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1823 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1825 /* arrange application icons */
1826 aicon
= w_global
.app_icon_list
;
1827 /* reverse them to avoid unnecessarily sliding of icons */
1828 while (aicon
&& aicon
->next
)
1829 aicon
= aicon
->next
;
1832 if (!aicon
->docked
) {
1833 /* CHECK: can icon be NULL here ? */
1834 /* The intention here is to place the AppIcon on the head that
1835 * contains most of the applications _main_ window. */
1836 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1838 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1840 if (!wPreferences
.no_animations
)
1841 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1842 #endif /* ANIMATIONS */
1844 wAppIconMove(aicon
, X
, Y
);
1846 if (vars
[head
].pi
>= vars
[head
].pf
) {
1851 aicon
= aicon
->prev
;
1854 /* arrange miniwindows */
1855 wwin
= scr
->focused_window
;
1856 /* reverse them to avoid unnecessarily shuffling */
1857 while (wwin
&& wwin
->prev
)
1861 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1862 (wwin
->frame
->workspace
== w_global
.workspace
.current
||
1863 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1865 head
= wGetHeadForWindow(wwin
);
1867 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1868 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1869 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1875 if (vars
[head
].pi
>= vars
[head
].pf
) {
1882 wwin
->flags
.icon_moved
= 0;
1884 /* we reversed the order, so we use next */
1891 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1893 WScreen
*scr
= wwin
->screen_ptr
;
1896 wwin
->flags
.selected
= 1;
1897 if (wwin
->frame
->selected_border_pixel
)
1898 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1900 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1902 if (!HAS_BORDER(wwin
)) {
1903 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1906 if (!scr
->selected_windows
)
1907 scr
->selected_windows
= WMCreateArray(4);
1908 WMAddToArray(scr
->selected_windows
, wwin
);
1910 wwin
->flags
.selected
= 0;
1911 if (wwin
->flags
.focused
) {
1912 if (wwin
->frame
->focused_border_pixel
)
1913 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1915 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1917 if (wwin
->frame
->border_pixel
)
1918 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1920 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1923 if (!HAS_BORDER(wwin
)) {
1924 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1927 if (scr
->selected_windows
) {
1928 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1933 void wMakeWindowVisible(WWindow
*wwin
)
1935 if (wwin
->frame
->workspace
!= w_global
.workspace
.current
)
1936 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1938 if (wwin
->flags
.shaded
)
1939 wUnshadeWindow(wwin
);
1941 if (wwin
->flags
.hidden
) {
1944 app
= wApplicationOf(wwin
->main_window
);
1946 /* trick to get focus to this window */
1947 app
->last_focused
= wwin
;
1948 wUnhideApplication(app
, False
, False
);
1951 if (wwin
->flags
.miniaturized
) {
1952 wDeiconifyWindow(wwin
);
1954 if (!WFLAGP(wwin
, no_focusable
))
1955 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1956 wRaiseFrame(wwin
->frame
->core
);
1961 * Do the animation while shading (called with what = SHADE)
1962 * or unshading (what = UNSHADE).
1965 static void shade_animate(WWindow
*wwin
, Bool what
)
1968 time_t time0
= time(NULL
);
1970 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1975 if (!wwin
->screen_ptr
->flags
.startup
) {
1976 /* do the shading animation */
1977 h
= wwin
->frame
->core
->height
;
1978 s
= h
/ SHADE_STEPS
;
1981 w
= wwin
->frame
->core
->width
;
1982 y
= wwin
->frame
->top_width
;
1983 while (h
> wwin
->frame
->top_width
+ 1) {
1984 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1985 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1988 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1991 if (SHADE_DELAY
> 0) {
1992 wusleep(SHADE_DELAY
* 1000L);
1999 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2004 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2005 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2006 s
= abs(y
) / SHADE_STEPS
;
2009 w
= wwin
->frame
->core
->width
;
2010 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2012 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2013 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2014 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2016 if (SHADE_DELAY
> 0) {
2017 wusleep(SHADE_DELAY
* 2000L / 3);
2024 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2028 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);