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 #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
);
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 /* set default values if no option set then */
435 if (!(directions
& (MAX_HORIZONTAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_MAXIMUS
))) {
436 new_width
= (wwin
->old_geometry
.width
) ? wwin
->old_geometry
.width
: wwin
->frame
->core
->width
;
437 new_x
= (wwin
->old_geometry
.x
) ? wwin
->old_geometry
.x
: wwin
->frame_x
;
439 if (!(directions
& (MAX_VERTICAL
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
))) {
440 new_height
= (wwin
->old_geometry
.height
) ? wwin
->old_geometry
.height
: wwin
->frame
->core
->height
;
441 new_y
= (wwin
->old_geometry
.y
) ? wwin
->old_geometry
.y
: wwin
->frame_y
;
444 /* left|right position */
445 if (directions
& MAX_LEFTHALF
) {
446 new_width
= half_scr_width
- adj_size
;
447 new_x
= usableArea
.x1
;
448 } else if (directions
& MAX_RIGHTHALF
) {
449 new_width
= half_scr_width
- adj_size
;
450 new_x
= usableArea
.x1
+ half_scr_width
;
452 /* top|bottom position */
453 if (directions
& MAX_TOPHALF
) {
454 new_height
= half_scr_height
- adj_size
;
455 new_y
= usableArea
.y1
;
456 } else if (directions
& MAX_BOTTOMHALF
) {
457 new_height
= half_scr_height
- adj_size
;
458 new_y
= usableArea
.y1
+ half_scr_height
;
461 /* vertical|horizontal position */
462 if (directions
& MAX_HORIZONTAL
) {
463 new_width
= usableArea
.x2
- usableArea
.x1
- adj_size
;
464 new_x
= usableArea
.x1
;
466 if (directions
& MAX_VERTICAL
) {
467 new_height
= usableArea
.y2
- usableArea
.y1
- adj_size
;
468 new_y
= usableArea
.y1
;
469 if (WFLAGP(wwin
, full_maximize
) && (new_y
== 0))
470 new_y
-= wwin
->frame
->top_width
;
474 if (!WFLAGP(wwin
, full_maximize
) && !(directions
== MAX_MAXIMUS
|| directions
== MAX_HORIZONTAL
))
475 new_height
-= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
477 /* set maximization state */
478 wwin
->flags
.maximized
= directions
;
479 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) && !wwin
->flags
.maximized
)
480 wwin
->flags
.maximized
= MAX_MAXIMUS
;
482 wWindowConstrainSize(wwin
, &new_width
, &new_height
);
484 wWindowCropSize(wwin
, usableArea
.x2
- usableArea
.x1
,
485 usableArea
.y2
- usableArea
.y1
, &new_width
, &new_height
);
487 wWindowConfigure(wwin
, new_x
, new_y
, new_width
, new_height
);
488 wWindowSynthConfigureNotify(wwin
);
490 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
493 /* generic (un)maximizer */
494 void handleMaximize(WWindow
*wwin
, int directions
)
496 int current
= wwin
->flags
.maximized
;
497 int requested
= directions
& (MAX_HORIZONTAL
| MAX_VERTICAL
| MAX_LEFTHALF
| MAX_RIGHTHALF
| MAX_TOPHALF
| MAX_BOTTOMHALF
| MAX_MAXIMUS
);
498 int effective
= requested
^ current
;
499 int flags
= directions
& ~requested
;
500 int head
= wGetHeadForWindow(wwin
);
504 /* allow wMaximizeWindow to restore the Maximusized size */
505 if ((wwin
->flags
.old_maximized
& MAX_MAXIMUS
) &&
506 !(requested
& MAX_MAXIMUS
))
507 wMaximizeWindow(wwin
, MAX_MAXIMUS
| flags
, head
);
509 else if (wPreferences
.alt_half_maximize
&&
510 current
& MAX_HORIZONTAL
&& current
& MAX_VERTICAL
&&
511 requested
& MAX_HORIZONTAL
&& requested
& MAX_VERTICAL
)
512 wUnmaximizeWindow(wwin
);
514 /* Apply for window state, which is only horizontally or vertically
515 * maximized. Quarters cannot be handled here, since there is not clear
516 * on which direction user intend to move such window. */
517 else if (wPreferences
.move_half_max_between_heads
&&
518 current
& (MAX_VERTICAL
| MAX_HORIZONTAL
)) {
519 if (requested
& MAX_LEFTHALF
&& current
& MAX_LEFTHALF
) {
520 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
521 head
, DIRECTION_LEFT
);
522 if (dest_head
!= -1) {
523 effective
|= MAX_RIGHTHALF
;
524 effective
|= MAX_VERTICAL
;
525 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
527 } else if (requested
& MAX_RIGHTHALF
&&
528 current
& MAX_RIGHTHALF
) {
529 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
530 head
, DIRECTION_RIGHT
);
531 if (dest_head
!= -1) {
532 effective
|= MAX_LEFTHALF
;
533 effective
|= MAX_VERTICAL
;
534 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
536 } else if (requested
& MAX_TOPHALF
&& current
& MAX_TOPHALF
) {
537 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
539 if (dest_head
!= -1) {
540 effective
|= MAX_BOTTOMHALF
;
541 effective
|= MAX_HORIZONTAL
;
542 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
544 } else if (requested
& MAX_BOTTOMHALF
&&
545 current
& MAX_BOTTOMHALF
) {
546 dest_head
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
547 head
, DIRECTION_DOWN
);
548 if (dest_head
!= -1) {
549 effective
|= MAX_TOPHALF
;
550 effective
|= MAX_HORIZONTAL
;
551 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
557 /* tell wMaximizeWindow that we were using keyboard, not mouse,
558 * so that it will use calculated head as destination for
559 * move_half_max_between_heads feature, not from mouse pointer */
560 wMaximizeWindow(wwin
, (effective
| flags
| MAX_KEYBOARD
),
562 else if (!wPreferences
.alt_half_maximize
)
563 wUnmaximizeWindow(wwin
);
568 /* these alone mean vertical|horizontal toggle */
569 if ((effective
== MAX_LEFTHALF
) ||
570 (effective
== MAX_RIGHTHALF
) ||
571 (effective
== MAX_TOPHALF
) ||
572 (effective
== MAX_BOTTOMHALF
))
573 wUnmaximizeWindow(wwin
);
575 /* Following conditions might look complicated, but they are really simple:
576 * allow fullscreen transition only for half maximized state (and not
577 * corners) and only when requested state is also half maximized, but on
578 * opposite side of the screen. As for corners, it is similar, but
579 * expected is that only quarter maximized windows on corner can change
580 * it's state to half maximized window, depending on direction. Note, that
581 * MAX_KEYBOARD is passed to the wMaximizeWindow function, to preserve the
582 * head, even if mouse was used for triggering the action. */
584 /* Quarters alternative transition. */
585 else if (wPreferences
.alt_half_maximize
&&
586 ((requested
& MAX_LEFTHALF
&& requested
& MAX_TOPHALF
&&
587 current
& MAX_RIGHTHALF
&& current
& MAX_TOPHALF
) ||
588 (requested
& MAX_RIGHTHALF
&& requested
& MAX_TOPHALF
&&
589 current
& MAX_LEFTHALF
&& current
& MAX_TOPHALF
)))
590 wMaximizeWindow(wwin
, (MAX_TOPHALF
| MAX_HORIZONTAL
| MAX_KEYBOARD
),
592 else if (wPreferences
.alt_half_maximize
&&
593 ((requested
& MAX_LEFTHALF
&& requested
& MAX_BOTTOMHALF
&&
594 current
& MAX_RIGHTHALF
&& current
& MAX_BOTTOMHALF
) ||
595 (requested
& MAX_RIGHTHALF
&& requested
& MAX_BOTTOMHALF
&&
596 current
& MAX_LEFTHALF
&& current
& MAX_BOTTOMHALF
)))
597 wMaximizeWindow(wwin
, (MAX_BOTTOMHALF
| MAX_HORIZONTAL
| MAX_KEYBOARD
),
599 else if (wPreferences
.alt_half_maximize
&&
600 ((requested
& MAX_LEFTHALF
&& requested
& MAX_BOTTOMHALF
&&
601 current
& MAX_LEFTHALF
&& current
& MAX_TOPHALF
) ||
602 (requested
& MAX_LEFTHALF
&& requested
& MAX_TOPHALF
&&
603 current
& MAX_LEFTHALF
&& current
& MAX_BOTTOMHALF
)))
604 wMaximizeWindow(wwin
, (MAX_LEFTHALF
| MAX_VERTICAL
| MAX_KEYBOARD
),
606 else if (wPreferences
.alt_half_maximize
&&
607 ((requested
& MAX_RIGHTHALF
&& requested
& MAX_BOTTOMHALF
&&
608 current
& MAX_RIGHTHALF
&& current
& MAX_TOPHALF
) ||
609 (requested
& MAX_RIGHTHALF
&& requested
& MAX_TOPHALF
&&
610 current
& MAX_RIGHTHALF
&& current
& MAX_BOTTOMHALF
)))
611 wMaximizeWindow(wwin
, (MAX_RIGHTHALF
| MAX_VERTICAL
| MAX_KEYBOARD
),
614 /* Half-maximized alternative transition */
615 else if (wPreferences
.alt_half_maximize
&& (
616 (requested
& MAX_LEFTHALF
&& requested
& MAX_VERTICAL
&&
617 current
& MAX_RIGHTHALF
&& current
& MAX_VERTICAL
) ||
618 (requested
& MAX_RIGHTHALF
&& requested
& MAX_VERTICAL
&&
619 current
& MAX_LEFTHALF
&& current
& MAX_VERTICAL
) ||
620 (requested
& MAX_TOPHALF
&& requested
& MAX_HORIZONTAL
&&
621 current
& MAX_BOTTOMHALF
&& current
& MAX_HORIZONTAL
) ||
622 (requested
& MAX_BOTTOMHALF
&& requested
& MAX_HORIZONTAL
&&
623 current
& MAX_TOPHALF
&& current
& MAX_HORIZONTAL
)))
624 wMaximizeWindow(wwin
, (MAX_HORIZONTAL
|MAX_VERTICAL
|MAX_KEYBOARD
),
628 if ((requested
== (MAX_HORIZONTAL
| MAX_VERTICAL
)) ||
629 (requested
== MAX_MAXIMUS
))
630 effective
= requested
;
632 if (requested
& MAX_LEFTHALF
) {
633 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
634 effective
|= MAX_VERTICAL
;
636 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
637 effective
|= MAX_LEFTHALF
;
638 effective
&= ~(MAX_HORIZONTAL
| MAX_RIGHTHALF
);
639 } else if (requested
& MAX_RIGHTHALF
) {
640 if (!(requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
)))
641 effective
|= MAX_VERTICAL
;
643 effective
|= requested
& (MAX_TOPHALF
| MAX_BOTTOMHALF
);
644 effective
|= MAX_RIGHTHALF
;
645 effective
&= ~(MAX_HORIZONTAL
| MAX_LEFTHALF
);
647 if (requested
& MAX_TOPHALF
) {
648 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
649 effective
|= MAX_HORIZONTAL
;
651 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
652 effective
|= MAX_TOPHALF
;
653 effective
&= ~(MAX_VERTICAL
| MAX_BOTTOMHALF
);
654 } else if (requested
& MAX_BOTTOMHALF
) {
655 if (!(requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
)))
656 effective
|= MAX_HORIZONTAL
;
658 effective
|= requested
& (MAX_LEFTHALF
| MAX_RIGHTHALF
);
659 effective
|= MAX_BOTTOMHALF
;
660 effective
&= ~(MAX_VERTICAL
| MAX_TOPHALF
);
662 if (requested
& MAX_HORIZONTAL
)
663 effective
&= ~(MAX_LEFTHALF
| MAX_RIGHTHALF
);
664 if (requested
& MAX_VERTICAL
)
665 effective
&= ~(MAX_TOPHALF
| MAX_BOTTOMHALF
);
666 effective
&= ~MAX_MAXIMUS
;
668 wMaximizeWindow(wwin
, effective
| flags
, head
);
672 /* Moving window between heads
674 * Window is moved between all avaiable heads for current screen in
675 * requested direction.
677 * If heads have different sizes, window position will be adjusted to be inside
678 * screen. Window will be unmaximized on move, so that it can be immediately be
679 * maximixed by another shortcut.
682 * direction = 0 means move clock-wise from 12h position to 6h
683 * (first try moving right, then bottom, then left, then up)
684 * direction = 1 means move clock-wise from 6h position to 12h
685 * (first try moving left, then up, then right, then bottom)
688 * As side effect this mean if you have 9 monitors - you will not be able to
689 * move window into central cell without mouse.
691 * For common cases with 1 or 2 extra monitors this should work just fine.
695 void moveBetweenHeads(WWindow
*wwin
, int direction
)
697 int head
= wGetHeadForWindow(wwin
);
700 unsigned int new_width
, new_height
;
701 int offsetX
, newX
= 0;
702 int offsetY
, newY
= 0;
703 WArea totalArea
, oldHeadArea
, destHeadArea
;
704 WScreen
*scr
= wwin
->screen_ptr
;
706 int try_movements
[2][4] = {
707 {DIRECTION_RIGHT
, DIRECTION_DOWN
, DIRECTION_LEFT
, DIRECTION_UP
},
708 {DIRECTION_LEFT
, DIRECTION_UP
, DIRECTION_RIGHT
, DIRECTION_DOWN
}
711 /* loop through directions array and try movements until one works */
712 for (int try_movement_idx
= 0;
713 destHead
== -1 && try_movement_idx
< 4; try_movement_idx
++) {
714 destHead
= wGetHeadRelativeToCurrentHead(wwin
->screen_ptr
,
715 head
, try_movements
[direction
][try_movement_idx
]);
718 if (destHead
!= -1) {
721 totalArea
.x2
= scr
->scr_width
;
722 totalArea
.y2
= scr
->scr_height
;
724 oldHeadArea
= wGetUsableAreaForHead(scr
, head
, &totalArea
, True
);
725 destHeadArea
= wGetUsableAreaForHead(scr
, destHead
, &totalArea
, True
);
727 offsetX
= wwin
->frame_x
- oldHeadArea
.x1
;
728 offsetY
= wwin
->frame_y
- oldHeadArea
.y1
;
730 newX
= destHeadArea
.x1
+ offsetX
;
731 newY
= destHeadArea
.y1
+ offsetY
;
733 new_width
= wwin
->client
.width
;
734 new_height
= wwin
->client
.height
;
736 /* try to brind window inside head coordinates */
737 if (newX
> destHeadArea
.x2
)
738 newX
= destHeadArea
.x2
- wwin
->client
.width
;
740 if (newX
< destHeadArea
.x1
)
741 newX
= destHeadArea
.x1
;
743 if (newY
> destHeadArea
.y2
)
744 newY
= destHeadArea
.y2
- wwin
->client
.height
;
746 if (newY
< destHeadArea
.y1
)
747 newY
= destHeadArea
.y1
;
749 /* unset maximization state */
750 wwin
->flags
.maximized
= 0;
751 wWindowConfigure(wwin
, newX
, newY
, new_width
, new_height
);
757 /* the window boundary coordinates */
767 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
769 obs
->left
= wwin
->frame_x
;
770 obs
->top
= wwin
->frame_y
;
771 obs
->width
= wwin
->frame
->core
->width
;
772 obs
->height
= wwin
->frame
->core
->height
;
773 obs
->bottom
= obs
->top
+ obs
->height
;
774 obs
->right
= obs
->left
+ obs
->width
;
778 * Maximus: tiled maximization (maximize without overlapping other windows)
780 * The original window 'orig' will be maximized to new coordinates 'new'.
781 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
783 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
784 unsigned int *new_width
, unsigned int *new_height
)
787 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
788 short int adjust_height
;
789 int x_intsect
, y_intsect
;
790 /* the obstructing, original and new windows */
791 win_coords obs
, orig
, new;
793 /* set the original coordinate positions of the window to be Maximumized */
794 if (wwin
->flags
.maximized
) {
795 /* window is already maximized; consider original geometry */
796 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
797 orig
.bottom
= orig
.top
+ orig
.height
;
798 orig
.right
= orig
.left
+ orig
.width
;
800 set_window_coords(wwin
, &orig
);
802 /* Try to fully maximize first, then readjust later */
803 new.left
= usableArea
.x1
;
804 new.right
= usableArea
.x2
;
805 new.top
= usableArea
.y1
;
806 new.bottom
= usableArea
.y2
;
808 if (HAS_TITLEBAR(wwin
))
809 tbar_height_0
= TITLEBAR_HEIGHT
;
810 if (HAS_RESIZEBAR(wwin
))
811 rbar_height_0
= RESIZEBAR_HEIGHT
;
812 if (HAS_BORDER(wwin
))
813 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
815 /* the length to be subtracted if the window has titlebar, etc */
816 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
819 /* The focused window is always the last in the list */
821 /* ignore windows in other workspaces etc */
822 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
823 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
829 /* Set the coordinates of obstructing window */
830 set_window_coords(tmp
, &obs
);
832 /* Try to maximize in the y direction first */
833 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
834 if (x_intsect
!= 0) {
835 /* TODO: Consider the case when coords are equal */
836 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
837 /* w_0 is below the bottom of w_j */
838 new.top
= obs
.bottom
+ 1;
840 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
841 /* The bottom of w_0 is above the top of w_j */
842 new.bottom
= obs
.top
- 1;
849 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
850 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
856 set_window_coords(tmp
, &obs
);
859 * Use the new.top and new.height instead of original values
860 * as they may have different intersections with the obstructing windows
862 new.height
= new.bottom
- new.top
- adjust_height
;
863 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
864 if (y_intsect
!= 0) {
865 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
866 /* w_0 is completely to the right of w_j */
867 new.left
= obs
.right
+ 1;
869 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
870 /* w_0 is completely to the left of w_j */
871 new.right
= obs
.left
- 1;
878 /* xcalc needs -7 here, but other apps don't */
879 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
880 *new_width
= new.right
- new.left
;
883 void wUnmaximizeWindow(WWindow
*wwin
)
887 if (!wwin
->flags
.maximized
)
890 if (wwin
->flags
.shaded
) {
891 wwin
->flags
.skip_next_animation
= 1;
892 wUnshadeWindow(wwin
);
895 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
896 wwin
->client_flags
.no_movable
= 0;
898 /* Use old coordinates if they are set, current values otherwise */
899 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
901 /* unMaximusize relative to original position */
902 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
903 x
+= wwin
->frame_x
- wwin
->maximus_x
;
904 y
+= wwin
->frame_y
- wwin
->maximus_y
;
907 wwin
->flags
.maximized
= 0;
908 wwin
->flags
.old_maximized
= 0;
909 wWindowConfigure(wwin
, x
, y
, w
, h
);
910 wWindowSynthConfigureNotify(wwin
);
912 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
915 void wFullscreenWindow(WWindow
*wwin
)
920 if (wwin
->flags
.fullscreen
)
923 wwin
->flags
.fullscreen
= True
;
925 wWindowConfigureBorders(wwin
);
927 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
929 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
930 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
931 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
932 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
934 head
= wGetHeadForWindow(wwin
);
935 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
936 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
938 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
939 wSetFocusTo(wwin
->screen_ptr
, wwin
);
941 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
944 void wUnfullscreenWindow(WWindow
*wwin
)
946 if (!wwin
->flags
.fullscreen
)
949 wwin
->flags
.fullscreen
= False
;
951 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
952 if (WFLAGP(wwin
, sunken
)) {
953 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
954 } else if (WFLAGP(wwin
, floating
)) {
955 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
957 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
961 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
962 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
964 wWindowConfigureBorders(wwin
);
966 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
967 wFrameWindowPaint(wwin->frame);
970 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
972 if (wwin
->screen_ptr
->bfs_focused_window
) {
973 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
974 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
978 #ifdef USE_ANIMATIONS
979 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
981 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
982 float cx
, cy
, cw
, ch
;
983 float xstep
, ystep
, wstep
, hstep
;
986 float angle
, final_angle
, delta
;
988 xstep
= (float)(fx
- x
) / steps
;
989 ystep
= (float)(fy
- y
) / steps
;
990 wstep
= (float)(fw
- w
) / steps
;
991 hstep
= (float)(fh
- h
) / steps
;
998 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
999 delta
= (float)(final_angle
/ FRAMES
);
1000 for (angle
= 0;; angle
+= delta
) {
1001 if (angle
> final_angle
)
1002 angle
= final_angle
;
1004 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
1005 dch
= (ch
/ 2) * cosf(angle
);
1006 midy
= cy
+ (ch
/ 2);
1008 points
[0].x
= cx
+ dx
;
1009 points
[0].y
= midy
- dch
;
1010 points
[1].x
= cx
+ cw
- dx
;
1011 points
[1].y
= points
[0].y
;
1012 points
[2].x
= cx
+ cw
+ dx
;
1013 points
[2].y
= midy
+ dch
;
1014 points
[3].x
= cx
- dx
;
1015 points
[3].y
= points
[2].y
;
1016 points
[4].x
= points
[0].x
;
1017 points
[4].y
= points
[0].y
;
1020 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1022 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
1024 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1030 if (angle
>= final_angle
)
1040 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
1042 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
1043 float cx
, cy
, cw
, ch
;
1044 float xstep
, ystep
, wstep
, hstep
;
1046 float angle
, final_angle
, a
, d
, delta
;
1053 xstep
= (float)(fx
- x
) / steps
;
1054 ystep
= (float)(fy
- y
) / steps
;
1055 wstep
= (float)(fw
- w
) / steps
;
1056 hstep
= (float)(fh
- h
) / steps
;
1063 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
1064 delta
= (float)(final_angle
/ FRAMES
);
1065 for (angle
= 0;; angle
+= delta
) {
1066 if (angle
> final_angle
)
1067 angle
= final_angle
;
1070 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
1072 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
1073 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
1074 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
1075 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
1076 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
1077 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
1078 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
1079 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
1080 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
1081 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
1083 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1085 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
1087 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1093 if (angle
>= final_angle
)
1102 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
1104 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
1105 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
1106 float xstep
, ystep
, wstep
, hstep
;
1109 xstep
= (float)(fx
- x
) / steps
;
1110 ystep
= (float)(fy
- y
) / steps
;
1111 wstep
= (float)(fw
- w
) / steps
;
1112 hstep
= (float)(fh
- h
) / steps
;
1114 for (j
= 0; j
< FRAMES
; j
++) {
1121 for (i
= 0; i
< steps
; i
++) {
1122 for (j
= 0; j
< FRAMES
; j
++) {
1123 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
1124 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1127 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
1129 for (j
= 0; j
< FRAMES
; j
++) {
1130 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
1131 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1132 if (j
< FRAMES
- 1) {
1146 for (j
= 0; j
< FRAMES
; j
++)
1147 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1149 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
1151 for (j
= 0; j
< FRAMES
; j
++)
1152 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1159 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
1161 int style
= wPreferences
.iconification_style
; /* Catch the value */
1164 if (style
== WIS_NONE
)
1167 if (style
== WIS_RANDOM
)
1172 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
1174 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1177 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
1179 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1183 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
1185 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1189 #endif /* USE_ANIMATIONS */
1191 static void flushExpose(void)
1195 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
1196 WMHandleEvent(&tmpev
);
1200 static void unmapTransientsFor(WWindow
*wwin
)
1204 tmp
= wwin
->screen_ptr
->focused_window
;
1206 /* unmap the transients for this transient */
1207 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1208 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1209 unmapTransientsFor(tmp
);
1210 tmp
->flags
.miniaturized
= 1;
1211 if (!tmp
->flags
.shaded
)
1214 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1216 if (!tmp->flags.shaded)
1218 wClientSetState(tmp
, IconicState
, None
);
1220 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1226 static void mapTransientsFor(WWindow
*wwin
)
1230 tmp
= wwin
->screen_ptr
->focused_window
;
1232 /* recursively map the transients for this transient */
1233 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1234 && tmp
->icon
== NULL
) {
1235 mapTransientsFor(tmp
);
1236 tmp
->flags
.miniaturized
= 0;
1237 if (!tmp
->flags
.shaded
)
1240 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1241 tmp
->flags
.semi_focused
= 0;
1243 if (!tmp->flags.shaded)
1245 wClientSetState(tmp
, NormalState
, None
);
1247 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1253 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1260 /* hackish way to detect transient_for cycle */
1261 i
= wwin
->screen_ptr
->window_count
+ 1;
1263 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1264 wwin
= wWindowFor(wwin
->transient_for
);
1267 if (i
== 0 && wwin
) {
1268 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1269 wwin
->frame
->title
);
1276 #ifdef USE_ANIMATIONS
1277 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1279 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1280 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1283 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1286 *iw
= wwin
->icon
->core
->width
;
1287 *ih
= wwin
->icon
->core
->height
;
1289 if (wwin
->flags
.net_handle_icon
) {
1297 *iw
= wwin
->screen_ptr
->scr_width
;
1298 *ih
= wwin
->screen_ptr
->scr_height
;
1303 #endif /* USE_ANIMATIONS */
1305 void wIconifyWindow(WWindow
*wwin
)
1307 XWindowAttributes attribs
;
1310 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1311 return; /* the window doesn't exist anymore */
1313 if (wwin
->flags
.miniaturized
)
1314 return; /* already miniaturized */
1316 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1317 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1319 if (owner
&& owner
->flags
.miniaturized
)
1323 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1325 /* if the window is in another workspace, simplify process */
1327 /* icon creation may take a while */
1328 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1329 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1330 GrabModeAsync
, None
, None
, CurrentTime
);
1333 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1334 if (!wwin
->flags
.icon_moved
)
1335 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1337 wwin
->icon
= icon_create_for_wwindow(wwin
);
1338 wwin
->icon
->mapped
= 1;
1340 /* extract the window screenshot every time, as the option can be enable anytime */
1341 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1342 RImage
*mini_preview
;
1348 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1349 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1354 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1355 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1357 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1358 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1360 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1362 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1363 XDestroyImage(pimg
);
1366 set_icon_minipreview(wwin
->icon
, mini_preview
);
1367 RReleaseImage(mini_preview
);
1372 if (wwin
->frame
->title
) {
1373 title
= wwin
->frame
->title
;
1375 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1378 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1384 wwin
->flags
.miniaturized
= 1;
1385 wwin
->flags
.mapped
= 0;
1387 /* unmap transients */
1388 unmapTransientsFor(wwin
);
1391 #ifdef USE_ANIMATIONS
1394 XUngrabPointer(dpy
, CurrentTime
);
1396 /* let all Expose events arrive so that we can repaint
1397 * something before the animation starts (and the server is grabbed) */
1400 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1401 wClientSetState(wwin
, IconicState
, None
);
1403 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1406 #ifdef USE_ANIMATIONS
1407 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1408 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1409 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1413 wwin
->flags
.skip_next_animation
= 0;
1415 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1416 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1417 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1418 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1420 AddToStackList(wwin
->icon
->core
);
1421 wLowerFrame(wwin
->icon
->core
);
1425 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1428 * It doesn't seem to be working and causes button event hangup
1429 * when deiconifying a transient window.
1430 setupIconGrabs(wwin->icon);
1432 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1433 && wPreferences
.focus_mode
== WKF_CLICK
) {
1438 if (!WFLAGP(tmp
, no_focusable
)
1439 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1440 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1444 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1445 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1446 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1448 #ifdef USE_ANIMATIONS
1449 if (!wwin
->screen_ptr
->flags
.startup
) {
1450 /* Catch up with events not processed while animation was running */
1451 Window clientwin
= wwin
->client_win
;
1453 ProcessPendingEvents();
1455 /* the window can disappear while ProcessPendingEvents() runs */
1456 if (!wWindowFor(clientwin
))
1462 /* maybe we want to do this regardless of net_handle_icon
1463 * it seems to me we might break behaviour this way.
1465 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1466 && !wwin
->flags
.net_handle_icon
)
1467 wIconSelect(wwin
->icon
);
1469 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1471 if (wPreferences
.auto_arrange_icons
)
1472 wArrangeIcons(wwin
->screen_ptr
, True
);
1475 void wDeiconifyWindow(WWindow
*wwin
)
1477 /* Let's avoid changing workspace while deiconifying */
1478 w_global
.ignore_workspace_change
= True
;
1480 /* we're hiding for show_desktop */
1481 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1482 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1485 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1487 if (!wwin
->flags
.miniaturized
) {
1488 w_global
.ignore_workspace_change
= False
;
1492 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1493 WWindow
*owner
= recursiveTransientFor(wwin
);
1495 if (owner
&& owner
->flags
.miniaturized
) {
1496 wDeiconifyWindow(owner
);
1497 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1498 wRaiseFrame(wwin
->frame
->core
);
1499 w_global
.ignore_workspace_change
= False
;
1504 wwin
->flags
.miniaturized
= 0;
1506 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1507 wwin
->flags
.mapped
= 1;
1509 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1510 /* maybe we want to do this regardless of net_handle_icon
1511 * it seems to me we might break behaviour this way.
1513 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1514 && wwin
->icon
!= NULL
) {
1515 if (wwin
->icon
->selected
)
1516 wIconSelect(wwin
->icon
);
1518 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1522 /* if the window is in another workspace, do it silently */
1523 if (!netwm_hidden
) {
1524 #ifdef USE_ANIMATIONS
1526 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1527 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1528 wwin
->frame_x
, wwin
->frame_y
,
1529 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1531 wwin
->flags
.skip_next_animation
= 0;
1533 if (!wwin
->flags
.shaded
)
1534 XMapWindow(dpy
, wwin
->client_win
);
1536 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1537 wRaiseFrame(wwin
->frame
->core
);
1538 if (!wwin
->flags
.shaded
)
1539 wClientSetState(wwin
, NormalState
, None
);
1541 mapTransientsFor(wwin
);
1544 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1545 && !wwin
->flags
.net_handle_icon
) {
1546 RemoveFromStackList(wwin
->icon
->core
);
1547 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1548 wIconDestroy(wwin
->icon
);
1552 if (!netwm_hidden
) {
1555 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1557 #ifdef USE_ANIMATIONS
1558 if (!wwin
->screen_ptr
->flags
.startup
) {
1559 /* Catch up with events not processed while animation was running */
1560 Window clientwin
= wwin
->client_win
;
1562 ProcessPendingEvents();
1564 /* the window can disappear while ProcessPendingEvents() runs */
1565 if (!wWindowFor(clientwin
)) {
1566 w_global
.ignore_workspace_change
= False
;
1573 if (wPreferences
.auto_arrange_icons
)
1574 wArrangeIcons(wwin
->screen_ptr
, True
);
1576 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1578 /* In case we were shaded and iconified, also unshade */
1580 wUnshadeWindow(wwin
);
1582 w_global
.ignore_workspace_change
= False
;
1585 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1587 if (wwin
->flags
.miniaturized
) {
1589 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1590 wwin
->icon
->mapped
= 0;
1592 wwin
->flags
.hidden
= 1;
1594 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1598 if (wwin
->flags
.inspector_open
)
1599 wHideInspectorForWindow(wwin
);
1601 wwin
->flags
.hidden
= 1;
1604 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1607 #ifdef USE_ANIMATIONS
1608 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1609 !wwin
->flags
.skip_next_animation
&& animate
) {
1610 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1611 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1612 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1615 /* Tell the compiler it is normal that those parameters are not used in this case */
1620 wwin
->flags
.skip_next_animation
= 0;
1622 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1625 void wHideAll(WScreen
*scr
)
1630 unsigned int wcount
= 0;
1636 menu
= scr
->switch_menu
;
1638 windows
= wmalloc(sizeof(WWindow
*));
1641 for (i
= 0; i
< menu
->entry_no
; i
++) {
1642 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1644 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1647 wwin
= scr
->focused_window
;
1650 windows
[wcount
] = wwin
;
1652 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1658 for (i
= 0; i
< wcount
; i
++) {
1660 if (wwin
->frame
->workspace
== scr
->current_workspace
1661 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1662 && !wwin
->flags
.internal_window
1663 && !WFLAGP(wwin
, no_miniaturizable
)
1665 wwin
->flags
.skip_next_animation
= 1;
1666 wIconifyWindow(wwin
);
1673 void wHideOtherApplications(WWindow
*awin
)
1680 wwin
= awin
->screen_ptr
->focused_window
;
1684 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1685 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1686 && !wwin
->flags
.internal_window
1687 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1689 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1690 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1691 wwin
->flags
.skip_next_animation
= 1;
1692 wIconifyWindow(wwin
);
1694 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1695 tapp
= wApplicationOf(wwin
->main_window
);
1697 tapp
->flags
.skip_next_animation
= 1;
1698 wHideApplication(tapp
);
1700 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1701 wwin
->flags
.skip_next_animation
= 1;
1702 wIconifyWindow(wwin
);
1710 wSetFocusTo(awin->screen_ptr, awin);
1714 void wHideApplication(WApplication
*wapp
)
1722 wwarning("trying to hide a non grouped window");
1725 if (!wapp
->main_window_desc
) {
1726 wwarning("group leader not found for window group");
1729 scr
= wapp
->main_window_desc
->screen_ptr
;
1731 wlist
= scr
->focused_window
;
1735 if (wlist
->main_window
== wapp
->main_window
)
1736 wapp
->last_focused
= wlist
;
1738 wapp
->last_focused
= NULL
;
1740 animate
= !wapp
->flags
.skip_next_animation
;
1743 if (wlist
->main_window
== wapp
->main_window
) {
1744 if (wlist
->flags
.focused
)
1746 if (wapp
->app_icon
) {
1747 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1748 wapp
->app_icon
->y_pos
, wlist
, animate
);
1752 wlist
= wlist
->prev
;
1755 wapp
->flags
.skip_next_animation
= 0;
1758 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1759 wlist
= scr
->focused_window
;
1761 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1762 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1764 wlist
= wlist
->prev
;
1766 wSetFocusTo(scr
, wlist
);
1768 wSetFocusTo(scr
, NULL
);
1772 wapp
->flags
.hidden
= 1;
1774 if (wPreferences
.auto_arrange_icons
)
1775 wArrangeIcons(scr
, True
);
1779 wAppIconPaint(wapp
->app_icon
);
1783 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1785 if (bringToCurrentWS
)
1786 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1788 wwin
->flags
.hidden
= 0;
1790 #ifdef USE_ANIMATIONS
1791 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1792 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1793 icon
->core
->width
, icon
->core
->height
,
1794 wwin
->frame_x
, wwin
->frame_y
,
1795 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1798 /* Tell the compiler it is normal that those parameters are not used in this case */
1804 wwin
->flags
.skip_next_animation
= 0;
1805 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1806 XMapWindow(dpy
, wwin
->client_win
);
1807 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1808 wClientSetState(wwin
, NormalState
, None
);
1809 wwin
->flags
.mapped
= 1;
1810 wRaiseFrame(wwin
->frame
->core
);
1812 if (wwin
->flags
.inspector_open
)
1813 wUnhideInspectorForWindow(wwin
);
1815 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1818 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1821 WWindow
*wlist
, *next
;
1822 WWindow
*focused
= NULL
;
1828 scr
= wapp
->main_window_desc
->screen_ptr
;
1829 wlist
= scr
->focused_window
;
1833 /* goto beginning of list */
1835 wlist
= wlist
->prev
;
1837 animate
= !wapp
->flags
.skip_next_animation
;
1842 if (wlist
->main_window
== wapp
->main_window
) {
1843 if (wlist
->flags
.focused
)
1845 else if (!focused
|| !focused
->flags
.focused
)
1848 if (wlist
->flags
.miniaturized
) {
1849 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1850 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1851 if (!wlist
->icon
->mapped
) {
1854 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1855 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1856 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1859 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1860 wlist
->icon
->mapped
= 1;
1862 wRaiseFrame(wlist
->icon
->core
);
1864 if (bringToCurrentWS
)
1865 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1866 wlist
->flags
.hidden
= 0;
1867 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1868 wDeiconifyWindow(wlist
);
1869 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1870 } else if (wlist
->flags
.shaded
) {
1871 if (bringToCurrentWS
)
1872 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1873 wlist
->flags
.hidden
= 0;
1874 wRaiseFrame(wlist
->frame
->core
);
1875 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1876 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1878 wUnshadeWindow(wlist
);
1880 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1881 } else if (wlist
->flags
.hidden
) {
1882 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1883 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1886 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1887 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1889 wRaiseFrame(wlist
->frame
->core
);
1895 wapp
->flags
.skip_next_animation
= 0;
1896 wapp
->flags
.hidden
= 0;
1898 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1899 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1900 wSetFocusTo(scr
, wapp
->last_focused
);
1901 } else if (focused
) {
1902 wSetFocusTo(scr
, focused
);
1904 wapp
->last_focused
= NULL
;
1905 if (wPreferences
.auto_arrange_icons
)
1906 wArrangeIcons(scr
, True
);
1909 wAppIconPaint(wapp
->app_icon
);
1913 void wShowAllWindows(WScreen
*scr
)
1915 WWindow
*wwin
, *old_foc
;
1918 old_foc
= wwin
= scr
->focused_window
;
1920 if (!wwin
->flags
.internal_window
&&
1921 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1922 if (wwin
->flags
.miniaturized
) {
1923 wwin
->flags
.skip_next_animation
= 1;
1924 wDeiconifyWindow(wwin
);
1925 } else if (wwin
->flags
.hidden
) {
1926 wapp
= wApplicationOf(wwin
->main_window
);
1928 wUnhideApplication(wapp
, False
, False
);
1930 wwin
->flags
.skip_next_animation
= 1;
1931 wDeiconifyWindow(wwin
);
1937 wSetFocusTo(scr
, old_foc
);
1938 /*wRaiseFrame(old_foc->frame->core); */
1941 void wRefreshDesktop(WScreen
*scr
)
1944 XSetWindowAttributes attr
;
1946 attr
.backing_store
= NotUseful
;
1947 attr
.save_under
= False
;
1948 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1949 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1950 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1951 XMapRaised(dpy
, win
);
1952 XDestroyWindow(dpy
, win
);
1956 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1962 const int heads
= wXineramaHeads(scr
);
1965 int pf
; /* primary axis */
1966 int sf
; /* secondary axis */
1970 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1976 int isize
= wPreferences
.icon_size
;
1978 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1980 for (head
= 0; head
< heads
; ++head
) {
1981 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1985 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1987 if (scr
->dock
->on_right_side
)
1993 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1995 vars
[head
].pi
= vars
[head
].si
= 0;
1996 vars
[head
].sx1
= rect
.pos
.x
;
1997 vars
[head
].sy1
= rect
.pos
.y
;
1998 vars
[head
].sw
= rect
.size
.width
;
1999 vars
[head
].sh
= rect
.size
.height
;
2000 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
2001 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
2002 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
2003 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
2004 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
2005 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
2007 /* icon yard boundaries */
2008 if (wPreferences
.icon_yard
& IY_VERT
) {
2009 vars
[head
].pf
= vars
[head
].fullH
;
2010 vars
[head
].sf
= vars
[head
].fullW
;
2012 vars
[head
].pf
= vars
[head
].fullW
;
2013 vars
[head
].sf
= vars
[head
].fullH
;
2015 if (wPreferences
.icon_yard
& IY_RIGHT
) {
2016 vars
[head
].xo
= vars
[head
].sx2
- isize
;
2019 vars
[head
].xo
= vars
[head
].sx1
;
2022 if (wPreferences
.icon_yard
& IY_TOP
) {
2023 vars
[head
].yo
= vars
[head
].sy1
;
2026 vars
[head
].yo
= vars
[head
].sy2
- isize
;
2031 #define X ((wPreferences.icon_yard & IY_VERT) \
2032 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
2033 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
2035 #define Y ((wPreferences.icon_yard & IY_VERT) \
2036 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
2037 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
2039 /* arrange application icons */
2040 aicon
= scr
->app_icon_list
;
2041 /* reverse them to avoid unnecessarily sliding of icons */
2042 while (aicon
&& aicon
->next
)
2043 aicon
= aicon
->next
;
2046 if (!aicon
->docked
) {
2047 /* CHECK: can icon be NULL here ? */
2048 /* The intention here is to place the AppIcon on the head that
2049 * contains most of the applications _main_ window. */
2050 head
= wGetHeadForWindow(aicon
->icon
->owner
);
2052 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
2053 #ifdef USE_ANIMATIONS
2054 if (!wPreferences
.no_animations
)
2055 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
2056 #endif /* USE_ANIMATIONS */
2058 wAppIconMove(aicon
, X
, Y
);
2060 if (vars
[head
].pi
>= vars
[head
].pf
) {
2065 aicon
= aicon
->prev
;
2068 /* arrange miniwindows */
2069 wwin
= scr
->focused_window
;
2070 /* reverse them to avoid unnecessarily shuffling */
2071 while (wwin
&& wwin
->prev
)
2075 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
2076 (wwin
->frame
->workspace
== scr
->current_workspace
||
2077 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
2079 head
= wGetHeadForWindow(wwin
);
2081 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
2082 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
2083 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
2089 if (vars
[head
].pi
>= vars
[head
].pf
) {
2096 wwin
->flags
.icon_moved
= 0;
2097 /* we reversed the order, so we use next */
2104 void wSelectWindow(WWindow
*wwin
, Bool flag
)
2106 WScreen
*scr
= wwin
->screen_ptr
;
2109 wwin
->flags
.selected
= 1;
2110 if (wwin
->frame
->selected_border_pixel
)
2111 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
2113 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
2115 if (!HAS_BORDER(wwin
))
2116 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
2118 if (!scr
->selected_windows
)
2119 scr
->selected_windows
= WMCreateArray(4);
2120 WMAddToArray(scr
->selected_windows
, wwin
);
2122 wwin
->flags
.selected
= 0;
2123 if (wwin
->flags
.focused
) {
2124 if (wwin
->frame
->focused_border_pixel
)
2125 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
2127 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
2129 if (wwin
->frame
->border_pixel
)
2130 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
2132 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
2135 if (!HAS_BORDER(wwin
))
2136 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
2138 if (scr
->selected_windows
)
2139 WMRemoveFromArray(scr
->selected_windows
, wwin
);
2143 void wMakeWindowVisible(WWindow
*wwin
)
2145 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
2146 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
2148 if (wwin
->flags
.shaded
)
2149 wUnshadeWindow(wwin
);
2151 if (wwin
->flags
.hidden
) {
2154 app
= wApplicationOf(wwin
->main_window
);
2156 /* trick to get focus to this window */
2157 app
->last_focused
= wwin
;
2158 wUnhideApplication(app
, False
, False
);
2161 if (wwin
->flags
.miniaturized
) {
2162 wDeiconifyWindow(wwin
);
2164 if (!WFLAGP(wwin
, no_focusable
))
2165 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2166 wRaiseFrame(wwin
->frame
->core
);
2170 void movePionterToWindowCenter(WWindow
*wwin
)
2172 if (!wPreferences
.pointer_with_half_max_windows
)
2175 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
2176 XWarpPointer(dpy
, None
, wwin
->screen_ptr
->root_win
, 0, 0, 0, 0,
2177 wwin
->frame_x
+ wwin
->client
.width
/ 2,
2178 wwin
->frame_y
+ wwin
->client
.height
/ 2);
2183 * Do the animation while shading (called with what = SHADE)
2184 * or unshading (what = UNSHADE).
2186 #ifdef USE_ANIMATIONS
2187 static void shade_animate(WWindow
*wwin
, Bool what
)
2190 time_t time0
= time(NULL
);
2192 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
2197 if (!wwin
->screen_ptr
->flags
.startup
) {
2198 /* do the shading animation */
2199 h
= wwin
->frame
->core
->height
;
2200 s
= h
/ SHADE_STEPS
;
2203 w
= wwin
->frame
->core
->width
;
2204 y
= wwin
->frame
->top_width
;
2205 while (h
> wwin
->frame
->top_width
+ 1) {
2206 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2207 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2210 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2213 if (SHADE_DELAY
> 0)
2214 wusleep(SHADE_DELAY
* 1000L);
2220 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2225 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2226 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2227 s
= abs(y
) / SHADE_STEPS
;
2230 w
= wwin
->frame
->core
->width
;
2231 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2233 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2234 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2235 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2237 if (SHADE_DELAY
> 0)
2238 wusleep(SHADE_DELAY
* 2000L / 3);
2244 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2248 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);