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"
50 /****** Global Variables ******/
52 int ignore_wks_change
= 0;
53 extern Time LastTimestamp
;
54 extern Time LastFocusChange
;
55 extern WPreferences wPreferences
;
56 extern Atom _XA_WM_TAKE_FOCUS
;
57 extern void ProcessPendingEvents();
58 extern int calcIntersectionLength(int p1
, int l1
, int p2
, int l2
);
60 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
61 unsigned int *new_width
, unsigned int *new_height
);
62 static void save_old_geometry(WWindow
*wwin
, int directions
);
64 /******* Local Variables *******/
70 SHADE_STEPS_UF
, SHADE_DELAY_UF
}, {
71 SHADE_STEPS_F
, SHADE_DELAY_F
}, {
72 SHADE_STEPS_M
, SHADE_DELAY_M
}, {
73 SHADE_STEPS_S
, SHADE_DELAY_S
}, {
74 SHADE_STEPS_US
, SHADE_DELAY_US
}};
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1
, Time t2
)
87 return (diff
< 60000) ? 1 : -1;
91 static void shade_animate(WWindow
*wwin
, Bool what
);
93 static void shade_animate(WWindow
*wwin
, Bool what
) { }
97 *----------------------------------------------------------------------
99 * Changes the window focus to the one passed as argument.
100 * If the window to focus is not already focused, it will be brought
101 * to the head of the list of windows. Previously focused window is
105 * Window list may be reordered and the window focus is changed.
107 *----------------------------------------------------------------------
109 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
111 static WScreen
*old_scr
= NULL
;
113 WWindow
*old_focused
;
114 WWindow
*focused
= scr
->focused_window
;
115 Time timestamp
= LastTimestamp
;
116 WApplication
*oapp
= NULL
, *napp
= NULL
;
119 if (scr
->flags
.ignore_focus_events
|| compareTimes(LastFocusChange
, timestamp
) > 0)
125 old_focused
= old_scr
->focused_window
;
127 LastFocusChange
= timestamp
;
130 oapp
= wApplicationOf(old_focused
->main_window
);
133 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
135 wWindowUnfocus(old_focused
);
138 wAppMenuUnmap(oapp
->menu
);
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 wApplicationDeactivate(oapp
);
206 wWindowFocus(wwin
, focused
);
208 if (napp
&& !wasfocused
) {
210 wUserMenuRefreshInstances(napp
->menu
, wwin
);
211 #endif /* USER_MENU */
213 if (wwin
->flags
.mapped
)
214 wAppMenuMap(napp
->menu
, wwin
);
217 wApplicationActivate(napp
);
223 void wShadeWindow(WWindow
*wwin
)
226 if (wwin
->flags
.shaded
)
229 XLowerWindow(dpy
, wwin
->client_win
);
230 shade_animate(wwin
, SHADE
);
232 wwin
->flags
.skip_next_animation
= 0;
233 wwin
->flags
.shaded
= 1;
234 wwin
->flags
.mapped
= 0;
235 /* prevent window withdrawal when getting UnmapNotify */
236 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
237 XUnmapWindow(dpy
, wwin
->client_win
);
238 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
240 /* for the client it's just like iconification */
241 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
243 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
244 wWindowSynthConfigureNotify(wwin
);
247 wClientSetState(wwin, IconicState, None);
250 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
253 if (!wwin
->screen_ptr
->flags
.startup
) {
254 /* Catch up with events not processed while animation was running */
255 ProcessPendingEvents();
260 void wUnshadeWindow(WWindow
*wwin
)
263 if (!wwin
->flags
.shaded
)
266 wwin
->flags
.shaded
= 0;
267 wwin
->flags
.mapped
= 1;
268 XMapWindow(dpy
, wwin
->client_win
);
270 shade_animate(wwin
, UNSHADE
);
272 wwin
->flags
.skip_next_animation
= 0;
273 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
274 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
276 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
277 wWindowSynthConfigureNotify(wwin
);
279 /* if the window is focused, set the focus again as it was disabled during
281 if (wwin
->flags
.focused
)
282 wSetFocusTo(wwin
->screen_ptr
, wwin
);
284 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
287 /* Set the old coordinates using the current values */
288 static void save_old_geometry(WWindow
*wwin
, int directions
)
290 if (directions
& MAX_HORIZONTAL
|| ! wwin
->old_geometry
.width
) {
291 wwin
->old_geometry
.width
= wwin
->client
.width
;
292 wwin
->old_geometry
.x
= wwin
->frame_x
;
294 if (directions
& MAX_VERTICAL
|| ! wwin
->old_geometry
.height
) {
295 wwin
->old_geometry
.height
= wwin
->client
.height
;
296 wwin
->old_geometry
.y
= wwin
->frame_y
;
300 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
302 WMRect old_geom_rect
;
306 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
307 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
308 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
309 *x
= (wwin
->old_geometry
.x
&& same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
310 *y
= (wwin
->old_geometry
.y
&& same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
311 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
312 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
315 #define IS_MAX_HORIZONTALLY(directions) ((directions & MAX_HORIZONTAL) | (directions & MAX_LEFTHALF) | (directions & MAX_RIGHTHALF))
316 void wMaximizeWindow(WWindow
*wwin
, int directions
)
319 unsigned int new_width
, new_height
, half_scr_width
;
322 unsigned int maximus_width
= 0;
323 unsigned int maximus_height
= 0;
324 WArea usableArea
, totalArea
;
326 int save_directions
= 0;
329 if (!IS_RESIZABLE(wwin
))
332 if (!HAS_BORDER(wwin
))
335 /* the size to adjust the geometry */
336 adj_size
= FRAME_BORDER_WIDTH
* 2 * has_border
;
338 /* save old coordinates before we change the current values
339 * but never if the window has been Maximusized */
340 if (!(wwin
->flags
.old_maximized
& MAX_MAXIMUS
)) {
341 if ((directions
& MAX_VERTICAL
) &&
342 !(wwin
->flags
.maximized
& MAX_VERTICAL
))
343 save_directions
|= MAX_VERTICAL
;
344 if (IS_MAX_HORIZONTALLY(directions
) &&
345 !IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
))
346 save_directions
|= MAX_HORIZONTAL
;
348 if ((directions
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
349 save_directions
|= MAX_VERTICAL
| MAX_HORIZONTAL
;
350 save_old_geometry(wwin
, save_directions
);
354 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
355 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
356 usableArea
= totalArea
;
358 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
359 WScreen
*scr
= wwin
->screen_ptr
;
362 if (directions
& MAX_KEYBOARD
)
363 head
= wGetHeadForWindow(wwin
);
365 head
= wGetHeadForPointerLocation(scr
);
367 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
370 /* remember Maximus geometry if we'll need it later */
371 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) || (directions
& MAX_MAXIMUS
))
372 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
374 /* Only save directions, not kbd or xinerama hints */
375 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
377 if (WFLAGP(wwin
, full_maximize
)) {
378 usableArea
= totalArea
;
380 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
382 if (wwin
->flags
.shaded
) {
383 wwin
->flags
.skip_next_animation
= 1;
384 wUnshadeWindow(wwin
);
387 if (directions
& MAX_HORIZONTAL
) {
388 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
389 new_x
= usableArea
.x1
;
390 } else if (directions
& MAX_LEFTHALF
) {
391 new_width
= half_scr_width
- adj_size
;
392 new_x
= usableArea
.x1
;
393 wwin
->flags
.old_maximized
|= MAX_LEFTHALF
;
394 wwin
->flags
.old_maximized
&= ~MAX_RIGHTHALF
;
395 } else if (directions
& MAX_RIGHTHALF
) {
396 new_width
= half_scr_width
- adj_size
;
397 new_x
= usableArea
.x1
+ half_scr_width
;
398 wwin
->flags
.old_maximized
|= MAX_RIGHTHALF
;
399 wwin
->flags
.old_maximized
&= ~MAX_LEFTHALF
;
400 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
402 new_width
= maximus_width
- adj_size
;
403 } else if (IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
)) {
404 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
405 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
407 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
408 new_x
= wwin
->frame_x
;
409 new_width
= wwin
->frame
->core
->width
;
412 if (directions
& MAX_VERTICAL
) {
413 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
414 new_y
= usableArea
.y1
;
415 if (WFLAGP(wwin
, full_maximize
)) {
416 new_y
-= wwin
->frame
->top_width
;
417 new_height
+= wwin
->frame
->bottom_width
- 1;
419 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
421 new_height
= maximus_height
- adj_size
;
422 /* HACK: this will be subtracted again below */
423 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
424 } else if (wwin
->flags
.maximized
& MAX_VERTICAL
) {
425 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
426 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
427 /* HACK: this will be subtracted again below */
428 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
429 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
431 new_y
= wwin
->frame_y
;
432 new_height
= wwin
->frame
->core
->height
;
435 if (!WFLAGP(wwin
, full_maximize
)) {
436 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
439 if (directions
& MAX_MAXIMUS
) {
442 new_width
= maximus_width
- adj_size
;
443 new_height
= maximus_height
- adj_size
;
444 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
445 new_y
-= wwin
->frame
->top_width
;
446 new_height
+= wwin
->frame
->top_width
- 1;
448 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
451 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
453 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
454 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
456 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
457 wWindowSynthConfigureNotify(wwin
);
459 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
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
;
467 /* generic (un)maximizer */
468 void handleMaximize(WWindow
*wwin
, int directions
)
470 int current
= wwin
->flags
.maximized
;
471 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
472 int effective
= requested
^ current
;
473 int flags
= directions
& ~requested
;
476 /* allow wMaximizeWindow to restore the Maximusized size */
477 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
478 !(requested
& MAX_MAXIMUS
))
479 wMaximizeWindow(wwin
, flags
);
481 wUnmaximizeWindow(wwin
);
484 /* MAX_MAXIMUS takes precedence */
485 effective
&= ~MAX_MAXIMUS
;
486 if (requested
& MAX_MAXIMUS
) {
487 /* window was previously Maximusized then maximized */
488 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !current
) {
489 wUnmaximizeWindow(wwin
);
493 effective
= MAX_MAXIMUS
;
495 else if (requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
))
496 effective
= requested
;
498 /* handle MAX_HORIZONTAL -> MAX_(LEFT|RIGHT)HALF */
499 if (IS_MAX_HORIZONTALLY(current
)) {
500 if (IS_MAX_HORIZONTALLY(requested
)) {
501 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
);
502 effective
|= (requested
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
));
503 if (requested
& MAX_HORIZONTAL
) {
504 /* restore to half maximization */
505 if (wwin
->flags
.old_maximized
& MAX_LEFTHALF
)
506 effective
|= MAX_LEFTHALF
;
507 else if (wwin
->flags
.old_maximized
& MAX_RIGHTHALF
)
508 effective
|= MAX_RIGHTHALF
;
510 /* MAX_VERTICAL is implicit with MAX_(LEFT|RIGHT)HALF */
512 effective
|= MAX_VERTICAL
;
514 /* toggling MAX_VERTICAL */
515 if ((requested
& MAX_VERTICAL
) &&
516 (current
& MAX_VERTICAL
)) {
517 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_VERTICAL
);
521 /* handle MAX_VERTICAL -> MAX_(LEFT|RIGHT)HALF */
522 if (current
& MAX_VERTICAL
) {
523 if ((requested
& MAX_LEFTHALF
) ||
524 (requested
& MAX_RIGHTHALF
)) {
525 effective
|= MAX_VERTICAL
;
528 /* toggling MAX_HORIZONTAL */
529 if ((requested
& MAX_HORIZONTAL
) &&
530 (current
& MAX_HORIZONTAL
))
531 effective
&= ~MAX_HORIZONTAL
;
533 wMaximizeWindow(wwin
, effective
| flags
);
538 /* the window boundary coordinates */
548 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
550 obs
->left
= wwin
->frame_x
;
551 obs
->top
= wwin
->frame_y
;
552 obs
->width
= wwin
->frame
->core
->width
;
553 obs
->height
= wwin
->frame
->core
->height
;
554 obs
->bottom
= obs
->top
+ obs
->height
;
555 obs
->right
= obs
->left
+ obs
->width
;
559 * Maximus: tiled maximization (maximize without overlapping other windows)
561 * The original window 'orig' will be maximized to new coordinates 'new'.
562 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
564 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
565 unsigned int *new_width
, unsigned int *new_height
)
568 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
569 short int adjust_height
;
570 int x_intsect
, y_intsect
;
571 /* the obstructing, original and new windows */
572 win_coords obs
, orig
, new;
574 /* set the original coordinate positions of the window to be Maximumized */
575 if (wwin
->flags
.maximized
) {
576 /* window is already maximized; consider original geometry */
577 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
578 orig
.bottom
= orig
.top
+ orig
.height
;
579 orig
.right
= orig
.left
+ orig
.width
;
582 set_window_coords(wwin
, &orig
);
584 /* Try to fully maximize first, then readjust later */
585 new.left
= usableArea
.x1
;
586 new.right
= usableArea
.x2
;
587 new.top
= usableArea
.y1
;
588 new.bottom
= usableArea
.y2
;
590 if (HAS_TITLEBAR(wwin
))
591 tbar_height_0
= TITLEBAR_HEIGHT
;
592 if (HAS_RESIZEBAR(wwin
))
593 rbar_height_0
= RESIZEBAR_HEIGHT
;
594 if (HAS_BORDER(wwin
))
595 bd_width_0
= FRAME_BORDER_WIDTH
;
597 /* the length to be subtracted if the window has titlebar, etc */
598 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
601 /* The focused window is always the last in the list */
603 /* ignore windows in other workspaces etc */
604 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
605 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
611 /* Set the coordinates of obstructing window */
612 set_window_coords(tmp
, &obs
);
614 /* Try to maximize in the y direction first */
615 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
616 if (x_intsect
!= 0) {
617 /* TODO: Consider the case when coords are equal */
618 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
619 /* w_0 is below the bottom of w_j */
620 new.top
= obs
.bottom
+ 1;
622 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
623 /* The bottom of w_0 is above the top of w_j */
624 new.bottom
= obs
.top
- 1;
631 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
632 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
638 set_window_coords(tmp
, &obs
);
641 * Use the new.top and new.height instead of original values
642 * as they may have different intersections with the obstructing windows
644 new.height
= new.bottom
- new.top
- adjust_height
;
645 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
646 if (y_intsect
!= 0) {
647 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
648 /* w_0 is completely to the right of w_j */
649 new.left
= obs
.right
+ 1;
651 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
652 /* w_0 is completely to the left of w_j */
653 new.right
= obs
.left
- 1;
660 /* xcalc needs -7 here, but other apps don't */
661 *new_height
= new.bottom
- new.top
- adjust_height
- 1;;
662 *new_width
= new.right
- new.left
;
665 void wUnmaximizeWindow(WWindow
*wwin
)
669 if (!wwin
->flags
.maximized
)
672 if (wwin
->flags
.shaded
) {
673 wwin
->flags
.skip_next_animation
= 1;
674 wUnshadeWindow(wwin
);
676 /* Use old coordinates if they are set, current values otherwise */
677 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
679 wwin
->flags
.maximized
= 0;
680 wwin
->flags
.old_maximized
= 0;
681 wWindowConfigure(wwin
, x
, y
, w
, h
);
682 wWindowSynthConfigureNotify(wwin
);
684 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
687 void wFullscreenWindow(WWindow
*wwin
)
692 if (wwin
->flags
.fullscreen
)
695 wwin
->flags
.fullscreen
= True
;
697 wWindowConfigureBorders(wwin
);
699 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
701 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
702 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
703 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
704 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
706 head
= wGetHeadForWindow(wwin
);
707 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
708 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
710 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
713 void wUnfullscreenWindow(WWindow
*wwin
)
715 if (!wwin
->flags
.fullscreen
)
718 wwin
->flags
.fullscreen
= False
;
720 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
721 if (WFLAGP(wwin
, sunken
)) {
722 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
723 } else if (WFLAGP(wwin
, floating
)) {
724 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
726 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
730 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
731 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
733 wWindowConfigureBorders(wwin
);
735 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
736 wFrameWindowPaint(wwin->frame);
739 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
743 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
745 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
746 float cx
, cy
, cw
, ch
;
747 float xstep
, ystep
, wstep
, hstep
;
750 float angle
, final_angle
, delta
;
752 xstep
= (float)(fx
- x
) / steps
;
753 ystep
= (float)(fy
- y
) / steps
;
754 wstep
= (float)(fw
- w
) / steps
;
755 hstep
= (float)(fh
- h
) / steps
;
762 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
763 delta
= (float)(final_angle
/ FRAMES
);
764 for (angle
= 0;; angle
+= delta
) {
765 if (angle
> final_angle
)
768 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
769 dch
= (ch
/ 2) * cos(angle
);
770 midy
= cy
+ (ch
/ 2);
772 points
[0].x
= cx
+ dx
;
773 points
[0].y
= midy
- dch
;
774 points
[1].x
= cx
+ cw
- dx
;
775 points
[1].y
= points
[0].y
;
776 points
[2].x
= cx
+ cw
+ dx
;
777 points
[2].y
= midy
+ dch
;
778 points
[3].x
= cx
- dx
;
779 points
[3].y
= points
[2].y
;
780 points
[4].x
= points
[0].x
;
781 points
[4].y
= points
[0].y
;
784 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
786 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
788 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
794 if (angle
>= final_angle
)
804 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
806 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
807 float cx
, cy
, cw
, ch
;
808 float xstep
, ystep
, wstep
, hstep
;
810 float angle
, final_angle
, a
, d
, delta
;
817 xstep
= (float)(fx
- x
) / steps
;
818 ystep
= (float)(fy
- y
) / steps
;
819 wstep
= (float)(fw
- w
) / steps
;
820 hstep
= (float)(fh
- h
) / steps
;
827 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
828 delta
= (float)(final_angle
/ FRAMES
);
829 for (angle
= 0;; angle
+= delta
) {
830 if (angle
> final_angle
)
834 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
836 points
[0].x
= cx
+ cos(angle
- a
) * d
;
837 points
[0].y
= cy
+ sin(angle
- a
) * d
;
838 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
839 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
840 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
841 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
842 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
843 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
844 points
[4].x
= cx
+ cos(angle
- a
) * d
;
845 points
[4].y
= cy
+ sin(angle
- a
) * d
;
847 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
849 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
851 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
857 if (angle
>= final_angle
)
866 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
868 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
869 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
870 float xstep
, ystep
, wstep
, hstep
;
873 xstep
= (float)(fx
- x
) / steps
;
874 ystep
= (float)(fy
- y
) / steps
;
875 wstep
= (float)(fw
- w
) / steps
;
876 hstep
= (float)(fh
- h
) / steps
;
878 for (j
= 0; j
< FRAMES
; j
++) {
885 for (i
= 0; i
< steps
; i
++) {
886 for (j
= 0; j
< FRAMES
; j
++) {
887 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
888 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
891 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
893 for (j
= 0; j
< FRAMES
; j
++) {
894 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
895 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
896 if (j
< FRAMES
- 1) {
910 for (j
= 0; j
< FRAMES
; j
++) {
911 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
914 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
916 for (j
= 0; j
< FRAMES
; j
++) {
917 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
925 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
927 int style
= wPreferences
.iconification_style
; /* Catch the value */
930 if (style
== WIS_NONE
)
933 if (style
== WIS_RANDOM
) {
939 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
941 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
944 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
946 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
950 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
952 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
956 #endif /* ANIMATIONS */
958 static void flushExpose(void)
962 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
963 WMHandleEvent(&tmpev
);
967 static void unmapTransientsFor(WWindow
*wwin
)
971 tmp
= wwin
->screen_ptr
->focused_window
;
973 /* unmap the transients for this transient */
974 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
975 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
976 unmapTransientsFor(tmp
);
977 tmp
->flags
.miniaturized
= 1;
978 if (!tmp
->flags
.shaded
) {
981 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
984 if (!tmp->flags.shaded)
986 wClientSetState(tmp
, IconicState
, None
);
988 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
994 static void mapTransientsFor(WWindow
*wwin
)
998 tmp
= wwin
->screen_ptr
->focused_window
;
1000 /* recursively map the transients for this transient */
1001 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1002 && tmp
->icon
== NULL
) {
1003 mapTransientsFor(tmp
);
1004 tmp
->flags
.miniaturized
= 0;
1005 if (!tmp
->flags
.shaded
) {
1008 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1010 tmp
->flags
.semi_focused
= 0;
1012 if (!tmp->flags.shaded)
1014 wClientSetState(tmp
, NormalState
, None
);
1016 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1022 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1029 /* hackish way to detect transient_for cycle */
1030 i
= wwin
->screen_ptr
->window_count
+ 1;
1032 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1033 wwin
= wWindowFor(wwin
->transient_for
);
1036 if (i
== 0 && wwin
) {
1037 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1044 void wIconifyWindow(WWindow
* wwin
)
1046 XWindowAttributes attribs
;
1049 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1050 return; /* the window doesn't exist anymore */
1052 if (wwin
->flags
.miniaturized
)
1053 return; /* already miniaturized */
1055 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1056 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1058 if (owner
&& owner
->flags
.miniaturized
)
1062 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1064 /* if the window is in another workspace, simplify process */
1066 /* icon creation may take a while */
1067 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1068 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1069 GrabModeAsync
, None
, None
, CurrentTime
);
1072 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1073 if (!wwin
->flags
.icon_moved
)
1074 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1076 wwin
->icon
= wIconCreate(wwin
);
1077 wwin
->icon
->mapped
= 1;
1080 wwin
->flags
.miniaturized
= 1;
1081 wwin
->flags
.mapped
= 0;
1083 /* unmap transients */
1084 unmapTransientsFor(wwin
);
1087 XUngrabPointer(dpy
, CurrentTime
);
1089 /* let all Expose events arrive so that we can repaint
1090 * something before the animation starts (and the server is grabbed) */
1093 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1094 wClientSetState(wwin
, IconicState
, None
);
1096 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1100 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1101 && !wPreferences
.no_animations
) {
1104 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1107 iw
= wwin
->icon
->core
->width
;
1108 ih
= wwin
->icon
->core
->height
;
1110 if (wwin
->flags
.net_handle_icon
) {
1118 iw
= wwin
->screen_ptr
->scr_width
;
1119 ih
= wwin
->screen_ptr
->scr_height
;
1122 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1123 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1128 wwin
->flags
.skip_next_animation
= 0;
1130 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1131 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1132 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1133 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1135 AddToStackList(wwin
->icon
->core
);
1136 wLowerFrame(wwin
->icon
->core
);
1140 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1143 * It doesn't seem to be working and causes button event hangup
1144 * when deiconifying a transient window.
1145 setupIconGrabs(wwin->icon);
1147 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1148 && wPreferences
.focus_mode
== WKF_CLICK
) {
1153 if (!WFLAGP(tmp
, no_focusable
)
1154 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1155 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1159 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1160 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1161 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1164 if (!wwin
->screen_ptr
->flags
.startup
) {
1165 /* Catch up with events not processed while animation was running */
1166 Window clientwin
= wwin
->client_win
;
1168 ProcessPendingEvents();
1170 /* the window can disappear while ProcessPendingEvents() runs */
1171 if (!wWindowFor(clientwin
)) {
1178 /* maybe we want to do this regardless of net_handle_icon
1179 * it seems to me we might break behaviour this way.
1181 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1182 && !wwin
->flags
.net_handle_icon
)
1183 wIconSelect(wwin
->icon
);
1185 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1187 if (wPreferences
.auto_arrange_icons
)
1188 wArrangeIcons(wwin
->screen_ptr
, True
);
1191 void wDeiconifyWindow(WWindow
*wwin
)
1193 /* Let's avoid changing workspace while deiconifying */
1194 ignore_wks_change
= 1;
1196 /* we're hiding for show_desktop */
1197 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1198 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1201 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1203 if (!wwin
->flags
.miniaturized
)
1206 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1207 WWindow
*owner
= recursiveTransientFor(wwin
);
1209 if (owner
&& owner
->flags
.miniaturized
) {
1210 wDeiconifyWindow(owner
);
1211 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1212 wRaiseFrame(wwin
->frame
->core
);
1217 wwin
->flags
.miniaturized
= 0;
1219 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1220 wwin
->flags
.mapped
= 1;
1222 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1223 /* maybe we want to do this regardless of net_handle_icon
1224 * it seems to me we might break behaviour this way.
1226 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1227 && wwin
->icon
!= NULL
) {
1228 if (wwin
->icon
->selected
)
1229 wIconSelect(wwin
->icon
);
1231 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1235 /* if the window is in another workspace, do it silently */
1236 if (!netwm_hidden
) {
1238 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1239 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1242 if (!wPreferences
.disable_miniwindows
1243 && !wwin
->flags
.net_handle_icon
) {
1246 iw
= wwin
->icon
->core
->width
;
1247 ih
= wwin
->icon
->core
->height
;
1249 if (wwin
->flags
.net_handle_icon
) {
1257 iw
= wwin
->screen_ptr
->scr_width
;
1258 ih
= wwin
->screen_ptr
->scr_height
;
1261 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1262 wwin
->frame_x
, wwin
->frame_y
,
1263 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1265 #endif /* ANIMATIONS */
1266 wwin
->flags
.skip_next_animation
= 0;
1268 if (!wwin
->flags
.shaded
)
1269 XMapWindow(dpy
, wwin
->client_win
);
1271 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1272 wRaiseFrame(wwin
->frame
->core
);
1273 if (!wwin
->flags
.shaded
)
1274 wClientSetState(wwin
, NormalState
, None
);
1276 mapTransientsFor(wwin
);
1279 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1280 && !wwin
->flags
.net_handle_icon
) {
1281 RemoveFromStackList(wwin
->icon
->core
);
1282 /* removeIconGrabs(wwin->icon); */
1283 wIconDestroy(wwin
->icon
);
1287 if (!netwm_hidden
) {
1290 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1293 if (!wwin
->screen_ptr
->flags
.startup
) {
1294 /* Catch up with events not processed while animation was running */
1295 Window clientwin
= wwin
->client_win
;
1297 ProcessPendingEvents();
1299 /* the window can disappear while ProcessPendingEvents() runs */
1300 if (!wWindowFor(clientwin
))
1306 if (wPreferences
.auto_arrange_icons
)
1307 wArrangeIcons(wwin
->screen_ptr
, True
);
1309 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1311 /* In case we were shaded and iconified, also unshade */
1313 wUnshadeWindow(wwin
);
1315 ignore_wks_change
= 0;
1318 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1320 if (wwin
->flags
.miniaturized
) {
1322 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1323 wwin
->icon
->mapped
= 0;
1325 wwin
->flags
.hidden
= 1;
1327 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1331 if (wwin
->flags
.inspector_open
) {
1332 wHideInspectorForWindow(wwin
);
1335 wwin
->flags
.hidden
= 1;
1338 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1342 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1343 !wwin
->flags
.skip_next_animation
&& animate
) {
1344 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1345 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1346 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1349 wwin
->flags
.skip_next_animation
= 0;
1351 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1354 void wHideAll(WScreen
*scr
)
1359 unsigned int wcount
= 0;
1365 menu
= scr
->switch_menu
;
1367 windows
= wmalloc(sizeof(WWindow
*));
1370 for (i
= 0; i
< menu
->entry_no
; i
++) {
1371 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1373 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1376 wwin
= scr
->focused_window
;
1379 windows
[wcount
] = wwin
;
1381 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1387 for (i
= 0; i
< wcount
; i
++) {
1389 if (wwin
->frame
->workspace
== scr
->current_workspace
1390 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1391 && !wwin
->flags
.internal_window
1392 && !WFLAGP(wwin
, no_miniaturizable
)
1394 wwin
->flags
.skip_next_animation
= 1;
1395 wIconifyWindow(wwin
);
1402 void wHideOtherApplications(WWindow
*awin
)
1409 wwin
= awin
->screen_ptr
->focused_window
;
1413 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1414 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1415 && !wwin
->flags
.internal_window
1416 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1418 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1419 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1420 wwin
->flags
.skip_next_animation
= 1;
1421 wIconifyWindow(wwin
);
1423 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1424 tapp
= wApplicationOf(wwin
->main_window
);
1426 tapp
->flags
.skip_next_animation
= 1;
1427 wHideApplication(tapp
);
1429 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1430 wwin
->flags
.skip_next_animation
= 1;
1431 wIconifyWindow(wwin
);
1439 wSetFocusTo(awin->screen_ptr, awin);
1443 void wHideApplication(WApplication
*wapp
)
1451 wwarning("trying to hide a non grouped window");
1454 if (!wapp
->main_window_desc
) {
1455 wwarning("group leader not found for window group");
1458 scr
= wapp
->main_window_desc
->screen_ptr
;
1460 wlist
= scr
->focused_window
;
1464 if (wlist
->main_window
== wapp
->main_window
)
1465 wapp
->last_focused
= wlist
;
1467 wapp
->last_focused
= NULL
;
1469 animate
= !wapp
->flags
.skip_next_animation
;
1472 if (wlist
->main_window
== wapp
->main_window
) {
1473 if (wlist
->flags
.focused
) {
1476 if (wapp
->app_icon
) {
1477 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1478 wapp
->app_icon
->y_pos
, wlist
, animate
);
1482 wlist
= wlist
->prev
;
1485 wapp
->flags
.skip_next_animation
= 0;
1488 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1489 wlist
= scr
->focused_window
;
1491 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1492 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1494 wlist
= wlist
->prev
;
1496 wSetFocusTo(scr
, wlist
);
1498 wSetFocusTo(scr
, NULL
);
1502 wapp
->flags
.hidden
= 1;
1504 if (wPreferences
.auto_arrange_icons
) {
1505 wArrangeIcons(scr
, True
);
1509 wAppIconPaint(wapp
->app_icon
);
1513 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1515 if (bringToCurrentWS
)
1516 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1518 wwin
->flags
.hidden
= 0;
1521 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1522 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1523 icon
->core
->width
, icon
->core
->height
,
1524 wwin
->frame_x
, wwin
->frame_y
,
1525 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1528 wwin
->flags
.skip_next_animation
= 0;
1529 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1530 XMapWindow(dpy
, wwin
->client_win
);
1531 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1532 wClientSetState(wwin
, NormalState
, None
);
1533 wwin
->flags
.mapped
= 1;
1534 wRaiseFrame(wwin
->frame
->core
);
1536 if (wwin
->flags
.inspector_open
) {
1537 wUnhideInspectorForWindow(wwin
);
1540 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1543 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1546 WWindow
*wlist
, *next
;
1547 WWindow
*focused
= NULL
;
1553 scr
= wapp
->main_window_desc
->screen_ptr
;
1554 wlist
= scr
->focused_window
;
1558 /* goto beginning of list */
1560 wlist
= wlist
->prev
;
1562 animate
= !wapp
->flags
.skip_next_animation
;
1567 if (wlist
->main_window
== wapp
->main_window
) {
1568 if (wlist
->flags
.focused
)
1570 else if (!focused
|| !focused
->flags
.focused
)
1573 if (wlist
->flags
.miniaturized
) {
1574 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1575 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1576 if (!wlist
->icon
->mapped
) {
1579 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1580 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1581 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1585 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1586 wlist
->icon
->mapped
= 1;
1588 wRaiseFrame(wlist
->icon
->core
);
1590 if (bringToCurrentWS
)
1591 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1592 wlist
->flags
.hidden
= 0;
1593 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1594 wDeiconifyWindow(wlist
);
1596 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1597 } else if (wlist
->flags
.shaded
) {
1598 if (bringToCurrentWS
)
1599 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1600 wlist
->flags
.hidden
= 0;
1601 wRaiseFrame(wlist
->frame
->core
);
1602 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1603 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1605 wUnshadeWindow(wlist
);
1608 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1609 } else if (wlist
->flags
.hidden
) {
1610 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1611 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1614 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1615 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1617 wRaiseFrame(wlist
->frame
->core
);
1623 wapp
->flags
.skip_next_animation
= 0;
1624 wapp
->flags
.hidden
= 0;
1626 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1627 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1628 wSetFocusTo(scr
, wapp
->last_focused
);
1629 } else if (focused
) {
1630 wSetFocusTo(scr
, focused
);
1632 wapp
->last_focused
= NULL
;
1633 if (wPreferences
.auto_arrange_icons
) {
1634 wArrangeIcons(scr
, True
);
1637 wAppIconPaint(wapp
->app_icon
);
1641 void wShowAllWindows(WScreen
*scr
)
1643 WWindow
*wwin
, *old_foc
;
1646 old_foc
= wwin
= scr
->focused_window
;
1648 if (!wwin
->flags
.internal_window
&&
1649 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1650 if (wwin
->flags
.miniaturized
) {
1651 wwin
->flags
.skip_next_animation
= 1;
1652 wDeiconifyWindow(wwin
);
1653 } else if (wwin
->flags
.hidden
) {
1654 wapp
= wApplicationOf(wwin
->main_window
);
1656 wUnhideApplication(wapp
, False
, False
);
1658 wwin
->flags
.skip_next_animation
= 1;
1659 wDeiconifyWindow(wwin
);
1665 wSetFocusTo(scr
, old_foc
);
1666 /*wRaiseFrame(old_foc->frame->core); */
1669 void wRefreshDesktop(WScreen
*scr
)
1672 XSetWindowAttributes attr
;
1674 attr
.backing_store
= NotUseful
;
1675 attr
.save_under
= False
;
1676 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1677 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1678 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1679 XMapRaised(dpy
, win
);
1680 XDestroyWindow(dpy
, win
);
1684 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1690 const int heads
= wXineramaHeads(scr
);
1693 int pf
; /* primary axis */
1694 int sf
; /* secondary axis */
1698 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1704 int isize
= wPreferences
.icon_size
;
1706 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1708 for (head
= 0; head
< heads
; ++head
) {
1709 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1710 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1711 vars
[head
].pi
= vars
[head
].si
= 0;
1712 vars
[head
].sx1
= rect
.pos
.x
;
1713 vars
[head
].sy1
= rect
.pos
.y
;
1714 vars
[head
].sw
= rect
.size
.width
;
1715 vars
[head
].sh
= rect
.size
.height
;
1716 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1717 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1718 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1719 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1720 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1721 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1723 /* icon yard boundaries */
1724 if (wPreferences
.icon_yard
& IY_VERT
) {
1725 vars
[head
].pf
= vars
[head
].fullH
;
1726 vars
[head
].sf
= vars
[head
].fullW
;
1728 vars
[head
].pf
= vars
[head
].fullW
;
1729 vars
[head
].sf
= vars
[head
].fullH
;
1731 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1732 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1735 vars
[head
].xo
= vars
[head
].sx1
;
1738 if (wPreferences
.icon_yard
& IY_TOP
) {
1739 vars
[head
].yo
= vars
[head
].sy1
;
1742 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1747 #define X ((wPreferences.icon_yard & IY_VERT) \
1748 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1749 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1751 #define Y ((wPreferences.icon_yard & IY_VERT) \
1752 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1753 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1755 /* arrange application icons */
1756 aicon
= scr
->app_icon_list
;
1757 /* reverse them to avoid unnecessarily sliding of icons */
1758 while (aicon
&& aicon
->next
)
1759 aicon
= aicon
->next
;
1762 if (!aicon
->docked
) {
1763 /* CHECK: can icon be NULL here ? */
1764 /* The intention here is to place the AppIcon on the head that
1765 * contains most of the applications _main_ window. */
1766 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1768 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1770 if (!wPreferences
.no_animations
) {
1771 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1773 #endif /* ANIMATIONS */
1775 wAppIconMove(aicon
, X
, Y
);
1777 if (vars
[head
].pi
>= vars
[head
].pf
) {
1782 aicon
= aicon
->prev
;
1785 /* arrange miniwindows */
1786 wwin
= scr
->focused_window
;
1787 /* reverse them to avoid unnecessarily shuffling */
1788 while (wwin
&& wwin
->prev
)
1792 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1793 (wwin
->frame
->workspace
== scr
->current_workspace
||
1794 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1796 head
= wGetHeadForWindow(wwin
);
1798 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1799 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
) {
1801 if (wPreferences
.no_animations
) {
1802 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1804 SlideWindow(wwin
->icon
->core
->window
, wwin
->icon_x
,
1805 wwin
->icon_y
, X
, Y
);
1808 XMoveWindow(dpy
, wwin
->icon
->core
->window
, X
, Y
);
1809 #endif /* ANIMATIONS */
1815 if (vars
[head
].pi
>= vars
[head
].pf
) {
1822 wwin
->flags
.icon_moved
= 0;
1824 /* we reversed the order, so we use next */
1831 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1833 WScreen
*scr
= wwin
->screen_ptr
;
1836 wwin
->flags
.selected
= 1;
1837 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1839 if (!HAS_BORDER(wwin
)) {
1840 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, FRAME_BORDER_WIDTH
);
1843 if (!scr
->selected_windows
)
1844 scr
->selected_windows
= WMCreateArray(4);
1845 WMAddToArray(scr
->selected_windows
, wwin
);
1847 wwin
->flags
.selected
= 0;
1848 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1850 if (!HAS_BORDER(wwin
)) {
1851 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1854 if (scr
->selected_windows
) {
1855 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1860 void wMakeWindowVisible(WWindow
*wwin
)
1862 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1863 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1865 if (wwin
->flags
.shaded
) {
1866 wUnshadeWindow(wwin
);
1868 if (wwin
->flags
.hidden
) {
1871 app
= wApplicationOf(wwin
->main_window
);
1873 /* trick to get focus to this window */
1874 app
->last_focused
= wwin
;
1875 wUnhideApplication(app
, False
, False
);
1878 if (wwin
->flags
.miniaturized
) {
1879 wDeiconifyWindow(wwin
);
1881 if (!WFLAGP(wwin
, no_focusable
))
1882 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1883 wRaiseFrame(wwin
->frame
->core
);
1888 * Do the animation while shading (called with what = SHADE)
1889 * or unshading (what = UNSHADE).
1892 static void shade_animate(WWindow
*wwin
, Bool what
)
1895 time_t time0
= time(NULL
);
1897 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1902 if (!wwin
->screen_ptr
->flags
.startup
) {
1903 /* do the shading animation */
1904 h
= wwin
->frame
->core
->height
;
1905 s
= h
/ SHADE_STEPS
;
1908 w
= wwin
->frame
->core
->width
;
1909 y
= wwin
->frame
->top_width
;
1910 while (h
> wwin
->frame
->top_width
+ 1) {
1911 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1912 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1915 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1918 if (SHADE_DELAY
> 0) {
1919 wusleep(SHADE_DELAY
* 1000L);
1926 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1931 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1932 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1933 s
= abs(y
) / SHADE_STEPS
;
1936 w
= wwin
->frame
->core
->width
;
1937 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1939 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1940 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1941 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1943 if (SHADE_DELAY
> 0) {
1944 wusleep(SHADE_DELAY
* 2000L / 3);
1951 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1955 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);