wmaker: fix stacking order of dock and fullscreen
[wmaker-crm.git] / src / actions.c
blobe6a91d5bc617d108a9a9f00eb6d32d3bd41341f8
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);
221 wWindowFocus(wwin, focused);
223 if (napp && !wasfocused) {
224 #ifdef USER_MENU
225 wUserMenuRefreshInstances(napp->menu, wwin);
226 #endif /* USER_MENU */
228 /* kix: Only menu map with mouse, not alt+tab! */
229 if (wwin->flags.mapped)
230 wAppMenuMap(napp->menu, wwin);
232 if (napp && wPreferences.highlight_active_app)
233 wApplicationActivate(napp);
235 XFlush(dpy);
236 old_scr = scr;
239 void wShadeWindow(WWindow *wwin)
242 if (wwin->flags.shaded)
243 return;
245 XLowerWindow(dpy, wwin->client_win);
246 shade_animate(wwin, SHADE);
248 wwin->flags.skip_next_animation = 0;
249 wwin->flags.shaded = 1;
250 wwin->flags.mapped = 0;
251 /* prevent window withdrawal when getting UnmapNotify */
252 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
253 XUnmapWindow(dpy, wwin->client_win);
254 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
256 /* for the client it's just like iconification */
257 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
259 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
260 wWindowSynthConfigureNotify(wwin);
263 wClientSetState(wwin, IconicState, None);
266 WMPostNotificationName(WMNChangedState, wwin, "shade");
268 #ifdef USE_ANIMATIONS
269 if (!wwin->screen_ptr->flags.startup) {
270 /* Catch up with events not processed while animation was running */
271 ProcessPendingEvents();
273 #endif
276 void wUnshadeWindow(WWindow *wwin)
279 if (!wwin->flags.shaded)
280 return;
282 wwin->flags.shaded = 0;
283 wwin->flags.mapped = 1;
284 XMapWindow(dpy, wwin->client_win);
286 shade_animate(wwin, UNSHADE);
288 wwin->flags.skip_next_animation = 0;
289 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
290 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
292 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
293 wWindowSynthConfigureNotify(wwin);
295 /* if the window is focused, set the focus again as it was disabled during
296 * shading */
297 if (wwin->flags.focused)
298 wSetFocusTo(wwin->screen_ptr, wwin);
300 WMPostNotificationName(WMNChangedState, wwin, "shade");
303 /* Set the old coordinates using the current values */
304 static void save_old_geometry(WWindow *wwin, int directions)
306 /* never been saved? */
307 if (!wwin->old_geometry.width)
308 directions |= SAVE_GEOMETRY_X | SAVE_GEOMETRY_WIDTH;
309 if (!wwin->old_geometry.height)
310 directions |= SAVE_GEOMETRY_Y | SAVE_GEOMETRY_HEIGHT;
312 if (directions & SAVE_GEOMETRY_X)
313 wwin->old_geometry.x = wwin->frame_x;
314 if (directions & SAVE_GEOMETRY_Y)
315 wwin->old_geometry.y = wwin->frame_y;
316 if (directions & SAVE_GEOMETRY_WIDTH)
317 wwin->old_geometry.width = wwin->client.width;
318 if (directions & SAVE_GEOMETRY_HEIGHT)
319 wwin->old_geometry.height = wwin->client.height;
322 static void remember_geometry(WWindow *wwin, int *x, int *y, int *w, int *h)
324 WMRect old_geom_rect;
325 int old_head;
326 Bool same_head;
328 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
329 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
330 same_head = (wGetHeadForWindow(wwin) == old_head);
331 *x = ((wwin->old_geometry.x || wwin->old_geometry.width) && same_head) ? wwin->old_geometry.x : wwin->frame_x;
332 *y = ((wwin->old_geometry.y || wwin->old_geometry.height) && same_head) ? wwin->old_geometry.y : wwin->frame_y;
333 *w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
334 *h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
337 /* Remember geometry for unmaximizing */
338 void update_saved_geometry(WWindow *wwin)
340 /* NOT if we aren't already maximized
341 * we'll save geometry when maximizing */
342 if (!wwin->flags.maximized)
343 return;
345 /* NOT if we are fully maximized */
346 if ((wwin->flags.maximized & MAX_MAXIMUS) ||
347 ((wwin->flags.maximized & MAX_HORIZONTAL) &&
348 (wwin->flags.maximized & MAX_VERTICAL)))
349 return;
351 /* save the co-ordinate in the axis in which we AREN'T maximized */
352 if (wwin->flags.maximized & MAX_HORIZONTAL)
353 save_old_geometry(wwin, SAVE_GEOMETRY_Y);
354 if (wwin->flags.maximized & MAX_VERTICAL)
355 save_old_geometry(wwin, SAVE_GEOMETRY_X);
358 void wMaximizeWindow(WWindow *wwin, int directions)
360 unsigned int new_width, new_height, half_scr_width, half_scr_height;
361 int new_x = 0;
362 int new_y = 0;
363 int maximus_x = 0;
364 int maximus_y = 0;
365 unsigned int maximus_width = 0;
366 unsigned int maximus_height = 0;
367 WArea usableArea, totalArea;
368 Bool has_border = 1;
369 int adj_size;
370 WScreen *scr = wwin->screen_ptr;
372 if (!IS_RESIZABLE(wwin))
373 return;
375 if (!HAS_BORDER(wwin))
376 has_border = 0;
378 if (wPreferences.drag_maximized_window == DRAGMAX_NOMOVE)
379 wwin->client_flags.no_movable = 1;
381 /* the size to adjust the geometry */
382 adj_size = scr->frame_border_width * 2 * has_border;
384 /* save old coordinates before we change the current values */
385 if (!wwin->flags.maximized)
386 save_old_geometry(wwin, SAVE_GEOMETRY_ALL);
388 totalArea.x2 = scr->scr_width;
389 totalArea.y2 = scr->scr_height;
390 totalArea.x1 = 0;
391 totalArea.y1 = 0;
392 usableArea = totalArea;
394 if (!(directions & MAX_IGNORE_XINERAMA)) {
395 WScreen *scr = wwin->screen_ptr;
396 int head;
398 if (directions & MAX_KEYBOARD)
399 head = wGetHeadForWindow(wwin);
400 else
401 head = wGetHeadForPointerLocation(scr);
403 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
407 /* Only save directions, not kbd or xinerama hints */
408 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
410 if (WFLAGP(wwin, full_maximize))
411 usableArea = totalArea;
412 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
413 half_scr_height = (usableArea.y2 - usableArea.y1)/2;
415 if (wwin->flags.shaded) {
416 wwin->flags.skip_next_animation = 1;
417 wUnshadeWindow(wwin);
420 if (directions & MAX_MAXIMUS) {
421 find_Maximus_geometry(wwin, usableArea, &maximus_x, &maximus_y, &maximus_width, &maximus_height);
422 new_width = maximus_width - adj_size;
423 new_height = maximus_height - adj_size;
424 new_x = maximus_x;
425 new_y = maximus_y;
426 if (WFLAGP(wwin, full_maximize) && (new_y == 0)) {
427 new_height += wwin->frame->bottom_width - 1;
428 new_y -= wwin->frame->top_width;
431 wwin->maximus_x = new_x;
432 wwin->maximus_y = new_y;
433 wwin->flags.old_maximized |= MAX_MAXIMUS;
434 } else {
435 /* set default values if no option set then */
436 if (!(directions & (MAX_HORIZONTAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS))) {
437 new_width = (wwin->old_geometry.width) ? wwin->old_geometry.width : wwin->frame->core->width;
438 new_x = (wwin->old_geometry.x) ? wwin->old_geometry.x : wwin->frame_x;
440 if (!(directions & (MAX_VERTICAL | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS))) {
441 new_height = (wwin->old_geometry.height) ? wwin->old_geometry.height : wwin->frame->core->height;
442 new_y = (wwin->old_geometry.y) ? wwin->old_geometry.y : wwin->frame_y;
445 /* left|right position */
446 if (directions & MAX_LEFTHALF) {
447 new_width = half_scr_width - adj_size;
448 new_x = usableArea.x1;
449 } else if (directions & MAX_RIGHTHALF) {
450 new_width = half_scr_width - adj_size;
451 new_x = usableArea.x1 + half_scr_width;
453 /* top|bottom position */
454 if (directions & MAX_TOPHALF) {
455 new_height = half_scr_height - adj_size;
456 new_y = usableArea.y1;
457 } else if (directions & MAX_BOTTOMHALF) {
458 new_height = half_scr_height - adj_size;
459 new_y = usableArea.y1 + half_scr_height;
462 /* vertical|horizontal position */
463 if (directions & MAX_HORIZONTAL) {
464 new_width = usableArea.x2 - usableArea.x1 - adj_size;
465 new_x = usableArea.x1;
467 if (directions & MAX_VERTICAL) {
468 new_height = usableArea.y2 - usableArea.y1 - adj_size;
469 new_y = usableArea.y1;
470 if (WFLAGP(wwin, full_maximize) && (new_y == 0))
471 new_y -= wwin->frame->top_width;
475 if (!WFLAGP(wwin, full_maximize) && !(directions == MAX_MAXIMUS || directions == MAX_HORIZONTAL))
476 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
478 /* set maximization state */
479 wwin->flags.maximized = directions;
480 if ((wwin->flags.old_maximized & MAX_MAXIMUS) && !wwin->flags.maximized)
481 wwin->flags.maximized = MAX_MAXIMUS;
483 wWindowConstrainSize(wwin, &new_width, &new_height);
485 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
486 usableArea.y2 - usableArea.y1, &new_width, &new_height);
488 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
489 wWindowSynthConfigureNotify(wwin);
491 WMPostNotificationName(WMNChangedState, wwin, "maximize");
494 /* generic (un)maximizer */
495 void handleMaximize(WWindow *wwin, int directions)
497 int current = wwin->flags.maximized;
498 int requested = directions & (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_TOPHALF | MAX_BOTTOMHALF | MAX_MAXIMUS);
499 int effective = requested ^ current;
500 int flags = directions & ~requested;
502 if (!effective) {
503 /* allow wMaximizeWindow to restore the Maximusized size */
504 if ((wwin->flags.old_maximized & MAX_MAXIMUS) &&
505 !(requested & MAX_MAXIMUS))
506 wMaximizeWindow(wwin, MAX_MAXIMUS | flags);
507 else
508 wUnmaximizeWindow(wwin);
509 /* these alone mean vertical|horizontal toggle */
510 } else if ((effective == MAX_LEFTHALF) ||
511 (effective == MAX_RIGHTHALF) ||
512 (effective == MAX_TOPHALF) ||
513 (effective == MAX_BOTTOMHALF))
514 wUnmaximizeWindow(wwin);
515 else {
516 if ((requested == (MAX_HORIZONTAL | MAX_VERTICAL)) ||
517 (requested == MAX_MAXIMUS))
518 effective = requested;
519 else {
520 if (requested & MAX_LEFTHALF) {
521 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
522 effective |= MAX_VERTICAL;
523 else
524 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
525 effective |= MAX_LEFTHALF;
526 effective &= ~(MAX_HORIZONTAL | MAX_RIGHTHALF);
527 } else if (requested & MAX_RIGHTHALF) {
528 if (!(requested & (MAX_TOPHALF | MAX_BOTTOMHALF)))
529 effective |= MAX_VERTICAL;
530 else
531 effective |= requested & (MAX_TOPHALF | MAX_BOTTOMHALF);
532 effective |= MAX_RIGHTHALF;
533 effective &= ~(MAX_HORIZONTAL | MAX_LEFTHALF);
535 if (requested & MAX_TOPHALF) {
536 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
537 effective |= MAX_HORIZONTAL;
538 else
539 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
540 effective |= MAX_TOPHALF;
541 effective &= ~(MAX_VERTICAL | MAX_BOTTOMHALF);
542 } else if (requested & MAX_BOTTOMHALF) {
543 if (!(requested & (MAX_LEFTHALF | MAX_RIGHTHALF)))
544 effective |= MAX_HORIZONTAL;
545 else
546 effective |= requested & (MAX_LEFTHALF | MAX_RIGHTHALF);
547 effective |= MAX_BOTTOMHALF;
548 effective &= ~(MAX_VERTICAL | MAX_TOPHALF);
550 if (requested & MAX_HORIZONTAL)
551 effective &= ~(MAX_LEFTHALF | MAX_RIGHTHALF);
552 if (requested & MAX_VERTICAL)
553 effective &= ~(MAX_TOPHALF | MAX_BOTTOMHALF);
554 effective &= ~MAX_MAXIMUS;
556 wMaximizeWindow(wwin, effective | flags);
560 /* the window boundary coordinates */
561 typedef struct {
562 int left;
563 int right;
564 int bottom;
565 int top;
566 int width;
567 int height;
568 } win_coords;
570 static void set_window_coords(WWindow *wwin, win_coords *obs)
572 obs->left = wwin->frame_x;
573 obs->top = wwin->frame_y;
574 obs->width = wwin->frame->core->width;
575 obs->height = wwin->frame->core->height;
576 obs->bottom = obs->top + obs->height;
577 obs->right = obs->left + obs->width;
581 * Maximus: tiled maximization (maximize without overlapping other windows)
583 * The original window 'orig' will be maximized to new coordinates 'new'.
584 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
586 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
587 unsigned int *new_width, unsigned int *new_height)
589 WWindow *tmp;
590 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
591 short int adjust_height;
592 int x_intsect, y_intsect;
593 /* the obstructing, original and new windows */
594 win_coords obs, orig, new;
596 /* set the original coordinate positions of the window to be Maximumized */
597 if (wwin->flags.maximized) {
598 /* window is already maximized; consider original geometry */
599 remember_geometry(wwin, &orig.left, &orig.top, &orig.width, &orig.height);
600 orig.bottom = orig.top + orig.height;
601 orig.right = orig.left + orig.width;
602 } else
603 set_window_coords(wwin, &orig);
605 /* Try to fully maximize first, then readjust later */
606 new.left = usableArea.x1;
607 new.right = usableArea.x2;
608 new.top = usableArea.y1;
609 new.bottom = usableArea.y2;
611 if (HAS_TITLEBAR(wwin))
612 tbar_height_0 = TITLEBAR_HEIGHT;
613 if (HAS_RESIZEBAR(wwin))
614 rbar_height_0 = RESIZEBAR_HEIGHT;
615 if (HAS_BORDER(wwin))
616 bd_width_0 = wwin->screen_ptr->frame_border_width;
618 /* the length to be subtracted if the window has titlebar, etc */
619 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
621 tmp = wwin;
622 /* The focused window is always the last in the list */
623 while (tmp->prev) {
624 /* ignore windows in other workspaces etc */
625 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
626 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
627 tmp = tmp->prev;
628 continue;
630 tmp = tmp->prev;
632 /* Set the coordinates of obstructing window */
633 set_window_coords(tmp, &obs);
635 /* Try to maximize in the y direction first */
636 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
637 if (x_intsect != 0) {
638 /* TODO: Consider the case when coords are equal */
639 if (obs.bottom < orig.top && obs.bottom > new.top) {
640 /* w_0 is below the bottom of w_j */
641 new.top = obs.bottom + 1;
643 if (orig.bottom < obs.top && obs.top < new.bottom) {
644 /* The bottom of w_0 is above the top of w_j */
645 new.bottom = obs.top - 1;
650 tmp = wwin;
651 while (tmp->prev) {
652 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
653 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
654 tmp = tmp->prev;
655 continue;
657 tmp = tmp->prev;
659 set_window_coords(tmp, &obs);
662 * Use the new.top and new.height instead of original values
663 * as they may have different intersections with the obstructing windows
665 new.height = new.bottom - new.top - adjust_height;
666 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
667 if (y_intsect != 0) {
668 if (obs.right < orig.left && obs.right > new.left) {
669 /* w_0 is completely to the right of w_j */
670 new.left = obs.right + 1;
672 if (orig.right < obs.left && obs.left < new.right) {
673 /* w_0 is completely to the left of w_j */
674 new.right = obs.left - 1;
679 *new_x = new.left;
680 *new_y = new.top;
681 /* xcalc needs -7 here, but other apps don't */
682 *new_height = new.bottom - new.top - adjust_height - 1;
683 *new_width = new.right - new.left;
686 void wUnmaximizeWindow(WWindow *wwin)
688 int x, y, w, h;
690 if (!wwin->flags.maximized)
691 return;
693 if (wwin->flags.shaded) {
694 wwin->flags.skip_next_animation = 1;
695 wUnshadeWindow(wwin);
698 if (wPreferences.drag_maximized_window == DRAGMAX_NOMOVE)
699 wwin->client_flags.no_movable = 0;
701 /* Use old coordinates if they are set, current values otherwise */
702 remember_geometry(wwin, &x, &y, &w, &h);
704 /* unMaximusize relative to original position */
705 if (wwin->flags.maximized & MAX_MAXIMUS) {
706 x += wwin->frame_x - wwin->maximus_x;
707 y += wwin->frame_y - wwin->maximus_y;
710 wwin->flags.maximized = 0;
711 wwin->flags.old_maximized = 0;
712 wWindowConfigure(wwin, x, y, w, h);
713 wWindowSynthConfigureNotify(wwin);
715 WMPostNotificationName(WMNChangedState, wwin, "maximize");
718 void wFullscreenWindow(WWindow *wwin)
720 int head;
721 WMRect rect;
723 if (wwin->flags.fullscreen)
724 return;
726 wwin->flags.fullscreen = True;
728 wWindowConfigureBorders(wwin);
730 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
732 wwin->bfs_geometry.x = wwin->frame_x;
733 wwin->bfs_geometry.y = wwin->frame_y;
734 wwin->bfs_geometry.width = wwin->frame->core->width;
735 wwin->bfs_geometry.height = wwin->frame->core->height;
737 head = wGetHeadForWindow(wwin);
738 rect = wGetRectForHead(wwin->screen_ptr, head);
739 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
741 wwin->screen_ptr->bfs_focused_window = wwin->screen_ptr->focused_window;
742 wSetFocusTo(wwin->screen_ptr, wwin);
744 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
747 void wUnfullscreenWindow(WWindow *wwin)
749 if (!wwin->flags.fullscreen)
750 return;
752 wwin->flags.fullscreen = False;
754 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
755 if (WFLAGP(wwin, sunken)) {
756 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
757 } else if (WFLAGP(wwin, floating)) {
758 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
759 } else {
760 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
764 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
765 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
767 wWindowConfigureBorders(wwin);
769 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
770 wFrameWindowPaint(wwin->frame);
773 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
775 if (wwin->screen_ptr->bfs_focused_window) {
776 wSetFocusTo(wwin->screen_ptr, wwin->screen_ptr->bfs_focused_window);
777 wwin->screen_ptr->bfs_focused_window = NULL;
781 #ifdef USE_ANIMATIONS
782 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
784 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
785 float cx, cy, cw, ch;
786 float xstep, ystep, wstep, hstep;
787 XPoint points[5];
788 float dx, dch, midy;
789 float angle, final_angle, delta;
791 xstep = (float)(fx - x) / steps;
792 ystep = (float)(fy - y) / steps;
793 wstep = (float)(fw - w) / steps;
794 hstep = (float)(fh - h) / steps;
796 cx = (float)x;
797 cy = (float)y;
798 cw = (float)w;
799 ch = (float)h;
801 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
802 delta = (float)(final_angle / FRAMES);
803 for (angle = 0;; angle += delta) {
804 if (angle > final_angle)
805 angle = final_angle;
807 dx = (cw / 10) - ((cw / 5) * sinf(angle));
808 dch = (ch / 2) * cosf(angle);
809 midy = cy + (ch / 2);
811 points[0].x = cx + dx;
812 points[0].y = midy - dch;
813 points[1].x = cx + cw - dx;
814 points[1].y = points[0].y;
815 points[2].x = cx + cw + dx;
816 points[2].y = midy + dch;
817 points[3].x = cx - dx;
818 points[3].y = points[2].y;
819 points[4].x = points[0].x;
820 points[4].y = points[0].y;
822 XGrabServer(dpy);
823 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
824 XFlush(dpy);
825 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
827 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
828 XUngrabServer(dpy);
829 cx += xstep;
830 cy += ystep;
831 cw += wstep;
832 ch += hstep;
833 if (angle >= final_angle)
834 break;
837 XFlush(dpy);
840 #undef FRAMES
842 static void
843 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
845 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
846 float cx, cy, cw, ch;
847 float xstep, ystep, wstep, hstep;
848 XPoint points[5];
849 float angle, final_angle, a, d, delta;
851 x += w / 2;
852 y += h / 2;
853 fx += fw / 2;
854 fy += fh / 2;
856 xstep = (float)(fx - x) / steps;
857 ystep = (float)(fy - y) / steps;
858 wstep = (float)(fw - w) / steps;
859 hstep = (float)(fh - h) / steps;
861 cx = (float)x;
862 cy = (float)y;
863 cw = (float)w;
864 ch = (float)h;
866 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
867 delta = (float)(final_angle / FRAMES);
868 for (angle = 0;; angle += delta) {
869 if (angle > final_angle)
870 angle = final_angle;
872 a = atan2f(ch, cw);
873 d = sqrtf((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
875 points[0].x = cx + cosf(angle - a) * d;
876 points[0].y = cy + sinf(angle - a) * d;
877 points[1].x = cx + cosf(angle + a) * d;
878 points[1].y = cy + sinf(angle + a) * d;
879 points[2].x = cx + cosf(angle - a + (float)WM_PI) * d;
880 points[2].y = cy + sinf(angle - a + (float)WM_PI) * d;
881 points[3].x = cx + cosf(angle + a + (float)WM_PI) * d;
882 points[3].y = cy + sinf(angle + a + (float)WM_PI) * d;
883 points[4].x = cx + cosf(angle - a) * d;
884 points[4].y = cy + sinf(angle - a) * d;
885 XGrabServer(dpy);
886 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
887 XFlush(dpy);
888 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
890 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
891 XUngrabServer(dpy);
892 cx += xstep;
893 cy += ystep;
894 cw += wstep;
895 ch += hstep;
896 if (angle >= final_angle)
897 break;
900 XFlush(dpy);
903 #undef FRAMES
905 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
907 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
908 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
909 float xstep, ystep, wstep, hstep;
910 int i, j;
912 xstep = (float)(fx - x) / steps;
913 ystep = (float)(fy - y) / steps;
914 wstep = (float)(fw - w) / steps;
915 hstep = (float)(fh - h) / steps;
917 for (j = 0; j < FRAMES; j++) {
918 cx[j] = (float)x;
919 cy[j] = (float)y;
920 cw[j] = (float)w;
921 ch[j] = (float)h;
923 XGrabServer(dpy);
924 for (i = 0; i < steps; i++) {
925 for (j = 0; j < FRAMES; j++) {
926 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
927 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
929 XFlush(dpy);
930 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
932 for (j = 0; j < FRAMES; j++) {
933 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
934 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
935 if (j < FRAMES - 1) {
936 cx[j] = cx[j + 1];
937 cy[j] = cy[j + 1];
938 cw[j] = cw[j + 1];
939 ch[j] = ch[j + 1];
940 } else {
941 cx[j] += xstep;
942 cy[j] += ystep;
943 cw[j] += wstep;
944 ch[j] += hstep;
949 for (j = 0; j < FRAMES; j++)
950 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
951 XFlush(dpy);
952 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
954 for (j = 0; j < FRAMES; j++)
955 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
957 XUngrabServer(dpy);
960 #undef FRAMES
962 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
964 int style = wPreferences.iconification_style; /* Catch the value */
965 int steps;
967 if (style == WIS_NONE)
968 return;
970 if (style == WIS_RANDOM)
971 style = rand() % 3;
973 switch (style) {
974 case WIS_TWIST:
975 steps = MINIATURIZE_ANIMATION_STEPS_T;
976 if (steps > 0)
977 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
978 break;
979 case WIS_FLIP:
980 steps = MINIATURIZE_ANIMATION_STEPS_F;
981 if (steps > 0)
982 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
983 break;
984 case WIS_ZOOM:
985 default:
986 steps = MINIATURIZE_ANIMATION_STEPS_Z;
987 if (steps > 0)
988 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
989 break;
992 #endif /* USE_ANIMATIONS */
994 static void flushExpose(void)
996 XEvent tmpev;
998 while (XCheckTypedEvent(dpy, Expose, &tmpev))
999 WMHandleEvent(&tmpev);
1000 XSync(dpy, 0);
1003 static void unmapTransientsFor(WWindow *wwin)
1005 WWindow *tmp;
1007 tmp = wwin->screen_ptr->focused_window;
1008 while (tmp) {
1009 /* unmap the transients for this transient */
1010 if (tmp != wwin && tmp->transient_for == wwin->client_win
1011 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
1012 unmapTransientsFor(tmp);
1013 tmp->flags.miniaturized = 1;
1014 if (!tmp->flags.shaded)
1015 wWindowUnmap(tmp);
1016 else
1017 XUnmapWindow(dpy, tmp->frame->core->window);
1019 if (!tmp->flags.shaded)
1021 wClientSetState(tmp, IconicState, None);
1023 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1025 tmp = tmp->prev;
1029 static void mapTransientsFor(WWindow *wwin)
1031 WWindow *tmp;
1033 tmp = wwin->screen_ptr->focused_window;
1034 while (tmp) {
1035 /* recursively map the transients for this transient */
1036 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
1037 && tmp->icon == NULL) {
1038 mapTransientsFor(tmp);
1039 tmp->flags.miniaturized = 0;
1040 if (!tmp->flags.shaded)
1041 wWindowMap(tmp);
1042 else
1043 XMapWindow(dpy, tmp->frame->core->window);
1044 tmp->flags.semi_focused = 0;
1046 if (!tmp->flags.shaded)
1048 wClientSetState(tmp, NormalState, None);
1050 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
1052 tmp = tmp->prev;
1056 static WWindow *recursiveTransientFor(WWindow *wwin)
1058 int i;
1060 if (!wwin)
1061 return None;
1063 /* hackish way to detect transient_for cycle */
1064 i = wwin->screen_ptr->window_count + 1;
1066 while (wwin && wwin->transient_for != None && i > 0) {
1067 wwin = wWindowFor(wwin->transient_for);
1068 i--;
1070 if (i == 0 && wwin) {
1071 wwarning(_("window \"%s\" has a severely broken WM_TRANSIENT_FOR hint"),
1072 wwin->frame->title);
1073 return NULL;
1076 return wwin;
1079 #ifdef USE_ANIMATIONS
1080 static int getAnimationGeometry(WWindow *wwin, int *ix, int *iy, int *iw, int *ih)
1082 if (wwin->screen_ptr->flags.startup || wPreferences.no_animations
1083 || wwin->flags.skip_next_animation || wwin->icon == NULL)
1084 return 0;
1086 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1087 *ix = wwin->icon_x;
1088 *iy = wwin->icon_y;
1089 *iw = wwin->icon->core->width;
1090 *ih = wwin->icon->core->height;
1091 } else {
1092 if (wwin->flags.net_handle_icon) {
1093 *ix = wwin->icon_x;
1094 *iy = wwin->icon_y;
1095 *iw = wwin->icon_w;
1096 *ih = wwin->icon_h;
1097 } else {
1098 *ix = 0;
1099 *iy = 0;
1100 *iw = wwin->screen_ptr->scr_width;
1101 *ih = wwin->screen_ptr->scr_height;
1104 return 1;
1106 #endif /* USE_ANIMATIONS */
1108 void wIconifyWindow(WWindow *wwin)
1110 XWindowAttributes attribs;
1111 int present;
1113 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs))
1114 return; /* the window doesn't exist anymore */
1116 if (wwin->flags.miniaturized)
1117 return; /* already miniaturized */
1119 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1120 WWindow *owner = wWindowFor(wwin->transient_for);
1122 if (owner && owner->flags.miniaturized)
1123 return;
1126 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
1128 /* if the window is in another workspace, simplify process */
1129 if (present) {
1130 /* icon creation may take a while */
1131 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
1132 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
1133 GrabModeAsync, None, None, CurrentTime);
1136 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1137 if (!wwin->flags.icon_moved)
1138 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
1140 wwin->icon = icon_create_for_wwindow(wwin);
1141 wwin->icon->mapped = 1;
1143 /* extract the window screenshot every time, as the option can be enable anytime */
1144 if (wwin->client_win && wwin->flags.mapped) {
1145 RImage *mini_preview;
1146 XImage *pimg;
1147 unsigned int w, h;
1148 int x, y;
1149 Window baz;
1151 XRaiseWindow(dpy, wwin->frame->core->window);
1152 XTranslateCoordinates(dpy, wwin->client_win, wwin->screen_ptr->root_win, 0, 0, &x, &y, &baz);
1154 w = attribs.width;
1155 h = attribs.height;
1157 if (x - attribs.x + attribs.width > wwin->screen_ptr->scr_width)
1158 w = wwin->screen_ptr->scr_width - x + attribs.x;
1160 if (y - attribs.y + attribs.height > wwin->screen_ptr->scr_height)
1161 h = wwin->screen_ptr->scr_height - y + attribs.y;
1163 pimg = XGetImage(dpy, wwin->client_win, 0, 0, w, h, AllPlanes, ZPixmap);
1164 if (pimg) {
1165 mini_preview = RCreateImageFromXImage(wwin->screen_ptr->rcontext, pimg, NULL);
1166 XDestroyImage(pimg);
1168 if (mini_preview) {
1169 set_icon_minipreview(wwin->icon, mini_preview);
1170 RReleaseImage(mini_preview);
1171 } else {
1172 const char *title;
1173 char title_buf[32];
1175 if (wwin->frame->title) {
1176 title = wwin->frame->title;
1177 } else {
1178 snprintf(title_buf, sizeof(title_buf), "(id=0x%lx)", wwin->client_win);
1179 title = title_buf;
1181 wwarning(_("creation of mini-preview failed for window \"%s\""), title);
1187 wwin->flags.miniaturized = 1;
1188 wwin->flags.mapped = 0;
1190 /* unmap transients */
1191 unmapTransientsFor(wwin);
1193 if (present) {
1194 #ifdef USE_ANIMATIONS
1195 int ix, iy, iw, ih;
1196 #endif
1197 XUngrabPointer(dpy, CurrentTime);
1198 wWindowUnmap(wwin);
1199 /* let all Expose events arrive so that we can repaint
1200 * something before the animation starts (and the server is grabbed) */
1201 XSync(dpy, 0);
1203 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1204 wClientSetState(wwin, IconicState, None);
1205 else
1206 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1208 flushExpose();
1209 #ifdef USE_ANIMATIONS
1210 if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih))
1211 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1212 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1213 #endif
1216 wwin->flags.skip_next_animation = 0;
1218 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1219 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1220 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1221 XMapWindow(dpy, wwin->icon->core->window);
1223 AddToStackList(wwin->icon->core);
1224 wLowerFrame(wwin->icon->core);
1227 if (present) {
1228 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1231 * It doesn't seem to be working and causes button event hangup
1232 * when deiconifying a transient window.
1233 setupIconGrabs(wwin->icon);
1235 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1236 && wPreferences.focus_mode == WKF_CLICK) {
1237 WWindow *tmp;
1239 tmp = wwin->prev;
1240 while (tmp) {
1241 if (!WFLAGP(tmp, no_focusable)
1242 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1243 && (wwin->frame->workspace == tmp->frame->workspace))
1244 break;
1245 tmp = tmp->prev;
1247 wSetFocusTo(wwin->screen_ptr, tmp);
1248 } else if (wPreferences.focus_mode != WKF_CLICK) {
1249 wSetFocusTo(wwin->screen_ptr, NULL);
1251 #ifdef USE_ANIMATIONS
1252 if (!wwin->screen_ptr->flags.startup) {
1253 /* Catch up with events not processed while animation was running */
1254 Window clientwin = wwin->client_win;
1256 ProcessPendingEvents();
1258 /* the window can disappear while ProcessPendingEvents() runs */
1259 if (!wWindowFor(clientwin))
1260 return;
1262 #endif
1265 /* maybe we want to do this regardless of net_handle_icon
1266 * it seems to me we might break behaviour this way.
1268 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1269 && !wwin->flags.net_handle_icon)
1270 wIconSelect(wwin->icon);
1272 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1274 if (wPreferences.auto_arrange_icons)
1275 wArrangeIcons(wwin->screen_ptr, True);
1278 void wDeiconifyWindow(WWindow *wwin)
1280 /* Let's avoid changing workspace while deiconifying */
1281 w_global.ignore_workspace_change = True;
1283 /* we're hiding for show_desktop */
1284 int netwm_hidden = wwin->flags.net_show_desktop &&
1285 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1287 if (!netwm_hidden)
1288 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1290 if (!wwin->flags.miniaturized) {
1291 w_global.ignore_workspace_change = False;
1292 return;
1295 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1296 WWindow *owner = recursiveTransientFor(wwin);
1298 if (owner && owner->flags.miniaturized) {
1299 wDeiconifyWindow(owner);
1300 wSetFocusTo(wwin->screen_ptr, wwin);
1301 wRaiseFrame(wwin->frame->core);
1302 w_global.ignore_workspace_change = False;
1303 return;
1307 wwin->flags.miniaturized = 0;
1309 if (!netwm_hidden && !wwin->flags.shaded)
1310 wwin->flags.mapped = 1;
1312 if (!netwm_hidden || wPreferences.sticky_icons) {
1313 /* maybe we want to do this regardless of net_handle_icon
1314 * it seems to me we might break behaviour this way.
1316 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1317 && wwin->icon != NULL) {
1318 if (wwin->icon->selected)
1319 wIconSelect(wwin->icon);
1321 XUnmapWindow(dpy, wwin->icon->core->window);
1325 /* if the window is in another workspace, do it silently */
1326 if (!netwm_hidden) {
1327 #ifdef USE_ANIMATIONS
1328 int ix, iy, iw, ih;
1329 if (getAnimationGeometry(wwin, &ix, &iy, &iw, &ih))
1330 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1331 wwin->frame_x, wwin->frame_y,
1332 wwin->frame->core->width, wwin->frame->core->height);
1333 #endif
1334 wwin->flags.skip_next_animation = 0;
1335 XGrabServer(dpy);
1336 if (!wwin->flags.shaded)
1337 XMapWindow(dpy, wwin->client_win);
1339 XMapWindow(dpy, wwin->frame->core->window);
1340 wRaiseFrame(wwin->frame->core);
1341 if (!wwin->flags.shaded)
1342 wClientSetState(wwin, NormalState, None);
1344 mapTransientsFor(wwin);
1347 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1348 && !wwin->flags.net_handle_icon) {
1349 RemoveFromStackList(wwin->icon->core);
1350 wSetFocusTo(wwin->screen_ptr, wwin);
1351 wIconDestroy(wwin->icon);
1352 wwin->icon = NULL;
1355 if (!netwm_hidden) {
1356 XUngrabServer(dpy);
1358 wSetFocusTo(wwin->screen_ptr, wwin);
1360 #ifdef USE_ANIMATIONS
1361 if (!wwin->screen_ptr->flags.startup) {
1362 /* Catch up with events not processed while animation was running */
1363 Window clientwin = wwin->client_win;
1365 ProcessPendingEvents();
1367 /* the window can disappear while ProcessPendingEvents() runs */
1368 if (!wWindowFor(clientwin)) {
1369 w_global.ignore_workspace_change = False;
1370 return;
1373 #endif
1376 if (wPreferences.auto_arrange_icons)
1377 wArrangeIcons(wwin->screen_ptr, True);
1379 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1381 /* In case we were shaded and iconified, also unshade */
1382 if (!netwm_hidden)
1383 wUnshadeWindow(wwin);
1385 w_global.ignore_workspace_change = False;
1388 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1390 if (wwin->flags.miniaturized) {
1391 if (wwin->icon) {
1392 XUnmapWindow(dpy, wwin->icon->core->window);
1393 wwin->icon->mapped = 0;
1395 wwin->flags.hidden = 1;
1397 WMPostNotificationName(WMNChangedState, wwin, "hide");
1398 return;
1401 if (wwin->flags.inspector_open)
1402 wHideInspectorForWindow(wwin);
1404 wwin->flags.hidden = 1;
1405 wWindowUnmap(wwin);
1407 wClientSetState(wwin, IconicState, icon->icon_win);
1408 flushExpose();
1410 #ifdef USE_ANIMATIONS
1411 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1412 !wwin->flags.skip_next_animation && animate) {
1413 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1414 wwin->frame->core->width, wwin->frame->core->height,
1415 icon_x, icon_y, icon->core->width, icon->core->height);
1417 #else
1418 /* Tell the compiler it is normal that those parameters are not used in this case */
1419 (void) icon_x;
1420 (void) icon_y;
1421 (void) animate;
1422 #endif
1423 wwin->flags.skip_next_animation = 0;
1425 WMPostNotificationName(WMNChangedState, wwin, "hide");
1428 void wHideAll(WScreen *scr)
1430 WWindow *wwin;
1431 WWindow **windows;
1432 WMenu *menu;
1433 unsigned int wcount = 0;
1434 int i;
1436 if (!scr)
1437 return;
1439 menu = scr->switch_menu;
1441 windows = wmalloc(sizeof(WWindow *));
1443 if (menu != NULL) {
1444 for (i = 0; i < menu->entry_no; i++) {
1445 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1446 wcount++;
1447 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1449 } else {
1450 wwin = scr->focused_window;
1452 while (wwin) {
1453 windows[wcount] = wwin;
1454 wcount++;
1455 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1456 wwin = wwin->prev;
1461 for (i = 0; i < wcount; i++) {
1462 wwin = windows[i];
1463 if (wwin->frame->workspace == scr->current_workspace
1464 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1465 && !wwin->flags.internal_window
1466 && !WFLAGP(wwin, no_miniaturizable)
1468 wwin->flags.skip_next_animation = 1;
1469 wIconifyWindow(wwin);
1473 wfree(windows);
1476 void wHideOtherApplications(WWindow *awin)
1478 WWindow *wwin;
1479 WApplication *tapp;
1481 if (!awin)
1482 return;
1483 wwin = awin->screen_ptr->focused_window;
1485 while (wwin) {
1486 if (wwin != awin
1487 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1488 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1489 && !wwin->flags.internal_window
1490 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1492 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1493 if (!WFLAGP(wwin, no_miniaturizable)) {
1494 wwin->flags.skip_next_animation = 1;
1495 wIconifyWindow(wwin);
1497 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1498 tapp = wApplicationOf(wwin->main_window);
1499 if (tapp) {
1500 tapp->flags.skip_next_animation = 1;
1501 wHideApplication(tapp);
1502 } else {
1503 if (!WFLAGP(wwin, no_miniaturizable)) {
1504 wwin->flags.skip_next_animation = 1;
1505 wIconifyWindow(wwin);
1510 wwin = wwin->prev;
1513 wSetFocusTo(awin->screen_ptr, awin);
1517 void wHideApplication(WApplication *wapp)
1519 WScreen *scr;
1520 WWindow *wlist;
1521 int hadfocus;
1522 int animate;
1524 if (!wapp) {
1525 wwarning("trying to hide a non grouped window");
1526 return;
1528 if (!wapp->main_window_desc) {
1529 wwarning("group leader not found for window group");
1530 return;
1532 scr = wapp->main_window_desc->screen_ptr;
1533 hadfocus = 0;
1534 wlist = scr->focused_window;
1535 if (!wlist)
1536 return;
1538 if (wlist->main_window == wapp->main_window)
1539 wapp->last_focused = wlist;
1540 else
1541 wapp->last_focused = NULL;
1543 animate = !wapp->flags.skip_next_animation;
1545 while (wlist) {
1546 if (wlist->main_window == wapp->main_window) {
1547 if (wlist->flags.focused)
1548 hadfocus = 1;
1549 if (wapp->app_icon) {
1550 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1551 wapp->app_icon->y_pos, wlist, animate);
1552 animate = False;
1555 wlist = wlist->prev;
1558 wapp->flags.skip_next_animation = 0;
1560 if (hadfocus) {
1561 if (wPreferences.focus_mode == WKF_CLICK) {
1562 wlist = scr->focused_window;
1563 while (wlist) {
1564 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1565 && (wlist->flags.mapped || wlist->flags.shaded))
1566 break;
1567 wlist = wlist->prev;
1569 wSetFocusTo(scr, wlist);
1570 } else {
1571 wSetFocusTo(scr, NULL);
1575 wapp->flags.hidden = 1;
1577 if (wPreferences.auto_arrange_icons)
1578 wArrangeIcons(scr, True);
1580 #ifdef HIDDENDOT
1581 if (wapp->app_icon)
1582 wAppIconPaint(wapp->app_icon);
1583 #endif
1586 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1588 if (bringToCurrentWS)
1589 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1591 wwin->flags.hidden = 0;
1593 #ifdef USE_ANIMATIONS
1594 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1595 animateResize(wwin->screen_ptr, icon_x, icon_y,
1596 icon->core->width, icon->core->height,
1597 wwin->frame_x, wwin->frame_y,
1598 wwin->frame->core->width, wwin->frame->core->height);
1600 #else
1601 /* Tell the compiler it is normal that those parameters are not used in this case */
1602 (void) icon;
1603 (void) icon_x;
1604 (void) icon_y;
1605 (void) animate;
1606 #endif
1607 wwin->flags.skip_next_animation = 0;
1608 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1609 XMapWindow(dpy, wwin->client_win);
1610 XMapWindow(dpy, wwin->frame->core->window);
1611 wClientSetState(wwin, NormalState, None);
1612 wwin->flags.mapped = 1;
1613 wRaiseFrame(wwin->frame->core);
1615 if (wwin->flags.inspector_open)
1616 wUnhideInspectorForWindow(wwin);
1618 WMPostNotificationName(WMNChangedState, wwin, "hide");
1621 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1623 WScreen *scr;
1624 WWindow *wlist, *next;
1625 WWindow *focused = NULL;
1626 int animate;
1628 if (!wapp)
1629 return;
1631 scr = wapp->main_window_desc->screen_ptr;
1632 wlist = scr->focused_window;
1633 if (!wlist)
1634 return;
1636 /* goto beginning of list */
1637 while (wlist->prev)
1638 wlist = wlist->prev;
1640 animate = !wapp->flags.skip_next_animation;
1642 while (wlist) {
1643 next = wlist->next;
1645 if (wlist->main_window == wapp->main_window) {
1646 if (wlist->flags.focused)
1647 focused = wlist;
1648 else if (!focused || !focused->flags.focused)
1649 focused = wlist;
1651 if (wlist->flags.miniaturized) {
1652 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1653 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1654 if (!wlist->icon->mapped) {
1655 int x, y;
1657 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1658 if (wlist->icon_x != x || wlist->icon_y != y)
1659 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1660 wlist->icon_x = x;
1661 wlist->icon_y = y;
1662 XMapWindow(dpy, wlist->icon->core->window);
1663 wlist->icon->mapped = 1;
1665 wRaiseFrame(wlist->icon->core);
1667 if (bringToCurrentWS)
1668 wWindowChangeWorkspace(wlist, scr->current_workspace);
1669 wlist->flags.hidden = 0;
1670 if (miniwindows && wlist->frame->workspace == scr->current_workspace)
1671 wDeiconifyWindow(wlist);
1672 WMPostNotificationName(WMNChangedState, wlist, "hide");
1673 } else if (wlist->flags.shaded) {
1674 if (bringToCurrentWS)
1675 wWindowChangeWorkspace(wlist, scr->current_workspace);
1676 wlist->flags.hidden = 0;
1677 wRaiseFrame(wlist->frame->core);
1678 if (wlist->frame->workspace == scr->current_workspace) {
1679 XMapWindow(dpy, wlist->frame->core->window);
1680 if (miniwindows)
1681 wUnshadeWindow(wlist);
1683 WMPostNotificationName(WMNChangedState, wlist, "hide");
1684 } else if (wlist->flags.hidden) {
1685 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1686 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1687 animate = False;
1688 } else {
1689 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace)
1690 wWindowChangeWorkspace(wlist, scr->current_workspace);
1692 wRaiseFrame(wlist->frame->core);
1695 wlist = next;
1698 wapp->flags.skip_next_animation = 0;
1699 wapp->flags.hidden = 0;
1701 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1702 wRaiseFrame(wapp->last_focused->frame->core);
1703 wSetFocusTo(scr, wapp->last_focused);
1704 } else if (focused) {
1705 wSetFocusTo(scr, focused);
1707 wapp->last_focused = NULL;
1708 if (wPreferences.auto_arrange_icons)
1709 wArrangeIcons(scr, True);
1711 #ifdef HIDDENDOT
1712 wAppIconPaint(wapp->app_icon);
1713 #endif
1716 void wShowAllWindows(WScreen *scr)
1718 WWindow *wwin, *old_foc;
1719 WApplication *wapp;
1721 old_foc = wwin = scr->focused_window;
1722 while (wwin) {
1723 if (!wwin->flags.internal_window &&
1724 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1725 if (wwin->flags.miniaturized) {
1726 wwin->flags.skip_next_animation = 1;
1727 wDeiconifyWindow(wwin);
1728 } else if (wwin->flags.hidden) {
1729 wapp = wApplicationOf(wwin->main_window);
1730 if (wapp) {
1731 wUnhideApplication(wapp, False, False);
1732 } else {
1733 wwin->flags.skip_next_animation = 1;
1734 wDeiconifyWindow(wwin);
1738 wwin = wwin->prev;
1740 wSetFocusTo(scr, old_foc);
1741 /*wRaiseFrame(old_foc->frame->core); */
1744 void wRefreshDesktop(WScreen *scr)
1746 Window win;
1747 XSetWindowAttributes attr;
1749 attr.backing_store = NotUseful;
1750 attr.save_under = False;
1751 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1752 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1753 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1754 XMapRaised(dpy, win);
1755 XDestroyWindow(dpy, win);
1756 XFlush(dpy);
1759 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1761 WWindow *wwin;
1762 WAppIcon *aicon;
1764 int head;
1765 const int heads = wXineramaHeads(scr);
1767 struct HeadVars {
1768 int pf; /* primary axis */
1769 int sf; /* secondary axis */
1770 int fullW;
1771 int fullH;
1772 int pi, si;
1773 int sx1, sx2, sy1, sy2; /* screen boundary */
1774 int sw, sh;
1775 int xo, yo;
1776 int xs, ys;
1777 } *vars;
1779 int isize = wPreferences.icon_size;
1781 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1783 for (head = 0; head < heads; ++head) {
1784 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1785 WMRect rect;
1787 if (scr->dock) {
1788 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
1790 if (scr->dock->on_right_side)
1791 area.x2 -= offset;
1792 else
1793 area.x1 += offset;
1796 rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1798 vars[head].pi = vars[head].si = 0;
1799 vars[head].sx1 = rect.pos.x;
1800 vars[head].sy1 = rect.pos.y;
1801 vars[head].sw = rect.size.width;
1802 vars[head].sh = rect.size.height;
1803 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1804 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1805 vars[head].sw = isize * (vars[head].sw / isize);
1806 vars[head].sh = isize * (vars[head].sh / isize);
1807 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1808 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1810 /* icon yard boundaries */
1811 if (wPreferences.icon_yard & IY_VERT) {
1812 vars[head].pf = vars[head].fullH;
1813 vars[head].sf = vars[head].fullW;
1814 } else {
1815 vars[head].pf = vars[head].fullW;
1816 vars[head].sf = vars[head].fullH;
1818 if (wPreferences.icon_yard & IY_RIGHT) {
1819 vars[head].xo = vars[head].sx2 - isize;
1820 vars[head].xs = -1;
1821 } else {
1822 vars[head].xo = vars[head].sx1;
1823 vars[head].xs = 1;
1825 if (wPreferences.icon_yard & IY_TOP) {
1826 vars[head].yo = vars[head].sy1;
1827 vars[head].ys = 1;
1828 } else {
1829 vars[head].yo = vars[head].sy2 - isize;
1830 vars[head].ys = -1;
1834 #define X ((wPreferences.icon_yard & IY_VERT) \
1835 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1836 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1838 #define Y ((wPreferences.icon_yard & IY_VERT) \
1839 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1840 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1842 /* arrange application icons */
1843 aicon = scr->app_icon_list;
1844 /* reverse them to avoid unnecessarily sliding of icons */
1845 while (aicon && aicon->next)
1846 aicon = aicon->next;
1848 while (aicon) {
1849 if (!aicon->docked) {
1850 /* CHECK: can icon be NULL here ? */
1851 /* The intention here is to place the AppIcon on the head that
1852 * contains most of the applications _main_ window. */
1853 head = wGetHeadForWindow(aicon->icon->owner);
1855 if (aicon->x_pos != X || aicon->y_pos != Y) {
1856 #ifdef USE_ANIMATIONS
1857 if (!wPreferences.no_animations)
1858 slide_window(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1859 #endif /* USE_ANIMATIONS */
1861 wAppIconMove(aicon, X, Y);
1862 vars[head].pi++;
1863 if (vars[head].pi >= vars[head].pf) {
1864 vars[head].pi = 0;
1865 vars[head].si++;
1868 aicon = aicon->prev;
1871 /* arrange miniwindows */
1872 wwin = scr->focused_window;
1873 /* reverse them to avoid unnecessarily shuffling */
1874 while (wwin && wwin->prev)
1875 wwin = wwin->prev;
1877 while (wwin) {
1878 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1879 (wwin->frame->workspace == scr->current_workspace ||
1880 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1882 head = wGetHeadForWindow(wwin);
1884 if (arrangeAll || !wwin->flags.icon_moved) {
1885 if (wwin->icon_x != X || wwin->icon_y != Y)
1886 move_window(wwin->icon->core->window, wwin->icon_x, wwin->icon_y, X, Y);
1888 wwin->icon_x = X;
1889 wwin->icon_y = Y;
1891 vars[head].pi++;
1892 if (vars[head].pi >= vars[head].pf) {
1893 vars[head].pi = 0;
1894 vars[head].si++;
1898 if (arrangeAll)
1899 wwin->flags.icon_moved = 0;
1900 /* we reversed the order, so we use next */
1901 wwin = wwin->next;
1904 wfree(vars);
1907 void wSelectWindow(WWindow *wwin, Bool flag)
1909 WScreen *scr = wwin->screen_ptr;
1911 if (flag) {
1912 wwin->flags.selected = 1;
1913 if (wwin->frame->selected_border_pixel)
1914 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->selected_border_pixel);
1915 else
1916 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1918 if (!HAS_BORDER(wwin))
1919 XSetWindowBorderWidth(dpy, wwin->frame->core->window, wwin->screen_ptr->frame_border_width);
1921 if (!scr->selected_windows)
1922 scr->selected_windows = WMCreateArray(4);
1923 WMAddToArray(scr->selected_windows, wwin);
1924 } else {
1925 wwin->flags.selected = 0;
1926 if (wwin->flags.focused) {
1927 if (wwin->frame->focused_border_pixel)
1928 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->focused_border_pixel);
1929 else
1930 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_focused_border_pixel);
1931 } else {
1932 if (wwin->frame->border_pixel)
1933 XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->border_pixel);
1934 else
1935 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1938 if (!HAS_BORDER(wwin))
1939 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1941 if (scr->selected_windows)
1942 WMRemoveFromArray(scr->selected_windows, wwin);
1946 void wMakeWindowVisible(WWindow *wwin)
1948 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1949 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1951 if (wwin->flags.shaded)
1952 wUnshadeWindow(wwin);
1954 if (wwin->flags.hidden) {
1955 WApplication *app;
1957 app = wApplicationOf(wwin->main_window);
1958 if (app) {
1959 /* trick to get focus to this window */
1960 app->last_focused = wwin;
1961 wUnhideApplication(app, False, False);
1964 if (wwin->flags.miniaturized) {
1965 wDeiconifyWindow(wwin);
1966 } else {
1967 if (!WFLAGP(wwin, no_focusable))
1968 wSetFocusTo(wwin->screen_ptr, wwin);
1969 wRaiseFrame(wwin->frame->core);
1974 * Do the animation while shading (called with what = SHADE)
1975 * or unshading (what = UNSHADE).
1977 #ifdef USE_ANIMATIONS
1978 static void shade_animate(WWindow *wwin, Bool what)
1980 int y, s, w, h;
1981 time_t time0 = time(NULL);
1983 if (wwin->flags.skip_next_animation || wPreferences.no_animations)
1984 return;
1986 switch (what) {
1987 case SHADE:
1988 if (!wwin->screen_ptr->flags.startup) {
1989 /* do the shading animation */
1990 h = wwin->frame->core->height;
1991 s = h / SHADE_STEPS;
1992 if (s < 1)
1993 s = 1;
1994 w = wwin->frame->core->width;
1995 y = wwin->frame->top_width;
1996 while (h > wwin->frame->top_width + 1) {
1997 XMoveWindow(dpy, wwin->client_win, 0, y);
1998 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1999 XFlush(dpy);
2001 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2002 break;
2004 if (SHADE_DELAY > 0)
2005 wusleep(SHADE_DELAY * 1000L);
2006 else
2007 wusleep(10);
2008 h -= s;
2009 y -= s;
2011 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2013 break;
2015 case UNSHADE:
2016 h = wwin->frame->top_width + wwin->frame->bottom_width;
2017 y = wwin->frame->top_width - wwin->client.height;
2018 s = abs(y) / SHADE_STEPS;
2019 if (s < 1)
2020 s = 1;
2021 w = wwin->frame->core->width;
2022 XMoveWindow(dpy, wwin->client_win, 0, y);
2023 if (s > 0) {
2024 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
2025 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2026 XMoveWindow(dpy, wwin->client_win, 0, y);
2027 XFlush(dpy);
2028 if (SHADE_DELAY > 0)
2029 wusleep(SHADE_DELAY * 2000L / 3);
2030 else
2031 wusleep(10);
2032 h += s;
2033 y += s;
2035 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2036 break;
2039 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2040 break;
2043 #endif