1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <X11/Xutil.h>
33 #include "WindowMaker.h"
39 #include "application.h"
45 #include "winspector.h"
46 #include "workspace.h"
49 #include "placement.h"
52 /****** Global Variables ******/
54 int ignore_wks_change
= 0;
55 extern Time LastTimestamp
;
56 extern Time LastFocusChange
;
57 extern WPreferences wPreferences
;
58 extern Atom _XA_WM_TAKE_FOCUS
;
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 if (wPreferences
.highlight_active_app
)
140 wApplicationDeactivate(oapp
);
143 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
147 if (old_scr
!= scr
&& old_focused
)
148 wWindowUnfocus(old_focused
);
150 wasfocused
= wwin
->flags
.focused
;
151 napp
= wApplicationOf(wwin
->main_window
);
153 /* remember last workspace where the app has been */
155 napp
->last_workspace
= wwin
->frame
->workspace
;
157 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
158 /* install colormap if colormap mode is lock mode */
159 if (wPreferences
.colormap_mode
== WCM_CLICK
)
160 wColormapInstallForWindow(scr
, wwin
);
162 /* set input focus */
163 switch (wwin
->focus_mode
) {
165 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
168 case WFM_LOCALLY_ACTIVE
:
169 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
171 case WFM_GLOBALLY_ACTIVE
:
176 if (wwin
->protocols
.TAKE_FOCUS
)
177 wClientSendProtocol(wwin
, _XA_WM_TAKE_FOCUS
, timestamp
);
181 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
184 if (WFLAGP(wwin
, no_focusable
))
187 /* if this is not the focused window focus it */
188 if (focused
!= wwin
) {
189 /* change the focus window list order */
191 wwin
->prev
->next
= wwin
->next
;
194 wwin
->next
->prev
= wwin
->prev
;
196 wwin
->prev
= focused
;
197 focused
->next
= wwin
;
199 scr
->focused_window
= wwin
;
201 if (oapp
&& oapp
!= napp
) {
202 wAppMenuUnmap(oapp
->menu
);
203 if (wPreferences
.highlight_active_app
)
204 wApplicationDeactivate(oapp
);
208 wWindowFocus(wwin
, focused
);
210 if (napp
&& !wasfocused
) {
212 wUserMenuRefreshInstances(napp
->menu
, wwin
);
213 #endif /* USER_MENU */
215 if (wwin
->flags
.mapped
)
216 wAppMenuMap(napp
->menu
, wwin
);
218 if (napp
&& wPreferences
.highlight_active_app
)
219 wApplicationActivate(napp
);
225 void wShadeWindow(WWindow
*wwin
)
228 if (wwin
->flags
.shaded
)
231 XLowerWindow(dpy
, wwin
->client_win
);
232 shade_animate(wwin
, SHADE
);
234 wwin
->flags
.skip_next_animation
= 0;
235 wwin
->flags
.shaded
= 1;
236 wwin
->flags
.mapped
= 0;
237 /* prevent window withdrawal when getting UnmapNotify */
238 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
239 XUnmapWindow(dpy
, wwin
->client_win
);
240 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
242 /* for the client it's just like iconification */
243 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
245 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
246 wWindowSynthConfigureNotify(wwin
);
249 wClientSetState(wwin, IconicState, None);
252 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
255 if (!wwin
->screen_ptr
->flags
.startup
) {
256 /* Catch up with events not processed while animation was running */
257 ProcessPendingEvents();
262 void wUnshadeWindow(WWindow
*wwin
)
265 if (!wwin
->flags
.shaded
)
268 wwin
->flags
.shaded
= 0;
269 wwin
->flags
.mapped
= 1;
270 XMapWindow(dpy
, wwin
->client_win
);
272 shade_animate(wwin
, UNSHADE
);
274 wwin
->flags
.skip_next_animation
= 0;
275 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
276 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
278 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
279 wWindowSynthConfigureNotify(wwin
);
281 /* if the window is focused, set the focus again as it was disabled during
283 if (wwin
->flags
.focused
)
284 wSetFocusTo(wwin
->screen_ptr
, wwin
);
286 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
289 /* Set the old coordinates using the current values */
290 static void save_old_geometry(WWindow
*wwin
, int directions
)
292 /* never been saved? */
293 if (! wwin
->old_geometry
.width
)
294 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
295 if (! wwin
->old_geometry
.height
)
296 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
298 if (directions
& SAVE_GEOMETRY_X
)
299 wwin
->old_geometry
.x
= wwin
->frame_x
;
300 if (directions
& SAVE_GEOMETRY_Y
)
301 wwin
->old_geometry
.y
= wwin
->frame_y
;
302 if (directions
& SAVE_GEOMETRY_WIDTH
)
303 wwin
->old_geometry
.width
= wwin
->client
.width
;
304 if (directions
& SAVE_GEOMETRY_HEIGHT
)
305 wwin
->old_geometry
.height
= wwin
->client
.height
;
308 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
310 WMRect old_geom_rect
;
314 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
315 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
316 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
317 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
318 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
319 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
320 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
323 /* Remember geometry for unmaximizing */
324 void update_saved_geometry(WWindow
*wwin
)
326 /* NOT if we aren't already maximized
327 * we'll save geometry when maximizing */
328 if (!wwin
->flags
.maximized
)
331 /* NOT if we are fully maximized */
332 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
333 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
334 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
337 /* save the co-ordinate in the axis in which we AREN'T maximized */
338 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
339 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
340 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
341 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
344 #define IS_MAX_HORIZONTALLY(directions) ((directions & MAX_HORIZONTAL) | (directions & MAX_LEFTHALF) | (directions & MAX_RIGHTHALF))
345 void wMaximizeWindow(WWindow
*wwin
, int directions
)
348 unsigned int new_width
, new_height
, half_scr_width
;
351 unsigned int maximus_width
= 0;
352 unsigned int maximus_height
= 0;
353 WArea usableArea
, totalArea
;
355 int save_directions
= 0;
358 if (!IS_RESIZABLE(wwin
))
361 if (!HAS_BORDER(wwin
))
364 /* the size to adjust the geometry */
365 adj_size
= wwin
->screen_ptr
->frame_border_width
* 2 * has_border
;
367 /* save old coordinates before we change the current values
368 * always if the window is not currently maximized at all
369 * but never if the window has been Maximusized */
370 if (!wwin
->flags
.maximized
)
371 save_directions
|= SAVE_GEOMETRY_ALL
;
372 else if (!(wwin
->flags
.old_maximized
& MAX_MAXIMUS
)) {
373 if ((directions
& MAX_VERTICAL
) &&
374 !(wwin
->flags
.maximized
& MAX_VERTICAL
))
375 save_directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
376 if (IS_MAX_HORIZONTALLY(directions
) &&
377 !IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
))
378 save_directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
380 if ((directions
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
381 save_directions
|= SAVE_GEOMETRY_ALL
;
382 save_old_geometry(wwin
, save_directions
);
386 totalArea
.x2
= wwin
->screen_ptr
->scr_width
;
387 totalArea
.y2
= wwin
->screen_ptr
->scr_height
;
388 usableArea
= totalArea
;
390 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
391 WScreen
*scr
= wwin
->screen_ptr
;
394 if (directions
& MAX_KEYBOARD
)
395 head
= wGetHeadForWindow(wwin
);
397 head
= wGetHeadForPointerLocation(scr
);
399 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
402 /* remember Maximus geometry if we'll need it later */
403 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) || (directions
& MAX_MAXIMUS
))
404 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
406 /* Only save directions, not kbd or xinerama hints */
407 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
409 if (WFLAGP(wwin
, full_maximize
)) {
410 usableArea
= totalArea
;
412 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
414 if (wwin
->flags
.shaded
) {
415 wwin
->flags
.skip_next_animation
= 1;
416 wUnshadeWindow(wwin
);
419 if (directions
& MAX_HORIZONTAL
) {
420 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
421 new_x
= usableArea
.x1
;
422 } else if (directions
& MAX_LEFTHALF
) {
423 new_width
= half_scr_width
- adj_size
;
424 new_x
= usableArea
.x1
;
425 wwin
->flags
.old_maximized
|= MAX_LEFTHALF
;
426 wwin
->flags
.old_maximized
&= ~MAX_RIGHTHALF
;
427 } else if (directions
& MAX_RIGHTHALF
) {
428 new_width
= half_scr_width
- adj_size
;
429 new_x
= usableArea
.x1
+ half_scr_width
;
430 wwin
->flags
.old_maximized
|= MAX_RIGHTHALF
;
431 wwin
->flags
.old_maximized
&= ~MAX_LEFTHALF
;
432 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
434 new_width
= maximus_width
- adj_size
;
435 } else if (IS_MAX_HORIZONTALLY(wwin
->flags
.maximized
)) {
436 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
437 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
439 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
440 new_x
= wwin
->frame_x
;
441 new_width
= wwin
->frame
->core
->width
;
444 if (directions
& MAX_VERTICAL
) {
445 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
446 new_y
= usableArea
.y1
;
447 if (WFLAGP(wwin
, full_maximize
)) {
448 new_y
-= wwin
->frame
->top_width
;
449 new_height
+= wwin
->frame
->bottom_width
- 1;
451 } else if (wwin
->flags
.old_maximized
& MAX_MAXIMUS
) {
453 new_height
= maximus_height
- adj_size
;
454 /* HACK: this will be subtracted again below */
455 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
456 } else if (wwin
->flags
.maximized
& MAX_VERTICAL
) {
457 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
458 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
459 /* HACK: this will be subtracted again below */
460 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
461 wwin
->flags
.old_maximized
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
463 new_y
= wwin
->frame_y
;
464 new_height
= wwin
->frame
->core
->height
;
467 if (!WFLAGP(wwin
, full_maximize
)) {
468 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
471 if (directions
& MAX_MAXIMUS
) {
474 new_width
= maximus_width
- adj_size
;
475 new_height
= maximus_height
- adj_size
;
476 if (WFLAGP(wwin
, full_maximize
) && new_y
== 0) {
477 new_y
-= wwin
->frame
->top_width
;
478 new_height
+= wwin
->frame
->top_width
- 1;
480 wwin
->maximus_x
= new_x
;
481 wwin
->maximus_y
= new_y
;
482 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
485 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
487 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
488 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
490 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
491 wWindowSynthConfigureNotify(wwin
);
493 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
495 /* set maximization state */
496 wwin
->flags
.maximized
= directions
;
497 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
498 wwin
->flags
.maximized
= MAX_MAXIMUS
;
501 /* generic (un)maximizer */
502 void handleMaximize(WWindow
*wwin
, int directions
)
504 int current
= wwin
->flags
.maximized
;
505 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
);
506 int effective
= requested
^ current
;
507 int flags
= directions
& ~requested
;
510 /* allow wMaximizeWindow to restore the Maximusized size */
511 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
512 !(requested
& MAX_MAXIMUS
))
513 wMaximizeWindow(wwin
, flags
);
515 wUnmaximizeWindow(wwin
);
516 /* these alone mean vertical toggle */
517 } else if ((effective
== MAX_LEFTHALF
) ||
518 (effective
== MAX_RIGHTHALF
))
519 wUnmaximizeWindow(wwin
);
521 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
522 (requested
== MAX_MAXIMUS
))
523 effective
= requested
;
525 if (requested
& MAX_LEFTHALF
) {
526 effective
|= MAX_VERTICAL
;
527 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
528 } else if (requested
& MAX_RIGHTHALF
) {
529 effective
|= MAX_VERTICAL
;
530 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
532 effective
&= ~MAX_MAXIMUS
;
534 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
= wwin
->screen_ptr
->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
);
677 /* Use old coordinates if they are set, current values otherwise */
678 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
680 /* unMaximusize relative to original position */
681 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
682 x
+= wwin
->frame_x
- wwin
->maximus_x
;
683 y
+= wwin
->frame_y
- wwin
->maximus_y
;
686 wwin
->flags
.maximized
= 0;
687 wwin
->flags
.old_maximized
= 0;
688 wWindowConfigure(wwin
, x
, y
, w
, h
);
689 wWindowSynthConfigureNotify(wwin
);
691 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
694 void wFullscreenWindow(WWindow
*wwin
)
699 if (wwin
->flags
.fullscreen
)
702 wwin
->flags
.fullscreen
= True
;
704 wWindowConfigureBorders(wwin
);
706 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
708 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
709 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
710 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
711 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
713 head
= wGetHeadForWindow(wwin
);
714 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
715 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
717 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
720 void wUnfullscreenWindow(WWindow
*wwin
)
722 if (!wwin
->flags
.fullscreen
)
725 wwin
->flags
.fullscreen
= False
;
727 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
728 if (WFLAGP(wwin
, sunken
)) {
729 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
730 } else if (WFLAGP(wwin
, floating
)) {
731 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
733 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
737 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
738 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
740 wWindowConfigureBorders(wwin
);
742 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
743 wFrameWindowPaint(wwin->frame);
746 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
750 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
752 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
753 float cx
, cy
, cw
, ch
;
754 float xstep
, ystep
, wstep
, hstep
;
757 float angle
, final_angle
, delta
;
759 xstep
= (float)(fx
- x
) / steps
;
760 ystep
= (float)(fy
- y
) / steps
;
761 wstep
= (float)(fw
- w
) / steps
;
762 hstep
= (float)(fh
- h
) / steps
;
769 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
770 delta
= (float)(final_angle
/ FRAMES
);
771 for (angle
= 0;; angle
+= delta
) {
772 if (angle
> final_angle
)
775 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
776 dch
= (ch
/ 2) * cos(angle
);
777 midy
= cy
+ (ch
/ 2);
779 points
[0].x
= cx
+ dx
;
780 points
[0].y
= midy
- dch
;
781 points
[1].x
= cx
+ cw
- dx
;
782 points
[1].y
= points
[0].y
;
783 points
[2].x
= cx
+ cw
+ dx
;
784 points
[2].y
= midy
+ dch
;
785 points
[3].x
= cx
- dx
;
786 points
[3].y
= points
[2].y
;
787 points
[4].x
= points
[0].x
;
788 points
[4].y
= points
[0].y
;
791 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
793 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
795 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
801 if (angle
>= final_angle
)
811 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
813 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
814 float cx
, cy
, cw
, ch
;
815 float xstep
, ystep
, wstep
, hstep
;
817 float angle
, final_angle
, a
, d
, delta
;
824 xstep
= (float)(fx
- x
) / steps
;
825 ystep
= (float)(fy
- y
) / steps
;
826 wstep
= (float)(fw
- w
) / steps
;
827 hstep
= (float)(fh
- h
) / steps
;
834 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
835 delta
= (float)(final_angle
/ FRAMES
);
836 for (angle
= 0;; angle
+= delta
) {
837 if (angle
> final_angle
)
841 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
843 points
[0].x
= cx
+ cos(angle
- a
) * d
;
844 points
[0].y
= cy
+ sin(angle
- a
) * d
;
845 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
846 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
847 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
848 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
849 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
850 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
851 points
[4].x
= cx
+ cos(angle
- a
) * d
;
852 points
[4].y
= cy
+ sin(angle
- a
) * d
;
854 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
856 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
858 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
864 if (angle
>= final_angle
)
873 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
875 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
876 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
877 float xstep
, ystep
, wstep
, hstep
;
880 xstep
= (float)(fx
- x
) / steps
;
881 ystep
= (float)(fy
- y
) / steps
;
882 wstep
= (float)(fw
- w
) / steps
;
883 hstep
= (float)(fh
- h
) / steps
;
885 for (j
= 0; j
< FRAMES
; j
++) {
892 for (i
= 0; i
< steps
; i
++) {
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
]);
898 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
900 for (j
= 0; j
< FRAMES
; j
++) {
901 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
902 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
903 if (j
< FRAMES
- 1) {
917 for (j
= 0; j
< FRAMES
; j
++) {
918 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
921 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
923 for (j
= 0; j
< FRAMES
; j
++) {
924 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
932 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
934 int style
= wPreferences
.iconification_style
; /* Catch the value */
937 if (style
== WIS_NONE
)
940 if (style
== WIS_RANDOM
) {
946 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
948 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
951 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
953 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
957 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
959 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
963 #endif /* ANIMATIONS */
965 static void flushExpose(void)
969 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
970 WMHandleEvent(&tmpev
);
974 static void unmapTransientsFor(WWindow
*wwin
)
978 tmp
= wwin
->screen_ptr
->focused_window
;
980 /* unmap the transients for this transient */
981 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
982 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
983 unmapTransientsFor(tmp
);
984 tmp
->flags
.miniaturized
= 1;
985 if (!tmp
->flags
.shaded
) {
988 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
991 if (!tmp->flags.shaded)
993 wClientSetState(tmp
, IconicState
, None
);
995 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1001 static void mapTransientsFor(WWindow
*wwin
)
1005 tmp
= wwin
->screen_ptr
->focused_window
;
1007 /* recursively map the transients for this transient */
1008 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1009 && tmp
->icon
== NULL
) {
1010 mapTransientsFor(tmp
);
1011 tmp
->flags
.miniaturized
= 0;
1012 if (!tmp
->flags
.shaded
) {
1015 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1017 tmp
->flags
.semi_focused
= 0;
1019 if (!tmp->flags.shaded)
1021 wClientSetState(tmp
, NormalState
, None
);
1023 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1029 static WWindow
*recursiveTransientFor(WWindow
* wwin
)
1036 /* hackish way to detect transient_for cycle */
1037 i
= wwin
->screen_ptr
->window_count
+ 1;
1039 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1040 wwin
= wWindowFor(wwin
->transient_for
);
1043 if (i
== 0 && wwin
) {
1044 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1051 void wIconifyWindow(WWindow
* wwin
)
1053 XWindowAttributes attribs
;
1056 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1057 return; /* the window doesn't exist anymore */
1059 if (wwin
->flags
.miniaturized
)
1060 return; /* already miniaturized */
1062 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1063 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1065 if (owner
&& owner
->flags
.miniaturized
)
1069 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1071 /* if the window is in another workspace, simplify process */
1073 /* icon creation may take a while */
1074 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1075 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1076 GrabModeAsync
, None
, None
, CurrentTime
);
1079 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1080 if (!wwin
->flags
.icon_moved
)
1081 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1083 wwin
->icon
= icon_create_for_wwindow(wwin
);
1084 wwin
->icon
->mapped
= 1;
1087 wwin
->flags
.miniaturized
= 1;
1088 wwin
->flags
.mapped
= 0;
1090 /* unmap transients */
1091 unmapTransientsFor(wwin
);
1094 XUngrabPointer(dpy
, CurrentTime
);
1096 /* let all Expose events arrive so that we can repaint
1097 * something before the animation starts (and the server is grabbed) */
1100 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1101 wClientSetState(wwin
, IconicState
, None
);
1103 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1107 if (!wwin
->screen_ptr
->flags
.startup
&& !wwin
->flags
.skip_next_animation
1108 && !wPreferences
.no_animations
) {
1111 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1114 iw
= wwin
->icon
->core
->width
;
1115 ih
= wwin
->icon
->core
->height
;
1117 if (wwin
->flags
.net_handle_icon
) {
1125 iw
= wwin
->screen_ptr
->scr_width
;
1126 ih
= wwin
->screen_ptr
->scr_height
;
1129 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1130 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1135 wwin
->flags
.skip_next_animation
= 0;
1137 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1138 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1139 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1140 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1142 AddToStackList(wwin
->icon
->core
);
1143 wLowerFrame(wwin
->icon
->core
);
1147 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1150 * It doesn't seem to be working and causes button event hangup
1151 * when deiconifying a transient window.
1152 setupIconGrabs(wwin->icon);
1154 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1155 && wPreferences
.focus_mode
== WKF_CLICK
) {
1160 if (!WFLAGP(tmp
, no_focusable
)
1161 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1162 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1166 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1167 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1168 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1171 if (!wwin
->screen_ptr
->flags
.startup
) {
1172 /* Catch up with events not processed while animation was running */
1173 Window clientwin
= wwin
->client_win
;
1175 ProcessPendingEvents();
1177 /* the window can disappear while ProcessPendingEvents() runs */
1178 if (!wWindowFor(clientwin
)) {
1185 /* maybe we want to do this regardless of net_handle_icon
1186 * it seems to me we might break behaviour this way.
1188 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1189 && !wwin
->flags
.net_handle_icon
)
1190 wIconSelect(wwin
->icon
);
1192 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1194 if (wPreferences
.auto_arrange_icons
)
1195 wArrangeIcons(wwin
->screen_ptr
, True
);
1198 void wDeiconifyWindow(WWindow
*wwin
)
1200 /* Let's avoid changing workspace while deiconifying */
1201 ignore_wks_change
= 1;
1203 /* we're hiding for show_desktop */
1204 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1205 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1208 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1210 if (!wwin
->flags
.miniaturized
)
1213 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1214 WWindow
*owner
= recursiveTransientFor(wwin
);
1216 if (owner
&& owner
->flags
.miniaturized
) {
1217 wDeiconifyWindow(owner
);
1218 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1219 wRaiseFrame(wwin
->frame
->core
);
1224 wwin
->flags
.miniaturized
= 0;
1226 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1227 wwin
->flags
.mapped
= 1;
1229 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1230 /* maybe we want to do this regardless of net_handle_icon
1231 * it seems to me we might break behaviour this way.
1233 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1234 && wwin
->icon
!= NULL
) {
1235 if (wwin
->icon
->selected
)
1236 wIconSelect(wwin
->icon
);
1238 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1242 /* if the window is in another workspace, do it silently */
1243 if (!netwm_hidden
) {
1245 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
1246 && !wwin
->flags
.skip_next_animation
&& wwin
->icon
!= NULL
) {
1249 if (!wPreferences
.disable_miniwindows
1250 && !wwin
->flags
.net_handle_icon
) {
1253 iw
= wwin
->icon
->core
->width
;
1254 ih
= wwin
->icon
->core
->height
;
1256 if (wwin
->flags
.net_handle_icon
) {
1264 iw
= wwin
->screen_ptr
->scr_width
;
1265 ih
= wwin
->screen_ptr
->scr_height
;
1268 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1269 wwin
->frame_x
, wwin
->frame_y
,
1270 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1272 #endif /* ANIMATIONS */
1273 wwin
->flags
.skip_next_animation
= 0;
1275 if (!wwin
->flags
.shaded
)
1276 XMapWindow(dpy
, wwin
->client_win
);
1278 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1279 wRaiseFrame(wwin
->frame
->core
);
1280 if (!wwin
->flags
.shaded
)
1281 wClientSetState(wwin
, NormalState
, None
);
1283 mapTransientsFor(wwin
);
1286 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1287 && !wwin
->flags
.net_handle_icon
) {
1288 RemoveFromStackList(wwin
->icon
->core
);
1289 /* removeIconGrabs(wwin->icon); */
1290 wIconDestroy(wwin
->icon
);
1294 if (!netwm_hidden
) {
1297 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1300 if (!wwin
->screen_ptr
->flags
.startup
) {
1301 /* Catch up with events not processed while animation was running */
1302 Window clientwin
= wwin
->client_win
;
1304 ProcessPendingEvents();
1306 /* the window can disappear while ProcessPendingEvents() runs */
1307 if (!wWindowFor(clientwin
))
1313 if (wPreferences
.auto_arrange_icons
)
1314 wArrangeIcons(wwin
->screen_ptr
, True
);
1316 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1318 /* In case we were shaded and iconified, also unshade */
1320 wUnshadeWindow(wwin
);
1322 ignore_wks_change
= 0;
1325 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1327 if (wwin
->flags
.miniaturized
) {
1329 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1330 wwin
->icon
->mapped
= 0;
1332 wwin
->flags
.hidden
= 1;
1334 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1338 if (wwin
->flags
.inspector_open
) {
1339 wHideInspectorForWindow(wwin
);
1342 wwin
->flags
.hidden
= 1;
1345 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1349 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1350 !wwin
->flags
.skip_next_animation
&& animate
) {
1351 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1352 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1353 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1356 wwin
->flags
.skip_next_animation
= 0;
1358 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1361 void wHideAll(WScreen
*scr
)
1366 unsigned int wcount
= 0;
1372 menu
= scr
->switch_menu
;
1374 windows
= wmalloc(sizeof(WWindow
*));
1377 for (i
= 0; i
< menu
->entry_no
; i
++) {
1378 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1380 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1383 wwin
= scr
->focused_window
;
1386 windows
[wcount
] = wwin
;
1388 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1394 for (i
= 0; i
< wcount
; i
++) {
1396 if (wwin
->frame
->workspace
== scr
->current_workspace
1397 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1398 && !wwin
->flags
.internal_window
1399 && !WFLAGP(wwin
, no_miniaturizable
)
1401 wwin
->flags
.skip_next_animation
= 1;
1402 wIconifyWindow(wwin
);
1409 void wHideOtherApplications(WWindow
*awin
)
1416 wwin
= awin
->screen_ptr
->focused_window
;
1420 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1421 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1422 && !wwin
->flags
.internal_window
1423 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1425 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1426 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1427 wwin
->flags
.skip_next_animation
= 1;
1428 wIconifyWindow(wwin
);
1430 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1431 tapp
= wApplicationOf(wwin
->main_window
);
1433 tapp
->flags
.skip_next_animation
= 1;
1434 wHideApplication(tapp
);
1436 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1437 wwin
->flags
.skip_next_animation
= 1;
1438 wIconifyWindow(wwin
);
1446 wSetFocusTo(awin->screen_ptr, awin);
1450 void wHideApplication(WApplication
*wapp
)
1458 wwarning("trying to hide a non grouped window");
1461 if (!wapp
->main_window_desc
) {
1462 wwarning("group leader not found for window group");
1465 scr
= wapp
->main_window_desc
->screen_ptr
;
1467 wlist
= scr
->focused_window
;
1471 if (wlist
->main_window
== wapp
->main_window
)
1472 wapp
->last_focused
= wlist
;
1474 wapp
->last_focused
= NULL
;
1476 animate
= !wapp
->flags
.skip_next_animation
;
1479 if (wlist
->main_window
== wapp
->main_window
) {
1480 if (wlist
->flags
.focused
) {
1483 if (wapp
->app_icon
) {
1484 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1485 wapp
->app_icon
->y_pos
, wlist
, animate
);
1489 wlist
= wlist
->prev
;
1492 wapp
->flags
.skip_next_animation
= 0;
1495 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1496 wlist
= scr
->focused_window
;
1498 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1499 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1501 wlist
= wlist
->prev
;
1503 wSetFocusTo(scr
, wlist
);
1505 wSetFocusTo(scr
, NULL
);
1509 wapp
->flags
.hidden
= 1;
1511 if (wPreferences
.auto_arrange_icons
)
1512 wArrangeIcons(scr
, True
);
1516 wAppIconPaint(wapp
->app_icon
);
1520 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1522 if (bringToCurrentWS
)
1523 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1525 wwin
->flags
.hidden
= 0;
1528 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1529 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1530 icon
->core
->width
, icon
->core
->height
,
1531 wwin
->frame_x
, wwin
->frame_y
,
1532 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1535 wwin
->flags
.skip_next_animation
= 0;
1536 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1537 XMapWindow(dpy
, wwin
->client_win
);
1538 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1539 wClientSetState(wwin
, NormalState
, None
);
1540 wwin
->flags
.mapped
= 1;
1541 wRaiseFrame(wwin
->frame
->core
);
1543 if (wwin
->flags
.inspector_open
) {
1544 wUnhideInspectorForWindow(wwin
);
1547 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1550 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1553 WWindow
*wlist
, *next
;
1554 WWindow
*focused
= NULL
;
1560 scr
= wapp
->main_window_desc
->screen_ptr
;
1561 wlist
= scr
->focused_window
;
1565 /* goto beginning of list */
1567 wlist
= wlist
->prev
;
1569 animate
= !wapp
->flags
.skip_next_animation
;
1574 if (wlist
->main_window
== wapp
->main_window
) {
1575 if (wlist
->flags
.focused
)
1577 else if (!focused
|| !focused
->flags
.focused
)
1580 if (wlist
->flags
.miniaturized
) {
1581 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1582 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1583 if (!wlist
->icon
->mapped
) {
1586 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1587 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
) {
1588 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1592 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1593 wlist
->icon
->mapped
= 1;
1595 wRaiseFrame(wlist
->icon
->core
);
1597 if (bringToCurrentWS
)
1598 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1599 wlist
->flags
.hidden
= 0;
1600 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
) {
1601 wDeiconifyWindow(wlist
);
1603 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1604 } else if (wlist
->flags
.shaded
) {
1605 if (bringToCurrentWS
)
1606 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1607 wlist
->flags
.hidden
= 0;
1608 wRaiseFrame(wlist
->frame
->core
);
1609 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1610 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1612 wUnshadeWindow(wlist
);
1615 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1616 } else if (wlist
->flags
.hidden
) {
1617 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1618 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1621 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
) {
1622 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1624 wRaiseFrame(wlist
->frame
->core
);
1630 wapp
->flags
.skip_next_animation
= 0;
1631 wapp
->flags
.hidden
= 0;
1633 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1634 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1635 wSetFocusTo(scr
, wapp
->last_focused
);
1636 } else if (focused
) {
1637 wSetFocusTo(scr
, focused
);
1639 wapp
->last_focused
= NULL
;
1640 if (wPreferences
.auto_arrange_icons
)
1641 wArrangeIcons(scr
, True
);
1644 wAppIconPaint(wapp
->app_icon
);
1648 void wShowAllWindows(WScreen
*scr
)
1650 WWindow
*wwin
, *old_foc
;
1653 old_foc
= wwin
= scr
->focused_window
;
1655 if (!wwin
->flags
.internal_window
&&
1656 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1657 if (wwin
->flags
.miniaturized
) {
1658 wwin
->flags
.skip_next_animation
= 1;
1659 wDeiconifyWindow(wwin
);
1660 } else if (wwin
->flags
.hidden
) {
1661 wapp
= wApplicationOf(wwin
->main_window
);
1663 wUnhideApplication(wapp
, False
, False
);
1665 wwin
->flags
.skip_next_animation
= 1;
1666 wDeiconifyWindow(wwin
);
1672 wSetFocusTo(scr
, old_foc
);
1673 /*wRaiseFrame(old_foc->frame->core); */
1676 void wRefreshDesktop(WScreen
*scr
)
1679 XSetWindowAttributes attr
;
1681 attr
.backing_store
= NotUseful
;
1682 attr
.save_under
= False
;
1683 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1684 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1685 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1686 XMapRaised(dpy
, win
);
1687 XDestroyWindow(dpy
, win
);
1691 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1697 const int heads
= wXineramaHeads(scr
);
1700 int pf
; /* primary axis */
1701 int sf
; /* secondary axis */
1705 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1711 int isize
= wPreferences
.icon_size
;
1713 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1715 for (head
= 0; head
< heads
; ++head
) {
1716 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1717 WMRect rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1718 vars
[head
].pi
= vars
[head
].si
= 0;
1719 vars
[head
].sx1
= rect
.pos
.x
;
1720 vars
[head
].sy1
= rect
.pos
.y
;
1721 vars
[head
].sw
= rect
.size
.width
;
1722 vars
[head
].sh
= rect
.size
.height
;
1723 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1724 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1725 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1726 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1727 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1728 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1730 /* icon yard boundaries */
1731 if (wPreferences
.icon_yard
& IY_VERT
) {
1732 vars
[head
].pf
= vars
[head
].fullH
;
1733 vars
[head
].sf
= vars
[head
].fullW
;
1735 vars
[head
].pf
= vars
[head
].fullW
;
1736 vars
[head
].sf
= vars
[head
].fullH
;
1738 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1739 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1742 vars
[head
].xo
= vars
[head
].sx1
;
1745 if (wPreferences
.icon_yard
& IY_TOP
) {
1746 vars
[head
].yo
= vars
[head
].sy1
;
1749 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1754 #define X ((wPreferences.icon_yard & IY_VERT) \
1755 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1756 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1758 #define Y ((wPreferences.icon_yard & IY_VERT) \
1759 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1760 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1762 /* arrange application icons */
1763 aicon
= scr
->app_icon_list
;
1764 /* reverse them to avoid unnecessarily sliding of icons */
1765 while (aicon
&& aicon
->next
)
1766 aicon
= aicon
->next
;
1769 if (!aicon
->docked
) {
1770 /* CHECK: can icon be NULL here ? */
1771 /* The intention here is to place the AppIcon on the head that
1772 * contains most of the applications _main_ window. */
1773 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1775 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1777 if (!wPreferences
.no_animations
)
1778 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1779 #endif /* ANIMATIONS */
1781 wAppIconMove(aicon
, X
, Y
);
1783 if (vars
[head
].pi
>= vars
[head
].pf
) {
1788 aicon
= aicon
->prev
;
1791 /* arrange miniwindows */
1792 wwin
= scr
->focused_window
;
1793 /* reverse them to avoid unnecessarily shuffling */
1794 while (wwin
&& wwin
->prev
)
1798 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1799 (wwin
->frame
->workspace
== scr
->current_workspace
||
1800 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1802 head
= wGetHeadForWindow(wwin
);
1804 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1805 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1806 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1812 if (vars
[head
].pi
>= vars
[head
].pf
) {
1819 wwin
->flags
.icon_moved
= 0;
1821 /* we reversed the order, so we use next */
1828 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1830 WScreen
*scr
= wwin
->screen_ptr
;
1833 wwin
->flags
.selected
= 1;
1834 if (wwin
->frame
->selected_border_pixel
)
1835 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1837 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1839 if (!HAS_BORDER(wwin
)) {
1840 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->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 if (wwin
->frame
->border_pixel
)
1849 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1851 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1853 if (!HAS_BORDER(wwin
)) {
1854 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1857 if (scr
->selected_windows
) {
1858 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1863 void wMakeWindowVisible(WWindow
*wwin
)
1865 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
1866 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1868 if (wwin
->flags
.shaded
) {
1869 wUnshadeWindow(wwin
);
1871 if (wwin
->flags
.hidden
) {
1874 app
= wApplicationOf(wwin
->main_window
);
1876 /* trick to get focus to this window */
1877 app
->last_focused
= wwin
;
1878 wUnhideApplication(app
, False
, False
);
1881 if (wwin
->flags
.miniaturized
) {
1882 wDeiconifyWindow(wwin
);
1884 if (!WFLAGP(wwin
, no_focusable
))
1885 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1886 wRaiseFrame(wwin
->frame
->core
);
1891 * Do the animation while shading (called with what = SHADE)
1892 * or unshading (what = UNSHADE).
1895 static void shade_animate(WWindow
*wwin
, Bool what
)
1898 time_t time0
= time(NULL
);
1900 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1905 if (!wwin
->screen_ptr
->flags
.startup
) {
1906 /* do the shading animation */
1907 h
= wwin
->frame
->core
->height
;
1908 s
= h
/ SHADE_STEPS
;
1911 w
= wwin
->frame
->core
->width
;
1912 y
= wwin
->frame
->top_width
;
1913 while (h
> wwin
->frame
->top_width
+ 1) {
1914 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1915 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1918 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1921 if (SHADE_DELAY
> 0) {
1922 wusleep(SHADE_DELAY
* 1000L);
1929 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1934 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1935 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1936 s
= abs(y
) / SHADE_STEPS
;
1939 w
= wwin
->frame
->core
->width
;
1940 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1942 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1943 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1944 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1946 if (SHADE_DELAY
> 0) {
1947 wusleep(SHADE_DELAY
* 2000L / 3);
1954 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1958 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);