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"
52 /****** Global Variables ******/
54 int ignore_wks_change
= 0;
55 extern Time LastTimestamp
;
56 extern Time LastFocusChange
;
57 extern WPreferences wPreferences
;
58 extern Atom _XA_WM_TAKE_FOCUS
;
59 extern void ProcessPendingEvents();
61 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
62 unsigned int *new_width
, unsigned int *new_height
);
63 static void save_old_geometry(WWindow
*wwin
, int directions
);
65 /******* Local Variables *******/
71 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
72 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
73 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
74 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
75 SHADE_STEPS_US
, SHADE_DELAY_US
}};
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
82 static int compareTimes(Time t1
, Time t2
)
88 return (diff
< 60000) ? 1 : -1;
92 static void shade_animate(WWindow
*wwin
, Bool what
);
94 static void shade_animate(WWindow
*wwin
, Bool what
) { }
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
= LastTimestamp
;
117 WApplication
*oapp
= NULL
, *napp
= NULL
;
120 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
126 old_focused
= old_scr
->focused_window
;
128 LastFocusChange
= 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
, _XA_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
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
319 *y
= (wwin
->old_geometry
.y
&& 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 #define IS_MAX_HORIZONTALLY(directions) ((directions & MAX_HORIZONTAL) | (directions & MAX_LEFTHALF) | (directions & MAX_RIGHTHALF))
346 void wMaximizeWindow(WWindow
*wwin
, int directions
)
349 unsigned int new_width
, new_height
, half_scr_width
;
352 unsigned int maximus_width
= 0;
353 unsigned int maximus_height
= 0;
354 WArea usableArea
, totalArea
;
356 int save_directions
= 0;
359 if (!IS_RESIZABLE(wwin
))
362 if (!HAS_BORDER(wwin
))
365 /* the size to adjust the geometry */
366 adj_size
= wwin
->screen_ptr
->frame_border_width
* 2 * has_border
;
368 /* save old coordinates before we change the current values
369 * always if the window is not currently maximized at all
370 * but never if the window has been Maximusized */
371 if (!wwin
->flags
.maximized
)
372 save_directions
|= SAVE_GEOMETRY_ALL
;
373 else if (!(wwin
->flags
.old_maximized
& MAX_MAXIMUS
)) {
374 if ((directions
& MAX_VERTICAL
) &&
375 !(wwin
->flags
.maximized
& MAX_VERTICAL
))
376 save_directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
377 if (IS_MAX_HORIZONTALLY(directions
) &&
378 !IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
))
379 save_directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
381 if ((directions
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
382 save_directions
|= SAVE_GEOMETRY_ALL
;
383 save_old_geometry(wwin
, save_directions
);
387 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
388 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
389 usableArea
= totalArea
;
391 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
392 WScreen
*scr
= wwin
->screen_ptr
;
395 if (directions
& MAX_KEYBOARD
)
396 head
= wGetHeadForWindow(wwin
);
398 head
= wGetHeadForPointerLocation(scr
);
400 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
403 /* remember Maximus geometry if we'll need it later */
404 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) || (directions
& MAX_MAXIMUS
))
405 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
407 /* Only save directions, not kbd or xinerama hints */
408 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
410 if (WFLAGP(wwin
, full_maximize
)) {
411 usableArea
= totalArea
;
413 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
415 if (wwin
->flags
.shaded
) {
416 wwin
->flags
.skip_next_animation
= 1;
417 wUnshadeWindow(wwin
);
420 if (directions
& MAX_HORIZONTAL
) {
421 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
422 new_x
= usableArea
.x1
;
423 } else if (directions
& MAX_LEFTHALF
) {
424 new_width
= half_scr_width
- adj_size
;
425 new_x
= usableArea
.x1
;
426 wwin
->flags
.old_maximized
|= MAX_LEFTHALF
;
427 wwin
->flags
.old_maximized
&= ~MAX_RIGHTHALF
;
428 } else if (directions
& MAX_RIGHTHALF
) {
429 new_width
= half_scr_width
- adj_size
;
430 new_x
= usableArea
.x1
+ half_scr_width
;
431 wwin
->flags
.old_maximized
|= MAX_RIGHTHALF
;
432 wwin
->flags
.old_maximized
&= ~MAX_LEFTHALF
;
433 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
435 new_width
= maximus_width
- adj_size
;
436 } else if (IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
)) {
437 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
438 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
440 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
441 new_x
= wwin
->frame_x
;
442 new_width
= wwin
->frame
->core
->width
;
445 if (directions
& MAX_VERTICAL
) {
446 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
447 new_y
= usableArea
.y1
;
448 if (WFLAGP(wwin
, full_maximize
)) {
449 new_y
-= wwin
->frame
->top_width
;
450 new_height
+= wwin
->frame
->bottom_width
- 1;
452 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
454 new_height
= maximus_height
- adj_size
;
455 /* HACK: this will be subtracted again below */
456 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
457 } else if (wwin
->flags
.maximized
& MAX_VERTICAL
) {
458 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
459 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
460 /* HACK: this will be subtracted again below */
461 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
462 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
464 new_y
= wwin
->frame_y
;
465 new_height
= wwin
->frame
->core
->height
;
468 if (!WFLAGP(wwin
, full_maximize
)) {
469 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
472 if (directions
& MAX_MAXIMUS
) {
475 new_width
= maximus_width
- adj_size
;
476 new_height
= maximus_height
- adj_size
;
477 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
478 new_y
-= wwin
->frame
->top_width
;
479 new_height
+= wwin
->frame
->top_width
- 1;
481 wwin
->maximus_x
= new_x
;
482 wwin
->maximus_y
= new_y
;
483 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
486 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
488 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
489 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
491 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
492 wWindowSynthConfigureNotify(wwin
);
494 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
496 /* set maximization state */
497 wwin
->flags
.maximized
= directions
;
498 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
499 wwin
->flags
.maximized
= MAX_MAXIMUS
;
502 /* generic (un)maximizer */
503 void handleMaximize(WWindow
*wwin
, int directions
)
505 int current
= wwin
->flags
.maximized
;
506 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
507 int effective
= requested
^ current
;
508 int flags
= directions
& ~requested
;
511 /* allow wMaximizeWindow to restore the Maximusized size */
512 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
513 !(requested
& MAX_MAXIMUS
))
514 wMaximizeWindow(wwin
, flags
);
516 wUnmaximizeWindow(wwin
);
519 /* MAX_MAXIMUS takes precedence */
520 effective
&= ~MAX_MAXIMUS
;
521 if (requested
& MAX_MAXIMUS
) {
522 /* window was previously Maximusized then maximized */
523 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !current
) {
524 wUnmaximizeWindow(wwin
);
528 effective
= MAX_MAXIMUS
;
530 else if (requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
))
531 effective
= requested
;
533 /* handle MAX_HORIZONTAL -> MAX_(LEFT|RIGHT)HALF */
534 if (IS_MAX_HORIZONTALLY(current
)) {
535 if (IS_MAX_HORIZONTALLY(requested
)) {
536 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
);
537 effective
|= (requested
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
));
538 if (requested
& MAX_HORIZONTAL
) {
539 /* restore to half maximization */
540 if (wwin
->flags
.old_maximized
& MAX_LEFTHALF
)
541 effective
|= MAX_LEFTHALF
;
542 else if (wwin
->flags
.old_maximized
& MAX_RIGHTHALF
)
543 effective
|= MAX_RIGHTHALF
;
545 /* MAX_VERTICAL is implicit with MAX_(LEFT|RIGHT)HALF */
547 effective
|= MAX_VERTICAL
;
549 /* toggling MAX_VERTICAL */
550 if ((requested
& MAX_VERTICAL
) &&
551 (current
& MAX_VERTICAL
)) {
552 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_VERTICAL
);
556 /* handle MAX_VERTICAL -> MAX_(LEFT|RIGHT)HALF */
557 if (current
& MAX_VERTICAL
) {
558 if ((requested
& MAX_LEFTHALF
) ||
559 (requested
& MAX_RIGHTHALF
)) {
560 effective
|= MAX_VERTICAL
;
563 /* toggling MAX_HORIZONTAL */
564 if ((requested
& MAX_HORIZONTAL
) &&
565 (current
& MAX_HORIZONTAL
))
566 effective
&= ~MAX_HORIZONTAL
;
568 wMaximizeWindow(wwin
, effective
| flags
);
573 /* the window boundary coordinates */
583 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
585 obs
->left
= wwin
->frame_x
;
586 obs
->top
= wwin
->frame_y
;
587 obs
->width
= wwin
->frame
->core
->width
;
588 obs
->height
= wwin
->frame
->core
->height
;
589 obs
->bottom
= obs
->top
+ obs
->height
;
590 obs
->right
= obs
->left
+ obs
->width
;
594 * Maximus: tiled maximization (maximize without overlapping other windows)
596 * The original window 'orig' will be maximized to new coordinates 'new'.
597 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
599 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
600 unsigned int *new_width
, unsigned int *new_height
)
603 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
604 short int adjust_height
;
605 int x_intsect
, y_intsect
;
606 /* the obstructing, original and new windows */
607 win_coords obs
, orig
, new;
609 /* set the original coordinate positions of the window to be Maximumized */
610 if (wwin
->flags
.maximized
) {
611 /* window is already maximized; consider original geometry */
612 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
613 orig
.bottom
= orig
.top
+ orig
.height
;
614 orig
.right
= orig
.left
+ orig
.width
;
617 set_window_coords(wwin
, &orig
);
619 /* Try to fully maximize first, then readjust later */
620 new.left
= usableArea
.x1
;
621 new.right
= usableArea
.x2
;
622 new.top
= usableArea
.y1
;
623 new.bottom
= usableArea
.y2
;
625 if (HAS_TITLEBAR(wwin
))
626 tbar_height_0
= TITLEBAR_HEIGHT
;
627 if (HAS_RESIZEBAR(wwin
))
628 rbar_height_0
= RESIZEBAR_HEIGHT
;
629 if (HAS_BORDER(wwin
))
630 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
632 /* the length to be subtracted if the window has titlebar, etc */
633 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
636 /* The focused window is always the last in the list */
638 /* ignore windows in other workspaces etc */
639 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
640 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
646 /* Set the coordinates of obstructing window */
647 set_window_coords(tmp
, &obs
);
649 /* Try to maximize in the y direction first */
650 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
651 if (x_intsect
!= 0) {
652 /* TODO: Consider the case when coords are equal */
653 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
654 /* w_0 is below the bottom of w_j */
655 new.top
= obs
.bottom
+ 1;
657 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
658 /* The bottom of w_0 is above the top of w_j */
659 new.bottom
= obs
.top
- 1;
666 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
667 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
673 set_window_coords(tmp
, &obs
);
676 * Use the new.top and new.height instead of original values
677 * as they may have different intersections with the obstructing windows
679 new.height
= new.bottom
- new.top
- adjust_height
;
680 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
681 if (y_intsect
!= 0) {
682 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
683 /* w_0 is completely to the right of w_j */
684 new.left
= obs
.right
+ 1;
686 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
687 /* w_0 is completely to the left of w_j */
688 new.right
= obs
.left
- 1;
695 /* xcalc needs -7 here, but other apps don't */
696 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
697 *new_width
= new.right
- new.left
;
700 void wUnmaximizeWindow(WWindow
*wwin
)
704 if (!wwin
->flags
.maximized
)
707 if (wwin
->flags
.shaded
) {
708 wwin
->flags
.skip_next_animation
= 1;
709 wUnshadeWindow(wwin
);
712 /* Use old coordinates if they are set, current values otherwise */
713 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
715 /* unMaximusize relative to original position */
716 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
717 x
+= wwin
->frame_x
- wwin
->maximus_x
;
718 y
+= wwin
->frame_y
- wwin
->maximus_y
;
721 wwin
->flags
.maximized
= 0;
722 wwin
->flags
.old_maximized
= 0;
723 wWindowConfigure(wwin
, x
, y
, w
, h
);
724 wWindowSynthConfigureNotify(wwin
);
726 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
729 void wFullscreenWindow(WWindow
*wwin
)
734 if (wwin
->flags
.fullscreen
)
737 wwin
->flags
.fullscreen
= True
;
739 wWindowConfigureBorders(wwin
);
741 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
743 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
744 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
745 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
746 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
748 head
= wGetHeadForWindow(wwin
);
749 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
750 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
752 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
755 void wUnfullscreenWindow(WWindow
*wwin
)
757 if (!wwin
->flags
.fullscreen
)
760 wwin
->flags
.fullscreen
= False
;
762 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
763 if (WFLAGP(wwin
, sunken
)) {
764 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
765 } else if (WFLAGP(wwin
, floating
)) {
766 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
768 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
772 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
773 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
775 wWindowConfigureBorders(wwin
);
777 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
778 wFrameWindowPaint(wwin->frame);
781 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
785 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
787 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
788 float cx
, cy
, cw
, ch
;
789 float xstep
, ystep
, wstep
, hstep
;
792 float angle
, final_angle
, delta
;
794 xstep
= (float)(fx
- x
) / steps
;
795 ystep
= (float)(fy
- y
) / steps
;
796 wstep
= (float)(fw
- w
) / steps
;
797 hstep
= (float)(fh
- h
) / steps
;
804 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
805 delta
= (float)(final_angle
/ FRAMES
);
806 for (angle
= 0;; angle
+= delta
) {
807 if (angle
> final_angle
)
810 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
811 dch
= (ch
/ 2) * cos(angle
);
812 midy
= cy
+ (ch
/ 2);
814 points
[0].x
= cx
+ dx
;
815 points
[0].y
= midy
- dch
;
816 points
[1].x
= cx
+ cw
- dx
;
817 points
[1].y
= points
[0].y
;
818 points
[2].x
= cx
+ cw
+ dx
;
819 points
[2].y
= midy
+ dch
;
820 points
[3].x
= cx
- dx
;
821 points
[3].y
= points
[2].y
;
822 points
[4].x
= points
[0].x
;
823 points
[4].y
= points
[0].y
;
826 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
828 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
830 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
836 if (angle
>= final_angle
)
846 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
848 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
849 float cx
, cy
, cw
, ch
;
850 float xstep
, ystep
, wstep
, hstep
;
852 float angle
, final_angle
, a
, d
, delta
;
859 xstep
= (float)(fx
- x
) / steps
;
860 ystep
= (float)(fy
- y
) / steps
;
861 wstep
= (float)(fw
- w
) / steps
;
862 hstep
= (float)(fh
- h
) / steps
;
869 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
870 delta
= (float)(final_angle
/ FRAMES
);
871 for (angle
= 0;; angle
+= delta
) {
872 if (angle
> final_angle
)
876 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
878 points
[0].x
= cx
+ cos(angle
- a
) * d
;
879 points
[0].y
= cy
+ sin(angle
- a
) * d
;
880 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
881 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
882 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
883 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
884 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
885 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
886 points
[4].x
= cx
+ cos(angle
- a
) * d
;
887 points
[4].y
= cy
+ sin(angle
- a
) * d
;
889 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
891 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
893 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
899 if (angle
>= final_angle
)
908 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
910 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
911 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
912 float xstep
, ystep
, wstep
, hstep
;
915 xstep
= (float)(fx
- x
) / steps
;
916 ystep
= (float)(fy
- y
) / steps
;
917 wstep
= (float)(fw
- w
) / steps
;
918 hstep
= (float)(fh
- h
) / steps
;
920 for (j
= 0; j
< FRAMES
; j
++) {
927 for (i
= 0; i
< steps
; i
++) {
928 for (j
= 0; j
< FRAMES
; j
++) {
929 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
930 (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
,
937 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
938 if (j
< FRAMES
- 1) {
952 for (j
= 0; j
< FRAMES
; j
++) {
953 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
956 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
958 for (j
= 0; j
< FRAMES
; j
++) {
959 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
967 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
969 int style
= wPreferences
.iconification_style
; /* Catch the value */
972 if (style
== WIS_NONE
)
975 if (style
== WIS_RANDOM
) {
981 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
983 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
986 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
988 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
992 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
994 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
998 #endif /* ANIMATIONS */
1000 static void flushExpose(void)
1004 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
1005 WMHandleEvent(&tmpev
);
1009 static void unmapTransientsFor(WWindow
*wwin
)
1013 tmp
= wwin
->screen_ptr
->focused_window
;
1015 /* unmap the transients for this transient */
1016 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1017 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1018 unmapTransientsFor(tmp
);
1019 tmp
->flags
.miniaturized
= 1;
1020 if (!tmp
->flags
.shaded
) {
1023 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1026 if (!tmp->flags.shaded)
1028 wClientSetState(tmp
, IconicState
, None
);
1030 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1036 static void mapTransientsFor(WWindow
*wwin
)
1040 tmp
= wwin
->screen_ptr
->focused_window
;
1042 /* recursively map the transients for this transient */
1043 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1044 && tmp
->icon
== NULL
) {
1045 mapTransientsFor(tmp
);
1046 tmp
->flags
.miniaturized
= 0;
1047 if (!tmp
->flags
.shaded
) {
1050 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1052 tmp
->flags
.semi_focused
= 0;
1054 if (!tmp->flags.shaded)
1056 wClientSetState(tmp
, NormalState
, None
);
1058 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1064 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1071 /* hackish way to detect transient_for cycle */
1072 i
= wwin
->screen_ptr
->window_count
+ 1;
1074 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1075 wwin
= wWindowFor(wwin
->transient_for
);
1078 if (i
== 0 && wwin
) {
1079 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1086 void wIconifyWindow(WWindow
* wwin
)
1088 XWindowAttributes attribs
;
1091 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1092 return; /* the window doesn't exist anymore */
1094 if (wwin
->flags
.miniaturized
)
1095 return; /* already miniaturized */
1097 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1098 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1100 if (owner
&& owner
->flags
.miniaturized
)
1104 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1106 /* if the window is in another workspace, simplify process */
1108 /* icon creation may take a while */
1109 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1110 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1111 GrabModeAsync
, None
, None
, CurrentTime
);
1114 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1115 if (!wwin
->flags
.icon_moved
)
1116 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1118 wwin
->icon
= icon_create_for_wwindow(wwin
);
1119 wwin
->icon
->mapped
= 1;
1122 wwin
->flags
.miniaturized
= 1;
1123 wwin
->flags
.mapped
= 0;
1125 /* unmap transients */
1126 unmapTransientsFor(wwin
);
1129 XUngrabPointer(dpy
, CurrentTime
);
1131 /* let all Expose events arrive so that we can repaint
1132 * something before the animation starts (and the server is grabbed) */
1135 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1136 wClientSetState(wwin
, IconicState
, None
);
1138 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1142 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1143 && !wPreferences
.no_animations
) {
1146 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1149 iw
= wwin
->icon
->core
->width
;
1150 ih
= wwin
->icon
->core
->height
;
1152 if (wwin
->flags
.net_handle_icon
) {
1160 iw
= wwin
->screen_ptr
->scr_width
;
1161 ih
= wwin
->screen_ptr
->scr_height
;
1164 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1165 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1170 wwin
->flags
.skip_next_animation
= 0;
1172 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1173 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1174 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1175 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1177 AddToStackList(wwin
->icon
->core
);
1178 wLowerFrame(wwin
->icon
->core
);
1182 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1185 * It doesn't seem to be working and causes button event hangup
1186 * when deiconifying a transient window.
1187 setupIconGrabs(wwin->icon);
1189 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1190 && wPreferences
.focus_mode
== WKF_CLICK
) {
1195 if (!WFLAGP(tmp
, no_focusable
)
1196 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1197 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1201 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1202 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1203 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1206 if (!wwin
->screen_ptr
->flags
.startup
) {
1207 /* Catch up with events not processed while animation was running */
1208 Window clientwin
= wwin
->client_win
;
1210 ProcessPendingEvents();
1212 /* the window can disappear while ProcessPendingEvents() runs */
1213 if (!wWindowFor(clientwin
)) {
1220 /* maybe we want to do this regardless of net_handle_icon
1221 * it seems to me we might break behaviour this way.
1223 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1224 && !wwin
->flags
.net_handle_icon
)
1225 wIconSelect(wwin
->icon
);
1227 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1229 if (wPreferences
.auto_arrange_icons
)
1230 wArrangeIcons(wwin
->screen_ptr
, True
);
1233 void wDeiconifyWindow(WWindow
*wwin
)
1235 /* Let's avoid changing workspace while deiconifying */
1236 ignore_wks_change
= 1;
1238 /* we're hiding for show_desktop */
1239 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1240 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1243 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1245 if (!wwin
->flags
.miniaturized
)
1248 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1249 WWindow
*owner
= recursiveTransientFor(wwin
);
1251 if (owner
&& owner
->flags
.miniaturized
) {
1252 wDeiconifyWindow(owner
);
1253 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1254 wRaiseFrame(wwin
->frame
->core
);
1259 wwin
->flags
.miniaturized
= 0;
1261 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1262 wwin
->flags
.mapped
= 1;
1264 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1265 /* maybe we want to do this regardless of net_handle_icon
1266 * it seems to me we might break behaviour this way.
1268 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1269 && wwin
->icon
!= NULL
) {
1270 if (wwin
->icon
->selected
)
1271 wIconSelect(wwin
->icon
);
1273 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1277 /* if the window is in another workspace, do it silently */
1278 if (!netwm_hidden
) {
1280 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1281 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1284 if (!wPreferences
.disable_miniwindows
1285 && !wwin
->flags
.net_handle_icon
) {
1288 iw
= wwin
->icon
->core
->width
;
1289 ih
= wwin
->icon
->core
->height
;
1291 if (wwin
->flags
.net_handle_icon
) {
1299 iw
= wwin
->screen_ptr
->scr_width
;
1300 ih
= wwin
->screen_ptr
->scr_height
;
1303 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1304 wwin
->frame_x
, wwin
->frame_y
,
1305 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1307 #endif /* ANIMATIONS */
1308 wwin
->flags
.skip_next_animation
= 0;
1310 if (!wwin
->flags
.shaded
)
1311 XMapWindow(dpy
, wwin
->client_win
);
1313 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1314 wRaiseFrame(wwin
->frame
->core
);
1315 if (!wwin
->flags
.shaded
)
1316 wClientSetState(wwin
, NormalState
, None
);
1318 mapTransientsFor(wwin
);
1321 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1322 && !wwin
->flags
.net_handle_icon
) {
1323 RemoveFromStackList(wwin
->icon
->core
);
1324 /* removeIconGrabs(wwin->icon); */
1325 wIconDestroy(wwin
->icon
);
1329 if (!netwm_hidden
) {
1332 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1335 if (!wwin
->screen_ptr
->flags
.startup
) {
1336 /* Catch up with events not processed while animation was running */
1337 Window clientwin
= wwin
->client_win
;
1339 ProcessPendingEvents();
1341 /* the window can disappear while ProcessPendingEvents() runs */
1342 if (!wWindowFor(clientwin
))
1348 if (wPreferences
.auto_arrange_icons
)
1349 wArrangeIcons(wwin
->screen_ptr
, True
);
1351 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1353 /* In case we were shaded and iconified, also unshade */
1355 wUnshadeWindow(wwin
);
1357 ignore_wks_change
= 0;
1360 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1362 if (wwin
->flags
.miniaturized
) {
1364 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1365 wwin
->icon
->mapped
= 0;
1367 wwin
->flags
.hidden
= 1;
1369 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1373 if (wwin
->flags
.inspector_open
) {
1374 wHideInspectorForWindow(wwin
);
1377 wwin
->flags
.hidden
= 1;
1380 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1384 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1385 !wwin
->flags
.skip_next_animation
&& animate
) {
1386 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1387 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1388 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1391 wwin
->flags
.skip_next_animation
= 0;
1393 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1396 void wHideAll(WScreen
*scr
)
1401 unsigned int wcount
= 0;
1407 menu
= scr
->switch_menu
;
1409 windows
= wmalloc(sizeof(WWindow
*));
1412 for (i
= 0; i
< menu
->entry_no
; i
++) {
1413 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1415 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1418 wwin
= scr
->focused_window
;
1421 windows
[wcount
] = wwin
;
1423 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1429 for (i
= 0; i
< wcount
; i
++) {
1431 if (wwin
->frame
->workspace
== scr
->current_workspace
1432 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1433 && !wwin
->flags
.internal_window
1434 && !WFLAGP(wwin
, no_miniaturizable
)
1436 wwin
->flags
.skip_next_animation
= 1;
1437 wIconifyWindow(wwin
);
1444 void wHideOtherApplications(WWindow
*awin
)
1451 wwin
= awin
->screen_ptr
->focused_window
;
1455 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1456 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1457 && !wwin
->flags
.internal_window
1458 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1460 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1461 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1462 wwin
->flags
.skip_next_animation
= 1;
1463 wIconifyWindow(wwin
);
1465 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1466 tapp
= wApplicationOf(wwin
->main_window
);
1468 tapp
->flags
.skip_next_animation
= 1;
1469 wHideApplication(tapp
);
1471 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1472 wwin
->flags
.skip_next_animation
= 1;
1473 wIconifyWindow(wwin
);
1481 wSetFocusTo(awin->screen_ptr, awin);
1485 void wHideApplication(WApplication
*wapp
)
1493 wwarning("trying to hide a non grouped window");
1496 if (!wapp
->main_window_desc
) {
1497 wwarning("group leader not found for window group");
1500 scr
= wapp
->main_window_desc
->screen_ptr
;
1502 wlist
= scr
->focused_window
;
1506 if (wlist
->main_window
== wapp
->main_window
)
1507 wapp
->last_focused
= wlist
;
1509 wapp
->last_focused
= NULL
;
1511 animate
= !wapp
->flags
.skip_next_animation
;
1514 if (wlist
->main_window
== wapp
->main_window
) {
1515 if (wlist
->flags
.focused
) {
1518 if (wapp
->app_icon
) {
1519 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1520 wapp
->app_icon
->y_pos
, wlist
, animate
);
1524 wlist
= wlist
->prev
;
1527 wapp
->flags
.skip_next_animation
= 0;
1530 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1531 wlist
= scr
->focused_window
;
1533 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1534 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1536 wlist
= wlist
->prev
;
1538 wSetFocusTo(scr
, wlist
);
1540 wSetFocusTo(scr
, NULL
);
1544 wapp
->flags
.hidden
= 1;
1546 if (wPreferences
.auto_arrange_icons
)
1547 wArrangeIcons(scr
, True
);
1551 wAppIconPaint(wapp
->app_icon
);
1555 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1557 if (bringToCurrentWS
)
1558 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1560 wwin
->flags
.hidden
= 0;
1563 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1564 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1565 icon
->core
->width
, icon
->core
->height
,
1566 wwin
->frame_x
, wwin
->frame_y
,
1567 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1570 wwin
->flags
.skip_next_animation
= 0;
1571 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1572 XMapWindow(dpy
, wwin
->client_win
);
1573 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1574 wClientSetState(wwin
, NormalState
, None
);
1575 wwin
->flags
.mapped
= 1;
1576 wRaiseFrame(wwin
->frame
->core
);
1578 if (wwin
->flags
.inspector_open
) {
1579 wUnhideInspectorForWindow(wwin
);
1582 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1585 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1588 WWindow
*wlist
, *next
;
1589 WWindow
*focused
= NULL
;
1595 scr
= wapp
->main_window_desc
->screen_ptr
;
1596 wlist
= scr
->focused_window
;
1600 /* goto beginning of list */
1602 wlist
= wlist
->prev
;
1604 animate
= !wapp
->flags
.skip_next_animation
;
1609 if (wlist
->main_window
== wapp
->main_window
) {
1610 if (wlist
->flags
.focused
)
1612 else if (!focused
|| !focused
->flags
.focused
)
1615 if (wlist
->flags
.miniaturized
) {
1616 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1617 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1618 if (!wlist
->icon
->mapped
) {
1621 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1622 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1623 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1627 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1628 wlist
->icon
->mapped
= 1;
1630 wRaiseFrame(wlist
->icon
->core
);
1632 if (bringToCurrentWS
)
1633 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1634 wlist
->flags
.hidden
= 0;
1635 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1636 wDeiconifyWindow(wlist
);
1638 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1639 } else if (wlist
->flags
.shaded
) {
1640 if (bringToCurrentWS
)
1641 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1642 wlist
->flags
.hidden
= 0;
1643 wRaiseFrame(wlist
->frame
->core
);
1644 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1645 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1647 wUnshadeWindow(wlist
);
1650 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1651 } else if (wlist
->flags
.hidden
) {
1652 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1653 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1656 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1657 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1659 wRaiseFrame(wlist
->frame
->core
);
1665 wapp
->flags
.skip_next_animation
= 0;
1666 wapp
->flags
.hidden
= 0;
1668 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1669 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1670 wSetFocusTo(scr
, wapp
->last_focused
);
1671 } else if (focused
) {
1672 wSetFocusTo(scr
, focused
);
1674 wapp
->last_focused
= NULL
;
1675 if (wPreferences
.auto_arrange_icons
)
1676 wArrangeIcons(scr
, True
);
1679 wAppIconPaint(wapp
->app_icon
);
1683 void wShowAllWindows(WScreen
*scr
)
1685 WWindow
*wwin
, *old_foc
;
1688 old_foc
= wwin
= scr
->focused_window
;
1690 if (!wwin
->flags
.internal_window
&&
1691 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1692 if (wwin
->flags
.miniaturized
) {
1693 wwin
->flags
.skip_next_animation
= 1;
1694 wDeiconifyWindow(wwin
);
1695 } else if (wwin
->flags
.hidden
) {
1696 wapp
= wApplicationOf(wwin
->main_window
);
1698 wUnhideApplication(wapp
, False
, False
);
1700 wwin
->flags
.skip_next_animation
= 1;
1701 wDeiconifyWindow(wwin
);
1707 wSetFocusTo(scr
, old_foc
);
1708 /*wRaiseFrame(old_foc->frame->core); */
1711 void wRefreshDesktop(WScreen
*scr
)
1714 XSetWindowAttributes attr
;
1716 attr
.backing_store
= NotUseful
;
1717 attr
.save_under
= False
;
1718 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1719 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1720 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1721 XMapRaised(dpy
, win
);
1722 XDestroyWindow(dpy
, win
);
1726 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1732 const int heads
= wXineramaHeads(scr
);
1735 int pf
; /* primary axis */
1736 int sf
; /* secondary axis */
1740 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1746 int isize
= wPreferences
.icon_size
;
1748 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1750 for (head
= 0; head
< heads
; ++head
) {
1751 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1752 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1753 vars
[head
].pi
= vars
[head
].si
= 0;
1754 vars
[head
].sx1
= rect
.pos
.x
;
1755 vars
[head
].sy1
= rect
.pos
.y
;
1756 vars
[head
].sw
= rect
.size
.width
;
1757 vars
[head
].sh
= rect
.size
.height
;
1758 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1759 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1760 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1761 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1762 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1763 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1765 /* icon yard boundaries */
1766 if (wPreferences
.icon_yard
& IY_VERT
) {
1767 vars
[head
].pf
= vars
[head
].fullH
;
1768 vars
[head
].sf
= vars
[head
].fullW
;
1770 vars
[head
].pf
= vars
[head
].fullW
;
1771 vars
[head
].sf
= vars
[head
].fullH
;
1773 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1774 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1777 vars
[head
].xo
= vars
[head
].sx1
;
1780 if (wPreferences
.icon_yard
& IY_TOP
) {
1781 vars
[head
].yo
= vars
[head
].sy1
;
1784 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1789 #define X ((wPreferences.icon_yard & IY_VERT) \
1790 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1791 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1793 #define Y ((wPreferences.icon_yard & IY_VERT) \
1794 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1795 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1797 /* arrange application icons */
1798 aicon
= scr
->app_icon_list
;
1799 /* reverse them to avoid unnecessarily sliding of icons */
1800 while (aicon
&& aicon
->next
)
1801 aicon
= aicon
->next
;
1804 if (!aicon
->docked
) {
1805 /* CHECK: can icon be NULL here ? */
1806 /* The intention here is to place the AppIcon on the head that
1807 * contains most of the applications _main_ window. */
1808 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1810 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1812 if (!wPreferences
.no_animations
)
1813 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1814 #endif /* ANIMATIONS */
1816 wAppIconMove(aicon
, X
, Y
);
1818 if (vars
[head
].pi
>= vars
[head
].pf
) {
1823 aicon
= aicon
->prev
;
1826 /* arrange miniwindows */
1827 wwin
= scr
->focused_window
;
1828 /* reverse them to avoid unnecessarily shuffling */
1829 while (wwin
&& wwin
->prev
)
1833 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1834 (wwin
->frame
->workspace
== scr
->current_workspace
||
1835 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1837 head
= wGetHeadForWindow(wwin
);
1839 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1840 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1841 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1847 if (vars
[head
].pi
>= vars
[head
].pf
) {
1854 wwin
->flags
.icon_moved
= 0;
1856 /* we reversed the order, so we use next */
1863 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1865 WScreen
*scr
= wwin
->screen_ptr
;
1868 wwin
->flags
.selected
= 1;
1869 if (wwin
->frame
->selected_border_pixel
)
1870 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1872 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1874 if (!HAS_BORDER(wwin
)) {
1875 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1878 if (!scr
->selected_windows
)
1879 scr
->selected_windows
= WMCreateArray(4);
1880 WMAddToArray(scr
->selected_windows
, wwin
);
1882 wwin
->flags
.selected
= 0;
1883 if (wwin
->frame
->border_pixel
)
1884 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1886 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1888 if (!HAS_BORDER(wwin
)) {
1889 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1892 if (scr
->selected_windows
) {
1893 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1898 void wMakeWindowVisible(WWindow
*wwin
)
1900 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1901 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1903 if (wwin
->flags
.shaded
) {
1904 wUnshadeWindow(wwin
);
1906 if (wwin
->flags
.hidden
) {
1909 app
= wApplicationOf(wwin
->main_window
);
1911 /* trick to get focus to this window */
1912 app
->last_focused
= wwin
;
1913 wUnhideApplication(app
, False
, False
);
1916 if (wwin
->flags
.miniaturized
) {
1917 wDeiconifyWindow(wwin
);
1919 if (!WFLAGP(wwin
, no_focusable
))
1920 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1921 wRaiseFrame(wwin
->frame
->core
);
1926 * Do the animation while shading (called with what = SHADE)
1927 * or unshading (what = UNSHADE).
1930 static void shade_animate(WWindow
*wwin
, Bool what
)
1933 time_t time0
= time(NULL
);
1935 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1940 if (!wwin
->screen_ptr
->flags
.startup
) {
1941 /* do the shading animation */
1942 h
= wwin
->frame
->core
->height
;
1943 s
= h
/ SHADE_STEPS
;
1946 w
= wwin
->frame
->core
->width
;
1947 y
= wwin
->frame
->top_width
;
1948 while (h
> wwin
->frame
->top_width
+ 1) {
1949 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1950 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1953 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1956 if (SHADE_DELAY
> 0) {
1957 wusleep(SHADE_DELAY
* 1000L);
1964 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1969 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1970 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1971 s
= abs(y
) / SHADE_STEPS
;
1974 w
= wwin
->frame
->core
->width
;
1975 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1977 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1978 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1979 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1981 if (SHADE_DELAY
> 0) {
1982 wusleep(SHADE_DELAY
* 2000L / 3);
1989 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1993 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);