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 LastFocusChange
;
57 extern Atom _XA_WM_TAKE_FOCUS
;
59 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
60 unsigned int *new_width
, unsigned int *new_height
);
61 static void save_old_geometry(WWindow
*wwin
, int directions
);
63 /******* Local Variables *******/
69 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
70 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
71 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
72 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
73 SHADE_STEPS_US
, SHADE_DELAY_US
}};
77 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
78 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
80 static int compareTimes(Time t1
, Time t2
)
86 return (diff
< 60000) ? 1 : -1;
90 static void shade_animate(WWindow
*wwin
, Bool what
);
92 static void shade_animate(WWindow
*wwin
, Bool what
) { }
96 *----------------------------------------------------------------------
98 * Changes the window focus to the one passed as argument.
99 * If the window to focus is not already focused, it will be brought
100 * to the head of the list of windows. Previously focused window is
104 * Window list may be reordered and the window focus is changed.
106 *----------------------------------------------------------------------
108 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
110 static WScreen
*old_scr
= NULL
;
112 WWindow
*old_focused
;
113 WWindow
*focused
= scr
->focused_window
;
114 Time timestamp
= w_global
.timestamp
.last_event
;
115 WApplication
*oapp
= NULL
, *napp
= NULL
;
118 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
124 old_focused
= old_scr
->focused_window
;
126 LastFocusChange
= timestamp
;
129 oapp
= wApplicationOf(old_focused
->main_window
);
132 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
134 wWindowUnfocus(old_focused
);
137 wAppMenuUnmap(oapp
->menu
);
138 if (wPreferences
.highlight_active_app
)
139 wApplicationDeactivate(oapp
);
142 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
146 if (old_scr
!= scr
&& old_focused
)
147 wWindowUnfocus(old_focused
);
149 wasfocused
= wwin
->flags
.focused
;
150 napp
= wApplicationOf(wwin
->main_window
);
152 /* remember last workspace where the app has been */
154 napp
->last_workspace
= wwin
->frame
->workspace
;
156 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
157 /* install colormap if colormap mode is lock mode */
158 if (wPreferences
.colormap_mode
== WCM_CLICK
)
159 wColormapInstallForWindow(scr
, wwin
);
161 /* set input focus */
162 switch (wwin
->focus_mode
) {
164 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
167 case WFM_LOCALLY_ACTIVE
:
168 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
170 case WFM_GLOBALLY_ACTIVE
:
175 if (wwin
->protocols
.TAKE_FOCUS
)
176 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
180 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
183 if (WFLAGP(wwin
, no_focusable
))
186 /* if this is not the focused window focus it */
187 if (focused
!= wwin
) {
188 /* change the focus window list order */
190 wwin
->prev
->next
= wwin
->next
;
193 wwin
->next
->prev
= wwin
->prev
;
195 wwin
->prev
= focused
;
196 focused
->next
= wwin
;
198 scr
->focused_window
= wwin
;
200 if (oapp
&& oapp
!= napp
) {
201 wAppMenuUnmap(oapp
->menu
);
202 if (wPreferences
.highlight_active_app
)
203 wApplicationDeactivate(oapp
);
207 wWindowFocus(wwin
, focused
);
209 if (napp
&& !wasfocused
) {
211 wUserMenuRefreshInstances(napp
->menu
, wwin
);
212 #endif /* USER_MENU */
214 if (wwin
->flags
.mapped
)
215 wAppMenuMap(napp
->menu
, wwin
);
217 if (napp
&& wPreferences
.highlight_active_app
)
218 wApplicationActivate(napp
);
224 void wShadeWindow(WWindow
*wwin
)
227 if (wwin
->flags
.shaded
)
230 XLowerWindow(dpy
, wwin
->client_win
);
231 shade_animate(wwin
, SHADE
);
233 wwin
->flags
.skip_next_animation
= 0;
234 wwin
->flags
.shaded
= 1;
235 wwin
->flags
.mapped
= 0;
236 /* prevent window withdrawal when getting UnmapNotify */
237 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
238 XUnmapWindow(dpy
, wwin
->client_win
);
239 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
241 /* for the client it's just like iconification */
242 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
244 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
245 wWindowSynthConfigureNotify(wwin
);
248 wClientSetState(wwin, IconicState, None);
251 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
254 if (!wwin
->screen_ptr
->flags
.startup
) {
255 /* Catch up with events not processed while animation was running */
256 ProcessPendingEvents();
261 void wUnshadeWindow(WWindow
*wwin
)
264 if (!wwin
->flags
.shaded
)
267 wwin
->flags
.shaded
= 0;
268 wwin
->flags
.mapped
= 1;
269 XMapWindow(dpy
, wwin
->client_win
);
271 shade_animate(wwin
, UNSHADE
);
273 wwin
->flags
.skip_next_animation
= 0;
274 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
275 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
277 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
278 wWindowSynthConfigureNotify(wwin
);
280 /* if the window is focused, set the focus again as it was disabled during
282 if (wwin
->flags
.focused
)
283 wSetFocusTo(wwin
->screen_ptr
, wwin
);
285 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
288 /* Set the old coordinates using the current values */
289 static void save_old_geometry(WWindow
*wwin
, int directions
)
291 /* never been saved? */
292 if (! wwin
->old_geometry
.width
)
293 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
294 if (! wwin
->old_geometry
.height
)
295 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
297 if (directions
& SAVE_GEOMETRY_X
)
298 wwin
->old_geometry
.x
= wwin
->frame_x
;
299 if (directions
& SAVE_GEOMETRY_Y
)
300 wwin
->old_geometry
.y
= wwin
->frame_y
;
301 if (directions
& SAVE_GEOMETRY_WIDTH
)
302 wwin
->old_geometry
.width
= wwin
->client
.width
;
303 if (directions
& SAVE_GEOMETRY_HEIGHT
)
304 wwin
->old_geometry
.height
= wwin
->client
.height
;
307 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
309 WMRect old_geom_rect
;
313 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
314 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
315 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
316 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
317 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
318 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
319 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
322 /* Remember geometry for unmaximizing */
323 void update_saved_geometry(WWindow
*wwin
)
325 /* NOT if we aren't already maximized
326 * we'll save geometry when maximizing */
327 if (!wwin
->flags
.maximized
)
330 /* NOT if we are fully maximized */
331 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
332 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
333 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
336 /* save the co-ordinate in the axis in which we AREN'T maximized */
337 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
338 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
339 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
340 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
343 void wMaximizeWindow(WWindow
*wwin
, int directions
)
345 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
350 unsigned int maximus_width
= 0;
351 unsigned int maximus_height
= 0;
352 WArea usableArea
, totalArea
;
356 if (!IS_RESIZABLE(wwin
))
359 if (!HAS_BORDER(wwin
))
362 /* the size to adjust the geometry */
363 adj_size
= wwin
->screen_ptr
->frame_border_width
* 2 * has_border
;
365 /* save old coordinates before we change the current values */
366 if (!wwin
->flags
.maximized
)
367 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
369 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
370 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
373 usableArea
= totalArea
;
375 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
376 WScreen
*scr
= wwin
->screen_ptr
;
379 if (directions
& MAX_KEYBOARD
)
380 head
= wGetHeadForWindow(wwin
);
382 head
= wGetHeadForPointerLocation(scr
);
384 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
387 /* Only save directions, not kbd or xinerama hints */
388 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
390 if (WFLAGP(wwin
, full_maximize
)) {
391 usableArea
= totalArea
;
393 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
394 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
396 if (wwin
->flags
.shaded
) {
397 wwin
->flags
.skip_next_animation
= 1;
398 wUnshadeWindow(wwin
);
401 if (directions
& MAX_MAXIMUS
) {
402 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
403 new_width
= maximus_width
- adj_size
;
404 new_height
= maximus_height
- adj_size
;
407 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
408 new_height
+= wwin
->frame
->bottom_width
- 1;
409 new_y
-= wwin
->frame
->top_width
;
412 wwin
->maximus_x
= new_x
;
413 wwin
->maximus_y
= new_y
;
414 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
416 /* set default values if no option set then */
417 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
418 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
419 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
421 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
422 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
423 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
426 /* left|right position */
427 if (directions
& MAX_LEFTHALF
) {
428 new_width
= half_scr_width
- adj_size
;
429 new_x
= usableArea
.x1
;
430 } else if (directions
& MAX_RIGHTHALF
) {
431 new_width
= half_scr_width
- adj_size
;
432 new_x
= usableArea
.x1
+ half_scr_width
;
434 /* top|bottom position */
435 if (directions
& MAX_TOPHALF
) {
436 new_height
= half_scr_height
- adj_size
;
437 new_y
= usableArea
.y1
;
438 } else if (directions
& MAX_BOTTOMHALF
) {
439 new_height
= half_scr_height
- adj_size
;
440 new_y
= usableArea
.y1
+ half_scr_height
;
443 /* vertical|horizontal position */
444 if (directions
& MAX_HORIZONTAL
) {
445 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
446 new_x
= usableArea
.x1
;
448 if (directions
& MAX_VERTICAL
) {
449 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
450 new_y
= usableArea
.y1
;
451 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
452 new_y
-= wwin
->frame
->top_width
;
456 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
457 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
459 /* set maximization state */
460 wwin
->flags
.maximized
= directions
;
461 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
462 wwin
->flags
.maximized
= MAX_MAXIMUS
;
464 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
466 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
467 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
469 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
470 wWindowSynthConfigureNotify(wwin
);
472 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
475 /* generic (un)maximizer */
476 void handleMaximize(WWindow
*wwin
, int directions
)
478 int current
= wwin
->flags
.maximized
;
479 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
480 int effective
= requested
^ current
;
481 int flags
= directions
& ~requested
;
484 /* allow wMaximizeWindow to restore the Maximusized size */
485 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
486 !(requested
& MAX_MAXIMUS
))
487 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
489 wUnmaximizeWindow(wwin
);
490 /* these alone mean vertical|horizontal toggle */
491 } else if ((effective
== MAX_LEFTHALF
) ||
492 (effective
== MAX_RIGHTHALF
) ||
493 (effective
== MAX_TOPHALF
) ||
494 (effective
== MAX_BOTTOMHALF
))
495 wUnmaximizeWindow(wwin
);
497 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
498 (requested
== MAX_MAXIMUS
))
499 effective
= requested
;
501 if (requested
& MAX_LEFTHALF
) {
502 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
503 effective
|= MAX_VERTICAL
;
505 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
506 effective
|= MAX_LEFTHALF
;
507 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
508 } else if (requested
& MAX_RIGHTHALF
) {
509 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
510 effective
|= MAX_VERTICAL
;
512 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
513 effective
|= MAX_RIGHTHALF
;
514 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
516 if (requested
& MAX_TOPHALF
) {
517 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
518 effective
|= MAX_HORIZONTAL
;
520 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
521 effective
|= MAX_TOPHALF
;
522 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
523 } else if (requested
& MAX_BOTTOMHALF
) {
524 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
525 effective
|= MAX_HORIZONTAL
;
527 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
528 effective
|= MAX_BOTTOMHALF
;
529 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
531 if (requested
& MAX_HORIZONTAL
)
532 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
533 if (requested
& MAX_VERTICAL
)
534 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
535 effective
&= ~MAX_MAXIMUS
;
537 wMaximizeWindow(wwin
, effective
| flags
);
541 /* the window boundary coordinates */
551 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
553 obs
->left
= wwin
->frame_x
;
554 obs
->top
= wwin
->frame_y
;
555 obs
->width
= wwin
->frame
->core
->width
;
556 obs
->height
= wwin
->frame
->core
->height
;
557 obs
->bottom
= obs
->top
+ obs
->height
;
558 obs
->right
= obs
->left
+ obs
->width
;
562 * Maximus: tiled maximization (maximize without overlapping other windows)
564 * The original window 'orig' will be maximized to new coordinates 'new'.
565 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
567 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
568 unsigned int *new_width
, unsigned int *new_height
)
571 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
572 short int adjust_height
;
573 int x_intsect
, y_intsect
;
574 /* the obstructing, original and new windows */
575 win_coords obs
, orig
, new;
577 /* set the original coordinate positions of the window to be Maximumized */
578 if (wwin
->flags
.maximized
) {
579 /* window is already maximized; consider original geometry */
580 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
581 orig
.bottom
= orig
.top
+ orig
.height
;
582 orig
.right
= orig
.left
+ orig
.width
;
585 set_window_coords(wwin
, &orig
);
587 /* Try to fully maximize first, then readjust later */
588 new.left
= usableArea
.x1
;
589 new.right
= usableArea
.x2
;
590 new.top
= usableArea
.y1
;
591 new.bottom
= usableArea
.y2
;
593 if (HAS_TITLEBAR(wwin
))
594 tbar_height_0
= TITLEBAR_HEIGHT
;
595 if (HAS_RESIZEBAR(wwin
))
596 rbar_height_0
= RESIZEBAR_HEIGHT
;
597 if (HAS_BORDER(wwin
))
598 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
600 /* the length to be subtracted if the window has titlebar, etc */
601 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
604 /* The focused window is always the last in the list */
606 /* ignore windows in other workspaces etc */
607 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
608 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
614 /* Set the coordinates of obstructing window */
615 set_window_coords(tmp
, &obs
);
617 /* Try to maximize in the y direction first */
618 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
619 if (x_intsect
!= 0) {
620 /* TODO: Consider the case when coords are equal */
621 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
622 /* w_0 is below the bottom of w_j */
623 new.top
= obs
.bottom
+ 1;
625 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
626 /* The bottom of w_0 is above the top of w_j */
627 new.bottom
= obs
.top
- 1;
634 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
635 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
641 set_window_coords(tmp
, &obs
);
644 * Use the new.top and new.height instead of original values
645 * as they may have different intersections with the obstructing windows
647 new.height
= new.bottom
- new.top
- adjust_height
;
648 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
649 if (y_intsect
!= 0) {
650 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
651 /* w_0 is completely to the right of w_j */
652 new.left
= obs
.right
+ 1;
654 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
655 /* w_0 is completely to the left of w_j */
656 new.right
= obs
.left
- 1;
663 /* xcalc needs -7 here, but other apps don't */
664 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
665 *new_width
= new.right
- new.left
;
668 void wUnmaximizeWindow(WWindow
*wwin
)
672 if (!wwin
->flags
.maximized
)
675 if (wwin
->flags
.shaded
) {
676 wwin
->flags
.skip_next_animation
= 1;
677 wUnshadeWindow(wwin
);
680 /* Use old coordinates if they are set, current values otherwise */
681 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
683 /* unMaximusize relative to original position */
684 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
685 x
+= wwin
->frame_x
- wwin
->maximus_x
;
686 y
+= wwin
->frame_y
- wwin
->maximus_y
;
689 wwin
->flags
.maximized
= 0;
690 wwin
->flags
.old_maximized
= 0;
691 wWindowConfigure(wwin
, x
, y
, w
, h
);
692 wWindowSynthConfigureNotify(wwin
);
694 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
697 void wFullscreenWindow(WWindow
*wwin
)
702 if (wwin
->flags
.fullscreen
)
705 wwin
->flags
.fullscreen
= True
;
707 wWindowConfigureBorders(wwin
);
709 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
711 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
712 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
713 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
714 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
716 head
= wGetHeadForWindow(wwin
);
717 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
718 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
720 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
723 void wUnfullscreenWindow(WWindow
*wwin
)
725 if (!wwin
->flags
.fullscreen
)
728 wwin
->flags
.fullscreen
= False
;
730 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
731 if (WFLAGP(wwin
, sunken
)) {
732 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
733 } else if (WFLAGP(wwin
, floating
)) {
734 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
736 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
740 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
741 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
743 wWindowConfigureBorders(wwin
);
745 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
746 wFrameWindowPaint(wwin->frame);
749 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
753 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
755 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
756 float cx
, cy
, cw
, ch
;
757 float xstep
, ystep
, wstep
, hstep
;
760 float angle
, final_angle
, delta
;
762 xstep
= (float)(fx
- x
) / steps
;
763 ystep
= (float)(fy
- y
) / steps
;
764 wstep
= (float)(fw
- w
) / steps
;
765 hstep
= (float)(fh
- h
) / steps
;
772 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
773 delta
= (float)(final_angle
/ FRAMES
);
774 for (angle
= 0;; angle
+= delta
) {
775 if (angle
> final_angle
)
778 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
779 dch
= (ch
/ 2) * cos(angle
);
780 midy
= cy
+ (ch
/ 2);
782 points
[0].x
= cx
+ dx
;
783 points
[0].y
= midy
- dch
;
784 points
[1].x
= cx
+ cw
- dx
;
785 points
[1].y
= points
[0].y
;
786 points
[2].x
= cx
+ cw
+ dx
;
787 points
[2].y
= midy
+ dch
;
788 points
[3].x
= cx
- dx
;
789 points
[3].y
= points
[2].y
;
790 points
[4].x
= points
[0].x
;
791 points
[4].y
= points
[0].y
;
794 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
796 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
798 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
804 if (angle
>= final_angle
)
814 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
816 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
817 float cx
, cy
, cw
, ch
;
818 float xstep
, ystep
, wstep
, hstep
;
820 float angle
, final_angle
, a
, d
, delta
;
827 xstep
= (float)(fx
- x
) / steps
;
828 ystep
= (float)(fy
- y
) / steps
;
829 wstep
= (float)(fw
- w
) / steps
;
830 hstep
= (float)(fh
- h
) / steps
;
837 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
838 delta
= (float)(final_angle
/ FRAMES
);
839 for (angle
= 0;; angle
+= delta
) {
840 if (angle
> final_angle
)
844 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
846 points
[0].x
= cx
+ cos(angle
- a
) * d
;
847 points
[0].y
= cy
+ sin(angle
- a
) * d
;
848 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
849 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
850 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
851 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
852 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
853 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
854 points
[4].x
= cx
+ cos(angle
- a
) * d
;
855 points
[4].y
= cy
+ sin(angle
- a
) * d
;
857 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
859 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
861 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
867 if (angle
>= final_angle
)
876 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
878 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
879 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
880 float xstep
, ystep
, wstep
, hstep
;
883 xstep
= (float)(fx
- x
) / steps
;
884 ystep
= (float)(fy
- y
) / steps
;
885 wstep
= (float)(fw
- w
) / steps
;
886 hstep
= (float)(fh
- h
) / steps
;
888 for (j
= 0; j
< FRAMES
; j
++) {
895 for (i
= 0; i
< steps
; i
++) {
896 for (j
= 0; j
< FRAMES
; j
++) {
897 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
898 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
901 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
903 for (j
= 0; j
< FRAMES
; j
++) {
904 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
905 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
906 if (j
< FRAMES
- 1) {
920 for (j
= 0; j
< FRAMES
; j
++) {
921 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
924 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
926 for (j
= 0; j
< FRAMES
; j
++) {
927 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
935 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
937 int style
= wPreferences
.iconification_style
; /* Catch the value */
940 if (style
== WIS_NONE
)
943 if (style
== WIS_RANDOM
) {
949 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
951 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
954 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
956 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
960 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
962 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
966 #endif /* ANIMATIONS */
968 static void flushExpose(void)
972 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
973 WMHandleEvent(&tmpev
);
977 static void unmapTransientsFor(WWindow
*wwin
)
981 tmp
= wwin
->screen_ptr
->focused_window
;
983 /* unmap the transients for this transient */
984 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
985 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
986 unmapTransientsFor(tmp
);
987 tmp
->flags
.miniaturized
= 1;
988 if (!tmp
->flags
.shaded
) {
991 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
994 if (!tmp->flags.shaded)
996 wClientSetState(tmp
, IconicState
, None
);
998 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1004 static void mapTransientsFor(WWindow
*wwin
)
1008 tmp
= wwin
->screen_ptr
->focused_window
;
1010 /* recursively map the transients for this transient */
1011 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1012 && tmp
->icon
== NULL
) {
1013 mapTransientsFor(tmp
);
1014 tmp
->flags
.miniaturized
= 0;
1015 if (!tmp
->flags
.shaded
) {
1018 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1020 tmp
->flags
.semi_focused
= 0;
1022 if (!tmp->flags.shaded)
1024 wClientSetState(tmp
, NormalState
, None
);
1026 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1032 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1039 /* hackish way to detect transient_for cycle */
1040 i
= wwin
->screen_ptr
->window_count
+ 1;
1042 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1043 wwin
= wWindowFor(wwin
->transient_for
);
1046 if (i
== 0 && wwin
) {
1047 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1054 void wIconifyWindow(WWindow
* wwin
)
1056 XWindowAttributes attribs
;
1059 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1060 return; /* the window doesn't exist anymore */
1062 if (wwin
->flags
.miniaturized
)
1063 return; /* already miniaturized */
1065 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1066 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1068 if (owner
&& owner
->flags
.miniaturized
)
1072 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1074 /* if the window is in another workspace, simplify process */
1076 /* icon creation may take a while */
1077 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1078 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1079 GrabModeAsync
, None
, None
, CurrentTime
);
1082 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1083 if (!wwin
->flags
.icon_moved
)
1084 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1086 wwin
->icon
= icon_create_for_wwindow(wwin
);
1087 wwin
->icon
->mapped
= 1;
1090 wwin
->flags
.miniaturized
= 1;
1091 wwin
->flags
.mapped
= 0;
1093 /* unmap transients */
1094 unmapTransientsFor(wwin
);
1097 XUngrabPointer(dpy
, CurrentTime
);
1099 /* let all Expose events arrive so that we can repaint
1100 * something before the animation starts (and the server is grabbed) */
1103 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1104 wClientSetState(wwin
, IconicState
, None
);
1106 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1110 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1111 && !wPreferences
.no_animations
) {
1114 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1117 iw
= wwin
->icon
->core
->width
;
1118 ih
= wwin
->icon
->core
->height
;
1120 if (wwin
->flags
.net_handle_icon
) {
1128 iw
= wwin
->screen_ptr
->scr_width
;
1129 ih
= wwin
->screen_ptr
->scr_height
;
1132 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1133 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1138 wwin
->flags
.skip_next_animation
= 0;
1140 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1141 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1142 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1143 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1145 AddToStackList(wwin
->icon
->core
);
1146 wLowerFrame(wwin
->icon
->core
);
1150 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1153 * It doesn't seem to be working and causes button event hangup
1154 * when deiconifying a transient window.
1155 setupIconGrabs(wwin->icon);
1157 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1158 && wPreferences
.focus_mode
== WKF_CLICK
) {
1163 if (!WFLAGP(tmp
, no_focusable
)
1164 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1165 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1169 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1170 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1171 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1174 if (!wwin
->screen_ptr
->flags
.startup
) {
1175 /* Catch up with events not processed while animation was running */
1176 Window clientwin
= wwin
->client_win
;
1178 ProcessPendingEvents();
1180 /* the window can disappear while ProcessPendingEvents() runs */
1181 if (!wWindowFor(clientwin
)) {
1188 /* maybe we want to do this regardless of net_handle_icon
1189 * it seems to me we might break behaviour this way.
1191 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1192 && !wwin
->flags
.net_handle_icon
)
1193 wIconSelect(wwin
->icon
);
1195 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1197 if (wPreferences
.auto_arrange_icons
)
1198 wArrangeIcons(wwin
->screen_ptr
, True
);
1201 void wDeiconifyWindow(WWindow
*wwin
)
1203 /* Let's avoid changing workspace while deiconifying */
1204 ignore_wks_change
= 1;
1206 /* we're hiding for show_desktop */
1207 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1208 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1211 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1213 if (!wwin
->flags
.miniaturized
) {
1214 ignore_wks_change
= 0;
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
);
1225 ignore_wks_change
= 0;
1230 wwin
->flags
.miniaturized
= 0;
1232 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1233 wwin
->flags
.mapped
= 1;
1235 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1236 /* maybe we want to do this regardless of net_handle_icon
1237 * it seems to me we might break behaviour this way.
1239 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1240 && wwin
->icon
!= NULL
) {
1241 if (wwin
->icon
->selected
)
1242 wIconSelect(wwin
->icon
);
1244 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1248 /* if the window is in another workspace, do it silently */
1249 if (!netwm_hidden
) {
1251 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1252 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1255 if (!wPreferences
.disable_miniwindows
1256 && !wwin
->flags
.net_handle_icon
) {
1259 iw
= wwin
->icon
->core
->width
;
1260 ih
= wwin
->icon
->core
->height
;
1262 if (wwin
->flags
.net_handle_icon
) {
1270 iw
= wwin
->screen_ptr
->scr_width
;
1271 ih
= wwin
->screen_ptr
->scr_height
;
1274 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1275 wwin
->frame_x
, wwin
->frame_y
,
1276 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1278 #endif /* ANIMATIONS */
1279 wwin
->flags
.skip_next_animation
= 0;
1281 if (!wwin
->flags
.shaded
)
1282 XMapWindow(dpy
, wwin
->client_win
);
1284 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1285 wRaiseFrame(wwin
->frame
->core
);
1286 if (!wwin
->flags
.shaded
)
1287 wClientSetState(wwin
, NormalState
, None
);
1289 mapTransientsFor(wwin
);
1292 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1293 && !wwin
->flags
.net_handle_icon
) {
1294 RemoveFromStackList(wwin
->icon
->core
);
1295 /* removeIconGrabs(wwin->icon); */
1296 wIconDestroy(wwin
->icon
);
1300 if (!netwm_hidden
) {
1303 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1306 if (!wwin
->screen_ptr
->flags
.startup
) {
1307 /* Catch up with events not processed while animation was running */
1308 Window clientwin
= wwin
->client_win
;
1310 ProcessPendingEvents();
1312 /* the window can disappear while ProcessPendingEvents() runs */
1313 if (!wWindowFor(clientwin
)) {
1314 ignore_wks_change
= 0;
1321 if (wPreferences
.auto_arrange_icons
)
1322 wArrangeIcons(wwin
->screen_ptr
, True
);
1324 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1326 /* In case we were shaded and iconified, also unshade */
1328 wUnshadeWindow(wwin
);
1330 ignore_wks_change
= 0;
1333 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1335 if (wwin
->flags
.miniaturized
) {
1337 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1338 wwin
->icon
->mapped
= 0;
1340 wwin
->flags
.hidden
= 1;
1342 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1346 if (wwin
->flags
.inspector_open
) {
1347 wHideInspectorForWindow(wwin
);
1350 wwin
->flags
.hidden
= 1;
1353 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1357 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1358 !wwin
->flags
.skip_next_animation
&& animate
) {
1359 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1360 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1361 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1364 wwin
->flags
.skip_next_animation
= 0;
1366 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1369 void wHideAll(WScreen
*scr
)
1374 unsigned int wcount
= 0;
1380 menu
= scr
->switch_menu
;
1382 windows
= wmalloc(sizeof(WWindow
*));
1385 for (i
= 0; i
< menu
->entry_no
; i
++) {
1386 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1388 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1391 wwin
= scr
->focused_window
;
1394 windows
[wcount
] = wwin
;
1396 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1402 for (i
= 0; i
< wcount
; i
++) {
1404 if (wwin
->frame
->workspace
== scr
->current_workspace
1405 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1406 && !wwin
->flags
.internal_window
1407 && !WFLAGP(wwin
, no_miniaturizable
)
1409 wwin
->flags
.skip_next_animation
= 1;
1410 wIconifyWindow(wwin
);
1417 void wHideOtherApplications(WWindow
*awin
)
1424 wwin
= awin
->screen_ptr
->focused_window
;
1428 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1429 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1430 && !wwin
->flags
.internal_window
1431 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1433 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1434 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1435 wwin
->flags
.skip_next_animation
= 1;
1436 wIconifyWindow(wwin
);
1438 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1439 tapp
= wApplicationOf(wwin
->main_window
);
1441 tapp
->flags
.skip_next_animation
= 1;
1442 wHideApplication(tapp
);
1444 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1445 wwin
->flags
.skip_next_animation
= 1;
1446 wIconifyWindow(wwin
);
1454 wSetFocusTo(awin->screen_ptr, awin);
1458 void wHideApplication(WApplication
*wapp
)
1466 wwarning("trying to hide a non grouped window");
1469 if (!wapp
->main_window_desc
) {
1470 wwarning("group leader not found for window group");
1473 scr
= wapp
->main_window_desc
->screen_ptr
;
1475 wlist
= scr
->focused_window
;
1479 if (wlist
->main_window
== wapp
->main_window
)
1480 wapp
->last_focused
= wlist
;
1482 wapp
->last_focused
= NULL
;
1484 animate
= !wapp
->flags
.skip_next_animation
;
1487 if (wlist
->main_window
== wapp
->main_window
) {
1488 if (wlist
->flags
.focused
) {
1491 if (wapp
->app_icon
) {
1492 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1493 wapp
->app_icon
->y_pos
, wlist
, animate
);
1497 wlist
= wlist
->prev
;
1500 wapp
->flags
.skip_next_animation
= 0;
1503 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1504 wlist
= scr
->focused_window
;
1506 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1507 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1509 wlist
= wlist
->prev
;
1511 wSetFocusTo(scr
, wlist
);
1513 wSetFocusTo(scr
, NULL
);
1517 wapp
->flags
.hidden
= 1;
1519 if (wPreferences
.auto_arrange_icons
)
1520 wArrangeIcons(scr
, True
);
1524 wAppIconPaint(wapp
->app_icon
);
1528 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1530 if (bringToCurrentWS
)
1531 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1533 wwin
->flags
.hidden
= 0;
1536 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1537 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1538 icon
->core
->width
, icon
->core
->height
,
1539 wwin
->frame_x
, wwin
->frame_y
,
1540 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1543 wwin
->flags
.skip_next_animation
= 0;
1544 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1545 XMapWindow(dpy
, wwin
->client_win
);
1546 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1547 wClientSetState(wwin
, NormalState
, None
);
1548 wwin
->flags
.mapped
= 1;
1549 wRaiseFrame(wwin
->frame
->core
);
1551 if (wwin
->flags
.inspector_open
) {
1552 wUnhideInspectorForWindow(wwin
);
1555 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1558 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1561 WWindow
*wlist
, *next
;
1562 WWindow
*focused
= NULL
;
1568 scr
= wapp
->main_window_desc
->screen_ptr
;
1569 wlist
= scr
->focused_window
;
1573 /* goto beginning of list */
1575 wlist
= wlist
->prev
;
1577 animate
= !wapp
->flags
.skip_next_animation
;
1582 if (wlist
->main_window
== wapp
->main_window
) {
1583 if (wlist
->flags
.focused
)
1585 else if (!focused
|| !focused
->flags
.focused
)
1588 if (wlist
->flags
.miniaturized
) {
1589 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1590 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1591 if (!wlist
->icon
->mapped
) {
1594 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1595 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1596 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1600 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1601 wlist
->icon
->mapped
= 1;
1603 wRaiseFrame(wlist
->icon
->core
);
1605 if (bringToCurrentWS
)
1606 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1607 wlist
->flags
.hidden
= 0;
1608 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1609 wDeiconifyWindow(wlist
);
1611 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1612 } else if (wlist
->flags
.shaded
) {
1613 if (bringToCurrentWS
)
1614 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1615 wlist
->flags
.hidden
= 0;
1616 wRaiseFrame(wlist
->frame
->core
);
1617 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1618 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1620 wUnshadeWindow(wlist
);
1623 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1624 } else if (wlist
->flags
.hidden
) {
1625 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1626 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1629 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1630 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1632 wRaiseFrame(wlist
->frame
->core
);
1638 wapp
->flags
.skip_next_animation
= 0;
1639 wapp
->flags
.hidden
= 0;
1641 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1642 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1643 wSetFocusTo(scr
, wapp
->last_focused
);
1644 } else if (focused
) {
1645 wSetFocusTo(scr
, focused
);
1647 wapp
->last_focused
= NULL
;
1648 if (wPreferences
.auto_arrange_icons
)
1649 wArrangeIcons(scr
, True
);
1652 wAppIconPaint(wapp
->app_icon
);
1656 void wShowAllWindows(WScreen
*scr
)
1658 WWindow
*wwin
, *old_foc
;
1661 old_foc
= wwin
= scr
->focused_window
;
1663 if (!wwin
->flags
.internal_window
&&
1664 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1665 if (wwin
->flags
.miniaturized
) {
1666 wwin
->flags
.skip_next_animation
= 1;
1667 wDeiconifyWindow(wwin
);
1668 } else if (wwin
->flags
.hidden
) {
1669 wapp
= wApplicationOf(wwin
->main_window
);
1671 wUnhideApplication(wapp
, False
, False
);
1673 wwin
->flags
.skip_next_animation
= 1;
1674 wDeiconifyWindow(wwin
);
1680 wSetFocusTo(scr
, old_foc
);
1681 /*wRaiseFrame(old_foc->frame->core); */
1684 void wRefreshDesktop(WScreen
*scr
)
1687 XSetWindowAttributes attr
;
1689 attr
.backing_store
= NotUseful
;
1690 attr
.save_under
= False
;
1691 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1692 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1693 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1694 XMapRaised(dpy
, win
);
1695 XDestroyWindow(dpy
, win
);
1699 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1705 const int heads
= wXineramaHeads(scr
);
1708 int pf
; /* primary axis */
1709 int sf
; /* secondary axis */
1713 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1719 int isize
= wPreferences
.icon_size
;
1721 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1723 for (head
= 0; head
< heads
; ++head
) {
1724 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1725 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1726 vars
[head
].pi
= vars
[head
].si
= 0;
1727 vars
[head
].sx1
= rect
.pos
.x
;
1728 vars
[head
].sy1
= rect
.pos
.y
;
1729 vars
[head
].sw
= rect
.size
.width
;
1730 vars
[head
].sh
= rect
.size
.height
;
1731 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1732 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1733 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1734 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1735 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1736 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1738 /* icon yard boundaries */
1739 if (wPreferences
.icon_yard
& IY_VERT
) {
1740 vars
[head
].pf
= vars
[head
].fullH
;
1741 vars
[head
].sf
= vars
[head
].fullW
;
1743 vars
[head
].pf
= vars
[head
].fullW
;
1744 vars
[head
].sf
= vars
[head
].fullH
;
1746 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1747 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1750 vars
[head
].xo
= vars
[head
].sx1
;
1753 if (wPreferences
.icon_yard
& IY_TOP
) {
1754 vars
[head
].yo
= vars
[head
].sy1
;
1757 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1762 #define X ((wPreferences.icon_yard & IY_VERT) \
1763 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1764 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1766 #define Y ((wPreferences.icon_yard & IY_VERT) \
1767 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1768 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1770 /* arrange application icons */
1771 aicon
= scr
->app_icon_list
;
1772 /* reverse them to avoid unnecessarily sliding of icons */
1773 while (aicon
&& aicon
->next
)
1774 aicon
= aicon
->next
;
1777 if (!aicon
->docked
) {
1778 /* CHECK: can icon be NULL here ? */
1779 /* The intention here is to place the AppIcon on the head that
1780 * contains most of the applications _main_ window. */
1781 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1783 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1785 if (!wPreferences
.no_animations
)
1786 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1787 #endif /* ANIMATIONS */
1789 wAppIconMove(aicon
, X
, Y
);
1791 if (vars
[head
].pi
>= vars
[head
].pf
) {
1796 aicon
= aicon
->prev
;
1799 /* arrange miniwindows */
1800 wwin
= scr
->focused_window
;
1801 /* reverse them to avoid unnecessarily shuffling */
1802 while (wwin
&& wwin
->prev
)
1806 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1807 (wwin
->frame
->workspace
== scr
->current_workspace
||
1808 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1810 head
= wGetHeadForWindow(wwin
);
1812 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1813 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1814 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1820 if (vars
[head
].pi
>= vars
[head
].pf
) {
1827 wwin
->flags
.icon_moved
= 0;
1829 /* we reversed the order, so we use next */
1836 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1838 WScreen
*scr
= wwin
->screen_ptr
;
1841 wwin
->flags
.selected
= 1;
1842 if (wwin
->frame
->selected_border_pixel
)
1843 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1845 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1847 if (!HAS_BORDER(wwin
)) {
1848 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1851 if (!scr
->selected_windows
)
1852 scr
->selected_windows
= WMCreateArray(4);
1853 WMAddToArray(scr
->selected_windows
, wwin
);
1855 wwin
->flags
.selected
= 0;
1856 if (wwin
->frame
->border_pixel
)
1857 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1859 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1861 if (!HAS_BORDER(wwin
)) {
1862 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1865 if (scr
->selected_windows
) {
1866 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1871 void wMakeWindowVisible(WWindow
*wwin
)
1873 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1874 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1876 if (wwin
->flags
.shaded
) {
1877 wUnshadeWindow(wwin
);
1879 if (wwin
->flags
.hidden
) {
1882 app
= wApplicationOf(wwin
->main_window
);
1884 /* trick to get focus to this window */
1885 app
->last_focused
= wwin
;
1886 wUnhideApplication(app
, False
, False
);
1889 if (wwin
->flags
.miniaturized
) {
1890 wDeiconifyWindow(wwin
);
1892 if (!WFLAGP(wwin
, no_focusable
))
1893 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1894 wRaiseFrame(wwin
->frame
->core
);
1899 * Do the animation while shading (called with what = SHADE)
1900 * or unshading (what = UNSHADE).
1903 static void shade_animate(WWindow
*wwin
, Bool what
)
1906 time_t time0
= time(NULL
);
1908 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1913 if (!wwin
->screen_ptr
->flags
.startup
) {
1914 /* do the shading animation */
1915 h
= wwin
->frame
->core
->height
;
1916 s
= h
/ SHADE_STEPS
;
1919 w
= wwin
->frame
->core
->width
;
1920 y
= wwin
->frame
->top_width
;
1921 while (h
> wwin
->frame
->top_width
+ 1) {
1922 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1923 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1926 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1929 if (SHADE_DELAY
> 0) {
1930 wusleep(SHADE_DELAY
* 1000L);
1937 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1942 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1943 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1944 s
= abs(y
) / SHADE_STEPS
;
1947 w
= wwin
->frame
->core
->width
;
1948 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1950 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1951 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1952 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1954 if (SHADE_DELAY
> 0) {
1955 wusleep(SHADE_DELAY
* 2000L / 3);
1962 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1966 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);