New option for enabling alternative half-maximized window movement.
[wmaker-crm.git] / src / actions.c
blob119f5ecfa6e744d8aa9a7752512c1664ad8340b1
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.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "framewin.h"
36 #include "window.h"
37 #include "client.h"
38 #include "icon.h"
39 #include "colormap.h"
40 #include "application.h"
41 #include "actions.h"
42 #include "stacking.h"
43 #include "appicon.h"
44 #include "dock.h"
45 #include "appmenu.h"
46 #include "winspector.h"
47 #include "workspace.h"
48 #include "xinerama.h"
49 #include "usermenu.h"
50 #include "placement.h"
51 #include "misc.h"
52 #include "event.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)))
60 #endif
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 *******/
67 #ifdef USE_ANIMATIONS
68 static struct {
69 int steps;
70 int delay;
71 } shadePars[5] = {
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
81 #endif
83 #define UNSHADE 0
84 #define SHADE 1
86 static int compareTimes(Time t1, Time t2)
88 Time diff;
89 if (t1 == t2)
90 return 0;
91 diff = t1 - t2;
92 return (diff < 60000) ? 1 : -1;
95 #ifdef USE_ANIMATIONS
96 static void shade_animate(WWindow *wwin, Bool what);
97 #else
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
104 (void) wwin;
105 (void) what;
107 #endif
110 *----------------------------------------------------------------------
111 * wSetFocusTo--
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
115 * unfocused.
117 * Side effects:
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;
130 int wasfocused;
132 if (scr->flags.ignore_focus_events || compareTimes(w_global.timestamp.focus_change, timestamp) > 0)
133 return;
135 if (!old_scr)
136 old_scr = scr;
138 old_focused = old_scr->focused_window;
140 w_global.timestamp.focus_change = timestamp;
142 if (old_focused)
143 oapp = wApplicationOf(old_focused->main_window);
145 if (wwin == NULL) {
146 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
147 if (old_focused)
148 wWindowUnfocus(old_focused);
150 if (oapp) {
151 wAppMenuUnmap(oapp->menu);
152 if (wPreferences.highlight_active_app)
153 wApplicationDeactivate(oapp);
156 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
157 return;
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 */
167 if (napp)
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) {
177 case WFM_NO_INPUT:
178 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
179 break;
180 case WFM_PASSIVE:
181 case WFM_LOCALLY_ACTIVE:
182 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
183 break;
184 case WFM_GLOBALLY_ACTIVE:
185 break;
188 XFlush(dpy);
189 if (wwin->protocols.TAKE_FOCUS)
190 wClientSendProtocol(wwin, w_global.atom.wm.take_focus, timestamp);
192 XSync(dpy, False);
193 } else {
194 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
197 if (WFLAGP(wwin, no_focusable))
198 return;
200 /* if this is not the focused window focus it */
201 if (focused != wwin) {
202 /* change the focus window list order */
203 if (wwin->prev)
204 wwin->prev->next = wwin->next;
206 if (wwin->next)
207 wwin->next->prev = wwin->prev;
209 wwin->prev = focused;
210 focused->next = wwin;
211 wwin->next = NULL;
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) {
228 #ifdef USER_MENU
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);
239 XFlush(dpy);
240 old_scr = scr;
243 void wShadeWindow(WWindow *wwin)
246 if (wwin->flags.shaded)
247 return;
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();
277 #endif
280 void wUnshadeWindow(WWindow *wwin)
283 if (!wwin->flags.shaded)
284 return;
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
300 * shading */
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;
329 int old_head;
330 Bool same_head;
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)
347 return;
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)))
353 return;
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;
365 int new_x = 0;
366 int new_y = 0;
367 int maximus_x = 0;
368 int maximus_y = 0;
369 unsigned int maximus_width = 0;
370 unsigned int maximus_height = 0;
371 WArea usableArea, totalArea;
372 Bool has_border = 1;
373 int adj_size;
374 WScreen *scr = wwin->screen_ptr;
376 if (!IS_RESIZABLE(wwin))
377 return;
379 if (!HAS_BORDER(wwin))
380 has_border = 0;
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;
394 totalArea.x1 = 0;
395 totalArea.y1 = 0;
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;
423 new_x = maximus_x;
424 new_y = maximus_y;
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;
433 } else {
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);
501 int dest_head = -1;
503 if (!effective) {
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.move_half_max_between_heads) {
510 /* Select windows, which are only horizontally or vertically
511 * maximized. Quarters cannot be handled here, since there is not
512 * clear on which direction user intend to move such window. */
513 if (current & (MAX_VERTICAL | MAX_HORIZONTAL)) {
514 if (requested & MAX_LEFTHALF && current & MAX_LEFTHALF) {
515 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
516 head, DIRECTION_LEFT);
517 if (dest_head != -1) {
518 effective |= MAX_RIGHTHALF;
519 effective |= MAX_VERTICAL;
520 effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
522 } else if (requested & MAX_RIGHTHALF &&
523 current & MAX_RIGHTHALF) {
524 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
525 head, DIRECTION_RIGHT);
526 if (dest_head != -1) {
527 effective |= MAX_LEFTHALF;
528 effective |= MAX_VERTICAL;
529 effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
531 } else if (requested & MAX_TOPHALF && current & MAX_TOPHALF) {
532 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
533 head, DIRECTION_UP);
534 if (dest_head != -1) {
535 effective |= MAX_BOTTOMHALF;
536 effective |= MAX_HORIZONTAL;
537 effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
539 } else if (requested & MAX_BOTTOMHALF &&
540 current & MAX_BOTTOMHALF) {
541 dest_head = wGetHeadRelativeToCurrentHead(wwin->screen_ptr,
542 head, DIRECTION_DOWN);
543 if (dest_head != -1) {
544 effective |= MAX_TOPHALF;
545 effective |= MAX_HORIZONTAL;
546 effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
548 } if (dest_head != -1)
549 /* tell wMaximizeWindow that we were using keyboard, not
550 * mouse, so that it will use calculated head as
551 * destination for move_half_max_between_heads feature,
552 * not from mouse pointer */
553 wMaximizeWindow(wwin, (effective | flags | MAX_KEYBOARD),
554 dest_head);
555 else
556 wUnmaximizeWindow(wwin);
557 } else
558 wUnmaximizeWindow(wwin);
559 } else
560 wUnmaximizeWindow(wwin);
561 /* these alone mean vertical|horizontal toggle */
562 } else if ((effective == MAX_LEFTHALF) ||
563 (effective == MAX_RIGHTHALF) ||
564 (effective == MAX_TOPHALF) ||
565 (effective == MAX_BOTTOMHALF))
566 wUnmaximizeWindow(wwin);
567 else {
568 if ((requested == (MAX_HORIZONTAL | MAX_VERTICAL)) ||
569 (requested == MAX_MAXIMUS))
570 effective = requested;
571 else {
572 if (requested & MAX_LEFTHALF) {
573 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
574 effective |= MAX_VERTICAL;
575 else
576 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
577 effective |= MAX_LEFTHALF;
578 effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
579 } else if (requested & MAX_RIGHTHALF) {
580 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
581 effective |= MAX_VERTICAL;
582 else
583 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
584 effective |= MAX_RIGHTHALF;
585 effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
587 if (requested & MAX_TOPHALF) {
588 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
589 effective |= MAX_HORIZONTAL;
590 else
591 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
592 effective |= MAX_TOPHALF;
593 effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
594 } else if (requested & MAX_BOTTOMHALF) {
595 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
596 effective |= MAX_HORIZONTAL;
597 else
598 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
599 effective |= MAX_BOTTOMHALF;
600 effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
602 if (requested & MAX_HORIZONTAL)
603 effective &= ~(MAX_LEFTHALF | MAX_RIGHTHALF);
604 if (requested & MAX_VERTICAL)
605 effective &= ~(MAX_TOPHALF | MAX_BOTTOMHALF);
606 effective &= ~MAX_MAXIMUS;
608 wMaximizeWindow(wwin, effective | flags, head);
612 /* the window boundary coordinates */
613 typedef struct {
614 int left;
615 int right;
616 int bottom;
617 int top;
618 int width;
619 int height;
620 } win_coords;
622 static void set_window_coords(WWindow *wwin, win_coords *obs)
624 obs->left = wwin->frame_x;
625 obs->top = wwin->frame_y;
626 obs->width = wwin->frame->core->width;
627 obs->height = wwin->frame->core->height;
628 obs->bottom = obs->top + obs->height;
629 obs->right = obs->left + obs->width;
633 * Maximus: tiled maximization (maximize without overlapping other windows)
635 * The original window 'orig' will be maximized to new coordinates 'new'.
636 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
638 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
639 unsigned int *new_width, unsigned int *new_height)
641 WWindow *tmp;
642 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
643 short int adjust_height;
644 int x_intsect, y_intsect;
645 /* the obstructing, original and new windows */
646 win_coords obs, orig, new;
648 /* set the original coordinate positions of the window to be Maximumized */
649 if (wwin->flags.maximized) {
650 /* window is already maximized; consider original geometry */
651 remember_geometry(wwin, &orig.left, &orig.top, &orig.width, &orig.height);
652 orig.bottom = orig.top + orig.height;
653 orig.right = orig.left + orig.width;
654 } else
655 set_window_coords(wwin, &orig);
657 /* Try to fully maximize first, then readjust later */
658 new.left = usableArea.x1;
659 new.right = usableArea.x2;
660 new.top = usableArea.y1;
661 new.bottom = usableArea.y2;
663 if (HAS_TITLEBAR(wwin))
664 tbar_height_0 = TITLEBAR_HEIGHT;
665 if (HAS_RESIZEBAR(wwin))
666 rbar_height_0 = RESIZEBAR_HEIGHT;
667 if (HAS_BORDER(wwin))
668 bd_width_0 = wwin->screen_ptr->frame_border_width;
670 /* the length to be subtracted if the window has titlebar, etc */
671 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
673 tmp = wwin;
674 /* The focused window is always the last in the list */
675 while (tmp->prev) {
676 /* ignore windows in other workspaces etc */
677 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
678 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
679 tmp = tmp->prev;
680 continue;
682 tmp = tmp->prev;
684 /* Set the coordinates of obstructing window */
685 set_window_coords(tmp, &obs);
687 /* Try to maximize in the y direction first */
688 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
689 if (x_intsect != 0) {
690 /* TODO: Consider the case when coords are equal */
691 if (obs.bottom < orig.top && obs.bottom > new.top) {
692 /* w_0 is below the bottom of w_j */
693 new.top = obs.bottom + 1;
695 if (orig.bottom < obs.top && obs.top < new.bottom) {
696 /* The bottom of w_0 is above the top of w_j */
697 new.bottom = obs.top - 1;
702 tmp = wwin;
703 while (tmp->prev) {
704 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
705 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
706 tmp = tmp->prev;
707 continue;
709 tmp = tmp->prev;
711 set_window_coords(tmp, &obs);
714 * Use the new.top and new.height instead of original values
715 * as they may have different intersections with the obstructing windows
717 new.height = new.bottom - new.top - adjust_height;
718 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
719 if (y_intsect != 0) {
720 if (obs.right < orig.left && obs.right > new.left) {
721 /* w_0 is completely to the right of w_j */
722 new.left = obs.right + 1;
724 if (orig.right < obs.left && obs.left < new.right) {
725 /* w_0 is completely to the left of w_j */
726 new.right = obs.left - 1;
731 *new_x = new.left;
732 *new_y = new.top;
733 /* xcalc needs -7 here, but other apps don't */
734 *new_height = new.bottom - new.top - adjust_height - 1;
735 *new_width = new.right - new.left;
738 void wUnmaximizeWindow(WWindow *wwin)
740 int x, y, w, h;
742 if (!wwin->flags.maximized)
743 return;
745 if (wwin->flags.shaded) {
746 wwin->flags.skip_next_animation = 1;
747 wUnshadeWindow(wwin);
750 if (wPreferences.drag_maximized_window == DRAGMAX_NOMOVE)
751 wwin->client_flags.no_movable = 0;
753 /* Use old coordinates if they are set, current values otherwise */
754 remember_geometry(wwin, &x, &y, &w, &h);
756 /* unMaximusize relative to original position */
757 if (wwin->flags.maximized & MAX_MAXIMUS) {
758 x += wwin->frame_x - wwin->maximus_x;
759 y += wwin->frame_y - wwin->maximus_y;
762 wwin->flags.maximized = 0;
763 wwin->flags.old_maximized = 0;
764 wWindowConfigure(wwin, x, y, w, h);
765 wWindowSynthConfigureNotify(wwin);
767 WMPostNotificationName(WMNChangedState, wwin, "maximize");
770 void wFullscreenWindow(WWindow *wwin)
772 int head;
773 WMRect rect;
775 if (wwin->flags.fullscreen)
776 return;
778 wwin->flags.fullscreen = True;
780 wWindowConfigureBorders(wwin);
782 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
784 wwin->bfs_geometry.x = wwin->frame_x;
785 wwin->bfs_geometry.y = wwin->frame_y;
786 wwin->bfs_geometry.width = wwin->frame->core->width;
787 wwin->bfs_geometry.height = wwin->frame->core->height;
789 head = wGetHeadForWindow(wwin);
790 rect = wGetRectForHead(wwin->screen_ptr, head);
791 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
793 wwin->screen_ptr->bfs_focused_window = wwin->screen_ptr->focused_window;
794 wSetFocusTo(wwin->screen_ptr, wwin);
796 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
799 void wUnfullscreenWindow(WWindow *wwin)
801 if (!wwin->flags.fullscreen)
802 return;
804 wwin->flags.fullscreen = False;
806 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
807 if (WFLAGP(wwin, sunken)) {
808 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
809 } else if (WFLAGP(wwin, floating)) {
810 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
811 } else {
812 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
816 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
817 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
819 wWindowConfigureBorders(wwin);
821 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
822 wFrameWindowPaint(wwin->frame);
825 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
827 if (wwin->screen_ptr->bfs_focused_window) {
828 wSetFocusTo(wwin->screen_ptr, wwin->screen_ptr->bfs_focused_window);
829 wwin->screen_ptr->bfs_focused_window = NULL;
833 #ifdef USE_ANIMATIONS
834 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
836 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
837 float cx, cy, cw, ch;
838 float xstep, ystep, wstep, hstep;
839 XPoint points[5];
840 float dx, dch, midy;
841 float angle, final_angle, delta;
843 xstep = (float)(fx - x) / steps;
844 ystep = (float)(fy - y) / steps;
845 wstep = (float)(fw - w) / steps;
846 hstep = (float)(fh - h) / steps;
848 cx = (float)x;
849 cy = (float)y;
850 cw = (float)w;
851 ch = (float)h;
853 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
854 delta = (float)(final_angle / FRAMES);
855 for (angle = 0;; angle += delta) {
856 if (angle > final_angle)
857 angle = final_angle;
859 dx = (cw / 10) - ((cw / 5) * sinf(angle));
860 dch = (ch / 2) * cosf(angle);
861 midy = cy + (ch / 2);
863 points[0].x = cx + dx;
864 points[0].y = midy - dch;
865 points[1].x = cx + cw - dx;
866 points[1].y = points[0].y;
867 points[2].x = cx + cw + dx;
868 points[2].y = midy + dch;
869 points[3].x = cx - dx;
870 points[3].y = points[2].y;
871 points[4].x = points[0].x;
872 points[4].y = points[0].y;
874 XGrabServer(dpy);
875 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
876 XFlush(dpy);
877 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
879 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
880 XUngrabServer(dpy);
881 cx += xstep;
882 cy += ystep;
883 cw += wstep;
884 ch += hstep;
885 if (angle >= final_angle)
886 break;
889 XFlush(dpy);
892 #undef FRAMES
894 static void
895 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
897 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
898 float cx, cy, cw, ch;
899 float xstep, ystep, wstep, hstep;
900 XPoint points[5];
901 float angle, final_angle, a, d, delta;
903 x += w / 2;
904 y += h / 2;
905 fx += fw / 2;
906 fy += fh / 2;
908 xstep = (float)(fx - x) / steps;
909 ystep = (float)(fy - y) / steps;
910 wstep = (float)(fw - w) / steps;
911 hstep = (float)(fh - h) / steps;
913 cx = (float)x;
914 cy = (float)y;
915 cw = (float)w;
916 ch = (float)h;
918 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
919 delta = (float)(final_angle / FRAMES);
920 for (angle = 0;; angle += delta) {
921 if (angle > final_angle)
922 angle = final_angle;
924 a = atan2f(ch, cw);
925 d = sqrtf((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
927 points[0].x = cx + cosf(angle - a) * d;
928 points[0].y = cy + sinf(angle - a) * d;
929 points[1].x = cx + cosf(angle + a) * d;
930 points[1].y = cy + sinf(angle + a) * d;
931 points[2].x = cx + cosf(angle - a + (float)WM_PI) * d;
932 points[2].y = cy + sinf(angle - a + (float)WM_PI) * d;
933 points[3].x = cx + cosf(angle + a + (float)WM_PI) * d;
934 points[3].y = cy + sinf(angle + a + (float)WM_PI) * d;
935 points[4].x = cx + cosf(angle - a) * d;
936 points[4].y = cy + sinf(angle - a) * d;
937 XGrabServer(dpy);
938 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
939 XFlush(dpy);
940 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
942 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
943 XUngrabServer(dpy);
944 cx += xstep;
945 cy += ystep;
946 cw += wstep;
947 ch += hstep;
948 if (angle >= final_angle)
949 break;
952 XFlush(dpy);
955 #undef FRAMES
957 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
959 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
960 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
961 float xstep, ystep, wstep, hstep;
962 int i, j;
964 xstep = (float)(fx - x) / steps;
965 ystep = (float)(fy - y) / steps;
966 wstep = (float)(fw - w) / steps;
967 hstep = (float)(fh - h) / steps;
969 for (j = 0; j < FRAMES; j++) {
970 cx[j] = (float)x;
971 cy[j] = (float)y;
972 cw[j] = (float)w;
973 ch[j] = (float)h;
975 XGrabServer(dpy);
976 for (i = 0; i < steps; i++) {
977 for (j = 0; j < FRAMES; j++) {
978 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
979 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
981 XFlush(dpy);
982 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
984 for (j = 0; j < FRAMES; j++) {
985 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
986 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
987 if (j < FRAMES - 1) {
988 cx[j] = cx[j + 1];
989 cy[j] = cy[j + 1];
990 cw[j] = cw[j + 1];
991 ch[j] = ch[j + 1];
992 } else {
993 cx[j] += xstep;
994 cy[j] += ystep;
995 cw[j] += wstep;
996 ch[j] += hstep;
1001 for (j = 0; j < FRAMES; j++)
1002 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
1003 XFlush(dpy);
1004 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
1006 for (j = 0; j < FRAMES; j++)
1007 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
1009 XUngrabServer(dpy);
1012 #undef FRAMES
1014 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
1016 int style = wPreferences.iconification_style; /* Catch the value */
1017 int steps;
1019 if (style == WIS_NONE)
1020 return;
1022 if (style == WIS_RANDOM)
1023 style = rand() % 3;
1025 switch (style) {
1026 case WIS_TWIST:
1027 steps = MINIATURIZE_ANIMATION_STEPS_T;
1028 if (steps > 0)
1029 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
1030 break;
1031 case WIS_FLIP:
1032 steps = MINIATURIZE_ANIMATION_STEPS_F;
1033 if (steps > 0)
1034 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
1035 break;
1036 case WIS_ZOOM:
1037 default:
1038 steps = MINIATURIZE_ANIMATION_STEPS_Z;
1039 if (steps > 0)
1040 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
1041 break;
1044 #endif /* USE_ANIMATIONS */
1046 static void flushExpose(void)
1048 XEvent tmpev;
1050 while (XCheckTypedEvent(dpy, Expose, &tmpev))
1051 WMHandleEvent(&tmpev);
1052 XSync(dpy, 0);
1055 static void unmapTransientsFor(WWindow *wwin)
1057 WWindow *tmp;
1059 tmp = wwin->screen_ptr->focused_window;
1060 while (tmp) {
1061 /* unmap the transients for this transient */
1062 if (tmp != wwin && tmp->transient_for == wwin->client_win
1063 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
1064 unmapTransientsFor(tmp);
1065 tmp->flags.miniaturized = 1;
1066 if (!tmp->flags.shaded)
1067 wWindowUnmap(tmp);
1068 else
1069 XUnmapWindow(dpy, tmp->frame->core->window);
1071 if (!tmp->flags.shaded)
1073 wClientSetState(tmp, IconicState, None);
1075 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1077 tmp = tmp->prev;
1081 static void mapTransientsFor(WWindow *wwin)
1083 WWindow *tmp;
1085 tmp = wwin->screen_ptr->focused_window;
1086 while (tmp) {
1087 /* recursively map the transients for this transient */
1088 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
1089 && tmp->icon == NULL) {
1090 mapTransientsFor(tmp);
1091 tmp->flags.miniaturized = 0;
1092 if (!tmp->flags.shaded)
1093 wWindowMap(tmp);
1094 else
1095 XMapWindow(dpy, tmp->frame->core->window);
1096 tmp->flags.semi_focused = 0;
1098 if (!tmp->flags.shaded)
1100 wClientSetState(tmp, NormalState, None);
1102 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1104 tmp = tmp->prev;
1108 static WWindow *recursiveTransientFor(WWindow *wwin)
1110 int i;
1112 if (!wwin)
1113 return None;
1115 /* hackish way to detect transient_for cycle */
1116 i = wwin->screen_ptr->window_count + 1;
1118 while (wwin && wwin->transient_for != None && i > 0) {
1119 wwin = wWindowFor(wwin->transient_for);
1120 i--;
1122 if (i == 0 && wwin) {
1123 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1124 wwin->frame->title);
1125 return NULL;
1128 return wwin;
1131 #ifdef USE_ANIMATIONS
1132 static int getAnimationGeometry(WWindow *wwin, int *ix, int *iy, int *iw, int *ih)
1134 if (wwin->screen_ptr->flags.startup || wPreferences.no_animations
1135 || wwin->flags.skip_next_animation || wwin->icon == NULL)
1136 return 0;
1138 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1139 *ix = wwin->icon_x;
1140 *iy = wwin->icon_y;
1141 *iw = wwin->icon->core->width;
1142 *ih = wwin->icon->core->height;
1143 } else {
1144 if (wwin->flags.net_handle_icon) {
1145 *ix = wwin->icon_x;
1146 *iy = wwin->icon_y;
1147 *iw = wwin->icon_w;
1148 *ih = wwin->icon_h;
1149 } else {
1150 *ix = 0;
1151 *iy = 0;
1152 *iw = wwin->screen_ptr->scr_width;
1153 *ih = wwin->screen_ptr->scr_height;
1156 return 1;
1158 #endif /* USE_ANIMATIONS */
1160 void wIconifyWindow(WWindow *wwin)
1162 XWindowAttributes attribs;
1163 int present;
1165 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs))
1166 return; /* the window doesn't exist anymore */
1168 if (wwin->flags.miniaturized)
1169 return; /* already miniaturized */
1171 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1172 WWindow *owner = wWindowFor(wwin->transient_for);
1174 if (owner && owner->flags.miniaturized)
1175 return;
1178 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
1180 /* if the window is in another workspace, simplify process */
1181 if (present) {
1182 /* icon creation may take a while */
1183 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
1184 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
1185 GrabModeAsync, None, None, CurrentTime);
1188 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1189 if (!wwin->flags.icon_moved)
1190 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
1192 wwin->icon = icon_create_for_wwindow(wwin);
1193 wwin->icon->mapped = 1;
1195 /* extract the window screenshot every time, as the option can be enable anytime */
1196 if (wwin->client_win && wwin->flags.mapped) {
1197 RImage *mini_preview;
1198 XImage *pimg;
1199 unsigned int w, h;
1200 int x, y;
1201 Window baz;
1203 XRaiseWindow(dpy, wwin->frame->core->window);
1204 XTranslateCoordinates(dpy, wwin->client_win, wwin->screen_ptr->root_win, 0, 0, &x, &y, &baz);
1206 w = attribs.width;
1207 h = attribs.height;
1209 if (x - attribs.x + attribs.width > wwin->screen_ptr->scr_width)
1210 w = wwin->screen_ptr->scr_width - x + attribs.x;
1212 if (y - attribs.y + attribs.height > wwin->screen_ptr->scr_height)
1213 h = wwin->screen_ptr->scr_height - y + attribs.y;
1215 pimg = XGetImage(dpy, wwin->client_win, 0, 0, w, h, AllPlanes, ZPixmap);
1216 if (pimg) {
1217 mini_preview = RCreateImageFromXImage(wwin->screen_ptr->rcontext, pimg, NULL);
1218 XDestroyImage(pimg);
1220 if (mini_preview) {
1221 set_icon_minipreview(wwin->icon, mini_preview);
1222 RReleaseImage(mini_preview);
1223 } else {
1224 const char *title;
1225 char title_buf[32];
1227 if (wwin->frame->title) {
1228 title = wwin->frame->title;
1229 } else {
1230 snprintf(title_buf, sizeof(title_buf), "(id=0x%lx)", wwin->client_win);
1231 title = title_buf;
1233 wwarning(_("creation of mini-preview failed for window \"%s\""), title);
1239 wwin->flags.miniaturized = 1;
1240 wwin->flags.mapped = 0;
1242 /* unmap transients */
1243 unmapTransientsFor(wwin);
1245 if (present) {
1246 #ifdef USE_ANIMATIONS
1247 int ix, iy, iw, ih;
1248 #endif
1249 XUngrabPointer(dpy, CurrentTime);
1250 wWindowUnmap(wwin);
1251 /* let all Expose events arrive so that we can repaint
1252 * something before the animation starts (and the server is grabbed) */
1253 XSync(dpy, 0);
1255 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1256 wClientSetState(wwin, IconicState, None);
1257 else
1258 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1260 flushExpose();
1261 #ifdef USE_ANIMATIONS
1262 if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih))
1263 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1264 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1265 #endif
1268 wwin->flags.skip_next_animation = 0;
1270 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1271 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1272 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1273 XMapWindow(dpy, wwin->icon->core->window);
1275 AddToStackList(wwin->icon->core);
1276 wLowerFrame(wwin->icon->core);
1279 if (present) {
1280 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1283 * It doesn't seem to be working and causes button event hangup
1284 * when deiconifying a transient window.
1285 setupIconGrabs(wwin->icon);
1287 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1288 && wPreferences.focus_mode == WKF_CLICK) {
1289 WWindow *tmp;
1291 tmp = wwin->prev;
1292 while (tmp) {
1293 if (!WFLAGP(tmp, no_focusable)
1294 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1295 && (wwin->frame->workspace == tmp->frame->workspace))
1296 break;
1297 tmp = tmp->prev;
1299 wSetFocusTo(wwin->screen_ptr, tmp);
1300 } else if (wPreferences.focus_mode != WKF_CLICK) {
1301 wSetFocusTo(wwin->screen_ptr, NULL);
1303 #ifdef USE_ANIMATIONS
1304 if (!wwin->screen_ptr->flags.startup) {
1305 /* Catch up with events not processed while animation was running */
1306 Window clientwin = wwin->client_win;
1308 ProcessPendingEvents();
1310 /* the window can disappear while ProcessPendingEvents() runs */
1311 if (!wWindowFor(clientwin))
1312 return;
1314 #endif
1317 /* maybe we want to do this regardless of net_handle_icon
1318 * it seems to me we might break behaviour this way.
1320 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1321 && !wwin->flags.net_handle_icon)
1322 wIconSelect(wwin->icon);
1324 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1326 if (wPreferences.auto_arrange_icons)
1327 wArrangeIcons(wwin->screen_ptr, True);
1330 void wDeiconifyWindow(WWindow *wwin)
1332 /* Let's avoid changing workspace while deiconifying */
1333 w_global.ignore_workspace_change = True;
1335 /* we're hiding for show_desktop */
1336 int netwm_hidden = wwin->flags.net_show_desktop &&
1337 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1339 if (!netwm_hidden)
1340 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1342 if (!wwin->flags.miniaturized) {
1343 w_global.ignore_workspace_change = False;
1344 return;
1347 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1348 WWindow *owner = recursiveTransientFor(wwin);
1350 if (owner && owner->flags.miniaturized) {
1351 wDeiconifyWindow(owner);
1352 wSetFocusTo(wwin->screen_ptr, wwin);
1353 wRaiseFrame(wwin->frame->core);
1354 w_global.ignore_workspace_change = False;
1355 return;
1359 wwin->flags.miniaturized = 0;
1361 if (!netwm_hidden && !wwin->flags.shaded)
1362 wwin->flags.mapped = 1;
1364 if (!netwm_hidden || wPreferences.sticky_icons) {
1365 /* maybe we want to do this regardless of net_handle_icon
1366 * it seems to me we might break behaviour this way.
1368 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1369 && wwin->icon != NULL) {
1370 if (wwin->icon->selected)
1371 wIconSelect(wwin->icon);
1373 XUnmapWindow(dpy, wwin->icon->core->window);
1377 /* if the window is in another workspace, do it silently */
1378 if (!netwm_hidden) {
1379 #ifdef USE_ANIMATIONS
1380 int ix, iy, iw, ih;
1381 if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih))
1382 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1383 wwin->frame_x, wwin->frame_y,
1384 wwin->frame->core->width, wwin->frame->core->height);
1385 #endif
1386 wwin->flags.skip_next_animation = 0;
1387 XGrabServer(dpy);
1388 if (!wwin->flags.shaded)
1389 XMapWindow(dpy, wwin->client_win);
1391 XMapWindow(dpy, wwin->frame->core->window);
1392 wRaiseFrame(wwin->frame->core);
1393 if (!wwin->flags.shaded)
1394 wClientSetState(wwin, NormalState, None);
1396 mapTransientsFor(wwin);
1399 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1400 && !wwin->flags.net_handle_icon) {
1401 RemoveFromStackList(wwin->icon->core);
1402 wSetFocusTo(wwin->screen_ptr, wwin);
1403 wIconDestroy(wwin->icon);
1404 wwin->icon = NULL;
1407 if (!netwm_hidden) {
1408 XUngrabServer(dpy);
1410 wSetFocusTo(wwin->screen_ptr, wwin);
1412 #ifdef USE_ANIMATIONS
1413 if (!wwin->screen_ptr->flags.startup) {
1414 /* Catch up with events not processed while animation was running */
1415 Window clientwin = wwin->client_win;
1417 ProcessPendingEvents();
1419 /* the window can disappear while ProcessPendingEvents() runs */
1420 if (!wWindowFor(clientwin)) {
1421 w_global.ignore_workspace_change = False;
1422 return;
1425 #endif
1428 if (wPreferences.auto_arrange_icons)
1429 wArrangeIcons(wwin->screen_ptr, True);
1431 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1433 /* In case we were shaded and iconified, also unshade */
1434 if (!netwm_hidden)
1435 wUnshadeWindow(wwin);
1437 w_global.ignore_workspace_change = False;
1440 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1442 if (wwin->flags.miniaturized) {
1443 if (wwin->icon) {
1444 XUnmapWindow(dpy, wwin->icon->core->window);
1445 wwin->icon->mapped = 0;
1447 wwin->flags.hidden = 1;
1449 WMPostNotificationName(WMNChangedState, wwin, "hide");
1450 return;
1453 if (wwin->flags.inspector_open)
1454 wHideInspectorForWindow(wwin);
1456 wwin->flags.hidden = 1;
1457 wWindowUnmap(wwin);
1459 wClientSetState(wwin, IconicState, icon->icon_win);
1460 flushExpose();
1462 #ifdef USE_ANIMATIONS
1463 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1464 !wwin->flags.skip_next_animation && animate) {
1465 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1466 wwin->frame->core->width, wwin->frame->core->height,
1467 icon_x, icon_y, icon->core->width, icon->core->height);
1469 #else
1470 /* Tell the compiler it is normal that those parameters are not used in this case */
1471 (void) icon_x;
1472 (void) icon_y;
1473 (void) animate;
1474 #endif
1475 wwin->flags.skip_next_animation = 0;
1477 WMPostNotificationName(WMNChangedState, wwin, "hide");
1480 void wHideAll(WScreen *scr)
1482 WWindow *wwin;
1483 WWindow **windows;
1484 WMenu *menu;
1485 unsigned int wcount = 0;
1486 int i;
1488 if (!scr)
1489 return;
1491 menu = scr->switch_menu;
1493 windows = wmalloc(sizeof(WWindow *));
1495 if (menu != NULL) {
1496 for (i = 0; i < menu->entry_no; i++) {
1497 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1498 wcount++;
1499 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1501 } else {
1502 wwin = scr->focused_window;
1504 while (wwin) {
1505 windows[wcount] = wwin;
1506 wcount++;
1507 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1508 wwin = wwin->prev;
1513 for (i = 0; i < wcount; i++) {
1514 wwin = windows[i];
1515 if (wwin->frame->workspace == scr->current_workspace
1516 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1517 && !wwin->flags.internal_window
1518 && !WFLAGP(wwin, no_miniaturizable)
1520 wwin->flags.skip_next_animation = 1;
1521 wIconifyWindow(wwin);
1525 wfree(windows);
1528 void wHideOtherApplications(WWindow *awin)
1530 WWindow *wwin;
1531 WApplication *tapp;
1533 if (!awin)
1534 return;
1535 wwin = awin->screen_ptr->focused_window;
1537 while (wwin) {
1538 if (wwin != awin
1539 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1540 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1541 && !wwin->flags.internal_window
1542 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1544 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1545 if (!WFLAGP(wwin, no_miniaturizable)) {
1546 wwin->flags.skip_next_animation = 1;
1547 wIconifyWindow(wwin);
1549 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1550 tapp = wApplicationOf(wwin->main_window);
1551 if (tapp) {
1552 tapp->flags.skip_next_animation = 1;
1553 wHideApplication(tapp);
1554 } else {
1555 if (!WFLAGP(wwin, no_miniaturizable)) {
1556 wwin->flags.skip_next_animation = 1;
1557 wIconifyWindow(wwin);
1562 wwin = wwin->prev;
1565 wSetFocusTo(awin->screen_ptr, awin);
1569 void wHideApplication(WApplication *wapp)
1571 WScreen *scr;
1572 WWindow *wlist;
1573 int hadfocus;
1574 int animate;
1576 if (!wapp) {
1577 wwarning("trying to hide a non grouped window");
1578 return;
1580 if (!wapp->main_window_desc) {
1581 wwarning("group leader not found for window group");
1582 return;
1584 scr = wapp->main_window_desc->screen_ptr;
1585 hadfocus = 0;
1586 wlist = scr->focused_window;
1587 if (!wlist)
1588 return;
1590 if (wlist->main_window == wapp->main_window)
1591 wapp->last_focused = wlist;
1592 else
1593 wapp->last_focused = NULL;
1595 animate = !wapp->flags.skip_next_animation;
1597 while (wlist) {
1598 if (wlist->main_window == wapp->main_window) {
1599 if (wlist->flags.focused)
1600 hadfocus = 1;
1601 if (wapp->app_icon) {
1602 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1603 wapp->app_icon->y_pos, wlist, animate);
1604 animate = False;
1607 wlist = wlist->prev;
1610 wapp->flags.skip_next_animation = 0;
1612 if (hadfocus) {
1613 if (wPreferences.focus_mode == WKF_CLICK) {
1614 wlist = scr->focused_window;
1615 while (wlist) {
1616 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1617 && (wlist->flags.mapped || wlist->flags.shaded))
1618 break;
1619 wlist = wlist->prev;
1621 wSetFocusTo(scr, wlist);
1622 } else {
1623 wSetFocusTo(scr, NULL);
1627 wapp->flags.hidden = 1;
1629 if (wPreferences.auto_arrange_icons)
1630 wArrangeIcons(scr, True);
1632 #ifdef HIDDENDOT
1633 if (wapp->app_icon)
1634 wAppIconPaint(wapp->app_icon);
1635 #endif
1638 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1640 if (bringToCurrentWS)
1641 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1643 wwin->flags.hidden = 0;
1645 #ifdef USE_ANIMATIONS
1646 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1647 animateResize(wwin->screen_ptr, icon_x, icon_y,
1648 icon->core->width, icon->core->height,
1649 wwin->frame_x, wwin->frame_y,
1650 wwin->frame->core->width, wwin->frame->core->height);
1652 #else
1653 /* Tell the compiler it is normal that those parameters are not used in this case */
1654 (void) icon;
1655 (void) icon_x;
1656 (void) icon_y;
1657 (void) animate;
1658 #endif
1659 wwin->flags.skip_next_animation = 0;
1660 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1661 XMapWindow(dpy, wwin->client_win);
1662 XMapWindow(dpy, wwin->frame->core->window);
1663 wClientSetState(wwin, NormalState, None);
1664 wwin->flags.mapped = 1;
1665 wRaiseFrame(wwin->frame->core);
1667 if (wwin->flags.inspector_open)
1668 wUnhideInspectorForWindow(wwin);
1670 WMPostNotificationName(WMNChangedState, wwin, "hide");
1673 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1675 WScreen *scr;
1676 WWindow *wlist, *next;
1677 WWindow *focused = NULL;
1678 int animate;
1680 if (!wapp)
1681 return;
1683 scr = wapp->main_window_desc->screen_ptr;
1684 wlist = scr->focused_window;
1685 if (!wlist)
1686 return;
1688 /* goto beginning of list */
1689 while (wlist->prev)
1690 wlist = wlist->prev;
1692 animate = !wapp->flags.skip_next_animation;
1694 while (wlist) {
1695 next = wlist->next;
1697 if (wlist->main_window == wapp->main_window) {
1698 if (wlist->flags.focused)
1699 focused = wlist;
1700 else if (!focused || !focused->flags.focused)
1701 focused = wlist;
1703 if (wlist->flags.miniaturized) {
1704 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1705 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1706 if (!wlist->icon->mapped) {
1707 int x, y;
1709 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1710 if (wlist->icon_x != x || wlist->icon_y != y)
1711 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1712 wlist->icon_x = x;
1713 wlist->icon_y = y;
1714 XMapWindow(dpy, wlist->icon->core->window);
1715 wlist->icon->mapped = 1;
1717 wRaiseFrame(wlist->icon->core);
1719 if (bringToCurrentWS)
1720 wWindowChangeWorkspace(wlist, scr->current_workspace);
1721 wlist->flags.hidden = 0;
1722 if (miniwindows && wlist->frame->workspace == scr->current_workspace)
1723 wDeiconifyWindow(wlist);
1724 WMPostNotificationName(WMNChangedState, wlist, "hide");
1725 } else if (wlist->flags.shaded) {
1726 if (bringToCurrentWS)
1727 wWindowChangeWorkspace(wlist, scr->current_workspace);
1728 wlist->flags.hidden = 0;
1729 wRaiseFrame(wlist->frame->core);
1730 if (wlist->frame->workspace == scr->current_workspace) {
1731 XMapWindow(dpy, wlist->frame->core->window);
1732 if (miniwindows)
1733 wUnshadeWindow(wlist);
1735 WMPostNotificationName(WMNChangedState, wlist, "hide");
1736 } else if (wlist->flags.hidden) {
1737 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1738 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1739 animate = False;
1740 } else {
1741 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace)
1742 wWindowChangeWorkspace(wlist, scr->current_workspace);
1744 wRaiseFrame(wlist->frame->core);
1747 wlist = next;
1750 wapp->flags.skip_next_animation = 0;
1751 wapp->flags.hidden = 0;
1753 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1754 wRaiseFrame(wapp->last_focused->frame->core);
1755 wSetFocusTo(scr, wapp->last_focused);
1756 } else if (focused) {
1757 wSetFocusTo(scr, focused);
1759 wapp->last_focused = NULL;
1760 if (wPreferences.auto_arrange_icons)
1761 wArrangeIcons(scr, True);
1763 #ifdef HIDDENDOT
1764 wAppIconPaint(wapp->app_icon);
1765 #endif
1768 void wShowAllWindows(WScreen *scr)
1770 WWindow *wwin, *old_foc;
1771 WApplication *wapp;
1773 old_foc = wwin = scr->focused_window;
1774 while (wwin) {
1775 if (!wwin->flags.internal_window &&
1776 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1777 if (wwin->flags.miniaturized) {
1778 wwin->flags.skip_next_animation = 1;
1779 wDeiconifyWindow(wwin);
1780 } else if (wwin->flags.hidden) {
1781 wapp = wApplicationOf(wwin->main_window);
1782 if (wapp) {
1783 wUnhideApplication(wapp, False, False);
1784 } else {
1785 wwin->flags.skip_next_animation = 1;
1786 wDeiconifyWindow(wwin);
1790 wwin = wwin->prev;
1792 wSetFocusTo(scr, old_foc);
1793 /*wRaiseFrame(old_foc->frame->core); */
1796 void wRefreshDesktop(WScreen *scr)
1798 Window win;
1799 XSetWindowAttributes attr;
1801 attr.backing_store = NotUseful;
1802 attr.save_under = False;
1803 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1804 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1805 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1806 XMapRaised(dpy, win);
1807 XDestroyWindow(dpy, win);
1808 XFlush(dpy);
1811 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1813 WWindow *wwin;
1814 WAppIcon *aicon;
1816 int head;
1817 const int heads = wXineramaHeads(scr);
1819 struct HeadVars {
1820 int pf; /* primary axis */
1821 int sf; /* secondary axis */
1822 int fullW;
1823 int fullH;
1824 int pi, si;
1825 int sx1, sx2, sy1, sy2; /* screen boundary */
1826 int sw, sh;
1827 int xo, yo;
1828 int xs, ys;
1829 } *vars;
1831 int isize = wPreferences.icon_size;
1833 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1835 for (head = 0; head < heads; ++head) {
1836 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1837 WMRect rect;
1839 if (scr->dock) {
1840 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
1842 if (scr->dock->on_right_side)
1843 area.x2 -= offset;
1844 else
1845 area.x1 += offset;
1848 rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1850 vars[head].pi = vars[head].si = 0;
1851 vars[head].sx1 = rect.pos.x;
1852 vars[head].sy1 = rect.pos.y;
1853 vars[head].sw = rect.size.width;
1854 vars[head].sh = rect.size.height;
1855 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1856 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1857 vars[head].sw = isize * (vars[head].sw / isize);
1858 vars[head].sh = isize * (vars[head].sh / isize);
1859 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1860 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1862 /* icon yard boundaries */
1863 if (wPreferences.icon_yard & IY_VERT) {
1864 vars[head].pf = vars[head].fullH;
1865 vars[head].sf = vars[head].fullW;
1866 } else {
1867 vars[head].pf = vars[head].fullW;
1868 vars[head].sf = vars[head].fullH;
1870 if (wPreferences.icon_yard & IY_RIGHT) {
1871 vars[head].xo = vars[head].sx2 - isize;
1872 vars[head].xs = -1;
1873 } else {
1874 vars[head].xo = vars[head].sx1;
1875 vars[head].xs = 1;
1877 if (wPreferences.icon_yard & IY_TOP) {
1878 vars[head].yo = vars[head].sy1;
1879 vars[head].ys = 1;
1880 } else {
1881 vars[head].yo = vars[head].sy2 - isize;
1882 vars[head].ys = -1;
1886 #define X ((wPreferences.icon_yard & IY_VERT) \
1887 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1888 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1890 #define Y ((wPreferences.icon_yard & IY_VERT) \
1891 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1892 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1894 /* arrange application icons */
1895 aicon = scr->app_icon_list;
1896 /* reverse them to avoid unnecessarily sliding of icons */
1897 while (aicon && aicon->next)
1898 aicon = aicon->next;
1900 while (aicon) {
1901 if (!aicon->docked) {
1902 /* CHECK: can icon be NULL here ? */
1903 /* The intention here is to place the AppIcon on the head that
1904 * contains most of the applications _main_ window. */
1905 head = wGetHeadForWindow(aicon->icon->owner);
1907 if (aicon->x_pos != X || aicon->y_pos != Y) {
1908 #ifdef USE_ANIMATIONS
1909 if (!wPreferences.no_animations)
1910 slide_window(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1911 #endif /* USE_ANIMATIONS */
1913 wAppIconMove(aicon, X, Y);
1914 vars[head].pi++;
1915 if (vars[head].pi >= vars[head].pf) {
1916 vars[head].pi = 0;
1917 vars[head].si++;
1920 aicon = aicon->prev;
1923 /* arrange miniwindows */
1924 wwin = scr->focused_window;
1925 /* reverse them to avoid unnecessarily shuffling */
1926 while (wwin && wwin->prev)
1927 wwin = wwin->prev;
1929 while (wwin) {
1930 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1931 (wwin->frame->workspace == scr->current_workspace ||
1932 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1934 head = wGetHeadForWindow(wwin);
1936 if (arrangeAll || !wwin->flags.icon_moved) {
1937 if (wwin->icon_x != X || wwin->icon_y != Y)
1938 move_window(wwin->icon->core->window, wwin->icon_x, wwin->icon_y, X, Y);
1940 wwin->icon_x = X;
1941 wwin->icon_y = Y;
1943 vars[head].pi++;
1944 if (vars[head].pi >= vars[head].pf) {
1945 vars[head].pi = 0;
1946 vars[head].si++;
1950 if (arrangeAll)
1951 wwin->flags.icon_moved = 0;
1952 /* we reversed the order, so we use next */
1953 wwin = wwin->next;
1956 wfree(vars);
1959 void wSelectWindow(WWindow *wwin, Bool flag)
1961 WScreen *scr = wwin->screen_ptr;
1963 if (flag) {
1964 wwin->flags.selected = 1;
1965 if (wwin->frame->selected_border_pixel)
1966 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->selected_border_pixel);
1967 else
1968 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1970 if (!HAS_BORDER(wwin))
1971 XSetWindowBorderWidth(dpy, wwin->frame->core->window, wwin->screen_ptr->frame_border_width);
1973 if (!scr->selected_windows)
1974 scr->selected_windows = WMCreateArray(4);
1975 WMAddToArray(scr->selected_windows, wwin);
1976 } else {
1977 wwin->flags.selected = 0;
1978 if (wwin->flags.focused) {
1979 if (wwin->frame->focused_border_pixel)
1980 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->focused_border_pixel);
1981 else
1982 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_focused_border_pixel);
1983 } else {
1984 if (wwin->frame->border_pixel)
1985 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->border_pixel);
1986 else
1987 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1990 if (!HAS_BORDER(wwin))
1991 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1993 if (scr->selected_windows)
1994 WMRemoveFromArray(scr->selected_windows, wwin);
1998 void wMakeWindowVisible(WWindow *wwin)
2000 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
2001 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
2003 if (wwin->flags.shaded)
2004 wUnshadeWindow(wwin);
2006 if (wwin->flags.hidden) {
2007 WApplication *app;
2009 app = wApplicationOf(wwin->main_window);
2010 if (app) {
2011 /* trick to get focus to this window */
2012 app->last_focused = wwin;
2013 wUnhideApplication(app, False, False);
2016 if (wwin->flags.miniaturized) {
2017 wDeiconifyWindow(wwin);
2018 } else {
2019 if (!WFLAGP(wwin, no_focusable))
2020 wSetFocusTo(wwin->screen_ptr, wwin);
2021 wRaiseFrame(wwin->frame->core);
2026 * Do the animation while shading (called with what = SHADE)
2027 * or unshading (what = UNSHADE).
2029 #ifdef USE_ANIMATIONS
2030 static void shade_animate(WWindow *wwin, Bool what)
2032 int y, s, w, h;
2033 time_t time0 = time(NULL);
2035 if (wwin->flags.skip_next_animation || wPreferences.no_animations)
2036 return;
2038 switch (what) {
2039 case SHADE:
2040 if (!wwin->screen_ptr->flags.startup) {
2041 /* do the shading animation */
2042 h = wwin->frame->core->height;
2043 s = h / SHADE_STEPS;
2044 if (s < 1)
2045 s = 1;
2046 w = wwin->frame->core->width;
2047 y = wwin->frame->top_width;
2048 while (h > wwin->frame->top_width + 1) {
2049 XMoveWindow(dpy, wwin->client_win, 0, y);
2050 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2051 XFlush(dpy);
2053 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2054 break;
2056 if (SHADE_DELAY > 0)
2057 wusleep(SHADE_DELAY * 1000L);
2058 else
2059 wusleep(10);
2060 h -= s;
2061 y -= s;
2063 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2065 break;
2067 case UNSHADE:
2068 h = wwin->frame->top_width + wwin->frame->bottom_width;
2069 y = wwin->frame->top_width - wwin->client.height;
2070 s = abs(y) / SHADE_STEPS;
2071 if (s < 1)
2072 s = 1;
2073 w = wwin->frame->core->width;
2074 XMoveWindow(dpy, wwin->client_win, 0, y);
2075 if (s > 0) {
2076 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
2077 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2078 XMoveWindow(dpy, wwin->client_win, 0, y);
2079 XFlush(dpy);
2080 if (SHADE_DELAY > 0)
2081 wusleep(SHADE_DELAY * 2000L / 3);
2082 else
2083 wusleep(10);
2084 h += s;
2085 y += s;
2087 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2088 break;
2091 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2092 break;
2095 #endif