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 /* the window boundary coordinates */
682 static void set_window_coords(WWindow
*wwin
, win_coords
*obs
)
684 obs
->left
= wwin
->frame_x
;
685 obs
->top
= wwin
->frame_y
;
686 obs
->width
= wwin
->frame
->core
->width
;
687 obs
->height
= wwin
->frame
->core
->height
;
688 obs
->bottom
= obs
->top
+ obs
->height
;
689 obs
->right
= obs
->left
+ obs
->width
;
693 * Maximus: tiled maximization (maximize without overlapping other windows)
695 * The original window 'orig' will be maximized to new coordinates 'new'.
696 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
698 static void find_Maximus_geometry(WWindow
*wwin
, WArea usableArea
, int *new_x
, int *new_y
,
699 unsigned int *new_width
, unsigned int *new_height
)
702 short int tbar_height_0
= 0, rbar_height_0
= 0, bd_width_0
= 0;
703 short int adjust_height
;
704 int x_intsect
, y_intsect
;
705 /* the obstructing, original and new windows */
706 win_coords obs
, orig
, new;
708 /* set the original coordinate positions of the window to be Maximumized */
709 if (wwin
->flags
.maximized
) {
710 /* window is already maximized; consider original geometry */
711 remember_geometry(wwin
, &orig
.left
, &orig
.top
, &orig
.width
, &orig
.height
);
712 orig
.bottom
= orig
.top
+ orig
.height
;
713 orig
.right
= orig
.left
+ orig
.width
;
715 set_window_coords(wwin
, &orig
);
717 /* Try to fully maximize first, then readjust later */
718 new.left
= usableArea
.x1
;
719 new.right
= usableArea
.x2
;
720 new.top
= usableArea
.y1
;
721 new.bottom
= usableArea
.y2
;
723 if (HAS_TITLEBAR(wwin
))
724 tbar_height_0
= TITLEBAR_HEIGHT
;
725 if (HAS_RESIZEBAR(wwin
))
726 rbar_height_0
= RESIZEBAR_HEIGHT
;
727 if (HAS_BORDER(wwin
))
728 bd_width_0
= wwin
->screen_ptr
->frame_border_width
;
730 /* the length to be subtracted if the window has titlebar, etc */
731 adjust_height
= tbar_height_0
+ 2 * bd_width_0
+ rbar_height_0
;
734 /* The focused window is always the last in the list */
736 /* ignore windows in other workspaces etc */
737 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
738 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
744 /* Set the coordinates of obstructing window */
745 set_window_coords(tmp
, &obs
);
747 /* Try to maximize in the y direction first */
748 x_intsect
= calcIntersectionLength(orig
.left
, orig
.width
, obs
.left
, obs
.width
);
749 if (x_intsect
!= 0) {
750 /* TODO: Consider the case when coords are equal */
751 if (obs
.bottom
< orig
.top
&& obs
.bottom
> new.top
) {
752 /* w_0 is below the bottom of w_j */
753 new.top
= obs
.bottom
+ 1;
755 if (orig
.bottom
< obs
.top
&& obs
.top
< new.bottom
) {
756 /* The bottom of w_0 is above the top of w_j */
757 new.bottom
= obs
.top
- 1;
764 if (tmp
->prev
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
765 || tmp
->prev
->flags
.miniaturized
|| tmp
->prev
->flags
.hidden
) {
771 set_window_coords(tmp
, &obs
);
774 * Use the new.top and new.height instead of original values
775 * as they may have different intersections with the obstructing windows
777 new.height
= new.bottom
- new.top
- adjust_height
;
778 y_intsect
= calcIntersectionLength(new.top
, new.height
, obs
.top
, obs
.height
);
779 if (y_intsect
!= 0) {
780 if (obs
.right
< orig
.left
&& obs
.right
> new.left
) {
781 /* w_0 is completely to the right of w_j */
782 new.left
= obs
.right
+ 1;
784 if (orig
.right
< obs
.left
&& obs
.left
< new.right
) {
785 /* w_0 is completely to the left of w_j */
786 new.right
= obs
.left
- 1;
793 /* xcalc needs -7 here, but other apps don't */
794 *new_height
= new.bottom
- new.top
- adjust_height
- 1;
795 *new_width
= new.right
- new.left
;
798 void wUnmaximizeWindow(WWindow
*wwin
)
802 if (!wwin
->flags
.maximized
)
805 if (wwin
->flags
.shaded
) {
806 wwin
->flags
.skip_next_animation
= 1;
807 wUnshadeWindow(wwin
);
810 if (wPreferences
.drag_maximized_window
== DRAGMAX_NOMOVE
)
811 wwin
->client_flags
.no_movable
= 0;
813 /* Use old coordinates if they are set, current values otherwise */
814 remember_geometry(wwin
, &x
, &y
, &w
, &h
);
816 /* unMaximusize relative to original position */
817 if (wwin
->flags
.maximized
& MAX_MAXIMUS
) {
818 x
+= wwin
->frame_x
- wwin
->maximus_x
;
819 y
+= wwin
->frame_y
- wwin
->maximus_y
;
822 wwin
->flags
.maximized
= 0;
823 wwin
->flags
.old_maximized
= 0;
824 wWindowConfigure(wwin
, x
, y
, w
, h
);
825 wWindowSynthConfigureNotify(wwin
);
827 WMPostNotificationName(WMNChangedState
, wwin
, "maximize");
830 void wFullscreenWindow(WWindow
*wwin
)
835 if (wwin
->flags
.fullscreen
)
838 wwin
->flags
.fullscreen
= True
;
840 wWindowConfigureBorders(wwin
);
842 ChangeStackingLevel(wwin
->frame
->core
, WMFullscreenLevel
);
844 wwin
->bfs_geometry
.x
= wwin
->frame_x
;
845 wwin
->bfs_geometry
.y
= wwin
->frame_y
;
846 wwin
->bfs_geometry
.width
= wwin
->frame
->core
->width
;
847 wwin
->bfs_geometry
.height
= wwin
->frame
->core
->height
;
849 head
= wGetHeadForWindow(wwin
);
850 rect
= wGetRectForHead(wwin
->screen_ptr
, head
);
851 wWindowConfigure(wwin
, rect
.pos
.x
, rect
.pos
.y
, rect
.size
.width
, rect
.size
.height
);
853 wwin
->screen_ptr
->bfs_focused_window
= wwin
->screen_ptr
->focused_window
;
854 wSetFocusTo(wwin
->screen_ptr
, wwin
);
856 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
859 void wUnfullscreenWindow(WWindow
*wwin
)
861 if (!wwin
->flags
.fullscreen
)
864 wwin
->flags
.fullscreen
= False
;
866 if (wwin
->frame
->core
->stacking
->window_level
== WMFullscreenLevel
) {
867 if (WFLAGP(wwin
, sunken
)) {
868 ChangeStackingLevel(wwin
->frame
->core
, WMSunkenLevel
);
869 } else if (WFLAGP(wwin
, floating
)) {
870 ChangeStackingLevel(wwin
->frame
->core
, WMFloatingLevel
);
872 ChangeStackingLevel(wwin
->frame
->core
, WMNormalLevel
);
876 wWindowConfigure(wwin
, wwin
->bfs_geometry
.x
, wwin
->bfs_geometry
.y
,
877 wwin
->bfs_geometry
.width
, wwin
->bfs_geometry
.height
);
879 wWindowConfigureBorders(wwin
);
881 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
882 wFrameWindowPaint(wwin->frame);
885 WMPostNotificationName(WMNChangedState
, wwin
, "fullscreen");
887 if (wwin
->screen_ptr
->bfs_focused_window
) {
888 wSetFocusTo(wwin
->screen_ptr
, wwin
->screen_ptr
->bfs_focused_window
);
889 wwin
->screen_ptr
->bfs_focused_window
= NULL
;
893 #ifdef USE_ANIMATIONS
894 static void animateResizeFlip(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
896 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
897 float cx
, cy
, cw
, ch
;
898 float xstep
, ystep
, wstep
, hstep
;
901 float angle
, final_angle
, delta
;
903 xstep
= (float)(fx
- x
) / steps
;
904 ystep
= (float)(fy
- y
) / steps
;
905 wstep
= (float)(fw
- w
) / steps
;
906 hstep
= (float)(fh
- h
) / steps
;
913 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_F
;
914 delta
= (float)(final_angle
/ FRAMES
);
915 for (angle
= 0;; angle
+= delta
) {
916 if (angle
> final_angle
)
919 dx
= (cw
/ 10) - ((cw
/ 5) * sinf(angle
));
920 dch
= (ch
/ 2) * cosf(angle
);
921 midy
= cy
+ (ch
/ 2);
923 points
[0].x
= cx
+ dx
;
924 points
[0].y
= midy
- dch
;
925 points
[1].x
= cx
+ cw
- dx
;
926 points
[1].y
= points
[0].y
;
927 points
[2].x
= cx
+ cw
+ dx
;
928 points
[2].y
= midy
+ dch
;
929 points
[3].x
= cx
- dx
;
930 points
[3].y
= points
[2].y
;
931 points
[4].x
= points
[0].x
;
932 points
[4].y
= points
[0].y
;
935 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
937 wusleep(MINIATURIZE_ANIMATION_DELAY_F
);
939 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
945 if (angle
>= final_angle
)
955 animateResizeTwist(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
957 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
958 float cx
, cy
, cw
, ch
;
959 float xstep
, ystep
, wstep
, hstep
;
961 float angle
, final_angle
, a
, d
, delta
;
968 xstep
= (float)(fx
- x
) / steps
;
969 ystep
= (float)(fy
- y
) / steps
;
970 wstep
= (float)(fw
- w
) / steps
;
971 hstep
= (float)(fh
- h
) / steps
;
978 final_angle
= 2 * WM_PI
* MINIATURIZE_ANIMATION_TWIST_T
;
979 delta
= (float)(final_angle
/ FRAMES
);
980 for (angle
= 0;; angle
+= delta
) {
981 if (angle
> final_angle
)
985 d
= sqrtf((cw
/ 2) * (cw
/ 2) + (ch
/ 2) * (ch
/ 2));
987 points
[0].x
= cx
+ cosf(angle
- a
) * d
;
988 points
[0].y
= cy
+ sinf(angle
- a
) * d
;
989 points
[1].x
= cx
+ cosf(angle
+ a
) * d
;
990 points
[1].y
= cy
+ sinf(angle
+ a
) * d
;
991 points
[2].x
= cx
+ cosf(angle
- a
+ (float)WM_PI
) * d
;
992 points
[2].y
= cy
+ sinf(angle
- a
+ (float)WM_PI
) * d
;
993 points
[3].x
= cx
+ cosf(angle
+ a
+ (float)WM_PI
) * d
;
994 points
[3].y
= cy
+ sinf(angle
+ a
+ (float)WM_PI
) * d
;
995 points
[4].x
= cx
+ cosf(angle
- a
) * d
;
996 points
[4].y
= cy
+ sinf(angle
- a
) * d
;
998 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1000 wusleep(MINIATURIZE_ANIMATION_DELAY_T
);
1002 XDrawLines(dpy
, scr
->root_win
, scr
->frame_gc
, points
, 5, CoordModeOrigin
);
1008 if (angle
>= final_angle
)
1017 static void animateResizeZoom(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
, int steps
)
1019 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
1020 float cx
[FRAMES
], cy
[FRAMES
], cw
[FRAMES
], ch
[FRAMES
];
1021 float xstep
, ystep
, wstep
, hstep
;
1024 xstep
= (float)(fx
- x
) / steps
;
1025 ystep
= (float)(fy
- y
) / steps
;
1026 wstep
= (float)(fw
- w
) / steps
;
1027 hstep
= (float)(fh
- h
) / steps
;
1029 for (j
= 0; j
< FRAMES
; j
++) {
1036 for (i
= 0; i
< steps
; i
++) {
1037 for (j
= 0; j
< FRAMES
; j
++) {
1038 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
1039 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1042 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
1044 for (j
= 0; j
< FRAMES
; j
++) {
1045 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
,
1046 (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1047 if (j
< FRAMES
- 1) {
1061 for (j
= 0; j
< FRAMES
; j
++)
1062 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1064 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
);
1066 for (j
= 0; j
< FRAMES
; j
++)
1067 XDrawRectangle(dpy
, scr
->root_win
, scr
->frame_gc
, (int)cx
[j
], (int)cy
[j
], (int)cw
[j
], (int)ch
[j
]);
1074 void animateResize(WScreen
*scr
, int x
, int y
, int w
, int h
, int fx
, int fy
, int fw
, int fh
)
1076 int style
= wPreferences
.iconification_style
; /* Catch the value */
1079 if (style
== WIS_NONE
)
1082 if (style
== WIS_RANDOM
)
1087 steps
= MINIATURIZE_ANIMATION_STEPS_T
;
1089 animateResizeTwist(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1092 steps
= MINIATURIZE_ANIMATION_STEPS_F
;
1094 animateResizeFlip(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1098 steps
= MINIATURIZE_ANIMATION_STEPS_Z
;
1100 animateResizeZoom(scr
, x
, y
, w
, h
, fx
, fy
, fw
, fh
, steps
);
1104 #endif /* USE_ANIMATIONS */
1106 static void flushExpose(void)
1110 while (XCheckTypedEvent(dpy
, Expose
, &tmpev
))
1111 WMHandleEvent(&tmpev
);
1115 static void unmapTransientsFor(WWindow
*wwin
)
1119 tmp
= wwin
->screen_ptr
->focused_window
;
1121 /* unmap the transients for this transient */
1122 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
1123 && (tmp
->flags
.mapped
|| wwin
->screen_ptr
->flags
.startup
|| tmp
->flags
.shaded
)) {
1124 unmapTransientsFor(tmp
);
1125 tmp
->flags
.miniaturized
= 1;
1126 if (!tmp
->flags
.shaded
)
1129 XUnmapWindow(dpy
, tmp
->frame
->core
->window
);
1131 if (!tmp->flags.shaded)
1133 wClientSetState(tmp
, IconicState
, None
);
1135 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1141 static void mapTransientsFor(WWindow
*wwin
)
1145 tmp
= wwin
->screen_ptr
->focused_window
;
1147 /* recursively map the transients for this transient */
1148 if (tmp
!= wwin
&& tmp
->transient_for
== wwin
->client_win
&& /*!tmp->flags.mapped */ tmp
->flags
.miniaturized
1149 && tmp
->icon
== NULL
) {
1150 mapTransientsFor(tmp
);
1151 tmp
->flags
.miniaturized
= 0;
1152 if (!tmp
->flags
.shaded
)
1155 XMapWindow(dpy
, tmp
->frame
->core
->window
);
1156 tmp
->flags
.semi_focused
= 0;
1158 if (!tmp->flags.shaded)
1160 wClientSetState(tmp
, NormalState
, None
);
1162 WMPostNotificationName(WMNChangedState
, tmp
, "iconify-transient");
1168 static WWindow
*recursiveTransientFor(WWindow
*wwin
)
1175 /* hackish way to detect transient_for cycle */
1176 i
= wwin
->screen_ptr
->window_count
+ 1;
1178 while (wwin
&& wwin
->transient_for
!= None
&& i
> 0) {
1179 wwin
= wWindowFor(wwin
->transient_for
);
1182 if (i
== 0 && wwin
) {
1183 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1184 wwin
->frame
->title
);
1191 #ifdef USE_ANIMATIONS
1192 static int getAnimationGeometry(WWindow
*wwin
, int *ix
, int *iy
, int *iw
, int *ih
)
1194 if (wwin
->screen_ptr
->flags
.startup
|| wPreferences
.no_animations
1195 || wwin
->flags
.skip_next_animation
|| wwin
->icon
== NULL
)
1198 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1201 *iw
= wwin
->icon
->core
->width
;
1202 *ih
= wwin
->icon
->core
->height
;
1204 if (wwin
->flags
.net_handle_icon
) {
1212 *iw
= wwin
->screen_ptr
->scr_width
;
1213 *ih
= wwin
->screen_ptr
->scr_height
;
1218 #endif /* USE_ANIMATIONS */
1220 void wIconifyWindow(WWindow
*wwin
)
1222 XWindowAttributes attribs
;
1225 if (!XGetWindowAttributes(dpy
, wwin
->client_win
, &attribs
))
1226 return; /* the window doesn't exist anymore */
1228 if (wwin
->flags
.miniaturized
)
1229 return; /* already miniaturized */
1231 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1232 WWindow
*owner
= wWindowFor(wwin
->transient_for
);
1234 if (owner
&& owner
->flags
.miniaturized
)
1238 present
= wwin
->frame
->workspace
== wwin
->screen_ptr
->current_workspace
;
1240 /* if the window is in another workspace, simplify process */
1242 /* icon creation may take a while */
1243 XGrabPointer(dpy
, wwin
->screen_ptr
->root_win
, False
,
1244 ButtonMotionMask
| ButtonReleaseMask
, GrabModeAsync
,
1245 GrabModeAsync
, None
, None
, CurrentTime
);
1248 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1249 if (!wwin
->flags
.icon_moved
)
1250 PlaceIcon(wwin
->screen_ptr
, &wwin
->icon_x
, &wwin
->icon_y
, wGetHeadForWindow(wwin
));
1252 wwin
->icon
= icon_create_for_wwindow(wwin
);
1253 wwin
->icon
->mapped
= 1;
1255 /* extract the window screenshot every time, as the option can be enable anytime */
1256 if (wwin
->client_win
&& wwin
->flags
.mapped
) {
1257 RImage
*mini_preview
;
1263 XRaiseWindow(dpy
, wwin
->frame
->core
->window
);
1264 XTranslateCoordinates(dpy
, wwin
->client_win
, wwin
->screen_ptr
->root_win
, 0, 0, &x
, &y
, &baz
);
1269 if (x
- attribs
.x
+ attribs
.width
> wwin
->screen_ptr
->scr_width
)
1270 w
= wwin
->screen_ptr
->scr_width
- x
+ attribs
.x
;
1272 if (y
- attribs
.y
+ attribs
.height
> wwin
->screen_ptr
->scr_height
)
1273 h
= wwin
->screen_ptr
->scr_height
- y
+ attribs
.y
;
1275 pimg
= XGetImage(dpy
, wwin
->client_win
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
1277 mini_preview
= RCreateImageFromXImage(wwin
->screen_ptr
->rcontext
, pimg
, NULL
);
1278 XDestroyImage(pimg
);
1281 set_icon_minipreview(wwin
->icon
, mini_preview
);
1282 RReleaseImage(mini_preview
);
1287 if (wwin
->frame
->title
) {
1288 title
= wwin
->frame
->title
;
1290 snprintf(title_buf
, sizeof(title_buf
), "(id=0x%lx)", wwin
->client_win
);
1293 wwarning(_("creation of mini-preview failed for window \"%s\""), title
);
1299 wwin
->flags
.miniaturized
= 1;
1300 wwin
->flags
.mapped
= 0;
1302 /* unmap transients */
1303 unmapTransientsFor(wwin
);
1306 #ifdef USE_ANIMATIONS
1309 XUngrabPointer(dpy
, CurrentTime
);
1311 /* let all Expose events arrive so that we can repaint
1312 * something before the animation starts (and the server is grabbed) */
1315 if (wPreferences
.disable_miniwindows
|| wwin
->flags
.net_handle_icon
)
1316 wClientSetState(wwin
, IconicState
, None
);
1318 wClientSetState(wwin
, IconicState
, wwin
->icon
->icon_win
);
1321 #ifdef USE_ANIMATIONS
1322 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1323 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1324 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
, ix
, iy
, iw
, ih
);
1328 wwin
->flags
.skip_next_animation
= 0;
1330 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
) {
1331 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
||
1332 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)
1333 XMapWindow(dpy
, wwin
->icon
->core
->window
);
1335 AddToStackList(wwin
->icon
->core
);
1336 wLowerFrame(wwin
->icon
->core
);
1340 WWindow
*owner
= recursiveTransientFor(wwin
->screen_ptr
->focused_window
);
1343 * It doesn't seem to be working and causes button event hangup
1344 * when deiconifying a transient window.
1345 setupIconGrabs(wwin->icon);
1347 if ((wwin
->flags
.focused
|| (owner
&& wwin
->client_win
== owner
->client_win
))
1348 && wPreferences
.focus_mode
== WKF_CLICK
) {
1353 if (!WFLAGP(tmp
, no_focusable
)
1354 && !(tmp
->flags
.hidden
|| tmp
->flags
.miniaturized
)
1355 && (wwin
->frame
->workspace
== tmp
->frame
->workspace
))
1359 wSetFocusTo(wwin
->screen_ptr
, tmp
);
1360 } else if (wPreferences
.focus_mode
!= WKF_CLICK
) {
1361 wSetFocusTo(wwin
->screen_ptr
, NULL
);
1363 #ifdef USE_ANIMATIONS
1364 if (!wwin
->screen_ptr
->flags
.startup
) {
1365 /* Catch up with events not processed while animation was running */
1366 Window clientwin
= wwin
->client_win
;
1368 ProcessPendingEvents();
1370 /* the window can disappear while ProcessPendingEvents() runs */
1371 if (!wWindowFor(clientwin
))
1377 /* maybe we want to do this regardless of net_handle_icon
1378 * it seems to me we might break behaviour this way.
1380 if (wwin
->flags
.selected
&& !wPreferences
.disable_miniwindows
1381 && !wwin
->flags
.net_handle_icon
)
1382 wIconSelect(wwin
->icon
);
1384 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1386 if (wPreferences
.auto_arrange_icons
)
1387 wArrangeIcons(wwin
->screen_ptr
, True
);
1390 void wDeiconifyWindow(WWindow
*wwin
)
1392 /* Let's avoid changing workspace while deiconifying */
1393 w_global
.ignore_workspace_change
= True
;
1395 /* we're hiding for show_desktop */
1396 int netwm_hidden
= wwin
->flags
.net_show_desktop
&&
1397 wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
;
1400 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1402 if (!wwin
->flags
.miniaturized
) {
1403 w_global
.ignore_workspace_change
= False
;
1407 if (wwin
->transient_for
!= None
&& wwin
->transient_for
!= wwin
->screen_ptr
->root_win
) {
1408 WWindow
*owner
= recursiveTransientFor(wwin
);
1410 if (owner
&& owner
->flags
.miniaturized
) {
1411 wDeiconifyWindow(owner
);
1412 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1413 wRaiseFrame(wwin
->frame
->core
);
1414 w_global
.ignore_workspace_change
= False
;
1419 wwin
->flags
.miniaturized
= 0;
1421 if (!netwm_hidden
&& !wwin
->flags
.shaded
)
1422 wwin
->flags
.mapped
= 1;
1424 if (!netwm_hidden
|| wPreferences
.sticky_icons
) {
1425 /* maybe we want to do this regardless of net_handle_icon
1426 * it seems to me we might break behaviour this way.
1428 if (!wPreferences
.disable_miniwindows
&& !wwin
->flags
.net_handle_icon
1429 && wwin
->icon
!= NULL
) {
1430 if (wwin
->icon
->selected
)
1431 wIconSelect(wwin
->icon
);
1433 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1437 /* if the window is in another workspace, do it silently */
1438 if (!netwm_hidden
) {
1439 #ifdef USE_ANIMATIONS
1441 if (getAnimationGeometry(wwin
, &ix
, &iy
, &iw
, &ih
))
1442 animateResize(wwin
->screen_ptr
, ix
, iy
, iw
, ih
,
1443 wwin
->frame_x
, wwin
->frame_y
,
1444 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1446 wwin
->flags
.skip_next_animation
= 0;
1448 if (!wwin
->flags
.shaded
)
1449 XMapWindow(dpy
, wwin
->client_win
);
1451 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1452 wRaiseFrame(wwin
->frame
->core
);
1453 if (!wwin
->flags
.shaded
)
1454 wClientSetState(wwin
, NormalState
, None
);
1456 mapTransientsFor(wwin
);
1459 if (!wPreferences
.disable_miniwindows
&& wwin
->icon
!= NULL
1460 && !wwin
->flags
.net_handle_icon
) {
1461 RemoveFromStackList(wwin
->icon
->core
);
1462 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1463 wIconDestroy(wwin
->icon
);
1467 if (!netwm_hidden
) {
1470 wSetFocusTo(wwin
->screen_ptr
, wwin
);
1472 #ifdef USE_ANIMATIONS
1473 if (!wwin
->screen_ptr
->flags
.startup
) {
1474 /* Catch up with events not processed while animation was running */
1475 Window clientwin
= wwin
->client_win
;
1477 ProcessPendingEvents();
1479 /* the window can disappear while ProcessPendingEvents() runs */
1480 if (!wWindowFor(clientwin
)) {
1481 w_global
.ignore_workspace_change
= False
;
1488 if (wPreferences
.auto_arrange_icons
)
1489 wArrangeIcons(wwin
->screen_ptr
, True
);
1491 WMPostNotificationName(WMNChangedState
, wwin
, "iconify");
1493 /* In case we were shaded and iconified, also unshade */
1495 wUnshadeWindow(wwin
);
1497 w_global
.ignore_workspace_change
= False
;
1500 static void hideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
)
1502 if (wwin
->flags
.miniaturized
) {
1504 XUnmapWindow(dpy
, wwin
->icon
->core
->window
);
1505 wwin
->icon
->mapped
= 0;
1507 wwin
->flags
.hidden
= 1;
1509 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1513 if (wwin
->flags
.inspector_open
)
1514 wHideInspectorForWindow(wwin
);
1516 wwin
->flags
.hidden
= 1;
1519 wClientSetState(wwin
, IconicState
, icon
->icon_win
);
1522 #ifdef USE_ANIMATIONS
1523 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&&
1524 !wwin
->flags
.skip_next_animation
&& animate
) {
1525 animateResize(wwin
->screen_ptr
, wwin
->frame_x
, wwin
->frame_y
,
1526 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
,
1527 icon_x
, icon_y
, icon
->core
->width
, icon
->core
->height
);
1530 /* Tell the compiler it is normal that those parameters are not used in this case */
1535 wwin
->flags
.skip_next_animation
= 0;
1537 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1540 void wHideAll(WScreen
*scr
)
1545 unsigned int wcount
= 0;
1551 menu
= scr
->switch_menu
;
1553 windows
= wmalloc(sizeof(WWindow
*));
1556 for (i
= 0; i
< menu
->entry_no
; i
++) {
1557 windows
[wcount
] = (WWindow
*) menu
->entries
[i
]->clientdata
;
1559 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1562 wwin
= scr
->focused_window
;
1565 windows
[wcount
] = wwin
;
1567 windows
= wrealloc(windows
, sizeof(WWindow
*) * (wcount
+ 1));
1573 for (i
= 0; i
< wcount
; i
++) {
1575 if (wwin
->frame
->workspace
== scr
->current_workspace
1576 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1577 && !wwin
->flags
.internal_window
1578 && !WFLAGP(wwin
, no_miniaturizable
)
1580 wwin
->flags
.skip_next_animation
= 1;
1581 wIconifyWindow(wwin
);
1588 void wHideOtherApplications(WWindow
*awin
)
1595 wwin
= awin
->screen_ptr
->focused_window
;
1599 && wwin
->frame
->workspace
== awin
->screen_ptr
->current_workspace
1600 && !(wwin
->flags
.miniaturized
|| wwin
->flags
.hidden
)
1601 && !wwin
->flags
.internal_window
1602 && wGetWindowOfInspectorForWindow(wwin
) != awin
&& !WFLAGP(wwin
, no_hide_others
)) {
1604 if (wwin
->main_window
== None
|| WFLAGP(wwin
, no_appicon
)) {
1605 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1606 wwin
->flags
.skip_next_animation
= 1;
1607 wIconifyWindow(wwin
);
1609 } else if (wwin
->main_window
!= None
&& awin
->main_window
!= wwin
->main_window
) {
1610 tapp
= wApplicationOf(wwin
->main_window
);
1612 tapp
->flags
.skip_next_animation
= 1;
1613 wHideApplication(tapp
);
1615 if (!WFLAGP(wwin
, no_miniaturizable
)) {
1616 wwin
->flags
.skip_next_animation
= 1;
1617 wIconifyWindow(wwin
);
1625 wSetFocusTo(awin->screen_ptr, awin);
1629 void wHideApplication(WApplication
*wapp
)
1637 wwarning("trying to hide a non grouped window");
1640 if (!wapp
->main_window_desc
) {
1641 wwarning("group leader not found for window group");
1644 scr
= wapp
->main_window_desc
->screen_ptr
;
1646 wlist
= scr
->focused_window
;
1650 if (wlist
->main_window
== wapp
->main_window
)
1651 wapp
->last_focused
= wlist
;
1653 wapp
->last_focused
= NULL
;
1655 animate
= !wapp
->flags
.skip_next_animation
;
1658 if (wlist
->main_window
== wapp
->main_window
) {
1659 if (wlist
->flags
.focused
)
1661 if (wapp
->app_icon
) {
1662 hideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1663 wapp
->app_icon
->y_pos
, wlist
, animate
);
1667 wlist
= wlist
->prev
;
1670 wapp
->flags
.skip_next_animation
= 0;
1673 if (wPreferences
.focus_mode
== WKF_CLICK
) {
1674 wlist
= scr
->focused_window
;
1676 if (!WFLAGP(wlist
, no_focusable
) && !wlist
->flags
.hidden
1677 && (wlist
->flags
.mapped
|| wlist
->flags
.shaded
))
1679 wlist
= wlist
->prev
;
1681 wSetFocusTo(scr
, wlist
);
1683 wSetFocusTo(scr
, NULL
);
1687 wapp
->flags
.hidden
= 1;
1689 if (wPreferences
.auto_arrange_icons
)
1690 wArrangeIcons(scr
, True
);
1694 wAppIconPaint(wapp
->app_icon
);
1698 static void unhideWindow(WIcon
*icon
, int icon_x
, int icon_y
, WWindow
*wwin
, int animate
, int bringToCurrentWS
)
1700 if (bringToCurrentWS
)
1701 wWindowChangeWorkspace(wwin
, wwin
->screen_ptr
->current_workspace
);
1703 wwin
->flags
.hidden
= 0;
1705 #ifdef USE_ANIMATIONS
1706 if (!wwin
->screen_ptr
->flags
.startup
&& !wPreferences
.no_animations
&& animate
) {
1707 animateResize(wwin
->screen_ptr
, icon_x
, icon_y
,
1708 icon
->core
->width
, icon
->core
->height
,
1709 wwin
->frame_x
, wwin
->frame_y
,
1710 wwin
->frame
->core
->width
, wwin
->frame
->core
->height
);
1713 /* Tell the compiler it is normal that those parameters are not used in this case */
1719 wwin
->flags
.skip_next_animation
= 0;
1720 if (wwin
->screen_ptr
->current_workspace
== wwin
->frame
->workspace
) {
1721 XMapWindow(dpy
, wwin
->client_win
);
1722 XMapWindow(dpy
, wwin
->frame
->core
->window
);
1723 wClientSetState(wwin
, NormalState
, None
);
1724 wwin
->flags
.mapped
= 1;
1725 wRaiseFrame(wwin
->frame
->core
);
1727 if (wwin
->flags
.inspector_open
)
1728 wUnhideInspectorForWindow(wwin
);
1730 WMPostNotificationName(WMNChangedState
, wwin
, "hide");
1733 void wUnhideApplication(WApplication
*wapp
, Bool miniwindows
, Bool bringToCurrentWS
)
1736 WWindow
*wlist
, *next
;
1737 WWindow
*focused
= NULL
;
1743 scr
= wapp
->main_window_desc
->screen_ptr
;
1744 wlist
= scr
->focused_window
;
1748 /* goto beginning of list */
1750 wlist
= wlist
->prev
;
1752 animate
= !wapp
->flags
.skip_next_animation
;
1757 if (wlist
->main_window
== wapp
->main_window
) {
1758 if (wlist
->flags
.focused
)
1760 else if (!focused
|| !focused
->flags
.focused
)
1763 if (wlist
->flags
.miniaturized
) {
1764 if ((bringToCurrentWS
|| wPreferences
.sticky_icons
||
1765 wlist
->frame
->workspace
== scr
->current_workspace
) && wlist
->icon
) {
1766 if (!wlist
->icon
->mapped
) {
1769 PlaceIcon(scr
, &x
, &y
, wGetHeadForWindow(wlist
));
1770 if (wlist
->icon_x
!= x
|| wlist
->icon_y
!= y
)
1771 XMoveWindow(dpy
, wlist
->icon
->core
->window
, x
, y
);
1774 XMapWindow(dpy
, wlist
->icon
->core
->window
);
1775 wlist
->icon
->mapped
= 1;
1777 wRaiseFrame(wlist
->icon
->core
);
1779 if (bringToCurrentWS
)
1780 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1781 wlist
->flags
.hidden
= 0;
1782 if (miniwindows
&& wlist
->frame
->workspace
== scr
->current_workspace
)
1783 wDeiconifyWindow(wlist
);
1784 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1785 } else if (wlist
->flags
.shaded
) {
1786 if (bringToCurrentWS
)
1787 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1788 wlist
->flags
.hidden
= 0;
1789 wRaiseFrame(wlist
->frame
->core
);
1790 if (wlist
->frame
->workspace
== scr
->current_workspace
) {
1791 XMapWindow(dpy
, wlist
->frame
->core
->window
);
1793 wUnshadeWindow(wlist
);
1795 WMPostNotificationName(WMNChangedState
, wlist
, "hide");
1796 } else if (wlist
->flags
.hidden
) {
1797 unhideWindow(wapp
->app_icon
->icon
, wapp
->app_icon
->x_pos
,
1798 wapp
->app_icon
->y_pos
, wlist
, animate
, bringToCurrentWS
);
1801 if (bringToCurrentWS
&& wlist
->frame
->workspace
!= scr
->current_workspace
)
1802 wWindowChangeWorkspace(wlist
, scr
->current_workspace
);
1804 wRaiseFrame(wlist
->frame
->core
);
1810 wapp
->flags
.skip_next_animation
= 0;
1811 wapp
->flags
.hidden
= 0;
1813 if (wapp
->last_focused
&& wapp
->last_focused
->flags
.mapped
) {
1814 wRaiseFrame(wapp
->last_focused
->frame
->core
);
1815 wSetFocusTo(scr
, wapp
->last_focused
);
1816 } else if (focused
) {
1817 wSetFocusTo(scr
, focused
);
1819 wapp
->last_focused
= NULL
;
1820 if (wPreferences
.auto_arrange_icons
)
1821 wArrangeIcons(scr
, True
);
1824 wAppIconPaint(wapp
->app_icon
);
1828 void wShowAllWindows(WScreen
*scr
)
1830 WWindow
*wwin
, *old_foc
;
1833 old_foc
= wwin
= scr
->focused_window
;
1835 if (!wwin
->flags
.internal_window
&&
1836 (scr
->current_workspace
== wwin
->frame
->workspace
|| IS_OMNIPRESENT(wwin
))) {
1837 if (wwin
->flags
.miniaturized
) {
1838 wwin
->flags
.skip_next_animation
= 1;
1839 wDeiconifyWindow(wwin
);
1840 } else if (wwin
->flags
.hidden
) {
1841 wapp
= wApplicationOf(wwin
->main_window
);
1843 wUnhideApplication(wapp
, False
, False
);
1845 wwin
->flags
.skip_next_animation
= 1;
1846 wDeiconifyWindow(wwin
);
1852 wSetFocusTo(scr
, old_foc
);
1853 /*wRaiseFrame(old_foc->frame->core); */
1856 void wRefreshDesktop(WScreen
*scr
)
1859 XSetWindowAttributes attr
;
1861 attr
.backing_store
= NotUseful
;
1862 attr
.save_under
= False
;
1863 win
= XCreateWindow(dpy
, scr
->root_win
, 0, 0, scr
->scr_width
,
1864 scr
->scr_height
, 0, CopyFromParent
, CopyFromParent
,
1865 (Visual
*) CopyFromParent
, CWBackingStore
| CWSaveUnder
, &attr
);
1866 XMapRaised(dpy
, win
);
1867 XDestroyWindow(dpy
, win
);
1871 void wArrangeIcons(WScreen
*scr
, Bool arrangeAll
)
1877 const int heads
= wXineramaHeads(scr
);
1880 int pf
; /* primary axis */
1881 int sf
; /* secondary axis */
1885 int sx1
, sx2
, sy1
, sy2
; /* screen boundary */
1891 int isize
= wPreferences
.icon_size
;
1893 vars
= (struct HeadVars
*)wmalloc(sizeof(struct HeadVars
) * heads
);
1895 for (head
= 0; head
< heads
; ++head
) {
1896 WArea area
= wGetUsableAreaForHead(scr
, head
, NULL
, False
);
1900 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
1902 if (scr
->dock
->on_right_side
)
1908 rect
= wmkrect(area
.x1
, area
.y1
, area
.x2
- area
.x1
, area
.y2
- area
.y1
);
1910 vars
[head
].pi
= vars
[head
].si
= 0;
1911 vars
[head
].sx1
= rect
.pos
.x
;
1912 vars
[head
].sy1
= rect
.pos
.y
;
1913 vars
[head
].sw
= rect
.size
.width
;
1914 vars
[head
].sh
= rect
.size
.height
;
1915 vars
[head
].sx2
= vars
[head
].sx1
+ vars
[head
].sw
;
1916 vars
[head
].sy2
= vars
[head
].sy1
+ vars
[head
].sh
;
1917 vars
[head
].sw
= isize
* (vars
[head
].sw
/ isize
);
1918 vars
[head
].sh
= isize
* (vars
[head
].sh
/ isize
);
1919 vars
[head
].fullW
= (vars
[head
].sx2
- vars
[head
].sx1
) / isize
;
1920 vars
[head
].fullH
= (vars
[head
].sy2
- vars
[head
].sy1
) / isize
;
1922 /* icon yard boundaries */
1923 if (wPreferences
.icon_yard
& IY_VERT
) {
1924 vars
[head
].pf
= vars
[head
].fullH
;
1925 vars
[head
].sf
= vars
[head
].fullW
;
1927 vars
[head
].pf
= vars
[head
].fullW
;
1928 vars
[head
].sf
= vars
[head
].fullH
;
1930 if (wPreferences
.icon_yard
& IY_RIGHT
) {
1931 vars
[head
].xo
= vars
[head
].sx2
- isize
;
1934 vars
[head
].xo
= vars
[head
].sx1
;
1937 if (wPreferences
.icon_yard
& IY_TOP
) {
1938 vars
[head
].yo
= vars
[head
].sy1
;
1941 vars
[head
].yo
= vars
[head
].sy2
- isize
;
1946 #define X ((wPreferences.icon_yard & IY_VERT) \
1947 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1948 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1950 #define Y ((wPreferences.icon_yard & IY_VERT) \
1951 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1952 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1954 /* arrange application icons */
1955 aicon
= scr
->app_icon_list
;
1956 /* reverse them to avoid unnecessarily sliding of icons */
1957 while (aicon
&& aicon
->next
)
1958 aicon
= aicon
->next
;
1961 if (!aicon
->docked
) {
1962 /* CHECK: can icon be NULL here ? */
1963 /* The intention here is to place the AppIcon on the head that
1964 * contains most of the applications _main_ window. */
1965 head
= wGetHeadForWindow(aicon
->icon
->owner
);
1967 if (aicon
->x_pos
!= X
|| aicon
->y_pos
!= Y
) {
1968 #ifdef USE_ANIMATIONS
1969 if (!wPreferences
.no_animations
)
1970 slide_window(aicon
->icon
->core
->window
, aicon
->x_pos
, aicon
->y_pos
, X
, Y
);
1971 #endif /* USE_ANIMATIONS */
1973 wAppIconMove(aicon
, X
, Y
);
1975 if (vars
[head
].pi
>= vars
[head
].pf
) {
1980 aicon
= aicon
->prev
;
1983 /* arrange miniwindows */
1984 wwin
= scr
->focused_window
;
1985 /* reverse them to avoid unnecessarily shuffling */
1986 while (wwin
&& wwin
->prev
)
1990 if (wwin
->icon
&& wwin
->flags
.miniaturized
&& !wwin
->flags
.hidden
&&
1991 (wwin
->frame
->workspace
== scr
->current_workspace
||
1992 IS_OMNIPRESENT(wwin
) || wPreferences
.sticky_icons
)) {
1994 head
= wGetHeadForWindow(wwin
);
1996 if (arrangeAll
|| !wwin
->flags
.icon_moved
) {
1997 if (wwin
->icon_x
!= X
|| wwin
->icon_y
!= Y
)
1998 move_window(wwin
->icon
->core
->window
, wwin
->icon_x
, wwin
->icon_y
, X
, Y
);
2004 if (vars
[head
].pi
>= vars
[head
].pf
) {
2011 wwin
->flags
.icon_moved
= 0;
2012 /* we reversed the order, so we use next */
2019 void wSelectWindow(WWindow
*wwin
, Bool flag
)
2021 WScreen
*scr
= wwin
->screen_ptr
;
2024 wwin
->flags
.selected
= 1;
2025 if (wwin
->frame
->selected_border_pixel
)
2026 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->selected_border_pixel
);
2028 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->white_pixel
);
2030 if (!HAS_BORDER(wwin
))
2031 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, wwin
->screen_ptr
->frame_border_width
);
2033 if (!scr
->selected_windows
)
2034 scr
->selected_windows
= WMCreateArray(4);
2035 WMAddToArray(scr
->selected_windows
, wwin
);
2037 wwin
->flags
.selected
= 0;
2038 if (wwin
->flags
.focused
) {
2039 if (wwin
->frame
->focused_border_pixel
)
2040 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->focused_border_pixel
);
2042 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_focused_border_pixel
);
2044 if (wwin
->frame
->border_pixel
)
2045 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, *wwin
->frame
->border_pixel
);
2047 XSetWindowBorder(dpy
, wwin
->frame
->core
->window
, scr
->frame_border_pixel
);
2050 if (!HAS_BORDER(wwin
))
2051 XSetWindowBorderWidth(dpy
, wwin
->frame
->core
->window
, 0);
2053 if (scr
->selected_windows
)
2054 WMRemoveFromArray(scr
->selected_windows
, wwin
);
2058 void wMakeWindowVisible(WWindow
*wwin
)
2060 if (wwin
->frame
->workspace
!= wwin
->screen_ptr
->current_workspace
)
2061 wWorkspaceChange(wwin
->screen_ptr
, wwin
->frame
->workspace
);
2063 if (wwin
->flags
.shaded
)
2064 wUnshadeWindow(wwin
);
2066 if (wwin
->flags
.hidden
) {
2069 app
= wApplicationOf(wwin
->main_window
);
2071 /* trick to get focus to this window */
2072 app
->last_focused
= wwin
;
2073 wUnhideApplication(app
, False
, False
);
2076 if (wwin
->flags
.miniaturized
) {
2077 wDeiconifyWindow(wwin
);
2079 if (!WFLAGP(wwin
, no_focusable
))
2080 wSetFocusTo(wwin
->screen_ptr
, wwin
);
2081 wRaiseFrame(wwin
->frame
->core
);
2085 void movePionterToWindowCenter(WWindow
*wwin
)
2087 if (!wPreferences
.pointer_with_half_max_windows
)
2090 XSelectInput(dpy
, wwin
->client_win
, wwin
->event_mask
);
2091 XWarpPointer(dpy
, None
, wwin
->screen_ptr
->root_win
, 0, 0, 0, 0,
2092 wwin
->frame_x
+ wwin
->client
.width
/ 2,
2093 wwin
->frame_y
+ wwin
->client
.height
/ 2);
2098 * Do the animation while shading (called with what = SHADE)
2099 * or unshading (what = UNSHADE).
2101 #ifdef USE_ANIMATIONS
2102 static void shade_animate(WWindow
*wwin
, Bool what
)
2105 time_t time0
= time(NULL
);
2107 if (wwin
->flags
.skip_next_animation
|| wPreferences
.no_animations
)
2112 if (!wwin
->screen_ptr
->flags
.startup
) {
2113 /* do the shading animation */
2114 h
= wwin
->frame
->core
->height
;
2115 s
= h
/ SHADE_STEPS
;
2118 w
= wwin
->frame
->core
->width
;
2119 y
= wwin
->frame
->top_width
;
2120 while (h
> wwin
->frame
->top_width
+ 1) {
2121 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2122 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2125 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2128 if (SHADE_DELAY
> 0)
2129 wusleep(SHADE_DELAY
* 1000L);
2135 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);
2140 h
= wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
;
2141 y
= wwin
->frame
->top_width
- wwin
->client
.height
;
2142 s
= abs(y
) / SHADE_STEPS
;
2145 w
= wwin
->frame
->core
->width
;
2146 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2148 while (h
< wwin
->client
.height
+ wwin
->frame
->top_width
+ wwin
->frame
->bottom_width
) {
2149 XResizeWindow(dpy
, wwin
->frame
->core
->window
, w
, h
);
2150 XMoveWindow(dpy
, wwin
->client_win
, 0, y
);
2152 if (SHADE_DELAY
> 0)
2153 wusleep(SHADE_DELAY
* 2000L / 3);
2159 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
2163 XMoveWindow(dpy
, wwin
->client_win
, 0, wwin
->frame
->top_width
);