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
7 * Copyright (c) 2014 Window Maker Team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
40 #include "application.h"
46 #include "winspector.h"
47 #include "workspace.h"
50 #include "placement.h"
55 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
56 unsigned int *new_width
, unsigned int *new_height
);
57 static void save_old_geometry(WWindow
*wwin
, int directions
);
59 /******* Local Variables *******/
64 { SHADE_STEPS_UF
, SHADE_DELAY_UF
},
65 { SHADE_STEPS_F
, SHADE_DELAY_F
},
66 { SHADE_STEPS_M
, SHADE_DELAY_M
},
67 { SHADE_STEPS_S
, SHADE_DELAY_S
},
68 { SHADE_STEPS_US
, SHADE_DELAY_US
}
73 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
74 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
76 static int compareTimes(Time t1
, Time t2
)
82 return (diff
< 60000) ? 1 : -1;
86 static void shade_animate(WWindow
*wwin
, Bool what
);
88 static inline void shade_animate(WWindow
*wwin
, Bool what
)
91 * This function is empty on purpose, so tell the compiler
92 * to not warn about parameters being not used
100 *----------------------------------------------------------------------
102 * Changes the window focus to the one passed as argument.
103 * If the window to focus is not already focused, it will be brought
104 * to the head of the list of windows. Previously focused window is
108 * Window list may be reordered and the window focus is changed.
110 *----------------------------------------------------------------------
112 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
114 static WScreen
*old_scr
= NULL
;
116 WWindow
*old_focused
;
117 WWindow
*focused
= scr
->focused_window
;
118 Time timestamp
= w_global
.timestamp
.last_event
;
119 WApplication
*oapp
= NULL
, *napp
= NULL
;
122 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
128 old_focused
= old_scr
->focused_window
;
130 w_global
.timestamp
.focus_change
= timestamp
;
133 oapp
= wApplicationOf(old_focused
->main_window
);
136 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
138 wWindowUnfocus(old_focused
);
141 wAppMenuUnmap(oapp
->menu
);
142 if (wPreferences
.highlight_active_app
)
143 wApplicationDeactivate(oapp
);
146 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
150 if (old_scr
!= scr
&& old_focused
)
151 wWindowUnfocus(old_focused
);
153 wasfocused
= wwin
->flags
.focused
;
154 napp
= wApplicationOf(wwin
->main_window
);
156 /* remember last workspace where the app has been */
158 napp
->last_workspace
= wwin
->frame
->workspace
;
160 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
161 /* install colormap if colormap mode is lock mode */
162 if (wPreferences
.colormap_mode
== WCM_CLICK
)
163 wColormapInstallForWindow(scr
, wwin
);
165 /* set input focus */
166 switch (wwin
->focus_mode
) {
168 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
171 case WFM_LOCALLY_ACTIVE
:
172 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
174 case WFM_GLOBALLY_ACTIVE
:
179 if (wwin
->protocols
.TAKE_FOCUS
)
180 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
184 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
187 if (WFLAGP(wwin
, no_focusable
))
190 /* if this is not the focused window focus it */
191 if (focused
!= wwin
) {
192 /* change the focus window list order */
194 wwin
->prev
->next
= wwin
->next
;
197 wwin
->next
->prev
= wwin
->prev
;
199 wwin
->prev
= focused
;
200 focused
->next
= wwin
;
202 scr
->focused_window
= wwin
;
204 if (oapp
&& oapp
!= napp
) {
205 wAppMenuUnmap(oapp
->menu
);
206 if (wPreferences
.highlight_active_app
)
207 wApplicationDeactivate(oapp
);
211 wWindowFocus(wwin
, focused
);
213 if (napp
&& !wasfocused
) {
215 wUserMenuRefreshInstances(napp
->menu
, wwin
);
216 #endif /* USER_MENU */
218 if (wwin
->flags
.mapped
)
219 wAppMenuMap(napp
->menu
, wwin
);
221 if (napp
&& wPreferences
.highlight_active_app
)
222 wApplicationActivate(napp
);
228 void wShadeWindow(WWindow
*wwin
)
231 if (wwin
->flags
.shaded
)
234 XLowerWindow(dpy
, wwin
->client_win
);
235 shade_animate(wwin
, SHADE
);
237 wwin
->flags
.skip_next_animation
= 0;
238 wwin
->flags
.shaded
= 1;
239 wwin
->flags
.mapped
= 0;
240 /* prevent window withdrawal when getting UnmapNotify */
241 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
242 XUnmapWindow(dpy
, wwin
->client_win
);
243 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
245 /* for the client it's just like iconification */
246 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
248 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
249 wWindowSynthConfigureNotify(wwin
);
252 wClientSetState(wwin, IconicState, None);
255 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
258 if (!wwin
->screen_ptr
->flags
.startup
) {
259 /* Catch up with events not processed while animation was running */
260 ProcessPendingEvents();
265 void wUnshadeWindow(WWindow
*wwin
)
268 if (!wwin
->flags
.shaded
)
271 wwin
->flags
.shaded
= 0;
272 wwin
->flags
.mapped
= 1;
273 XMapWindow(dpy
, wwin
->client_win
);
275 shade_animate(wwin
, UNSHADE
);
277 wwin
->flags
.skip_next_animation
= 0;
278 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
279 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
281 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
282 wWindowSynthConfigureNotify(wwin
);
284 /* if the window is focused, set the focus again as it was disabled during
286 if (wwin
->flags
.focused
)
287 wSetFocusTo(wwin
->screen_ptr
, wwin
);
289 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
292 /* Set the old coordinates using the current values */
293 static void save_old_geometry(WWindow
*wwin
, int directions
)
295 /* never been saved? */
296 if (!wwin
->old_geometry
.width
)
297 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
298 if (!wwin
->old_geometry
.height
)
299 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
301 if (directions
& SAVE_GEOMETRY_X
)
302 wwin
->old_geometry
.x
= wwin
->frame_x
;
303 if (directions
& SAVE_GEOMETRY_Y
)
304 wwin
->old_geometry
.y
= wwin
->frame_y
;
305 if (directions
& SAVE_GEOMETRY_WIDTH
)
306 wwin
->old_geometry
.width
= wwin
->client
.width
;
307 if (directions
& SAVE_GEOMETRY_HEIGHT
)
308 wwin
->old_geometry
.height
= wwin
->client
.height
;
311 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
313 WMRect old_geom_rect
;
317 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
318 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
319 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
320 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
321 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
322 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
323 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
326 /* Remember geometry for unmaximizing */
327 void update_saved_geometry(WWindow
*wwin
)
329 /* NOT if we aren't already maximized
330 * we'll save geometry when maximizing */
331 if (!wwin
->flags
.maximized
)
334 /* NOT if we are fully maximized */
335 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
336 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
337 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
340 /* save the co-ordinate in the axis in which we AREN'T maximized */
341 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
342 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
343 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
344 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
347 void wMaximizeWindow(WWindow
*wwin
, int directions
)
349 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
354 unsigned int maximus_width
= 0;
355 unsigned int maximus_height
= 0;
356 WArea usableArea
, totalArea
;
359 WScreen
*scr
= wwin
->screen_ptr
;
361 if (!IS_RESIZABLE(wwin
))
364 if (!HAS_BORDER(wwin
))
367 /* the size to adjust the geometry */
368 adj_size
= scr
->frame_border_width
* 2 * has_border
;
370 /* save old coordinates before we change the current values */
371 if (!wwin
->flags
.maximized
)
372 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
374 totalArea
.x2
= scr
->scr_width
;
375 totalArea
.y2
= scr
->scr_height
;
378 usableArea
= totalArea
;
380 if (!(directions
& MAX_IGNORE_XINERAMA
)) {
381 WScreen
*scr
= wwin
->screen_ptr
;
384 if (directions
& MAX_KEYBOARD
)
385 head
= wGetHeadForWindow(wwin
);
387 head
= wGetHeadForPointerLocation(scr
);
389 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
393 /* Only save directions, not kbd or xinerama hints */
394 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
396 if (WFLAGP(wwin
, full_maximize
))
397 usableArea
= totalArea
;
398 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
399 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
401 if (wwin
->flags
.shaded
) {
402 wwin
->flags
.skip_next_animation
= 1;
403 wUnshadeWindow(wwin
);
406 if (directions
& MAX_MAXIMUS
) {
407 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
408 new_width
= maximus_width
- adj_size
;
409 new_height
= maximus_height
- adj_size
;
412 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
413 new_height
+= wwin
->frame
->bottom_width
- 1;
414 new_y
-= wwin
->frame
->top_width
;
417 wwin
->maximus_x
= new_x
;
418 wwin
->maximus_y
= new_y
;
419 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
421 /* set default values if no option set then */
422 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
423 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
424 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
426 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
427 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
428 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
431 /* left|right position */
432 if (directions
& MAX_LEFTHALF
) {
433 new_width
= half_scr_width
- adj_size
;
434 new_x
= usableArea
.x1
;
435 } else if (directions
& MAX_RIGHTHALF
) {
436 new_width
= half_scr_width
- adj_size
;
437 new_x
= usableArea
.x1
+ half_scr_width
;
439 /* top|bottom position */
440 if (directions
& MAX_TOPHALF
) {
441 new_height
= half_scr_height
- adj_size
;
442 new_y
= usableArea
.y1
;
443 } else if (directions
& MAX_BOTTOMHALF
) {
444 new_height
= half_scr_height
- adj_size
;
445 new_y
= usableArea
.y1
+ half_scr_height
;
448 /* vertical|horizontal position */
449 if (directions
& MAX_HORIZONTAL
) {
450 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
451 new_x
= usableArea
.x1
;
453 if (directions
& MAX_VERTICAL
) {
454 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
455 new_y
= usableArea
.y1
;
456 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
457 new_y
-= wwin
->frame
->top_width
;
461 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
462 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
464 /* set maximization state */
465 wwin
->flags
.maximized
= directions
;
466 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
467 wwin
->flags
.maximized
= MAX_MAXIMUS
;
469 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
471 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
472 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
474 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
475 wWindowSynthConfigureNotify(wwin
);
477 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
480 /* generic (un)maximizer */
481 void handleMaximize(WWindow
*wwin
, int directions
)
483 int current
= wwin
->flags
.maximized
;
484 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
485 int effective
= requested
^ current
;
486 int flags
= directions
& ~requested
;
489 /* allow wMaximizeWindow to restore the Maximusized size */
490 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
491 !(requested
& MAX_MAXIMUS
))
492 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
);
494 wUnmaximizeWindow(wwin
);
495 /* these alone mean vertical|horizontal toggle */
496 } else if ((effective
== MAX_LEFTHALF
) ||
497 (effective
== MAX_RIGHTHALF
) ||
498 (effective
== MAX_TOPHALF
) ||
499 (effective
== MAX_BOTTOMHALF
))
500 wUnmaximizeWindow(wwin
);
502 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
503 (requested
== MAX_MAXIMUS
))
504 effective
= requested
;
506 if (requested
& MAX_LEFTHALF
) {
507 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
508 effective
|= MAX_VERTICAL
;
510 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
511 effective
|= MAX_LEFTHALF
;
512 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
513 } else if (requested
& MAX_RIGHTHALF
) {
514 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
515 effective
|= MAX_VERTICAL
;
517 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
518 effective
|= MAX_RIGHTHALF
;
519 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
521 if (requested
& MAX_TOPHALF
) {
522 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
523 effective
|= MAX_HORIZONTAL
;
525 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
526 effective
|= MAX_TOPHALF
;
527 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
528 } else if (requested
& MAX_BOTTOMHALF
) {
529 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
530 effective
|= MAX_HORIZONTAL
;
532 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
533 effective
|= MAX_BOTTOMHALF
;
534 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
536 if (requested
& MAX_HORIZONTAL
)
537 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
538 if (requested
& MAX_VERTICAL
)
539 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
540 effective
&= ~MAX_MAXIMUS
;
542 wMaximizeWindow(wwin
, effective
| flags
);
546 /* the window boundary coordinates */
556 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
558 obs
->left
= wwin
->frame_x
;
559 obs
->top
= wwin
->frame_y
;
560 obs
->width
= wwin
->frame
->core
->width
;
561 obs
->height
= wwin
->frame
->core
->height
;
562 obs
->bottom
= obs
->top
+ obs
->height
;
563 obs
->right
= obs
->left
+ obs
->width
;
567 * Maximus: tiled maximization (maximize without overlapping other windows)
569 * The original window 'orig' will be maximized to new coordinates 'new'.
570 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
572 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
573 unsigned int *new_width
, unsigned int *new_height
)
576 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
577 short int adjust_height
;
578 int x_intsect
, y_intsect
;
579 /* the obstructing, original and new windows */
580 win_coords obs
, orig
, new;
582 /* set the original coordinate positions of the window to be Maximumized */
583 if (wwin
->flags
.maximized
) {
584 /* window is already maximized; consider original geometry */
585 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
586 orig
.bottom
= orig
.top
+ orig
.height
;
587 orig
.right
= orig
.left
+ orig
.width
;
589 set_window_coords(wwin
, &orig
);
591 /* Try to fully maximize first, then readjust later */
592 new.left
= usableArea
.x1
;
593 new.right
= usableArea
.x2
;
594 new.top
= usableArea
.y1
;
595 new.bottom
= usableArea
.y2
;
597 if (HAS_TITLEBAR(wwin
))
598 tbar_height_0
= TITLEBAR_HEIGHT
;
599 if (HAS_RESIZEBAR(wwin
))
600 rbar_height_0
= RESIZEBAR_HEIGHT
;
601 if (HAS_BORDER(wwin
))
602 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
604 /* the length to be subtracted if the window has titlebar, etc */
605 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
608 /* The focused window is always the last in the list */
610 /* ignore windows in other workspaces etc */
611 if (tmp
->prev
->frame
->workspace
!= w_global
.workspace
.current
||
612 tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
618 /* Set the coordinates of obstructing window */
619 set_window_coords(tmp
, &obs
);
621 /* Try to maximize in the y direction first */
622 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
623 if (x_intsect
!= 0) {
624 /* TODO: Consider the case when coords are equal */
625 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
626 /* w_0 is below the bottom of w_j */
627 new.top
= obs
.bottom
+ 1;
629 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
630 /* The bottom of w_0 is above the top of w_j */
631 new.bottom
= obs
.top
- 1;
638 if (tmp
->prev
->frame
->workspace
!= w_global
.workspace
.current
||
639 tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
645 set_window_coords(tmp
, &obs
);
648 * Use the new.top and new.height instead of original values
649 * as they may have different intersections with the obstructing windows
651 new.height
= new.bottom
- new.top
- adjust_height
;
652 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
653 if (y_intsect
!= 0) {
654 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
655 /* w_0 is completely to the right of w_j */
656 new.left
= obs
.right
+ 1;
658 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
659 /* w_0 is completely to the left of w_j */
660 new.right
= obs
.left
- 1;
667 /* xcalc needs -7 here, but other apps don't */
668 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
669 *new_width
= new.right
- new.left
;
672 void wUnmaximizeWindow(WWindow
*wwin
)
676 if (!wwin
->flags
.maximized
)
679 if (wwin
->flags
.shaded
) {
680 wwin
->flags
.skip_next_animation
= 1;
681 wUnshadeWindow(wwin
);
684 /* Use old coordinates if they are set, current values otherwise */
685 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
687 /* unMaximusize relative to original position */
688 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
689 x
+= wwin
->frame_x
- wwin
->maximus_x
;
690 y
+= wwin
->frame_y
- wwin
->maximus_y
;
693 wwin
->flags
.maximized
= 0;
694 wwin
->flags
.old_maximized
= 0;
695 wWindowConfigure(wwin
, x
, y
, w
, h
);
696 wWindowSynthConfigureNotify(wwin
);
698 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
701 void wFullscreenWindow(WWindow
*wwin
)
706 if (wwin
->flags
.fullscreen
)
709 wwin
->flags
.fullscreen
= True
;
711 wWindowConfigureBorders(wwin
);
713 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
714 wRaiseFrame(wwin
->frame
->core
);
716 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
717 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
718 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
719 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
721 head
= wGetHeadForWindow(wwin
);
722 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
723 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
725 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
726 wSetFocusTo(wwin
->screen_ptr
, wwin
);
728 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
731 void wUnfullscreenWindow(WWindow
*wwin
)
733 if (!wwin
->flags
.fullscreen
)
736 wwin
->flags
.fullscreen
= False
;
738 if (WFLAGP(wwin
, sunken
))
739 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
740 else if (WFLAGP(wwin
, floating
))
741 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
743 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
744 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
746 wWindowConfigureBorders(wwin
);
748 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
749 wFrameWindowPaint(wwin->frame);
752 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
754 if (wwin
->screen_ptr
->bfs_focused_window
) {
755 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
756 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
761 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
763 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
764 float cx
, cy
, cw
, ch
;
765 float xstep
, ystep
, wstep
, hstep
;
768 float angle
, final_angle
, delta
;
770 xstep
= (float)(fx
- x
) / steps
;
771 ystep
= (float)(fy
- y
) / steps
;
772 wstep
= (float)(fw
- w
) / steps
;
773 hstep
= (float)(fh
- h
) / steps
;
780 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
781 delta
= (float)(final_angle
/ FRAMES
);
782 for (angle
= 0;; angle
+= delta
) {
783 if (angle
> final_angle
)
786 dx
= (cw
/ 10) - ((cw
/ 5) * sin(angle
));
787 dch
= (ch
/ 2) * cos(angle
);
788 midy
= cy
+ (ch
/ 2);
790 points
[0].x
= cx
+ dx
;
791 points
[0].y
= midy
- dch
;
792 points
[1].x
= cx
+ cw
- dx
;
793 points
[1].y
= points
[0].y
;
794 points
[2].x
= cx
+ cw
+ dx
;
795 points
[2].y
= midy
+ dch
;
796 points
[3].x
= cx
- dx
;
797 points
[3].y
= points
[2].y
;
798 points
[4].x
= points
[0].x
;
799 points
[4].y
= points
[0].y
;
802 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
804 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
806 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
812 if (angle
>= final_angle
)
822 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
824 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
825 float cx
, cy
, cw
, ch
;
826 float xstep
, ystep
, wstep
, hstep
;
828 float angle
, final_angle
, a
, d
, delta
;
835 xstep
= (float)(fx
- x
) / steps
;
836 ystep
= (float)(fy
- y
) / steps
;
837 wstep
= (float)(fw
- w
) / steps
;
838 hstep
= (float)(fh
- h
) / steps
;
845 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
846 delta
= (float)(final_angle
/ FRAMES
);
847 for (angle
= 0;; angle
+= delta
) {
848 if (angle
> final_angle
)
852 d
= sqrt((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
854 points
[0].x
= cx
+ cos(angle
- a
) * d
;
855 points
[0].y
= cy
+ sin(angle
- a
) * d
;
856 points
[1].x
= cx
+ cos(angle
+ a
) * d
;
857 points
[1].y
= cy
+ sin(angle
+ a
) * d
;
858 points
[2].x
= cx
+ cos(angle
- a
+ WM_PI
) * d
;
859 points
[2].y
= cy
+ sin(angle
- a
+ WM_PI
) * d
;
860 points
[3].x
= cx
+ cos(angle
+ a
+ WM_PI
) * d
;
861 points
[3].y
= cy
+ sin(angle
+ a
+ WM_PI
) * d
;
862 points
[4].x
= cx
+ cos(angle
- a
) * d
;
863 points
[4].y
= cy
+ sin(angle
- a
) * d
;
865 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
867 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
869 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
875 if (angle
>= final_angle
)
884 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
886 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
887 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
888 float xstep
, ystep
, wstep
, hstep
;
891 xstep
= (float)(fx
- x
) / steps
;
892 ystep
= (float)(fy
- y
) / steps
;
893 wstep
= (float)(fw
- w
) / steps
;
894 hstep
= (float)(fh
- h
) / steps
;
896 for (j
= 0; j
< FRAMES
; j
++) {
903 for (i
= 0; i
< steps
; i
++) {
904 for (j
= 0; j
< FRAMES
; j
++) {
905 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
906 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
909 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
911 for (j
= 0; j
< FRAMES
; j
++) {
912 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
913 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
914 if (j
< FRAMES
- 1) {
928 for (j
= 0; j
< FRAMES
; j
++)
929 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
931 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
933 for (j
= 0; j
< FRAMES
; j
++)
934 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
941 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
943 int style
= wPreferences
.iconification_style
; /* Catch the value */
946 if (style
== WIS_NONE
)
949 if (style
== WIS_RANDOM
)
954 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
956 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
959 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
961 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
965 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
967 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
971 #endif /* ANIMATIONS */
973 static void flushExpose(void)
977 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
978 WMHandleEvent(&tmpev
);
982 static void unmapTransientsFor(WWindow
*wwin
)
986 tmp
= wwin
->screen_ptr
->focused_window
;
988 /* unmap the transients for this transient */
989 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
990 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
991 unmapTransientsFor(tmp
);
992 tmp
->flags
.miniaturized
= 1;
993 if (!tmp
->flags
.shaded
)
996 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
998 if (!tmp->flags.shaded)
1000 wClientSetState(tmp
, IconicState
, None
);
1002 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1008 static void mapTransientsFor(WWindow
*wwin
)
1012 tmp
= wwin
->screen_ptr
->focused_window
;
1014 /* recursively map the transients for this transient */
1015 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1016 && tmp
->icon
== NULL
) {
1017 mapTransientsFor(tmp
);
1018 tmp
->flags
.miniaturized
= 0;
1019 if (!tmp
->flags
.shaded
)
1022 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1023 tmp
->flags
.semi_focused
= 0;
1025 if (!tmp->flags.shaded)
1027 wClientSetState(tmp
, NormalState
, None
);
1029 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1035 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1042 /* hackish way to detect transient_for cycle */
1043 i
= wwin
->screen_ptr
->window_count
+ 1;
1045 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1046 wwin
= wWindowFor(wwin
->transient_for
);
1049 if (i
== 0 && wwin
) {
1050 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin
->frame
->title
);
1057 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1059 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1060 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1063 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1066 *iw
= wwin
->icon
->core
->width
;
1067 *ih
= wwin
->icon
->core
->height
;
1069 if (wwin
->flags
.net_handle_icon
) {
1077 *iw
= wwin
->screen_ptr
->scr_width
;
1078 *ih
= wwin
->screen_ptr
->scr_height
;
1084 void wIconifyWindow(WWindow
*wwin
)
1086 XWindowAttributes attribs
;
1089 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1090 return; /* the window doesn't exist anymore */
1092 if (wwin
->flags
.miniaturized
)
1093 return; /* already miniaturized */
1095 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1096 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1098 if (owner
&& owner
->flags
.miniaturized
)
1102 present
= wwin
->frame
->workspace
== w_global
.workspace
.current
;
1104 /* if the window is in another workspace, simplify process */
1106 /* icon creation may take a while */
1107 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1108 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1109 GrabModeAsync
, None
, None
, CurrentTime
);
1112 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1113 if (!wwin
->flags
.icon_moved
)
1114 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1116 wwin
->icon
= icon_create_for_wwindow(wwin
);
1117 wwin
->icon
->mapped
= 1;
1119 /* extract the window screenshot everytime, as the option can be enable anytime */
1120 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1127 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1128 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1133 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1134 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1136 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1137 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1139 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1141 apercu
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1142 XDestroyImage(pimg
);
1145 set_icon_apercu(wwin
->icon
, apercu
);
1146 RReleaseImage(apercu
);
1148 wwarning("window apercu creation failed");
1154 wwin
->flags
.miniaturized
= 1;
1155 wwin
->flags
.mapped
= 0;
1157 /* unmap transients */
1158 unmapTransientsFor(wwin
);
1164 XUngrabPointer(dpy
, CurrentTime
);
1166 /* let all Expose events arrive so that we can repaint
1167 * something before the animation starts (and the server is grabbed) */
1170 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1171 wClientSetState(wwin
, IconicState
, None
);
1173 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1177 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1178 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1179 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1183 wwin
->flags
.skip_next_animation
= 0;
1185 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1186 if (w_global
.workspace
.current
== wwin
->frame
->workspace
||
1187 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1188 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1190 AddToStackList(wwin
->icon
->core
);
1191 wLowerFrame(wwin
->icon
->core
);
1195 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1198 * It doesn't seem to be working and causes button event hangup
1199 * when deiconifying a transient window.
1200 setupIconGrabs(wwin->icon);
1202 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1203 && wPreferences
.focus_mode
== WKF_CLICK
) {
1208 if (!WFLAGP(tmp
, no_focusable
)
1209 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1210 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1214 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1215 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1216 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1219 if (!wwin
->screen_ptr
->flags
.startup
) {
1220 /* Catch up with events not processed while animation was running */
1221 Window clientwin
= wwin
->client_win
;
1223 ProcessPendingEvents();
1225 /* the window can disappear while ProcessPendingEvents() runs */
1226 if (!wWindowFor(clientwin
))
1232 /* maybe we want to do this regardless of net_handle_icon
1233 * it seems to me we might break behaviour this way.
1235 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1236 && !wwin
->flags
.net_handle_icon
)
1237 wIconSelect(wwin
->icon
);
1239 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1241 if (wPreferences
.auto_arrange_icons
)
1242 wArrangeIcons(wwin
->screen_ptr
, True
);
1245 void wDeiconifyWindow(WWindow
*wwin
)
1247 /* Let's avoid changing workspace while deiconifying */
1248 w_global
.workspace
.ignore_change
= True
;
1250 /* we're hiding for show_desktop */
1251 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1252 wwin
->frame
->workspace
!= w_global
.workspace
.current
;
1255 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1257 if (!wwin
->flags
.miniaturized
) {
1258 w_global
.workspace
.ignore_change
= False
;
1262 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1263 WWindow
*owner
= recursiveTransientFor(wwin
);
1265 if (owner
&& owner
->flags
.miniaturized
) {
1266 wDeiconifyWindow(owner
);
1267 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1268 wRaiseFrame(wwin
->frame
->core
);
1269 w_global
.workspace
.ignore_change
= False
;
1274 wwin
->flags
.miniaturized
= 0;
1276 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1277 wwin
->flags
.mapped
= 1;
1279 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1280 /* maybe we want to do this regardless of net_handle_icon
1281 * it seems to me we might break behaviour this way.
1283 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1284 && wwin
->icon
!= NULL
) {
1285 if (wwin
->icon
->selected
)
1286 wIconSelect(wwin
->icon
);
1288 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1292 /* if the window is in another workspace, do it silently */
1293 if (!netwm_hidden
) {
1296 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1297 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1298 wwin
->frame_x
, wwin
->frame_y
,
1299 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1301 wwin
->flags
.skip_next_animation
= 0;
1303 if (!wwin
->flags
.shaded
)
1304 XMapWindow(dpy
, wwin
->client_win
);
1306 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1307 wRaiseFrame(wwin
->frame
->core
);
1308 if (!wwin
->flags
.shaded
)
1309 wClientSetState(wwin
, NormalState
, None
);
1311 mapTransientsFor(wwin
);
1314 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1315 && !wwin
->flags
.net_handle_icon
) {
1316 RemoveFromStackList(wwin
->icon
->core
);
1317 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1318 wIconDestroy(wwin
->icon
);
1322 if (!netwm_hidden
) {
1325 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1328 if (!wwin
->screen_ptr
->flags
.startup
) {
1329 /* Catch up with events not processed while animation was running */
1330 Window clientwin
= wwin
->client_win
;
1332 ProcessPendingEvents();
1334 /* the window can disappear while ProcessPendingEvents() runs */
1335 if (!wWindowFor(clientwin
)) {
1336 w_global
.workspace
.ignore_change
= False
;
1343 if (wPreferences
.auto_arrange_icons
)
1344 wArrangeIcons(wwin
->screen_ptr
, True
);
1346 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1348 /* In case we were shaded and iconified, also unshade */
1350 wUnshadeWindow(wwin
);
1352 w_global
.workspace
.ignore_change
= False
;
1355 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1357 if (wwin
->flags
.miniaturized
) {
1359 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1360 wwin
->icon
->mapped
= 0;
1362 wwin
->flags
.hidden
= 1;
1364 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1368 if (wwin
->flags
.inspector_open
)
1369 wHideInspectorForWindow(wwin
);
1371 wwin
->flags
.hidden
= 1;
1374 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1378 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1379 !wwin
->flags
.skip_next_animation
&& animate
) {
1380 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1381 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1382 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1385 wwin
->flags
.skip_next_animation
= 0;
1387 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1390 void wHideAll(WScreen
*scr
)
1395 unsigned int wcount
= 0;
1401 menu
= scr
->switch_menu
;
1403 windows
= wmalloc(sizeof(WWindow
*));
1406 for (i
= 0; i
< menu
->entry_no
; i
++) {
1407 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1409 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1412 wwin
= scr
->focused_window
;
1415 windows
[wcount
] = wwin
;
1417 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1423 for (i
= 0; i
< wcount
; i
++) {
1425 if (wwin
->frame
->workspace
== w_global
.workspace
.current
1426 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1427 && !wwin
->flags
.internal_window
1428 && !WFLAGP(wwin
, no_miniaturizable
)
1430 wwin
->flags
.skip_next_animation
= 1;
1431 wIconifyWindow(wwin
);
1438 void wHideOtherApplications(WWindow
*awin
)
1445 wwin
= awin
->screen_ptr
->focused_window
;
1449 && wwin
->frame
->workspace
== w_global
.workspace
.current
1450 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1451 && !wwin
->flags
.internal_window
1452 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1454 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1455 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1456 wwin
->flags
.skip_next_animation
= 1;
1457 wIconifyWindow(wwin
);
1459 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1460 tapp
= wApplicationOf(wwin
->main_window
);
1462 tapp
->flags
.skip_next_animation
= 1;
1463 wHideApplication(tapp
);
1465 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1466 wwin
->flags
.skip_next_animation
= 1;
1467 wIconifyWindow(wwin
);
1475 wSetFocusTo(awin->screen_ptr, awin);
1479 void wHideApplication(WApplication
*wapp
)
1487 wwarning("trying to hide a non grouped window");
1490 if (!wapp
->main_window_desc
) {
1491 wwarning("group leader not found for window group");
1494 scr
= wapp
->main_window_desc
->screen_ptr
;
1496 wlist
= scr
->focused_window
;
1500 if (wlist
->main_window
== wapp
->main_window
)
1501 wapp
->last_focused
= wlist
;
1503 wapp
->last_focused
= NULL
;
1505 animate
= !wapp
->flags
.skip_next_animation
;
1508 if (wlist
->main_window
== wapp
->main_window
) {
1509 if (wlist
->flags
.focused
)
1511 if (wapp
->app_icon
) {
1512 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1513 wapp
->app_icon
->y_pos
, wlist
, animate
);
1517 wlist
= wlist
->prev
;
1520 wapp
->flags
.skip_next_animation
= 0;
1523 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1524 wlist
= scr
->focused_window
;
1526 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1527 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1529 wlist
= wlist
->prev
;
1531 wSetFocusTo(scr
, wlist
);
1533 wSetFocusTo(scr
, NULL
);
1537 wapp
->flags
.hidden
= 1;
1539 if (wPreferences
.auto_arrange_icons
)
1540 wArrangeIcons(scr
, True
);
1544 wAppIconPaint(wapp
->app_icon
);
1548 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1550 if (bringToCurrentWS
)
1551 wWindowChangeWorkspace(wwin
, w_global
.workspace
.current
);
1553 wwin
->flags
.hidden
= 0;
1556 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1557 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1558 icon
->core
->width
, icon
->core
->height
,
1559 wwin
->frame_x
, wwin
->frame_y
,
1560 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1563 wwin
->flags
.skip_next_animation
= 0;
1564 if (w_global
.workspace
.current
== wwin
->frame
->workspace
) {
1565 XMapWindow(dpy
, wwin
->client_win
);
1566 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1567 wClientSetState(wwin
, NormalState
, None
);
1568 wwin
->flags
.mapped
= 1;
1569 wRaiseFrame(wwin
->frame
->core
);
1571 if (wwin
->flags
.inspector_open
)
1572 wUnhideInspectorForWindow(wwin
);
1574 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1577 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1580 WWindow
*wlist
, *next
;
1581 WWindow
*focused
= NULL
;
1587 scr
= wapp
->main_window_desc
->screen_ptr
;
1588 wlist
= scr
->focused_window
;
1592 /* goto beginning of list */
1594 wlist
= wlist
->prev
;
1596 animate
= !wapp
->flags
.skip_next_animation
;
1601 if (wlist
->main_window
== wapp
->main_window
) {
1602 if (wlist
->flags
.focused
)
1604 else if (!focused
|| !focused
->flags
.focused
)
1607 if (wlist
->flags
.miniaturized
) {
1608 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1609 wlist
->frame
->workspace
== w_global
.workspace
.current
) && wlist
->icon
) {
1610 if (!wlist
->icon
->mapped
) {
1613 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1614 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1615 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1618 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1619 wlist
->icon
->mapped
= 1;
1621 wRaiseFrame(wlist
->icon
->core
);
1623 if (bringToCurrentWS
)
1624 wWindowChangeWorkspace(wlist
, w_global
.workspace
.current
);
1625 wlist
->flags
.hidden
= 0;
1626 if (miniwindows
&& wlist
->frame
->workspace
== w_global
.workspace
.current
)
1627 wDeiconifyWindow(wlist
);
1628 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1629 } else if (wlist
->flags
.shaded
) {
1630 if (bringToCurrentWS
)
1631 wWindowChangeWorkspace(wlist
, w_global
.workspace
.current
);
1632 wlist
->flags
.hidden
= 0;
1633 wRaiseFrame(wlist
->frame
->core
);
1634 if (wlist
->frame
->workspace
== w_global
.workspace
.current
) {
1635 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1637 wUnshadeWindow(wlist
);
1639 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1640 } else if (wlist
->flags
.hidden
) {
1641 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1642 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1645 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= w_global
.workspace
.current
)
1646 wWindowChangeWorkspace(wlist
, w_global
.workspace
.current
);
1648 wRaiseFrame(wlist
->frame
->core
);
1654 wapp
->flags
.skip_next_animation
= 0;
1655 wapp
->flags
.hidden
= 0;
1657 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1658 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1659 wSetFocusTo(scr
, wapp
->last_focused
);
1660 } else if (focused
) {
1661 wSetFocusTo(scr
, focused
);
1663 wapp
->last_focused
= NULL
;
1664 if (wPreferences
.auto_arrange_icons
)
1665 wArrangeIcons(scr
, True
);
1668 wAppIconPaint(wapp
->app_icon
);
1672 void wShowAllWindows(WScreen
*scr
)
1674 WWindow
*wwin
, *old_foc
;
1677 old_foc
= wwin
= scr
->focused_window
;
1679 if (!wwin
->flags
.internal_window
&&
1680 (w_global
.workspace
.current
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1681 if (wwin
->flags
.miniaturized
) {
1682 wwin
->flags
.skip_next_animation
= 1;
1683 wDeiconifyWindow(wwin
);
1684 } else if (wwin
->flags
.hidden
) {
1685 wapp
= wApplicationOf(wwin
->main_window
);
1687 wUnhideApplication(wapp
, False
, False
);
1689 wwin
->flags
.skip_next_animation
= 1;
1690 wDeiconifyWindow(wwin
);
1696 wSetFocusTo(scr
, old_foc
);
1697 /*wRaiseFrame(old_foc->frame->core); */
1700 void wRefreshDesktop(WScreen
*scr
)
1703 XSetWindowAttributes attr
;
1705 attr
.backing_store
= NotUseful
;
1706 attr
.save_under
= False
;
1707 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1708 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1709 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1710 XMapRaised(dpy
, win
);
1711 XDestroyWindow(dpy
, win
);
1715 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1721 const int heads
= wXineramaHeads(scr
);
1724 int pf
; /* primary axis */
1725 int sf
; /* secondary axis */
1729 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1735 int isize
= wPreferences
.icon_size
;
1737 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1739 for (head
= 0; head
< heads
; ++head
) {
1740 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1744 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1746 if (scr
->dock
->on_right_side
)
1752 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1754 vars
[head
].pi
= vars
[head
].si
= 0;
1755 vars
[head
].sx1
= rect
.pos
.x
;
1756 vars
[head
].sy1
= rect
.pos
.y
;
1757 vars
[head
].sw
= rect
.size
.width
;
1758 vars
[head
].sh
= rect
.size
.height
;
1759 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1760 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1761 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1762 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1763 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1764 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1766 /* icon yard boundaries */
1767 if (wPreferences
.icon_yard
& IY_VERT
) {
1768 vars
[head
].pf
= vars
[head
].fullH
;
1769 vars
[head
].sf
= vars
[head
].fullW
;
1771 vars
[head
].pf
= vars
[head
].fullW
;
1772 vars
[head
].sf
= vars
[head
].fullH
;
1774 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1775 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1778 vars
[head
].xo
= vars
[head
].sx1
;
1781 if (wPreferences
.icon_yard
& IY_TOP
) {
1782 vars
[head
].yo
= vars
[head
].sy1
;
1785 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1790 #define X ((wPreferences.icon_yard & IY_VERT) \
1791 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1792 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1794 #define Y ((wPreferences.icon_yard & IY_VERT) \
1795 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1796 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1798 /* arrange application icons */
1799 aicon
= w_global
.app_icon_list
;
1800 /* reverse them to avoid unnecessarily sliding of icons */
1801 while (aicon
&& aicon
->next
)
1802 aicon
= aicon
->next
;
1805 if (!aicon
->docked
) {
1806 /* CHECK: can icon be NULL here ? */
1807 /* The intention here is to place the AppIcon on the head that
1808 * contains most of the applications _main_ window. */
1809 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1811 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1813 if (!wPreferences
.no_animations
)
1814 SlideWindow(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1815 #endif /* ANIMATIONS */
1817 wAppIconMove(aicon
, X
, Y
);
1819 if (vars
[head
].pi
>= vars
[head
].pf
) {
1824 aicon
= aicon
->prev
;
1827 /* arrange miniwindows */
1828 wwin
= scr
->focused_window
;
1829 /* reverse them to avoid unnecessarily shuffling */
1830 while (wwin
&& wwin
->prev
)
1834 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1835 (wwin
->frame
->workspace
== w_global
.workspace
.current
||
1836 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1838 head
= wGetHeadForWindow(wwin
);
1840 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1841 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1842 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
1848 if (vars
[head
].pi
>= vars
[head
].pf
) {
1855 wwin
->flags
.icon_moved
= 0;
1856 /* we reversed the order, so we use next */
1863 void wSelectWindow(WWindow
*wwin
, Bool flag
)
1865 WScreen
*scr
= wwin
->screen_ptr
;
1868 wwin
->flags
.selected
= 1;
1869 if (wwin
->frame
->selected_border_pixel
)
1870 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
1872 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
1874 if (!HAS_BORDER(wwin
))
1875 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
1877 if (!scr
->selected_windows
)
1878 scr
->selected_windows
= WMCreateArray(4);
1879 WMAddToArray(scr
->selected_windows
, wwin
);
1881 wwin
->flags
.selected
= 0;
1882 if (wwin
->flags
.focused
) {
1883 if (wwin
->frame
->focused_border_pixel
)
1884 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
1886 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
1888 if (wwin
->frame
->border_pixel
)
1889 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
1891 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
1894 if (!HAS_BORDER(wwin
))
1895 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
1897 if (scr
->selected_windows
)
1898 WMRemoveFromArray(scr
->selected_windows
, wwin
);
1902 void wMakeWindowVisible(WWindow
*wwin
)
1904 if (wwin
->frame
->workspace
!= w_global
.workspace
.current
)
1905 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
1907 if (wwin
->flags
.shaded
)
1908 wUnshadeWindow(wwin
);
1910 if (wwin
->flags
.hidden
) {
1913 app
= wApplicationOf(wwin
->main_window
);
1915 /* trick to get focus to this window */
1916 app
->last_focused
= wwin
;
1917 wUnhideApplication(app
, False
, False
);
1920 if (wwin
->flags
.miniaturized
) {
1921 wDeiconifyWindow(wwin
);
1923 if (!WFLAGP(wwin
, no_focusable
))
1924 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1925 wRaiseFrame(wwin
->frame
->core
);
1930 * Do the animation while shading (called with what = SHADE)
1931 * or unshading (what = UNSHADE).
1934 static void shade_animate(WWindow
*wwin
, Bool what
)
1937 time_t time0
= time(NULL
);
1939 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
1944 if (!wwin
->screen_ptr
->flags
.startup
) {
1945 /* do the shading animation */
1946 h
= wwin
->frame
->core
->height
;
1947 s
= h
/ SHADE_STEPS
;
1950 w
= wwin
->frame
->core
->width
;
1951 y
= wwin
->frame
->top_width
;
1952 while (h
> wwin
->frame
->top_width
+ 1) {
1953 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1954 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1957 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1960 if (SHADE_DELAY
> 0)
1961 wusleep(SHADE_DELAY
* 1000L);
1967 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
1972 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
1973 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
1974 s
= abs(y
) / SHADE_STEPS
;
1977 w
= wwin
->frame
->core
->width
;
1978 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1980 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
1981 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
1982 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
1984 if (SHADE_DELAY
> 0)
1985 wusleep(SHADE_DELAY
* 2000L / 3);
1991 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
1995 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);