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"
53 /****** Global Variables ******/
55 int ignore_wks_change
= 0;
56 extern Time LastTimestamp
;
57 extern Time LastFocusChange
;
58 extern WPreferences wPreferences
;
59 extern Atom _XA_WM_TAKE_FOCUS
;
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
|| 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
;
358 if (!IS_RESIZABLE(wwin
))
361 if (!HAS_BORDER(wwin
))
364 /* the size to adjust the geometry */
365 adj_size
= wwin
->screen_ptr
->frame_border_width
* 2 * has_border
;
367 /* save old coordinates before we change the current values */
368 if (!wwin
->flags
.maximized
)
369 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
371 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
372 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
375 usableArea
= totalArea
;
377 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
378 WScreen
*scr
= wwin
->screen_ptr
;
381 if (directions
& MAX_KEYBOARD
)
382 head
= wGetHeadForWindow(wwin
);
384 head
= wGetHeadForPointerLocation(scr
);
386 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
389 /* Only save directions, not kbd or xinerama hints */
390 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
392 if (WFLAGP(wwin
, full_maximize
)) {
393 usableArea
= totalArea
;
395 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
396 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
398 if (wwin
->flags
.shaded
) {
399 wwin
->flags
.skip_next_animation
= 1;
400 wUnshadeWindow(wwin
);
403 if (directions
& MAX_MAXIMUS
) {
404 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
405 new_width
= maximus_width
- adj_size
;
406 new_height
= maximus_height
- adj_size
;
409 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
410 new_height
+= wwin
->frame
->bottom_width
- 1;
411 new_y
-= wwin
->frame
->top_width
;
414 wwin
->maximus_x
= new_x
;
415 wwin
->maximus_y
= new_y
;
416 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
418 /* set default values if no option set then */
419 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
420 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
421 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
423 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
424 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
425 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
428 /* left|right position */
429 if (directions
& MAX_LEFTHALF
) {
430 new_width
= half_scr_width
- adj_size
;
431 new_x
= usableArea
.x1
;
432 } else if (directions
& MAX_RIGHTHALF
) {
433 new_width
= half_scr_width
- adj_size
;
434 new_x
= usableArea
.x1
+ half_scr_width
;
436 /* top|bottom position */
437 if (directions
& MAX_TOPHALF
) {
438 new_height
= half_scr_height
- adj_size
;
439 new_y
= usableArea
.y1
;
440 } else if (directions
& MAX_BOTTOMHALF
) {
441 new_height
= half_scr_height
- adj_size
;
442 new_y
= usableArea
.y1
+ half_scr_height
;
445 /* vertical|horizontal position */
446 if (directions
& MAX_HORIZONTAL
) {
447 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
448 new_x
= usableArea
.x1
;
450 if (directions
& MAX_VERTICAL
) {
451 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
452 new_y
= usableArea
.y1
;
453 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
454 new_y
-= wwin
->frame
->top_width
;
458 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
459 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
461 /* set maximization state */
462 wwin
->flags
.maximized
= directions
;
463 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
464 wwin
->flags
.maximized
= MAX_MAXIMUS
;
466 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
468 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
469 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
471 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
472 wWindowSynthConfigureNotify(wwin
);
474 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
477 /* generic (un)maximizer */
478 void handleMaximize(WWindow
*wwin
, int directions
)
480 int current
= wwin
->flags
.maximized
;
481 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
482 int effective
= requested
^ current
;
483 int flags
= directions
& ~requested
;
486 /* allow wMaximizeWindow to restore the Maximusized size */
487 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
488 !(requested
& MAX_MAXIMUS
))
489 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
491 wUnmaximizeWindow(wwin
);
492 /* these alone mean vertical|horizontal toggle */
493 } else if ((effective
== MAX_LEFTHALF
) ||
494 (effective
== MAX_RIGHTHALF
) ||
495 (effective
== MAX_TOPHALF
) ||
496 (effective
== MAX_BOTTOMHALF
))
497 wUnmaximizeWindow(wwin
);
499 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
500 (requested
== MAX_MAXIMUS
))
501 effective
= requested
;
503 if (requested
& MAX_LEFTHALF
) {
504 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
505 effective
|= MAX_VERTICAL
;
507 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
508 effective
|= MAX_LEFTHALF
;
509 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
510 } else if (requested
& MAX_RIGHTHALF
) {
511 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
512 effective
|= MAX_VERTICAL
;
514 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
515 effective
|= MAX_RIGHTHALF
;
516 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
518 if (requested
& MAX_TOPHALF
) {
519 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
520 effective
|= MAX_HORIZONTAL
;
522 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
523 effective
|= MAX_TOPHALF
;
524 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
525 } else if (requested
& MAX_BOTTOMHALF
) {
526 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
527 effective
|= MAX_HORIZONTAL
;
529 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
530 effective
|= MAX_BOTTOMHALF
;
531 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
533 if (requested
& MAX_HORIZONTAL
)
534 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
535 if (requested
& MAX_VERTICAL
)
536 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
537 effective
&= ~MAX_MAXIMUS
;
539 wMaximizeWindow(wwin
, effective
| flags
);
543 /* the window boundary coordinates */
553 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
555 obs
->left
= wwin
->frame_x
;
556 obs
->top
= wwin
->frame_y
;
557 obs
->width
= wwin
->frame
->core
->width
;
558 obs
->height
= wwin
->frame
->core
->height
;
559 obs
->bottom
= obs
->top
+ obs
->height
;
560 obs
->right
= obs
->left
+ obs
->width
;
564 * Maximus: tiled maximization (maximize without overlapping other windows)
566 * The original window 'orig' will be maximized to new coordinates 'new'.
567 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
569 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
570 unsigned int *new_width
, unsigned int *new_height
)
573 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
574 short int adjust_height
;
575 int x_intsect
, y_intsect
;
576 /* the obstructing, original and new windows */
577 win_coords obs
, orig
, new;
579 /* set the original coordinate positions of the window to be Maximumized */
580 if (wwin
->flags
.maximized
) {
581 /* window is already maximized; consider original geometry */
582 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
583 orig
.bottom
= orig
.top
+ orig
.height
;
584 orig
.right
= orig
.left
+ orig
.width
;
587 set_window_coords(wwin
, &orig
);
589 /* Try to fully maximize first, then readjust later */
590 new.left
= usableArea
.x1
;
591 new.right
= usableArea
.x2
;
592 new.top
= usableArea
.y1
;
593 new.bottom
= usableArea
.y2
;
595 if (HAS_TITLEBAR(wwin
))
596 tbar_height_0
= TITLEBAR_HEIGHT
;
597 if (HAS_RESIZEBAR(wwin
))
598 rbar_height_0
= RESIZEBAR_HEIGHT
;
599 if (HAS_BORDER(wwin
))
600 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
602 /* the length to be subtracted if the window has titlebar, etc */
603 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
606 /* The focused window is always the last in the list */
608 /* ignore windows in other workspaces etc */
609 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
610 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
616 /* Set the coordinates of obstructing window */
617 set_window_coords(tmp
, &obs
);
619 /* Try to maximize in the y direction first */
620 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
621 if (x_intsect
!= 0) {
622 /* TODO: Consider the case when coords are equal */
623 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
624 /* w_0 is below the bottom of w_j */
625 new.top
= obs
.bottom
+ 1;
627 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
628 /* The bottom of w_0 is above the top of w_j */
629 new.bottom
= obs
.top
- 1;
636 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
637 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
643 set_window_coords(tmp
, &obs
);
646 * Use the new.top and new.height instead of original values
647 * as they may have different intersections with the obstructing windows
649 new.height
= new.bottom
- new.top
- adjust_height
;
650 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
651 if (y_intsect
!= 0) {
652 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
653 /* w_0 is completely to the right of w_j */
654 new.left
= obs
.right
+ 1;
656 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
657 /* w_0 is completely to the left of w_j */
658 new.right
= obs
.left
- 1;
665 /* xcalc needs -7 here, but other apps don't */
666 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
667 *new_width
= new.right
- new.left
;
670 void wUnmaximizeWindow(WWindow
*wwin
)
674 if (!wwin
->flags
.maximized
)
677 if (wwin
->flags
.shaded
) {
678 wwin
->flags
.skip_next_animation
= 1;
679 wUnshadeWindow(wwin
);
682 /* Use old coordinates if they are set, current values otherwise */
683 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
685 /* unMaximusize relative to original position */
686 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
687 x
+= wwin
->frame_x
- wwin
->maximus_x
;
688 y
+= wwin
->frame_y
- wwin
->maximus_y
;
691 wwin
->flags
.maximized
= 0;
692 wwin
->flags
.old_maximized
= 0;
693 wWindowConfigure(wwin
, x
, y
, w
, h
);
694 wWindowSynthConfigureNotify(wwin
);
696 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
699 void wFullscreenWindow(WWindow
*wwin
)
704 if (wwin
->flags
.fullscreen
)
707 wwin
->flags
.fullscreen
= True
;
709 wWindowConfigureBorders(wwin
);
711 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
713 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
714 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
715 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
716 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
718 head
= wGetHeadForWindow(wwin
);
719 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
720 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
722 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
725 void wUnfullscreenWindow(WWindow
*wwin
)
727 if (!wwin
->flags
.fullscreen
)
730 wwin
->flags
.fullscreen
= False
;
732 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
733 if (WFLAGP(wwin
, sunken
)) {
734 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
735 } else if (WFLAGP(wwin
, floating
)) {
736 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
738 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
742 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
743 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
745 wWindowConfigureBorders(wwin
);
747 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
748 wFrameWindowPaint(wwin->frame);
751 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
755 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
757 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
758 float cx
, cy
, cw
, ch
;
759 float xstep
, ystep
, wstep
, hstep
;
762 float angle
, final_angle
, delta
;
764 xstep
= (float)(fx
- x
) / steps
;
765 ystep
= (float)(fy
- y
) / steps
;
766 wstep
= (float)(fw
- w
) / steps
;
767 hstep
= (float)(fh
- h
) / steps
;
774 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
775 delta
= (float)(final_angle
/ FRAMES
);
776 for (angle
= 0;; angle
+= delta
) {
777 if (angle
> final_angle
)
780 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
781 dch
= (ch
/ 2) * cos(angle
);
782 midy
= cy
+ (ch
/ 2);
784 points
[0].x
= cx
+ dx
;
785 points
[0].y
= midy
- dch
;
786 points
[1].x
= cx
+ cw
- dx
;
787 points
[1].y
= points
[0].y
;
788 points
[2].x
= cx
+ cw
+ dx
;
789 points
[2].y
= midy
+ dch
;
790 points
[3].x
= cx
- dx
;
791 points
[3].y
= points
[2].y
;
792 points
[4].x
= points
[0].x
;
793 points
[4].y
= points
[0].y
;
796 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
798 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
800 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
806 if (angle
>= final_angle
)
816 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
818 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
819 float cx
, cy
, cw
, ch
;
820 float xstep
, ystep
, wstep
, hstep
;
822 float angle
, final_angle
, a
, d
, delta
;
829 xstep
= (float)(fx
- x
) / steps
;
830 ystep
= (float)(fy
- y
) / steps
;
831 wstep
= (float)(fw
- w
) / steps
;
832 hstep
= (float)(fh
- h
) / steps
;
839 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
840 delta
= (float)(final_angle
/ FRAMES
);
841 for (angle
= 0;; angle
+= delta
) {
842 if (angle
> final_angle
)
846 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
848 points
[0].x
= cx
+ cos(angle
- a
) * d
;
849 points
[0].y
= cy
+ sin(angle
- a
) * d
;
850 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
851 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
852 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
853 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
854 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
855 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
856 points
[4].x
= cx
+ cos(angle
- a
) * d
;
857 points
[4].y
= cy
+ sin(angle
- a
) * d
;
859 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
861 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
863 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
869 if (angle
>= final_angle
)
878 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
880 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
881 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
882 float xstep
, ystep
, wstep
, hstep
;
885 xstep
= (float)(fx
- x
) / steps
;
886 ystep
= (float)(fy
- y
) / steps
;
887 wstep
= (float)(fw
- w
) / steps
;
888 hstep
= (float)(fh
- h
) / steps
;
890 for (j
= 0; j
< FRAMES
; j
++) {
897 for (i
= 0; i
< steps
; i
++) {
898 for (j
= 0; j
< FRAMES
; j
++) {
899 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
900 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
903 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
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
]);
908 if (j
< FRAMES
- 1) {
922 for (j
= 0; j
< FRAMES
; j
++) {
923 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
926 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
928 for (j
= 0; j
< FRAMES
; j
++) {
929 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
937 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
939 int style
= wPreferences
.iconification_style
; /* Catch the value */
942 if (style
== WIS_NONE
)
945 if (style
== WIS_RANDOM
) {
951 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
953 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
956 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
958 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
962 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
964 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
968 #endif /* ANIMATIONS */
970 static void flushExpose(void)
974 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
975 WMHandleEvent(&tmpev
);
979 static void unmapTransientsFor(WWindow
*wwin
)
983 tmp
= wwin
->screen_ptr
->focused_window
;
985 /* unmap the transients for this transient */
986 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
987 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
988 unmapTransientsFor(tmp
);
989 tmp
->flags
.miniaturized
= 1;
990 if (!tmp
->flags
.shaded
) {
993 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
996 if (!tmp->flags.shaded)
998 wClientSetState(tmp
, IconicState
, None
);
1000 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1006 static void mapTransientsFor(WWindow
*wwin
)
1010 tmp
= wwin
->screen_ptr
->focused_window
;
1012 /* recursively map the transients for this transient */
1013 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1014 && tmp
->icon
== NULL
) {
1015 mapTransientsFor(tmp
);
1016 tmp
->flags
.miniaturized
= 0;
1017 if (!tmp
->flags
.shaded
) {
1020 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1022 tmp
->flags
.semi_focused
= 0;
1024 if (!tmp->flags.shaded)
1026 wClientSetState(tmp
, NormalState
, None
);
1028 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1034 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1041 /* hackish way to detect transient_for cycle */
1042 i
= wwin
->screen_ptr
->window_count
+ 1;
1044 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1045 wwin
= wWindowFor(wwin
->transient_for
);
1048 if (i
== 0 && wwin
) {
1049 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1056 void wIconifyWindow(WWindow
* wwin
)
1058 XWindowAttributes attribs
;
1061 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1062 return; /* the window doesn't exist anymore */
1064 if (wwin
->flags
.miniaturized
)
1065 return; /* already miniaturized */
1067 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1068 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1070 if (owner
&& owner
->flags
.miniaturized
)
1074 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1076 /* if the window is in another workspace, simplify process */
1078 /* icon creation may take a while */
1079 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1080 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1081 GrabModeAsync
, None
, None
, CurrentTime
);
1084 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1085 if (!wwin
->flags
.icon_moved
)
1086 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1088 wwin
->icon
= icon_create_for_wwindow(wwin
);
1089 wwin
->icon
->mapped
= 1;
1092 wwin
->flags
.miniaturized
= 1;
1093 wwin
->flags
.mapped
= 0;
1095 /* unmap transients */
1096 unmapTransientsFor(wwin
);
1099 XUngrabPointer(dpy
, CurrentTime
);
1101 /* let all Expose events arrive so that we can repaint
1102 * something before the animation starts (and the server is grabbed) */
1105 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1106 wClientSetState(wwin
, IconicState
, None
);
1108 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1112 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1113 && !wPreferences
.no_animations
) {
1116 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1119 iw
= wwin
->icon
->core
->width
;
1120 ih
= wwin
->icon
->core
->height
;
1122 if (wwin
->flags
.net_handle_icon
) {
1130 iw
= wwin
->screen_ptr
->scr_width
;
1131 ih
= wwin
->screen_ptr
->scr_height
;
1134 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1135 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1140 wwin
->flags
.skip_next_animation
= 0;
1142 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1143 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1144 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1145 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1147 AddToStackList(wwin
->icon
->core
);
1148 wLowerFrame(wwin
->icon
->core
);
1152 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1155 * It doesn't seem to be working and causes button event hangup
1156 * when deiconifying a transient window.
1157 setupIconGrabs(wwin->icon);
1159 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1160 && wPreferences
.focus_mode
== WKF_CLICK
) {
1165 if (!WFLAGP(tmp
, no_focusable
)
1166 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1167 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1171 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1172 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1173 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1176 if (!wwin
->screen_ptr
->flags
.startup
) {
1177 /* Catch up with events not processed while animation was running */
1178 Window clientwin
= wwin
->client_win
;
1180 ProcessPendingEvents();
1182 /* the window can disappear while ProcessPendingEvents() runs */
1183 if (!wWindowFor(clientwin
)) {
1190 /* maybe we want to do this regardless of net_handle_icon
1191 * it seems to me we might break behaviour this way.
1193 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1194 && !wwin
->flags
.net_handle_icon
)
1195 wIconSelect(wwin
->icon
);
1197 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1199 if (wPreferences
.auto_arrange_icons
)
1200 wArrangeIcons(wwin
->screen_ptr
, True
);
1203 void wDeiconifyWindow(WWindow
*wwin
)
1205 /* Let's avoid changing workspace while deiconifying */
1206 ignore_wks_change
= 1;
1208 /* we're hiding for show_desktop */
1209 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1210 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1213 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1215 if (!wwin
->flags
.miniaturized
)
1218 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1219 WWindow
*owner
= recursiveTransientFor(wwin
);
1221 if (owner
&& owner
->flags
.miniaturized
) {
1222 wDeiconifyWindow(owner
);
1223 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1224 wRaiseFrame(wwin
->frame
->core
);
1229 wwin
->flags
.miniaturized
= 0;
1231 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1232 wwin
->flags
.mapped
= 1;
1234 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1235 /* maybe we want to do this regardless of net_handle_icon
1236 * it seems to me we might break behaviour this way.
1238 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1239 && wwin
->icon
!= NULL
) {
1240 if (wwin
->icon
->selected
)
1241 wIconSelect(wwin
->icon
);
1243 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1247 /* if the window is in another workspace, do it silently */
1248 if (!netwm_hidden
) {
1250 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1251 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1254 if (!wPreferences
.disable_miniwindows
1255 && !wwin
->flags
.net_handle_icon
) {
1258 iw
= wwin
->icon
->core
->width
;
1259 ih
= wwin
->icon
->core
->height
;
1261 if (wwin
->flags
.net_handle_icon
) {
1269 iw
= wwin
->screen_ptr
->scr_width
;
1270 ih
= wwin
->screen_ptr
->scr_height
;
1273 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1274 wwin
->frame_x
, wwin
->frame_y
,
1275 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1277 #endif /* ANIMATIONS */
1278 wwin
->flags
.skip_next_animation
= 0;
1280 if (!wwin
->flags
.shaded
)
1281 XMapWindow(dpy
, wwin
->client_win
);
1283 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1284 wRaiseFrame(wwin
->frame
->core
);
1285 if (!wwin
->flags
.shaded
)
1286 wClientSetState(wwin
, NormalState
, None
);
1288 mapTransientsFor(wwin
);
1291 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1292 && !wwin
->flags
.net_handle_icon
) {
1293 RemoveFromStackList(wwin
->icon
->core
);
1294 /* removeIconGrabs(wwin->icon); */
1295 wIconDestroy(wwin
->icon
);
1299 if (!netwm_hidden
) {
1302 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1305 if (!wwin
->screen_ptr
->flags
.startup
) {
1306 /* Catch up with events not processed while animation was running */
1307 Window clientwin
= wwin
->client_win
;
1309 ProcessPendingEvents();
1311 /* the window can disappear while ProcessPendingEvents() runs */
1312 if (!wWindowFor(clientwin
))
1318 if (wPreferences
.auto_arrange_icons
)
1319 wArrangeIcons(wwin
->screen_ptr
, True
);
1321 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1323 /* In case we were shaded and iconified, also unshade */
1325 wUnshadeWindow(wwin
);
1327 ignore_wks_change
= 0;
1330 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1332 if (wwin
->flags
.miniaturized
) {
1334 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1335 wwin
->icon
->mapped
= 0;
1337 wwin
->flags
.hidden
= 1;
1339 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1343 if (wwin
->flags
.inspector_open
) {
1344 wHideInspectorForWindow(wwin
);
1347 wwin
->flags
.hidden
= 1;
1350 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1354 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1355 !wwin
->flags
.skip_next_animation
&& animate
) {
1356 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1357 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1358 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1361 wwin
->flags
.skip_next_animation
= 0;
1363 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1366 void wHideAll(WScreen
*scr
)
1371 unsigned int wcount
= 0;
1377 menu
= scr
->switch_menu
;
1379 windows
= wmalloc(sizeof(WWindow
*));
1382 for (i
= 0; i
< menu
->entry_no
; i
++) {
1383 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1385 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1388 wwin
= scr
->focused_window
;
1391 windows
[wcount
] = wwin
;
1393 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1399 for (i
= 0; i
< wcount
; i
++) {
1401 if (wwin
->frame
->workspace
== scr
->current_workspace
1402 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1403 && !wwin
->flags
.internal_window
1404 && !WFLAGP(wwin
, no_miniaturizable
)
1406 wwin
->flags
.skip_next_animation
= 1;
1407 wIconifyWindow(wwin
);
1414 void wHideOtherApplications(WWindow
*awin
)
1421 wwin
= awin
->screen_ptr
->focused_window
;
1425 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1426 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1427 && !wwin
->flags
.internal_window
1428 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1430 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1431 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1432 wwin
->flags
.skip_next_animation
= 1;
1433 wIconifyWindow(wwin
);
1435 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1436 tapp
= wApplicationOf(wwin
->main_window
);
1438 tapp
->flags
.skip_next_animation
= 1;
1439 wHideApplication(tapp
);
1441 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1442 wwin
->flags
.skip_next_animation
= 1;
1443 wIconifyWindow(wwin
);
1451 wSetFocusTo(awin->screen_ptr, awin);
1455 void wHideApplication(WApplication
*wapp
)
1463 wwarning("trying to hide a non grouped window");
1466 if (!wapp
->main_window_desc
) {
1467 wwarning("group leader not found for window group");
1470 scr
= wapp
->main_window_desc
->screen_ptr
;
1472 wlist
= scr
->focused_window
;
1476 if (wlist
->main_window
== wapp
->main_window
)
1477 wapp
->last_focused
= wlist
;
1479 wapp
->last_focused
= NULL
;
1481 animate
= !wapp
->flags
.skip_next_animation
;
1484 if (wlist
->main_window
== wapp
->main_window
) {
1485 if (wlist
->flags
.focused
) {
1488 if (wapp
->app_icon
) {
1489 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1490 wapp
->app_icon
->y_pos
, wlist
, animate
);
1494 wlist
= wlist
->prev
;
1497 wapp
->flags
.skip_next_animation
= 0;
1500 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1501 wlist
= scr
->focused_window
;
1503 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1504 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1506 wlist
= wlist
->prev
;
1508 wSetFocusTo(scr
, wlist
);
1510 wSetFocusTo(scr
, NULL
);
1514 wapp
->flags
.hidden
= 1;
1516 if (wPreferences
.auto_arrange_icons
)
1517 wArrangeIcons(scr
, True
);
1521 wAppIconPaint(wapp
->app_icon
);
1525 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1527 if (bringToCurrentWS
)
1528 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1530 wwin
->flags
.hidden
= 0;
1533 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1534 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1535 icon
->core
->width
, icon
->core
->height
,
1536 wwin
->frame_x
, wwin
->frame_y
,
1537 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1540 wwin
->flags
.skip_next_animation
= 0;
1541 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1542 XMapWindow(dpy
, wwin
->client_win
);
1543 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1544 wClientSetState(wwin
, NormalState
, None
);
1545 wwin
->flags
.mapped
= 1;
1546 wRaiseFrame(wwin
->frame
->core
);
1548 if (wwin
->flags
.inspector_open
) {
1549 wUnhideInspectorForWindow(wwin
);
1552 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1555 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1558 WWindow
*wlist
, *next
;
1559 WWindow
*focused
= NULL
;
1565 scr
= wapp
->main_window_desc
->screen_ptr
;
1566 wlist
= scr
->focused_window
;
1570 /* goto beginning of list */
1572 wlist
= wlist
->prev
;
1574 animate
= !wapp
->flags
.skip_next_animation
;
1579 if (wlist
->main_window
== wapp
->main_window
) {
1580 if (wlist
->flags
.focused
)
1582 else if (!focused
|| !focused
->flags
.focused
)
1585 if (wlist
->flags
.miniaturized
) {
1586 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1587 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1588 if (!wlist
->icon
->mapped
) {
1591 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1592 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1593 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1597 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1598 wlist
->icon
->mapped
= 1;
1600 wRaiseFrame(wlist
->icon
->core
);
1602 if (bringToCurrentWS
)
1603 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1604 wlist
->flags
.hidden
= 0;
1605 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1606 wDeiconifyWindow(wlist
);
1608 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1609 } else if (wlist
->flags
.shaded
) {
1610 if (bringToCurrentWS
)
1611 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1612 wlist
->flags
.hidden
= 0;
1613 wRaiseFrame(wlist
->frame
->core
);
1614 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1615 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1617 wUnshadeWindow(wlist
);
1620 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1621 } else if (wlist
->flags
.hidden
) {
1622 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1623 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1626 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1627 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1629 wRaiseFrame(wlist
->frame
->core
);
1635 wapp
->flags
.skip_next_animation
= 0;
1636 wapp
->flags
.hidden
= 0;
1638 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1639 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1640 wSetFocusTo(scr
, wapp
->last_focused
);
1641 } else if (focused
) {
1642 wSetFocusTo(scr
, focused
);
1644 wapp
->last_focused
= NULL
;
1645 if (wPreferences
.auto_arrange_icons
)
1646 wArrangeIcons(scr
, True
);
1649 wAppIconPaint(wapp
->app_icon
);
1653 void wShowAllWindows(WScreen
*scr
)
1655 WWindow
*wwin
, *old_foc
;
1658 old_foc
= wwin
= scr
->focused_window
;
1660 if (!wwin
->flags
.internal_window
&&
1661 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1662 if (wwin
->flags
.miniaturized
) {
1663 wwin
->flags
.skip_next_animation
= 1;
1664 wDeiconifyWindow(wwin
);
1665 } else if (wwin
->flags
.hidden
) {
1666 wapp
= wApplicationOf(wwin
->main_window
);
1668 wUnhideApplication(wapp
, False
, False
);
1670 wwin
->flags
.skip_next_animation
= 1;
1671 wDeiconifyWindow(wwin
);
1677 wSetFocusTo(scr
, old_foc
);
1678 /*wRaiseFrame(old_foc->frame->core); */
1681 void wRefreshDesktop(WScreen
*scr
)
1684 XSetWindowAttributes attr
;
1686 attr
.backing_store
= NotUseful
;
1687 attr
.save_under
= False
;
1688 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1689 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1690 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1691 XMapRaised(dpy
, win
);
1692 XDestroyWindow(dpy
, win
);
1696 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1702 const int heads
= wXineramaHeads(scr
);
1705 int pf
; /* primary axis */
1706 int sf
; /* secondary axis */
1710 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1716 int isize
= wPreferences
.icon_size
;
1718 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1720 for (head
= 0; head
< heads
; ++head
) {
1721 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1722 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1723 vars
[head
].pi
= vars
[head
].si
= 0;
1724 vars
[head
].sx1
= rect
.pos
.x
;
1725 vars
[head
].sy1
= rect
.pos
.y
;
1726 vars
[head
].sw
= rect
.size
.width
;
1727 vars
[head
].sh
= rect
.size
.height
;
1728 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1729 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1730 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1731 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1732 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1733 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1735 /* icon yard boundaries */
1736 if (wPreferences
.icon_yard
& IY_VERT
) {
1737 vars
[head
].pf
= vars
[head
].fullH
;
1738 vars
[head
].sf
= vars
[head
].fullW
;
1740 vars
[head
].pf
= vars
[head
].fullW
;
1741 vars
[head
].sf
= vars
[head
].fullH
;
1743 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1744 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1747 vars
[head
].xo
= vars
[head
].sx1
;
1750 if (wPreferences
.icon_yard
& IY_TOP
) {
1751 vars
[head
].yo
= vars
[head
].sy1
;
1754 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1759 #define X ((wPreferences.icon_yard & IY_VERT) \
1760 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1761 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1763 #define Y ((wPreferences.icon_yard & IY_VERT) \
1764 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1765 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1767 /* arrange application icons */
1768 aicon
= scr
->app_icon_list
;
1769 /* reverse them to avoid unnecessarily sliding of icons */
1770 while (aicon
&& aicon
->next
)
1771 aicon
= aicon
->next
;
1774 if (!aicon
->docked
) {
1775 /* CHECK: can icon be NULL here ? */
1776 /* The intention here is to place the AppIcon on the head that
1777 * contains most of the applications _main_ window. */
1778 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1780 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1782 if (!wPreferences
.no_animations
)
1783 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1784 #endif /* ANIMATIONS */
1786 wAppIconMove(aicon
, X
, Y
);
1788 if (vars
[head
].pi
>= vars
[head
].pf
) {
1793 aicon
= aicon
->prev
;
1796 /* arrange miniwindows */
1797 wwin
= scr
->focused_window
;
1798 /* reverse them to avoid unnecessarily shuffling */
1799 while (wwin
&& wwin
->prev
)
1803 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1804 (wwin
->frame
->workspace
== scr
->current_workspace
||
1805 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1807 head
= wGetHeadForWindow(wwin
);
1809 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1810 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1811 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1817 if (vars
[head
].pi
>= vars
[head
].pf
) {
1824 wwin
->flags
.icon_moved
= 0;
1826 /* we reversed the order, so we use next */
1833 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1835 WScreen
*scr
= wwin
->screen_ptr
;
1838 wwin
->flags
.selected
= 1;
1839 if (wwin
->frame
->selected_border_pixel
)
1840 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1842 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1844 if (!HAS_BORDER(wwin
)) {
1845 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1848 if (!scr
->selected_windows
)
1849 scr
->selected_windows
= WMCreateArray(4);
1850 WMAddToArray(scr
->selected_windows
, wwin
);
1852 wwin
->flags
.selected
= 0;
1853 if (wwin
->frame
->border_pixel
)
1854 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1856 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1858 if (!HAS_BORDER(wwin
)) {
1859 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1862 if (scr
->selected_windows
) {
1863 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1868 void wMakeWindowVisible(WWindow
*wwin
)
1870 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1871 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1873 if (wwin
->flags
.shaded
) {
1874 wUnshadeWindow(wwin
);
1876 if (wwin
->flags
.hidden
) {
1879 app
= wApplicationOf(wwin
->main_window
);
1881 /* trick to get focus to this window */
1882 app
->last_focused
= wwin
;
1883 wUnhideApplication(app
, False
, False
);
1886 if (wwin
->flags
.miniaturized
) {
1887 wDeiconifyWindow(wwin
);
1889 if (!WFLAGP(wwin
, no_focusable
))
1890 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1891 wRaiseFrame(wwin
->frame
->core
);
1896 * Do the animation while shading (called with what = SHADE)
1897 * or unshading (what = UNSHADE).
1900 static void shade_animate(WWindow
*wwin
, Bool what
)
1903 time_t time0
= time(NULL
);
1905 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1910 if (!wwin
->screen_ptr
->flags
.startup
) {
1911 /* do the shading animation */
1912 h
= wwin
->frame
->core
->height
;
1913 s
= h
/ SHADE_STEPS
;
1916 w
= wwin
->frame
->core
->width
;
1917 y
= wwin
->frame
->top_width
;
1918 while (h
> wwin
->frame
->top_width
+ 1) {
1919 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1920 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1923 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1926 if (SHADE_DELAY
> 0) {
1927 wusleep(SHADE_DELAY
* 1000L);
1934 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1939 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1940 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1941 s
= abs(y
) / SHADE_STEPS
;
1944 w
= wwin
->frame
->core
->width
;
1945 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1947 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1948 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1949 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1951 if (SHADE_DELAY
> 0) {
1952 wusleep(SHADE_DELAY
* 2000L / 3);
1959 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1963 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);