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-2023 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 #ifndef HAVE_FLOAT_MATHFUNC
56 #define sinf(x) ((float)sin((double)(x)))
57 #define cosf(x) ((float)cos((double)(x)))
58 #define sqrtf(x) ((float)sqrt((double)(x)))
59 #define atan2f(y, x) ((float)atan((double)(y) / (double)(x)))
62 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
63 unsigned int *new_width
, unsigned int *new_height
);
64 static void save_old_geometry(WWindow
*wwin
, int directions
);
66 /******* Local Variables *******/
72 { SHADE_STEPS_UF
, SHADE_DELAY_UF
},
73 { SHADE_STEPS_F
, SHADE_DELAY_F
},
74 { SHADE_STEPS_M
, SHADE_DELAY_M
},
75 { SHADE_STEPS_S
, SHADE_DELAY_S
},
76 { SHADE_STEPS_US
, SHADE_DELAY_US
}
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
86 static int compareTimes(Time t1
, Time t2
)
92 return (diff
< 60000) ? 1 : -1;
96 static void shade_animate(WWindow
*wwin
, Bool what
);
98 static inline void shade_animate(WWindow
*wwin
, Bool what
)
101 * This function is empty on purpose, so tell the compiler
102 * to not warn about parameters being not used
110 *----------------------------------------------------------------------
112 * Changes the window focus to the one passed as argument.
113 * If the window to focus is not already focused, it will be brought
114 * to the head of the list of windows. Previously focused window is
118 * Window list may be reordered and the window focus is changed.
120 *----------------------------------------------------------------------
122 void wSetFocusTo(WScreen
*scr
, WWindow
*wwin
)
124 static WScreen
*old_scr
= NULL
;
126 WWindow
*old_focused
;
127 WWindow
*focused
= scr
->focused_window
;
128 Time timestamp
= w_global
.timestamp
.last_event
;
129 WApplication
*oapp
= NULL
, *napp
= NULL
;
132 if (scr
->flags
.ignore_focus_events
|| compareTimes(w_global
.timestamp
.focus_change
, timestamp
) > 0)
138 old_focused
= old_scr
->focused_window
;
140 w_global
.timestamp
.focus_change
= timestamp
;
143 oapp
= wApplicationOf(old_focused
->main_window
);
146 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
148 wWindowUnfocus(old_focused
);
151 wAppMenuUnmap(oapp
->menu
);
152 if (wPreferences
.highlight_active_app
)
153 wApplicationDeactivate(oapp
);
156 WMPostNotificationName(WMNChangedFocus
, NULL
, (void *)True
);
160 if (old_scr
!= scr
&& old_focused
)
161 wWindowUnfocus(old_focused
);
163 wasfocused
= wwin
->flags
.focused
;
164 napp
= wApplicationOf(wwin
->main_window
);
166 /* remember last workspace where the app has been */
168 napp
->last_workspace
= wwin
->frame
->workspace
;
170 if (wwin
->flags
.mapped
&& !WFLAGP(wwin
, no_focusable
)) {
171 /* install colormap if colormap mode is lock mode */
172 if (wPreferences
.colormap_mode
== WCM_CLICK
)
173 wColormapInstallForWindow(scr
, wwin
);
175 /* set input focus */
176 switch (wwin
->focus_mode
) {
178 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
181 case WFM_LOCALLY_ACTIVE
:
182 XSetInputFocus(dpy
, wwin
->client_win
, RevertToParent
, CurrentTime
);
184 case WFM_GLOBALLY_ACTIVE
:
189 if (wwin
->protocols
.TAKE_FOCUS
)
190 wClientSendProtocol(wwin
, w_global
.atom
.wm
.take_focus
, timestamp
);
194 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
197 if (WFLAGP(wwin
, no_focusable
))
200 /* if this is not the focused window focus it */
201 if (focused
!= wwin
) {
202 /* change the focus window list order */
204 wwin
->prev
->next
= wwin
->next
;
207 wwin
->next
->prev
= wwin
->prev
;
209 wwin
->prev
= focused
;
210 focused
->next
= wwin
;
212 scr
->focused_window
= wwin
;
214 if (oapp
&& oapp
!= napp
) {
215 wAppMenuUnmap(oapp
->menu
);
216 if (wPreferences
.highlight_active_app
)
217 wApplicationDeactivate(oapp
);
220 /* reset fullscreen if temporarily removed due to lost focus*/
221 if (wwin
->flags
.fullscreen
)
222 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
225 wWindowFocus(wwin
, focused
);
227 if (napp
&& !wasfocused
) {
229 wUserMenuRefreshInstances(napp
->menu
, wwin
);
230 #endif /* USER_MENU */
232 /* kix: Only menu map with mouse, not alt+tab! */
233 if (wwin
->flags
.mapped
)
234 wAppMenuMap(napp
->menu
, wwin
);
236 if (napp
&& wPreferences
.highlight_active_app
)
237 wApplicationActivate(napp
);
243 void wShadeWindow(WWindow
*wwin
)
246 if (wwin
->flags
.shaded
)
249 XLowerWindow(dpy
, wwin
->client_win
);
250 shade_animate(wwin
, SHADE
);
252 wwin
->flags
.skip_next_animation
= 0;
253 wwin
->flags
.shaded
= 1;
254 wwin
->flags
.mapped
= 0;
255 /* prevent window withdrawal when getting UnmapNotify */
256 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
& ~StructureNotifyMask
);
257 XUnmapWindow(dpy
, wwin
->client_win
);
258 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
260 /* for the client it's just like iconification */
261 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
, wwin
->frame
->top_width
- 1);
263 wwin
->client
.y
= wwin
->frame_y
- wwin
->client
.height
+ wwin
->frame
->top_width
;
264 wWindowSynthConfigureNotify(wwin
);
267 wClientSetState(wwin, IconicState, None);
270 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
272 #ifdef USE_ANIMATIONS
273 if (!wwin
->screen_ptr
->flags
.startup
) {
274 /* Catch up with events not processed while animation was running */
275 ProcessPendingEvents();
280 void wUnshadeWindow(WWindow
*wwin
)
283 if (!wwin
->flags
.shaded
)
286 wwin
->flags
.shaded
= 0;
287 wwin
->flags
.mapped
= 1;
288 XMapWindow(dpy
, wwin
->client_win
);
290 shade_animate(wwin
, UNSHADE
);
292 wwin
->flags
.skip_next_animation
= 0;
293 wFrameWindowResize(wwin
->frame
, wwin
->frame
->core
->width
,
294 wwin
->frame
->top_width
+ wwin
->client
.height
+ wwin
->frame
->bottom_width
);
296 wwin
->client
.y
= wwin
->frame_y
+ wwin
->frame
->top_width
;
297 wWindowSynthConfigureNotify(wwin
);
299 /* if the window is focused, set the focus again as it was disabled during
301 if (wwin
->flags
.focused
)
302 wSetFocusTo(wwin
->screen_ptr
, wwin
);
304 WMPostNotificationName(WMNChangedState
, wwin
, "shade");
307 /* Set the old coordinates using the current values */
308 static void save_old_geometry(WWindow
*wwin
, int directions
)
310 /* never been saved? */
311 if (!wwin
->old_geometry
.width
)
312 directions
|= SAVE_GEOMETRY_X
| SAVE_GEOMETRY_WIDTH
;
313 if (!wwin
->old_geometry
.height
)
314 directions
|= SAVE_GEOMETRY_Y
| SAVE_GEOMETRY_HEIGHT
;
316 if (directions
& SAVE_GEOMETRY_X
)
317 wwin
->old_geometry
.x
= wwin
->frame_x
;
318 if (directions
& SAVE_GEOMETRY_Y
)
319 wwin
->old_geometry
.y
= wwin
->frame_y
;
320 if (directions
& SAVE_GEOMETRY_WIDTH
)
321 wwin
->old_geometry
.width
= wwin
->client
.width
;
322 if (directions
& SAVE_GEOMETRY_HEIGHT
)
323 wwin
->old_geometry
.height
= wwin
->client
.height
;
326 static void remember_geometry(WWindow
*wwin
, int *x
, int *y
, int *w
, int *h
)
328 WMRect old_geom_rect
;
332 old_geom_rect
= wmkrect(wwin
->old_geometry
.x
, wwin
->old_geometry
.y
, wwin
->old_geometry
.width
, wwin
->old_geometry
.height
);
333 old_head
= wGetHeadForRect(wwin
->screen_ptr
, old_geom_rect
);
334 same_head
= (wGetHeadForWindow(wwin
) == old_head
);
335 *x
= ((wwin
->old_geometry
.x
|| wwin
->old_geometry
.width
) && same_head
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
336 *y
= ((wwin
->old_geometry
.y
|| wwin
->old_geometry
.height
) && same_head
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
337 *w
= wwin
->old_geometry
.width
? wwin
->old_geometry
.width
: wwin
->client
.width
;
338 *h
= wwin
->old_geometry
.height
? wwin
->old_geometry
.height
: wwin
->client
.height
;
341 /* Remember geometry for unmaximizing */
342 void update_saved_geometry(WWindow
*wwin
)
344 /* NOT if we aren't already maximized
345 * we'll save geometry when maximizing */
346 if (!wwin
->flags
.maximized
)
349 /* NOT if we are fully maximized */
350 if ((wwin
->flags
.maximized
& MAX_MAXIMUS
) ||
351 ((wwin
->flags
.maximized
& MAX_HORIZONTAL
) &&
352 (wwin
->flags
.maximized
& MAX_VERTICAL
)))
355 /* save the co-ordinate in the axis in which we AREN'T maximized */
356 if (wwin
->flags
.maximized
& MAX_HORIZONTAL
)
357 save_old_geometry(wwin
, SAVE_GEOMETRY_Y
);
358 if (wwin
->flags
.maximized
& MAX_VERTICAL
)
359 save_old_geometry(wwin
, SAVE_GEOMETRY_X
);
362 void wMaximizeWindow(WWindow
*wwin
, int directions
, int head
)
364 unsigned int new_width
, new_height
, half_scr_width
, half_scr_height
;
369 unsigned int maximus_width
= 0;
370 unsigned int maximus_height
= 0;
371 WArea usableArea
, totalArea
;
374 WScreen
*scr
= wwin
->screen_ptr
;
376 if (!IS_RESIZABLE(wwin
))
379 if (!HAS_BORDER(wwin
))
382 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
383 wwin
->client_flags
.no_movable
= 1;
385 /* the size to adjust the geometry */
386 adj_size
= scr
->frame_border_width
* 2 * has_border
;
388 /* save old coordinates before we change the current values */
389 if (!wwin
->flags
.maximized
)
390 save_old_geometry(wwin
, SAVE_GEOMETRY_ALL
);
392 totalArea
.x2
= scr
->scr_width
;
393 totalArea
.y2
= scr
->scr_height
;
397 /* In case of mouse initiated maximize, use the head in which pointer is
398 located, rather than window position, which is passed to the function */
399 if (!(directions
& MAX_IGNORE_XINERAMA
) && !(directions
& MAX_KEYBOARD
)) {
400 WScreen
*scr
= wwin
->screen_ptr
;
401 head
= wGetHeadForPointerLocation(scr
);
404 usableArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
406 /* Only save directions, not kbd or xinerama hints */
407 directions
&= (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
| MAX_CENTRAL
);
409 if (WFLAGP(wwin
, full_maximize
))
410 usableArea
= totalArea
;
411 half_scr_width
= (usableArea
.x2
- usableArea
.x1
)/2;
412 half_scr_height
= (usableArea
.y2
- usableArea
.y1
)/2;
414 if (wwin
->flags
.shaded
) {
415 wwin
->flags
.skip_next_animation
= 1;
416 wUnshadeWindow(wwin
);
419 if (directions
& MAX_MAXIMUS
) {
420 find_Maximus_geometry(wwin
, usableArea
, &maximus_x
, &maximus_y
, &maximus_width
, &maximus_height
);
421 new_width
= maximus_width
- adj_size
;
422 new_height
= maximus_height
- adj_size
;
425 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0)) {
426 new_height
+= wwin
->frame
->bottom_width
- 1;
427 new_y
-= wwin
->frame
->top_width
;
430 wwin
->maximus_x
= new_x
;
431 wwin
->maximus_y
= new_y
;
432 wwin
->flags
.old_maximized
|= MAX_MAXIMUS
;
434 /* center the window if can fit, if not sticking it to the screen edges */
435 if (directions
& MAX_CENTRAL
) {
436 if (wwin
->frame
->core
->height
> (usableArea
.y2
- usableArea
.y1
)) {
437 new_y
= usableArea
.y1
;
438 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
440 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
441 new_height
+= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
442 new_y
= half_scr_height
- new_height
/ 2;
444 if (wwin
->frame
->core
->width
> (usableArea
.x2
- usableArea
.x1
)) {
445 new_x
= usableArea
.x1
;
446 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
449 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
450 new_x
= half_scr_width
- new_width
/ 2;
453 /* set default values if no option set then */
454 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
| MAX_CENTRAL
))) {
455 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
456 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
458 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
| MAX_CENTRAL
))) {
459 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
460 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
463 /* left|right position */
464 if (directions
& MAX_LEFTHALF
) {
465 new_width
= half_scr_width
- adj_size
;
466 new_x
= usableArea
.x1
;
467 if (directions
& MAX_CENTRAL
) {
468 new_y
= half_scr_height
- wwin
->old_geometry
.height
/ 2;
470 } else if (directions
& MAX_RIGHTHALF
) {
471 new_width
= half_scr_width
- adj_size
;
472 new_x
= usableArea
.x1
+ half_scr_width
;
473 if (directions
& MAX_CENTRAL
)
474 new_y
= half_scr_height
- wwin
->old_geometry
.height
/ 2;
476 /* top|bottom position */
477 if (directions
& MAX_TOPHALF
) {
478 new_height
= half_scr_height
- adj_size
;
479 new_y
= usableArea
.y1
;
480 if (directions
& MAX_CENTRAL
)
481 new_x
= half_scr_width
- wwin
->old_geometry
.width
/ 2;
482 } else if (directions
& MAX_BOTTOMHALF
) {
483 new_height
= half_scr_height
- adj_size
;
484 new_y
= usableArea
.y1
+ half_scr_height
;
485 if (directions
& MAX_CENTRAL
)
486 new_x
= half_scr_width
- wwin
->old_geometry
.width
/ 2;
489 /* vertical|horizontal position */
490 if (directions
& MAX_HORIZONTAL
) {
491 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
492 new_x
= usableArea
.x1
;
494 if (directions
& MAX_VERTICAL
) {
495 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
496 new_y
= usableArea
.y1
;
497 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
498 new_y
-= wwin
->frame
->top_width
;
502 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
503 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
505 /* set maximization state */
506 wwin
->flags
.maximized
= directions
;
507 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
508 wwin
->flags
.maximized
= MAX_MAXIMUS
;
510 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
512 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
513 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
515 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
516 wWindowSynthConfigureNotify(wwin
);
518 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
521 /* generic (un)maximizer */
522 void handleMaximize(WWindow
*wwin
, int directions
)
524 int current
= wwin
->flags
.maximized
;
525 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
| MAX_CENTRAL
);
526 int effective
= requested
^ current
;
527 int flags
= directions
& ~requested
;
528 int head
= wGetHeadForWindow(wwin
);
532 /* allow wMaximizeWindow to restore the Maximusized size */
533 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
534 !(requested
& MAX_MAXIMUS
))
535 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
, head
);
537 else if (wPreferences
.alt_half_maximize
&&
538 current
& MAX_HORIZONTAL
&& current
& MAX_VERTICAL
&&
539 requested
& MAX_HORIZONTAL
&& requested
& MAX_VERTICAL
)
540 wUnmaximizeWindow(wwin
);
542 /* Apply for window state, which is only horizontally or vertically
543 * maximized. Quarters cannot be handled here, since there is not clear
544 * on which direction user intend to move such window. */
545 else if (wPreferences
.move_half_max_between_heads
&&
546 current
& (MAX_VERTICAL
| MAX_HORIZONTAL
)) {
547 if (requested
& MAX_LEFTHALF
&& current
& MAX_LEFTHALF
) {
548 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
549 head
, DIRECTION_LEFT
);
550 if (dest_head
!= -1) {
551 effective
|= MAX_RIGHTHALF
;
552 effective
|= MAX_VERTICAL
;
553 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
555 } else if (requested
& MAX_RIGHTHALF
&&
556 current
& MAX_RIGHTHALF
) {
557 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
558 head
, DIRECTION_RIGHT
);
559 if (dest_head
!= -1) {
560 effective
|= MAX_LEFTHALF
;
561 effective
|= MAX_VERTICAL
;
562 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
564 } else if (requested
& MAX_TOPHALF
&& current
& MAX_TOPHALF
) {
565 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
567 if (dest_head
!= -1) {
568 effective
|= MAX_BOTTOMHALF
;
569 effective
|= MAX_HORIZONTAL
;
570 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
572 } else if (requested
& MAX_BOTTOMHALF
&&
573 current
& MAX_BOTTOMHALF
) {
574 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
575 head
, DIRECTION_DOWN
);
576 if (dest_head
!= -1) {
577 effective
|= MAX_TOPHALF
;
578 effective
|= MAX_HORIZONTAL
;
579 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
585 /* tell wMaximizeWindow that we were using keyboard, not mouse,
586 * so that it will use calculated head as destination for
587 * move_half_max_between_heads feature, not from mouse pointer */
588 wMaximizeWindow(wwin
, (effective
| flags
| MAX_KEYBOARD
),
590 else if (!wPreferences
.alt_half_maximize
)
591 wUnmaximizeWindow(wwin
);
596 /* these alone mean vertical|horizontal toggle */
597 if ((effective
== MAX_LEFTHALF
) ||
598 (effective
== MAX_RIGHTHALF
) ||
599 (effective
== MAX_TOPHALF
) ||
600 (effective
== MAX_BOTTOMHALF
))
601 wUnmaximizeWindow(wwin
);
603 /* Following conditions might look complicated, but they are really simple:
604 * allow fullscreen transition only for half maximized state (and not
605 * corners) and only when requested state is also half maximized, but on
606 * opposite side of the screen. As for corners, it is similar, but
607 * expected is that only quarter maximized windows on corner can change
608 * its state to half maximized window, depending on direction. Note, that
609 * MAX_KEYBOARD is passed to the wMaximizeWindow function, to preserve the
610 * head, even if mouse was used for triggering the action. */
612 /* Quarters alternative transition. */
613 else if (wPreferences
.alt_half_maximize
&&
614 ((requested
& MAX_LEFTHALF
&& requested
& MAX_TOPHALF
&&
615 current
& MAX_RIGHTHALF
&& current
& MAX_TOPHALF
) ||
616 (requested
& MAX_RIGHTHALF
&& requested
& MAX_TOPHALF
&&
617 current
& MAX_LEFTHALF
&& current
& MAX_TOPHALF
)))
618 wMaximizeWindow(wwin
, (MAX_TOPHALF
| MAX_HORIZONTAL
| MAX_KEYBOARD
),
620 else if (wPreferences
.alt_half_maximize
&&
621 ((requested
& MAX_LEFTHALF
&& requested
& MAX_BOTTOMHALF
&&
622 current
& MAX_RIGHTHALF
&& current
& MAX_BOTTOMHALF
) ||
623 (requested
& MAX_RIGHTHALF
&& requested
& MAX_BOTTOMHALF
&&
624 current
& MAX_LEFTHALF
&& current
& MAX_BOTTOMHALF
)))
625 wMaximizeWindow(wwin
, (MAX_BOTTOMHALF
| MAX_HORIZONTAL
| MAX_KEYBOARD
),
627 else if (wPreferences
.alt_half_maximize
&&
628 ((requested
& MAX_LEFTHALF
&& requested
& MAX_BOTTOMHALF
&&
629 current
& MAX_LEFTHALF
&& current
& MAX_TOPHALF
) ||
630 (requested
& MAX_LEFTHALF
&& requested
& MAX_TOPHALF
&&
631 current
& MAX_LEFTHALF
&& current
& MAX_BOTTOMHALF
)))
632 wMaximizeWindow(wwin
, (MAX_LEFTHALF
| MAX_VERTICAL
| MAX_KEYBOARD
),
634 else if (wPreferences
.alt_half_maximize
&&
635 ((requested
& MAX_RIGHTHALF
&& requested
& MAX_BOTTOMHALF
&&
636 current
& MAX_RIGHTHALF
&& current
& MAX_TOPHALF
) ||
637 (requested
& MAX_RIGHTHALF
&& requested
& MAX_TOPHALF
&&
638 current
& MAX_RIGHTHALF
&& current
& MAX_BOTTOMHALF
)))
639 wMaximizeWindow(wwin
, (MAX_RIGHTHALF
| MAX_VERTICAL
| MAX_KEYBOARD
),
642 /* Half-maximized alternative transition */
643 else if (wPreferences
.alt_half_maximize
&& (
644 (requested
& MAX_LEFTHALF
&& requested
& MAX_VERTICAL
&&
645 current
& MAX_RIGHTHALF
&& current
& MAX_VERTICAL
) ||
646 (requested
& MAX_RIGHTHALF
&& requested
& MAX_VERTICAL
&&
647 current
& MAX_LEFTHALF
&& current
& MAX_VERTICAL
) ||
648 (requested
& MAX_TOPHALF
&& requested
& MAX_HORIZONTAL
&&
649 current
& MAX_BOTTOMHALF
&& current
& MAX_HORIZONTAL
) ||
650 (requested
& MAX_BOTTOMHALF
&& requested
& MAX_HORIZONTAL
&&
651 current
& MAX_TOPHALF
&& current
& MAX_HORIZONTAL
)))
652 wMaximizeWindow(wwin
, (MAX_HORIZONTAL
|MAX_VERTICAL
|MAX_KEYBOARD
),
657 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
658 (requested
== MAX_MAXIMUS
))
659 effective
= requested
;
661 if (requested
& MAX_CENTRAL
) {
662 effective
|= MAX_CENTRAL
;
663 if (current
& (MAX_HORIZONTAL
| MAX_VERTICAL
))
664 effective
&= ~(MAX_HORIZONTAL
| MAX_VERTICAL
);
665 else if (current
& MAX_TOPHALF
&& current
& MAX_LEFTHALF
)
666 effective
&= ~(MAX_TOPHALF
| MAX_LEFTHALF
);
667 else if (current
& MAX_TOPHALF
&& current
& MAX_RIGHTHALF
)
668 effective
&= ~(MAX_TOPHALF
| MAX_RIGHTHALF
);
669 else if (current
& MAX_BOTTOMHALF
&& current
& MAX_LEFTHALF
)
670 effective
&= ~(MAX_BOTTOMHALF
| MAX_LEFTHALF
);
671 else if (current
& MAX_BOTTOMHALF
&& current
& MAX_RIGHTHALF
)
672 effective
&= ~(MAX_BOTTOMHALF
| MAX_RIGHTHALF
);
673 } else if (requested
& MAX_LEFTHALF
) {
674 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
675 effective
|= MAX_VERTICAL
;
677 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
678 effective
|= MAX_LEFTHALF
;
679 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
680 } else if (requested
& MAX_RIGHTHALF
) {
681 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
682 effective
|= MAX_VERTICAL
;
684 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
685 effective
|= MAX_RIGHTHALF
;
686 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
688 if (requested
& MAX_TOPHALF
) {
689 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
690 effective
|= MAX_HORIZONTAL
;
692 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
693 effective
|= MAX_TOPHALF
;
694 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
695 } else if (requested
& MAX_BOTTOMHALF
) {
696 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
697 effective
|= MAX_HORIZONTAL
;
699 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
700 effective
|= MAX_BOTTOMHALF
;
701 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
703 if (requested
& MAX_HORIZONTAL
)
704 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
705 if (requested
& MAX_VERTICAL
)
706 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
707 effective
&= ~MAX_MAXIMUS
;
709 wMaximizeWindow(wwin
, effective
| flags
, head
);
713 /* Moving window between heads
715 * Window is moved between all avaiable heads for current screen in
716 * requested direction.
718 * If heads have different sizes, window position will be adjusted to be inside
719 * screen. Window will be unmaximized on move, so that it can be immediately be
720 * maximixed by another shortcut.
723 * direction = 0 means move clock-wise from 12h position to 6h
724 * (first try moving right, then bottom, then left, then up)
725 * direction = 1 means move clock-wise from 6h position to 12h
726 * (first try moving left, then up, then right, then bottom)
729 * As side effect this mean if you have 9 monitors - you will not be able to
730 * move window into central cell without mouse.
732 * For common cases with 1 or 2 extra monitors this should work just fine.
736 void moveBetweenHeads(WWindow
*wwin
, int direction
)
738 int head
= wGetHeadForWindow(wwin
);
741 unsigned int new_width
, new_height
;
742 int offsetX
, newX
= 0;
743 int offsetY
, newY
= 0;
744 WArea totalArea
, oldHeadArea
, destHeadArea
;
745 WScreen
*scr
= wwin
->screen_ptr
;
747 int try_movements
[2][4] = {
748 {DIRECTION_RIGHT
, DIRECTION_DOWN
, DIRECTION_LEFT
, DIRECTION_UP
},
749 {DIRECTION_LEFT
, DIRECTION_UP
, DIRECTION_RIGHT
, DIRECTION_DOWN
}
752 /* loop through directions array and try movements until one works */
753 for (int try_movement_idx
= 0;
754 destHead
== -1 && try_movement_idx
< 4; try_movement_idx
++) {
755 destHead
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
756 head
, try_movements
[direction
][try_movement_idx
]);
759 if (destHead
!= -1) {
762 totalArea
.x2
= scr
->scr_width
;
763 totalArea
.y2
= scr
->scr_height
;
765 oldHeadArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
766 destHeadArea
= wGetUsableAreaForHead(scr
, destHead
, &totalArea
, True
);
768 offsetX
= wwin
->frame_x
- oldHeadArea
.x1
;
769 offsetY
= wwin
->frame_y
- oldHeadArea
.y1
;
771 newX
= destHeadArea
.x1
+ offsetX
;
772 newY
= destHeadArea
.y1
+ offsetY
;
774 new_width
= wwin
->client
.width
;
775 new_height
= wwin
->client
.height
;
777 /* try to brind window inside head coordinates */
778 if (newX
> destHeadArea
.x2
)
779 newX
= destHeadArea
.x2
- wwin
->client
.width
;
781 if (newX
< destHeadArea
.x1
)
782 newX
= destHeadArea
.x1
;
784 if (newY
> destHeadArea
.y2
)
785 newY
= destHeadArea
.y2
- wwin
->client
.height
;
787 if (newY
< destHeadArea
.y1
)
788 newY
= destHeadArea
.y1
;
790 /* unset maximization state */
791 wwin
->flags
.maximized
= 0;
792 wWindowConfigure(wwin
, newX
, newY
, new_width
, new_height
);
798 /* the window boundary coordinates */
808 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
810 obs
->left
= wwin
->frame_x
;
811 obs
->top
= wwin
->frame_y
;
812 obs
->width
= wwin
->frame
->core
->width
;
813 obs
->height
= wwin
->frame
->core
->height
;
814 obs
->bottom
= obs
->top
+ obs
->height
;
815 obs
->right
= obs
->left
+ obs
->width
;
819 * Maximus: tiled maximization (maximize without overlapping other windows)
821 * The original window 'orig' will be maximized to new coordinates 'new'.
822 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
824 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
825 unsigned int *new_width
, unsigned int *new_height
)
828 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
829 short int adjust_height
;
830 int x_intsect
, y_intsect
;
831 /* the obstructing, original and new windows */
832 win_coords obs
, orig
, new;
834 /* set the original coordinate positions of the window to be Maximumized */
835 if (wwin
->flags
.maximized
) {
836 /* window is already maximized; consider original geometry */
837 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
838 orig
.bottom
= orig
.top
+ orig
.height
;
839 orig
.right
= orig
.left
+ orig
.width
;
841 set_window_coords(wwin
, &orig
);
843 /* Try to fully maximize first, then readjust later */
844 new.left
= usableArea
.x1
;
845 new.right
= usableArea
.x2
;
846 new.top
= usableArea
.y1
;
847 new.bottom
= usableArea
.y2
;
849 if (HAS_TITLEBAR(wwin
))
850 tbar_height_0
= TITLEBAR_HEIGHT
;
851 if (HAS_RESIZEBAR(wwin
))
852 rbar_height_0
= RESIZEBAR_HEIGHT
;
853 if (HAS_BORDER(wwin
))
854 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
856 /* the length to be subtracted if the window has titlebar, etc */
857 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
860 /* The focused window is always the last in the list */
862 /* ignore windows in other workspaces etc */
863 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
864 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
870 /* Set the coordinates of obstructing window */
871 set_window_coords(tmp
, &obs
);
873 /* Try to maximize in the y direction first */
874 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
875 if (x_intsect
!= 0) {
876 /* TODO: Consider the case when coords are equal */
877 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
878 /* w_0 is below the bottom of w_j */
879 new.top
= obs
.bottom
+ 1;
881 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
882 /* The bottom of w_0 is above the top of w_j */
883 new.bottom
= obs
.top
- 1;
890 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
891 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
897 set_window_coords(tmp
, &obs
);
900 * Use the new.top and new.height instead of original values
901 * as they may have different intersections with the obstructing windows
903 new.height
= new.bottom
- new.top
- adjust_height
;
904 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
905 if (y_intsect
!= 0) {
906 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
907 /* w_0 is completely to the right of w_j */
908 new.left
= obs
.right
+ 1;
910 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
911 /* w_0 is completely to the left of w_j */
912 new.right
= obs
.left
- 1;
919 /* xcalc needs -7 here, but other apps don't */
920 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
921 *new_width
= new.right
- new.left
;
924 void wUnmaximizeWindow(WWindow
*wwin
)
928 if (!wwin
->flags
.maximized
)
931 if (wwin
->flags
.shaded
) {
932 wwin
->flags
.skip_next_animation
= 1;
933 wUnshadeWindow(wwin
);
936 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
937 wwin
->client_flags
.no_movable
= 0;
939 /* Use old coordinates if they are set, current values otherwise */
940 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
942 /* unMaximusize relative to original position */
943 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
944 x
+= wwin
->frame_x
- wwin
->maximus_x
;
945 y
+= wwin
->frame_y
- wwin
->maximus_y
;
948 wwin
->flags
.maximized
= 0;
949 wwin
->flags
.old_maximized
= 0;
950 wWindowConfigure(wwin
, x
, y
, w
, h
);
951 wWindowSynthConfigureNotify(wwin
);
953 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
957 void wFullscreenMonitorsWindow(WWindow
*wwin
, unsigned long top
, unsigned long bottom
,
958 unsigned long left
, unsigned long right
)
964 if ((int)top
< wwin
->screen_ptr
->xine_info
.count
&&
965 (int)bottom
< wwin
->screen_ptr
->xine_info
.count
&&
966 (int)left
< wwin
->screen_ptr
->xine_info
.count
&&
967 (int)right
< wwin
->screen_ptr
->xine_info
.count
) {
968 wwin
->flags
.fullscreen_monitors
[0] = top
;
969 wwin
->flags
.fullscreen_monitors
[1] = bottom
;
970 wwin
->flags
.fullscreen_monitors
[2] = left
;
971 wwin
->flags
.fullscreen_monitors
[3] = right
;
973 wwin
->flags
.fullscreen_monitors
[0] = -1;
977 wwin
->flags
.fullscreen
= True
;
978 wWindowConfigureBorders(wwin
);
979 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
981 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
982 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
983 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
984 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
987 monitor
= wwin
->flags
.fullscreen_monitors
[i
];
988 rect1
= wwin
->screen_ptr
->xine_info
.screens
[monitor
];
990 for (i
= 1; i
<= 3; i
++) {
991 monitor
= wwin
->flags
.fullscreen_monitors
[i
];
992 rect2
= wwin
->screen_ptr
->xine_info
.screens
[monitor
];
993 wGetRectUnion(&rect1
, &rect2
, &rect1
);
995 wWindowConfigure(wwin
, rect1
.pos
.x
, rect1
.pos
.y
, rect1
.size
.width
, rect1
.size
.height
);
997 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
998 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1000 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
1004 void wFullscreenWindow(WWindow
*wwin
)
1009 if (wwin
->flags
.fullscreen
)
1012 wwin
->flags
.fullscreen
= True
;
1014 wWindowConfigureBorders(wwin
);
1016 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
1018 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
1019 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
1020 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
1021 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
1023 head
= wGetHeadForWindow(wwin
);
1024 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
1025 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
1027 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
1028 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1030 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
1033 void wUnfullscreenWindow(WWindow
*wwin
)
1035 if (!wwin
->flags
.fullscreen
)
1038 wwin
->flags
.fullscreen
= False
;
1040 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
1041 if (WFLAGP(wwin
, sunken
)) {
1042 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
1043 } else if (WFLAGP(wwin
, floating
)) {
1044 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
1046 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
1050 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
1051 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
1053 wWindowConfigureBorders(wwin
);
1055 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
1056 wFrameWindowPaint(wwin->frame);
1059 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
1061 if (wwin
->screen_ptr
->bfs_focused_window
) {
1062 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
1063 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
1067 #ifdef USE_ANIMATIONS
1068 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
1070 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
1071 float cx
, cy
, cw
, ch
;
1072 float xstep
, ystep
, wstep
, hstep
;
1074 float dx
, dch
, midy
;
1075 float angle
, final_angle
, delta
;
1077 xstep
= (float)(fx
- x
) / steps
;
1078 ystep
= (float)(fy
- y
) / steps
;
1079 wstep
= (float)(fw
- w
) / steps
;
1080 hstep
= (float)(fh
- h
) / steps
;
1087 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
1088 delta
= (float)(final_angle
/ FRAMES
);
1089 for (angle
= 0;; angle
+= delta
) {
1090 if (angle
> final_angle
)
1091 angle
= final_angle
;
1093 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
1094 dch
= (ch
/ 2) * cosf(angle
);
1095 midy
= cy
+ (ch
/ 2);
1097 points
[0].x
= cx
+ dx
;
1098 points
[0].y
= midy
- dch
;
1099 points
[1].x
= cx
+ cw
- dx
;
1100 points
[1].y
= points
[0].y
;
1101 points
[2].x
= cx
+ cw
+ dx
;
1102 points
[2].y
= midy
+ dch
;
1103 points
[3].x
= cx
- dx
;
1104 points
[3].y
= points
[2].y
;
1105 points
[4].x
= points
[0].x
;
1106 points
[4].y
= points
[0].y
;
1109 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1111 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
1113 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1119 if (angle
>= final_angle
)
1129 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
1131 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
1132 float cx
, cy
, cw
, ch
;
1133 float xstep
, ystep
, wstep
, hstep
;
1135 float angle
, final_angle
, a
, d
, delta
;
1142 xstep
= (float)(fx
- x
) / steps
;
1143 ystep
= (float)(fy
- y
) / steps
;
1144 wstep
= (float)(fw
- w
) / steps
;
1145 hstep
= (float)(fh
- h
) / steps
;
1152 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
1153 delta
= (float)(final_angle
/ FRAMES
);
1154 for (angle
= 0;; angle
+= delta
) {
1155 if (angle
> final_angle
)
1156 angle
= final_angle
;
1159 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
1161 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
1162 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
1163 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
1164 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
1165 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
1166 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
1167 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
1168 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
1169 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
1170 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
1172 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1174 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
1176 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1182 if (angle
>= final_angle
)
1191 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
1193 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
1194 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
1195 float xstep
, ystep
, wstep
, hstep
;
1198 xstep
= (float)(fx
- x
) / steps
;
1199 ystep
= (float)(fy
- y
) / steps
;
1200 wstep
= (float)(fw
- w
) / steps
;
1201 hstep
= (float)(fh
- h
) / steps
;
1203 for (j
= 0; j
< FRAMES
; j
++) {
1210 for (i
= 0; i
< steps
; i
++) {
1211 for (j
= 0; j
< FRAMES
; j
++) {
1212 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
1213 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1216 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
1218 for (j
= 0; j
< FRAMES
; j
++) {
1219 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
1220 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1221 if (j
< FRAMES
- 1) {
1235 for (j
= 0; j
< FRAMES
; j
++)
1236 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1238 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
1240 for (j
= 0; j
< FRAMES
; j
++)
1241 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1248 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
1250 int style
= wPreferences
.iconification_style
; /* Catch the value */
1253 if (style
== WIS_NONE
)
1256 if (style
== WIS_RANDOM
)
1261 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
1263 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1266 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
1268 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1272 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
1274 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1278 #endif /* USE_ANIMATIONS */
1280 static void flushExpose(void)
1284 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
1285 WMHandleEvent(&tmpev
);
1289 static void unmapTransientsFor(WWindow
*wwin
)
1293 tmp
= wwin
->screen_ptr
->focused_window
;
1295 /* unmap the transients for this transient */
1296 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1297 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1298 unmapTransientsFor(tmp
);
1299 tmp
->flags
.miniaturized
= 1;
1300 if (!tmp
->flags
.shaded
)
1303 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1305 if (!tmp->flags.shaded)
1307 wClientSetState(tmp
, IconicState
, None
);
1309 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1315 static void mapTransientsFor(WWindow
*wwin
)
1319 tmp
= wwin
->screen_ptr
->focused_window
;
1321 /* recursively map the transients for this transient */
1322 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1323 && tmp
->icon
== NULL
) {
1324 mapTransientsFor(tmp
);
1325 tmp
->flags
.miniaturized
= 0;
1326 if (!tmp
->flags
.shaded
)
1329 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1330 tmp
->flags
.semi_focused
= 0;
1332 if (!tmp->flags.shaded)
1334 wClientSetState(tmp
, NormalState
, None
);
1336 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1342 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1349 /* hackish way to detect transient_for cycle */
1350 i
= wwin
->screen_ptr
->window_count
+ 1;
1352 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1353 wwin
= wWindowFor(wwin
->transient_for
);
1356 if (i
== 0 && wwin
) {
1357 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1358 wwin
->frame
->title
);
1365 #ifdef USE_ANIMATIONS
1366 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1368 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1369 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1372 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1375 *iw
= wwin
->icon
->core
->width
;
1376 *ih
= wwin
->icon
->core
->height
;
1378 if (wwin
->flags
.net_handle_icon
) {
1386 *iw
= wwin
->screen_ptr
->scr_width
;
1387 *ih
= wwin
->screen_ptr
->scr_height
;
1392 #endif /* USE_ANIMATIONS */
1394 void wIconifyWindow(WWindow
*wwin
)
1396 XWindowAttributes attribs
;
1399 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1400 return; /* the window doesn't exist anymore */
1402 if (wwin
->flags
.miniaturized
)
1403 return; /* already miniaturized */
1405 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1406 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1408 if (owner
&& owner
->flags
.miniaturized
)
1412 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1414 /* if the window is in another workspace, simplify process */
1416 /* icon creation may take a while */
1417 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1418 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1419 GrabModeAsync
, None
, None
, CurrentTime
);
1422 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1423 if (!wwin
->flags
.icon_moved
)
1424 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1426 wwin
->icon
= icon_create_for_wwindow(wwin
);
1427 wwin
->icon
->mapped
= 1;
1429 /* extract the window screenshot every time, as the option can be enable anytime */
1430 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1431 RImage
*mini_preview
;
1437 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1438 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1443 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1444 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1446 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1447 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1449 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1451 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1452 XDestroyImage(pimg
);
1455 set_icon_minipreview(wwin
->icon
, mini_preview
);
1456 RReleaseImage(mini_preview
);
1461 if (wwin
->frame
->title
) {
1462 title
= wwin
->frame
->title
;
1464 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1467 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1473 wwin
->flags
.miniaturized
= 1;
1474 wwin
->flags
.mapped
= 0;
1476 /* unmap transients */
1477 unmapTransientsFor(wwin
);
1480 #ifdef USE_ANIMATIONS
1483 XUngrabPointer(dpy
, CurrentTime
);
1485 /* let all Expose events arrive so that we can repaint
1486 * something before the animation starts (and the server is grabbed) */
1489 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1490 wClientSetState(wwin
, IconicState
, None
);
1492 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1495 #ifdef USE_ANIMATIONS
1496 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1497 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1498 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1502 wwin
->flags
.skip_next_animation
= 0;
1504 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1505 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1506 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1507 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1509 AddToStackList(wwin
->icon
->core
);
1510 wLowerFrame(wwin
->icon
->core
);
1514 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1517 * It doesn't seem to be working and causes button event hangup
1518 * when deiconifying a transient window.
1519 setupIconGrabs(wwin->icon);
1521 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1522 && wPreferences
.focus_mode
== WKF_CLICK
) {
1527 if (!WFLAGP(tmp
, no_focusable
)
1528 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1529 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1533 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1534 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1535 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1537 #ifdef USE_ANIMATIONS
1538 if (!wwin
->screen_ptr
->flags
.startup
) {
1539 /* Catch up with events not processed while animation was running */
1540 Window clientwin
= wwin
->client_win
;
1542 ProcessPendingEvents();
1544 /* the window can disappear while ProcessPendingEvents() runs */
1545 if (!wWindowFor(clientwin
))
1551 /* maybe we want to do this regardless of net_handle_icon
1552 * it seems to me we might break behaviour this way.
1554 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1555 && !wwin
->flags
.net_handle_icon
)
1556 wIconSelect(wwin
->icon
);
1558 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1560 if (wPreferences
.auto_arrange_icons
)
1561 wArrangeIcons(wwin
->screen_ptr
, True
);
1564 void wDeiconifyWindow(WWindow
*wwin
)
1566 /* Let's avoid changing workspace while deiconifying */
1567 w_global
.ignore_workspace_change
= True
;
1569 /* we're hiding for show_desktop */
1570 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1571 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1574 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1576 if (!wwin
->flags
.miniaturized
) {
1577 w_global
.ignore_workspace_change
= False
;
1581 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1582 WWindow
*owner
= recursiveTransientFor(wwin
);
1584 if (owner
&& owner
->flags
.miniaturized
) {
1585 wDeiconifyWindow(owner
);
1586 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1587 wRaiseFrame(wwin
->frame
->core
);
1588 w_global
.ignore_workspace_change
= False
;
1593 wwin
->flags
.miniaturized
= 0;
1595 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1596 wwin
->flags
.mapped
= 1;
1598 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1599 /* maybe we want to do this regardless of net_handle_icon
1600 * it seems to me we might break behaviour this way.
1602 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1603 && wwin
->icon
!= NULL
) {
1604 if (wwin
->icon
->selected
)
1605 wIconSelect(wwin
->icon
);
1607 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1611 /* if the window is in another workspace, do it silently */
1612 if (!netwm_hidden
) {
1613 #ifdef USE_ANIMATIONS
1615 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1616 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1617 wwin
->frame_x
, wwin
->frame_y
,
1618 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1620 wwin
->flags
.skip_next_animation
= 0;
1622 if (!wwin
->flags
.shaded
)
1623 XMapWindow(dpy
, wwin
->client_win
);
1625 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1626 wRaiseFrame(wwin
->frame
->core
);
1627 if (!wwin
->flags
.shaded
)
1628 wClientSetState(wwin
, NormalState
, None
);
1630 mapTransientsFor(wwin
);
1633 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1634 && !wwin
->flags
.net_handle_icon
) {
1635 RemoveFromStackList(wwin
->icon
->core
);
1636 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1637 wIconDestroy(wwin
->icon
);
1641 if (!netwm_hidden
) {
1644 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1646 #ifdef USE_ANIMATIONS
1647 if (!wwin
->screen_ptr
->flags
.startup
) {
1648 /* Catch up with events not processed while animation was running */
1649 Window clientwin
= wwin
->client_win
;
1651 ProcessPendingEvents();
1653 /* the window can disappear while ProcessPendingEvents() runs */
1654 if (!wWindowFor(clientwin
)) {
1655 w_global
.ignore_workspace_change
= False
;
1662 if (wPreferences
.auto_arrange_icons
)
1663 wArrangeIcons(wwin
->screen_ptr
, True
);
1665 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1667 /* In case we were shaded and iconified, also unshade */
1669 wUnshadeWindow(wwin
);
1671 w_global
.ignore_workspace_change
= False
;
1674 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1676 if (wwin
->flags
.miniaturized
) {
1678 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1679 wwin
->icon
->mapped
= 0;
1681 wwin
->flags
.hidden
= 1;
1683 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1687 if (wwin
->flags
.inspector_open
)
1688 wHideInspectorForWindow(wwin
);
1690 wwin
->flags
.hidden
= 1;
1693 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1696 #ifdef USE_ANIMATIONS
1697 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1698 !wwin
->flags
.skip_next_animation
&& animate
) {
1699 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1700 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1701 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1704 /* Tell the compiler it is normal that those parameters are not used in this case */
1709 wwin
->flags
.skip_next_animation
= 0;
1711 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1714 void wHideAll(WScreen
*scr
)
1719 unsigned int wcount
= 0;
1725 menu
= scr
->switch_menu
;
1727 windows
= wmalloc(sizeof(WWindow
*));
1730 for (i
= 0; i
< menu
->entry_no
; i
++) {
1731 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1733 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1736 wwin
= scr
->focused_window
;
1739 windows
[wcount
] = wwin
;
1741 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1747 for (i
= 0; i
< wcount
; i
++) {
1749 if (wwin
->frame
->workspace
== scr
->current_workspace
1750 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1751 && !wwin
->flags
.internal_window
1752 && !WFLAGP(wwin
, no_miniaturizable
)
1754 wwin
->flags
.skip_next_animation
= 1;
1755 wIconifyWindow(wwin
);
1762 void wHideOtherApplications(WWindow
*awin
)
1769 wwin
= awin
->screen_ptr
->focused_window
;
1773 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1774 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1775 && !wwin
->flags
.internal_window
1776 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1778 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1779 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1780 wwin
->flags
.skip_next_animation
= 1;
1781 wIconifyWindow(wwin
);
1783 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1784 tapp
= wApplicationOf(wwin
->main_window
);
1786 tapp
->flags
.skip_next_animation
= 1;
1787 wHideApplication(tapp
);
1789 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1790 wwin
->flags
.skip_next_animation
= 1;
1791 wIconifyWindow(wwin
);
1799 wSetFocusTo(awin->screen_ptr, awin);
1803 void wHideApplication(WApplication
*wapp
)
1811 wwarning("trying to hide a non grouped window");
1814 if (!wapp
->main_window_desc
) {
1815 wwarning("group leader not found for window group");
1818 scr
= wapp
->main_window_desc
->screen_ptr
;
1820 wlist
= scr
->focused_window
;
1824 if (wlist
->main_window
== wapp
->main_window
)
1825 wapp
->last_focused
= wlist
;
1827 wapp
->last_focused
= NULL
;
1829 animate
= !wapp
->flags
.skip_next_animation
;
1832 if (wlist
->main_window
== wapp
->main_window
) {
1833 if (wlist
->flags
.focused
)
1835 if (wapp
->app_icon
) {
1836 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1837 wapp
->app_icon
->y_pos
, wlist
, animate
);
1841 wlist
= wlist
->prev
;
1844 wapp
->flags
.skip_next_animation
= 0;
1847 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1848 wlist
= scr
->focused_window
;
1850 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1851 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1853 wlist
= wlist
->prev
;
1855 wSetFocusTo(scr
, wlist
);
1857 wSetFocusTo(scr
, NULL
);
1861 wapp
->flags
.hidden
= 1;
1863 if (wPreferences
.auto_arrange_icons
)
1864 wArrangeIcons(scr
, True
);
1868 wAppIconPaint(wapp
->app_icon
);
1872 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1874 if (bringToCurrentWS
)
1875 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1877 wwin
->flags
.hidden
= 0;
1879 #ifdef USE_ANIMATIONS
1880 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1881 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1882 icon
->core
->width
, icon
->core
->height
,
1883 wwin
->frame_x
, wwin
->frame_y
,
1884 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1887 /* Tell the compiler it is normal that those parameters are not used in this case */
1893 wwin
->flags
.skip_next_animation
= 0;
1894 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1895 XMapWindow(dpy
, wwin
->client_win
);
1896 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1897 wClientSetState(wwin
, NormalState
, None
);
1898 wwin
->flags
.mapped
= 1;
1899 wRaiseFrame(wwin
->frame
->core
);
1901 if (wwin
->flags
.inspector_open
)
1902 wUnhideInspectorForWindow(wwin
);
1904 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1907 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1910 WWindow
*wlist
, *next
;
1911 WWindow
*focused
= NULL
;
1917 scr
= wapp
->main_window_desc
->screen_ptr
;
1918 wlist
= scr
->focused_window
;
1922 /* goto beginning of list */
1924 wlist
= wlist
->prev
;
1926 animate
= !wapp
->flags
.skip_next_animation
;
1931 if (wlist
->main_window
== wapp
->main_window
) {
1932 if (wlist
->flags
.focused
)
1934 else if (!focused
|| !focused
->flags
.focused
)
1937 if (wlist
->flags
.miniaturized
) {
1938 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1939 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1940 if (!wlist
->icon
->mapped
) {
1943 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1944 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1945 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1948 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1949 wlist
->icon
->mapped
= 1;
1951 wRaiseFrame(wlist
->icon
->core
);
1953 if (bringToCurrentWS
)
1954 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1955 wlist
->flags
.hidden
= 0;
1956 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1957 wDeiconifyWindow(wlist
);
1958 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1959 } else if (wlist
->flags
.shaded
) {
1960 if (bringToCurrentWS
)
1961 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1962 wlist
->flags
.hidden
= 0;
1963 wRaiseFrame(wlist
->frame
->core
);
1964 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1965 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1967 wUnshadeWindow(wlist
);
1969 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1970 } else if (wlist
->flags
.hidden
) {
1971 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1972 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1975 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1976 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1978 wRaiseFrame(wlist
->frame
->core
);
1984 wapp
->flags
.skip_next_animation
= 0;
1985 wapp
->flags
.hidden
= 0;
1987 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1988 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1989 wSetFocusTo(scr
, wapp
->last_focused
);
1990 } else if (focused
) {
1991 wSetFocusTo(scr
, focused
);
1993 wapp
->last_focused
= NULL
;
1994 if (wPreferences
.auto_arrange_icons
)
1995 wArrangeIcons(scr
, True
);
1998 wAppIconPaint(wapp
->app_icon
);
2002 void wShowAllWindows(WScreen
*scr
)
2004 WWindow
*wwin
, *old_foc
;
2007 old_foc
= wwin
= scr
->focused_window
;
2009 if (!wwin
->flags
.internal_window
&&
2010 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
2011 if (wwin
->flags
.miniaturized
) {
2012 wwin
->flags
.skip_next_animation
= 1;
2013 wDeiconifyWindow(wwin
);
2014 } else if (wwin
->flags
.hidden
) {
2015 wapp
= wApplicationOf(wwin
->main_window
);
2017 wUnhideApplication(wapp
, False
, False
);
2019 wwin
->flags
.skip_next_animation
= 1;
2020 wDeiconifyWindow(wwin
);
2026 wSetFocusTo(scr
, old_foc
);
2027 /*wRaiseFrame(old_foc->frame->core); */
2030 void wRefreshDesktop(WScreen
*scr
)
2033 XSetWindowAttributes attr
;
2035 attr
.backing_store
= NotUseful
;
2036 attr
.save_under
= False
;
2037 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
2038 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
2039 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
2040 XMapRaised(dpy
, win
);
2041 XDestroyWindow(dpy
, win
);
2045 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
2051 const int heads
= wXineramaHeads(scr
);
2054 int pf
; /* primary axis */
2055 int sf
; /* secondary axis */
2059 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
2065 int isize
= wPreferences
.icon_size
;
2067 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
2069 for (head
= 0; head
< heads
; ++head
) {
2070 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
2074 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
2076 if (scr
->dock
->on_right_side
)
2082 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
2084 vars
[head
].pi
= vars
[head
].si
= 0;
2085 vars
[head
].sx1
= rect
.pos
.x
;
2086 vars
[head
].sy1
= rect
.pos
.y
;
2087 vars
[head
].sw
= rect
.size
.width
;
2088 vars
[head
].sh
= rect
.size
.height
;
2089 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
2090 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
2091 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
2092 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
2093 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
2094 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
2096 /* icon yard boundaries */
2097 if (wPreferences
.icon_yard
& IY_VERT
) {
2098 vars
[head
].pf
= vars
[head
].fullH
;
2099 vars
[head
].sf
= vars
[head
].fullW
;
2101 vars
[head
].pf
= vars
[head
].fullW
;
2102 vars
[head
].sf
= vars
[head
].fullH
;
2104 if (wPreferences
.icon_yard
& IY_RIGHT
) {
2105 vars
[head
].xo
= vars
[head
].sx2
- isize
;
2108 vars
[head
].xo
= vars
[head
].sx1
;
2111 if (wPreferences
.icon_yard
& IY_TOP
) {
2112 vars
[head
].yo
= vars
[head
].sy1
;
2115 vars
[head
].yo
= vars
[head
].sy2
- isize
;
2120 #define X ((wPreferences.icon_yard & IY_VERT) \
2121 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
2122 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
2124 #define Y ((wPreferences.icon_yard & IY_VERT) \
2125 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
2126 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
2128 /* arrange application icons */
2129 aicon
= scr
->app_icon_list
;
2130 /* reverse them to avoid unnecessarily sliding of icons */
2131 while (aicon
&& aicon
->next
)
2132 aicon
= aicon
->next
;
2135 if (!aicon
->docked
) {
2136 /* CHECK: can icon be NULL here ? */
2137 /* The intention here is to place the AppIcon on the head that
2138 * contains most of the applications _main_ window. */
2139 head
= wGetHeadForWindow(aicon
->icon
->owner
);
2141 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
2142 #ifdef USE_ANIMATIONS
2143 if (!wPreferences
.no_animations
)
2144 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
2145 #endif /* USE_ANIMATIONS */
2147 wAppIconMove(aicon
, X
, Y
);
2149 if (vars
[head
].pi
>= vars
[head
].pf
) {
2154 aicon
= aicon
->prev
;
2157 /* arrange miniwindows */
2158 wwin
= scr
->focused_window
;
2159 /* reverse them to avoid unnecessarily shuffling */
2160 while (wwin
&& wwin
->prev
)
2164 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
2165 (wwin
->frame
->workspace
== scr
->current_workspace
||
2166 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
2168 head
= wGetHeadForWindow(wwin
);
2170 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
2171 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
2172 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
2178 if (vars
[head
].pi
>= vars
[head
].pf
) {
2185 wwin
->flags
.icon_moved
= 0;
2186 /* we reversed the order, so we use next */
2193 void wSelectWindow(WWindow
*wwin
, Bool flag
)
2195 WScreen
*scr
= wwin
->screen_ptr
;
2198 wwin
->flags
.selected
= 1;
2199 if (wwin
->frame
->selected_border_pixel
)
2200 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
2202 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
2204 if (!HAS_BORDER(wwin
))
2205 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
2207 if (!scr
->selected_windows
)
2208 scr
->selected_windows
= WMCreateArray(4);
2209 WMAddToArray(scr
->selected_windows
, wwin
);
2211 wwin
->flags
.selected
= 0;
2212 if (wwin
->flags
.focused
) {
2213 if (wwin
->frame
->focused_border_pixel
)
2214 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
2216 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
2218 if (wwin
->frame
->border_pixel
)
2219 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
2221 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
2224 if (!HAS_BORDER(wwin
))
2225 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
2227 if (scr
->selected_windows
)
2228 WMRemoveFromArray(scr
->selected_windows
, wwin
);
2232 void wMakeWindowVisible(WWindow
*wwin
)
2234 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
2235 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
2237 if (wwin
->flags
.shaded
)
2238 wUnshadeWindow(wwin
);
2240 if (wwin
->flags
.hidden
) {
2243 app
= wApplicationOf(wwin
->main_window
);
2245 /* trick to get focus to this window */
2246 app
->last_focused
= wwin
;
2247 wUnhideApplication(app
, False
, False
);
2250 if (wwin
->flags
.miniaturized
) {
2251 wDeiconifyWindow(wwin
);
2253 if (!WFLAGP(wwin
, no_focusable
))
2254 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2255 wRaiseFrame(wwin
->frame
->core
);
2259 void movePointerToWindowCenter(WWindow
*wwin
)
2261 if (!wPreferences
.pointer_with_half_max_windows
)
2264 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
2265 XWarpPointer(dpy
, None
, wwin
->screen_ptr
->root_win
, 0, 0, 0, 0,
2266 wwin
->frame_x
+ wwin
->client
.width
/ 2,
2267 wwin
->frame_y
+ wwin
->client
.height
/ 2);
2272 * Do the animation while shading (called with what = SHADE)
2273 * or unshading (what = UNSHADE).
2275 #ifdef USE_ANIMATIONS
2276 static void shade_animate(WWindow
*wwin
, Bool what
)
2279 time_t time0
= time(NULL
);
2281 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
2286 if (!wwin
->screen_ptr
->flags
.startup
) {
2287 /* do the shading animation */
2288 h
= wwin
->frame
->core
->height
;
2289 s
= h
/ SHADE_STEPS
;
2292 w
= wwin
->frame
->core
->width
;
2293 y
= wwin
->frame
->top_width
;
2294 while (h
> wwin
->frame
->top_width
+ 1) {
2295 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2296 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2299 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2302 if (SHADE_DELAY
> 0)
2303 wusleep(SHADE_DELAY
* 1000L);
2309 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2314 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2315 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2316 s
= abs(y
) / SHADE_STEPS
;
2319 w
= wwin
->frame
->core
->width
;
2320 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2322 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2323 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2324 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2326 if (SHADE_DELAY
> 0)
2327 wusleep(SHADE_DELAY
* 2000L / 3);
2333 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2337 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);